Coverage Report

Created: 2026-04-28 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.3.0.x/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
168k
{
54
168k
  if (cinfo->global_state == DSTATE_READY) {
55
    /* First call: initialize master control, select active modules */
56
168k
    jinit_master_decompress(cinfo);
57
168k
    if (cinfo->buffered_image) {
58
      /* No more work here; expecting jpeg_start_output next */
59
25.8k
      cinfo->global_state = DSTATE_BUFIMAGE;
60
25.8k
      return TRUE;
61
25.8k
    }
62
142k
    cinfo->global_state = DSTATE_PRELOAD;
63
142k
  }
64
142k
  if (cinfo->global_state == DSTATE_PRELOAD) {
65
    /* If file has multiple scans, absorb them all into the coef buffer */
66
90.5k
    if (cinfo->inputctl->has_multiple_scans) {
67
64.8k
#ifdef D_MULTISCAN_FILES_SUPPORTED
68
349M
      for (;;) {
69
349M
        int retcode;
70
        /* Call progress monitor hook if present */
71
349M
        if (cinfo->progress != NULL)
72
349M
          (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
73
        /* Absorb some more input */
74
349M
        retcode = (*cinfo->inputctl->consume_input) (cinfo);
75
349M
        if (retcode == JPEG_SUSPENDED)
76
0
          return FALSE;
77
349M
        if (retcode == JPEG_REACHED_EOI)
78
50.3k
          break;
79
        /* Advance progress counter if appropriate */
80
349M
        if (cinfo->progress != NULL &&
81
349M
            (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
82
348M
          if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
83
            /* jdmaster underestimated number of scans; ratchet up one scan */
84
244k
            cinfo->progress->pass_limit += (long)cinfo->total_iMCU_rows;
85
244k
          }
86
348M
        }
87
349M
      }
88
#else
89
      ERREXIT(cinfo, JERR_NOT_COMPILED);
90
#endif /* D_MULTISCAN_FILES_SUPPORTED */
91
64.8k
    }
92
90.5k
    cinfo->output_scan_number = cinfo->input_scan_number;
93
90.5k
  } 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
142k
  return output_pass_setup(cinfo);
97
142k
}
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
21.2k
{
111
21.2k
  if (cinfo->global_state != DSTATE_PRESCAN) {
112
    /* First call: do pass setup */
113
21.2k
    (*cinfo->master->prepare_for_output_pass) (cinfo);
114
21.2k
    cinfo->output_scanline = 0;
115
21.2k
    cinfo->global_state = DSTATE_PRESCAN;
116
21.2k
  }
117
  /* Loop over any required dummy passes */
118
21.2k
  while (cinfo->master->is_dummy_pass) {
119
0
#ifdef QUANT_2PASS_SUPPORTED
120
    /* Crank through the dummy pass */
121
0
    while (cinfo->output_scanline < cinfo->output_height) {
122
0
      JDIMENSION last_scanline;
123
      /* Call progress monitor hook if present */
124
0
      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
0
      last_scanline = cinfo->output_scanline;
131
0
      if (cinfo->data_precision == 16) {
132
0
#ifdef D_LOSSLESS_SUPPORTED
133
0
        if (cinfo->main->process_data_16 == NULL)
134
0
          ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
135
0
        (*cinfo->main->process_data_16) (cinfo, (J16SAMPARRAY)NULL,
136
0
                                         &cinfo->output_scanline,
137
0
                                         (JDIMENSION)0);
138
#else
139
        ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
140
#endif
141
0
      } else if (cinfo->data_precision == 12) {
142
0
        if (cinfo->main->process_data_12 == NULL)
143
0
          ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
144
0
        (*cinfo->main->process_data_12) (cinfo, (J12SAMPARRAY)NULL,
145
0
                                         &cinfo->output_scanline,
146
0
                                         (JDIMENSION)0);
147
0
      } else {
148
0
        if (cinfo->main->process_data == NULL)
149
0
          ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
150
0
        (*cinfo->main->process_data) (cinfo, (JSAMPARRAY)NULL,
151
0
                                      &cinfo->output_scanline, (JDIMENSION)0);
152
0
      }
153
0
      if (cinfo->output_scanline == last_scanline)
154
0
        return FALSE;           /* No progress made, must suspend */
155
0
    }
156
    /* Finish up dummy pass, and set up for another one */
157
0
    (*cinfo->master->finish_output_pass) (cinfo);
158
0
    (*cinfo->master->prepare_for_output_pass) (cinfo);
159
0
    cinfo->output_scanline = 0;
160
#else
161
    ERREXIT(cinfo, JERR_NOT_COMPILED);
162
#endif /* QUANT_2PASS_SUPPORTED */
163
0
  }
164
  /* Ready for application to drive output pass through
165
   * _jpeg_read_scanlines or _jpeg_read_raw_data.
166
   */
167
21.2k
  cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
168
21.2k
  return TRUE;
169
21.2k
}
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.05k
{
189
4.05k
  int ci, align, orig_downsampled_width;
190
4.05k
  JDIMENSION input_xoffset;
191
4.05k
  boolean reinit_upsampler = FALSE;
192
4.05k
  jpeg_component_info *compptr;
193
4.05k
#ifdef UPSAMPLE_MERGING_SUPPORTED
194
4.05k
  my_master_ptr master = (my_master_ptr)cinfo->master;
195
4.05k
#endif
196
197
4.05k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
198
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
199
200
4.05k
  if (cinfo->master->lossless || cinfo->raw_data_out)
201
0
    ERREXIT(cinfo, JERR_NOTIMPL);
202
203
4.05k
  if ((cinfo->global_state != DSTATE_SCANNING &&
204
4.05k
       cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0)
205
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
206
207
4.05k
  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.05k
  if (*width == 0 ||
212
4.05k
      (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.05k
  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.05k
  if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1)
238
3.11k
    align = cinfo->_min_DCT_scaled_size;
239
936
  else
240
936
    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.05k
  input_xoffset = *xoffset;
244
4.05k
  *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.05k
  *width = *width + input_xoffset - *xoffset;
252
4.05k
  cinfo->output_width = *width;
253
4.05k
#ifdef UPSAMPLE_MERGING_SUPPORTED
254
4.05k
  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.05k
#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.05k
  cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align;
265
4.05k
  cinfo->master->last_iMCU_col =
266
4.05k
    (JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width),
267
4.05k
                              (long)align) - 1;
268
269
9.99k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
270
5.93k
       ci++, compptr++) {
271
5.93k
    int hsf = (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) ?
272
3.11k
              1 : compptr->h_samp_factor;
273
274
    /* Set downsampled_width to the new output width. */
275
5.93k
    orig_downsampled_width = compptr->downsampled_width;
276
5.93k
    compptr->downsampled_width =
277
5.93k
      (JDIMENSION)jdiv_round_up((long)cinfo->output_width *
278
5.93k
                                (long)(compptr->h_samp_factor *
279
5.93k
                                       compptr->_DCT_scaled_size),
280
5.93k
                                (long)(cinfo->max_h_samp_factor *
281
5.93k
                                       cinfo->_min_DCT_scaled_size));
282
5.93k
    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.93k
    cinfo->master->first_MCU_col[ci] =
289
5.93k
      (JDIMENSION)(long)(*xoffset * hsf) / (long)align;
290
5.93k
    cinfo->master->last_MCU_col[ci] =
291
5.93k
      (JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf),
292
5.93k
                                (long)align) - 1;
293
5.93k
  }
294
295
4.05k
  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.05k
}
jpeg12_crop_scanline
Line
Count
Source
188
2.17k
{
189
2.17k
  int ci, align, orig_downsampled_width;
190
2.17k
  JDIMENSION input_xoffset;
191
2.17k
  boolean reinit_upsampler = FALSE;
192
2.17k
  jpeg_component_info *compptr;
193
2.17k
#ifdef UPSAMPLE_MERGING_SUPPORTED
194
2.17k
  my_master_ptr master = (my_master_ptr)cinfo->master;
195
2.17k
#endif
196
197
2.17k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
198
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
199
200
2.17k
  if (cinfo->master->lossless || cinfo->raw_data_out)
201
0
    ERREXIT(cinfo, JERR_NOTIMPL);
202
203
2.17k
  if ((cinfo->global_state != DSTATE_SCANNING &&
204
2.17k
       cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0)
205
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
206
207
2.17k
  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.17k
  if (*width == 0 ||
212
2.17k
      (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.17k
  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.17k
  if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1)
238
1.61k
    align = cinfo->_min_DCT_scaled_size;
239
555
  else
240
555
    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.17k
  input_xoffset = *xoffset;
244
2.17k
  *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.17k
  *width = *width + input_xoffset - *xoffset;
252
2.17k
  cinfo->output_width = *width;
253
2.17k
#ifdef UPSAMPLE_MERGING_SUPPORTED
254
2.17k
  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.17k
#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.17k
  cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align;
265
2.17k
  cinfo->master->last_iMCU_col =
266
2.17k
    (JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width),
267
2.17k
                              (long)align) - 1;
268
269
5.45k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
270
3.28k
       ci++, compptr++) {
271
3.28k
    int hsf = (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) ?
272
1.66k
              1 : compptr->h_samp_factor;
273
274
    /* Set downsampled_width to the new output width. */
275
3.28k
    orig_downsampled_width = compptr->downsampled_width;
276
3.28k
    compptr->downsampled_width =
277
3.28k
      (JDIMENSION)jdiv_round_up((long)cinfo->output_width *
278
3.28k
                                (long)(compptr->h_samp_factor *
279
3.28k
                                       compptr->_DCT_scaled_size),
280
3.28k
                                (long)(cinfo->max_h_samp_factor *
281
3.28k
                                       cinfo->_min_DCT_scaled_size));
282
3.28k
    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
3.28k
    cinfo->master->first_MCU_col[ci] =
289
3.28k
      (JDIMENSION)(long)(*xoffset * hsf) / (long)align;
290
3.28k
    cinfo->master->last_MCU_col[ci] =
291
3.28k
      (JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf),
292
3.28k
                                (long)align) - 1;
293
3.28k
  }
