/src/libjpeg-turbo.dev/src/jdcoefct.c
Line | Count | Source |
1 | | /* |
2 | | * jdcoefct.c |
3 | | * |
4 | | * This file was part of the Independent JPEG Group's software: |
5 | | * Copyright (C) 1994-1997, Thomas G. Lane. |
6 | | * libjpeg-turbo Modifications: |
7 | | * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB |
8 | | * Copyright (C) 2010, 2015-2016, 2019-2020, 2022-2025, D. R. Commander. |
9 | | * Copyright (C) 2015, 2020, Google, Inc. |
10 | | * For conditions of distribution and use, see the accompanying README.ijg |
11 | | * file. |
12 | | * |
13 | | * This file contains the coefficient buffer controller for decompression. |
14 | | * This controller is the top level of the lossy JPEG decompressor proper. |
15 | | * The coefficient buffer lies between entropy decoding and inverse-DCT steps. |
16 | | * |
17 | | * In buffered-image mode, this controller is the interface between |
18 | | * input-oriented processing and output-oriented processing. |
19 | | * Also, the input side (only) is used when reading a file for transcoding. |
20 | | */ |
21 | | |
22 | | #include "jinclude.h" |
23 | | #include "jdcoefct.h" |
24 | | #include "jpegapicomp.h" |
25 | | #include "jsamplecomp.h" |
26 | | #ifdef WITH_PROFILE |
27 | | #include "tjutil.h" |
28 | | #endif |
29 | | |
30 | | |
31 | | /* Forward declarations */ |
32 | | METHODDEF(int) decompress_onepass(j_decompress_ptr cinfo, |
33 | | _JSAMPIMAGE output_buf); |
34 | | #ifdef D_MULTISCAN_FILES_SUPPORTED |
35 | | METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf); |
36 | | #endif |
37 | | #ifdef BLOCK_SMOOTHING_SUPPORTED |
38 | | LOCAL(boolean) smoothing_ok(j_decompress_ptr cinfo); |
39 | | METHODDEF(int) decompress_smooth_data(j_decompress_ptr cinfo, |
40 | | _JSAMPIMAGE output_buf); |
41 | | #endif |
42 | | |
43 | | |
44 | | /* |
45 | | * Initialize for an input processing pass. |
46 | | */ |
47 | | |
48 | | METHODDEF(void) |
49 | | start_input_pass(j_decompress_ptr cinfo) |
50 | 71.5k | { |
51 | 71.5k | cinfo->input_iMCU_row = 0; |
52 | 71.5k | start_iMCU_row(cinfo); |
53 | 71.5k | } jdcoefct-8.c:start_input_pass Line | Count | Source | 50 | 68.6k | { | 51 | 68.6k | cinfo->input_iMCU_row = 0; | 52 | 68.6k | start_iMCU_row(cinfo); | 53 | 68.6k | } |
jdcoefct-12.c:start_input_pass Line | Count | Source | 50 | 2.90k | { | 51 | 2.90k | cinfo->input_iMCU_row = 0; | 52 | 2.90k | start_iMCU_row(cinfo); | 53 | 2.90k | } |
|
54 | | |
55 | | |
56 | | /* |
57 | | * Initialize for an output processing pass. |
58 | | */ |
59 | | |
60 | | METHODDEF(void) |
61 | | start_output_pass(j_decompress_ptr cinfo) |
62 | 0 | { |
63 | 0 | #ifdef BLOCK_SMOOTHING_SUPPORTED |
64 | 0 | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; |
65 | | |
66 | | /* If multipass, check to see whether to use block smoothing on this pass */ |
67 | 0 | if (coef->pub.coef_arrays != NULL) { |
68 | 0 | if (cinfo->do_block_smoothing && smoothing_ok(cinfo)) |
69 | 0 | coef->pub._decompress_data = decompress_smooth_data; |
70 | 0 | else |
71 | 0 | coef->pub._decompress_data = decompress_data; |
72 | 0 | } |
73 | 0 | #endif |
74 | 0 | cinfo->output_iMCU_row = 0; |
75 | 0 | } Unexecuted instantiation: jdcoefct-8.c:start_output_pass Unexecuted instantiation: jdcoefct-12.c:start_output_pass |
76 | | |
77 | | |
78 | | /* |
79 | | * Decompress and return some data in the single-pass case. |
80 | | * Always attempts to emit one fully interleaved MCU row ("iMCU" row). |
81 | | * Input and output must run in lockstep since we have only a one-MCU buffer. |
82 | | * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. |
83 | | * |
84 | | * NB: output_buf contains a plane for each component in image, |
85 | | * which we index according to the component's SOF position. |
86 | | */ |
87 | | |
88 | | METHODDEF(int) |
89 | | decompress_onepass(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf) |
90 | 0 | { |
91 | 0 | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; |
92 | 0 | JDIMENSION MCU_col_num; /* index of current MCU within row */ |
93 | 0 | JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1; |
94 | 0 | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
95 | 0 | int blkn, ci, xindex, yindex, yoffset, useful_width; |
96 | 0 | _JSAMPARRAY output_ptr; |
97 | 0 | JDIMENSION start_col, output_col; |
98 | 0 | jpeg_component_info *compptr; |
99 | 0 | _inverse_DCT_method_ptr inverse_DCT; |
100 | | |
101 | | /* Loop to process as much as one whole iMCU row */ |
102 | 0 | for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; |
103 | 0 | yoffset++) { |
104 | 0 | for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col; |
105 | 0 | MCU_col_num++) { |
106 | | /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */ |
107 | 0 | jzero_far((void *)coef->MCU_buffer[0], |
108 | 0 | (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK))); |
109 | 0 | if (!cinfo->entropy->insufficient_data) |
110 | 0 | cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row; |
111 | 0 | if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { |
112 | | /* Suspension forced; update state counters and exit */ |
113 | 0 | coef->MCU_vert_offset = yoffset; |
114 | 0 | coef->MCU_ctr = MCU_col_num; |
115 | 0 | return JPEG_SUSPENDED; |
116 | 0 | } |
117 | | |
118 | | /* Only perform the IDCT on blocks that are contained within the desired |
119 | | * cropping region. |
120 | | */ |
121 | 0 | if (MCU_col_num >= cinfo->master->first_iMCU_col && |
122 | 0 | MCU_col_num <= cinfo->master->last_iMCU_col) { |
123 | | /* Determine where data should go in output_buf and do the IDCT thing. |
124 | | * We skip dummy blocks at the right and bottom edges (but blkn gets |
125 | | * incremented past them!). Note the inner loop relies on having |
126 | | * allocated the MCU_buffer[] blocks sequentially. |
127 | | */ |
128 | 0 | blkn = 0; /* index of current DCT block within MCU */ |
129 | 0 | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
130 | 0 | compptr = cinfo->cur_comp_info[ci]; |
131 | | /* Don't bother to IDCT an uninteresting component. */ |
132 | 0 | if (!compptr->component_needed) { |
133 | 0 | blkn += compptr->MCU_blocks; |
134 | 0 | continue; |
135 | 0 | } |
136 | 0 | inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index]; |
137 | 0 | useful_width = (MCU_col_num < last_MCU_col) ? |
138 | 0 | compptr->MCU_width : compptr->last_col_width; |
139 | 0 | output_ptr = output_buf[compptr->component_index] + |
140 | 0 | yoffset * compptr->_DCT_scaled_size; |
141 | 0 | start_col = (MCU_col_num - cinfo->master->first_iMCU_col) * |
142 | 0 | compptr->MCU_sample_width; |
143 | 0 | for (yindex = 0; yindex < compptr->MCU_height; yindex++) { |
144 | 0 | if (cinfo->input_iMCU_row < last_iMCU_row || |
145 | 0 | yoffset + yindex < compptr->last_row_height) { |
146 | 0 | output_col = start_col; |
147 | 0 | for (xindex = 0; xindex < useful_width; xindex++) { |
148 | | #ifdef WITH_PROFILE |
149 | | cinfo->master->start = getTime(); |
150 | | #endif |
151 | 0 | (*inverse_DCT) (cinfo, compptr, |
152 | 0 | (JCOEFPTR)coef->MCU_buffer[blkn + xindex], |
153 | 0 | output_ptr, output_col); |
154 | | #ifdef WITH_PROFILE |
155 | | cinfo->master->idct_elapsed += |
156 | | getTime() - cinfo->master->start; |
157 | | cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.; |
158 | | #endif |
159 | 0 | output_col += compptr->_DCT_scaled_size; |
160 | 0 | } |
161 | 0 | } |
162 | 0 | blkn += compptr->MCU_width; |
163 | 0 | output_ptr += compptr->_DCT_scaled_size; |
164 | 0 | } |
165 | 0 | } |
166 | 0 | } |
167 | 0 | } |
168 | | /* Completed an MCU row, but perhaps not an iMCU row */ |
169 | 0 | coef->MCU_ctr = 0; |
170 | 0 | } |
171 | | /* Completed the iMCU row, advance counters for next one */ |
172 | 0 | cinfo->output_iMCU_row++; |
173 | 0 | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { |
174 | 0 | start_iMCU_row(cinfo); |
175 | 0 | return JPEG_ROW_COMPLETED; |
176 | 0 | } |
177 | | /* Completed the scan */ |
178 | 0 | (*cinfo->inputctl->finish_input_pass) (cinfo); |
179 | 0 | return JPEG_SCAN_COMPLETED; |
180 | 0 | } Unexecuted instantiation: jdcoefct-8.c:decompress_onepass Unexecuted instantiation: jdcoefct-12.c:decompress_onepass |
181 | | |
182 | | |
183 | | /* |
184 | | * Dummy consume-input routine for single-pass operation. |
185 | | */ |
186 | | |
187 | | METHODDEF(int) |
188 | | dummy_consume_data(j_decompress_ptr cinfo) |
189 | 0 | { |
190 | 0 | return JPEG_SUSPENDED; /* Always indicate nothing was done */ |
191 | 0 | } Unexecuted instantiation: jdcoefct-8.c:dummy_consume_data Unexecuted instantiation: jdcoefct-12.c:dummy_consume_data |
192 | | |
193 | | |
194 | | #ifdef D_MULTISCAN_FILES_SUPPORTED |
195 | | |
196 | | /* |
197 | | * Consume input data and store it in the full-image coefficient buffer. |
198 | | * We read as much as one fully interleaved MCU row ("iMCU" row) per call, |
199 | | * ie, v_samp_factor block rows for each component in the scan. |
200 | | * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. |
201 | | */ |
202 | | |
203 | | METHODDEF(int) |
204 | | consume_data(j_decompress_ptr cinfo) |
205 | 26.1M | { |
206 | 26.1M | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; |
207 | 26.1M | JDIMENSION MCU_col_num; /* index of current MCU within row */ |
208 | 26.1M | int blkn, ci, xindex, yindex, yoffset; |
209 | 26.1M | JDIMENSION start_col; |
210 | 26.1M | JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; |
211 | 26.1M | JBLOCKROW buffer_ptr; |
212 | 26.1M | jpeg_component_info *compptr; |
213 | | |
214 | | /* Align the virtual buffers for the components used in this scan. */ |
215 | 54.6M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
216 | 28.4M | compptr = cinfo->cur_comp_info[ci]; |
217 | 28.4M | buffer[ci] = (*cinfo->mem->access_virt_barray) |
218 | 28.4M | ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index], |
219 | 28.4M | cinfo->input_iMCU_row * compptr->v_samp_factor, |
220 | 28.4M | (JDIMENSION)compptr->v_samp_factor, TRUE); |
221 | | /* Note: entropy decoder expects buffer to be zeroed, |
222 | | * but this is handled automatically by the memory manager |
223 | | * because we requested a pre-zeroed array. |
224 | | */ |
225 | 28.4M | } |
226 | | |
227 | | /* Loop to process one whole iMCU row */ |
228 | 57.6M | for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; |
229 | 31.4M | yoffset++) { |
230 | 238M | for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row; |
231 | 206M | MCU_col_num++) { |
232 | | /* Construct list of pointers to DCT blocks belonging to this MCU */ |
233 | 206M | blkn = 0; /* index of current DCT block within MCU */ |
234 | 445M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { |
235 | 238M | compptr = cinfo->cur_comp_info[ci]; |
236 | 238M | start_col = MCU_col_num * compptr->MCU_width; |
237 | 486M | for (yindex = 0; yindex < compptr->MCU_height; yindex++) { |
238 | 247M | buffer_ptr = buffer[ci][yindex + yoffset] + start_col; |
239 | 526M | for (xindex = 0; xindex < compptr->MCU_width; xindex++) { |
240 | 278M | coef->MCU_buffer[blkn++] = buffer_ptr++; |
241 | 278M | } |
242 | 247M | } |
243 | 238M | } |
244 | 206M | if (!cinfo->entropy->insufficient_data) |
245 | 104M | cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row; |
246 | | /* Try to fetch the MCU. */ |
247 | 206M | if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { |
248 | | /* Suspension forced; update state counters and exit */ |
249 | 0 | coef->MCU_vert_offset = yoffset; |
250 | 0 | coef->MCU_ctr = MCU_col_num; |
251 | 0 | return JPEG_SUSPENDED; |
252 | 0 | } |
253 | 206M | } |
254 | | /* Completed an MCU row, but perhaps not an iMCU row */ |
255 | 31.4M | coef->MCU_ctr = 0; |
256 | 31.4M | } |
257 | | /* Completed the iMCU row, advance counters for next one */ |
258 | 26.1M | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { |
259 | 26.1M | start_iMCU_row(cinfo); |
260 | 26.1M | return JPEG_ROW_COMPLETED; |
261 | 26.1M | } |
262 | | /* Completed the scan */ |
263 | 71.5k | (*cinfo->inputctl->finish_input_pass) (cinfo); |
264 | 71.5k | return JPEG_SCAN_COMPLETED; |
265 | 26.1M | } jdcoefct-8.c:consume_data Line | Count | Source | 205 | 24.7M | { | 206 | 24.7M | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; | 207 | 24.7M | JDIMENSION MCU_col_num; /* index of current MCU within row */ | 208 | 24.7M | int blkn, ci, xindex, yindex, yoffset; | 209 | 24.7M | JDIMENSION start_col; | 210 | 24.7M | JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; | 211 | 24.7M | JBLOCKROW buffer_ptr; | 212 | 24.7M | jpeg_component_info *compptr; | 213 | | | 214 | | /* Align the virtual buffers for the components used in this scan. */ | 215 | 51.5M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 216 | 26.7M | compptr = cinfo->cur_comp_info[ci]; | 217 | 26.7M | buffer[ci] = (*cinfo->mem->access_virt_barray) | 218 | 26.7M | ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index], | 219 | 26.7M | cinfo->input_iMCU_row * compptr->v_samp_factor, | 220 | 26.7M | (JDIMENSION)compptr->v_samp_factor, TRUE); | 221 | | /* Note: entropy decoder expects buffer to be zeroed, | 222 | | * but this is handled automatically by the memory manager | 223 | | * because we requested a pre-zeroed array. | 224 | | */ | 225 | 26.7M | } | 226 | | | 227 | | /* Loop to process one whole iMCU row */ | 228 | 54.5M | for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; | 229 | 29.8M | yoffset++) { | 230 | 226M | for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row; | 231 | 196M | MCU_col_num++) { | 232 | | /* Construct list of pointers to DCT blocks belonging to this MCU */ | 233 | 196M | blkn = 0; /* index of current DCT block within MCU */ | 234 | 423M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 235 | 227M | compptr = cinfo->cur_comp_info[ci]; | 236 | 227M | start_col = MCU_col_num * compptr->MCU_width; | 237 | 464M | for (yindex = 0; yindex < compptr->MCU_height; yindex++) { | 238 | 236M | buffer_ptr = buffer[ci][yindex + yoffset] + start_col; | 239 | 504M | for (xindex = 0; xindex < compptr->MCU_width; xindex++) { | 240 | 267M | coef->MCU_buffer[blkn++] = buffer_ptr++; | 241 | 267M | } | 242 | 236M | } | 243 | 227M | } | 244 | 196M | if (!cinfo->entropy->insufficient_data) | 245 | 97.7M | cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row; | 246 | | /* Try to fetch the MCU. */ | 247 | 196M | if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { | 248 | | /* Suspension forced; update state counters and exit */ | 249 | 0 | coef->MCU_vert_offset = yoffset; | 250 | 0 | coef->MCU_ctr = MCU_col_num; | 251 | 0 | return JPEG_SUSPENDED; | 252 | 0 | } | 253 | 196M | } | 254 | | /* Completed an MCU row, but perhaps not an iMCU row */ | 255 | 29.8M | coef->MCU_ctr = 0; | 256 | 29.8M | } | 257 | | /* Completed the iMCU row, advance counters for next one */ | 258 | 24.7M | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { | 259 | 24.6M | start_iMCU_row(cinfo); | 260 | 24.6M | return JPEG_ROW_COMPLETED; | 261 | 24.6M | } | 262 | | /* Completed the scan */ | 263 | 68.6k | (*cinfo->inputctl->finish_input_pass) (cinfo); | 264 | 68.6k | return JPEG_SCAN_COMPLETED; | 265 | 24.7M | } |
jdcoefct-12.c:consume_data Line | Count | Source | 205 | 1.47M | { | 206 | 1.47M | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; | 207 | 1.47M | JDIMENSION MCU_col_num; /* index of current MCU within row */ | 208 | 1.47M | int blkn, ci, xindex, yindex, yoffset; | 209 | 1.47M | JDIMENSION start_col; | 210 | 1.47M | JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN]; | 211 | 1.47M | JBLOCKROW buffer_ptr; | 212 | 1.47M | jpeg_component_info *compptr; | 213 | | | 214 | | /* Align the virtual buffers for the components used in this scan. */ | 215 | 3.15M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 216 | 1.67M | compptr = cinfo->cur_comp_info[ci]; | 217 | 1.67M | buffer[ci] = (*cinfo->mem->access_virt_barray) | 218 | 1.67M | ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index], | 219 | 1.67M | cinfo->input_iMCU_row * compptr->v_samp_factor, | 220 | 1.67M | (JDIMENSION)compptr->v_samp_factor, TRUE); | 221 | | /* Note: entropy decoder expects buffer to be zeroed, | 222 | | * but this is handled automatically by the memory manager | 223 | | * because we requested a pre-zeroed array. | 224 | | */ | 225 | 1.67M | } | 226 | | | 227 | | /* Loop to process one whole iMCU row */ | 228 | 3.08M | for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row; | 229 | 1.60M | yoffset++) { | 230 | 12.2M | for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row; | 231 | 10.6M | MCU_col_num++) { | 232 | | /* Construct list of pointers to DCT blocks belonging to this MCU */ | 233 | 10.6M | blkn = 0; /* index of current DCT block within MCU */ | 234 | 21.5M | for (ci = 0; ci < cinfo->comps_in_scan; ci++) { | 235 | 10.9M | compptr = cinfo->cur_comp_info[ci]; | 236 | 10.9M | start_col = MCU_col_num * compptr->MCU_width; | 237 | 22.0M | for (yindex = 0; yindex < compptr->MCU_height; yindex++) { | 238 | 11.0M | buffer_ptr = buffer[ci][yindex + yoffset] + start_col; | 239 | 22.6M | for (xindex = 0; xindex < compptr->MCU_width; xindex++) { | 240 | 11.5M | coef->MCU_buffer[blkn++] = buffer_ptr++; | 241 | 11.5M | } | 242 | 11.0M | } | 243 | 10.9M | } | 244 | 10.6M | if (!cinfo->entropy->insufficient_data) | 245 | 6.43M | cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row; | 246 | | /* Try to fetch the MCU. */ | 247 | 10.6M | if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) { | 248 | | /* Suspension forced; update state counters and exit */ | 249 | 0 | coef->MCU_vert_offset = yoffset; | 250 | 0 | coef->MCU_ctr = MCU_col_num; | 251 | 0 | return JPEG_SUSPENDED; | 252 | 0 | } | 253 | 10.6M | } | 254 | | /* Completed an MCU row, but perhaps not an iMCU row */ | 255 | 1.60M | coef->MCU_ctr = 0; | 256 | 1.60M | } | 257 | | /* Completed the iMCU row, advance counters for next one */ | 258 | 1.47M | if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) { | 259 | 1.47M | start_iMCU_row(cinfo); | 260 | 1.47M | return JPEG_ROW_COMPLETED; | 261 | 1.47M | } | 262 | | /* Completed the scan */ | 263 | 2.90k | (*cinfo->inputctl->finish_input_pass) (cinfo); | 264 | 2.90k | return JPEG_SCAN_COMPLETED; | 265 | 1.47M | } |
|
266 | | |
267 | | |
268 | | /* |
269 | | * Decompress and return some data in the multi-pass case. |
270 | | * Always attempts to emit one fully interleaved MCU row ("iMCU" row). |
271 | | * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED. |
272 | | * |
273 | | * NB: output_buf contains a plane for each component in image. |
274 | | */ |
275 | | |
276 | | METHODDEF(int) |
277 | | decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf) |
278 | 0 | { |
279 | 0 | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; |
280 | 0 | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
281 | 0 | JDIMENSION block_num; |
282 | 0 | int ci, block_row, block_rows; |
283 | 0 | JBLOCKARRAY buffer; |
284 | 0 | JBLOCKROW buffer_ptr; |
285 | 0 | _JSAMPARRAY output_ptr; |
286 | 0 | JDIMENSION output_col; |
287 | 0 | jpeg_component_info *compptr; |
288 | 0 | _inverse_DCT_method_ptr inverse_DCT; |
289 | | |
290 | | /* Force some input to be done if we are getting ahead of the input. */ |
291 | 0 | while (cinfo->input_scan_number < cinfo->output_scan_number || |
292 | 0 | (cinfo->input_scan_number == cinfo->output_scan_number && |
293 | 0 | cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) { |
294 | 0 | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) |
295 | 0 | return JPEG_SUSPENDED; |
296 | 0 | } |
297 | | |
298 | | /* OK, output from the virtual arrays. */ |
299 | 0 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
300 | 0 | ci++, compptr++) { |
301 | | /* Don't bother to IDCT an uninteresting component. */ |
302 | 0 | if (!compptr->component_needed) |
303 | 0 | continue; |
304 | | /* Align the virtual buffer for this component. */ |
305 | 0 | buffer = (*cinfo->mem->access_virt_barray) |
306 | 0 | ((j_common_ptr)cinfo, coef->whole_image[ci], |
307 | 0 | cinfo->output_iMCU_row * compptr->v_samp_factor, |
308 | 0 | (JDIMENSION)compptr->v_samp_factor, FALSE); |
309 | | /* Count non-dummy DCT block rows in this iMCU row. */ |
310 | 0 | if (cinfo->output_iMCU_row < last_iMCU_row) |
311 | 0 | block_rows = compptr->v_samp_factor; |
312 | 0 | else { |
313 | | /* NB: can't use last_row_height here; it is input-side-dependent! */ |
314 | 0 | block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); |
315 | 0 | if (block_rows == 0) block_rows = compptr->v_samp_factor; |
316 | 0 | } |
317 | 0 | inverse_DCT = cinfo->idct->_inverse_DCT[ci]; |
318 | 0 | output_ptr = output_buf[ci]; |
319 | | /* Loop over all DCT blocks to be processed. */ |
320 | 0 | for (block_row = 0; block_row < block_rows; block_row++) { |
321 | 0 | buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci]; |
322 | 0 | output_col = 0; |
323 | 0 | for (block_num = cinfo->master->first_MCU_col[ci]; |
324 | 0 | block_num <= cinfo->master->last_MCU_col[ci]; block_num++) { |
325 | | #ifdef WITH_PROFILE |
326 | | cinfo->master->start = getTime(); |
327 | | #endif |
328 | 0 | (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr, |
329 | 0 | output_col); |
330 | | #ifdef WITH_PROFILE |
331 | | cinfo->master->idct_elapsed += getTime() - cinfo->master->start; |
332 | | cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.; |
333 | | #endif |
334 | 0 | buffer_ptr++; |
335 | 0 | output_col += compptr->_DCT_scaled_size; |
336 | 0 | } |
337 | 0 | output_ptr += compptr->_DCT_scaled_size; |
338 | 0 | } |
339 | 0 | } |
340 | |
|
341 | 0 | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) |
342 | 0 | return JPEG_ROW_COMPLETED; |
343 | 0 | return JPEG_SCAN_COMPLETED; |
344 | 0 | } Unexecuted instantiation: jdcoefct-8.c:decompress_data Unexecuted instantiation: jdcoefct-12.c:decompress_data |
345 | | |
346 | | #endif /* D_MULTISCAN_FILES_SUPPORTED */ |
347 | | |
348 | | |
349 | | #ifdef BLOCK_SMOOTHING_SUPPORTED |
350 | | |
351 | | /* |
352 | | * This code applies interblock smoothing; the first 9 AC coefficients are |
353 | | * estimated from the DC values of a DCT block and its 24 neighboring blocks. |
354 | | * We apply smoothing only for progressive JPEG decoding, and only if |
355 | | * the coefficients it can estimate are not yet known to full precision. |
356 | | */ |
357 | | |
358 | | /* Natural-order array positions of the first 9 zigzag-order coefficients */ |
359 | 0 | #define Q01_POS 1 |
360 | 0 | #define Q10_POS 8 |
361 | 0 | #define Q20_POS 16 |
362 | 0 | #define Q11_POS 9 |
363 | 0 | #define Q02_POS 2 |
364 | 0 | #define Q03_POS 3 |
365 | 0 | #define Q12_POS 10 |
366 | 0 | #define Q21_POS 17 |
367 | 0 | #define Q30_POS 24 |
368 | | |
369 | | /* |
370 | | * Determine whether block smoothing is applicable and safe. |
371 | | * We also latch the current states of the coef_bits[] entries for the |
372 | | * AC coefficients; otherwise, if the input side of the decompressor |
373 | | * advances into a new scan, we might think the coefficients are known |
374 | | * more accurately than they really are. |
375 | | */ |
376 | | |
377 | | LOCAL(boolean) |
378 | | smoothing_ok(j_decompress_ptr cinfo) |
379 | 0 | { |
380 | 0 | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; |
381 | 0 | boolean smoothing_useful = FALSE; |
382 | 0 | int ci, coefi; |
383 | 0 | jpeg_component_info *compptr; |
384 | 0 | JQUANT_TBL *qtable; |
385 | 0 | int *coef_bits, *prev_coef_bits; |
386 | 0 | int *coef_bits_latch, *prev_coef_bits_latch; |
387 | |
|
388 | 0 | if (!cinfo->progressive_mode || cinfo->coef_bits == NULL) |
389 | 0 | return FALSE; |
390 | | |
391 | | /* Allocate latch area if not already done */ |
392 | 0 | if (coef->coef_bits_latch == NULL) |
393 | 0 | coef->coef_bits_latch = (int *) |
394 | 0 | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
395 | 0 | cinfo->num_components * 2 * |
396 | 0 | (SAVED_COEFS * sizeof(int))); |
397 | 0 | coef_bits_latch = coef->coef_bits_latch; |
398 | 0 | prev_coef_bits_latch = |
399 | 0 | &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS]; |
400 | |
|
401 | 0 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
402 | 0 | ci++, compptr++) { |
403 | | /* All components' quantization values must already be latched. */ |
404 | 0 | if ((qtable = compptr->quant_table) == NULL) |
405 | 0 | return FALSE; |
406 | | /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */ |
407 | 0 | if (qtable->quantval[0] == 0 || |
408 | 0 | qtable->quantval[Q01_POS] == 0 || |
409 | 0 | qtable->quantval[Q10_POS] == 0 || |
410 | 0 | qtable->quantval[Q20_POS] == 0 || |
411 | 0 | qtable->quantval[Q11_POS] == 0 || |
412 | 0 | qtable->quantval[Q02_POS] == 0 || |
413 | 0 | qtable->quantval[Q03_POS] == 0 || |
414 | 0 | qtable->quantval[Q12_POS] == 0 || |
415 | 0 | qtable->quantval[Q21_POS] == 0 || |
416 | 0 | qtable->quantval[Q30_POS] == 0) |
417 | 0 | return FALSE; |
418 | | /* DC values must be at least partly known for all components. */ |
419 | 0 | coef_bits = cinfo->coef_bits[ci]; |
420 | 0 | prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components]; |
421 | 0 | if (coef_bits[0] < 0) |
422 | 0 | return FALSE; |
423 | 0 | coef_bits_latch[0] = coef_bits[0]; |
424 | | /* Block smoothing is helpful if some AC coefficients remain inaccurate. */ |
425 | 0 | for (coefi = 1; coefi < SAVED_COEFS; coefi++) { |
426 | 0 | if (cinfo->input_scan_number > 1) |
427 | 0 | prev_coef_bits_latch[coefi] = prev_coef_bits[coefi]; |
428 | 0 | else |
429 | 0 | prev_coef_bits_latch[coefi] = -1; |
430 | 0 | coef_bits_latch[coefi] = coef_bits[coefi]; |
431 | 0 | if (coef_bits[coefi] != 0) |
432 | 0 | smoothing_useful = TRUE; |
433 | 0 | } |
434 | 0 | coef_bits_latch += SAVED_COEFS; |
435 | 0 | prev_coef_bits_latch += SAVED_COEFS; |
436 | 0 | } |
437 | | |
438 | 0 | return smoothing_useful; |
439 | 0 | } Unexecuted instantiation: jdcoefct-8.c:smoothing_ok Unexecuted instantiation: jdcoefct-12.c:smoothing_ok |
440 | | |
441 | | |
442 | | /* |
443 | | * Variant of decompress_data for use when doing block smoothing. |
444 | | */ |
445 | | |
446 | | METHODDEF(int) |
447 | | decompress_smooth_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf) |
448 | 0 | { |
449 | 0 | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; |
450 | 0 | JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1; |
451 | 0 | JDIMENSION block_num, last_block_column; |
452 | 0 | int ci, block_row, block_rows, access_rows, image_block_row, |
453 | 0 | image_block_rows; |
454 | 0 | JBLOCKARRAY buffer; |
455 | 0 | JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row; |
456 | 0 | JBLOCKROW next_block_row, next_next_block_row; |
457 | 0 | _JSAMPARRAY output_ptr; |
458 | 0 | JDIMENSION output_col; |
459 | 0 | jpeg_component_info *compptr; |
460 | 0 | _inverse_DCT_method_ptr inverse_DCT; |
461 | 0 | boolean change_dc; |
462 | 0 | JCOEF *workspace; |
463 | 0 | int *coef_bits; |
464 | 0 | JQUANT_TBL *quanttbl; |
465 | 0 | JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num; |
466 | 0 | int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12, |
467 | 0 | DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24, |
468 | 0 | DC25; |
469 | 0 | int Al, pred; |
470 | | |
471 | | /* Keep a local variable to avoid looking it up more than once */ |
472 | 0 | workspace = coef->workspace; |
473 | | |
474 | | /* Force some input to be done if we are getting ahead of the input. */ |
475 | 0 | while (cinfo->input_scan_number <= cinfo->output_scan_number && |
476 | 0 | !cinfo->inputctl->eoi_reached) { |
477 | 0 | if (cinfo->input_scan_number == cinfo->output_scan_number) { |
478 | | /* If input is working on current scan, we ordinarily want it to |
479 | | * have completed the current row. But if input scan is DC, |
480 | | * we want it to keep two rows ahead so that next two block rows' DC |
481 | | * values are up to date. |
482 | | */ |
483 | 0 | JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0; |
484 | 0 | if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta) |
485 | 0 | break; |
486 | 0 | } |
487 | 0 | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) |
488 | 0 | return JPEG_SUSPENDED; |
489 | 0 | } |
490 | | |
491 | | /* OK, output from the virtual arrays. */ |
492 | 0 | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
493 | 0 | ci++, compptr++) { |
494 | | /* Don't bother to IDCT an uninteresting component. */ |
495 | 0 | if (!compptr->component_needed) |
496 | 0 | continue; |
497 | | /* Count non-dummy DCT block rows in this iMCU row. */ |
498 | 0 | if (cinfo->output_iMCU_row + 1 < last_iMCU_row) { |
499 | 0 | block_rows = compptr->v_samp_factor; |
500 | 0 | access_rows = block_rows * 3; /* this and next two iMCU rows */ |
501 | 0 | } else if (cinfo->output_iMCU_row < last_iMCU_row) { |
502 | 0 | block_rows = compptr->v_samp_factor; |
503 | 0 | access_rows = block_rows * 2; /* this and next iMCU row */ |
504 | 0 | } else { |
505 | | /* NB: can't use last_row_height here; it is input-side-dependent! */ |
506 | 0 | block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor); |
507 | 0 | if (block_rows == 0) block_rows = compptr->v_samp_factor; |
508 | 0 | access_rows = block_rows; /* this iMCU row only */ |
509 | 0 | } |
510 | | /* Align the virtual buffer for this component. */ |
511 | 0 | if (cinfo->output_iMCU_row > 1) { |
512 | 0 | access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */ |
513 | 0 | buffer = (*cinfo->mem->access_virt_barray) |
514 | 0 | ((j_common_ptr)cinfo, coef->whole_image[ci], |
515 | 0 | (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor, |
516 | 0 | (JDIMENSION)access_rows, FALSE); |
517 | 0 | buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */ |
518 | 0 | } else if (cinfo->output_iMCU_row > 0) { |
519 | 0 | access_rows += compptr->v_samp_factor; /* prior iMCU row too */ |
520 | 0 | buffer = (*cinfo->mem->access_virt_barray) |
521 | 0 | ((j_common_ptr)cinfo, coef->whole_image[ci], |
522 | 0 | (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor, |
523 | 0 | (JDIMENSION)access_rows, FALSE); |
524 | 0 | buffer += compptr->v_samp_factor; /* point to current iMCU row */ |
525 | 0 | } else { |
526 | 0 | buffer = (*cinfo->mem->access_virt_barray) |
527 | 0 | ((j_common_ptr)cinfo, coef->whole_image[ci], |
528 | 0 | (JDIMENSION)0, (JDIMENSION)access_rows, FALSE); |
529 | 0 | } |
530 | | /* Fetch component-dependent info. |
531 | | * If the current scan is incomplete, then we use the component-dependent |
532 | | * info from the previous scan. |
533 | | */ |
534 | 0 | if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row) |
535 | 0 | coef_bits = |
536 | 0 | coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS); |
537 | 0 | else |
538 | 0 | coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS); |
539 | | |
540 | | /* We only do DC interpolation if no AC coefficient data is available. */ |
541 | 0 | change_dc = |
542 | 0 | coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 && |
543 | 0 | coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 && |
544 | 0 | coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1; |
545 | |
|
546 | 0 | quanttbl = compptr->quant_table; |
547 | 0 | Q00 = quanttbl->quantval[0]; |
548 | 0 | Q01 = quanttbl->quantval[Q01_POS]; |
549 | 0 | Q10 = quanttbl->quantval[Q10_POS]; |
550 | 0 | Q20 = quanttbl->quantval[Q20_POS]; |
551 | 0 | Q11 = quanttbl->quantval[Q11_POS]; |
552 | 0 | Q02 = quanttbl->quantval[Q02_POS]; |
553 | 0 | if (change_dc) { |
554 | 0 | Q03 = quanttbl->quantval[Q03_POS]; |
555 | 0 | Q12 = quanttbl->quantval[Q12_POS]; |
556 | 0 | Q21 = quanttbl->quantval[Q21_POS]; |
557 | 0 | Q30 = quanttbl->quantval[Q30_POS]; |
558 | 0 | } |
559 | 0 | inverse_DCT = cinfo->idct->_inverse_DCT[ci]; |
560 | 0 | output_ptr = output_buf[ci]; |
561 | | /* Loop over all DCT blocks to be processed. */ |
562 | 0 | image_block_rows = block_rows * cinfo->total_iMCU_rows; |
563 | 0 | for (block_row = 0; block_row < block_rows; block_row++) { |
564 | 0 | image_block_row = cinfo->output_iMCU_row * block_rows + block_row; |
565 | 0 | buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci]; |
566 | |
|
567 | 0 | if (image_block_row > 0) |
568 | 0 | prev_block_row = |
569 | 0 | buffer[block_row - 1] + cinfo->master->first_MCU_col[ci]; |
570 | 0 | else |
571 | 0 | prev_block_row = buffer_ptr; |
572 | |
|
573 | 0 | if (image_block_row > 1) |
574 | 0 | prev_prev_block_row = |
575 | 0 | buffer[block_row - 2] + cinfo->master->first_MCU_col[ci]; |
576 | 0 | else |
577 | 0 | prev_prev_block_row = prev_block_row; |
578 | |
|
579 | 0 | if (image_block_row < image_block_rows - 1) |
580 | 0 | next_block_row = |
581 | 0 | buffer[block_row + 1] + cinfo->master->first_MCU_col[ci]; |
582 | 0 | else |
583 | 0 | next_block_row = buffer_ptr; |
584 | |
|
585 | 0 | if (image_block_row < image_block_rows - 2) |
586 | 0 | next_next_block_row = |
587 | 0 | buffer[block_row + 2] + cinfo->master->first_MCU_col[ci]; |
588 | 0 | else |
589 | 0 | next_next_block_row = next_block_row; |
590 | | |
591 | | /* We fetch the surrounding DC values using a sliding-register approach. |
592 | | * Initialize all 25 here so as to do the right thing on narrow pics. |
593 | | */ |
594 | 0 | DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0]; |
595 | 0 | DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0]; |
596 | 0 | DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0]; |
597 | 0 | DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0]; |
598 | 0 | DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0]; |
599 | 0 | output_col = 0; |
600 | 0 | last_block_column = compptr->width_in_blocks - 1; |
601 | 0 | for (block_num = cinfo->master->first_MCU_col[ci]; |
602 | 0 | block_num <= cinfo->master->last_MCU_col[ci]; block_num++) { |
603 | | /* Fetch current DCT block into workspace so we can modify it. */ |
604 | 0 | jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1); |
605 | | /* Update DC values */ |
606 | 0 | if (block_num == cinfo->master->first_MCU_col[ci] && |
607 | 0 | block_num < last_block_column) { |
608 | 0 | DC04 = DC05 = (int)prev_prev_block_row[1][0]; |
609 | 0 | DC09 = DC10 = (int)prev_block_row[1][0]; |
610 | 0 | DC14 = DC15 = (int)buffer_ptr[1][0]; |
611 | 0 | DC19 = DC20 = (int)next_block_row[1][0]; |
612 | 0 | DC24 = DC25 = (int)next_next_block_row[1][0]; |
613 | 0 | } |
614 | 0 | if (block_num + 1 < last_block_column) { |
615 | 0 | DC05 = (int)prev_prev_block_row[2][0]; |
616 | 0 | DC10 = (int)prev_block_row[2][0]; |
617 | 0 | DC15 = (int)buffer_ptr[2][0]; |
618 | 0 | DC20 = (int)next_block_row[2][0]; |
619 | 0 | DC25 = (int)next_next_block_row[2][0]; |
620 | 0 | } |
621 | | /* If DC interpolation is enabled, compute coefficient estimates using |
622 | | * a Gaussian-like kernel, keeping the averages of the DC values. |
623 | | * |
624 | | * If DC interpolation is disabled, compute coefficient estimates using |
625 | | * an algorithm similar to the one described in Section K.8 of the JPEG |
626 | | * standard, except applied to a 5x5 window rather than a 3x3 window. |
627 | | * |
628 | | * An estimate is applied only if the coefficient is still zero and is |
629 | | * not known to be fully accurate. |
630 | | */ |
631 | | /* AC01 */ |
632 | 0 | if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) { |
633 | 0 | num = Q00 * (change_dc ? |
634 | 0 | (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 - |
635 | 0 | 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 + |
636 | 0 | 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 - |
637 | 0 | DC21 - DC22 + DC24 + DC25) : |
638 | 0 | (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15)); |
639 | 0 | if (num >= 0) { |
640 | 0 | pred = (int)(((Q01 << 7) + num) / (Q01 << 8)); |
641 | 0 | if (Al > 0 && pred >= (1 << Al)) |
642 | 0 | pred = (1 << Al) - 1; |
643 | 0 | } else { |
644 | 0 | pred = (int)(((Q01 << 7) - num) / (Q01 << 8)); |
645 | 0 | if (Al > 0 && pred >= (1 << Al)) |
646 | 0 | pred = (1 << Al) - 1; |
647 | 0 | pred = -pred; |
648 | 0 | } |
649 | 0 | workspace[1] = (JCOEF)pred; |
650 | 0 | } |
651 | | /* AC10 */ |
652 | 0 | if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) { |
653 | 0 | num = Q00 * (change_dc ? |
654 | 0 | (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 + |
655 | 0 | 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 - |
656 | 0 | 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 + |
657 | 0 | 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) : |
658 | 0 | (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23)); |
659 | 0 | if (num >= 0) { |
660 | 0 | pred = (int)(((Q10 << 7) + num) / (Q10 << 8)); |
661 | 0 | if (Al > 0 && pred >= (1 << Al)) |
662 | 0 | pred = (1 << Al) - 1; |
663 | 0 | } else { |
664 | 0 | pred = (int)(((Q10 << 7) - num) / (Q10 << 8)); |
665 | 0 | if (Al > 0 && pred >= (1 << Al)) |
666 | 0 | pred = (1 << Al) - 1; |
667 | 0 | pred = -pred; |
668 | 0 | } |
669 | 0 | workspace[8] = (JCOEF)pred; |
670 | 0 | } |
671 | | /* AC20 */ |
672 | 0 | if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) { |
673 | 0 | num = Q00 * (change_dc ? |
674 | 0 | (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 - |
675 | 0 | 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) : |
676 | 0 | (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23)); |
677 | 0 | if (num >= 0) { |
678 | 0 | pred = (int)(((Q20 << 7) + num) / (Q20 << 8)); |
679 | 0 | if (Al > 0 && pred >= (1 << Al)) |
680 | 0 | pred = (1 << Al) - 1; |
681 | 0 | } else { |
682 | 0 | pred = (int)(((Q20 << 7) - num) / (Q20 << 8)); |
683 | 0 | if (Al > 0 && pred >= (1 << Al)) |
684 | 0 | pred = (1 << Al) - 1; |
685 | 0 | pred = -pred; |
686 | 0 | } |
687 | 0 | workspace[16] = (JCOEF)pred; |
688 | 0 | } |
689 | | /* AC11 */ |
690 | 0 | if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) { |
691 | 0 | num = Q00 * (change_dc ? |
692 | 0 | (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 + |
693 | 0 | 9 * DC19 + DC21 - DC25) : |
694 | 0 | (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 - |
695 | 0 | DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09)); |
696 | 0 | if (num >= 0) { |
697 | 0 | pred = (int)(((Q11 << 7) + num) / (Q11 << 8)); |
698 | 0 | if (Al > 0 && pred >= (1 << Al)) |
699 | 0 | pred = (1 << Al) - 1; |
700 | 0 | } else { |
701 | 0 | pred = (int)(((Q11 << 7) - num) / (Q11 << 8)); |
702 | 0 | if (Al > 0 && pred >= (1 << Al)) |
703 | 0 | pred = (1 << Al) - 1; |
704 | 0 | pred = -pred; |
705 | 0 | } |
706 | 0 | workspace[9] = (JCOEF)pred; |
707 | 0 | } |
708 | | /* AC02 */ |
709 | 0 | if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) { |
710 | 0 | num = Q00 * (change_dc ? |
711 | 0 | (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 + |
712 | 0 | 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) : |
713 | 0 | (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15)); |
714 | 0 | if (num >= 0) { |
715 | 0 | pred = (int)(((Q02 << 7) + num) / (Q02 << 8)); |
716 | 0 | if (Al > 0 && pred >= (1 << Al)) |
717 | 0 | pred = (1 << Al) - 1; |
718 | 0 | } else { |
719 | 0 | pred = (int)(((Q02 << 7) - num) / (Q02 << 8)); |
720 | 0 | if (Al > 0 && pred >= (1 << Al)) |
721 | 0 | pred = (1 << Al) - 1; |
722 | 0 | pred = -pred; |
723 | 0 | } |
724 | 0 | workspace[2] = (JCOEF)pred; |
725 | 0 | } |
726 | 0 | if (change_dc) { |
727 | | /* AC03 */ |
728 | 0 | if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) { |
729 | 0 | num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19); |
730 | 0 | if (num >= 0) { |
731 | 0 | pred = (int)(((Q03 << 7) + num) / (Q03 << 8)); |
732 | 0 | if (Al > 0 && pred >= (1 << Al)) |
733 | 0 | pred = (1 << Al) - 1; |
734 | 0 | } else { |
735 | 0 | pred = (int)(((Q03 << 7) - num) / (Q03 << 8)); |
736 | 0 | if (Al > 0 && pred >= (1 << Al)) |
737 | 0 | pred = (1 << Al) - 1; |
738 | 0 | pred = -pred; |
739 | 0 | } |
740 | 0 | workspace[3] = (JCOEF)pred; |
741 | 0 | } |
742 | | /* AC12 */ |
743 | 0 | if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) { |
744 | 0 | num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19); |
745 | 0 | if (num >= 0) { |
746 | 0 | pred = (int)(((Q12 << 7) + num) / (Q12 << 8)); |
747 | 0 | if (Al > 0 && pred >= (1 << Al)) |
748 | 0 | pred = (1 << Al) - 1; |
749 | 0 | } else { |
750 | 0 | pred = (int)(((Q12 << 7) - num) / (Q12 << 8)); |
751 | 0 | if (Al > 0 && pred >= (1 << Al)) |
752 | 0 | pred = (1 << Al) - 1; |
753 | 0 | pred = -pred; |
754 | 0 | } |
755 | 0 | workspace[10] = (JCOEF)pred; |
756 | 0 | } |
757 | | /* AC21 */ |
758 | 0 | if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) { |
759 | 0 | num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19); |
760 | 0 | if (num >= 0) { |
761 | 0 | pred = (int)(((Q21 << 7) + num) / (Q21 << 8)); |
762 | 0 | if (Al > 0 && pred >= (1 << Al)) |
763 | 0 | pred = (1 << Al) - 1; |
764 | 0 | } else { |
765 | 0 | pred = (int)(((Q21 << 7) - num) / (Q21 << 8)); |
766 | 0 | if (Al > 0 && pred >= (1 << Al)) |
767 | 0 | pred = (1 << Al) - 1; |
768 | 0 | pred = -pred; |
769 | 0 | } |
770 | 0 | workspace[17] = (JCOEF)pred; |
771 | 0 | } |
772 | | /* AC30 */ |
773 | 0 | if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) { |
774 | 0 | num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19); |
775 | 0 | if (num >= 0) { |
776 | 0 | pred = (int)(((Q30 << 7) + num) / (Q30 << 8)); |
777 | 0 | if (Al > 0 && pred >= (1 << Al)) |
778 | 0 | pred = (1 << Al) - 1; |
779 | 0 | } else { |
780 | 0 | pred = (int)(((Q30 << 7) - num) / (Q30 << 8)); |
781 | 0 | if (Al > 0 && pred >= (1 << Al)) |
782 | 0 | pred = (1 << Al) - 1; |
783 | 0 | pred = -pred; |
784 | 0 | } |
785 | 0 | workspace[24] = (JCOEF)pred; |
786 | 0 | } |
787 | | /* coef_bits[0] is non-negative. Otherwise this function would not |
788 | | * be called. |
789 | | */ |
790 | 0 | num = Q00 * |
791 | 0 | (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 - |
792 | 0 | 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 - |
793 | 0 | 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 - |
794 | 0 | 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 - |
795 | 0 | 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25); |
796 | 0 | if (num >= 0) { |
797 | 0 | pred = (int)(((Q00 << 7) + num) / (Q00 << 8)); |
798 | 0 | } else { |
799 | 0 | pred = (int)(((Q00 << 7) - num) / (Q00 << 8)); |
800 | 0 | pred = -pred; |
801 | 0 | } |
802 | 0 | workspace[0] = (JCOEF)pred; |
803 | 0 | } /* change_dc */ |
804 | | |
805 | | /* OK, do the IDCT */ |
806 | | #ifdef WITH_PROFILE |
807 | | cinfo->master->start = getTime(); |
808 | | #endif |
809 | 0 | (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr, |
810 | 0 | output_col); |
811 | | #ifdef WITH_PROFILE |
812 | | cinfo->master->idct_elapsed += getTime() - cinfo->master->start; |
813 | | cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.; |
814 | | #endif |
815 | | /* Advance for next column */ |
816 | 0 | DC01 = DC02; DC02 = DC03; DC03 = DC04; DC04 = DC05; |
817 | 0 | DC06 = DC07; DC07 = DC08; DC08 = DC09; DC09 = DC10; |
818 | 0 | DC11 = DC12; DC12 = DC13; DC13 = DC14; DC14 = DC15; |
819 | 0 | DC16 = DC17; DC17 = DC18; DC18 = DC19; DC19 = DC20; |
820 | 0 | DC21 = DC22; DC22 = DC23; DC23 = DC24; DC24 = DC25; |
821 | 0 | buffer_ptr++, prev_block_row++, next_block_row++, |
822 | 0 | prev_prev_block_row++, next_next_block_row++; |
823 | 0 | output_col += compptr->_DCT_scaled_size; |
824 | 0 | } |
825 | 0 | output_ptr += compptr->_DCT_scaled_size; |
826 | 0 | } |
827 | 0 | } |
828 | |
|
829 | 0 | if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows) |
830 | 0 | return JPEG_ROW_COMPLETED; |
831 | 0 | return JPEG_SCAN_COMPLETED; |
832 | 0 | } Unexecuted instantiation: jdcoefct-8.c:decompress_smooth_data Unexecuted instantiation: jdcoefct-12.c:decompress_smooth_data |
833 | | |
834 | | #endif /* BLOCK_SMOOTHING_SUPPORTED */ |
835 | | |
836 | | |
837 | | /* |
838 | | * Initialize coefficient buffer controller. |
839 | | */ |
840 | | |
841 | | GLOBAL(void) |
842 | | _jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer) |
843 | 14.9k | { |
844 | 14.9k | my_coef_ptr coef; |
845 | | |
846 | 14.9k | if (cinfo->data_precision != BITS_IN_JSAMPLE) |
847 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
848 | | |
849 | 14.9k | coef = (my_coef_ptr) |
850 | 14.9k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
851 | 14.9k | sizeof(my_coef_controller)); |
852 | 14.9k | memset(coef, 0, sizeof(my_coef_controller)); |
853 | 14.9k | cinfo->coef = (struct jpeg_d_coef_controller *)coef; |
854 | 14.9k | coef->pub.start_input_pass = start_input_pass; |
855 | 14.9k | coef->pub.start_output_pass = start_output_pass; |
856 | 14.9k | #ifdef BLOCK_SMOOTHING_SUPPORTED |
857 | 14.9k | coef->coef_bits_latch = NULL; |
858 | 14.9k | #endif |
859 | | |
860 | | /* Create the coefficient buffer. */ |
861 | 14.9k | if (need_full_buffer) { |
862 | 14.9k | #ifdef D_MULTISCAN_FILES_SUPPORTED |
863 | | /* Allocate a full-image virtual array for each component, */ |
864 | | /* padded to a multiple of samp_factor DCT blocks in each direction. */ |
865 | | /* Note we ask for a pre-zeroed array. */ |
866 | 14.9k | int ci, access_rows; |
867 | 14.9k | jpeg_component_info *compptr; |
868 | | |
869 | 42.6k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
870 | 27.6k | ci++, compptr++) { |
871 | 27.6k | access_rows = compptr->v_samp_factor; |
872 | 27.6k | #ifdef BLOCK_SMOOTHING_SUPPORTED |
873 | | /* If block smoothing could be used, need a bigger window */ |
874 | 27.6k | if (cinfo->progressive_mode) |
875 | 10.5k | access_rows *= 5; |
876 | 27.6k | #endif |
877 | 27.6k | coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) |
878 | 27.6k | ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE, |
879 | 27.6k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, |
880 | 27.6k | (long)compptr->h_samp_factor), |
881 | 27.6k | (JDIMENSION)jround_up((long)compptr->height_in_blocks, |
882 | 27.6k | (long)compptr->v_samp_factor), |
883 | 27.6k | (JDIMENSION)access_rows); |
884 | 27.6k | } |
885 | 14.9k | coef->pub.consume_data = consume_data; |
886 | 14.9k | coef->pub._decompress_data = decompress_data; |
887 | 14.9k | coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */ |
888 | | #else |
889 | | ERREXIT(cinfo, JERR_NOT_COMPILED); |
890 | | #endif |
891 | 14.9k | } else { |
892 | | /* We only need a single-MCU buffer. */ |
893 | 0 | JBLOCKROW buffer; |
894 | 0 | int i; |
895 | |
|
896 | 0 | buffer = (JBLOCKROW) |
897 | 0 | (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
898 | 0 | D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK)); |
899 | 0 | for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) { |
900 | 0 | coef->MCU_buffer[i] = buffer + i; |
901 | 0 | } |
902 | 0 | coef->pub.consume_data = dummy_consume_data; |
903 | 0 | coef->pub._decompress_data = decompress_onepass; |
904 | 0 | coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */ |
905 | 0 | } |
906 | | |
907 | | /* Allocate the workspace buffer */ |
908 | 14.9k | coef->workspace = (JCOEF *) |
909 | 14.9k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
910 | 14.9k | sizeof(JCOEF) * DCTSIZE2); |
911 | 14.9k | } Line | Count | Source | 843 | 12.9k | { | 844 | 12.9k | my_coef_ptr coef; | 845 | | | 846 | 12.9k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 847 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 848 | | | 849 | 12.9k | coef = (my_coef_ptr) | 850 | 12.9k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 851 | 12.9k | sizeof(my_coef_controller)); | 852 | 12.9k | memset(coef, 0, sizeof(my_coef_controller)); | 853 | 12.9k | cinfo->coef = (struct jpeg_d_coef_controller *)coef; | 854 | 12.9k | coef->pub.start_input_pass = start_input_pass; | 855 | 12.9k | coef->pub.start_output_pass = start_output_pass; | 856 | 12.9k | #ifdef BLOCK_SMOOTHING_SUPPORTED | 857 | 12.9k | coef->coef_bits_latch = NULL; | 858 | 12.9k | #endif | 859 | | | 860 | | /* Create the coefficient buffer. */ | 861 | 12.9k | if (need_full_buffer) { | 862 | 12.9k | #ifdef D_MULTISCAN_FILES_SUPPORTED | 863 | | /* Allocate a full-image virtual array for each component, */ | 864 | | /* padded to a multiple of samp_factor DCT blocks in each direction. */ | 865 | | /* Note we ask for a pre-zeroed array. */ | 866 | 12.9k | int ci, access_rows; | 867 | 12.9k | jpeg_component_info *compptr; | 868 | | | 869 | 37.7k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 870 | 24.7k | ci++, compptr++) { | 871 | 24.7k | access_rows = compptr->v_samp_factor; | 872 | 24.7k | #ifdef BLOCK_SMOOTHING_SUPPORTED | 873 | | /* If block smoothing could be used, need a bigger window */ | 874 | 24.7k | if (cinfo->progressive_mode) | 875 | 9.31k | access_rows *= 5; | 876 | 24.7k | #endif | 877 | 24.7k | coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) | 878 | 24.7k | ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE, | 879 | 24.7k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 880 | 24.7k | (long)compptr->h_samp_factor), | 881 | 24.7k | (JDIMENSION)jround_up((long)compptr->height_in_blocks, | 882 | 24.7k | (long)compptr->v_samp_factor), | 883 | 24.7k | (JDIMENSION)access_rows); | 884 | 24.7k | } | 885 | 12.9k | coef->pub.consume_data = consume_data; | 886 | 12.9k | coef->pub._decompress_data = decompress_data; | 887 | 12.9k | coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */ | 888 | | #else | 889 | | ERREXIT(cinfo, JERR_NOT_COMPILED); | 890 | | #endif | 891 | 12.9k | } else { | 892 | | /* We only need a single-MCU buffer. */ | 893 | 0 | JBLOCKROW buffer; | 894 | 0 | int i; | 895 | |
| 896 | 0 | buffer = (JBLOCKROW) | 897 | 0 | (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 898 | 0 | D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK)); | 899 | 0 | for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) { | 900 | 0 | coef->MCU_buffer[i] = buffer + i; | 901 | 0 | } | 902 | 0 | coef->pub.consume_data = dummy_consume_data; | 903 | 0 | coef->pub._decompress_data = decompress_onepass; | 904 | 0 | coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */ | 905 | 0 | } | 906 | | | 907 | | /* Allocate the workspace buffer */ | 908 | 12.9k | coef->workspace = (JCOEF *) | 909 | 12.9k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 910 | 12.9k | sizeof(JCOEF) * DCTSIZE2); | 911 | 12.9k | } |
j12init_d_coef_controller Line | Count | Source | 843 | 1.95k | { | 844 | 1.95k | my_coef_ptr coef; | 845 | | | 846 | 1.95k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 847 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 848 | | | 849 | 1.95k | coef = (my_coef_ptr) | 850 | 1.95k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 851 | 1.95k | sizeof(my_coef_controller)); | 852 | 1.95k | memset(coef, 0, sizeof(my_coef_controller)); | 853 | 1.95k | cinfo->coef = (struct jpeg_d_coef_controller *)coef; | 854 | 1.95k | coef->pub.start_input_pass = start_input_pass; | 855 | 1.95k | coef->pub.start_output_pass = start_output_pass; | 856 | 1.95k | #ifdef BLOCK_SMOOTHING_SUPPORTED | 857 | 1.95k | coef->coef_bits_latch = NULL; | 858 | 1.95k | #endif | 859 | | | 860 | | /* Create the coefficient buffer. */ | 861 | 1.95k | if (need_full_buffer) { | 862 | 1.95k | #ifdef D_MULTISCAN_FILES_SUPPORTED | 863 | | /* Allocate a full-image virtual array for each component, */ | 864 | | /* padded to a multiple of samp_factor DCT blocks in each direction. */ | 865 | | /* Note we ask for a pre-zeroed array. */ | 866 | 1.95k | int ci, access_rows; | 867 | 1.95k | jpeg_component_info *compptr; | 868 | | | 869 | 4.90k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 870 | 2.95k | ci++, compptr++) { | 871 | 2.95k | access_rows = compptr->v_samp_factor; | 872 | 2.95k | #ifdef BLOCK_SMOOTHING_SUPPORTED | 873 | | /* If block smoothing could be used, need a bigger window */ | 874 | 2.95k | if (cinfo->progressive_mode) | 875 | 1.28k | access_rows *= 5; | 876 | 2.95k | #endif | 877 | 2.95k | coef->whole_image[ci] = (*cinfo->mem->request_virt_barray) | 878 | 2.95k | ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE, | 879 | 2.95k | (JDIMENSION)jround_up((long)compptr->width_in_blocks, | 880 | 2.95k | (long)compptr->h_samp_factor), | 881 | 2.95k | (JDIMENSION)jround_up((long)compptr->height_in_blocks, | 882 | 2.95k | (long)compptr->v_samp_factor), | 883 | 2.95k | (JDIMENSION)access_rows); | 884 | 2.95k | } | 885 | 1.95k | coef->pub.consume_data = consume_data; | 886 | 1.95k | coef->pub._decompress_data = decompress_data; | 887 | 1.95k | coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */ | 888 | | #else | 889 | | ERREXIT(cinfo, JERR_NOT_COMPILED); | 890 | | #endif | 891 | 1.95k | } else { | 892 | | /* We only need a single-MCU buffer. */ | 893 | 0 | JBLOCKROW buffer; | 894 | 0 | int i; | 895 | |
| 896 | 0 | buffer = (JBLOCKROW) | 897 | 0 | (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 898 | 0 | D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK)); | 899 | 0 | for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) { | 900 | 0 | coef->MCU_buffer[i] = buffer + i; | 901 | 0 | } | 902 | 0 | coef->pub.consume_data = dummy_consume_data; | 903 | 0 | coef->pub._decompress_data = decompress_onepass; | 904 | 0 | coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */ | 905 | 0 | } | 906 | | | 907 | | /* Allocate the workspace buffer */ | 908 | 1.95k | coef->workspace = (JCOEF *) | 909 | 1.95k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 910 | 1.95k | sizeof(JCOEF) * DCTSIZE2); | 911 | 1.95k | } |
|