/src/libjpeg-turbo.main/src/jdapistd.c
Line | Count | Source |
1 | | /* |
2 | | * jdapistd.c |
3 | | * |
4 | | * This file was part of the Independent JPEG Group's software: |
5 | | * Copyright (C) 1994-1996, Thomas G. Lane. |
6 | | * libjpeg-turbo Modifications: |
7 | | * Copyright (C) 2010, 2015-2020, 2022-2026, D. R. Commander. |
8 | | * Copyright (C) 2015, Google, Inc. |
9 | | * For conditions of distribution and use, see the accompanying README.ijg |
10 | | * file. |
11 | | * |
12 | | * This file contains application interface code for the decompression half |
13 | | * of the JPEG library. These are the "standard" API routines that are |
14 | | * used in the normal full-decompression case. They are not used by a |
15 | | * transcoding-only application. Note that if an application links in |
16 | | * jpeg_start_decompress, it will end up linking in the entire decompressor. |
17 | | * We thus must separate this file from jdapimin.c to avoid linking the |
18 | | * whole decompression library into a transcoder. |
19 | | */ |
20 | | |
21 | | #include "jinclude.h" |
22 | | #if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) |
23 | | #include "jdmainct.h" |
24 | | #include "jdcoefct.h" |
25 | | #else |
26 | | #define JPEG_INTERNALS |
27 | | #include "jpeglib.h" |
28 | | #endif |
29 | | #include "jdmaster.h" |
30 | | #include "jdmerge.h" |
31 | | #include "jdsample.h" |
32 | | #include "jmemsys.h" |
33 | | #ifdef WITH_PROFILE |
34 | | #include "tjutil.h" |
35 | | #endif |
36 | | |
37 | | #if BITS_IN_JSAMPLE == 8 |
38 | | |
39 | | /* Forward declarations */ |
40 | | LOCAL(boolean) output_pass_setup(j_decompress_ptr cinfo); |
41 | | |
42 | | |
43 | | /* |
44 | | * Decompression initialization. |
45 | | * jpeg_read_header must be completed before calling this. |
46 | | * |
47 | | * If a multipass operating mode was selected, this will do all but the |
48 | | * last pass, and thus may take a great deal of time. |
49 | | * |
50 | | * Returns FALSE if suspended. The return value need be inspected only if |
51 | | * a suspending data source is used. |
52 | | */ |
53 | | |
54 | | GLOBAL(boolean) |
55 | | jpeg_start_decompress(j_decompress_ptr cinfo) |
56 | 30.5k | { |
57 | 30.5k | if (cinfo->global_state == DSTATE_READY) { |
58 | | /* First call: initialize master control, select active modules */ |
59 | 30.5k | jinit_master_decompress(cinfo); |
60 | 30.5k | if (cinfo->buffered_image) { |
61 | | /* No more work here; expecting jpeg_start_output next */ |
62 | 0 | cinfo->global_state = DSTATE_BUFIMAGE; |
63 | 0 | return TRUE; |
64 | 0 | } |
65 | 30.5k | cinfo->global_state = DSTATE_PRELOAD; |
66 | 30.5k | } |
67 | 30.5k | if (cinfo->global_state == DSTATE_PRELOAD) { |
68 | | /* If file has multiple scans, absorb them all into the coef buffer */ |
69 | 14.6k | if (cinfo->inputctl->has_multiple_scans) { |
70 | 9.81k | #ifdef D_MULTISCAN_FILES_SUPPORTED |
71 | 28.8M | for (;;) { |
72 | 28.8M | int retcode; |
73 | | /* Call progress monitor hook if present */ |
74 | 28.8M | if (cinfo->progress != NULL) |
75 | 28.8M | (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo); |
76 | | /* Absorb some more input */ |
77 | 28.8M | retcode = (*cinfo->inputctl->consume_input) (cinfo); |
78 | 28.8M | if (retcode == JPEG_SUSPENDED) |
79 | 0 | return FALSE; |
80 | 28.8M | if (retcode == JPEG_REACHED_EOI) |
81 | 8.38k | break; |
82 | | /* Advance progress counter if appropriate */ |
83 | 28.8M | if (cinfo->progress != NULL && |
84 | 28.8M | (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) { |
85 | 28.7M | if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) { |
86 | | /* jdmaster underestimated number of scans; ratchet up one scan */ |
87 | 15.6k | cinfo->progress->pass_limit += (long)cinfo->total_iMCU_rows; |
88 | 15.6k | } |
89 | 28.7M | } |
90 | 28.8M | } |
91 | | #else |
92 | | ERREXIT(cinfo, JERR_NOT_COMPILED); |
93 | | #endif /* D_MULTISCAN_FILES_SUPPORTED */ |
94 | 9.81k | } |
95 | 14.6k | cinfo->output_scan_number = cinfo->input_scan_number; |
96 | 15.9k | } else if (cinfo->global_state != DSTATE_PRESCAN) |
97 | 0 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
98 | | /* Perform any dummy output passes, and set up for the final pass */ |
99 | 30.5k | return output_pass_setup(cinfo); |
100 | 30.5k | } |
101 | | |
102 | | |
103 | | /* |
104 | | * Set up for an output pass, and perform any dummy pass(es) needed. |
105 | | * Common subroutine for jpeg_start_decompress and jpeg_start_output. |
106 | | * Entry: global_state = DSTATE_PRESCAN only if previously suspended. |
107 | | * Exit: If done, returns TRUE and sets global_state for proper output mode. |
108 | | * If suspended, returns FALSE and sets global_state = DSTATE_PRESCAN. |
109 | | */ |
110 | | |
111 | | LOCAL(boolean) |
112 | | output_pass_setup(j_decompress_ptr cinfo) |
113 | 13.2k | { |
114 | 13.2k | if (cinfo->global_state != DSTATE_PRESCAN) { |
115 | | /* First call: do pass setup */ |
116 | 13.2k | (*cinfo->master->prepare_for_output_pass) (cinfo); |
117 | 13.2k | cinfo->output_scanline = 0; |
118 | 13.2k | cinfo->global_state = DSTATE_PRESCAN; |
119 | 13.2k | } |
120 | | /* Loop over any required dummy passes */ |
121 | 13.2k | while (cinfo->master->is_dummy_pass) { |
122 | 0 | #ifdef QUANT_2PASS_SUPPORTED |
123 | | /* Crank through the dummy pass */ |
124 | 0 | while (cinfo->output_scanline < cinfo->output_height) { |
125 | 0 | JDIMENSION last_scanline; |
126 | | /* Call progress monitor hook if present */ |
127 | 0 | if (cinfo->progress != NULL) { |
128 | 0 | cinfo->progress->pass_counter = (long)cinfo->output_scanline; |
129 | 0 | cinfo->progress->pass_limit = (long)cinfo->output_height; |
130 | 0 | (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo); |
131 | 0 | } |
132 | | /* Process some data */ |
133 | 0 | last_scanline = cinfo->output_scanline; |
134 | 0 | if (cinfo->data_precision <= 8) { |
135 | 0 | if (cinfo->main->process_data == NULL) |
136 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
137 | 0 | (*cinfo->main->process_data) (cinfo, (JSAMPARRAY)NULL, |
138 | 0 | &cinfo->output_scanline, (JDIMENSION)0); |
139 | 0 | } else if (cinfo->data_precision <= 12) { |
140 | 0 | if (cinfo->main->process_data_12 == NULL) |
141 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
142 | 0 | (*cinfo->main->process_data_12) (cinfo, (J12SAMPARRAY)NULL, |
143 | 0 | &cinfo->output_scanline, |
144 | 0 | (JDIMENSION)0); |
145 | 0 | } else { |
146 | 0 | #ifdef D_LOSSLESS_SUPPORTED |
147 | 0 | if (cinfo->main->process_data_16 == NULL) |
148 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
149 | 0 | (*cinfo->main->process_data_16) (cinfo, (J16SAMPARRAY)NULL, |
150 | 0 | &cinfo->output_scanline, |
151 | 0 | (JDIMENSION)0); |
152 | | #else |
153 | | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
154 | | #endif |
155 | 0 | } |
156 | 0 | if (cinfo->output_scanline == last_scanline) |
157 | 0 | return FALSE; /* No progress made, must suspend */ |
158 | 0 | } |
159 | | /* Finish up dummy pass, and set up for another one */ |
160 | 0 | (*cinfo->master->finish_output_pass) (cinfo); |
161 | 0 | (*cinfo->master->prepare_for_output_pass) (cinfo); |
162 | 0 | cinfo->output_scanline = 0; |
163 | | #else |
164 | | ERREXIT(cinfo, JERR_NOT_COMPILED); |
165 | | #endif /* QUANT_2PASS_SUPPORTED */ |
166 | 0 | } |
167 | | /* Ready for application to drive output pass through |
168 | | * _jpeg_read_scanlines or _jpeg_read_raw_data. |
169 | | */ |
170 | 13.2k | cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING; |
171 | 13.2k | return TRUE; |
172 | 13.2k | } |
173 | | |
174 | | #endif /* BITS_IN_JSAMPLE == 8 */ |
175 | | |
176 | | |
177 | | #if BITS_IN_JSAMPLE != 16 |
178 | | |
179 | | /* |
180 | | * Enable partial scanline decompression |
181 | | * |
182 | | * Must be called after jpeg_start_decompress() and before any calls to |
183 | | * _jpeg_read_scanlines() or _jpeg_skip_scanlines(). |
184 | | * |
185 | | * Refer to libjpeg.txt for more information. |
186 | | */ |
187 | | |
188 | | GLOBAL(void) |
189 | | _jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset, |
190 | | JDIMENSION *width) |
191 | 1.88k | { |
192 | 1.88k | int ci, align, orig_downsampled_width; |
193 | 1.88k | JDIMENSION input_xoffset; |
194 | 1.88k | boolean reinit_upsampler = FALSE; |
195 | 1.88k | jpeg_component_info *compptr; |
196 | 1.88k | #ifdef UPSAMPLE_MERGING_SUPPORTED |
197 | 1.88k | my_master_ptr master = (my_master_ptr)cinfo->master; |
198 | 1.88k | #endif |
199 | | |
200 | 1.88k | if (cinfo->data_precision != BITS_IN_JSAMPLE) |
201 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
202 | | |
203 | 1.88k | if (cinfo->master->lossless || cinfo->raw_data_out) |
204 | 0 | ERREXIT(cinfo, JERR_NOTIMPL); |
205 | | |
206 | 1.88k | if ((cinfo->global_state != DSTATE_SCANNING && |
207 | 1.88k | cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0) |
208 | 0 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
209 | | |
210 | 1.88k | if (!xoffset || !width) |
211 | 0 | ERREXIT(cinfo, JERR_BAD_CROP_SPEC); |
212 | | |
213 | | /* xoffset and width must fall within the output image dimensions. */ |
214 | 1.88k | if (*width == 0 || |
215 | 1.88k | (unsigned long long)(*xoffset) + *width > cinfo->output_width) |
216 | 0 | ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); |
217 | | |
218 | | /* No need to do anything if the caller wants the entire width. */ |
219 | 1.88k | if (*width == cinfo->output_width) |
220 | 0 | return; |
221 | | |
222 | | /* Ensuring the proper alignment of xoffset is tricky. At minimum, it |
223 | | * must align with an MCU boundary, because: |
224 | | * |
225 | | * (1) The IDCT is performed in blocks, and it is not feasible to modify |
226 | | * the algorithm so that it can transform partial blocks. |
227 | | * (2) Because of the SIMD extensions, any input buffer passed to the |
228 | | * upsampling and color conversion routines must be aligned to the |
229 | | * SIMD word size (for instance, 128-bit in the case of SSE2.) The |
230 | | * easiest way to accomplish this without copying data is to ensure |
231 | | * that upsampling and color conversion begin at the start of the |
232 | | * first MCU column that will be inverse transformed. |
233 | | * |
234 | | * In practice, we actually impose a stricter alignment requirement. We |
235 | | * require that xoffset be a multiple of the maximum MCU column width of all |
236 | | * of the components (the "iMCU column width.") This is to simplify the |
237 | | * single-pass decompression case, allowing us to use the same MCU column |
238 | | * width for all of the components. |
239 | | */ |
240 | 1.88k | if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) |
241 | 1.75k | align = cinfo->_min_DCT_scaled_size; |
242 | 130 | else |
243 | 130 | align = cinfo->_min_DCT_scaled_size * cinfo->max_h_samp_factor; |
244 | | |
245 | | /* Adjust xoffset to the nearest iMCU boundary <= the requested value */ |
246 | 1.88k | input_xoffset = *xoffset; |
247 | 1.88k | *xoffset = (input_xoffset / align) * align; |
248 | | |
249 | | /* Adjust the width so that the right edge of the output image is as |
250 | | * requested (only the left edge is altered.) It is important that calling |
251 | | * programs check this value after this function returns, so that they can |
252 | | * allocate an output buffer with the appropriate size. |
253 | | */ |
254 | 1.88k | *width = *width + input_xoffset - *xoffset; |
255 | 1.88k | cinfo->output_width = *width; |
256 | 1.88k | #ifdef UPSAMPLE_MERGING_SUPPORTED |
257 | 1.88k | if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) { |
258 | 0 | my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; |
259 | 0 | upsample->out_row_width = |
260 | 0 | cinfo->output_width * cinfo->out_color_components; |
261 | 0 | } |
262 | 1.88k | #endif |
263 | | |
264 | | /* Set the first and last iMCU columns that we must decompress. These values |
265 | | * will be used in single-scan decompressions. |
266 | | */ |
267 | 1.88k | cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align; |
268 | 1.88k | cinfo->master->last_iMCU_col = |
269 | 1.88k | (JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width), |
270 | 1.88k | (long)align) - 1; |
271 | | |
272 | 4.03k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
273 | 2.14k | ci++, compptr++) { |
274 | 2.14k | int hsf = (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) ? |
275 | 1.75k | 1 : compptr->h_samp_factor; |
276 | | |
277 | | /* Set downsampled_width to the new output width. */ |
278 | 2.14k | orig_downsampled_width = compptr->downsampled_width; |
279 | 2.14k | compptr->downsampled_width = |
280 | 2.14k | (JDIMENSION)jdiv_round_up((long)cinfo->output_width * |
281 | 2.14k | (long)(compptr->h_samp_factor * |
282 | 2.14k | compptr->_DCT_scaled_size), |
283 | 2.14k | (long)(cinfo->max_h_samp_factor * |
284 | 2.14k | cinfo->_min_DCT_scaled_size)); |
285 | 2.14k | if (compptr->downsampled_width < 2 && |
286 | 0 | #ifdef UPSAMPLE_MERGING_SUPPORTED |
287 | 0 | !master->using_merged_upsample && |
288 | 0 | #endif |
289 | 0 | orig_downsampled_width >= 2) |
290 | 0 | reinit_upsampler = TRUE; |
291 | | |
292 | | /* Set the first and last iMCU columns that we must decompress. These |
293 | | * values will be used in multi-scan decompressions. |
294 | | */ |
295 | 2.14k | cinfo->master->first_MCU_col[ci] = |
296 | 2.14k | (JDIMENSION)(long)(*xoffset * hsf) / (long)align; |
297 | 2.14k | cinfo->master->last_MCU_col[ci] = |
298 | 2.14k | (JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf), |
299 | 2.14k | (long)align) - 1; |
300 | 2.14k | } |
301 | | |
302 | 1.88k | if (reinit_upsampler) { |
303 | 0 | cinfo->master->jinit_upsampler_no_alloc = TRUE; |
304 | 0 | _jinit_upsampler(cinfo); |
305 | 0 | cinfo->master->jinit_upsampler_no_alloc = FALSE; |
306 | 0 | } |
307 | 1.88k | } Line | Count | Source | 191 | 1.02k | { | 192 | 1.02k | int ci, align, orig_downsampled_width; | 193 | 1.02k | JDIMENSION input_xoffset; | 194 | 1.02k | boolean reinit_upsampler = FALSE; | 195 | 1.02k | jpeg_component_info *compptr; | 196 | 1.02k | #ifdef UPSAMPLE_MERGING_SUPPORTED | 197 | 1.02k | my_master_ptr master = (my_master_ptr)cinfo->master; | 198 | 1.02k | #endif | 199 | | | 200 | 1.02k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 201 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 202 | | | 203 | 1.02k | if (cinfo->master->lossless || cinfo->raw_data_out) | 204 | 0 | ERREXIT(cinfo, JERR_NOTIMPL); | 205 | | | 206 | 1.02k | if ((cinfo->global_state != DSTATE_SCANNING && | 207 | 1.02k | cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0) | 208 | 0 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 209 | | | 210 | 1.02k | if (!xoffset || !width) | 211 | 0 | ERREXIT(cinfo, JERR_BAD_CROP_SPEC); | 212 | | | 213 | | /* xoffset and width must fall within the output image dimensions. */ | 214 | 1.02k | if (*width == 0 || | 215 | 1.02k | (unsigned long long)(*xoffset) + *width > cinfo->output_width) | 216 | 0 | ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); | 217 | | | 218 | | /* No need to do anything if the caller wants the entire width. */ | 219 | 1.02k | if (*width == cinfo->output_width) | 220 | 0 | return; | 221 | | | 222 | | /* Ensuring the proper alignment of xoffset is tricky. At minimum, it | 223 | | * must align with an MCU boundary, because: | 224 | | * | 225 | | * (1) The IDCT is performed in blocks, and it is not feasible to modify | 226 | | * the algorithm so that it can transform partial blocks. | 227 | | * (2) Because of the SIMD extensions, any input buffer passed to the | 228 | | * upsampling and color conversion routines must be aligned to the | 229 | | * SIMD word size (for instance, 128-bit in the case of SSE2.) The | 230 | | * easiest way to accomplish this without copying data is to ensure | 231 | | * that upsampling and color conversion begin at the start of the | 232 | | * first MCU column that will be inverse transformed. | 233 | | * | 234 | | * In practice, we actually impose a stricter alignment requirement. We | 235 | | * require that xoffset be a multiple of the maximum MCU column width of all | 236 | | * of the components (the "iMCU column width.") This is to simplify the | 237 | | * single-pass decompression case, allowing us to use the same MCU column | 238 | | * width for all of the components. | 239 | | */ | 240 | 1.02k | if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) | 241 | 966 | align = cinfo->_min_DCT_scaled_size; | 242 | 56 | else | 243 | 56 | align = cinfo->_min_DCT_scaled_size * cinfo->max_h_samp_factor; | 244 | | | 245 | | /* Adjust xoffset to the nearest iMCU boundary <= the requested value */ | 246 | 1.02k | input_xoffset = *xoffset; | 247 | 1.02k | *xoffset = (input_xoffset / align) * align; | 248 | | | 249 | | /* Adjust the width so that the right edge of the output image is as | 250 | | * requested (only the left edge is altered.) It is important that calling | 251 | | * programs check this value after this function returns, so that they can | 252 | | * allocate an output buffer with the appropriate size. | 253 | | */ | 254 | 1.02k | *width = *width + input_xoffset - *xoffset; | 255 | 1.02k | cinfo->output_width = *width; | 256 | 1.02k | #ifdef UPSAMPLE_MERGING_SUPPORTED | 257 | 1.02k | if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) { | 258 | 0 | my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; | 259 | 0 | upsample->out_row_width = | 260 | 0 | cinfo->output_width * cinfo->out_color_components; | 261 | 0 | } | 262 | 1.02k | #endif | 263 | | | 264 | | /* Set the first and last iMCU columns that we must decompress. These values | 265 | | * will be used in single-scan decompressions. | 266 | | */ | 267 | 1.02k | cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align; | 268 | 1.02k | cinfo->master->last_iMCU_col = | 269 | 1.02k | (JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width), | 270 | 1.02k | (long)align) - 1; | 271 | | | 272 | 2.15k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 273 | 1.13k | ci++, compptr++) { | 274 | 1.13k | int hsf = (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) ? | 275 | 966 | 1 : compptr->h_samp_factor; | 276 | | | 277 | | /* Set downsampled_width to the new output width. */ | 278 | 1.13k | orig_downsampled_width = compptr->downsampled_width; | 279 | 1.13k | compptr->downsampled_width = | 280 | 1.13k | (JDIMENSION)jdiv_round_up((long)cinfo->output_width * | 281 | 1.13k | (long)(compptr->h_samp_factor * | 282 | 1.13k | compptr->_DCT_scaled_size), | 283 | 1.13k | (long)(cinfo->max_h_samp_factor * | 284 | 1.13k | cinfo->_min_DCT_scaled_size)); | 285 | 1.13k | if (compptr->downsampled_width < 2 && | 286 | 0 | #ifdef UPSAMPLE_MERGING_SUPPORTED | 287 | 0 | !master->using_merged_upsample && | 288 | 0 | #endif | 289 | 0 | orig_downsampled_width >= 2) | 290 | 0 | reinit_upsampler = TRUE; | 291 | | | 292 | | /* Set the first and last iMCU columns that we must decompress. These | 293 | | * values will be used in multi-scan decompressions. | 294 | | */ | 295 | 1.13k | cinfo->master->first_MCU_col[ci] = | 296 | 1.13k | (JDIMENSION)(long)(*xoffset * hsf) / (long)align; | 297 | 1.13k | cinfo->master->last_MCU_col[ci] = | 298 | 1.13k | (JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf), | 299 | 1.13k | (long)align) - 1; | 300 | 1.13k | } | 301 | | | 302 | 1.02k | if (reinit_upsampler) { | 303 | 0 | cinfo->master->jinit_upsampler_no_alloc = TRUE; | 304 | 0 | _jinit_upsampler(cinfo); | 305 | 0 | cinfo->master->jinit_upsampler_no_alloc = FALSE; | 306 | 0 | } | 307 | 1.02k | } |
Line | Count | Source | 191 | 865 | { | 192 | 865 | int ci, align, orig_downsampled_width; | 193 | 865 | JDIMENSION input_xoffset; | 194 | 865 | boolean reinit_upsampler = FALSE; | 195 | 865 | jpeg_component_info *compptr; | 196 | 865 | #ifdef UPSAMPLE_MERGING_SUPPORTED | 197 | 865 | my_master_ptr master = (my_master_ptr)cinfo->master; | 198 | 865 | #endif | 199 | | | 200 | 865 | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 201 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 202 | | | 203 | 865 | if (cinfo->master->lossless || cinfo->raw_data_out) | 204 | 0 | ERREXIT(cinfo, JERR_NOTIMPL); | 205 | | | 206 | 865 | if ((cinfo->global_state != DSTATE_SCANNING && | 207 | 865 | cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0) | 208 | 0 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 209 | | | 210 | 865 | if (!xoffset || !width) | 211 | 0 | ERREXIT(cinfo, JERR_BAD_CROP_SPEC); | 212 | | | 213 | | /* xoffset and width must fall within the output image dimensions. */ | 214 | 865 | if (*width == 0 || | 215 | 865 | (unsigned long long)(*xoffset) + *width > cinfo->output_width) | 216 | 0 | ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); | 217 | | | 218 | | /* No need to do anything if the caller wants the entire width. */ | 219 | 865 | if (*width == cinfo->output_width) | 220 | 0 | return; | 221 | | | 222 | | /* Ensuring the proper alignment of xoffset is tricky. At minimum, it | 223 | | * must align with an MCU boundary, because: | 224 | | * | 225 | | * (1) The IDCT is performed in blocks, and it is not feasible to modify | 226 | | * the algorithm so that it can transform partial blocks. | 227 | | * (2) Because of the SIMD extensions, any input buffer passed to the | 228 | | * upsampling and color conversion routines must be aligned to the | 229 | | * SIMD word size (for instance, 128-bit in the case of SSE2.) The | 230 | | * easiest way to accomplish this without copying data is to ensure | 231 | | * that upsampling and color conversion begin at the start of the | 232 | | * first MCU column that will be inverse transformed. | 233 | | * | 234 | | * In practice, we actually impose a stricter alignment requirement. We | 235 | | * require that xoffset be a multiple of the maximum MCU column width of all | 236 | | * of the components (the "iMCU column width.") This is to simplify the | 237 | | * single-pass decompression case, allowing us to use the same MCU column | 238 | | * width for all of the components. | 239 | | */ | 240 | 865 | if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) | 241 | 791 | align = cinfo->_min_DCT_scaled_size; | 242 | 74 | else | 243 | 74 | align = cinfo->_min_DCT_scaled_size * cinfo->max_h_samp_factor; | 244 | | | 245 | | /* Adjust xoffset to the nearest iMCU boundary <= the requested value */ | 246 | 865 | input_xoffset = *xoffset; | 247 | 865 | *xoffset = (input_xoffset / align) * align; | 248 | | | 249 | | /* Adjust the width so that the right edge of the output image is as | 250 | | * requested (only the left edge is altered.) It is important that calling | 251 | | * programs check this value after this function returns, so that they can | 252 | | * allocate an output buffer with the appropriate size. | 253 | | */ | 254 | 865 | *width = *width + input_xoffset - *xoffset; | 255 | 865 | cinfo->output_width = *width; | 256 | 865 | #ifdef UPSAMPLE_MERGING_SUPPORTED | 257 | 865 | if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) { | 258 | 0 | my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; | 259 | 0 | upsample->out_row_width = | 260 | 0 | cinfo->output_width * cinfo->out_color_components; | 261 | 0 | } | 262 | 865 | #endif | 263 | | | 264 | | /* Set the first and last iMCU columns that we must decompress. These values | 265 | | * will be used in single-scan decompressions. | 266 | | */ | 267 | 865 | cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align; | 268 | 865 | cinfo->master->last_iMCU_col = | 269 | 865 | (JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width), | 270 | 865 | (long)align) - 1; | 271 | | | 272 | 1.87k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 273 | 1.01k | ci++, compptr++) { | 274 | 1.01k | int hsf = (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) ? | 275 | 791 | 1 : compptr->h_samp_factor; | 276 | | | 277 | | /* Set downsampled_width to the new output width. */ | 278 | 1.01k | orig_downsampled_width = compptr->downsampled_width; | 279 | 1.01k | compptr->downsampled_width = | 280 | 1.01k | (JDIMENSION)jdiv_round_up((long)cinfo->output_width * | 281 | 1.01k | (long)(compptr->h_samp_factor * | 282 | 1.01k | compptr->_DCT_scaled_size), | 283 | 1.01k | (long)(cinfo->max_h_samp_factor * | 284 | 1.01k | cinfo->_min_DCT_scaled_size)); | 285 | 1.01k | if (compptr->downsampled_width < 2 && | 286 | 0 | #ifdef UPSAMPLE_MERGING_SUPPORTED | 287 | 0 | !master->using_merged_upsample && | 288 | 0 | #endif | 289 | 0 | orig_downsampled_width >= 2) | 290 | 0 | reinit_upsampler = TRUE; | 291 | | | 292 | | /* Set the first and last iMCU columns that we must decompress. These | 293 | | * values will be used in multi-scan decompressions. | 294 | | */ | 295 | 1.01k | cinfo->master->first_MCU_col[ci] = | 296 | 1.01k | (JDIMENSION)(long)(*xoffset * hsf) / (long)align; | 297 | 1.01k | cinfo->master->last_MCU_col[ci] = | 298 | 1.01k | (JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf), | 299 | 1.01k | (long)align) - 1; | 300 | 1.01k | } | 301 | | | 302 | 865 | if (reinit_upsampler) { | 303 | 0 | cinfo->master->jinit_upsampler_no_alloc = TRUE; | 304 | 0 | _jinit_upsampler(cinfo); | 305 | 0 | cinfo->master->jinit_upsampler_no_alloc = FALSE; | 306 | 0 | } | 307 | 865 | } |
|
308 | | |
309 | | #endif /* BITS_IN_JSAMPLE != 16 */ |
310 | | |
311 | | |
312 | | /* |
313 | | * Read some scanlines of data from the JPEG decompressor. |
314 | | * |
315 | | * The return value will be the number of lines actually read. |
316 | | * This may be less than the number requested in several cases, |
317 | | * including bottom of image, data source suspension, and operating |
318 | | * modes that emit multiple scanlines at a time. |
319 | | * |
320 | | * Note: we warn about excess calls to _jpeg_read_scanlines() since |
321 | | * this likely signals an application programmer error. However, |
322 | | * an oversize buffer (max_lines > scanlines remaining) is not an error. |
323 | | */ |
324 | | |
325 | | GLOBAL(JDIMENSION) |
326 | | _jpeg_read_scanlines(j_decompress_ptr cinfo, _JSAMPARRAY scanlines, |
327 | | JDIMENSION max_lines) |
328 | 21.4M | { |
329 | 21.4M | #if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) |
330 | 21.4M | JDIMENSION row_ctr; |
331 | | |
332 | 21.4M | #ifdef D_LOSSLESS_SUPPORTED |
333 | 21.4M | if (cinfo->master->lossless) { |
334 | | #if BITS_IN_JSAMPLE == 8 |
335 | 1.97M | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) |
336 | | #else |
337 | 3.80M | if (cinfo->data_precision > BITS_IN_JSAMPLE || |
338 | 3.80M | cinfo->data_precision < BITS_IN_JSAMPLE - 3) |
339 | 89 | #endif |
340 | 89 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
341 | 5.77M | } else |
342 | 15.6M | #endif |
343 | 15.6M | { |
344 | 15.6M | if (cinfo->data_precision != BITS_IN_JSAMPLE) |
345 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
346 | 15.6M | } |
347 | | |
348 | 21.4M | if (cinfo->global_state != DSTATE_SCANNING) |
349 | 0 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
350 | 21.4M | if (cinfo->output_scanline >= cinfo->output_height) { |
351 | 0 | WARNMS(cinfo, JWRN_TOO_MUCH_DATA); |
352 | 0 | return 0; |
353 | 0 | } |
354 | | |
355 | | /* Call progress monitor hook if present */ |
356 | 21.4M | if (cinfo->progress != NULL) { |
357 | 21.4M | cinfo->progress->pass_counter = (long)cinfo->output_scanline; |
358 | 21.4M | cinfo->progress->pass_limit = (long)cinfo->output_height; |
359 | 21.4M | (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo); |
360 | 21.4M | } |
361 | | |
362 | | /* Process some data */ |
363 | 21.4M | row_ctr = 0; |
364 | 21.4M | if (cinfo->main->_process_data == NULL) |
365 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
366 | 21.4M | (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines); |
367 | 21.4M | cinfo->output_scanline += row_ctr; |
368 | 21.4M | return row_ctr; |
369 | | #else |
370 | | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
371 | | return 0; |
372 | | #endif |
373 | 21.4M | } Line | Count | Source | 328 | 10.8M | { | 329 | 10.8M | #if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) | 330 | 10.8M | JDIMENSION row_ctr; | 331 | | | 332 | 10.8M | #ifdef D_LOSSLESS_SUPPORTED | 333 | 10.8M | if (cinfo->master->lossless) { | 334 | 1.97M | #if BITS_IN_JSAMPLE == 8 | 335 | 1.97M | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 336 | | #else | 337 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 338 | | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 339 | | #endif | 340 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 341 | 1.97M | } else | 342 | 8.88M | #endif | 343 | 8.88M | { | 344 | 8.88M | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 345 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 346 | 8.88M | } | 347 | | | 348 | 10.8M | if (cinfo->global_state != DSTATE_SCANNING) | 349 | 0 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 350 | 10.8M | if (cinfo->output_scanline >= cinfo->output_height) { | 351 | 0 | WARNMS(cinfo, JWRN_TOO_MUCH_DATA); | 352 | 0 | return 0; | 353 | 0 | } | 354 | | | 355 | | /* Call progress monitor hook if present */ | 356 | 10.8M | if (cinfo->progress != NULL) { | 357 | 10.8M | cinfo->progress->pass_counter = (long)cinfo->output_scanline; | 358 | 10.8M | cinfo->progress->pass_limit = (long)cinfo->output_height; | 359 | 10.8M | (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo); | 360 | 10.8M | } | 361 | | | 362 | | /* Process some data */ | 363 | 10.8M | row_ctr = 0; | 364 | 10.8M | if (cinfo->main->_process_data == NULL) | 365 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 366 | 10.8M | (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines); | 367 | 10.8M | cinfo->output_scanline += row_ctr; | 368 | 10.8M | return row_ctr; | 369 | | #else | 370 | | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 371 | | return 0; | 372 | | #endif | 373 | 10.8M | } |
Line | Count | Source | 328 | 8.47M | { | 329 | 8.47M | #if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) | 330 | 8.47M | JDIMENSION row_ctr; | 331 | | | 332 | 8.47M | #ifdef D_LOSSLESS_SUPPORTED | 333 | 8.47M | if (cinfo->master->lossless) { | 334 | | #if BITS_IN_JSAMPLE == 8 | 335 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 336 | | #else | 337 | 1.66M | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 338 | 1.66M | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 339 | 0 | #endif | 340 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 341 | 1.66M | } else | 342 | 6.80M | #endif | 343 | 6.80M | { | 344 | 6.80M | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 345 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 346 | 6.80M | } | 347 | | | 348 | 8.47M | if (cinfo->global_state != DSTATE_SCANNING) | 349 | 0 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 350 | 8.47M | if (cinfo->output_scanline >= cinfo->output_height) { | 351 | 0 | WARNMS(cinfo, JWRN_TOO_MUCH_DATA); | 352 | 0 | return 0; | 353 | 0 | } | 354 | | | 355 | | /* Call progress monitor hook if present */ | 356 | 8.47M | if (cinfo->progress != NULL) { | 357 | 8.47M | cinfo->progress->pass_counter = (long)cinfo->output_scanline; | 358 | 8.47M | cinfo->progress->pass_limit = (long)cinfo->output_height; | 359 | 8.47M | (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo); | 360 | 8.47M | } | 361 | | | 362 | | /* Process some data */ | 363 | 8.47M | row_ctr = 0; | 364 | 8.47M | if (cinfo->main->_process_data == NULL) | 365 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 366 | 8.47M | (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines); | 367 | 8.47M | cinfo->output_scanline += row_ctr; | 368 | 8.47M | return row_ctr; | 369 | | #else | 370 | | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 371 | | return 0; | 372 | | #endif | 373 | 8.47M | } |
Line | Count | Source | 328 | 2.13M | { | 329 | 2.13M | #if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) | 330 | 2.13M | JDIMENSION row_ctr; | 331 | | | 332 | 2.13M | #ifdef D_LOSSLESS_SUPPORTED | 333 | 2.13M | if (cinfo->master->lossless) { | 334 | | #if BITS_IN_JSAMPLE == 8 | 335 | | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) | 336 | | #else | 337 | 2.13M | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 338 | 2.13M | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 339 | 89 | #endif | 340 | 89 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 341 | 2.13M | } else | 342 | 0 | #endif | 343 | 0 | { | 344 | 0 | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 345 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 346 | 0 | } | 347 | | | 348 | 2.13M | if (cinfo->global_state != DSTATE_SCANNING) | 349 | 0 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 350 | 2.13M | if (cinfo->output_scanline >= cinfo->output_height) { | 351 | 0 | WARNMS(cinfo, JWRN_TOO_MUCH_DATA); | 352 | 0 | return 0; | 353 | 0 | } | 354 | | | 355 | | /* Call progress monitor hook if present */ | 356 | 2.13M | if (cinfo->progress != NULL) { | 357 | 2.13M | cinfo->progress->pass_counter = (long)cinfo->output_scanline; | 358 | 2.13M | cinfo->progress->pass_limit = (long)cinfo->output_height; | 359 | 2.13M | (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo); | 360 | 2.13M | } | 361 | | | 362 | | /* Process some data */ | 363 | 2.13M | row_ctr = 0; | 364 | 2.13M | if (cinfo->main->_process_data == NULL) | 365 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 366 | 2.13M | (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines); | 367 | 2.13M | cinfo->output_scanline += row_ctr; | 368 | 2.13M | return row_ctr; | 369 | | #else | 370 | | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 371 | | return 0; | 372 | | #endif | 373 | 2.13M | } |
|
374 | | |
375 | | |
376 | | #if BITS_IN_JSAMPLE != 16 |
377 | | |
378 | | /* Dummy color convert function used by _jpeg_skip_scanlines() */ |
379 | | LOCAL(void) |
380 | | noop_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf, |
381 | | JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows) |
382 | 5.51k | { |
383 | 5.51k | } jdapistd-8.c:noop_convert Line | Count | Source | 382 | 2.52k | { | 383 | 2.52k | } |
jdapistd-12.c:noop_convert Line | Count | Source | 382 | 2.98k | { | 383 | 2.98k | } |
|
384 | | |
385 | | |
386 | | /* Dummy quantize function used by _jpeg_skip_scanlines() */ |
387 | | LOCAL(void) |
388 | | noop_quantize(j_decompress_ptr cinfo, _JSAMPARRAY input_buf, |
389 | | _JSAMPARRAY output_buf, int num_rows) |
390 | 0 | { |
391 | 0 | } Unexecuted instantiation: jdapistd-8.c:noop_quantize Unexecuted instantiation: jdapistd-12.c:noop_quantize |
392 | | |
393 | | |
394 | | /* |
395 | | * In some cases, it is best to call _jpeg_read_scanlines() and discard the |
396 | | * output, rather than skipping the scanlines, because this allows us to |
397 | | * maintain the internal state of the context-based upsampler. In these cases, |
398 | | * we set up and tear down a dummy color converter in order to avoid valgrind |
399 | | * errors and to achieve the best possible performance. |
400 | | */ |
401 | | |
402 | | LOCAL(void) |
403 | | read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines) |
404 | 1.88k | { |
405 | 1.88k | JDIMENSION n; |
406 | 1.88k | #ifdef UPSAMPLE_MERGING_SUPPORTED |
407 | 1.88k | my_master_ptr master = (my_master_ptr)cinfo->master; |
408 | 1.88k | #endif |
409 | 1.88k | _JSAMPLE dummy_sample[1] = { 0 }; |
410 | 1.88k | _JSAMPROW dummy_row = dummy_sample; |
411 | 1.88k | _JSAMPARRAY scanlines = NULL; |
412 | 1.88k | void (*color_convert) (j_decompress_ptr cinfo, _JSAMPIMAGE input_buf, |
413 | 1.88k | JDIMENSION input_row, _JSAMPARRAY output_buf, |
414 | 1.88k | int num_rows) = NULL; |
415 | 1.88k | void (*color_quantize) (j_decompress_ptr cinfo, _JSAMPARRAY input_buf, |
416 | 1.88k | _JSAMPARRAY output_buf, int num_rows) = NULL; |
417 | | |
418 | 1.88k | if (cinfo->cconvert && |
419 | 1.88k | #ifdef UPSAMPLE_MERGING_SUPPORTED |
420 | 1.88k | !master->using_merged_upsample && |
421 | 1.88k | #endif |
422 | 1.88k | cinfo->cconvert->_color_convert) { |
423 | 1.88k | color_convert = cinfo->cconvert->_color_convert; |
424 | 1.88k | cinfo->cconvert->_color_convert = noop_convert; |
425 | | /* This just prevents UBSan from complaining about adding 0 to a NULL |
426 | | * pointer. The pointer isn't actually used. |
427 | | */ |
428 | 1.88k | scanlines = &dummy_row; |
429 | 1.88k | } |
430 | | |
431 | 1.88k | if (cinfo->quantize_colors && cinfo->cquantize && |
432 | 0 | cinfo->cquantize->_color_quantize) { |
433 | 0 | color_quantize = cinfo->cquantize->_color_quantize; |
434 | 0 | cinfo->cquantize->_color_quantize = noop_quantize; |
435 | 0 | } |
436 | | |
437 | 1.88k | #ifdef UPSAMPLE_MERGING_SUPPORTED |
438 | 1.88k | if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) { |
439 | 0 | my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; |
440 | 0 | scanlines = &upsample->spare_row; |
441 | 0 | } |
442 | 1.88k | #endif |
443 | | |
444 | 7.39k | for (n = 0; n < num_lines; n++) |
445 | 5.51k | _jpeg_read_scanlines(cinfo, scanlines, 1); |
446 | | |
447 | 1.88k | if (color_convert) |
448 | 1.88k | cinfo->cconvert->_color_convert = color_convert; |
449 | | |
450 | 1.88k | if (color_quantize) |
451 | 0 | cinfo->cquantize->_color_quantize = color_quantize; |
452 | 1.88k | } jdapistd-8.c:read_and_discard_scanlines Line | Count | Source | 404 | 1.01k | { | 405 | 1.01k | JDIMENSION n; | 406 | 1.01k | #ifdef UPSAMPLE_MERGING_SUPPORTED | 407 | 1.01k | my_master_ptr master = (my_master_ptr)cinfo->master; | 408 | 1.01k | #endif | 409 | 1.01k | _JSAMPLE dummy_sample[1] = { 0 }; | 410 | 1.01k | _JSAMPROW dummy_row = dummy_sample; | 411 | 1.01k | _JSAMPARRAY scanlines = NULL; | 412 | 1.01k | void (*color_convert) (j_decompress_ptr cinfo, _JSAMPIMAGE input_buf, | 413 | 1.01k | JDIMENSION input_row, _JSAMPARRAY output_buf, | 414 | 1.01k | int num_rows) = NULL; | 415 | 1.01k | void (*color_quantize) (j_decompress_ptr cinfo, _JSAMPARRAY input_buf, | 416 | 1.01k | _JSAMPARRAY output_buf, int num_rows) = NULL; | 417 | | | 418 | 1.01k | if (cinfo->cconvert && | 419 | 1.01k | #ifdef UPSAMPLE_MERGING_SUPPORTED | 420 | 1.01k | !master->using_merged_upsample && | 421 | 1.01k | #endif | 422 | 1.01k | cinfo->cconvert->_color_convert) { | 423 | 1.01k | color_convert = cinfo->cconvert->_color_convert; | 424 | 1.01k | cinfo->cconvert->_color_convert = noop_convert; | 425 | | /* This just prevents UBSan from complaining about adding 0 to a NULL | 426 | | * pointer. The pointer isn't actually used. | 427 | | */ | 428 | 1.01k | scanlines = &dummy_row; | 429 | 1.01k | } | 430 | | | 431 | 1.01k | if (cinfo->quantize_colors && cinfo->cquantize && | 432 | 0 | cinfo->cquantize->_color_quantize) { | 433 | 0 | color_quantize = cinfo->cquantize->_color_quantize; | 434 | 0 | cinfo->cquantize->_color_quantize = noop_quantize; | 435 | 0 | } | 436 | | | 437 | 1.01k | #ifdef UPSAMPLE_MERGING_SUPPORTED | 438 | 1.01k | if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) { | 439 | 0 | my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; | 440 | 0 | scanlines = &upsample->spare_row; | 441 | 0 | } | 442 | 1.01k | #endif | 443 | | | 444 | 3.54k | for (n = 0; n < num_lines; n++) | 445 | 2.52k | _jpeg_read_scanlines(cinfo, scanlines, 1); | 446 | | | 447 | 1.01k | if (color_convert) | 448 | 1.01k | cinfo->cconvert->_color_convert = color_convert; | 449 | | | 450 | 1.01k | if (color_quantize) | 451 | 0 | cinfo->cquantize->_color_quantize = color_quantize; | 452 | 1.01k | } |
jdapistd-12.c:read_and_discard_scanlines Line | Count | Source | 404 | 862 | { | 405 | 862 | JDIMENSION n; | 406 | 862 | #ifdef UPSAMPLE_MERGING_SUPPORTED | 407 | 862 | my_master_ptr master = (my_master_ptr)cinfo->master; | 408 | 862 | #endif | 409 | 862 | _JSAMPLE dummy_sample[1] = { 0 }; | 410 | 862 | _JSAMPROW dummy_row = dummy_sample; | 411 | 862 | _JSAMPARRAY scanlines = NULL; | 412 | 862 | void (*color_convert) (j_decompress_ptr cinfo, _JSAMPIMAGE input_buf, | 413 | 862 | JDIMENSION input_row, _JSAMPARRAY output_buf, | 414 | 862 | int num_rows) = NULL; | 415 | 862 | void (*color_quantize) (j_decompress_ptr cinfo, _JSAMPARRAY input_buf, | 416 | 862 | _JSAMPARRAY output_buf, int num_rows) = NULL; | 417 | | | 418 | 862 | if (cinfo->cconvert && | 419 | 862 | #ifdef UPSAMPLE_MERGING_SUPPORTED | 420 | 862 | !master->using_merged_upsample && | 421 | 862 | #endif | 422 | 862 | cinfo->cconvert->_color_convert) { | 423 | 862 | color_convert = cinfo->cconvert->_color_convert; | 424 | 862 | cinfo->cconvert->_color_convert = noop_convert; | 425 | | /* This just prevents UBSan from complaining about adding 0 to a NULL | 426 | | * pointer. The pointer isn't actually used. | 427 | | */ | 428 | 862 | scanlines = &dummy_row; | 429 | 862 | } | 430 | | | 431 | 862 | if (cinfo->quantize_colors && cinfo->cquantize && | 432 | 0 | cinfo->cquantize->_color_quantize) { | 433 | 0 | color_quantize = cinfo->cquantize->_color_quantize; | 434 | 0 | cinfo->cquantize->_color_quantize = noop_quantize; | 435 | 0 | } | 436 | | | 437 | 862 | #ifdef UPSAMPLE_MERGING_SUPPORTED | 438 | 862 | if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) { | 439 | 0 | my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; | 440 | 0 | scanlines = &upsample->spare_row; | 441 | 0 | } | 442 | 862 | #endif | 443 | | | 444 | 3.85k | for (n = 0; n < num_lines; n++) | 445 | 2.98k | _jpeg_read_scanlines(cinfo, scanlines, 1); | 446 | | | 447 | 862 | if (color_convert) | 448 | 862 | cinfo->cconvert->_color_convert = color_convert; | 449 | | | 450 | 862 | if (color_quantize) | 451 | 0 | cinfo->cquantize->_color_quantize = color_quantize; | 452 | 862 | } |
|
453 | | |
454 | | |
455 | | /* |
456 | | * Called by _jpeg_skip_scanlines(). This partially skips a decompress block |
457 | | * by incrementing the rowgroup counter. |
458 | | */ |
459 | | |
460 | | LOCAL(void) |
461 | | increment_simple_rowgroup_ctr(j_decompress_ptr cinfo, JDIMENSION rows) |
462 | 1.84k | { |
463 | 1.84k | JDIMENSION rows_left; |
464 | 1.84k | my_main_ptr main_ptr = (my_main_ptr)cinfo->main; |
465 | | |
466 | 1.84k | if (!cinfo->upsample->need_context_rows && cinfo->max_v_samp_factor != 1) { |
467 | 958 | read_and_discard_scanlines(cinfo, rows); |
468 | 958 | return; |
469 | 958 | } |
470 | | |
471 | | /* Increment the counter to the next row group after the skipped rows. */ |
472 | 882 | main_ptr->rowgroup_ctr += rows / cinfo->max_v_samp_factor; |
473 | | |
474 | | /* Partially skipping a row group would involve modifying the internal state |
475 | | * of the upsampler, so read the remaining rows into a dummy buffer instead. |
476 | | */ |
477 | 882 | rows_left = rows % cinfo->max_v_samp_factor; |
478 | 882 | cinfo->output_scanline += rows - rows_left; |
479 | | |
480 | 882 | read_and_discard_scanlines(cinfo, rows_left); |
481 | 882 | } jdapistd-8.c:increment_simple_rowgroup_ctr Line | Count | Source | 462 | 1.00k | { | 463 | 1.00k | JDIMENSION rows_left; | 464 | 1.00k | my_main_ptr main_ptr = (my_main_ptr)cinfo->main; | 465 | | | 466 | 1.00k | if (!cinfo->upsample->need_context_rows && cinfo->max_v_samp_factor != 1) { | 467 | 471 | read_and_discard_scanlines(cinfo, rows); | 468 | 471 | return; | 469 | 471 | } | 470 | | | 471 | | /* Increment the counter to the next row group after the skipped rows. */ | 472 | 537 | main_ptr->rowgroup_ctr += rows / cinfo->max_v_samp_factor; | 473 | | | 474 | | /* Partially skipping a row group would involve modifying the internal state | 475 | | * of the upsampler, so read the remaining rows into a dummy buffer instead. | 476 | | */ | 477 | 537 | rows_left = rows % cinfo->max_v_samp_factor; | 478 | 537 | cinfo->output_scanline += rows - rows_left; | 479 | | | 480 | 537 | read_and_discard_scanlines(cinfo, rows_left); | 481 | 537 | } |
jdapistd-12.c:increment_simple_rowgroup_ctr Line | Count | Source | 462 | 832 | { | 463 | 832 | JDIMENSION rows_left; | 464 | 832 | my_main_ptr main_ptr = (my_main_ptr)cinfo->main; | 465 | | | 466 | 832 | if (!cinfo->upsample->need_context_rows && cinfo->max_v_samp_factor != 1) { | 467 | 487 | read_and_discard_scanlines(cinfo, rows); | 468 | 487 | return; | 469 | 487 | } | 470 | | | 471 | | /* Increment the counter to the next row group after the skipped rows. */ | 472 | 345 | main_ptr->rowgroup_ctr += rows / cinfo->max_v_samp_factor; | 473 | | | 474 | | /* Partially skipping a row group would involve modifying the internal state | 475 | | * of the upsampler, so read the remaining rows into a dummy buffer instead. | 476 | | */ | 477 | 345 | rows_left = rows % cinfo->max_v_samp_factor; | 478 | 345 | cinfo->output_scanline += rows - rows_left; | 479 | | | 480 | 345 | read_and_discard_scanlines(cinfo, rows_left); | 481 | 345 | } |
|
482 | | |
483 | | /* |
484 | | * Skips some scanlines of data from the JPEG decompressor. |
485 | | * |
486 | | * The return value will be the number of lines actually skipped. If skipping |
487 | | * num_lines would move beyond the end of the image, then the actual number of |
488 | | * lines remaining in the image is returned. Otherwise, the return value will |
489 | | * be equal to num_lines. |
490 | | * |
491 | | * Refer to libjpeg.txt for more information. |
492 | | */ |
493 | | |
494 | | GLOBAL(JDIMENSION) |
495 | | _jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines) |
496 | 3.74k | { |
497 | 3.74k | my_main_ptr main_ptr = (my_main_ptr)cinfo->main; |
498 | 3.74k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; |
499 | 3.74k | my_master_ptr master = (my_master_ptr)cinfo->master; |
500 | 3.74k | JDIMENSION i, x; |
501 | 3.74k | int y; |
502 | 3.74k | JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row; |
503 | 3.74k | JDIMENSION lines_to_skip, lines_to_read; |
504 | | |
505 | 3.74k | if (cinfo->data_precision != BITS_IN_JSAMPLE) |
506 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
507 | | |
508 | 3.74k | if (cinfo->master->lossless) |
509 | 0 | ERREXIT(cinfo, JERR_NOTIMPL); |
510 | | |
511 | | /* Two-pass color quantization is not supported. */ |
512 | 3.74k | if (cinfo->quantize_colors && cinfo->two_pass_quantize) |
513 | 0 | ERREXIT(cinfo, JERR_NOTIMPL); |
514 | | |
515 | 3.74k | if (cinfo->global_state != DSTATE_SCANNING) |
516 | 0 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
517 | | |
518 | | /* Do not skip past the bottom of the image. */ |
519 | 3.74k | if ((unsigned long long)cinfo->output_scanline + num_lines >= |
520 | 3.74k | cinfo->output_height) { |
521 | 1.86k | num_lines = cinfo->output_height - cinfo->output_scanline; |
522 | 1.86k | cinfo->output_scanline = cinfo->output_height; |
523 | 1.86k | (*cinfo->inputctl->finish_input_pass) (cinfo); |
524 | 1.86k | cinfo->inputctl->eoi_reached = TRUE; |
525 | 1.86k | return num_lines; |
526 | 1.86k | } |
527 | | |
528 | 1.88k | if (num_lines == 0) |
529 | 0 | return 0; |
530 | | |
531 | 1.88k | lines_per_iMCU_row = cinfo->_min_DCT_scaled_size * cinfo->max_v_samp_factor; |
532 | 1.88k | lines_left_in_iMCU_row = |
533 | 1.88k | (lines_per_iMCU_row - (cinfo->output_scanline % lines_per_iMCU_row)) % |
534 | 1.88k | lines_per_iMCU_row; |
535 | 1.88k | lines_after_iMCU_row = num_lines - lines_left_in_iMCU_row; |
536 | | |
537 | | /* Skip the lines remaining in the current iMCU row. When upsampling |
538 | | * requires context rows, we need the previous and next rows in order to read |
539 | | * the current row. This adds some complexity. |
540 | | */ |
541 | 1.88k | if (cinfo->upsample->need_context_rows) { |
542 | | /* If the skipped lines would not move us past the current iMCU row, we |
543 | | * read the lines and ignore them. There might be a faster way of doing |
544 | | * this, but we are facing increasing complexity for diminishing returns. |
545 | | * The increasing complexity would be a by-product of meddling with the |
546 | | * state machine used to skip context rows. Near the end of an iMCU row, |
547 | | * the next iMCU row may have already been entropy-decoded. In this unique |
548 | | * case, we will read the next iMCU row if we cannot skip past it as well. |
549 | | */ |
550 | 41 | if ((num_lines < lines_left_in_iMCU_row + 1) || |
551 | 41 | (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full && |
552 | 0 | lines_after_iMCU_row < lines_per_iMCU_row + 1)) { |
553 | 0 | read_and_discard_scanlines(cinfo, num_lines); |
554 | 0 | return num_lines; |
555 | 0 | } |
556 | | |
557 | | /* If the next iMCU row has already been entropy-decoded, make sure that |
558 | | * we do not skip too far. |
559 | | */ |
560 | 41 | if (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full) { |
561 | 0 | cinfo->output_scanline += lines_left_in_iMCU_row + lines_per_iMCU_row; |
562 | 0 | lines_after_iMCU_row -= lines_per_iMCU_row; |
563 | 41 | } else { |
564 | 41 | cinfo->output_scanline += lines_left_in_iMCU_row; |
565 | 41 | } |
566 | | |
567 | | /* If we have just completed the first block, adjust the buffer pointers */ |
568 | 41 | if (main_ptr->iMCU_row_ctr == 0 || |
569 | 0 | (main_ptr->iMCU_row_ctr == 1 && lines_left_in_iMCU_row > 2)) |
570 | 41 | set_wraparound_pointers(cinfo); |
571 | 41 | main_ptr->buffer_full = FALSE; |
572 | 41 | main_ptr->rowgroup_ctr = 0; |
573 | 41 | main_ptr->context_state = CTX_PREPARE_FOR_IMCU; |
574 | 41 | if (!master->using_merged_upsample) { |
575 | 41 | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; |
576 | 41 | upsample->next_row_out = cinfo->max_v_samp_factor; |
577 | 41 | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; |
578 | 41 | } |
579 | 41 | } |
580 | | |
581 | | /* Skipping is much simpler when context rows are not required. */ |
582 | 1.84k | else { |
583 | 1.84k | if (num_lines < lines_left_in_iMCU_row) { |
584 | 0 | increment_simple_rowgroup_ctr(cinfo, num_lines); |
585 | 0 | return num_lines; |
586 | 1.84k | } else { |
587 | 1.84k | cinfo->output_scanline += lines_left_in_iMCU_row; |
588 | 1.84k | main_ptr->buffer_full = FALSE; |
589 | 1.84k | main_ptr->rowgroup_ctr = 0; |
590 | 1.84k | #ifdef UPSAMPLE_MERGING_SUPPORTED |
591 | 1.84k | if (master->using_merged_upsample) { |
592 | 0 | my_merged_upsample_ptr upsample = |
593 | 0 | (my_merged_upsample_ptr)cinfo->upsample; |
594 | 0 | upsample->spare_full = FALSE; |
595 | 0 | } else |
596 | 1.84k | #endif |
597 | 1.84k | { |
598 | 1.84k | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; |
599 | 1.84k | upsample->next_row_out = cinfo->max_v_samp_factor; |
600 | 1.84k | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; |
601 | 1.84k | } |
602 | 1.84k | } |
603 | 1.84k | } |
604 | | |
605 | | /* Calculate how many full iMCU rows we can skip. */ |
606 | 1.88k | if (cinfo->upsample->need_context_rows) |
607 | 41 | lines_to_skip = ((lines_after_iMCU_row - 1) / lines_per_iMCU_row) * |
608 | 41 | lines_per_iMCU_row; |
609 | 1.84k | else |
610 | 1.84k | lines_to_skip = (lines_after_iMCU_row / lines_per_iMCU_row) * |
611 | 1.84k | lines_per_iMCU_row; |
612 | | /* Calculate the number of lines that remain to be skipped after skipping all |
613 | | * of the full iMCU rows that we can. We will not read these lines unless we |
614 | | * have to. |
615 | | */ |
616 | 1.88k | lines_to_read = lines_after_iMCU_row - lines_to_skip; |
617 | | |
618 | | /* For images requiring multiple scans (progressive, non-interleaved, etc.), |
619 | | * all of the entropy decoding occurs in jpeg_start_decompress(), assuming |
620 | | * that the input data source is non-suspending. This makes skipping easy. |
621 | | */ |
622 | 1.88k | if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) { |
623 | 1.06k | if (cinfo->upsample->need_context_rows) { |
624 | 10 | cinfo->output_scanline += lines_to_skip; |
625 | 10 | cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row; |
626 | 10 | main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row; |
627 | | /* It is complex to properly move to the middle of a context block, so |
628 | | * read the remaining lines instead of skipping them. |
629 | | */ |
630 | 10 | read_and_discard_scanlines(cinfo, lines_to_read); |
631 | 1.05k | } else { |
632 | 1.05k | cinfo->output_scanline += lines_to_skip; |
633 | 1.05k | cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row; |
634 | 1.05k | increment_simple_rowgroup_ctr(cinfo, lines_to_read); |
635 | 1.05k | } |
636 | 1.06k | #ifdef UPSAMPLE_MERGING_SUPPORTED |
637 | 1.06k | if (master->using_merged_upsample) { |
638 | 0 | my_merged_upsample_ptr upsample = |
639 | 0 | (my_merged_upsample_ptr)cinfo->upsample; |
640 | 0 | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; |
641 | 0 | } else |
642 | 1.06k | #endif |
643 | 1.06k | { |
644 | 1.06k | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; |
645 | 1.06k | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; |
646 | 1.06k | } |
647 | 1.06k | return num_lines; |
648 | 1.06k | } |
649 | | |
650 | | /* Skip the iMCU rows that we can safely skip. */ |
651 | 2.27k | for (i = 0; i < lines_to_skip; i += lines_per_iMCU_row) { |
652 | 3.38k | for (y = 0; y < coef->MCU_rows_per_iMCU_row; y++) { |
653 | 287k | for (x = 0; x < cinfo->MCUs_per_row; x++) { |
654 | | /* Calling decode_mcu() with a NULL pointer causes it to discard the |
655 | | * decoded coefficients. This is ~5% faster for large subsets, but |
656 | | * it's tough to tell a difference for smaller images. |
657 | | */ |
658 | 285k | if (!cinfo->entropy->insufficient_data) |
659 | 135k | cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row; |
660 | | #ifdef WITH_PROFILE |
661 | | cinfo->master->start = getTime(); |
662 | | #endif |
663 | 285k | (*cinfo->entropy->decode_mcu) (cinfo, NULL); |
664 | | #ifdef WITH_PROFILE |
665 | | cinfo->master->entropy_elapsed += getTime() - cinfo->master->start; |
666 | | cinfo->master->entropy_mcoeffs += |
667 | | (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.; |
668 | | #endif |
669 | 285k | } |
670 | 1.93k | } |
671 | 1.45k | cinfo->input_iMCU_row++; |
672 | 1.45k | cinfo->output_iMCU_row++; |
673 | 1.45k | if (cinfo->input_iMCU_row < cinfo->total_iMCU_rows) |
674 | 1.45k | start_iMCU_row(cinfo); |
675 | 0 | else |
676 | 0 | (*cinfo->inputctl->finish_input_pass) (cinfo); |
677 | 1.45k | } |
678 | 819 | cinfo->output_scanline += lines_to_skip; |
679 | | |
680 | 819 | if (cinfo->upsample->need_context_rows) { |
681 | | /* Context-based upsampling keeps track of iMCU rows. */ |
682 | 31 | main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row; |
683 | | |
684 | | /* It is complex to properly move to the middle of a context block, so |
685 | | * read the remaining lines instead of skipping them. |
686 | | */ |
687 | 31 | read_and_discard_scanlines(cinfo, lines_to_read); |
688 | 788 | } else { |
689 | 788 | increment_simple_rowgroup_ctr(cinfo, lines_to_read); |
690 | 788 | } |
691 | | |
692 | | /* Since skipping lines involves skipping the upsampling step, the value of |
693 | | * "rows_to_go" will become invalid unless we set it here. NOTE: This is a |
694 | | * bit odd, since "rows_to_go" seems to be redundantly keeping track of |
695 | | * output_scanline. |
696 | | */ |
697 | 819 | #ifdef UPSAMPLE_MERGING_SUPPORTED |
698 | 819 | if (master->using_merged_upsample) { |
699 | 0 | my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; |
700 | 0 | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; |
701 | 0 | } else |
702 | 819 | #endif |
703 | 819 | { |
704 | 819 | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; |
705 | 819 | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; |
706 | 819 | } |
707 | | |
708 | | /* Always skip the requested number of lines. */ |
709 | 819 | return num_lines; |
710 | 1.88k | } Line | Count | Source | 496 | 2.02k | { | 497 | 2.02k | my_main_ptr main_ptr = (my_main_ptr)cinfo->main; | 498 | 2.02k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; | 499 | 2.02k | my_master_ptr master = (my_master_ptr)cinfo->master; | 500 | 2.02k | JDIMENSION i, x; | 501 | 2.02k | int y; | 502 | 2.02k | JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row; | 503 | 2.02k | JDIMENSION lines_to_skip, lines_to_read; | 504 | | | 505 | 2.02k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 506 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 507 | | | 508 | 2.02k | if (cinfo->master->lossless) | 509 | 0 | ERREXIT(cinfo, JERR_NOTIMPL); | 510 | | | 511 | | /* Two-pass color quantization is not supported. */ | 512 | 2.02k | if (cinfo->quantize_colors && cinfo->two_pass_quantize) | 513 | 0 | ERREXIT(cinfo, JERR_NOTIMPL); | 514 | | | 515 | 2.02k | if (cinfo->global_state != DSTATE_SCANNING) | 516 | 0 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 517 | | | 518 | | /* Do not skip past the bottom of the image. */ | 519 | 2.02k | if ((unsigned long long)cinfo->output_scanline + num_lines >= | 520 | 2.02k | cinfo->output_height) { | 521 | 1.00k | num_lines = cinfo->output_height - cinfo->output_scanline; | 522 | 1.00k | cinfo->output_scanline = cinfo->output_height; | 523 | 1.00k | (*cinfo->inputctl->finish_input_pass) (cinfo); | 524 | 1.00k | cinfo->inputctl->eoi_reached = TRUE; | 525 | 1.00k | return num_lines; | 526 | 1.00k | } | 527 | | | 528 | 1.01k | if (num_lines == 0) | 529 | 0 | return 0; | 530 | | | 531 | 1.01k | lines_per_iMCU_row = cinfo->_min_DCT_scaled_size * cinfo->max_v_samp_factor; | 532 | 1.01k | lines_left_in_iMCU_row = | 533 | 1.01k | (lines_per_iMCU_row - (cinfo->output_scanline % lines_per_iMCU_row)) % | 534 | 1.01k | lines_per_iMCU_row; | 535 | 1.01k | lines_after_iMCU_row = num_lines - lines_left_in_iMCU_row; | 536 | | | 537 | | /* Skip the lines remaining in the current iMCU row. When upsampling | 538 | | * requires context rows, we need the previous and next rows in order to read | 539 | | * the current row. This adds some complexity. | 540 | | */ | 541 | 1.01k | if (cinfo->upsample->need_context_rows) { | 542 | | /* If the skipped lines would not move us past the current iMCU row, we | 543 | | * read the lines and ignore them. There might be a faster way of doing | 544 | | * this, but we are facing increasing complexity for diminishing returns. | 545 | | * The increasing complexity would be a by-product of meddling with the | 546 | | * state machine used to skip context rows. Near the end of an iMCU row, | 547 | | * the next iMCU row may have already been entropy-decoded. In this unique | 548 | | * case, we will read the next iMCU row if we cannot skip past it as well. | 549 | | */ | 550 | 11 | if ((num_lines < lines_left_in_iMCU_row + 1) || | 551 | 11 | (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full && | 552 | 0 | lines_after_iMCU_row < lines_per_iMCU_row + 1)) { | 553 | 0 | read_and_discard_scanlines(cinfo, num_lines); | 554 | 0 | return num_lines; | 555 | 0 | } | 556 | | | 557 | | /* If the next iMCU row has already been entropy-decoded, make sure that | 558 | | * we do not skip too far. | 559 | | */ | 560 | 11 | if (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full) { | 561 | 0 | cinfo->output_scanline += lines_left_in_iMCU_row + lines_per_iMCU_row; | 562 | 0 | lines_after_iMCU_row -= lines_per_iMCU_row; | 563 | 11 | } else { | 564 | 11 | cinfo->output_scanline += lines_left_in_iMCU_row; | 565 | 11 | } | 566 | | | 567 | | /* If we have just completed the first block, adjust the buffer pointers */ | 568 | 11 | if (main_ptr->iMCU_row_ctr == 0 || | 569 | 0 | (main_ptr->iMCU_row_ctr == 1 && lines_left_in_iMCU_row > 2)) | 570 | 11 | set_wraparound_pointers(cinfo); | 571 | 11 | main_ptr->buffer_full = FALSE; | 572 | 11 | main_ptr->rowgroup_ctr = 0; | 573 | 11 | main_ptr->context_state = CTX_PREPARE_FOR_IMCU; | 574 | 11 | if (!master->using_merged_upsample) { | 575 | 11 | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; | 576 | 11 | upsample->next_row_out = cinfo->max_v_samp_factor; | 577 | 11 | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; | 578 | 11 | } | 579 | 11 | } | 580 | | | 581 | | /* Skipping is much simpler when context rows are not required. */ | 582 | 1.00k | else { | 583 | 1.00k | if (num_lines < lines_left_in_iMCU_row) { | 584 | 0 | increment_simple_rowgroup_ctr(cinfo, num_lines); | 585 | 0 | return num_lines; | 586 | 1.00k | } else { | 587 | 1.00k | cinfo->output_scanline += lines_left_in_iMCU_row; | 588 | 1.00k | main_ptr->buffer_full = FALSE; | 589 | 1.00k | main_ptr->rowgroup_ctr = 0; | 590 | 1.00k | #ifdef UPSAMPLE_MERGING_SUPPORTED | 591 | 1.00k | if (master->using_merged_upsample) { | 592 | 0 | my_merged_upsample_ptr upsample = | 593 | 0 | (my_merged_upsample_ptr)cinfo->upsample; | 594 | 0 | upsample->spare_full = FALSE; | 595 | 0 | } else | 596 | 1.00k | #endif | 597 | 1.00k | { | 598 | 1.00k | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; | 599 | 1.00k | upsample->next_row_out = cinfo->max_v_samp_factor; | 600 | 1.00k | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; | 601 | 1.00k | } | 602 | 1.00k | } | 603 | 1.00k | } | 604 | | | 605 | | /* Calculate how many full iMCU rows we can skip. */ | 606 | 1.01k | if (cinfo->upsample->need_context_rows) | 607 | 11 | lines_to_skip = ((lines_after_iMCU_row - 1) / lines_per_iMCU_row) * | 608 | 11 | lines_per_iMCU_row; | 609 | 1.00k | else | 610 | 1.00k | lines_to_skip = (lines_after_iMCU_row / lines_per_iMCU_row) * | 611 | 1.00k | lines_per_iMCU_row; | 612 | | /* Calculate the number of lines that remain to be skipped after skipping all | 613 | | * of the full iMCU rows that we can. We will not read these lines unless we | 614 | | * have to. | 615 | | */ | 616 | 1.01k | lines_to_read = lines_after_iMCU_row - lines_to_skip; | 617 | | | 618 | | /* For images requiring multiple scans (progressive, non-interleaved, etc.), | 619 | | * all of the entropy decoding occurs in jpeg_start_decompress(), assuming | 620 | | * that the input data source is non-suspending. This makes skipping easy. | 621 | | */ | 622 | 1.01k | if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) { | 623 | 561 | if (cinfo->upsample->need_context_rows) { | 624 | 5 | cinfo->output_scanline += lines_to_skip; | 625 | 5 | cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row; | 626 | 5 | main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row; | 627 | | /* It is complex to properly move to the middle of a context block, so | 628 | | * read the remaining lines instead of skipping them. | 629 | | */ | 630 | 5 | read_and_discard_scanlines(cinfo, lines_to_read); | 631 | 556 | } else { | 632 | 556 | cinfo->output_scanline += lines_to_skip; | 633 | 556 | cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row; | 634 | 556 | increment_simple_rowgroup_ctr(cinfo, lines_to_read); | 635 | 556 | } | 636 | 561 | #ifdef UPSAMPLE_MERGING_SUPPORTED | 637 | 561 | if (master->using_merged_upsample) { | 638 | 0 | my_merged_upsample_ptr upsample = | 639 | 0 | (my_merged_upsample_ptr)cinfo->upsample; | 640 | 0 | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; | 641 | 0 | } else | 642 | 561 | #endif | 643 | 561 | { | 644 | 561 | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; | 645 | 561 | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; | 646 | 561 | } | 647 | 561 | return num_lines; | 648 | 561 | } | 649 | | | 650 | | /* Skip the iMCU rows that we can safely skip. */ | 651 | 1.35k | for (i = 0; i < lines_to_skip; i += lines_per_iMCU_row) { | 652 | 2.02k | for (y = 0; y < coef->MCU_rows_per_iMCU_row; y++) { | 653 | 149k | for (x = 0; x < cinfo->MCUs_per_row; x++) { | 654 | | /* Calling decode_mcu() with a NULL pointer causes it to discard the | 655 | | * decoded coefficients. This is ~5% faster for large subsets, but | 656 | | * it's tough to tell a difference for smaller images. | 657 | | */ | 658 | 148k | if (!cinfo->entropy->insufficient_data) | 659 | 58.7k | cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row; | 660 | | #ifdef WITH_PROFILE | 661 | | cinfo->master->start = getTime(); | 662 | | #endif | 663 | 148k | (*cinfo->entropy->decode_mcu) (cinfo, NULL); | 664 | | #ifdef WITH_PROFILE | 665 | | cinfo->master->entropy_elapsed += getTime() - cinfo->master->start; | 666 | | cinfo->master->entropy_mcoeffs += | 667 | | (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.; | 668 | | #endif | 669 | 148k | } | 670 | 1.13k | } | 671 | 893 | cinfo->input_iMCU_row++; | 672 | 893 | cinfo->output_iMCU_row++; | 673 | 893 | if (cinfo->input_iMCU_row < cinfo->total_iMCU_rows) | 674 | 893 | start_iMCU_row(cinfo); | 675 | 0 | else | 676 | 0 | (*cinfo->inputctl->finish_input_pass) (cinfo); | 677 | 893 | } | 678 | 458 | cinfo->output_scanline += lines_to_skip; | 679 | | | 680 | 458 | if (cinfo->upsample->need_context_rows) { | 681 | | /* Context-based upsampling keeps track of iMCU rows. */ | 682 | 6 | main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row; | 683 | | | 684 | | /* It is complex to properly move to the middle of a context block, so | 685 | | * read the remaining lines instead of skipping them. | 686 | | */ | 687 | 6 | read_and_discard_scanlines(cinfo, lines_to_read); | 688 | 452 | } else { | 689 | 452 | increment_simple_rowgroup_ctr(cinfo, lines_to_read); | 690 | 452 | } | 691 | | | 692 | | /* Since skipping lines involves skipping the upsampling step, the value of | 693 | | * "rows_to_go" will become invalid unless we set it here. NOTE: This is a | 694 | | * bit odd, since "rows_to_go" seems to be redundantly keeping track of | 695 | | * output_scanline. | 696 | | */ | 697 | 458 | #ifdef UPSAMPLE_MERGING_SUPPORTED | 698 | 458 | if (master->using_merged_upsample) { | 699 | 0 | my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; | 700 | 0 | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; | 701 | 0 | } else | 702 | 458 | #endif | 703 | 458 | { | 704 | 458 | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; | 705 | 458 | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; | 706 | 458 | } | 707 | | | 708 | | /* Always skip the requested number of lines. */ | 709 | 458 | return num_lines; | 710 | 1.01k | } |
Line | Count | Source | 496 | 1.71k | { | 497 | 1.71k | my_main_ptr main_ptr = (my_main_ptr)cinfo->main; | 498 | 1.71k | my_coef_ptr coef = (my_coef_ptr)cinfo->coef; | 499 | 1.71k | my_master_ptr master = (my_master_ptr)cinfo->master; | 500 | 1.71k | JDIMENSION i, x; | 501 | 1.71k | int y; | 502 | 1.71k | JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row; | 503 | 1.71k | JDIMENSION lines_to_skip, lines_to_read; | 504 | | | 505 | 1.71k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 506 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 507 | | | 508 | 1.71k | if (cinfo->master->lossless) | 509 | 0 | ERREXIT(cinfo, JERR_NOTIMPL); | 510 | | | 511 | | /* Two-pass color quantization is not supported. */ | 512 | 1.71k | if (cinfo->quantize_colors && cinfo->two_pass_quantize) | 513 | 0 | ERREXIT(cinfo, JERR_NOTIMPL); | 514 | | | 515 | 1.71k | if (cinfo->global_state != DSTATE_SCANNING) | 516 | 0 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); | 517 | | | 518 | | /* Do not skip past the bottom of the image. */ | 519 | 1.71k | if ((unsigned long long)cinfo->output_scanline + num_lines >= | 520 | 1.71k | cinfo->output_height) { | 521 | 856 | num_lines = cinfo->output_height - cinfo->output_scanline; | 522 | 856 | cinfo->output_scanline = cinfo->output_height; | 523 | 856 | (*cinfo->inputctl->finish_input_pass) (cinfo); | 524 | 856 | cinfo->inputctl->eoi_reached = TRUE; | 525 | 856 | return num_lines; | 526 | 856 | } | 527 | | | 528 | 862 | if (num_lines == 0) | 529 | 0 | return 0; | 530 | | | 531 | 862 | lines_per_iMCU_row = cinfo->_min_DCT_scaled_size * cinfo->max_v_samp_factor; | 532 | 862 | lines_left_in_iMCU_row = | 533 | 862 | (lines_per_iMCU_row - (cinfo->output_scanline % lines_per_iMCU_row)) % | 534 | 862 | lines_per_iMCU_row; | 535 | 862 | lines_after_iMCU_row = num_lines - lines_left_in_iMCU_row; | 536 | | | 537 | | /* Skip the lines remaining in the current iMCU row. When upsampling | 538 | | * requires context rows, we need the previous and next rows in order to read | 539 | | * the current row. This adds some complexity. | 540 | | */ | 541 | 862 | if (cinfo->upsample->need_context_rows) { | 542 | | /* If the skipped lines would not move us past the current iMCU row, we | 543 | | * read the lines and ignore them. There might be a faster way of doing | 544 | | * this, but we are facing increasing complexity for diminishing returns. | 545 | | * The increasing complexity would be a by-product of meddling with the | 546 | | * state machine used to skip context rows. Near the end of an iMCU row, | 547 | | * the next iMCU row may have already been entropy-decoded. In this unique | 548 | | * case, we will read the next iMCU row if we cannot skip past it as well. | 549 | | */ | 550 | 30 | if ((num_lines < lines_left_in_iMCU_row + 1) || | 551 | 30 | (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full && | 552 | 0 | lines_after_iMCU_row < lines_per_iMCU_row + 1)) { | 553 | 0 | read_and_discard_scanlines(cinfo, num_lines); | 554 | 0 | return num_lines; | 555 | 0 | } | 556 | | | 557 | | /* If the next iMCU row has already been entropy-decoded, make sure that | 558 | | * we do not skip too far. | 559 | | */ | 560 | 30 | if (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full) { | 561 | 0 | cinfo->output_scanline += lines_left_in_iMCU_row + lines_per_iMCU_row; | 562 | 0 | lines_after_iMCU_row -= lines_per_iMCU_row; | 563 | 30 | } else { | 564 | 30 | cinfo->output_scanline += lines_left_in_iMCU_row; | 565 | 30 | } | 566 | | | 567 | | /* If we have just completed the first block, adjust the buffer pointers */ | 568 | 30 | if (main_ptr->iMCU_row_ctr == 0 || | 569 | 0 | (main_ptr->iMCU_row_ctr == 1 && lines_left_in_iMCU_row > 2)) | 570 | 30 | set_wraparound_pointers(cinfo); | 571 | 30 | main_ptr->buffer_full = FALSE; | 572 | 30 | main_ptr->rowgroup_ctr = 0; | 573 | 30 | main_ptr->context_state = CTX_PREPARE_FOR_IMCU; | 574 | 30 | if (!master->using_merged_upsample) { | 575 | 30 | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; | 576 | 30 | upsample->next_row_out = cinfo->max_v_samp_factor; | 577 | 30 | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; | 578 | 30 | } | 579 | 30 | } | 580 | | | 581 | | /* Skipping is much simpler when context rows are not required. */ | 582 | 832 | else { | 583 | 832 | if (num_lines < lines_left_in_iMCU_row) { | 584 | 0 | increment_simple_rowgroup_ctr(cinfo, num_lines); | 585 | 0 | return num_lines; | 586 | 832 | } else { | 587 | 832 | cinfo->output_scanline += lines_left_in_iMCU_row; | 588 | 832 | main_ptr->buffer_full = FALSE; | 589 | 832 | main_ptr->rowgroup_ctr = 0; | 590 | 832 | #ifdef UPSAMPLE_MERGING_SUPPORTED | 591 | 832 | if (master->using_merged_upsample) { | 592 | 0 | my_merged_upsample_ptr upsample = | 593 | 0 | (my_merged_upsample_ptr)cinfo->upsample; | 594 | 0 | upsample->spare_full = FALSE; | 595 | 0 | } else | 596 | 832 | #endif | 597 | 832 | { | 598 | 832 | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; | 599 | 832 | upsample->next_row_out = cinfo->max_v_samp_factor; | 600 | 832 | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; | 601 | 832 | } | 602 | 832 | } | 603 | 832 | } | 604 | | | 605 | | /* Calculate how many full iMCU rows we can skip. */ | 606 | 862 | if (cinfo->upsample->need_context_rows) | 607 | 30 | lines_to_skip = ((lines_after_iMCU_row - 1) / lines_per_iMCU_row) * | 608 | 30 | lines_per_iMCU_row; | 609 | 832 | else | 610 | 832 | lines_to_skip = (lines_after_iMCU_row / lines_per_iMCU_row) * | 611 | 832 | lines_per_iMCU_row; | 612 | | /* Calculate the number of lines that remain to be skipped after skipping all | 613 | | * of the full iMCU rows that we can. We will not read these lines unless we | 614 | | * have to. | 615 | | */ | 616 | 862 | lines_to_read = lines_after_iMCU_row - lines_to_skip; | 617 | | | 618 | | /* For images requiring multiple scans (progressive, non-interleaved, etc.), | 619 | | * all of the entropy decoding occurs in jpeg_start_decompress(), assuming | 620 | | * that the input data source is non-suspending. This makes skipping easy. | 621 | | */ | 622 | 862 | if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) { | 623 | 501 | if (cinfo->upsample->need_context_rows) { | 624 | 5 | cinfo->output_scanline += lines_to_skip; | 625 | 5 | cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row; | 626 | 5 | main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row; | 627 | | /* It is complex to properly move to the middle of a context block, so | 628 | | * read the remaining lines instead of skipping them. | 629 | | */ | 630 | 5 | read_and_discard_scanlines(cinfo, lines_to_read); | 631 | 496 | } else { | 632 | 496 | cinfo->output_scanline += lines_to_skip; | 633 | 496 | cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row; | 634 | 496 | increment_simple_rowgroup_ctr(cinfo, lines_to_read); | 635 | 496 | } | 636 | 501 | #ifdef UPSAMPLE_MERGING_SUPPORTED | 637 | 501 | if (master->using_merged_upsample) { | 638 | 0 | my_merged_upsample_ptr upsample = | 639 | 0 | (my_merged_upsample_ptr)cinfo->upsample; | 640 | 0 | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; | 641 | 0 | } else | 642 | 501 | #endif | 643 | 501 | { | 644 | 501 | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; | 645 | 501 | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; | 646 | 501 | } | 647 | 501 | return num_lines; | 648 | 501 | } | 649 | | | 650 | | /* Skip the iMCU rows that we can safely skip. */ | 651 | 920 | for (i = 0; i < lines_to_skip; i += lines_per_iMCU_row) { | 652 | 1.36k | for (y = 0; y < coef->MCU_rows_per_iMCU_row; y++) { | 653 | 138k | for (x = 0; x < cinfo->MCUs_per_row; x++) { | 654 | | /* Calling decode_mcu() with a NULL pointer causes it to discard the | 655 | | * decoded coefficients. This is ~5% faster for large subsets, but | 656 | | * it's tough to tell a difference for smaller images. | 657 | | */ | 658 | 137k | if (!cinfo->entropy->insufficient_data) | 659 | 76.5k | cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row; | 660 | | #ifdef WITH_PROFILE | 661 | | cinfo->master->start = getTime(); | 662 | | #endif | 663 | 137k | (*cinfo->entropy->decode_mcu) (cinfo, NULL); | 664 | | #ifdef WITH_PROFILE | 665 | | cinfo->master->entropy_elapsed += getTime() - cinfo->master->start; | 666 | | cinfo->master->entropy_mcoeffs += | 667 | | (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.; | 668 | | #endif | 669 | 137k | } | 670 | 803 | } | 671 | 559 | cinfo->input_iMCU_row++; | 672 | 559 | cinfo->output_iMCU_row++; | 673 | 559 | if (cinfo->input_iMCU_row < cinfo->total_iMCU_rows) | 674 | 559 | start_iMCU_row(cinfo); | 675 | 0 | else | 676 | 0 | (*cinfo->inputctl->finish_input_pass) (cinfo); | 677 | 559 | } | 678 | 361 | cinfo->output_scanline += lines_to_skip; | 679 | | | 680 | 361 | if (cinfo->upsample->need_context_rows) { | 681 | | /* Context-based upsampling keeps track of iMCU rows. */ | 682 | 25 | main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row; | 683 | | | 684 | | /* It is complex to properly move to the middle of a context block, so | 685 | | * read the remaining lines instead of skipping them. | 686 | | */ | 687 | 25 | read_and_discard_scanlines(cinfo, lines_to_read); | 688 | 336 | } else { | 689 | 336 | increment_simple_rowgroup_ctr(cinfo, lines_to_read); | 690 | 336 | } | 691 | | | 692 | | /* Since skipping lines involves skipping the upsampling step, the value of | 693 | | * "rows_to_go" will become invalid unless we set it here. NOTE: This is a | 694 | | * bit odd, since "rows_to_go" seems to be redundantly keeping track of | 695 | | * output_scanline. | 696 | | */ | 697 | 361 | #ifdef UPSAMPLE_MERGING_SUPPORTED | 698 | 361 | if (master->using_merged_upsample) { | 699 | 0 | my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample; | 700 | 0 | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; | 701 | 0 | } else | 702 | 361 | #endif | 703 | 361 | { | 704 | 361 | my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample; | 705 | 361 | upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline; | 706 | 361 | } | 707 | | | 708 | | /* Always skip the requested number of lines. */ | 709 | 361 | return num_lines; | 710 | 862 | } |
|
711 | | |
712 | | /* |
713 | | * Alternate entry point to read raw data. |
714 | | * Processes exactly one iMCU row per call, unless suspended. |
715 | | */ |
716 | | |
717 | | GLOBAL(JDIMENSION) |
718 | | _jpeg_read_raw_data(j_decompress_ptr cinfo, _JSAMPIMAGE data, |
719 | | JDIMENSION max_lines) |
720 | 0 | { |
721 | 0 | JDIMENSION lines_per_iMCU_row; |
722 | |
|
723 | 0 | if (cinfo->data_precision != BITS_IN_JSAMPLE) |
724 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
725 | |
|
726 | 0 | if (cinfo->master->lossless) |
727 | 0 | ERREXIT(cinfo, JERR_NOTIMPL); |
728 | |
|
729 | 0 | if (cinfo->global_state != DSTATE_RAW_OK) |
730 | 0 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
731 | 0 | if (cinfo->output_scanline >= cinfo->output_height) { |
732 | 0 | WARNMS(cinfo, JWRN_TOO_MUCH_DATA); |
733 | 0 | return 0; |
734 | 0 | } |
735 | | |
736 | | /* Call progress monitor hook if present */ |
737 | 0 | if (cinfo->progress != NULL) { |
738 | 0 | cinfo->progress->pass_counter = (long)cinfo->output_scanline; |
739 | 0 | cinfo->progress->pass_limit = (long)cinfo->output_height; |
740 | 0 | (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo); |
741 | 0 | } |
742 | | |
743 | | /* Verify that at least one iMCU row can be returned. */ |
744 | 0 | lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size; |
745 | 0 | if (max_lines < lines_per_iMCU_row) |
746 | 0 | ERREXIT(cinfo, JERR_BUFFER_SIZE); |
747 | | |
748 | | /* Decompress directly into user's buffer. */ |
749 | 0 | if (cinfo->coef->_decompress_data == NULL) |
750 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
751 | 0 | if (!(*cinfo->coef->_decompress_data) (cinfo, data)) |
752 | 0 | return 0; /* suspension forced, can do nothing more */ |
753 | | |
754 | | /* OK, we processed one iMCU row. */ |
755 | 0 | cinfo->output_scanline += lines_per_iMCU_row; |
756 | 0 | return lines_per_iMCU_row; |
757 | 0 | } Unexecuted instantiation: jpeg_read_raw_data Unexecuted instantiation: jpeg12_read_raw_data |
758 | | |
759 | | #endif /* BITS_IN_JSAMPLE != 16 */ |
760 | | |
761 | | |
762 | | #if BITS_IN_JSAMPLE == 8 |
763 | | |
764 | | /* Additional entry points for buffered-image mode. */ |
765 | | |
766 | | #ifdef D_MULTISCAN_FILES_SUPPORTED |
767 | | |
768 | | /* |
769 | | * Initialize for an output pass in buffered-image mode. |
770 | | */ |
771 | | |
772 | | GLOBAL(boolean) |
773 | | jpeg_start_output(j_decompress_ptr cinfo, int scan_number) |
774 | 0 | { |
775 | 0 | if (cinfo->global_state != DSTATE_BUFIMAGE && |
776 | 0 | cinfo->global_state != DSTATE_PRESCAN) |
777 | 0 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
778 | | /* Limit scan number to valid range */ |
779 | 0 | if (scan_number <= 0) |
780 | 0 | scan_number = 1; |
781 | 0 | if (cinfo->inputctl->eoi_reached && scan_number > cinfo->input_scan_number) |
782 | 0 | scan_number = cinfo->input_scan_number; |
783 | 0 | cinfo->output_scan_number = scan_number; |
784 | | /* Perform any dummy output passes, and set up for the real pass */ |
785 | 0 | return output_pass_setup(cinfo); |
786 | 0 | } |
787 | | |
788 | | |
789 | | /* |
790 | | * Finish up after an output pass in buffered-image mode. |
791 | | * |
792 | | * Returns FALSE if suspended. The return value need be inspected only if |
793 | | * a suspending data source is used. |
794 | | */ |
795 | | |
796 | | GLOBAL(boolean) |
797 | | jpeg_finish_output(j_decompress_ptr cinfo) |
798 | 0 | { |
799 | 0 | if ((cinfo->global_state == DSTATE_SCANNING || |
800 | 0 | cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) { |
801 | | /* Terminate this pass. */ |
802 | | /* We do not require the whole pass to have been completed. */ |
803 | 0 | (*cinfo->master->finish_output_pass) (cinfo); |
804 | 0 | cinfo->global_state = DSTATE_BUFPOST; |
805 | 0 | } else if (cinfo->global_state != DSTATE_BUFPOST) { |
806 | | /* BUFPOST = repeat call after a suspension, anything else is error */ |
807 | 0 | ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); |
808 | 0 | } |
809 | | /* Read markers looking for SOS or EOI */ |
810 | 0 | while (cinfo->input_scan_number <= cinfo->output_scan_number && |
811 | 0 | !cinfo->inputctl->eoi_reached) { |
812 | 0 | if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED) |
813 | 0 | return FALSE; /* Suspend, come back later */ |
814 | 0 | } |
815 | 0 | cinfo->global_state = DSTATE_BUFIMAGE; |
816 | 0 | return TRUE; |
817 | 0 | } |
818 | | |
819 | | #endif /* D_MULTISCAN_FILES_SUPPORTED */ |
820 | | |
821 | | #endif /* BITS_IN_JSAMPLE == 8 */ |