OLD | NEW |
1 /* | 1 /* |
2 * jdcoefct.c | 2 * jdcoefct.c |
3 * | 3 * |
4 * This file was part of the Independent JPEG Group's software: | 4 * This file was part of the Independent JPEG Group's software: |
5 * Copyright (C) 1994-1997, Thomas G. Lane. | 5 * Copyright (C) 1994-1997, Thomas G. Lane. |
6 * libjpeg-turbo Modifications: | 6 * libjpeg-turbo Modifications: |
7 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB | 7 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
8 * Copyright (C) 2010, D. R. Commander. | 8 * Copyright (C) 2010, 2015-2016, D. R. Commander. |
9 * For conditions of distribution and use, see the accompanying README file. | 9 * Copyright (C) 2015, Google, Inc. |
| 10 * For conditions of distribution and use, see the accompanying README.ijg |
| 11 * file. |
10 * | 12 * |
11 * This file contains the coefficient buffer controller for decompression. | 13 * This file contains the coefficient buffer controller for decompression. |
12 * This controller is the top level of the JPEG decompressor proper. | 14 * This controller is the top level of the JPEG decompressor proper. |
13 * The coefficient buffer lies between entropy decoding and inverse-DCT steps. | 15 * The coefficient buffer lies between entropy decoding and inverse-DCT steps. |
14 * | 16 * |
15 * In buffered-image mode, this controller is the interface between | 17 * In buffered-image mode, this controller is the interface between |
16 * input-oriented processing and output-oriented processing. | 18 * input-oriented processing and output-oriented processing. |
17 * Also, the input side (only) is used when reading a file for transcoding. | 19 * Also, the input side (only) is used when reading a file for transcoding. |
18 */ | 20 */ |
19 | 21 |
| 22 #include "jinclude.h" |
20 #include "jdcoefct.h" | 23 #include "jdcoefct.h" |
21 #include "jpegcomp.h" | 24 #include "jpegcomp.h" |
22 | 25 |
23 | 26 |
24 /* Forward declarations */ | 27 /* Forward declarations */ |
25 METHODDEF(int) decompress_onepass | 28 METHODDEF(int) decompress_onepass |
26 » JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf)); | 29 (j_decompress_ptr cinfo, JSAMPIMAGE output_buf); |
27 #ifdef D_MULTISCAN_FILES_SUPPORTED | 30 #ifdef D_MULTISCAN_FILES_SUPPORTED |
28 METHODDEF(int) decompress_data | 31 METHODDEF(int) decompress_data |
29 » JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf)); | 32 (j_decompress_ptr cinfo, JSAMPIMAGE output_buf); |
30 #endif | 33 #endif |
31 #ifdef BLOCK_SMOOTHING_SUPPORTED | 34 #ifdef BLOCK_SMOOTHING_SUPPORTED |
32 LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo)); | 35 LOCAL(boolean) smoothing_ok (j_decompress_ptr cinfo); |
33 METHODDEF(int) decompress_smooth_data | 36 METHODDEF(int) decompress_smooth_data |
34 » JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf)); | 37 (j_decompress_ptr cinfo, JSAMPIMAGE output_buf); |
35 #endif | 38 #endif |
36 | 39 |
37 | 40 |
38 /* | 41 /* |
39 * Initialize for an input processing pass. | 42 * Initialize for an input processing pass. |
40 */ | 43 */ |
41 | 44 |
42 METHODDEF(void) | 45 METHODDEF(void) |
43 start_input_pass (j_decompress_ptr cinfo) | 46 start_input_pass (j_decompress_ptr cinfo) |
44 { | 47 { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. | 79 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. |
77 * | 80 * |
78 * NB: output_buf contains a plane for each component in image, | 81 * NB: output_buf contains a plane for each component in image, |
79 * which we index according to the component's SOF position. | 82 * which we index according to the component's SOF position. |
80 */ | 83 */ |
81 | 84 |
82 METHODDEF(int) | 85 METHODDEF(int) |
83 decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) | 86 decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) |
84 { | 87 { |
85 my_coef_ptr coef = (my_coef_ptr) cinfo->coef; | 88 my_coef_ptr coef = (my_coef_ptr) cinfo->coef; |
86 JDIMENSION MCU_col_num;» /* index of current MCU within row */ | 89 JDIMENSION MCU_col_num; /* index of current MCU within row */ |
87 JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; | 90 JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; |
88 JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 91 JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
89 int blkn, ci, xindex, yindex, yoffset, useful_width; | 92 int blkn, ci, xindex, yindex, yoffset, useful_width; |
90 JSAMPARRAY output_ptr; | 93 JSAMPARRAY output_ptr; |
91 JDIMENSION start_col, output_col; | 94 JDIMENSION start_col, output_col; |
92 jpeg_component_info *compptr; | 95 jpeg_component_info *compptr; |
93 inverse_DCT_method_ptr inverse_DCT; | 96 inverse_DCT_method_ptr inverse_DCT; |
94 | 97 |
95 /* Loop to process as much as one whole iMCU row */ | 98 /* Loop to process as much as one whole iMCU row */ |
96 for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; | 99 for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; |
97 yoffset++) { | 100 yoffset++) { |
98 for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col; | 101 for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col; |
99 » MCU_col_num++) { | 102 MCU_col_num++) { |
100 /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */ | 103 /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */ |
101 jzero_far((void FAR *) coef->MCU_buffer[0], | 104 jzero_far((void *) coef->MCU_buffer[0], |
102 » » (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK))); | 105 (size_t) (cinfo->blocks_in_MCU * sizeof(JBLOCK))); |
103 if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { | 106 if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { |
104 » /* Suspension forced; update state counters and exit */ | 107 /* Suspension forced; update state counters and exit */ |
105 » coef->MCU_vert_offset = yoffset; | 108 coef->MCU_vert_offset = yoffset; |
106 » coef->MCU_ctr = MCU_col_num; | 109 coef->MCU_ctr = MCU_col_num; |
107 » return JPEG_SUSPENDED; | 110 return JPEG_SUSPENDED; |
108 } | 111 } |
109 /* Determine where data should go in output_buf and do the IDCT thing. | 112 |
110 * We skip dummy blocks at the right and bottom edges (but blkn gets | 113 /* Only perform the IDCT on blocks that are contained within the desired |
111 * incremented past them!). Note the inner loop relies on having | 114 * cropping region. |
112 * allocated the MCU_buffer[] blocks sequentially. | |
113 */ | 115 */ |
114 blkn = 0;»» » /* index of current DCT block within MCU */ | 116 if (MCU_col_num >= cinfo->master->first_iMCU_col && |
115 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 117 MCU_col_num <= cinfo->master->last_iMCU_col) { |
116 » compptr = cinfo->cur_comp_info[ci]; | 118 /* Determine where data should go in output_buf and do the IDCT thing. |
117 » /* Don't bother to IDCT an uninteresting component. */ | 119 * We skip dummy blocks at the right and bottom edges (but blkn gets |
118 » if (! compptr->component_needed) { | 120 * incremented past them!). Note the inner loop relies on having |
119 » blkn += compptr->MCU_blocks; | 121 * allocated the MCU_buffer[] blocks sequentially. |
120 » continue; | 122 */ |
121 » } | 123 blkn = 0; /* index of current DCT block within MCU */ |
122 » inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index]; | 124 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
123 » useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width | 125 compptr = cinfo->cur_comp_info[ci]; |
124 » » » » » » : compptr->last_col_width; | 126 /* Don't bother to IDCT an uninteresting component. */ |
125 » output_ptr = output_buf[compptr->component_index] + | 127 if (! compptr->component_needed) { |
126 » yoffset * compptr->_DCT_scaled_size; | 128 blkn += compptr->MCU_blocks; |
127 » start_col = MCU_col_num * compptr->MCU_sample_width; | 129 continue; |
128 » for (yindex = 0; yindex < compptr->MCU_height; yindex++) { | 130 } |
129 » if (cinfo->input_iMCU_row < last_iMCU_row || | 131 inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index]; |
130 » yoffset+yindex < compptr->last_row_height) { | 132 useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width |
131 » output_col = start_col; | 133 : compptr->last_col_width; |
132 » for (xindex = 0; xindex < useful_width; xindex++) { | 134 output_ptr = output_buf[compptr->component_index] + |
133 » (*inverse_DCT) (cinfo, compptr, | 135 yoffset * compptr->_DCT_scaled_size; |
134 » » » (JCOEFPTR) coef->MCU_buffer[blkn+xindex], | 136 start_col = (MCU_col_num - cinfo->master->first_iMCU_col) * |
135 » » » output_ptr, output_col); | 137 compptr->MCU_sample_width; |
136 » output_col += compptr->_DCT_scaled_size; | 138 for (yindex = 0; yindex < compptr->MCU_height; yindex++) { |
137 » } | 139 if (cinfo->input_iMCU_row < last_iMCU_row || |
138 » } | 140 yoffset+yindex < compptr->last_row_height) { |
139 » blkn += compptr->MCU_width; | 141 output_col = start_col; |
140 » output_ptr += compptr->_DCT_scaled_size; | 142 for (xindex = 0; xindex < useful_width; xindex++) { |
141 » } | 143 (*inverse_DCT) (cinfo, compptr, |
| 144 (JCOEFPTR) coef->MCU_buffer[blkn+xindex], |
| 145 output_ptr, output_col); |
| 146 output_col += compptr->_DCT_scaled_size; |
| 147 } |
| 148 } |
| 149 blkn += compptr->MCU_width; |
| 150 output_ptr += compptr->_DCT_scaled_size; |
| 151 } |
| 152 } |
142 } | 153 } |
143 } | 154 } |
144 /* Completed an MCU row, but perhaps not an iMCU row */ | 155 /* Completed an MCU row, but perhaps not an iMCU row */ |
145 coef->MCU_ctr = 0; | 156 coef->MCU_ctr = 0; |
146 } | 157 } |
147 /* Completed the iMCU row, advance counters for next one */ | 158 /* Completed the iMCU row, advance counters for next one */ |
148 cinfo->output_iMCU_row++; | 159 cinfo->output_iMCU_row++; |
149 if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { | 160 if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { |
150 start_iMCU_row(cinfo); | 161 start_iMCU_row(cinfo); |
151 return JPEG_ROW_COMPLETED; | 162 return JPEG_ROW_COMPLETED; |
152 } | 163 } |
153 /* Completed the scan */ | 164 /* Completed the scan */ |
154 (*cinfo->inputctl->finish_input_pass) (cinfo); | 165 (*cinfo->inputctl->finish_input_pass) (cinfo); |
155 return JPEG_SCAN_COMPLETED; | 166 return JPEG_SCAN_COMPLETED; |
156 } | 167 } |
157 | 168 |
158 | 169 |
159 /* | 170 /* |
160 * Dummy consume-input routine for single-pass operation. | 171 * Dummy consume-input routine for single-pass operation. |
161 */ | 172 */ |
162 | 173 |
163 METHODDEF(int) | 174 METHODDEF(int) |
164 dummy_consume_data (j_decompress_ptr cinfo) | 175 dummy_consume_data (j_decompress_ptr cinfo) |
165 { | 176 { |
166 return JPEG_SUSPENDED;» /* Always indicate nothing was done */ | 177 return JPEG_SUSPENDED; /* Always indicate nothing was done */ |
167 } | 178 } |
168 | 179 |
169 | 180 |
170 #ifdef D_MULTISCAN_FILES_SUPPORTED | 181 #ifdef D_MULTISCAN_FILES_SUPPORTED |
171 | 182 |
172 /* | 183 /* |
173 * Consume input data and store it in the full-image coefficient buffer. | 184 * Consume input data and store it in the full-image coefficient buffer. |
174 * We read as much as one fully interleaved MCU row ("iMCU" row) per call, | 185 * We read as much as one fully interleaved MCU row ("iMCU" row) per call, |
175 * ie, v_samp_factor block rows for each component in the scan. | 186 * ie, v_samp_factor block rows for each component in the scan. |
176 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. | 187 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. |
177 */ | 188 */ |
178 | 189 |
179 METHODDEF(int) | 190 METHODDEF(int) |
180 consume_data (j_decompress_ptr cinfo) | 191 consume_data (j_decompress_ptr cinfo) |
181 { | 192 { |
182 my_coef_ptr coef = (my_coef_ptr) cinfo->coef; | 193 my_coef_ptr coef = (my_coef_ptr) cinfo->coef; |
183 JDIMENSION MCU_col_num;» /* index of current MCU within row */ | 194 JDIMENSION MCU_col_num; /* index of current MCU within row */ |
184 int blkn, ci, xindex, yindex, yoffset; | 195 int blkn, ci, xindex, yindex, yoffset; |
185 JDIMENSION start_col; | 196 JDIMENSION start_col; |
186 JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; | 197 JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; |
187 JBLOCKROW buffer_ptr; | 198 JBLOCKROW buffer_ptr; |
188 jpeg_component_info *compptr; | 199 jpeg_component_info *compptr; |
189 | 200 |
190 /* Align the virtual buffers for the components used in this scan. */ | 201 /* Align the virtual buffers for the components used in this scan. */ |
191 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 202 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
192 compptr = cinfo->cur_comp_info[ci]; | 203 compptr = cinfo->cur_comp_info[ci]; |
193 buffer[ci] = (*cinfo->mem->access_virt_barray) | 204 buffer[ci] = (*cinfo->mem->access_virt_barray) |
194 ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index], | 205 ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index], |
195 cinfo->input_iMCU_row * compptr->v_samp_factor, | 206 cinfo->input_iMCU_row * compptr->v_samp_factor, |
196 (JDIMENSION) compptr->v_samp_factor, TRUE); | 207 (JDIMENSION) compptr->v_samp_factor, TRUE); |
197 /* Note: entropy decoder expects buffer to be zeroed, | 208 /* Note: entropy decoder expects buffer to be zeroed, |
198 * but this is handled automatically by the memory manager | 209 * but this is handled automatically by the memory manager |
199 * because we requested a pre-zeroed array. | 210 * because we requested a pre-zeroed array. |
200 */ | 211 */ |
201 } | 212 } |
202 | 213 |
203 /* Loop to process one whole iMCU row */ | 214 /* Loop to process one whole iMCU row */ |
204 for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; | 215 for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; |
205 yoffset++) { | 216 yoffset++) { |
206 for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row; | 217 for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row; |
207 » MCU_col_num++) { | 218 MCU_col_num++) { |
208 /* Construct list of pointers to DCT blocks belonging to this MCU */ | 219 /* Construct list of pointers to DCT blocks belonging to this MCU */ |
209 blkn = 0;»» » /* index of current DCT block within MCU */ | 220 blkn = 0; /* index of current DCT block within MCU */ |
210 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 221 for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
211 » compptr = cinfo->cur_comp_info[ci]; | 222 compptr = cinfo->cur_comp_info[ci]; |
212 » start_col = MCU_col_num * compptr->MCU_width; | 223 start_col = MCU_col_num * compptr->MCU_width; |
213 » for (yindex = 0; yindex < compptr->MCU_height; yindex++) { | 224 for (yindex = 0; yindex < compptr->MCU_height; yindex++) { |
214 » buffer_ptr = buffer[ci][yindex+yoffset] + start_col; | 225 buffer_ptr = buffer[ci][yindex+yoffset] + start_col; |
215 » for (xindex = 0; xindex < compptr->MCU_width; xindex++) { | 226 for (xindex = 0; xindex < compptr->MCU_width; xindex++) { |
216 » coef->MCU_buffer[blkn++] = buffer_ptr++; | 227 coef->MCU_buffer[blkn++] = buffer_ptr++; |
217 » } | 228 } |
218 » } | 229 } |
219 } | 230 } |
220 /* Try to fetch the MCU. */ | 231 /* Try to fetch the MCU. */ |
221 if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { | 232 if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { |
222 » /* Suspension forced; update state counters and exit */ | 233 /* Suspension forced; update state counters and exit */ |
223 » coef->MCU_vert_offset = yoffset; | 234 coef->MCU_vert_offset = yoffset; |
224 » coef->MCU_ctr = MCU_col_num; | 235 coef->MCU_ctr = MCU_col_num; |
225 » return JPEG_SUSPENDED; | 236 return JPEG_SUSPENDED; |
226 } | 237 } |
227 } | 238 } |
228 /* Completed an MCU row, but perhaps not an iMCU row */ | 239 /* Completed an MCU row, but perhaps not an iMCU row */ |
229 coef->MCU_ctr = 0; | 240 coef->MCU_ctr = 0; |
230 } | 241 } |
231 /* Completed the iMCU row, advance counters for next one */ | 242 /* Completed the iMCU row, advance counters for next one */ |
232 if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { | 243 if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { |
233 start_iMCU_row(cinfo); | 244 start_iMCU_row(cinfo); |
234 return JPEG_ROW_COMPLETED; | 245 return JPEG_ROW_COMPLETED; |
235 } | 246 } |
(...skipping 20 matching lines...) Expand all Loading... |
256 int ci, block_row, block_rows; | 267 int ci, block_row, block_rows; |
257 JBLOCKARRAY buffer; | 268 JBLOCKARRAY buffer; |
258 JBLOCKROW buffer_ptr; | 269 JBLOCKROW buffer_ptr; |
259 JSAMPARRAY output_ptr; | 270 JSAMPARRAY output_ptr; |
260 JDIMENSION output_col; | 271 JDIMENSION output_col; |
261 jpeg_component_info *compptr; | 272 jpeg_component_info *compptr; |
262 inverse_DCT_method_ptr inverse_DCT; | 273 inverse_DCT_method_ptr inverse_DCT; |
263 | 274 |
264 /* Force some input to be done if we are getting ahead of the input. */ | 275 /* Force some input to be done if we are getting ahead of the input. */ |
265 while (cinfo->input_scan_number < cinfo->output_scan_number || | 276 while (cinfo->input_scan_number < cinfo->output_scan_number || |
266 » (cinfo->input_scan_number == cinfo->output_scan_number && | 277 (cinfo->input_scan_number == cinfo->output_scan_number && |
267 » cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { | 278 cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { |
268 if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED) | 279 if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED) |
269 return JPEG_SUSPENDED; | 280 return JPEG_SUSPENDED; |
270 } | 281 } |
271 | 282 |
272 /* OK, output from the virtual arrays. */ | 283 /* OK, output from the virtual arrays. */ |
273 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 284 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
274 ci++, compptr++) { | 285 ci++, compptr++) { |
275 /* Don't bother to IDCT an uninteresting component. */ | 286 /* Don't bother to IDCT an uninteresting component. */ |
276 if (! compptr->component_needed) | 287 if (! compptr->component_needed) |
277 continue; | 288 continue; |
278 /* Align the virtual buffer for this component. */ | 289 /* Align the virtual buffer for this component. */ |
279 buffer = (*cinfo->mem->access_virt_barray) | 290 buffer = (*cinfo->mem->access_virt_barray) |
280 ((j_common_ptr) cinfo, coef->whole_image[ci], | 291 ((j_common_ptr) cinfo, coef->whole_image[ci], |
281 cinfo->output_iMCU_row * compptr->v_samp_factor, | 292 cinfo->output_iMCU_row * compptr->v_samp_factor, |
282 (JDIMENSION) compptr->v_samp_factor, FALSE); | 293 (JDIMENSION) compptr->v_samp_factor, FALSE); |
283 /* Count non-dummy DCT block rows in this iMCU row. */ | 294 /* Count non-dummy DCT block rows in this iMCU row. */ |
284 if (cinfo->output_iMCU_row < last_iMCU_row) | 295 if (cinfo->output_iMCU_row < last_iMCU_row) |
285 block_rows = compptr->v_samp_factor; | 296 block_rows = compptr->v_samp_factor; |
286 else { | 297 else { |
287 /* NB: can't use last_row_height here; it is input-side-dependent! */ | 298 /* NB: can't use last_row_height here; it is input-side-dependent! */ |
288 block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); | 299 block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); |
289 if (block_rows == 0) block_rows = compptr->v_samp_factor; | 300 if (block_rows == 0) block_rows = compptr->v_samp_factor; |
290 } | 301 } |
291 inverse_DCT = cinfo->idct->inverse_DCT[ci]; | 302 inverse_DCT = cinfo->idct->inverse_DCT[ci]; |
292 output_ptr = output_buf[ci]; | 303 output_ptr = output_buf[ci]; |
293 /* Loop over all DCT blocks to be processed. */ | 304 /* Loop over all DCT blocks to be processed. */ |
294 for (block_row = 0; block_row < block_rows; block_row++) { | 305 for (block_row = 0; block_row < block_rows; block_row++) { |
295 buffer_ptr = buffer[block_row]; | 306 buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci]; |
296 output_col = 0; | 307 output_col = 0; |
297 for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) { | 308 for (block_num = cinfo->master->first_MCU_col[ci]; |
298 » (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr, | 309 block_num <= cinfo->master->last_MCU_col[ci]; block_num++) { |
299 » » » output_ptr, output_col); | 310 (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr, |
300 » buffer_ptr++; | 311 output_ptr, output_col); |
301 » output_col += compptr->_DCT_scaled_size; | 312 buffer_ptr++; |
| 313 output_col += compptr->_DCT_scaled_size; |
302 } | 314 } |
303 output_ptr += compptr->_DCT_scaled_size; | 315 output_ptr += compptr->_DCT_scaled_size; |
304 } | 316 } |
305 } | 317 } |
306 | 318 |
307 if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) | 319 if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) |
308 return JPEG_ROW_COMPLETED; | 320 return JPEG_ROW_COMPLETED; |
309 return JPEG_SCAN_COMPLETED; | 321 return JPEG_SCAN_COMPLETED; |
310 } | 322 } |
311 | 323 |
(...skipping 25 matching lines...) Expand all Loading... |
337 * more accurately than they really are. | 349 * more accurately than they really are. |
338 */ | 350 */ |
339 | 351 |
340 LOCAL(boolean) | 352 LOCAL(boolean) |
341 smoothing_ok (j_decompress_ptr cinfo) | 353 smoothing_ok (j_decompress_ptr cinfo) |
342 { | 354 { |
343 my_coef_ptr coef = (my_coef_ptr) cinfo->coef; | 355 my_coef_ptr coef = (my_coef_ptr) cinfo->coef; |
344 boolean smoothing_useful = FALSE; | 356 boolean smoothing_useful = FALSE; |
345 int ci, coefi; | 357 int ci, coefi; |
346 jpeg_component_info *compptr; | 358 jpeg_component_info *compptr; |
347 JQUANT_TBL * qtable; | 359 JQUANT_TBL *qtable; |
348 int * coef_bits; | 360 int *coef_bits; |
349 int * coef_bits_latch; | 361 int *coef_bits_latch; |
350 | 362 |
351 if (! cinfo->progressive_mode || cinfo->coef_bits == NULL) | 363 if (! cinfo->progressive_mode || cinfo->coef_bits == NULL) |
352 return FALSE; | 364 return FALSE; |
353 | 365 |
354 /* Allocate latch area if not already done */ | 366 /* Allocate latch area if not already done */ |
355 if (coef->coef_bits_latch == NULL) | 367 if (coef->coef_bits_latch == NULL) |
356 coef->coef_bits_latch = (int *) | 368 coef->coef_bits_latch = (int *) |
357 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 369 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
358 » » » » cinfo->num_components * | 370 cinfo->num_components * |
359 » » » » (SAVED_COEFS * SIZEOF(int))); | 371 (SAVED_COEFS * sizeof(int))); |
360 coef_bits_latch = coef->coef_bits_latch; | 372 coef_bits_latch = coef->coef_bits_latch; |
361 | 373 |
362 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 374 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
363 ci++, compptr++) { | 375 ci++, compptr++) { |
364 /* All components' quantization values must already be latched. */ | 376 /* All components' quantization values must already be latched. */ |
365 if ((qtable = compptr->quant_table) == NULL) | 377 if ((qtable = compptr->quant_table) == NULL) |
366 return FALSE; | 378 return FALSE; |
367 /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */ | 379 /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */ |
368 if (qtable->quantval[0] == 0 || | 380 if (qtable->quantval[0] == 0 || |
369 » qtable->quantval[Q01_POS] == 0 || | 381 qtable->quantval[Q01_POS] == 0 || |
370 » qtable->quantval[Q10_POS] == 0 || | 382 qtable->quantval[Q10_POS] == 0 || |
371 » qtable->quantval[Q20_POS] == 0 || | 383 qtable->quantval[Q20_POS] == 0 || |
372 » qtable->quantval[Q11_POS] == 0 || | 384 qtable->quantval[Q11_POS] == 0 || |
373 » qtable->quantval[Q02_POS] == 0) | 385 qtable->quantval[Q02_POS] == 0) |
374 return FALSE; | 386 return FALSE; |
375 /* DC values must be at least partly known for all components. */ | 387 /* DC values must be at least partly known for all components. */ |
376 coef_bits = cinfo->coef_bits[ci]; | 388 coef_bits = cinfo->coef_bits[ci]; |
377 if (coef_bits[0] < 0) | 389 if (coef_bits[0] < 0) |
378 return FALSE; | 390 return FALSE; |
379 /* Block smoothing is helpful if some AC coefficients remain inaccurate. */ | 391 /* Block smoothing is helpful if some AC coefficients remain inaccurate. */ |
380 for (coefi = 1; coefi <= 5; coefi++) { | 392 for (coefi = 1; coefi <= 5; coefi++) { |
381 coef_bits_latch[coefi] = coef_bits[coefi]; | 393 coef_bits_latch[coefi] = coef_bits[coefi]; |
382 if (coef_bits[coefi] != 0) | 394 if (coef_bits[coefi] != 0) |
383 » smoothing_useful = TRUE; | 395 smoothing_useful = TRUE; |
384 } | 396 } |
385 coef_bits_latch += SAVED_COEFS; | 397 coef_bits_latch += SAVED_COEFS; |
386 } | 398 } |
387 | 399 |
388 return smoothing_useful; | 400 return smoothing_useful; |
389 } | 401 } |
390 | 402 |
391 | 403 |
392 /* | 404 /* |
393 * Variant of decompress_data for use when doing block smoothing. | 405 * Variant of decompress_data for use when doing block smoothing. |
394 */ | 406 */ |
395 | 407 |
396 METHODDEF(int) | 408 METHODDEF(int) |
397 decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) | 409 decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf) |
398 { | 410 { |
399 my_coef_ptr coef = (my_coef_ptr) cinfo->coef; | 411 my_coef_ptr coef = (my_coef_ptr) cinfo->coef; |
400 JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; | 412 JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
401 JDIMENSION block_num, last_block_column; | 413 JDIMENSION block_num, last_block_column; |
402 int ci, block_row, block_rows, access_rows; | 414 int ci, block_row, block_rows, access_rows; |
403 JBLOCKARRAY buffer; | 415 JBLOCKARRAY buffer; |
404 JBLOCKROW buffer_ptr, prev_block_row, next_block_row; | 416 JBLOCKROW buffer_ptr, prev_block_row, next_block_row; |
405 JSAMPARRAY output_ptr; | 417 JSAMPARRAY output_ptr; |
406 JDIMENSION output_col; | 418 JDIMENSION output_col; |
407 jpeg_component_info *compptr; | 419 jpeg_component_info *compptr; |
408 inverse_DCT_method_ptr inverse_DCT; | 420 inverse_DCT_method_ptr inverse_DCT; |
409 boolean first_row, last_row; | 421 boolean first_row, last_row; |
410 JCOEF * workspace; | 422 JCOEF *workspace; |
411 int *coef_bits; | 423 int *coef_bits; |
412 JQUANT_TBL *quanttbl; | 424 JQUANT_TBL *quanttbl; |
413 INT32 Q00,Q01,Q02,Q10,Q11,Q20, num; | 425 JLONG Q00,Q01,Q02,Q10,Q11,Q20, num; |
414 int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9; | 426 int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9; |
415 int Al, pred; | 427 int Al, pred; |
416 | 428 |
417 /* Keep a local variable to avoid looking it up more than once */ | 429 /* Keep a local variable to avoid looking it up more than once */ |
418 workspace = coef->workspace; | 430 workspace = coef->workspace; |
419 | 431 |
420 /* Force some input to be done if we are getting ahead of the input. */ | 432 /* Force some input to be done if we are getting ahead of the input. */ |
421 while (cinfo->input_scan_number <= cinfo->output_scan_number && | 433 while (cinfo->input_scan_number <= cinfo->output_scan_number && |
422 » ! cinfo->inputctl->eoi_reached) { | 434 ! cinfo->inputctl->eoi_reached) { |
423 if (cinfo->input_scan_number == cinfo->output_scan_number) { | 435 if (cinfo->input_scan_number == cinfo->output_scan_number) { |
424 /* If input is working on current scan, we ordinarily want it to | 436 /* If input is working on current scan, we ordinarily want it to |
425 * have completed the current row. But if input scan is DC, | 437 * have completed the current row. But if input scan is DC, |
426 * we want it to keep one row ahead so that next block row's DC | 438 * we want it to keep one row ahead so that next block row's DC |
427 * values are up to date. | 439 * values are up to date. |
428 */ | 440 */ |
429 JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0; | 441 JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0; |
430 if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta) | 442 if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta) |
431 » break; | 443 break; |
432 } | 444 } |
433 if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED) | 445 if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED) |
434 return JPEG_SUSPENDED; | 446 return JPEG_SUSPENDED; |
435 } | 447 } |
436 | 448 |
437 /* OK, output from the virtual arrays. */ | 449 /* OK, output from the virtual arrays. */ |
438 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 450 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
439 ci++, compptr++) { | 451 ci++, compptr++) { |
440 /* Don't bother to IDCT an uninteresting component. */ | 452 /* Don't bother to IDCT an uninteresting component. */ |
441 if (! compptr->component_needed) | 453 if (! compptr->component_needed) |
442 continue; | 454 continue; |
443 /* Count non-dummy DCT block rows in this iMCU row. */ | 455 /* Count non-dummy DCT block rows in this iMCU row. */ |
444 if (cinfo->output_iMCU_row < last_iMCU_row) { | 456 if (cinfo->output_iMCU_row < last_iMCU_row) { |
445 block_rows = compptr->v_samp_factor; | 457 block_rows = compptr->v_samp_factor; |
446 access_rows = block_rows * 2; /* this and next iMCU row */ | 458 access_rows = block_rows * 2; /* this and next iMCU row */ |
447 last_row = FALSE; | 459 last_row = FALSE; |
448 } else { | 460 } else { |
449 /* NB: can't use last_row_height here; it is input-side-dependent! */ | 461 /* NB: can't use last_row_height here; it is input-side-dependent! */ |
450 block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); | 462 block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor); |
451 if (block_rows == 0) block_rows = compptr->v_samp_factor; | 463 if (block_rows == 0) block_rows = compptr->v_samp_factor; |
452 access_rows = block_rows; /* this iMCU row only */ | 464 access_rows = block_rows; /* this iMCU row only */ |
453 last_row = TRUE; | 465 last_row = TRUE; |
454 } | 466 } |
455 /* Align the virtual buffer for this component. */ | 467 /* Align the virtual buffer for this component. */ |
456 if (cinfo->output_iMCU_row > 0) { | 468 if (cinfo->output_iMCU_row > 0) { |
457 access_rows += compptr->v_samp_factor; /* prior iMCU row too */ | 469 access_rows += compptr->v_samp_factor; /* prior iMCU row too */ |
458 buffer = (*cinfo->mem->access_virt_barray) | 470 buffer = (*cinfo->mem->access_virt_barray) |
459 » ((j_common_ptr) cinfo, coef->whole_image[ci], | 471 ((j_common_ptr) cinfo, coef->whole_image[ci], |
460 » (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor, | 472 (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor, |
461 » (JDIMENSION) access_rows, FALSE); | 473 (JDIMENSION) access_rows, FALSE); |
462 buffer += compptr->v_samp_factor;»/* point to current iMCU row */ | 474 buffer += compptr->v_samp_factor; /* point to current iMCU row */ |
463 first_row = FALSE; | 475 first_row = FALSE; |
464 } else { | 476 } else { |
465 buffer = (*cinfo->mem->access_virt_barray) | 477 buffer = (*cinfo->mem->access_virt_barray) |
466 » ((j_common_ptr) cinfo, coef->whole_image[ci], | 478 ((j_common_ptr) cinfo, coef->whole_image[ci], |
467 » (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE); | 479 (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE); |
468 first_row = TRUE; | 480 first_row = TRUE; |
469 } | 481 } |
470 /* Fetch component-dependent info */ | 482 /* Fetch component-dependent info */ |
471 coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS); | 483 coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS); |
472 quanttbl = compptr->quant_table; | 484 quanttbl = compptr->quant_table; |
473 Q00 = quanttbl->quantval[0]; | 485 Q00 = quanttbl->quantval[0]; |
474 Q01 = quanttbl->quantval[Q01_POS]; | 486 Q01 = quanttbl->quantval[Q01_POS]; |
475 Q10 = quanttbl->quantval[Q10_POS]; | 487 Q10 = quanttbl->quantval[Q10_POS]; |
476 Q20 = quanttbl->quantval[Q20_POS]; | 488 Q20 = quanttbl->quantval[Q20_POS]; |
477 Q11 = quanttbl->quantval[Q11_POS]; | 489 Q11 = quanttbl->quantval[Q11_POS]; |
478 Q02 = quanttbl->quantval[Q02_POS]; | 490 Q02 = quanttbl->quantval[Q02_POS]; |
479 inverse_DCT = cinfo->idct->inverse_DCT[ci]; | 491 inverse_DCT = cinfo->idct->inverse_DCT[ci]; |
480 output_ptr = output_buf[ci]; | 492 output_ptr = output_buf[ci]; |
481 /* Loop over all DCT blocks to be processed. */ | 493 /* Loop over all DCT blocks to be processed. */ |
482 for (block_row = 0; block_row < block_rows; block_row++) { | 494 for (block_row = 0; block_row < block_rows; block_row++) { |
483 buffer_ptr = buffer[block_row]; | 495 buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci]; |
484 if (first_row && block_row == 0) | 496 if (first_row && block_row == 0) |
485 » prev_block_row = buffer_ptr; | 497 prev_block_row = buffer_ptr; |
486 else | 498 else |
487 » prev_block_row = buffer[block_row-1]; | 499 prev_block_row = buffer[block_row-1]; |
488 if (last_row && block_row == block_rows-1) | 500 if (last_row && block_row == block_rows-1) |
489 » next_block_row = buffer_ptr; | 501 next_block_row = buffer_ptr; |
490 else | 502 else |
491 » next_block_row = buffer[block_row+1]; | 503 next_block_row = buffer[block_row+1]; |
492 /* We fetch the surrounding DC values using a sliding-register approach. | 504 /* We fetch the surrounding DC values using a sliding-register approach. |
493 * Initialize all nine here so as to do the right thing on narrow pics. | 505 * Initialize all nine here so as to do the right thing on narrow pics. |
494 */ | 506 */ |
495 DC1 = DC2 = DC3 = (int) prev_block_row[0][0]; | 507 DC1 = DC2 = DC3 = (int) prev_block_row[0][0]; |
496 DC4 = DC5 = DC6 = (int) buffer_ptr[0][0]; | 508 DC4 = DC5 = DC6 = (int) buffer_ptr[0][0]; |
497 DC7 = DC8 = DC9 = (int) next_block_row[0][0]; | 509 DC7 = DC8 = DC9 = (int) next_block_row[0][0]; |
498 output_col = 0; | 510 output_col = 0; |
499 last_block_column = compptr->width_in_blocks - 1; | 511 last_block_column = compptr->width_in_blocks - 1; |
500 for (block_num = 0; block_num <= last_block_column; block_num++) { | 512 for (block_num = cinfo->master->first_MCU_col[ci]; |
501 » /* Fetch current DCT block into workspace so we can modify it. */ | 513 block_num <= cinfo->master->last_MCU_col[ci]; block_num++) { |
502 » jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1); | 514 /* Fetch current DCT block into workspace so we can modify it. */ |
503 » /* Update DC values */ | 515 jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1); |
504 » if (block_num < last_block_column) { | 516 /* Update DC values */ |
505 » DC3 = (int) prev_block_row[1][0]; | 517 if (block_num < last_block_column) { |
506 » DC6 = (int) buffer_ptr[1][0]; | 518 DC3 = (int) prev_block_row[1][0]; |
507 » DC9 = (int) next_block_row[1][0]; | 519 DC6 = (int) buffer_ptr[1][0]; |
508 » } | 520 DC9 = (int) next_block_row[1][0]; |
509 » /* Compute coefficient estimates per K.8. | 521 } |
510 » * An estimate is applied only if coefficient is still zero, | 522 /* Compute coefficient estimates per K.8. |
511 » * and is not known to be fully accurate. | 523 * An estimate is applied only if coefficient is still zero, |
512 » */ | 524 * and is not known to be fully accurate. |
513 » /* AC01 */ | 525 */ |
514 » if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) { | 526 /* AC01 */ |
515 » num = 36 * Q00 * (DC4 - DC6); | 527 if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) { |
516 » if (num >= 0) { | 528 num = 36 * Q00 * (DC4 - DC6); |
517 » pred = (int) (((Q01<<7) + num) / (Q01<<8)); | 529 if (num >= 0) { |
518 » if (Al > 0 && pred >= (1<<Al)) | 530 pred = (int) (((Q01<<7) + num) / (Q01<<8)); |
519 » pred = (1<<Al)-1; | 531 if (Al > 0 && pred >= (1<<Al)) |
520 » } else { | 532 pred = (1<<Al)-1; |
521 » pred = (int) (((Q01<<7) - num) / (Q01<<8)); | 533 } else { |
522 » if (Al > 0 && pred >= (1<<Al)) | 534 pred = (int) (((Q01<<7) - num) / (Q01<<8)); |
523 » pred = (1<<Al)-1; | 535 if (Al > 0 && pred >= (1<<Al)) |
524 » pred = -pred; | 536 pred = (1<<Al)-1; |
525 » } | 537 pred = -pred; |
526 » workspace[1] = (JCOEF) pred; | 538 } |
527 » } | 539 workspace[1] = (JCOEF) pred; |
528 » /* AC10 */ | 540 } |
529 » if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) { | 541 /* AC10 */ |
530 » num = 36 * Q00 * (DC2 - DC8); | 542 if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) { |
531 » if (num >= 0) { | 543 num = 36 * Q00 * (DC2 - DC8); |
532 » pred = (int) (((Q10<<7) + num) / (Q10<<8)); | 544 if (num >= 0) { |
533 » if (Al > 0 && pred >= (1<<Al)) | 545 pred = (int) (((Q10<<7) + num) / (Q10<<8)); |
534 » pred = (1<<Al)-1; | 546 if (Al > 0 && pred >= (1<<Al)) |
535 » } else { | 547 pred = (1<<Al)-1; |
536 » pred = (int) (((Q10<<7) - num) / (Q10<<8)); | 548 } else { |
537 » if (Al > 0 && pred >= (1<<Al)) | 549 pred = (int) (((Q10<<7) - num) / (Q10<<8)); |
538 » pred = (1<<Al)-1; | 550 if (Al > 0 && pred >= (1<<Al)) |
539 » pred = -pred; | 551 pred = (1<<Al)-1; |
540 » } | 552 pred = -pred; |
541 » workspace[8] = (JCOEF) pred; | 553 } |
542 » } | 554 workspace[8] = (JCOEF) pred; |
543 » /* AC20 */ | 555 } |
544 » if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) { | 556 /* AC20 */ |
545 » num = 9 * Q00 * (DC2 + DC8 - 2*DC5); | 557 if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) { |
546 » if (num >= 0) { | 558 num = 9 * Q00 * (DC2 + DC8 - 2*DC5); |
547 » pred = (int) (((Q20<<7) + num) / (Q20<<8)); | 559 if (num >= 0) { |
548 » if (Al > 0 && pred >= (1<<Al)) | 560 pred = (int) (((Q20<<7) + num) / (Q20<<8)); |
549 » pred = (1<<Al)-1; | 561 if (Al > 0 && pred >= (1<<Al)) |
550 » } else { | 562 pred = (1<<Al)-1; |
551 » pred = (int) (((Q20<<7) - num) / (Q20<<8)); | 563 } else { |
552 » if (Al > 0 && pred >= (1<<Al)) | 564 pred = (int) (((Q20<<7) - num) / (Q20<<8)); |
553 » pred = (1<<Al)-1; | 565 if (Al > 0 && pred >= (1<<Al)) |
554 » pred = -pred; | 566 pred = (1<<Al)-1; |
555 » } | 567 pred = -pred; |
556 » workspace[16] = (JCOEF) pred; | 568 } |
557 » } | 569 workspace[16] = (JCOEF) pred; |
558 » /* AC11 */ | 570 } |
559 » if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) { | 571 /* AC11 */ |
560 » num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9); | 572 if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) { |
561 » if (num >= 0) { | 573 num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9); |
562 » pred = (int) (((Q11<<7) + num) / (Q11<<8)); | 574 if (num >= 0) { |
563 » if (Al > 0 && pred >= (1<<Al)) | 575 pred = (int) (((Q11<<7) + num) / (Q11<<8)); |
564 » pred = (1<<Al)-1; | 576 if (Al > 0 && pred >= (1<<Al)) |
565 » } else { | 577 pred = (1<<Al)-1; |
566 » pred = (int) (((Q11<<7) - num) / (Q11<<8)); | 578 } else { |
567 » if (Al > 0 && pred >= (1<<Al)) | 579 pred = (int) (((Q11<<7) - num) / (Q11<<8)); |
568 » pred = (1<<Al)-1; | 580 if (Al > 0 && pred >= (1<<Al)) |
569 » pred = -pred; | 581 pred = (1<<Al)-1; |
570 » } | 582 pred = -pred; |
571 » workspace[9] = (JCOEF) pred; | 583 } |
572 » } | 584 workspace[9] = (JCOEF) pred; |
573 » /* AC02 */ | 585 } |
574 » if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) { | 586 /* AC02 */ |
575 » num = 9 * Q00 * (DC4 + DC6 - 2*DC5); | 587 if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) { |
576 » if (num >= 0) { | 588 num = 9 * Q00 * (DC4 + DC6 - 2*DC5); |
577 » pred = (int) (((Q02<<7) + num) / (Q02<<8)); | 589 if (num >= 0) { |
578 » if (Al > 0 && pred >= (1<<Al)) | 590 pred = (int) (((Q02<<7) + num) / (Q02<<8)); |
579 » pred = (1<<Al)-1; | 591 if (Al > 0 && pred >= (1<<Al)) |
580 » } else { | 592 pred = (1<<Al)-1; |
581 » pred = (int) (((Q02<<7) - num) / (Q02<<8)); | 593 } else { |
582 » if (Al > 0 && pred >= (1<<Al)) | 594 pred = (int) (((Q02<<7) - num) / (Q02<<8)); |
583 » pred = (1<<Al)-1; | 595 if (Al > 0 && pred >= (1<<Al)) |
584 » pred = -pred; | 596 pred = (1<<Al)-1; |
585 » } | 597 pred = -pred; |
586 » workspace[2] = (JCOEF) pred; | 598 } |
587 » } | 599 workspace[2] = (JCOEF) pred; |
588 » /* OK, do the IDCT */ | 600 } |
589 » (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace, | 601 /* OK, do the IDCT */ |
590 » » » output_ptr, output_col); | 602 (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace, |
591 » /* Advance for next column */ | 603 output_ptr, output_col); |
592 » DC1 = DC2; DC2 = DC3; | 604 /* Advance for next column */ |
593 » DC4 = DC5; DC5 = DC6; | 605 DC1 = DC2; DC2 = DC3; |
594 » DC7 = DC8; DC8 = DC9; | 606 DC4 = DC5; DC5 = DC6; |
595 » buffer_ptr++, prev_block_row++, next_block_row++; | 607 DC7 = DC8; DC8 = DC9; |
596 » output_col += compptr->_DCT_scaled_size; | 608 buffer_ptr++, prev_block_row++, next_block_row++; |
| 609 output_col += compptr->_DCT_scaled_size; |
597 } | 610 } |
598 output_ptr += compptr->_DCT_scaled_size; | 611 output_ptr += compptr->_DCT_scaled_size; |
599 } | 612 } |
600 } | 613 } |
601 | 614 |
602 if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) | 615 if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) |
603 return JPEG_ROW_COMPLETED; | 616 return JPEG_ROW_COMPLETED; |
604 return JPEG_SCAN_COMPLETED; | 617 return JPEG_SCAN_COMPLETED; |
605 } | 618 } |
606 | 619 |
607 #endif /* BLOCK_SMOOTHING_SUPPORTED */ | 620 #endif /* BLOCK_SMOOTHING_SUPPORTED */ |
608 | 621 |
609 | 622 |
610 /* | 623 /* |
611 * Initialize coefficient buffer controller. | 624 * Initialize coefficient buffer controller. |
612 */ | 625 */ |
613 | 626 |
614 GLOBAL(void) | 627 GLOBAL(void) |
615 jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer) | 628 jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer) |
616 { | 629 { |
617 my_coef_ptr coef; | 630 my_coef_ptr coef; |
618 | 631 |
619 coef = (my_coef_ptr) | 632 coef = (my_coef_ptr) |
620 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 633 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
621 » » » » SIZEOF(my_coef_controller)); | 634 sizeof(my_coef_controller)); |
622 cinfo->coef = (struct jpeg_d_coef_controller *) coef; | 635 cinfo->coef = (struct jpeg_d_coef_controller *) coef; |
623 coef->pub.start_input_pass = start_input_pass; | 636 coef->pub.start_input_pass = start_input_pass; |
624 coef->pub.start_output_pass = start_output_pass; | 637 coef->pub.start_output_pass = start_output_pass; |
625 #ifdef BLOCK_SMOOTHING_SUPPORTED | 638 #ifdef BLOCK_SMOOTHING_SUPPORTED |
626 coef->coef_bits_latch = NULL; | 639 coef->coef_bits_latch = NULL; |
627 #endif | 640 #endif |
628 | 641 |
629 /* Create the coefficient buffer. */ | 642 /* Create the coefficient buffer. */ |
630 if (need_full_buffer) { | 643 if (need_full_buffer) { |
631 #ifdef D_MULTISCAN_FILES_SUPPORTED | 644 #ifdef D_MULTISCAN_FILES_SUPPORTED |
632 /* Allocate a full-image virtual array for each component, */ | 645 /* Allocate a full-image virtual array for each component, */ |
633 /* padded to a multiple of samp_factor DCT blocks in each direction. */ | 646 /* padded to a multiple of samp_factor DCT blocks in each direction. */ |
634 /* Note we ask for a pre-zeroed array. */ | 647 /* Note we ask for a pre-zeroed array. */ |
635 int ci, access_rows; | 648 int ci, access_rows; |
636 jpeg_component_info *compptr; | 649 jpeg_component_info *compptr; |
637 | 650 |
638 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 651 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
639 » ci++, compptr++) { | 652 ci++, compptr++) { |
640 access_rows = compptr->v_samp_factor; | 653 access_rows = compptr->v_samp_factor; |
641 #ifdef BLOCK_SMOOTHING_SUPPORTED | 654 #ifdef BLOCK_SMOOTHING_SUPPORTED |
642 /* If block smoothing could be used, need a bigger window */ | 655 /* If block smoothing could be used, need a bigger window */ |
643 if (cinfo->progressive_mode) | 656 if (cinfo->progressive_mode) |
644 » access_rows *= 3; | 657 access_rows *= 3; |
645 #endif | 658 #endif |
646 coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) | 659 coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) |
647 » ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE, | 660 ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE, |
648 » (JDIMENSION) jround_up((long) compptr->width_in_blocks, | 661 (JDIMENSION) jround_up((long) compptr->width_in_blocks, |
649 » » » » (long) compptr->h_samp_factor), | 662 (long) compptr->h_samp_factor), |
650 » (JDIMENSION) jround_up((long) compptr->height_in_blocks, | 663 (JDIMENSION) jround_up((long) compptr->height_in_blocks, |
651 » » » » (long) compptr->v_samp_factor), | 664 (long) compptr->v_samp_factor), |
652 » (JDIMENSION) access_rows); | 665 (JDIMENSION) access_rows); |
653 } | 666 } |
654 coef->pub.consume_data = consume_data; | 667 coef->pub.consume_data = consume_data; |
655 coef->pub.decompress_data = decompress_data; | 668 coef->pub.decompress_data = decompress_data; |
656 coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */ | 669 coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */ |
657 #else | 670 #else |
658 ERREXIT(cinfo, JERR_NOT_COMPILED); | 671 ERREXIT(cinfo, JERR_NOT_COMPILED); |
659 #endif | 672 #endif |
660 } else { | 673 } else { |
661 /* We only need a single-MCU buffer. */ | 674 /* We only need a single-MCU buffer. */ |
662 JBLOCKROW buffer; | 675 JBLOCKROW buffer; |
663 int i; | 676 int i; |
664 | 677 |
665 buffer = (JBLOCKROW) | 678 buffer = (JBLOCKROW) |
666 (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 679 (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
667 » » » » D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)); | 680 D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK)); |
668 for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) { | 681 for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) { |
669 coef->MCU_buffer[i] = buffer + i; | 682 coef->MCU_buffer[i] = buffer + i; |
670 } | 683 } |
671 coef->pub.consume_data = dummy_consume_data; | 684 coef->pub.consume_data = dummy_consume_data; |
672 coef->pub.decompress_data = decompress_onepass; | 685 coef->pub.decompress_data = decompress_onepass; |
673 coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */ | 686 coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */ |
674 } | 687 } |
675 | 688 |
676 /* Allocate the workspace buffer */ | 689 /* Allocate the workspace buffer */ |
677 coef->workspace = (JCOEF *) | 690 coef->workspace = (JCOEF *) |
678 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, | 691 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
679 SIZEOF(JCOEF) * DCTSIZE2); | 692 sizeof(JCOEF) * DCTSIZE2); |
680 } | 693 } |
OLD | NEW |