294
295
2.17k
  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.17k
}
jpeg_crop_scanline
Line
Count
Source
188
1.88k
{
189
1.88k
  int ci, align, orig_downsampled_width;
190
1.88k
  JDIMENSION input_xoffset;
191
1.88k
  boolean reinit_upsampler = FALSE;
192
1.88k
  jpeg_component_info *compptr;
193
1.88k
#ifdef UPSAMPLE_MERGING_SUPPORTED
194
1.88k
  my_master_ptr master = (my_master_ptr)cinfo->master;
195
1.88k
#endif
196
197
1.88k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
198
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
199
200
1.88k
  if (cinfo->master->lossless || cinfo->raw_data_out)
201
0
    ERREXIT(cinfo, JERR_NOTIMPL);
202
203
1.88k
  if ((cinfo->global_state != DSTATE_SCANNING &&
204
1.88k
       cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0)
205
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
206
207
1.88k
  if (!xoffset || !width)
208
0
    ERREXIT(cinfo, JERR_BAD_CROP_SPEC);
209
210
  /* xoffset and width must fall within the output image dimensions. */
211
1.88k
  if (*width == 0 ||
212
1.88k
      (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
1.88k
  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
1.88k
  if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1)
238
1.50k
    align = cinfo->_min_DCT_scaled_size;
239
381
  else
240
381
    align = cinfo->_min_DCT_scaled_size * cinfo->max_h_samp_factor;
241
242
  /* Adjust xoffset to the nearest iMCU boundary <= the requested value */
243
1.88k
  input_xoffset = *xoffset;
244
1.88k
  *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
1.88k
  *width = *width + input_xoffset - *xoffset;
252
1.88k
  cinfo->output_width = *width;
253
1.88k
#ifdef UPSAMPLE_MERGING_SUPPORTED
254
1.88k
  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
1.88k
#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
1.88k
  cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align;
265
1.88k
  cinfo->master->last_iMCU_col =
266
1.88k
    (JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width),
267
1.88k
                              (long)align) - 1;
268
269
4.53k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
270
2.65k
       ci++, compptr++) {
271
2.65k
    int hsf = (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) ?
272
1.50k
              1 : compptr->h_samp_factor;
273
274
    /* Set downsampled_width to the new output width. */
275
2.65k
    orig_downsampled_width = compptr->downsampled_width;
276
2.65k
    compptr->downsampled_width =
277
2.65k
      (JDIMENSION)jdiv_round_up((long)cinfo->output_width *
278
2.65k
                                (long)(compptr->h_samp_factor *
279
2.65k
                                       compptr->_DCT_scaled_size),
280
2.65k
                                (long)(cinfo->max_h_samp_factor *
281
2.65k
                                       cinfo->_min_DCT_scaled_size));
282
2.65k
    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.65k
    cinfo->master->first_MCU_col[ci] =
289
2.65k
      (JDIMENSION)(long)(*xoffset * hsf) / (long)align;
290
2.65k
    cinfo->master->last_MCU_col[ci] =
291
2.65k
      (JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf),
292
2.65k
                                (long)align) - 1;
293
2.65k
  }
294
295
1.88k
  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
