Final 350 project
Dependencies: uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed
jcapimin.c
00001 /* 00002 * jcapimin.c 00003 * 00004 * Copyright (C) 1994-1998, Thomas G. Lane. 00005 * Modified 2003-2010 by Guido Vollbeding. 00006 * This file is part of the Independent JPEG Group's software. 00007 * For conditions of distribution and use, see the accompanying README file. 00008 * 00009 * This file contains application interface code for the compression half 00010 * of the JPEG library. These are the "minimum" API routines that may be 00011 * needed in either the normal full-compression case or the transcoding-only 00012 * case. 00013 * 00014 * Most of the routines intended to be called directly by an application 00015 * are in this file or in jcapistd.c. But also see jcparam.c for 00016 * parameter-setup helper routines, jcomapi.c for routines shared by 00017 * compression and decompression, and jctrans.c for the transcoding case. 00018 */ 00019 00020 #define JPEG_INTERNALS 00021 #include "jinclude.h" 00022 #include "jpeglib.h" 00023 00024 00025 /* 00026 * Initialization of a JPEG compression object. 00027 * The error manager must already be set up (in case memory manager fails). 00028 */ 00029 00030 GLOBAL(void) 00031 jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize) 00032 { 00033 int i; 00034 00035 /* Guard against version mismatches between library and caller. */ 00036 cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */ 00037 if (version != JPEG_LIB_VERSION) 00038 ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); 00039 if (structsize != SIZEOF(struct jpeg_compress_struct)) 00040 ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, 00041 (int) SIZEOF(struct jpeg_compress_struct), (int) structsize); 00042 00043 /* For debugging purposes, we zero the whole master structure. 00044 * But the application has already set the err pointer, and may have set 00045 * client_data, so we have to save and restore those fields. 00046 * Note: if application hasn't set client_data, tools like Purify may 00047 * complain here. 00048 */ 00049 { 00050 struct jpeg_error_mgr * err = cinfo->err; 00051 void * client_data = cinfo->client_data; /* ignore Purify complaint here */ 00052 MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct)); 00053 cinfo->err = err; 00054 cinfo->client_data = client_data; 00055 } 00056 cinfo->is_decompressor = FALSE; 00057 00058 /* Initialize a memory manager instance for this object */ 00059 jinit_memory_mgr((j_common_ptr) cinfo); 00060 00061 /* Zero out pointers to permanent structures. */ 00062 cinfo->progress = NULL; 00063 cinfo->dest = NULL; 00064 00065 cinfo->comp_info = NULL; 00066 00067 for (i = 0; i < NUM_QUANT_TBLS; i++) { 00068 cinfo->quant_tbl_ptrs[i] = NULL; 00069 cinfo->q_scale_factor[i] = 100; 00070 } 00071 00072 for (i = 0; i < NUM_HUFF_TBLS; i++) { 00073 cinfo->dc_huff_tbl_ptrs[i] = NULL; 00074 cinfo->ac_huff_tbl_ptrs[i] = NULL; 00075 } 00076 00077 /* Must do it here for emit_dqt in case jpeg_write_tables is used */ 00078 cinfo->block_size = DCTSIZE; 00079 cinfo->natural_order = jpeg_natural_order; 00080 cinfo->lim_Se = DCTSIZE2-1; 00081 00082 cinfo->script_space = NULL; 00083 00084 cinfo->input_gamma = 1.0; /* in case application forgets */ 00085 00086 /* OK, I'm ready */ 00087 cinfo->global_state = CSTATE_START; 00088 } 00089 00090 00091 /* 00092 * Destruction of a JPEG compression object 00093 */ 00094 00095 GLOBAL(void) 00096 jpeg_destroy_compress (j_compress_ptr cinfo) 00097 { 00098 jpeg_destroy((j_common_ptr) cinfo); /* use common routine */ 00099 } 00100 00101 00102 /* 00103 * Abort processing of a JPEG compression operation, 00104 * but don't destroy the object itself. 00105 */ 00106 00107 GLOBAL(void) 00108 jpeg_abort_compress (j_compress_ptr cinfo) 00109 { 00110 jpeg_abort((j_common_ptr) cinfo); /* use common routine */ 00111 } 00112 00113 00114 /* 00115 * Forcibly suppress or un-suppress all quantization and Huffman tables. 00116 * Marks all currently defined tables as already written (if suppress) 00117 * or not written (if !suppress). This will control whether they get emitted 00118 * by a subsequent jpeg_start_compress call. 00119 * 00120 * This routine is exported for use by applications that want to produce 00121 * abbreviated JPEG datastreams. It logically belongs in jcparam.c, but 00122 * since it is called by jpeg_start_compress, we put it here --- otherwise 00123 * jcparam.o would be linked whether the application used it or not. 00124 */ 00125 00126 GLOBAL(void) 00127 jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress) 00128 { 00129 int i; 00130 JQUANT_TBL * qtbl; 00131 JHUFF_TBL * htbl; 00132 00133 for (i = 0; i < NUM_QUANT_TBLS; i++) { 00134 if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL) 00135 qtbl->sent_table = suppress; 00136 } 00137 00138 for (i = 0; i < NUM_HUFF_TBLS; i++) { 00139 if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL) 00140 htbl->sent_table = suppress; 00141 if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL) 00142 htbl->sent_table = suppress; 00143 } 00144 } 00145 00146 00147 /* 00148 * Finish JPEG compression. 00149 * 00150 * If a multipass operating mode was selected, this may do a great deal of 00151 * work including most of the actual output. 00152 */ 00153 00154 GLOBAL(void) 00155 jpeg_finish_compress (j_compress_ptr cinfo) 00156 { 00157 JDIMENSION iMCU_row; 00158 00159 if (cinfo->global_state == CSTATE_SCANNING || 00160 cinfo->global_state == CSTATE_RAW_OK) { 00161 /* Terminate first pass */ 00162 if (cinfo->next_scanline < cinfo->image_height) 00163 ERREXIT(cinfo, JERR_TOO_LITTLE_DATA); 00164 (*cinfo->master->finish_pass) (cinfo); 00165 } else if (cinfo->global_state != CSTATE_WRCOEFS) 00166 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 00167 /* Perform any remaining passes */ 00168 while (! cinfo->master->is_last_pass) { 00169 (*cinfo->master->prepare_for_pass) (cinfo); 00170 for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) { 00171 if (cinfo->progress != NULL) { 00172 cinfo->progress->pass_counter = (long) iMCU_row; 00173 cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows; 00174 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); 00175 } 00176 /* We bypass the main controller and invoke coef controller directly; 00177 * all work is being done from the coefficient buffer. 00178 */ 00179 if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL)) 00180 ERREXIT(cinfo, JERR_CANT_SUSPEND); 00181 } 00182 (*cinfo->master->finish_pass) (cinfo); 00183 } 00184 /* Write EOI, do final cleanup */ 00185 (*cinfo->marker->write_file_trailer) (cinfo); 00186 (*cinfo->dest->term_destination) (cinfo); 00187 /* We can use jpeg_abort to release memory and reset global_state */ 00188 jpeg_abort((j_common_ptr) cinfo); 00189 } 00190 00191 00192 /* 00193 * Write a special marker. 00194 * This is only recommended for writing COM or APPn markers. 00195 * Must be called after jpeg_start_compress() and before 00196 * first call to jpeg_write_scanlines() or jpeg_write_raw_data(). 00197 */ 00198 00199 GLOBAL(void) 00200 jpeg_write_marker (j_compress_ptr cinfo, int marker, 00201 const JOCTET *dataptr, unsigned int datalen) 00202 { 00203 JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val)); 00204 00205 if (cinfo->next_scanline != 0 || 00206 (cinfo->global_state != CSTATE_SCANNING && 00207 cinfo->global_state != CSTATE_RAW_OK && 00208 cinfo->global_state != CSTATE_WRCOEFS)) 00209 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 00210 00211 (*cinfo->marker->write_marker_header) (cinfo, marker, datalen); 00212 write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */ 00213 while (datalen--) { 00214 (*write_marker_byte) (cinfo, *dataptr); 00215 dataptr++; 00216 } 00217 } 00218 00219 /* Same, but piecemeal. */ 00220 00221 GLOBAL(void) 00222 jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen) 00223 { 00224 if (cinfo->next_scanline != 0 || 00225 (cinfo->global_state != CSTATE_SCANNING && 00226 cinfo->global_state != CSTATE_RAW_OK && 00227 cinfo->global_state != CSTATE_WRCOEFS)) 00228 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 00229 00230 (*cinfo->marker->write_marker_header) (cinfo, marker, datalen); 00231 } 00232 00233 GLOBAL(void) 00234 jpeg_write_m_byte (j_compress_ptr cinfo, int val) 00235 { 00236 (*cinfo->marker->write_marker_byte) (cinfo, val); 00237 } 00238 00239 00240 /* 00241 * Alternate compression function: just write an abbreviated table file. 00242 * Before calling this, all parameters and a data destination must be set up. 00243 * 00244 * To produce a pair of files containing abbreviated tables and abbreviated 00245 * image data, one would proceed as follows: 00246 * 00247 * initialize JPEG object 00248 * set JPEG parameters 00249 * set destination to table file 00250 * jpeg_write_tables(cinfo); 00251 * set destination to image file 00252 * jpeg_start_compress(cinfo, FALSE); 00253 * write data... 00254 * jpeg_finish_compress(cinfo); 00255 * 00256 * jpeg_write_tables has the side effect of marking all tables written 00257 * (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress 00258 * will not re-emit the tables unless it is passed write_all_tables=TRUE. 00259 */ 00260 00261 GLOBAL(void) 00262 jpeg_write_tables (j_compress_ptr cinfo) 00263 { 00264 if (cinfo->global_state != CSTATE_START) 00265 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 00266 00267 /* (Re)initialize error mgr and destination modules */ 00268 (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo); 00269 (*cinfo->dest->init_destination) (cinfo); 00270 /* Initialize the marker writer ... bit of a crock to do it here. */ 00271 jinit_marker_writer(cinfo); 00272 /* Write them tables! */ 00273 (*cinfo->marker->write_tables_only) (cinfo); 00274 /* And clean up. */ 00275 (*cinfo->dest->term_destination) (cinfo); 00276 /* 00277 * In library releases up through v6a, we called jpeg_abort() here to free 00278 * any working memory allocated by the destination manager and marker 00279 * writer. Some applications had a problem with that: they allocated space 00280 * of their own from the library memory manager, and didn't want it to go 00281 * away during write_tables. So now we do nothing. This will cause a 00282 * memory leak if an app calls write_tables repeatedly without doing a full 00283 * compression cycle or otherwise resetting the JPEG object. However, that 00284 * seems less bad than unexpectedly freeing memory in the normal case. 00285 * An app that prefers the old behavior can call jpeg_abort for itself after 00286 * each call to jpeg_write_tables(). 00287 */ 00288 }
Generated on Wed Jul 13 2022 18:56:09 by 1.7.2