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