1.88k
}
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
22.8M
{
322
22.8M
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
323
22.8M
  JDIMENSION row_ctr;
324
325
22.8M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
326
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
327
328
22.8M
  if (cinfo->global_state != DSTATE_SCANNING)
329
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
330
22.8M
  if (cinfo->output_scanline >= cinfo->output_height) {
331
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
332
0
    return 0;
333
0
  }
334
335
  /* Call progress monitor hook if present */
336
22.8M
  if (cinfo->progress != NULL) {
337
22.8M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
338
22.8M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
339
22.8M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
340
22.8M
  }
341
342
  /* Process some data */
343
22.8M
  row_ctr = 0;
344
22.8M
  if (cinfo->main->_process_data == NULL)
345
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
346
22.8M
  (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
347
22.8M
  cinfo->output_scanline += row_ctr;
348
22.8M
  return row_ctr;
349
#else
350
  ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
351
  return 0;
352
#endif
353
22.8M
}
jpeg12_read_scanlines
Line
Count
Source
321
8.57M
{
322
8.57M
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
323
8.57M
  JDIMENSION row_ctr;
324
325
8.57M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
326
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
327
328
8.57M
  if (cinfo->global_state != DSTATE_SCANNING)
329
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
330
8.57M
  if (cinfo->output_scanline >= cinfo->output_height) {
331
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
332
0
    return 0;
333
0
  }
334
335
  /* Call progress monitor hook if present */
336
8.57M
  if (cinfo->progress != NULL) {
337
8.57M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
338
8.57M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
339
8.57M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
340
8.57M
  }
341
342
  /* Process some data */
343
8.57M
  row_ctr = 0;
344
8.57M
  if (cinfo->main->_process_data == NULL)
345
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
346
8.57M
  (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
347
8.57M
  cinfo->output_scanline += row_ctr;
348
8.57M
  return row_ctr;
349
#else
350
  ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
351
  return 0;
352
#endif
353
8.57M
}
jpeg16_read_scanlines
Line
Count
Source
321
1.35M
{
322
1.35M
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
323
1.35M
  JDIMENSION row_ctr;
324
325
1.35M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
326
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
327
328
1.35M
  if (cinfo->global_state != DSTATE_SCANNING)
329
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
330
1.35M
  if (cinfo->output_scanline >= cinfo->output_height) {
331
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
332
0
    return 0;
333
0
  }
334
335
  /* Call progress monitor hook if present */
336
1.35M
  if (cinfo->progress != NULL) {
337
1.35M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
338
1.35M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
339
1.35M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
340
1.35M
  }
341
342
  /* Process some data */
343
1.35M
  row_ctr = 0;
344
1.35M
  if (cinfo->main->_process_data == NULL)
345
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
346
1.35M
  (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
347
1.35M
  cinfo->output_scanline += row_ctr;
348
1.35M
  return row_ctr;
349
#else
350
  ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
351
  return 0;
352
#endif
353
1.35M
}
jpeg_read_scanlines
Line
Count
Source
321
12.9M
{
322
12.9M
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
323
12.9M
  JDIMENSION row_ctr;
324
325
12.9M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
326
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
327
328
12.9M
  if (cinfo->global_state != DSTATE_SCANNING)
329
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
330
12.9M
  if (cinfo->output_scanline >= cinfo->output_height) {
331
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
332
0
    return 0;
333
0
  }
334
335
  /* Call progress monitor hook if present */
336
12.9M
  if (cinfo->progress != NULL) {
337
12.9M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
338
12.9M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
339
12.9M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
340
12.9M
  }
341
342
  /* Process some data */
343
12.9M
  row_ctr = 0;
344
12.9M
  if (cinfo->main->_process_data == NULL)
345
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
346
12.9M
  (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
347
12.9M
  cinfo->output_scanline += row_ctr;
348
12.9M
  return row_ctr;
349
#else
350
  ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
351
  return 0;
352
#endif
353
12.9M
}
354
355
356
#if BITS_IN_JSAMPLE != 16
357
358
/* Dummy color convert function used by _jpeg_skip_scanlines() */
359
LOCAL(void)
360
noop_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
361
             JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
362
0
{
363
0
}
364
365
366
/* Dummy quantize function used by _jpeg_skip_scanlines() */
367
LOCAL(void)
368
noop_quantize(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
369
              _JSAMPARRAY output_buf, int num_rows)
370
0
{
371
0
}
372
373
374
/*
375
 * In some cases, it is best to call _jpeg_read_scanlines() and discard the
376
 * output, rather than skipping the scanlines, because this allows us to
377
 * maintain the internal state of the context-based upsampler.  In these cases,
378
 * we set up and tear down a dummy color converter in order to avoid valgrind
379
 * errors and to achieve the best possible performance.
380
 */
381
382
LOCAL(void)
383
read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
384
13
{
385
13
  JDIMENSION n;
386
13
#ifdef UPSAMPLE_MERGING_SUPPORTED
387
13
  my_master_ptr master = (my_master_ptr)cinfo->master;
388
13
#endif
389
13
  _JSAMPLE dummy_sample[1] = { 0 };
390
13
  _JSAMPROW dummy_row = dummy_sample;
391
13
  _JSAMPARRAY scanlines = NULL;
392
13
  void (*color_convert) (j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
393
13
                         JDIMENSION input_row, _JSAMPARRAY output_buf,
394
13
                         int num_rows) = NULL;
395
13
  void (*color_quantize) (j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
396
13
                          _JSAMPARRAY output_buf, int num_rows) = NULL;
397
398
13
  if (cinfo->cconvert &&
399
13
#ifdef UPSAMPLE_MERGING_SUPPORTED
400
13
      !master->using_merged_upsample &&
401
13
#endif
402
13
      cinfo->cconvert->_color_convert) {
403
13
    color_convert = cinfo->cconvert->_color_convert;
404
13
    cinfo->cconvert->_color_convert = noop_convert;
405
    /* This just prevents UBSan from complaining about adding 0 to a NULL
406
     * pointer.  The pointer isn't actually used.
407
     */
408
13
    scanlines = &dummy_row;
409
13
  }
410
411
13
  if (cinfo->quantize_colors && cinfo->cquantize &&
412
0
      cinfo->cquantize->_color_quantize) {
413
0
    color_quantize = cinfo->cquantize->_color_quantize;
414
0
    cinfo->cquantize->_color_quantize = noop_quantize;
415
0
  }
416
417
13
#ifdef UPSAMPLE_MERGING_SUPPORTED
418
13
  if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) {
419
0
    my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
420
0
    scanlines = &upsample->spare_row;
421
0
  }
422
13
#endif
423
424
13
  for (n = 0; n < num_lines; n++)
425
0
    _jpeg_read_scanlines(cinfo, scanlines, 1);
426
427
13
  if (color_convert)
428
13
    cinfo->cconvert->_color_convert = color_convert;
429
430
13
  if (color_quantize)
431
0
    cinfo->cquantize->_color_quantize = color_quantize;
432
13
}
433
434
435
/*
436
 * Called by _jpeg_skip_scanlines().  This partially skips a decompress block
437
 * by incrementing the rowgroup counter.
438
 */
439
440
LOCAL(void)
441
increment_simple_rowgroup_ctr(j_decompress_ptr cinfo, JDIMENSION rows)
442
13
{
443
13
  JDIMENSION rows_left;
444
13
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
445
13
  my_master_ptr master = (my_master_ptr)cinfo->master;
446
447
13
  if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) {
448
0
    read_and_discard_scanlines(cinfo, rows);
449
0
    return;
450
0
  }
451
452
  /* Increment the counter to the next row group after the skipped rows. */
453
13
  main_ptr->rowgroup_ctr += rows / cinfo->max_v_samp_factor;
454
455
  /* Partially skipping a row group would involve modifying the internal state
456
   * of the upsampler, so read the remaining rows into a dummy buffer instead.
457
   */
458
13
  rows_left = rows % cinfo->max_v_samp_factor;
459
13
  cinfo->output_scanline += rows - rows_left;
460
461
13
  read_and_discard_scanlines(cinfo, rows_left);
462
13
}
463
464
/*
465
 * Skips some scanlines of data from the JPEG decompressor.
466
 *
467
 * The return value will be the number of lines actually skipped.  If skipping
468
 * num_lines would move beyond the end of the image, then the actual number of
469
 * lines remaining in the image is returned.  Otherwise, the return value will
470
 * be equal to num_lines.
471
 *
472
 * Refer to libjpeg.txt for more information.
473
 */
474
475
GLOBAL(JDIMENSION)
476
_jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
477
104k
{
478
104k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
479
104k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
480
104k
  my_master_ptr master = (my_master_ptr)cinfo->master;
481
104k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
482
104k
  JDIMENSION i, x;
483
104k
  int y;
484
104k
  JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
485
104k
  JDIMENSION lines_to_skip, lines_to_read;
486
487
104k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
488
119
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
489
490
104k
  if (cinfo->master->lossless)
491
0
    ERREXIT(cinfo, JERR_NOTIMPL);
492
493
  /* Two-pass color quantization is not supported. */
494
104k
  if (cinfo->quantize_colors && cinfo->two_pass_quantize)
495
0
    ERREXIT(cinfo, JERR_NOTIMPL);
496
497
104k
  if (cinfo->global_state != DSTATE_SCANNING)
498
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
499
500
  /* Do not skip past the bottom of the image. */
501
104k
  if ((unsigned long long)cinfo->output_scanline + num_lines >=
502
104k
      cinfo->output_height) {
503
6.46k
    num_lines = cinfo->output_height - cinfo->output_scanline;
504
6.46k
    cinfo->output_scanline = cinfo->output_height;
505
6.46k
    (*cinfo->inputctl->finish_input_pass) (cinfo);
506
6.46k
    cinfo->inputctl->eoi_reached = TRUE;
507
6.46k
    return num_lines;
508
6.46k
  }
509
510
97.6k
  if (num_lines == 0)
511
0
    return 0;
512
513
97.6k
  lines_per_iMCU_row = cinfo->_min_DCT_scaled_size * cinfo->max_v_samp_factor;
514
97.6k
  lines_left_in_iMCU_row =
515
97.6k
    (lines_per_iMCU_row - (cinfo->output_scanline % lines_per_iMCU_row)) %
516
97.6k
    lines_per_iMCU_row;
517
97.6k
  lines_after_iMCU_row = num_lines - lines_left_in_iMCU_row;
518
519
  /* Skip the lines remaining in the current iMCU row.  When upsampling
520
   * requires context rows, we need the previous and next rows in order to read
521
   * the current row.  This adds some complexity.
522
   */
523
97.6k
  if (cinfo->upsample->need_context_rows) {
524
    /* If the skipped lines would not move us past the current iMCU row, we
525
     * read the lines and ignore them.  There might be a faster way of doing
526
     * this, but we are facing increasing complexity for diminishing returns.
527
     * The increasing complexity would be a by-product of meddling with the
528
     * state machine used to skip context rows.  Near the end of an iMCU row,
529
     * the next iMCU row may have already been entropy-decoded.  In this unique
530
     * case, we will read the next iMCU row if we cannot skip past it as well.
531
     */
532
33.9k
    if ((num_lines < lines_left_in_iMCU_row + 1) ||
533
29.5k
        (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full &&
534
14.4k
         lines_after_iMCU_row < lines_per_iMCU_row + 1)) {
535
14.4k
      read_and_discard_scanlines(cinfo, num_lines);
536
14.4k
      return num_lines;
537
14.4k
    }
538
539
    /* If the next iMCU row has already been entropy-decoded, make sure that
540
     * we do not skip too far.
541
     */
542
19.5k
    if (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full) {
543
0
      cinfo->output_scanline += lines_left_in_iMCU_row + lines_per_iMCU_row;
544
0
      lines_after_iMCU_row -= lines_per_iMCU_row;
545
19.5k
    } else {
546
19.5k
      cinfo->output_scanline += lines_left_in_iMCU_row;
547
19.5k
    }
548
549
    /* If we have just completed the first block, adjust the buffer pointers */
550
19.5k
    if (main_ptr->iMCU_row_ctr == 0 ||
551
0
        (main_ptr->iMCU_row_ctr == 1 && lines_left_in_iMCU_row > 2))
552
19.5k
      set_wraparound_pointers(cinfo);
553
19.5k
    main_ptr->buffer_full = FALSE;
554
19.5k
    main_ptr->rowgroup_ctr = 0;
555
19.5k
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
556
19.5k
    if (!master->using_merged_upsample) {
557
19.5k
      upsample->next_row_out = cinfo->max_v_samp_factor;
558
19.5k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
559
19.5k
    }
560
19.5k
  }
561
562
  /* Skipping is much simpler when context rows are not required. */
563
63.6k
  else {
564
63.6k
    if (num_lines < lines_left_in_iMCU_row) {
565
10.0k
      increment_simple_rowgroup_ctr(cinfo, num_lines);
566
10.0k
      return num_lines;
567
53.6k
    } else {
568
53.6k
      cinfo->output_scanline += lines_left_in_iMCU_row;
569
53.6k
      main_ptr->buffer_full = FALSE;
570
53.6k
      main_ptr->rowgroup_ctr = 0;
571
53.6k
      if (!master->using_merged_upsample) {
572
53.4k
        upsample->next_row_out = cinfo->max_v_samp_factor;
573
53.4k
        upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
574
53.4k
      }
575
53.6k
    }
576
63.6k
  }
577
578
  /* Calculate how many full iMCU rows we can skip. */
579
73.1k
  if (cinfo->upsample->need_context_rows)
580
19.5k
    lines_to_skip = ((lines_after_iMCU_row - 1) / lines_per_iMCU_row) *
581
19.5k
                    lines_per_iMCU_row;
582
53.6k
  else
583
53.6k
    lines_to_skip = (lines_after_iMCU_row / lines_per_iMCU_row) *
584
53.6k
                    lines_per_iMCU_row;
585
  /* Calculate the number of lines that remain to be skipped after skipping all
586
   * of the full iMCU rows that we can.  We will not read these lines unless we
587
   * have to.
588
   */
589
73.1k
  lines_to_read = lines_after_iMCU_row - lines_to_skip;
590
591
  /* For images requiring multiple scans (progressive, non-interleaved, etc.),
592
   * all of the entropy decoding occurs in jpeg_start_decompress(), assuming
593
   * that the input data source is non-suspending.  This makes skipping easy.
594
   */
595
73.1k
  if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) {
596
59.3k
    if (cinfo->upsample->need_context_rows) {
597
18.9k
      cinfo->output_scanline += lines_to_skip;
598
18.9k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
599
18.9k
      main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
600
      /* It is complex to properly move to the middle of a context block, so
601
       * read the remaining lines instead of skipping them.
602
       */
603
18.9k
      read_and_discard_scanlines(cinfo, lines_to_read);
604
40.3k
    } else {
605
40.3k
      cinfo->output_scanline += lines_to_skip;
606
40.3k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
607
40.3k
      increment_simple_rowgroup_ctr(cinfo, lines_to_read);
608
40.3k
    }
609
59.3k
    if (!master->using_merged_upsample)
610
59.3k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
611
59.3k
    return num_lines;
612
59.3k
  }
613
614
  /* Skip the iMCU rows that we can safely skip. */
615
25.8k
  for (i = 0; i < lines_to_skip; i += lines_per_iMCU_row) {
616
25.1k
    for (y = 0; y < coef->MCU_rows_per_iMCU_row; y++) {
617
3.18M
      for (x = 0; x < cinfo->MCUs_per_row; x++) {
618
        /* Calling decode_mcu() with a NULL pointer causes it to discard the
619
         * decoded coefficients.  This is ~5% faster for large subsets, but
620
         * it's tough to tell a difference for smaller images.
621
         */
622
3.17M
        if (!cinfo->entropy->insufficient_data)
623
1.24M
          cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
624
3.17M
        (*cinfo->entropy->decode_mcu) (cinfo, NULL);
625
3.17M
      }
626
13.1k
    }
627
12.0k
    cinfo->input_iMCU_row++;
628
12.0k
    cinfo->output_iMCU_row++;
629
12.0k
    if (cinfo->input_iMCU_row < cinfo->total_iMCU_rows)
630
12.0k
      start_iMCU_row(cinfo);
631
0
    else
632
0
      (*cinfo->inputctl->finish_input_pass) (cinfo);
633
12.0k
  }
634
13.7k
  cinfo->output_scanline += lines_to_skip;
635
636
13.7k
  if (cinfo->upsample->need_context_rows) {
637
    /* Context-based upsampling keeps track of iMCU rows. */
638
589
    main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
639
640
    /* It is complex to properly move to the middle of a context block, so
641
     * read the remaining lines instead of skipping them.
642
     */
643
589
    read_and_discard_scanlines(cinfo, lines_to_read);
644
13.2k
  } else {
645
13.2k
    increment_simple_rowgroup_ctr(cinfo, lines_to_read);
646
13.2k
  }
647
648
  /* Since skipping lines involves skipping the upsampling step, the value of
649
   * "rows_to_go" will become invalid unless we set it here.  NOTE: This is a
650
   * bit odd, since "rows_to_go" seems to be redundantly keeping track of
651
   * output_scanline.
652
   */
653
13.7k
  if (!master->using_merged_upsample)
654
13.6k
    upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
655
656
  /* Always skip the requested number of lines. */
657
13.7k
  return num_lines;
658
73.1k
}
jpeg12_skip_scanlines
Line
Count
Source
477
4.30k
{
478
4.30k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
479
4.30k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
480
4.30k
  my_master_ptr master = (my_master_ptr)cinfo->master;
481
4.30k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
482
4.30k
  JDIMENSION i, x;
483
4.30k
  int y;
484
4.30k
  JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
485
4.30k
  JDIMENSION lines_to_skip, lines_to_read;
486
487
4.30k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
488
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
489
490
4.30k
  if (cinfo->master->lossless)
491
0
    ERREXIT(cinfo, JERR_NOTIMPL);
492
493
  /* Two-pass color quantization is not supported. */
494
4.30k
  if (cinfo->quantize_colors && cinfo->two_pass_quantize)
495
0
    ERREXIT(cinfo, JERR_NOTIMPL);
496
497
4.30k
  if (cinfo->global_state != DSTATE_SCANNING)
498
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
499
500
  /* Do not skip past the bottom of the image. */
501
4.30k
  if ((unsigned long long)cinfo->output_scanline + num_lines >=
502
4.30k
      cinfo->output_height) {
503
2.13k
    num_lines = cinfo->output_height - cinfo->output_scanline;
504
2.13k
    cinfo->output_scanline = cinfo->output_height;
505
2.13k
    (*cinfo->inputctl->finish_input_pass) (cinfo);
506
2.13k
    cinfo->inputctl->eoi_reached = TRUE;
507
2.13k
    return num_lines;
508
2.13k
  }
509
510
2.16k
  if (num_lines == 0)
511
0
    return 0;
512
513
2.16k
  lines_per_iMCU_row = cinfo->_min_DCT_scaled_size * cinfo->max_v_samp_factor;
514
2.16k
  lines_left_in_iMCU_row =
515
2.16k
    (lines_per_iMCU_row - (cinfo->output_scanline % lines_per_iMCU_row)) %
516
2.16k
    lines_per_iMCU_row;
517
2.16k
  lines_after_iMCU_row = num_lines - lines_left_in_iMCU_row;
518
519
  /* Skip the lines remaining in the current iMCU row.  When upsampling
520
   * requires context rows, we need the previous and next rows in order to read
521
   * the current row.  This adds some complexity.
522
   */
523
2.16k
  if (cinfo->upsample->need_context_rows) {
524
    /* If the skipped lines would not move us past the current iMCU row, we
525
     * read the lines and ignore them.  There might be a faster way of doing
526
     * this, but we are facing increasing complexity for diminishing returns.
527
     * The increasing complexity would be a by-product of meddling with the
528
     * state machine used to skip context rows.  Near the end of an iMCU row,
529
     * the next iMCU row may have already been entropy-decoded.  In this unique
530
     * case, we will read the next iMCU row if we cannot skip past it as well.
531
     */
532
72
    if ((num_lines < lines_left_in_iMCU_row + 1) ||
533
72
        (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full &&
534
0
         lines_after_iMCU_row < lines_per_iMCU_row + 1)) {
535
0
      read_and_discard_scanlines(cinfo, num_lines);
536
0
      return num_lines;
537
0
    }
538
539
    /* If the next iMCU row has already been entropy-decoded, make sure that
540
     * we do not skip too far.
541
     */
542
72
    if (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full) {
543
0
      cinfo->output_scanline += lines_left_in_iMCU_row + lines_per_iMCU_row;
544
0
      lines_after_iMCU_row -= lines_per_iMCU_row;
545
72
    } else {
546
72
      cinfo->output_scanline += lines_left_in_iMCU_row;
547
72
    }
548
549
    /* If we have just completed the first block, adjust the buffer pointers */
550
72
    if (main_ptr->iMCU_row_ctr == 0 ||
551
0
        (main_ptr->iMCU_row_ctr == 1 && lines_left_in_iMCU_row > 2))
552
72
      set_wraparound_pointers(cinfo);
553
72
    main_ptr->buffer_full = FALSE;
554
72
    main_ptr->rowgroup_ctr = 0;
555
72
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
556
72
    if (!master->using_merged_upsample) {
557
72
      upsample->next_row_out = cinfo->max_v_samp_factor;
558
72
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
559
72
    }
560
72
  }
561
562
  /* Skipping is much simpler when context rows are not required. */
563
2.09k
  else {
564
2.09k
    if (num_lines < lines_left_in_iMCU_row) {
565
0
      increment_simple_rowgroup_ctr(cinfo, num_lines);
566
0
      return num_lines;
567
2.09k
    } else {
568
2.09k
      cinfo->output_scanline += lines_left_in_iMCU_row;
569
2.09k
      main_ptr->buffer_full = FALSE;
570
2.09k
      main_ptr->rowgroup_ctr = 0;
571
2.09k
      if (!master->using_merged_upsample) {
572
2.09k
        upsample->next_row_out = cinfo->max_v_samp_factor;
573
2.09k
        upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
574
2.09k
      }
575
2.09k
    }
576
2.09k
  }
577
578
  /* Calculate how many full iMCU rows we can skip. */
579
2.16k
  if (cinfo->upsample->need_context_rows)
580
72
    lines_to_skip = ((lines_after_iMCU_row - 1) / lines_per_iMCU_row) *
581
72
                    lines_per_iMCU_row;
582
2.09k
  else
583
2.09k
    lines_to_skip = (lines_after_iMCU_row / lines_per_iMCU_row) *
584
2.09k
                    lines_per_iMCU_row;
585
  /* Calculate the number of lines that remain to be skipped after skipping all
586
   * of the full iMCU rows that we can.  We will not read these lines unless we
587
   * have to.
588
   */
589
2.16k
  lines_to_read = lines_after_iMCU_row - lines_to_skip;
590
591
  /* For images requiring multiple scans (progressive, non-interleaved, etc.),
592
   * all of the entropy decoding occurs in jpeg_start_decompress(), assuming
593
   * that the input data source is non-suspending.  This makes skipping easy.
594
   */
595
2.16k
  if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) {
596
1.28k
    if (cinfo->upsample->need_context_rows) {
597
11
      cinfo->output_scanline += lines_to_skip;
598
11
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
599
11
      main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
600
      /* It is complex to properly move to the middle of a context block, so
601
       * read the remaining lines instead of skipping them.
602
       */
603
11
      read_and_discard_scanlines(cinfo, lines_to_read);
604
1.26k
    } else {
605
1.26k
      cinfo->output_scanline += lines_to_skip;
606
1.26k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
607
1.26k
      increment_simple_rowgroup_ctr(cinfo, lines_to_read);
608
1.26k
    }
609
1.28k
    if (!master->using_merged_upsample)
610
1.28k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
611
1.28k
    return num_lines;
612
1.28k
  }
613
614
  /* Skip the iMCU rows that we can safely skip. */
615
2.21k
  for (i = 0; i < lines_to_skip; i += lines_per_iMCU_row) {
616
3.33k
    for (y = 0; y < coef->MCU_rows_per_iMCU_row; y++) {
617
294k
      for (x = 0; x < cinfo->MCUs_per_row; x++) {
618
        /* Calling decode_mcu() with a NULL pointer causes it to discard the
619
         * decoded coefficients.  This is ~5% faster for large subsets, but
620
         * it's tough to tell a difference for smaller images.
621
         */
622
292k
        if (!cinfo->entropy->insufficient_data)
623
114k
          cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
624
292k
        (*cinfo->entropy->decode_mcu) (cinfo, NULL);
625
292k
      }
626
2.01k
    }
627
1.32k
    cinfo->input_iMCU_row++;
628
1.32k
    cinfo->output_iMCU_row++;
629
1.32k
    if (cinfo->input_iMCU_row < cinfo->total_iMCU_rows)
630
1.32k
      start_iMCU_row(cinfo);
631
0
    else
632
0
      (*cinfo->inputctl->finish_input_pass) (cinfo);
633
1.32k
  }
634
889
  cinfo->output_scanline += lines_to_skip;
635
636
889
  if (cinfo->upsample->need_context_rows) {
637
    /* Context-based upsampling keeps track of iMCU rows. */
638
61
    main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
639
640
    /* It is complex to properly move to the middle of a context block, so
641
     * read the remaining lines instead of skipping them.
642
     */
643
61
    read_and_discard_scanlines(cinfo, lines_to_read);
644
828
  } else {
645
828
    increment_simple_rowgroup_ctr(cinfo, lines_to_read);
646
828
  }
647
648
  /* Since skipping lines involves skipping the upsampling step, the value of
649
   * "rows_to_go" will become invalid unless we set it here.  NOTE: This is a
650
   * bit odd, since "rows_to_go" seems to be redundantly keeping track of
651
   * output_scanline.
652
   */
653
889
  if (!master->using_merged_upsample)
654
889
    upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
655
656
  /* Always skip the requested number of lines. */
657
889
  return num_lines;
658
2.16k
}
jpeg_skip_scanlines
Line
Count
Source
477
99.7k
{
478
99.7k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
479
99.7k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
480
99.7k
  my_master_ptr master = (my_master_ptr)cinfo->master;
481
99.7k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
482
99.7k
  JDIMENSION i, x;
483
99.7k
  int y;
484
99.7k
  JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
485
99.7k
  JDIMENSION lines_to_skip, lines_to_read;
486
487
99.7k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
488
119
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
489
490
99.7k
  if (cinfo->master->lossless)
491
0
    ERREXIT(cinfo, JERR_NOTIMPL);
492
493
  /* Two-pass color quantization is not supported. */
494
99.7k
  if (cinfo->quantize_colors && cinfo->two_pass_quantize)
495
0
    ERREXIT(cinfo, JERR_NOTIMPL);
496
497
99.7k
  if (cinfo->global_state != DSTATE_SCANNING)
498
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
499
500
  /* Do not skip past the bottom of the image. */
501
99.7k
  if ((unsigned long long)cinfo->output_scanline + num_lines >=
502
99.7k
      cinfo->output_height) {
503
4.32k
    num_lines = cinfo->output_height - cinfo->output_scanline;
504
4.32k
    cinfo->output_scanline = cinfo->output_height;
505
4.32k
    (*cinfo->inputctl->finish_input_pass) (cinfo);
506
4.32k
    cinfo->inputctl->eoi_reached = TRUE;
507
4.32k
    return num_lines;
508
4.32k
  }
509
510
95.4k
  if (num_lines == 0)
511
0
    return 0;
512
513
95.4k
  lines_per_iMCU_row = cinfo->_min_DCT_scaled_size * cinfo->max_v_samp_factor;
514
95.4k
  lines_left_in_iMCU_row =
515
95.4k
    (lines_per_iMCU_row - (cinfo->output_scanline % lines_per_iMCU_row)) %
516
95.4k
    lines_per_iMCU_row;
517
95.4k
  lines_after_iMCU_row = num_lines - lines_left_in_iMCU_row;
518
519
  /* Skip the lines remaining in the current iMCU row.  When upsampling
520
   * requires context rows, we need the previous and next rows in order to read
521
   * the current row.  This adds some complexity.
522
   */
523
95.4k
  if (cinfo->upsample->need_context_rows) {
524
    /* If the skipped lines would not move us past the current iMCU row, we
525
     * read the lines and ignore them.  There might be a faster way of doing
526
     * this, but we are facing increasing complexity for diminishing returns.
527
     * The increasing complexity would be a by-product of meddling with the
528
     * state machine used to skip context rows.  Near the end of an iMCU row,
529
     * the next iMCU row may have already been entropy-decoded.  In this unique
530
     * case, we will read the next iMCU row if we cannot skip past it as well.
531
     */
532
33.9k
    if ((num_lines < lines_left_in_iMCU_row + 1) ||
533
29.5k
        (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full &&
534
14.4k
         lines_after_iMCU_row < lines_per_iMCU_row + 1)) {
535
14.4k
      read_and_discard_scanlines(cinfo, num_lines);
536
14.4k
      return num_lines;
537
14.4k
    }
538
539
    /* If the next iMCU row has already been entropy-decoded, make sure that
540
     * we do not skip too far.
541
     */
542
19.5k
    if (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full) {
543
0
      cinfo->output_scanline += lines_left_in_iMCU_row + lines_per_iMCU_row;
544
0
      lines_after_iMCU_row -= lines_per_iMCU_row;
545
19.5k
    } else {
546
19.5k
      cinfo->output_scanline += lines_left_in_iMCU_row;
547
19.5k
    }
548
549
    /* If we have just completed the first block, adjust the buffer pointers */
550
19.5k
    if (main_ptr->iMCU_row_ctr == 0 ||
551
0
        (main_ptr->iMCU_row_ctr == 1 && lines_left_in_iMCU_row > 2))
552
19.5k
      set_wraparound_pointers(cinfo);
553
19.5k
    main_ptr->buffer_full = FALSE;
554
19.5k
    main_ptr->rowgroup_ctr = 0;
555
19.5k
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
556
19.5k
    if (!master->using_merged_upsample) {
557
19.5k
      upsample->next_row_out = cinfo->max_v_samp_factor;
558
19.5k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
559
19.5k
    }
560
19.5k
  }
561
562
  /* Skipping is much simpler when context rows are not required. */
563
61.5k
  else {
564
61.5k
    if (num_lines < lines_left_in_iMCU_row) {
565
10.0k
      increment_simple_rowgroup_ctr(cinfo, num_lines);
566
10.0k
      return num_lines;
567
51.5k
    } else {
568
51.5k
      cinfo->output_scanline += lines_left_in_iMCU_row;
569
51.5k
      main_ptr->buffer_full = FALSE;
570
51.5k
      main_ptr->rowgroup_ctr = 0;
571
51.5k
      if (!master->using_merged_upsample) {
572
51.3k
        upsample->next_row_out = cinfo->max_v_samp_factor;
573
51.3k
        upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
574
51.3k
      }
575
51.5k
    }
576
61.5k
  }
577
578
  /* Calculate how many full iMCU rows we can skip. */
579
71.0k
  if (cinfo->upsample->need_context_rows)
580
19.5k
    lines_to_skip = ((lines_after_iMCU_row - 1) / lines_per_iMCU_row) *
581
19.5k
                    lines_per_iMCU_row;
582
51.5k
  else
583
51.5k
    lines_to_skip = (lines_after_iMCU_row / lines_per_iMCU_row) *
584
51.5k
                    lines_per_iMCU_row;
585
  /* Calculate the number of lines that remain to be skipped after skipping all
586
   * of the full iMCU rows that we can.  We will not read these lines unless we
587
   * have to.
588
   */
589
71.0k
  lines_to_read = lines_after_iMCU_row - lines_to_skip;
590
591
  /* For images requiring multiple scans (progressive, non-interleaved, etc.),
592
   * all of the entropy decoding occurs in jpeg_start_decompress(), assuming
593
   * that the input data source is non-suspending.  This makes skipping easy.
594
   */
595
71.0k
  if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) {
596
58.1k
    if (cinfo->upsample->need_context_rows) {
597
18.9k
      cinfo->output_scanline += lines_to_skip;
598
18.9k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
599
18.9k
      main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
600
      /* It is complex to properly move to the middle of a context block, so
601
       * read the remaining lines instead of skipping them.
602
       */
603
18.9k
      read_and_discard_scanlines(cinfo, lines_to_read);
604
39.1k
    } else {
605
39.1k
      cinfo->output_scanline += lines_to_skip;
606
39.1k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
607
39.1k
      increment_simple_rowgroup_ctr(cinfo, lines_to_read);
608
39.1k
    }
609
58.1k
    if (!master->using_merged_upsample)
610
58.1k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
611
58.1k
    return num_lines;
612
58.1k
  }
