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

Side by Side Diff: jcmainct.c

Issue 8720003: Update libjpeg-turbo to r722. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libjpeg_turbo/
Patch Set: '' Created 9 years 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 | Annotate | Revision Log
« no previous file with comments | « jccolor.c ('k') | jconfig.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * jcmainct.c 2 * jcmainct.c
3 * 3 *
4 * Copyright (C) 1994-1996, Thomas G. Lane. 4 * Copyright (C) 1994-1996, Thomas G. Lane.
5 * This file is part of the Independent JPEG Group's software. 5 * This file is part of the Independent JPEG Group's software.
6 * For conditions of distribution and use, see the accompanying README file. 6 * For conditions of distribution and use, see the accompanying README file.
7 * 7 *
8 * This file contains the main buffer controller for compression. 8 * This file contains the main buffer controller for compression.
9 * The main buffer lies between the pre-processor and the JPEG 9 * The main buffer lies between the pre-processor and the JPEG
10 * compressor proper; it holds downsampled data in the JPEG colorspace. 10 * compressor proper; it holds downsampled data in the JPEG colorspace.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #endif 61 #endif
62 62
63 63
64 /* 64 /*
65 * Initialize for a processing pass. 65 * Initialize for a processing pass.
66 */ 66 */
67 67
68 METHODDEF(void) 68 METHODDEF(void)
69 start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode) 69 start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
70 { 70 {
71 my_main_ptr main = (my_main_ptr) cinfo->main; 71 my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
72 72
73 /* Do nothing in raw-data mode. */ 73 /* Do nothing in raw-data mode. */
74 if (cinfo->raw_data_in) 74 if (cinfo->raw_data_in)
75 return; 75 return;
76 76
77 main->cur_iMCU_row = 0;» /* initialize counters */ 77 main_ptr->cur_iMCU_row = 0;» /* initialize counters */
78 main->rowgroup_ctr = 0; 78 main_ptr->rowgroup_ctr = 0;
79 main->suspended = FALSE; 79 main_ptr->suspended = FALSE;
80 main->pass_mode = pass_mode;» /* save mode for use by process_data */ 80 main_ptr->pass_mode = pass_mode;» /* save mode for use by process_data */
81 81
82 switch (pass_mode) { 82 switch (pass_mode) {
83 case JBUF_PASS_THRU: 83 case JBUF_PASS_THRU:
84 #ifdef FULL_MAIN_BUFFER_SUPPORTED 84 #ifdef FULL_MAIN_BUFFER_SUPPORTED
85 if (main->whole_image[0] != NULL) 85 if (main_ptr->whole_image[0] != NULL)
86 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); 86 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
87 #endif 87 #endif
88 main->pub.process_data = process_data_simple_main; 88 main_ptr->pub.process_data = process_data_simple_main;
89 break; 89 break;
90 #ifdef FULL_MAIN_BUFFER_SUPPORTED 90 #ifdef FULL_MAIN_BUFFER_SUPPORTED
91 case JBUF_SAVE_SOURCE: 91 case JBUF_SAVE_SOURCE:
92 case JBUF_CRANK_DEST: 92 case JBUF_CRANK_DEST:
93 case JBUF_SAVE_AND_PASS: 93 case JBUF_SAVE_AND_PASS:
94 if (main->whole_image[0] == NULL) 94 if (main_ptr->whole_image[0] == NULL)
95 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); 95 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
96 main->pub.process_data = process_data_buffer_main; 96 main_ptr->pub.process_data = process_data_buffer_main;
97 break; 97 break;
98 #endif 98 #endif
99 default: 99 default:
100 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); 100 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
101 break; 101 break;
102 } 102 }
103 } 103 }
104 104
105 105
106 /* 106 /*
107 * Process some data. 107 * Process some data.
108 * This routine handles the simple pass-through mode, 108 * This routine handles the simple pass-through mode,
109 * where we have only a strip buffer. 109 * where we have only a strip buffer.
110 */ 110 */
111 111
112 METHODDEF(void) 112 METHODDEF(void)
113 process_data_simple_main (j_compress_ptr cinfo, 113 process_data_simple_main (j_compress_ptr cinfo,
114 JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, 114 JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
115 JDIMENSION in_rows_avail) 115 JDIMENSION in_rows_avail)
116 { 116 {
117 my_main_ptr main = (my_main_ptr) cinfo->main; 117 my_main_ptr main_ptr = (my_main_ptr) cinfo->main;
118 118
119 while (main->cur_iMCU_row < cinfo->total_iMCU_rows) { 119 while (main_ptr->cur_iMCU_row < cinfo->total_iMCU_rows) {
120 /* Read input data if we haven't filled the main buffer yet */ 120 /* Read input data if we haven't filled the main buffer yet */
121 if (main->rowgroup_ctr < DCTSIZE) 121 if (main_ptr->rowgroup_ctr < DCTSIZE)
122 (*cinfo->prep->pre_process_data) (cinfo, 122 (*cinfo->prep->pre_process_data) (cinfo,
123 input_buf, in_row_ctr, in_rows_avail, 123 input_buf, in_row_ctr, in_rows_avail,
124 » » » » » main->buffer, &main->rowgroup_ctr, 124 » » » » » main_ptr->buffer, &main_ptr->rowgroup_ct r,
125 (JDIMENSION) DCTSIZE); 125 (JDIMENSION) DCTSIZE);
126 126
127 /* If we don't have a full iMCU row buffered, return to application for 127 /* If we don't have a full iMCU row buffered, return to application for
128 * more data. Note that preprocessor will always pad to fill the iMCU row 128 * more data. Note that preprocessor will always pad to fill the iMCU row
129 * at the bottom of the image. 129 * at the bottom of the image.
130 */ 130 */
131 if (main->rowgroup_ctr != DCTSIZE) 131 if (main_ptr->rowgroup_ctr != DCTSIZE)
132 return; 132 return;
133 133
134 /* Send the completed row to the compressor */ 134 /* Send the completed row to the compressor */
135 if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) { 135 if (! (*cinfo->coef->compress_data) (cinfo, main_ptr->buffer)) {
136 /* If compressor did not consume the whole row, then we must need to 136 /* If compressor did not consume the whole row, then we must need to
137 * suspend processing and return to the application. In this situation 137 * suspend processing and return to the application. In this situation
138 * we pretend we didn't yet consume the last input row; otherwise, if 138 * we pretend we didn't yet consume the last input row; otherwise, if
139 * it happened to be the last row of the image, the application would 139 * it happened to be the last row of the image, the application would
140 * think we were done. 140 * think we were done.
141 */ 141 */
142 if (! main->suspended) { 142 if (! main_ptr->suspended) {
143 (*in_row_ctr)--; 143 (*in_row_ctr)--;
144 » main->suspended = TRUE; 144 » main_ptr->suspended = TRUE;
145 } 145 }
146 return; 146 return;
147 } 147 }
148 /* We did finish the row. Undo our little suspension hack if a previous 148 /* We did finish the row. Undo our little suspension hack if a previous
149 * call suspended; then mark the main buffer empty. 149 * call suspended; then mark the main buffer empty.
150 */ 150 */
151 if (main->suspended) { 151 if (main_ptr->suspended) {
152 (*in_row_ctr)++; 152 (*in_row_ctr)++;
153 main->suspended = FALSE; 153 main_ptr->suspended = FALSE;
154 } 154 }
155 main->rowgroup_ctr = 0; 155 main_ptr->rowgroup_ctr = 0;
156 main->cur_iMCU_row++; 156 main_ptr->cur_iMCU_row++;
157 } 157 }
158 } 158 }
159 159
160 160
161 #ifdef FULL_MAIN_BUFFER_SUPPORTED 161 #ifdef FULL_MAIN_BUFFER_SUPPORTED
162 162
163 /* 163 /*
164 * Process some data. 164 * Process some data.
165 * This routine handles all of the modes that use a full-size buffer. 165 * This routine handles all of the modes that use a full-size buffer.
166 */ 166 */
167 167
168 METHODDEF(void) 168 METHODDEF(void)
169 process_data_buffer_main (j_compress_ptr cinfo, 169 process_data_buffer_main (j_compress_ptr cinfo,
170 JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, 170 JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
171 JDIMENSION in_rows_avail) 171 JDIMENSION in_rows_avail)
172 { 172 {
173 my_main_ptr main = (my_main_ptr) cinfo->main; 173 my_main_ptr main = (my_main_ptr) cinfo->main;
174 int ci; 174 int ci;
175 jpeg_component_info *compptr; 175 jpeg_component_info *compptr;
176 boolean writing = (main->pass_mode != JBUF_CRANK_DEST); 176 boolean writing = (main_ptr->pass_mode != JBUF_CRANK_DEST);
177 177
178 while (main->cur_iMCU_row < cinfo->total_iMCU_rows) { 178 while (main_ptr->cur_iMCU_row < cinfo->total_iMCU_rows) {
179 /* Realign the virtual buffers if at the start of an iMCU row. */ 179 /* Realign the virtual buffers if at the start of an iMCU row. */
180 if (main->rowgroup_ctr == 0) { 180 if (main_ptr->rowgroup_ctr == 0) {
181 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 181 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
182 ci++, compptr++) { 182 ci++, compptr++) {
183 » main->buffer[ci] = (*cinfo->mem->access_virt_sarray) 183 » main_ptr->buffer[ci] = (*cinfo->mem->access_virt_sarray)
184 » ((j_common_ptr) cinfo, main->whole_image[ci], 184 » ((j_common_ptr) cinfo, main_ptr->whole_image[ci],
185 » main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE), 185 » main_ptr->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
186 (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing); 186 (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
187 } 187 }
188 /* In a read pass, pretend we just read some source data. */ 188 /* In a read pass, pretend we just read some source data. */
189 if (! writing) { 189 if (! writing) {
190 *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE; 190 *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
191 » main->rowgroup_ctr = DCTSIZE; 191 » main_ptr->rowgroup_ctr = DCTSIZE;
192 } 192 }
193 } 193 }
194 194
195 /* If a write pass, read input data until the current iMCU row is full. */ 195 /* If a write pass, read input data until the current iMCU row is full. */
196 /* Note: preprocessor will pad if necessary to fill the last iMCU row. */ 196 /* Note: preprocessor will pad if necessary to fill the last iMCU row. */
197 if (writing) { 197 if (writing) {
198 (*cinfo->prep->pre_process_data) (cinfo, 198 (*cinfo->prep->pre_process_data) (cinfo,
199 input_buf, in_row_ctr, in_rows_avail, 199 input_buf, in_row_ctr, in_rows_avail,
200 » » » » » main->buffer, &main->rowgroup_ctr, 200 » » » » » main_ptr->buffer, &main_ptr->rowgroup_ct r,
201 (JDIMENSION) DCTSIZE); 201 (JDIMENSION) DCTSIZE);
202 /* Return to application if we need more data to fill the iMCU row. */ 202 /* Return to application if we need more data to fill the iMCU row. */
203 if (main->rowgroup_ctr < DCTSIZE) 203 if (main_ptr->rowgroup_ctr < DCTSIZE)
204 return; 204 return;
205 } 205 }
206 206
207 /* Emit data, unless this is a sink-only pass. */ 207 /* Emit data, unless this is a sink-only pass. */
208 if (main->pass_mode != JBUF_SAVE_SOURCE) { 208 if (main_ptr->pass_mode != JBUF_SAVE_SOURCE) {
209 if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) { 209 if (! (*cinfo->coef->compress_data) (cinfo, main_ptr->buffer)) {
210 /* If compressor did not consume the whole row, then we must need to 210 /* If compressor did not consume the whole row, then we must need to
211 * suspend processing and return to the application. In this situation 211 * suspend processing and return to the application. In this situation
212 * we pretend we didn't yet consume the last input row; otherwise, if 212 * we pretend we didn't yet consume the last input row; otherwise, if
213 * it happened to be the last row of the image, the application would 213 * it happened to be the last row of the image, the application would
214 * think we were done. 214 * think we were done.
215 */ 215 */
216 » if (! main->suspended) { 216 » if (! main_ptr->suspended) {
217 (*in_row_ctr)--; 217 (*in_row_ctr)--;
218 » main->suspended = TRUE; 218 » main_ptr->suspended = TRUE;
219 } 219 }
220 return; 220 return;
221 } 221 }
222 /* We did finish the row. Undo our little suspension hack if a previous 222 /* We did finish the row. Undo our little suspension hack if a previous
223 * call suspended; then mark the main buffer empty. 223 * call suspended; then mark the main buffer empty.
224 */ 224 */
225 if (main->suspended) { 225 if (main_ptr->suspended) {
226 (*in_row_ctr)++; 226 (*in_row_ctr)++;
227 » main->suspended = FALSE; 227 » main_ptr->suspended = FALSE;
228 } 228 }
229 } 229 }
230 230
231 /* If get here, we are done with this iMCU row. Mark buffer empty. */ 231 /* If get here, we are done with this iMCU row. Mark buffer empty. */
232 main->rowgroup_ctr = 0; 232 main_ptr->rowgroup_ctr = 0;
233 main->cur_iMCU_row++; 233 main_ptr->cur_iMCU_row++;
234 } 234 }
235 } 235 }
236 236
237 #endif /* FULL_MAIN_BUFFER_SUPPORTED */ 237 #endif /* FULL_MAIN_BUFFER_SUPPORTED */
238 238
239 239
240 /* 240 /*
241 * Initialize main buffer controller. 241 * Initialize main buffer controller.
242 */ 242 */
243 243
244 GLOBAL(void) 244 GLOBAL(void)
245 jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer) 245 jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
246 { 246 {
247 my_main_ptr main; 247 my_main_ptr main_ptr;
248 int ci; 248 int ci;
249 jpeg_component_info *compptr; 249 jpeg_component_info *compptr;
250 250
251 main = (my_main_ptr) 251 main_ptr = (my_main_ptr)
252 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, 252 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
253 SIZEOF(my_main_controller)); 253 SIZEOF(my_main_controller));
254 cinfo->main = (struct jpeg_c_main_controller *) main; 254 cinfo->main = (struct jpeg_c_main_controller *) main_ptr;
255 main->pub.start_pass = start_pass_main; 255 main_ptr->pub.start_pass = start_pass_main;
256 256
257 /* We don't need to create a buffer in raw-data mode. */ 257 /* We don't need to create a buffer in raw-data mode. */
258 if (cinfo->raw_data_in) 258 if (cinfo->raw_data_in)
259 return; 259 return;
260 260
261 /* Create the buffer. It holds downsampled data, so each component 261 /* Create the buffer. It holds downsampled data, so each component
262 * may be of a different size. 262 * may be of a different size.
263 */ 263 */
264 if (need_full_buffer) { 264 if (need_full_buffer) {
265 #ifdef FULL_MAIN_BUFFER_SUPPORTED 265 #ifdef FULL_MAIN_BUFFER_SUPPORTED
266 /* Allocate a full-image virtual array for each component */ 266 /* Allocate a full-image virtual array for each component */
267 /* Note we pad the bottom to a multiple of the iMCU height */ 267 /* Note we pad the bottom to a multiple of the iMCU height */
268 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 268 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
269 ci++, compptr++) { 269 ci++, compptr++) {
270 main->whole_image[ci] = (*cinfo->mem->request_virt_sarray) 270 main_ptr->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
271 ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE, 271 ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
272 compptr->width_in_blocks * DCTSIZE, 272 compptr->width_in_blocks * DCTSIZE,
273 (JDIMENSION) jround_up((long) compptr->height_in_blocks, 273 (JDIMENSION) jround_up((long) compptr->height_in_blocks,
274 (long) compptr->v_samp_factor) * DCTSIZE, 274 (long) compptr->v_samp_factor) * DCTSIZE,
275 (JDIMENSION) (compptr->v_samp_factor * DCTSIZE)); 275 (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
276 } 276 }
277 #else 277 #else
278 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE); 278 ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
279 #endif 279 #endif
280 } else { 280 } else {
281 #ifdef FULL_MAIN_BUFFER_SUPPORTED 281 #ifdef FULL_MAIN_BUFFER_SUPPORTED
282 main->whole_image[0] = NULL; /* flag for no virtual arrays */ 282 main_ptr->whole_image[0] = NULL; /* flag for no virtual arrays */
283 #endif 283 #endif
284 /* Allocate a strip buffer for each component */ 284 /* Allocate a strip buffer for each component */
285 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; 285 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
286 ci++, compptr++) { 286 ci++, compptr++) {
287 main->buffer[ci] = (*cinfo->mem->alloc_sarray) 287 main_ptr->buffer[ci] = (*cinfo->mem->alloc_sarray)
288 ((j_common_ptr) cinfo, JPOOL_IMAGE, 288 ((j_common_ptr) cinfo, JPOOL_IMAGE,
289 compptr->width_in_blocks * DCTSIZE, 289 compptr->width_in_blocks * DCTSIZE,
290 (JDIMENSION) (compptr->v_samp_factor * DCTSIZE)); 290 (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
291 } 291 }
292 } 292 }
293 } 293 }
OLDNEW
« no previous file with comments | « jccolor.c ('k') | jconfig.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698