147 JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; |
147 JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; |
148 JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
148 JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
149 int blkn, bi, ci, yindex, yoffset, blockcnt; |
149 int blkn, bi, ci, yindex, yoffset, blockcnt; |
150 JDIMENSION ypos, xpos; |
150 JDIMENSION ypos, xpos; |
151 jpeg_component_info *compptr; |
151 jpeg_component_info *compptr; |
|
152 forward_DCT_ptr forward_DCT; |
152 |
153 |
153 /* Loop to write as much as one whole iMCU row */ |
154 /* Loop to write as much as one whole iMCU row */ |
154 for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; |
155 for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; |
155 yoffset++) { |
156 yoffset++) { |
156 for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col; |
157 for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col; |
165 * block's DC value. (Thanks to Thomas Kinsman for this idea.) |
166 * block's DC value. (Thanks to Thomas Kinsman for this idea.) |
166 */ |
167 */ |
167 blkn = 0; |
168 blkn = 0; |
168 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
169 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
169 compptr = cinfo->cur_comp_info[ci]; |
170 compptr = cinfo->cur_comp_info[ci]; |
|
171 forward_DCT = cinfo->fdct->forward_DCT[compptr->component_index]; |
170 blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width |
172 blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width |
171 : compptr->last_col_width; |
173 : compptr->last_col_width; |
172 xpos = MCU_col_num * compptr->MCU_sample_width; |
174 xpos = MCU_col_num * compptr->MCU_sample_width; |
173 ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */ |
175 ypos = yoffset * compptr->DCT_v_scaled_size; |
|
176 /* ypos == (yoffset+yindex) * DCTSIZE */ |
174 for (yindex = 0; yindex < compptr->MCU_height; yindex++) { |
177 for (yindex = 0; yindex < compptr->MCU_height; yindex++) { |
175 if (coef->iMCU_row_num < last_iMCU_row || |
178 if (coef->iMCU_row_num < last_iMCU_row || |
176 yoffset+yindex < compptr->last_row_height) { |
179 yoffset+yindex < compptr->last_row_height) { |
177 (*cinfo->fdct->forward_DCT) (cinfo, compptr, |
180 (*forward_DCT) (cinfo, compptr, |
178 input_buf[compptr->component_index], |
181 input_buf[compptr->component_index], |
179 coef->MCU_buffer[blkn], |
182 coef->MCU_buffer[blkn], |
180 ypos, xpos, (JDIMENSION) blockcnt); |
183 ypos, xpos, (JDIMENSION) blockcnt); |
181 if (blockcnt < compptr->MCU_width) { |
184 if (blockcnt < compptr->MCU_width) { |
182 /* Create some dummy blocks at the right edge of the image. */ |
185 /* Create some dummy blocks at the right edge of the image. */ |
183 jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt], |
186 jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt], |
184 (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK)); |
187 (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK)); |
185 for (bi = blockcnt; bi < compptr->MCU_width; bi++) { |
188 for (bi = blockcnt; bi < compptr->MCU_width; bi++) { |
193 for (bi = 0; bi < compptr->MCU_width; bi++) { |
196 for (bi = 0; bi < compptr->MCU_width; bi++) { |
194 coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0]; |
197 coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0]; |
195 } |
198 } |
196 } |
199 } |
197 blkn += compptr->MCU_width; |
200 blkn += compptr->MCU_width; |
198 ypos += DCTSIZE; |
201 ypos += compptr->DCT_v_scaled_size; |
199 } |
202 } |
200 } |
203 } |
201 /* Try to write the MCU. In event of a suspension failure, we will |
204 /* Try to write the MCU. In event of a suspension failure, we will |
202 * re-DCT the MCU on restart (a bit inefficient, could be fixed...) |
205 * re-DCT the MCU on restart (a bit inefficient, could be fixed...) |
203 */ |
206 */ |
250 int bi, ci, h_samp_factor, block_row, block_rows, ndummy; |
253 int bi, ci, h_samp_factor, block_row, block_rows, ndummy; |
251 JCOEF lastDC; |
254 JCOEF lastDC; |
252 jpeg_component_info *compptr; |
255 jpeg_component_info *compptr; |
253 JBLOCKARRAY buffer; |
256 JBLOCKARRAY buffer; |
254 JBLOCKROW thisblockrow, lastblockrow; |
257 JBLOCKROW thisblockrow, lastblockrow; |
|
258 forward_DCT_ptr forward_DCT; |
255 |
259 |
256 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
260 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
257 ci++, compptr++) { |
261 ci++, compptr++) { |
258 /* Align the virtual buffer for this component. */ |
262 /* Align the virtual buffer for this component. */ |
259 buffer = (*cinfo->mem->access_virt_barray) |
263 buffer = (*cinfo->mem->access_virt_barray) |
272 h_samp_factor = compptr->h_samp_factor; |
276 h_samp_factor = compptr->h_samp_factor; |
273 /* Count number of dummy blocks to be added at the right margin. */ |
277 /* Count number of dummy blocks to be added at the right margin. */ |
274 ndummy = (int) (blocks_across % h_samp_factor); |
278 ndummy = (int) (blocks_across % h_samp_factor); |
275 if (ndummy > 0) |
279 if (ndummy > 0) |
276 ndummy = h_samp_factor - ndummy; |
280 ndummy = h_samp_factor - ndummy; |
|
281 forward_DCT = cinfo->fdct->forward_DCT[ci]; |
277 /* Perform DCT for all non-dummy blocks in this iMCU row. Each call |
282 /* Perform DCT for all non-dummy blocks in this iMCU row. Each call |
278 * on forward_DCT processes a complete horizontal row of DCT blocks. |
283 * on forward_DCT processes a complete horizontal row of DCT blocks. |
279 */ |
284 */ |
280 for (block_row = 0; block_row < block_rows; block_row++) { |
285 for (block_row = 0; block_row < block_rows; block_row++) { |
281 thisblockrow = buffer[block_row]; |
286 thisblockrow = buffer[block_row]; |
282 (*cinfo->fdct->forward_DCT) (cinfo, compptr, |
287 (*forward_DCT) (cinfo, compptr, input_buf[ci], thisblockrow, |
283 input_buf[ci], thisblockrow, |
288 (JDIMENSION) (block_row * compptr->DCT_v_scaled_size), |
284 (JDIMENSION) (block_row * DCTSIZE), |
289 (JDIMENSION) 0, blocks_across); |
285 (JDIMENSION) 0, blocks_across); |
|
286 if (ndummy > 0) { |
290 if (ndummy > 0) { |
287 /* Create dummy blocks at the right edge of the image. */ |
291 /* Create dummy blocks at the right edge of the image. */ |
288 thisblockrow += blocks_across; /* => first dummy block */ |
292 thisblockrow += blocks_across; /* => first dummy block */ |
289 jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK)); |
293 jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK)); |
290 lastDC = thisblockrow[-1][0]; |
294 lastDC = thisblockrow[-1][0]; |