613
614
  /* Skip the iMCU rows that we can safely skip. */
615
23.6k
  for (i = 0; i < lines_to_skip; i += lines_per_iMCU_row) {
616
21.8k
    for (y = 0; y < coef->MCU_rows_per_iMCU_row; y++) {
617
2.89M
      for (x = 0; x < cinfo->MCUs_per_row; x++) {
618
        /* Calling decode_mcu() with a NULL pointer causes it to discard the
619
         * decoded coefficients.  This is ~5% faster for large subsets, but
620
         * it's tough to tell a difference for smaller images.
621
         */
622
2.88M
        if (!cinfo->entropy->insufficient_data)
623
1.12M
          cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
624
2.88M
        (*cinfo->entropy->decode_mcu) (cinfo, NULL);
625
2.88M
      }
626
11.0k
    }
627
10.7k
    cinfo->input_iMCU_row++;
628
10.7k
    cinfo->output_iMCU_row++;
629
10.7k
    if (cinfo->input_iMCU_row < cinfo->total_iMCU_rows)
630
10.7k
      start_iMCU_row(cinfo);
631
0
    else
632
0
      (*cinfo->inputctl->finish_input_pass) (cinfo);
633
10.7k
  }
634
12.9k
  cinfo->output_scanline += lines_to_skip;
