Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(352)

Side by Side Diff: jcapimin.c

Issue 1934113002: Update libjpeg_turbo to 1.4.90 from https://github.com/libjpeg-turbo/ (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * jcapimin.c 2 * jcapimin.c
3 * 3 *
4 * This file was part of the Independent JPEG Group's software:
4 * Copyright (C) 1994-1998, Thomas G. Lane. 5 * Copyright (C) 1994-1998, Thomas G. Lane.
5 * Modified 2003-2010 by Guido Vollbeding. 6 * Modified 2003-2010 by Guido Vollbeding.
6 * This file is part of the Independent JPEG Group's software. 7 * It was modified by The libjpeg-turbo Project to include only code relevant
7 * For conditions of distribution and use, see the accompanying README file. 8 * to libjpeg-turbo.
9 * For conditions of distribution and use, see the accompanying README.ijg
10 * file.
8 * 11 *
9 * This file contains application interface code for the compression half 12 * This file contains application interface code for the compression half
10 * of the JPEG library. These are the "minimum" API routines that may be 13 * of the JPEG library. These are the "minimum" API routines that may be
11 * needed in either the normal full-compression case or the transcoding-only 14 * needed in either the normal full-compression case or the transcoding-only
12 * case. 15 * case.
13 * 16 *
14 * Most of the routines intended to be called directly by an application 17 * Most of the routines intended to be called directly by an application
15 * are in this file or in jcapistd.c. But also see jcparam.c for 18 * are in this file or in jcapistd.c. But also see jcparam.c for
16 * parameter-setup helper routines, jcomapi.c for routines shared by 19 * parameter-setup helper routines, jcomapi.c for routines shared by
17 * compression and decompression, and jctrans.c for the transcoding case. 20 * compression and decompression, and jctrans.c for the transcoding case.
18 */ 21 */
19 22
20 #define JPEG_INTERNALS 23 #define JPEG_INTERNALS
21 #include "jinclude.h" 24 #include "jinclude.h"
22 #include "jpeglib.h" 25 #include "jpeglib.h"
23 26
24 27
25 /* 28 /*
26 * Initialization of a JPEG compression object. 29 * Initialization of a JPEG compression object.
27 * The error manager must already be set up (in case memory manager fails). 30 * The error manager must already be set up (in case memory manager fails).
28 */ 31 */
29 32
30 GLOBAL(void) 33 GLOBAL(void)
31 jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize) 34 jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
32 { 35 {
33 int i; 36 int i;
34 37
35 /* Guard against version mismatches between library and caller. */ 38 /* Guard against version mismatches between library and caller. */
36 cinfo->mem = NULL;» » /* so jpeg_destroy knows mem mgr not called */ 39 cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
37 if (version != JPEG_LIB_VERSION) 40 if (version != JPEG_LIB_VERSION)
38 ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version); 41 ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
39 if (structsize != SIZEOF(struct jpeg_compress_struct)) 42 if (structsize != sizeof(struct jpeg_compress_struct))
40 ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, 43 ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
41 » (int) SIZEOF(struct jpeg_compress_struct), (int) structsize); 44 (int) sizeof(struct jpeg_compress_struct), (int) structsize);
42 45
43 /* For debugging purposes, we zero the whole master structure. 46 /* For debugging purposes, we zero the whole master structure.
44 * But the application has already set the err pointer, and may have set 47 * But the application has already set the err pointer, and may have set
45 * client_data, so we have to save and restore those fields. 48 * client_data, so we have to save and restore those fields.
46 * Note: if application hasn't set client_data, tools like Purify may 49 * Note: if application hasn't set client_data, tools like Purify may
47 * complain here. 50 * complain here.
48 */ 51 */
49 { 52 {
50 struct jpeg_error_mgr * err = cinfo->err; 53 struct jpeg_error_mgr *err = cinfo->err;
51 void * client_data = cinfo->client_data; /* ignore Purify complaint here */ 54 void *client_data = cinfo->client_data; /* ignore Purify complaint here */
52 MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct)); 55 MEMZERO(cinfo, sizeof(struct jpeg_compress_struct));
53 cinfo->err = err; 56 cinfo->err = err;
54 cinfo->client_data = client_data; 57 cinfo->client_data = client_data;
55 } 58 }
56 cinfo->is_decompressor = FALSE; 59 cinfo->is_decompressor = FALSE;
57 60
58 /* Initialize a memory manager instance for this object */ 61 /* Initialize a memory manager instance for this object */
59 jinit_memory_mgr((j_common_ptr) cinfo); 62 jinit_memory_mgr((j_common_ptr) cinfo);
60 63
61 /* Zero out pointers to permanent structures. */ 64 /* Zero out pointers to permanent structures. */
62 cinfo->progress = NULL; 65 cinfo->progress = NULL;
(...skipping 15 matching lines...) Expand all
78 81
79 #if JPEG_LIB_VERSION >= 80 82 #if JPEG_LIB_VERSION >= 80
80 /* Must do it here for emit_dqt in case jpeg_write_tables is used */ 83 /* Must do it here for emit_dqt in case jpeg_write_tables is used */
81 cinfo->block_size = DCTSIZE; 84 cinfo->block_size = DCTSIZE;
82 cinfo->natural_order = jpeg_natural_order; 85 cinfo->natural_order = jpeg_natural_order;
83 cinfo->lim_Se = DCTSIZE2-1; 86 cinfo->lim_Se = DCTSIZE2-1;
84 #endif 87 #endif
85 88
86 cinfo->script_space = NULL; 89 cinfo->script_space = NULL;
87 90
88 cinfo->input_gamma = 1.0;» /* in case application forgets */ 91 cinfo->input_gamma = 1.0; /* in case application forgets */
89 92
90 /* OK, I'm ready */ 93 /* OK, I'm ready */
91 cinfo->global_state = CSTATE_START; 94 cinfo->global_state = CSTATE_START;
92 } 95 }
93 96
94 97
95 /* 98 /*
96 * Destruction of a JPEG compression object 99 * Destruction of a JPEG compression object
97 */ 100 */
98 101
(...skipping 25 matching lines...) Expand all
124 * This routine is exported for use by applications that want to produce 127 * This routine is exported for use by applications that want to produce
125 * abbreviated JPEG datastreams. It logically belongs in jcparam.c, but 128 * abbreviated JPEG datastreams. It logically belongs in jcparam.c, but
126 * since it is called by jpeg_start_compress, we put it here --- otherwise 129 * since it is called by jpeg_start_compress, we put it here --- otherwise
127 * jcparam.o would be linked whether the application used it or not. 130 * jcparam.o would be linked whether the application used it or not.
128 */ 131 */
129 132
130 GLOBAL(void) 133 GLOBAL(void)
131 jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress) 134 jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
132 { 135 {
133 int i; 136 int i;
134 JQUANT_TBL * qtbl; 137 JQUANT_TBL *qtbl;
135 JHUFF_TBL * htbl; 138 JHUFF_TBL *htbl;
136 139
137 for (i = 0; i < NUM_QUANT_TBLS; i++) { 140 for (i = 0; i < NUM_QUANT_TBLS; i++) {
138 if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL) 141 if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
139 qtbl->sent_table = suppress; 142 qtbl->sent_table = suppress;
140 } 143 }
141 144
142 for (i = 0; i < NUM_HUFF_TBLS; i++) { 145 for (i = 0; i < NUM_HUFF_TBLS; i++) {
143 if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL) 146 if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
144 htbl->sent_table = suppress; 147 htbl->sent_table = suppress;
145 if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL) 148 if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
(...skipping 20 matching lines...) Expand all
166 if (cinfo->next_scanline < cinfo->image_height) 169 if (cinfo->next_scanline < cinfo->image_height)
167 ERREXIT(cinfo, JERR_TOO_LITTLE_DATA); 170 ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
168 (*cinfo->master->finish_pass) (cinfo); 171 (*cinfo->master->finish_pass) (cinfo);
169 } else if (cinfo->global_state != CSTATE_WRCOEFS) 172 } else if (cinfo->global_state != CSTATE_WRCOEFS)
170 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 173 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
171 /* Perform any remaining passes */ 174 /* Perform any remaining passes */
172 while (! cinfo->master->is_last_pass) { 175 while (! cinfo->master->is_last_pass) {
173 (*cinfo->master->prepare_for_pass) (cinfo); 176 (*cinfo->master->prepare_for_pass) (cinfo);
174 for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) { 177 for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
175 if (cinfo->progress != NULL) { 178 if (cinfo->progress != NULL) {
176 » cinfo->progress->pass_counter = (long) iMCU_row; 179 cinfo->progress->pass_counter = (long) iMCU_row;
177 » cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows; 180 cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
178 » (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo); 181 (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
179 } 182 }
180 /* We bypass the main controller and invoke coef controller directly; 183 /* We bypass the main controller and invoke coef controller directly;
181 * all work is being done from the coefficient buffer. 184 * all work is being done from the coefficient buffer.
182 */ 185 */
183 if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL)) 186 if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
184 » ERREXIT(cinfo, JERR_CANT_SUSPEND); 187 ERREXIT(cinfo, JERR_CANT_SUSPEND);
185 } 188 }
186 (*cinfo->master->finish_pass) (cinfo); 189 (*cinfo->master->finish_pass) (cinfo);
187 } 190 }
188 /* Write EOI, do final cleanup */ 191 /* Write EOI, do final cleanup */
189 (*cinfo->marker->write_file_trailer) (cinfo); 192 (*cinfo->marker->write_file_trailer) (cinfo);
190 (*cinfo->dest->term_destination) (cinfo); 193 (*cinfo->dest->term_destination) (cinfo);
191 /* We can use jpeg_abort to release memory and reset global_state */ 194 /* We can use jpeg_abort to release memory and reset global_state */
192 jpeg_abort((j_common_ptr) cinfo); 195 jpeg_abort((j_common_ptr) cinfo);
193 } 196 }
194 197
195 198
196 /* 199 /*
197 * Write a special marker. 200 * Write a special marker.
198 * This is only recommended for writing COM or APPn markers. 201 * This is only recommended for writing COM or APPn markers.
199 * Must be called after jpeg_start_compress() and before 202 * Must be called after jpeg_start_compress() and before
200 * first call to jpeg_write_scanlines() or jpeg_write_raw_data(). 203 * first call to jpeg_write_scanlines() or jpeg_write_raw_data().
201 */ 204 */
202 205
203 GLOBAL(void) 206 GLOBAL(void)
204 jpeg_write_marker (j_compress_ptr cinfo, int marker, 207 jpeg_write_marker (j_compress_ptr cinfo, int marker,
205 » » const JOCTET *dataptr, unsigned int datalen) 208 const JOCTET *dataptr, unsigned int datalen)
206 { 209 {
207 JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val)); 210 void (*write_marker_byte) (j_compress_ptr info, int val);
208 211
209 if (cinfo->next_scanline != 0 || 212 if (cinfo->next_scanline != 0 ||
210 (cinfo->global_state != CSTATE_SCANNING && 213 (cinfo->global_state != CSTATE_SCANNING &&
211 cinfo->global_state != CSTATE_RAW_OK && 214 cinfo->global_state != CSTATE_RAW_OK &&
212 cinfo->global_state != CSTATE_WRCOEFS)) 215 cinfo->global_state != CSTATE_WRCOEFS))
213 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); 216 ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
214 217
215 (*cinfo->marker->write_marker_header) (cinfo, marker, datalen); 218 (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
216 write_marker_byte = cinfo->marker->write_marker_byte;»/* copy for speed */ 219 write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
217 while (datalen--) { 220 while (datalen--) {
218 (*write_marker_byte) (cinfo, *dataptr); 221 (*write_marker_byte) (cinfo, *dataptr);
219 dataptr++; 222 dataptr++;
220 } 223 }
221 } 224 }
222 225
223 /* Same, but piecemeal. */ 226 /* Same, but piecemeal. */
224 227
225 GLOBAL(void) 228 GLOBAL(void)
226 jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen) 229 jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
(...skipping 14 matching lines...) Expand all
241 } 244 }
242 245
243 246
244 /* 247 /*
245 * Alternate compression function: just write an abbreviated table file. 248 * Alternate compression function: just write an abbreviated table file.
246 * Before calling this, all parameters and a data destination must be set up. 249 * Before calling this, all parameters and a data destination must be set up.
247 * 250 *
248 * To produce a pair of files containing abbreviated tables and abbreviated 251 * To produce a pair of files containing abbreviated tables and abbreviated
249 * image data, one would proceed as follows: 252 * image data, one would proceed as follows:
250 * 253 *
251 *» » initialize JPEG object 254 * initialize JPEG object
252 *» » set JPEG parameters 255 * set JPEG parameters
253 *» » set destination to table file 256 * set destination to table file
254 *» » jpeg_write_tables(cinfo); 257 * jpeg_write_tables(cinfo);
255 *» » set destination to image file 258 * set destination to image file
256 *» » jpeg_start_compress(cinfo, FALSE); 259 * jpeg_start_compress(cinfo, FALSE);
257 *» » write data... 260 * write data...
258 *» » jpeg_finish_compress(cinfo); 261 * jpeg_finish_compress(cinfo);
259 * 262 *
260 * jpeg_write_tables has the side effect of marking all tables written 263 * jpeg_write_tables has the side effect of marking all tables written
261 * (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress 264 * (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress
262 * will not re-emit the tables unless it is passed write_all_tables=TRUE. 265 * will not re-emit the tables unless it is passed write_all_tables=TRUE.
263 */ 266 */
264 267
265 GLOBAL(void) 268 GLOBAL(void)
266 jpeg_write_tables (j_compress_ptr cinfo) 269 jpeg_write_tables (j_compress_ptr cinfo)
267 { 270 {
268 if (cinfo->global_state != CSTATE_START) 271 if (cinfo->global_state != CSTATE_START)
(...skipping 14 matching lines...) Expand all
283 * writer. Some applications had a problem with that: they allocated space 286 * writer. Some applications had a problem with that: they allocated space
284 * of their own from the library memory manager, and didn't want it to go 287 * of their own from the library memory manager, and didn't want it to go
285 * away during write_tables. So now we do nothing. This will cause a 288 * away during write_tables. So now we do nothing. This will cause a
286 * memory leak if an app calls write_tables repeatedly without doing a full 289 * memory leak if an app calls write_tables repeatedly without doing a full
287 * compression cycle or otherwise resetting the JPEG object. However, that 290 * compression cycle or otherwise resetting the JPEG object. However, that
288 * seems less bad than unexpectedly freeing memory in the normal case. 291 * seems less bad than unexpectedly freeing memory in the normal case.
289 * An app that prefers the old behavior can call jpeg_abort for itself after 292 * An app that prefers the old behavior can call jpeg_abort for itself after
290 * each call to jpeg_write_tables(). 293 * each call to jpeg_write_tables().
291 */ 294 */
292 } 295 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698