159 * This is done only once, not once per pass. |
159 * This is done only once, not once per pass. |
160 */ |
160 */ |
161 { |
161 { |
162 my_main_ptr main = (my_main_ptr) cinfo->main; |
162 my_main_ptr main = (my_main_ptr) cinfo->main; |
163 int ci, rgroup; |
163 int ci, rgroup; |
164 int M = cinfo->min_DCT_scaled_size; |
164 int M = cinfo->min_DCT_v_scaled_size; |
165 jpeg_component_info *compptr; |
165 jpeg_component_info *compptr; |
166 JSAMPARRAY xbuf; |
166 JSAMPARRAY xbuf; |
167 |
167 |
168 /* Get top-level space for component array pointers. |
168 /* Get top-level space for component array pointers. |
169 * We alloc both arrays with one call to save a few cycles. |
169 * We alloc both arrays with one call to save a few cycles. |
173 cinfo->num_components * 2 * SIZEOF(JSAMPARRAY)); |
173 cinfo->num_components * 2 * SIZEOF(JSAMPARRAY)); |
174 main->xbuffer[1] = main->xbuffer[0] + cinfo->num_components; |
174 main->xbuffer[1] = main->xbuffer[0] + cinfo->num_components; |
175 |
175 |
176 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
176 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
177 ci++, compptr++) { |
177 ci++, compptr++) { |
178 rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) / |
178 rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) / |
179 cinfo->min_DCT_scaled_size; /* height of a row group of component */ |
179 cinfo->min_DCT_v_scaled_size; /* height of a row group of component */ |
180 /* Get space for pointer lists --- M+4 row groups in each list. |
180 /* Get space for pointer lists --- M+4 row groups in each list. |
181 * We alloc both pointer lists with one call to save a few cycles. |
181 * We alloc both pointer lists with one call to save a few cycles. |
182 */ |
182 */ |
183 xbuf = (JSAMPARRAY) |
183 xbuf = (JSAMPARRAY) |
184 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
184 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
200 * This will be repeated at the beginning of each pass. |
200 * This will be repeated at the beginning of each pass. |
201 */ |
201 */ |
202 { |
202 { |
203 my_main_ptr main = (my_main_ptr) cinfo->main; |
203 my_main_ptr main = (my_main_ptr) cinfo->main; |
204 int ci, i, rgroup; |
204 int ci, i, rgroup; |
205 int M = cinfo->min_DCT_scaled_size; |
205 int M = cinfo->min_DCT_v_scaled_size; |
206 jpeg_component_info *compptr; |
206 jpeg_component_info *compptr; |
207 JSAMPARRAY buf, xbuf0, xbuf1; |
207 JSAMPARRAY buf, xbuf0, xbuf1; |
208 |
208 |
209 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
209 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
210 ci++, compptr++) { |
210 ci++, compptr++) { |
211 rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) / |
211 rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) / |
212 cinfo->min_DCT_scaled_size; /* height of a row group of component */ |
212 cinfo->min_DCT_v_scaled_size; /* height of a row group of component */ |
213 xbuf0 = main->xbuffer[0][ci]; |
213 xbuf0 = main->xbuffer[0][ci]; |
214 xbuf1 = main->xbuffer[1][ci]; |
214 xbuf1 = main->xbuffer[1][ci]; |
215 /* First copy the workspace pointers as-is */ |
215 /* First copy the workspace pointers as-is */ |
216 buf = main->buffer[ci]; |
216 buf = main->buffer[ci]; |
217 for (i = 0; i < rgroup * (M + 2); i++) { |
217 for (i = 0; i < rgroup * (M + 2); i++) { |
240 * This changes the pointer list state from top-of-image to the normal state. |
240 * This changes the pointer list state from top-of-image to the normal state. |
241 */ |
241 */ |
242 { |
242 { |
243 my_main_ptr main = (my_main_ptr) cinfo->main; |
243 my_main_ptr main = (my_main_ptr) cinfo->main; |
244 int ci, i, rgroup; |
244 int ci, i, rgroup; |
245 int M = cinfo->min_DCT_scaled_size; |
245 int M = cinfo->min_DCT_v_scaled_size; |
246 jpeg_component_info *compptr; |
246 jpeg_component_info *compptr; |
247 JSAMPARRAY xbuf0, xbuf1; |
247 JSAMPARRAY xbuf0, xbuf1; |
248 |
248 |
249 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
249 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
250 ci++, compptr++) { |
250 ci++, compptr++) { |
251 rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) / |
251 rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) / |
252 cinfo->min_DCT_scaled_size; /* height of a row group of component */ |
252 cinfo->min_DCT_v_scaled_size; /* height of a row group of component */ |
253 xbuf0 = main->xbuffer[0][ci]; |
253 xbuf0 = main->xbuffer[0][ci]; |
254 xbuf1 = main->xbuffer[1][ci]; |
254 xbuf1 = main->xbuffer[1][ci]; |
255 for (i = 0; i < rgroup; i++) { |
255 for (i = 0; i < rgroup; i++) { |
256 xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i]; |
256 xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i]; |
257 xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i]; |
257 xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i]; |
275 JSAMPARRAY xbuf; |
275 JSAMPARRAY xbuf; |
276 |
276 |
277 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
277 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
278 ci++, compptr++) { |
278 ci++, compptr++) { |
279 /* Count sample rows in one iMCU row and in one row group */ |
279 /* Count sample rows in one iMCU row and in one row group */ |
280 iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size; |
280 iMCUheight = compptr->v_samp_factor * compptr->DCT_v_scaled_size; |
281 rgroup = iMCUheight / cinfo->min_DCT_scaled_size; |
281 rgroup = iMCUheight / cinfo->min_DCT_v_scaled_size; |
282 /* Count nondummy sample rows remaining for this component */ |
282 /* Count nondummy sample rows remaining for this component */ |
283 rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight); |
283 rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight); |
284 if (rows_left == 0) rows_left = iMCUheight; |
284 if (rows_left == 0) rows_left = iMCUheight; |
285 /* Count nondummy row groups. Should get same answer for each component, |
285 /* Count nondummy row groups. Should get same answer for each component, |
286 * so we need only do it once. |
286 * so we need only do it once. |
355 return; /* suspension forced, can do nothing more */ |
355 return; /* suspension forced, can do nothing more */ |
356 main->buffer_full = TRUE; /* OK, we have an iMCU row to work with */ |
356 main->buffer_full = TRUE; /* OK, we have an iMCU row to work with */ |
357 } |
357 } |
358 |
358 |
359 /* There are always min_DCT_scaled_size row groups in an iMCU row. */ |
359 /* There are always min_DCT_scaled_size row groups in an iMCU row. */ |
360 rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size; |
360 rowgroups_avail = (JDIMENSION) cinfo->min_DCT_v_scaled_size; |
361 /* Note: at the bottom of the image, we may pass extra garbage row groups |
361 /* Note: at the bottom of the image, we may pass extra garbage row groups |
362 * to the postprocessor. The postprocessor has to check for bottom |
362 * to the postprocessor. The postprocessor has to check for bottom |
363 * of image anyway (at row resolution), so no point in us doing it too. |
363 * of image anyway (at row resolution), so no point in us doing it too. |
364 */ |
364 */ |
365 |
365 |
415 return; /* Postprocessor exactly filled output buf */ |
415 return; /* Postprocessor exactly filled output buf */ |
416 /*FALLTHROUGH*/ |
416 /*FALLTHROUGH*/ |
417 case CTX_PREPARE_FOR_IMCU: |
417 case CTX_PREPARE_FOR_IMCU: |
418 /* Prepare to process first M-1 row groups of this iMCU row */ |
418 /* Prepare to process first M-1 row groups of this iMCU row */ |
419 main->rowgroup_ctr = 0; |
419 main->rowgroup_ctr = 0; |
420 main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1); |
420 main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_v_scaled_size - 1); |
421 /* Check for bottom of image: if so, tweak pointers to "duplicate" |
421 /* Check for bottom of image: if so, tweak pointers to "duplicate" |
422 * the last sample row, and adjust rowgroups_avail to ignore padding rows. |
422 * the last sample row, and adjust rowgroups_avail to ignore padding rows. |
423 */ |
423 */ |
424 if (main->iMCU_row_ctr == cinfo->total_iMCU_rows) |
424 if (main->iMCU_row_ctr == cinfo->total_iMCU_rows) |
425 set_bottom_pointers(cinfo); |
425 set_bottom_pointers(cinfo); |
438 /* Prepare to load new iMCU row using other xbuffer list */ |
438 /* Prepare to load new iMCU row using other xbuffer list */ |
439 main->whichptr ^= 1; /* 0=>1 or 1=>0 */ |
439 main->whichptr ^= 1; /* 0=>1 or 1=>0 */ |
440 main->buffer_full = FALSE; |
440 main->buffer_full = FALSE; |
441 /* Still need to process last row group of this iMCU row, */ |
441 /* Still need to process last row group of this iMCU row, */ |
442 /* which is saved at index M+1 of the other xbuffer */ |
442 /* which is saved at index M+1 of the other xbuffer */ |
443 main->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1); |
443 main->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_v_scaled_size + 1); |
444 main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2); |
444 main->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_v_scaled_size + 2); |
445 main->context_state = CTX_POSTPONED_ROW; |
445 main->context_state = CTX_POSTPONED_ROW; |
446 } |
446 } |
447 } |
447 } |
448 |
448 |
449 |
449 |
490 |
490 |
491 /* Allocate the workspace. |
491 /* Allocate the workspace. |
492 * ngroups is the number of row groups we need. |
492 * ngroups is the number of row groups we need. |
493 */ |
493 */ |
494 if (cinfo->upsample->need_context_rows) { |
494 if (cinfo->upsample->need_context_rows) { |
495 if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */ |
495 if (cinfo->min_DCT_v_scaled_size < 2) /* unsupported, see comments above */ |
496 ERREXIT(cinfo, JERR_NOTIMPL); |
496 ERREXIT(cinfo, JERR_NOTIMPL); |
497 alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */ |
497 alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */ |
498 ngroups = cinfo->min_DCT_scaled_size + 2; |
498 ngroups = cinfo->min_DCT_v_scaled_size + 2; |
499 } else { |
499 } else { |
500 ngroups = cinfo->min_DCT_scaled_size; |
500 ngroups = cinfo->min_DCT_v_scaled_size; |
501 } |
501 } |
502 |
502 |
503 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
503 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
504 ci++, compptr++) { |
504 ci++, compptr++) { |
505 rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) / |
505 rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) / |
506 cinfo->min_DCT_scaled_size; /* height of a row group of component */ |
506 cinfo->min_DCT_v_scaled_size; /* height of a row group of component */ |
507 main->buffer[ci] = (*cinfo->mem->alloc_sarray) |
507 main->buffer[ci] = (*cinfo->mem->alloc_sarray) |
508 ((j_common_ptr) cinfo, JPOOL_IMAGE, |
508 ((j_common_ptr) cinfo, JPOOL_IMAGE, |
509 compptr->width_in_blocks * compptr->DCT_scaled_size, |
509 compptr->width_in_blocks * compptr->DCT_h_scaled_size, |
510 (JDIMENSION) (rgroup * ngroups)); |
510 (JDIMENSION) (rgroup * ngroups)); |
511 } |
511 } |
512 } |
512 } |