635
636
12.9k
  if (cinfo->upsample->need_context_rows) {
637
    /* Context-based upsampling keeps track of iMCU rows. */
638
528
    main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
639
640
    /* It is complex to properly move to the middle of a context block, so
641
     * read the remaining lines instead of skipping them.
642
     */
643
528
    read_and_discard_scanlines(cinfo, lines_to_read);
644
12.3k
  } else {
645
12.3k
    increment_simple_rowgroup_ctr(cinfo, lines_to_read);
646
12.3k
  }
647
648
  /* Since skipping lines involves skipping the upsampling step, the value of
649
   * "rows_to_go" will become invalid unless we set it here.  NOTE: This is a
650
   * bit odd, since "rows_to_go" seems to be redundantly keeping track of
651
   * output_scanline.
652
   */
653
12.9k
  if (!master->using_merged_upsample)
654
12.7k
    upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
655
656
  /* Always skip the requested number of lines. */
657
12.9k
  return num_lines;
658
71.0k
}
659
660
/*
661
 * Alternate entry point to read raw data.
662
 * Processes exactly one iMCU row per call, unless suspended.
663
 */
664
665
GLOBAL(JDIMENSION)
666
_jpeg_read_raw_data(j_decompress_ptr cinfo, _JSAMPIMAGE data,
667
                    JDIMENSION max_lines)
668
6.33M
{
669
6.33M
  JDIMENSION lines_per_iMCU_row;
670
671
6.33M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
672
8.17k
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
673
674
6.33M
  if (cinfo->master->lossless)
675
1.80k
    ERREXIT(cinfo, JERR_NOTIMPL);
676
677
6.33M
  if (cinfo->global_state != DSTATE_RAW_OK)
678
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
679
6.33M
  if (cinfo->output_scanline >= cinfo->output_height) {
680
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
681
0
    return 0;
682
0
  }
683
684
  /* Call progress monitor hook if present */
685
6.33M
  if (cinfo->progress != NULL) {
686
6.32M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
687
6.32M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
688
6.32M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
689
6.32M
  }
690
691
  /* Verify that at least one iMCU row can be returned. */
692
6.33M
  lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size;
693
6.33M
  if (max_lines < lines_per_iMCU_row)
694
0
    ERREXIT(cinfo, JERR_BUFFER_SIZE);
695
696
  /* Decompress directly into user's buffer. */
697
6.33M
  if (cinfo->coef->_decompress_data == NULL)
698
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
699
6.33M
  if (!(*cinfo->coef->_decompress_data) (cinfo, data))
700
0
    return 0;                   /* suspension forced, can do nothing more */
701
702
  /* OK, we processed one iMCU row. */
703
6.33M
  cinfo->output_scanline += lines_per_iMCU_row;
704
6.33M
  return lines_per_iMCU_row;
705
6.33M
}
Unexecuted instantiation: jpeg12_read_raw_data
jpeg_read_raw_data
Line
Count
Source
668
6.33M
{
669
6.33M
  JDIMENSION lines_per_iMCU_row;
670
671
6.33M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
672
8.17k
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
673
674
6.33M
  if (cinfo->master->lossless)
675
1.80k
    ERREXIT(cinfo, JERR_NOTIMPL);
676
677
6.33M
  if (cinfo->global_state != DSTATE_RAW_OK)
678
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
679
6.33M
  if (cinfo->output_scanline >= cinfo->output_height) {
680
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
681
0
    return 0;
682
0
  }
683
684
  /* Call progress monitor hook if present */
685
6.33M
  if (cinfo->progress != NULL) {
686
6.32M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
687
6.32M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
688
6.32M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
689
6.32M
  }
690
691
  /* Verify that at least one iMCU row can be returned. */
692
6.33M
  lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size;
693
6.33M
  if (max_lines < lines_per_iMCU_row)
694
0
    ERREXIT(cinfo, JERR_BUFFER_SIZE);
695
696
  /* Decompress directly into user's buffer. */
697
6.33M
  if (cinfo->coef->_decompress_data == NULL)
698
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
699
6.33M
  if (!(*cinfo->coef->_decompress_data) (cinfo, data))
700
0
    return 0;                   /* suspension forced, can do nothing more */
701
702
  /* OK, we processed one iMCU row. */
703
6.33M
  cinfo->output_scanline += lines_per_iMCU_row;
704
6.33M
  return lines_per_iMCU_row;
705
6.33M
}
706
707
#endif /* BITS_IN_JSAMPLE != 16 */
708
709
710
#if BITS_IN_JSAMPLE == 8
711
712
/* Additional entry points for buffered-image mode. */
713
714
#ifdef D_MULTISCAN_FILES_SUPPORTED
715
716
/*
717
 * Initialize for an output pass in buffered-image mode.
718
 */
719
720
GLOBAL(boolean)
721
jpeg_start_output(j_decompress_ptr cinfo, int scan_number)
722
61.2k
{
723
61.2k
  if (cinfo->global_state != DSTATE_BUFIMAGE &&
724
0
      cinfo->global_state != DSTATE_PRESCAN)
725
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
726
  /* Limit scan number to valid range */
727
61.2k
  if (scan_number <= 0)
728
0
    scan_number = 1;
729
61.2k
  if (cinfo->inputctl->eoi_reached && scan_number > cinfo->input_scan_number)
730
0
    scan_number = cinfo->input_scan_number;
731
61.2k
  cinfo->output_scan_number = scan_number;
732
  /* Perform any dummy output passes, and set up for the real pass */
733
61.2k
  return output_pass_setup(cinfo);
734
61.2k
}
735
736
737
/*
738
 * Finish up after an output pass in buffered-image mode.
739
 *
740
 * Returns FALSE if suspended.  The return value need be inspected only if
741
 * a suspending data source is used.
742
 */
743
744
GLOBAL(boolean)
745
jpeg_finish_output(j_decompress_ptr cinfo)
746
60.7k
{
747
60.7k
  if ((cinfo->global_state == DSTATE_SCANNING ||
748
60.7k
       cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
749
    /* Terminate this pass. */
750
    /* We do not require the whole pass to have been completed. */
751
60.7k
    (*cinfo->master->finish_output_pass) (cinfo);
752
60.7k
    cinfo->global_state = DSTATE_BUFPOST;
753
60.7k
  } else if (cinfo->global_state != DSTATE_BUFPOST) {
754
    /* BUFPOST = repeat call after a suspension, anything else is error */
755
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
756
0
  }
757
  /* Read markers looking for SOS or EOI */
758
111k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
759
61.8k
         !cinfo->inputctl->eoi_reached) {
760
50.9k
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
761
108
      return FALSE;             /* Suspend, come back later */
762
50.9k
  }
763
60.6k
  cinfo->global_state = DSTATE_BUFIMAGE;
764
60.6k
  return TRUE;
765
60.7k
}
766
767
#endif /* D_MULTISCAN_FILES_SUPPORTED */
768
769
#endif /* BITS_IN_JSAMPLE == 8 */