Coverage Report

Created: 2026-03-12 08:02

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-2025, 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
160k
{
54
160k
  if (cinfo->global_state == DSTATE_READY) {
55
    /* First call: initialize master control, select active modules */
56
160k
    jinit_master_decompress(cinfo);
57
160k
    if (cinfo->buffered_image) {
58
      /* No more work here; expecting jpeg_start_output next */
59
23.2k
      cinfo->global_state = DSTATE_BUFIMAGE;
60
23.2k
      return TRUE;
61
23.2k
    }
62
136k
    cinfo->global_state = DSTATE_PRELOAD;
63
136k
  }
64
136k
  if (cinfo->global_state == DSTATE_PRELOAD) {
65
    /* If file has multiple scans, absorb them all into the coef buffer */
66
89.4k
    if (cinfo->inputctl->has_multiple_scans) {
67
63.7k
#ifdef D_MULTISCAN_FILES_SUPPORTED
68
996M
      for (;;) {
69
996M
        int retcode;
70
        /* Call progress monitor hook if present */
71
996M
        if (cinfo->progress != NULL)
72
996M
          (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
73
        /* Absorb some more input */
74
996M
        retcode = (*cinfo->inputctl->consume_input) (cinfo);
75
996M
        if (retcode == JPEG_SUSPENDED)
76
0
          return FALSE;
77
996M
        if (retcode == JPEG_REACHED_EOI)
78
51.3k
          break;
79
        /* Advance progress counter if appropriate */
80
996M
        if (cinfo->progress != NULL &&
81
996M
            (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
82
996M
          if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
83
            /* jdmaster underestimated number of scans; ratchet up one scan */
84
292k
            cinfo->progress->pass_limit += (long)cinfo->total_iMCU_rows;
85
292k
          }
86
996M
        }
87
996M
      }
88
#else
89
      ERREXIT(cinfo, JERR_NOT_COMPILED);
90
#endif /* D_MULTISCAN_FILES_SUPPORTED */
91
63.7k
    }
92
89.4k
    cinfo->output_scan_number = cinfo->input_scan_number;
93
89.4k
  } 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
136k
  return output_pass_setup(cinfo);
97
136k
}
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
19.5k
{
111
19.5k
  if (cinfo->global_state != DSTATE_PRESCAN) {
112
    /* First call: do pass setup */
113
19.5k
    (*cinfo->master->prepare_for_output_pass) (cinfo);
114
19.5k
    cinfo->output_scanline = 0;
115
19.5k
    cinfo->global_state = DSTATE_PRESCAN;
116
19.5k
  }
117
  /* Loop over any required dummy passes */
118
19.5k
  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
19.5k
  cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
168
19.5k
  return TRUE;
169
19.5k
}
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
3.20k
{
189
3.20k
  int ci, align, orig_downsampled_width;
190
3.20k
  JDIMENSION input_xoffset;
191
3.20k
  boolean reinit_upsampler = FALSE;
192
3.20k
  jpeg_component_info *compptr;
193
3.20k
#ifdef UPSAMPLE_MERGING_SUPPORTED
194
3.20k
  my_master_ptr master = (my_master_ptr)cinfo->master;
195
3.20k
#endif
196
197
3.20k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
198
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
199
200
3.20k
  if (cinfo->master->lossless)
201
0
    ERREXIT(cinfo, JERR_NOTIMPL);
202
203
3.20k
  if ((cinfo->global_state != DSTATE_SCANNING &&
204
3.20k
       cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0)
205
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
206
207
3.20k
  if (!xoffset || !width)
208
0
    ERREXIT(cinfo, JERR_BAD_CROP_SPEC);
209
210
  /* xoffset and width must fall within the output image dimensions. */
211
3.20k
  if (*width == 0 ||
212
3.20k
      (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
3.20k
  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
3.20k
  if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1)
238
2.82k
    align = cinfo->_min_DCT_scaled_size;
239
375
  else
240
375
    align = cinfo->_min_DCT_scaled_size * cinfo->max_h_samp_factor;
241
242
  /* Adjust xoffset to the nearest iMCU boundary <= the requested value */
243
3.20k
  input_xoffset = *xoffset;
244
3.20k
  *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
3.20k
  *width = *width + input_xoffset - *xoffset;
252
3.20k
  cinfo->output_width = *width;
253
3.20k
#ifdef UPSAMPLE_MERGING_SUPPORTED
254
3.20k
  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
3.20k
#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
3.20k
  cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align;
265
3.20k
  cinfo->master->last_iMCU_col =
266
3.20k
    (JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width),
267
3.20k
                              (long)align) - 1;
268
269
7.16k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
270
3.96k
       ci++, compptr++) {
271
3.96k
    int hsf = (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) ?
272
2.82k
              1 : compptr->h_samp_factor;
273
274
    /* Set downsampled_width to the new output width. */
275
3.96k
    orig_downsampled_width = compptr->downsampled_width;
276
3.96k
    compptr->downsampled_width =
277
3.96k
      (JDIMENSION)jdiv_round_up((long)cinfo->output_width *
278
3.96k
                                (long)(compptr->h_samp_factor *
279
3.96k
                                       compptr->_DCT_scaled_size),
280
3.96k
                                (long)(cinfo->max_h_samp_factor *
281
3.96k
                                       cinfo->_min_DCT_scaled_size));
282
3.96k
    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.96k
    cinfo->master->first_MCU_col[ci] =
289
3.96k
      (JDIMENSION)(long)(*xoffset * hsf) / (long)align;
290
3.96k
    cinfo->master->last_MCU_col[ci] =
291
3.96k
      (JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf),
292
3.96k
                                (long)align) - 1;
293
3.96k
  }
294
295
3.20k
  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
3.20k
}
jpeg12_crop_scanline
Line
Count
Source
188
1.26k
{
189
1.26k
  int ci, align, orig_downsampled_width;
190
1.26k
  JDIMENSION input_xoffset;
191
1.26k
  boolean reinit_upsampler = FALSE;
192
1.26k
  jpeg_component_info *compptr;
193
1.26k
#ifdef UPSAMPLE_MERGING_SUPPORTED
194
1.26k
  my_master_ptr master = (my_master_ptr)cinfo->master;
195
1.26k
#endif
196
197
1.26k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
198
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
199
200
1.26k
  if (cinfo->master->lossless)
201
0
    ERREXIT(cinfo, JERR_NOTIMPL);
202
203
1.26k
  if ((cinfo->global_state != DSTATE_SCANNING &&
204
1.26k
       cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0)
205
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
206
207
1.26k
  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.26k
  if (*width == 0 ||
212
1.26k
      (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.26k
  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.26k
  if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1)
238
1.03k
    align = cinfo->_min_DCT_scaled_size;
239
225
  else
240
225
    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.26k
  input_xoffset = *xoffset;
244
1.26k
  *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.26k
  *width = *width + input_xoffset - *xoffset;
252
1.26k
  cinfo->output_width = *width;
253
1.26k
#ifdef UPSAMPLE_MERGING_SUPPORTED
254
1.26k
  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.26k
#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.26k
  cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align;
265
1.26k
  cinfo->master->last_iMCU_col =
266
1.26k
    (JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width),
267
1.26k
                              (long)align) - 1;
268
269
2.98k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
270
1.71k
       ci++, compptr++) {
271
1.71k
    int hsf = (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) ?
272
1.03k
              1 : compptr->h_samp_factor;
273
274
    /* Set downsampled_width to the new output width. */
275
1.71k
    orig_downsampled_width = compptr->downsampled_width;
276
1.71k
    compptr->downsampled_width =
277
1.71k
      (JDIMENSION)jdiv_round_up((long)cinfo->output_width *
278
1.71k
                                (long)(compptr->h_samp_factor *
279
1.71k
                                       compptr->_DCT_scaled_size),
280
1.71k
                                (long)(cinfo->max_h_samp_factor *
281
1.71k
                                       cinfo->_min_DCT_scaled_size));
282
1.71k
    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
1.71k
    cinfo->master->first_MCU_col[ci] =
289
1.71k
      (JDIMENSION)(long)(*xoffset * hsf) / (long)align;
290
1.71k
    cinfo->master->last_MCU_col[ci] =
291
1.71k
      (JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf),
292
1.71k
                                (long)align) - 1;
293
1.71k
  }
294
295
1.26k
  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.26k
}
jpeg_crop_scanline
Line
Count
Source
188
1.93k
{
189
1.93k
  int ci, align, orig_downsampled_width;
190
1.93k
  JDIMENSION input_xoffset;
191
1.93k
  boolean reinit_upsampler = FALSE;
192
1.93k
  jpeg_component_info *compptr;
193
1.93k
#ifdef UPSAMPLE_MERGING_SUPPORTED
194
1.93k
  my_master_ptr master = (my_master_ptr)cinfo->master;
195
1.93k
#endif
196
197
1.93k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
198
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
199
200
1.93k
  if (cinfo->master->lossless)
201
0
    ERREXIT(cinfo, JERR_NOTIMPL);
202
203
1.93k
  if ((cinfo->global_state != DSTATE_SCANNING &&
204
1.93k
       cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0)
205
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
206
207
1.93k
  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.93k
  if (*width == 0 ||
212
1.93k
      (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.93k
  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.93k
  if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1)
238
1.78k
    align = cinfo->_min_DCT_scaled_size;
239
150
  else
240
150
    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.93k
  input_xoffset = *xoffset;
244
1.93k
  *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.93k
  *width = *width + input_xoffset - *xoffset;
252
1.93k
  cinfo->output_width = *width;
253
1.93k
#ifdef UPSAMPLE_MERGING_SUPPORTED
254
1.93k
  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.93k
#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.93k
  cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align;
265
1.93k
  cinfo->master->last_iMCU_col =
266
1.93k
    (JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width),
267
1.93k
                              (long)align) - 1;
268
269
4.18k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
270
2.24k
       ci++, compptr++) {
271
2.24k
    int hsf = (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) ?
272
1.78k
              1 : compptr->h_samp_factor;
273
274
    /* Set downsampled_width to the new output width. */
275
2.24k
    orig_downsampled_width = compptr->downsampled_width;
276
2.24k
    compptr->downsampled_width =
277
2.24k
      (JDIMENSION)jdiv_round_up((long)cinfo->output_width *
278
2.24k
                                (long)(compptr->h_samp_factor *
279
2.24k
                                       compptr->_DCT_scaled_size),
280
2.24k
                                (long)(cinfo->max_h_samp_factor *
281
2.24k
                                       cinfo->_min_DCT_scaled_size));
282
2.24k
    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.24k
    cinfo->master->first_MCU_col[ci] =
289
2.24k
      (JDIMENSION)(long)(*xoffset * hsf) / (long)align;
290
2.24k
    cinfo->master->last_MCU_col[ci] =
291
2.24k
      (JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf),
292
2.24k
                                (long)align) - 1;
293
2.24k
  }
294
295
1.93k
  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.93k
}
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
21.9M
{
322
21.9M
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
323
21.9M
  JDIMENSION row_ctr;
324
325
21.9M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
326
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
327
328
21.9M
  if (cinfo->global_state != DSTATE_SCANNING)
329
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
330
21.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
21.9M
  if (cinfo->progress != NULL) {
337
21.9M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
338
21.9M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
339
21.9M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
340
21.9M
  }
341
342
  /* Process some data */
343
21.9M
  row_ctr = 0;
344
21.9M
  if (cinfo->main->_process_data == NULL)
345
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
346
21.9M
  (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
347
21.9M
  cinfo->output_scanline += row_ctr;
348
21.9M
  return row_ctr;
349
#else
350
  ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
351
  return 0;
352
#endif
353
21.9M
}
jpeg12_read_scanlines
Line
Count
Source
321
8.41M
{
322
8.41M
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
323
8.41M
  JDIMENSION row_ctr;
324
325
8.41M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
326
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
327
328
8.41M
  if (cinfo->global_state != DSTATE_SCANNING)
329
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
330
8.41M
  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.41M
  if (cinfo->progress != NULL) {
337
8.41M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
338
8.41M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
339
8.41M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
340
8.41M
  }
341
342
  /* Process some data */
343
8.41M
  row_ctr = 0;
344
8.41M
  if (cinfo->main->_process_data == NULL)
345
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
346
8.41M
  (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
347
8.41M
  cinfo->output_scanline += row_ctr;
348
8.41M
  return row_ctr;
349
#else
350
  ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
351
  return 0;
352
#endif
353
8.41M
}
jpeg16_read_scanlines
Line
Count
Source
321
626k
{
322
626k
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
323
626k
  JDIMENSION row_ctr;
324
325
626k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
326
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
327
328
626k
  if (cinfo->global_state != DSTATE_SCANNING)
329
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
330
626k
  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
626k
  if (cinfo->progress != NULL) {
337
626k
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
338
626k
    cinfo->progress->pass_limit = (long)cinfo->output_height;
339
626k
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
340
626k
  }
341
342
  /* Process some data */
343
626k
  row_ctr = 0;
344
626k
  if (cinfo->main->_process_data == NULL)
345
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
346
626k
  (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
347
626k
  cinfo->output_scanline += row_ctr;
348
626k
  return row_ctr;
349
#else
350
  ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
351
  return 0;
352
#endif
353
626k
}
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
7
{
385
7
  JDIMENSION n;
386
7
#ifdef UPSAMPLE_MERGING_SUPPORTED
387
7
  my_master_ptr master = (my_master_ptr)cinfo->master;
388
7
#endif
389
7
  _JSAMPLE dummy_sample[1] = { 0 };
390
7
  _JSAMPROW dummy_row = dummy_sample;
391
7
  _JSAMPARRAY scanlines = NULL;
392
7
  void (*color_convert) (j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
393
7
                         JDIMENSION input_row, _JSAMPARRAY output_buf,
394
7
                         int num_rows) = NULL;
395
7
  void (*color_quantize) (j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
396
7
                          _JSAMPARRAY output_buf, int num_rows) = NULL;
397
398
7
  if (!master->using_merged_upsample && cinfo->cconvert &&
399
7
      cinfo->cconvert->_color_convert) {
400
7
    color_convert = cinfo->cconvert->_color_convert;
401
7
    cinfo->cconvert->_color_convert = noop_convert;
402
    /* This just prevents UBSan from complaining about adding 0 to a NULL
403
     * pointer.  The pointer isn't actually used.
404
     */
405
7
    scanlines = &dummy_row;
406
7
  }
407
408
7
  if (cinfo->quantize_colors && cinfo->cquantize &&
409
0
      cinfo->cquantize->_color_quantize) {
410
0
    color_quantize = cinfo->cquantize->_color_quantize;
411
0
    cinfo->cquantize->_color_quantize = noop_quantize;
412
0
  }
413
414
7
#ifdef UPSAMPLE_MERGING_SUPPORTED
415
7
  if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) {
416
0
    my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
417
0
    scanlines = &upsample->spare_row;
418
0
  }
419
7
#endif
420
421
7
  for (n = 0; n < num_lines; n++)
422
0
    _jpeg_read_scanlines(cinfo, scanlines, 1);
423
424
7
  if (color_convert)
425
7
    cinfo->cconvert->_color_convert = color_convert;
426
427
7
  if (color_quantize)
428
0
    cinfo->cquantize->_color_quantize = color_quantize;
429
7
}
430
431
432
/*
433
 * Called by _jpeg_skip_scanlines().  This partially skips a decompress block
434
 * by incrementing the rowgroup counter.
435
 */
436
437
LOCAL(void)
438
increment_simple_rowgroup_ctr(j_decompress_ptr cinfo, JDIMENSION rows)
439
7
{
440
7
  JDIMENSION rows_left;
441
7
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
442
7
  my_master_ptr master = (my_master_ptr)cinfo->master;
443
444
7
  if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) {
445
0
    read_and_discard_scanlines(cinfo, rows);
446
0
    return;
447
0
  }
448
449
  /* Increment the counter to the next row group after the skipped rows. */
450
7
  main_ptr->rowgroup_ctr += rows / cinfo->max_v_samp_factor;
451
452
  /* Partially skipping a row group would involve modifying the internal state
453
   * of the upsampler, so read the remaining rows into a dummy buffer instead.
454
   */
455
7
  rows_left = rows % cinfo->max_v_samp_factor;
456
7
  cinfo->output_scanline += rows - rows_left;
457
458
7
  read_and_discard_scanlines(cinfo, rows_left);
459
7
}
460
461
/*
462
 * Skips some scanlines of data from the JPEG decompressor.
463
 *
464
 * The return value will be the number of lines actually skipped.  If skipping
465
 * num_lines would move beyond the end of the image, then the actual number of
466
 * lines remaining in the image is returned.  Otherwise, the return value will
467
 * be equal to num_lines.
468
 *
469
 * Refer to libjpeg.txt for more information.
470
 */
471
472
GLOBAL(JDIMENSION)
473
_jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
474
100k
{
475
100k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
476
100k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
477
100k
  my_master_ptr master = (my_master_ptr)cinfo->master;
478
100k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
479
100k
  JDIMENSION i, x;
480
100k
  int y;
481
100k
  JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
482
100k
  JDIMENSION lines_to_skip, lines_to_read;
483
484
100k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
485
122
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
486
487
100k
  if (cinfo->master->lossless)
488
0
    ERREXIT(cinfo, JERR_NOTIMPL);
489
490
  /* Two-pass color quantization is not supported. */
491
100k
  if (cinfo->quantize_colors && cinfo->two_pass_quantize)
492
0
    ERREXIT(cinfo, JERR_NOTIMPL);
493
494
100k
  if (cinfo->global_state != DSTATE_SCANNING)
495
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
496
497
  /* Do not skip past the bottom of the image. */
498
100k
  if ((unsigned long long)cinfo->output_scanline + num_lines >=
499
100k
      cinfo->output_height) {
500
6.04k
    num_lines = cinfo->output_height - cinfo->output_scanline;
501
6.04k
    cinfo->output_scanline = cinfo->output_height;
502
6.04k
    (*cinfo->inputctl->finish_input_pass) (cinfo);
503
6.04k
    cinfo->inputctl->eoi_reached = TRUE;
504
6.04k
    return num_lines;
505
6.04k
  }
506
507
94.0k
  if (num_lines == 0)
508
0
    return 0;
509
510
94.0k
  lines_per_iMCU_row = cinfo->_min_DCT_scaled_size * cinfo->max_v_samp_factor;
511
94.0k
  lines_left_in_iMCU_row =
512
94.0k
    (lines_per_iMCU_row - (cinfo->output_scanline % lines_per_iMCU_row)) %
513
94.0k
    lines_per_iMCU_row;
514
94.0k
  lines_after_iMCU_row = num_lines - lines_left_in_iMCU_row;
515
516
  /* Skip the lines remaining in the current iMCU row.  When upsampling
517
   * requires context rows, we need the previous and next rows in order to read
518
   * the current row.  This adds some complexity.
519
   */
520
94.0k
  if (cinfo->upsample->need_context_rows) {
521
    /* If the skipped lines would not move us past the current iMCU row, we
522
     * read the lines and ignore them.  There might be a faster way of doing
523
     * this, but we are facing increasing complexity for diminishing returns.
524
     * The increasing complexity would be a by-product of meddling with the
525
     * state machine used to skip context rows.  Near the end of an iMCU row,
526
     * the next iMCU row may have already been entropy-decoded.  In this unique
527
     * case, we will read the next iMCU row if we cannot skip past it as well.
528
     */
529
41.1k
    if ((num_lines < lines_left_in_iMCU_row + 1) ||
530
34.9k
        (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full &&
531
19.3k
         lines_after_iMCU_row < lines_per_iMCU_row + 1)) {
532
19.3k
      read_and_discard_scanlines(cinfo, num_lines);
533
19.3k
      return num_lines;
534
19.3k
    }
535
536
    /* If the next iMCU row has already been entropy-decoded, make sure that
537
     * we do not skip too far.
538
     */
539
21.8k
    if (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full) {
540
0
      cinfo->output_scanline += lines_left_in_iMCU_row + lines_per_iMCU_row;
541
0
      lines_after_iMCU_row -= lines_per_iMCU_row;
542
21.8k
    } else {
543
21.8k
      cinfo->output_scanline += lines_left_in_iMCU_row;
544
21.8k
    }
545
546
    /* If we have just completed the first block, adjust the buffer pointers */
547
21.8k
    if (main_ptr->iMCU_row_ctr == 0 ||
548
0
        (main_ptr->iMCU_row_ctr == 1 && lines_left_in_iMCU_row > 2))
549
21.8k
      set_wraparound_pointers(cinfo);
550
21.8k
    main_ptr->buffer_full = FALSE;
551
21.8k
    main_ptr->rowgroup_ctr = 0;
552
21.8k
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
553
21.8k
    if (!master->using_merged_upsample) {
554
21.8k
      upsample->next_row_out = cinfo->max_v_samp_factor;
555
21.8k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
556
21.8k
    }
557
21.8k
  }
558
559
  /* Skipping is much simpler when context rows are not required. */
560
52.9k
  else {
561
52.9k
    if (num_lines < lines_left_in_iMCU_row) {
562
8.06k
      increment_simple_rowgroup_ctr(cinfo, num_lines);
563
8.06k
      return num_lines;
564
44.8k
    } else {
565
44.8k
      cinfo->output_scanline += lines_left_in_iMCU_row;
566
44.8k
      main_ptr->buffer_full = FALSE;
567
44.8k
      main_ptr->rowgroup_ctr = 0;
568
44.8k
      if (!master->using_merged_upsample) {
569
44.7k
        upsample->next_row_out = cinfo->max_v_samp_factor;
570
44.7k
        upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
571
44.7k
      }
572
44.8k
    }
573
52.9k
  }
574
575
  /* Calculate how many full iMCU rows we can skip. */
576
66.6k
  if (cinfo->upsample->need_context_rows)
577
21.8k
    lines_to_skip = ((lines_after_iMCU_row - 1) / lines_per_iMCU_row) *
578
21.8k
                    lines_per_iMCU_row;
579
44.8k
  else
580
44.8k
    lines_to_skip = (lines_after_iMCU_row / lines_per_iMCU_row) *
581
44.8k
                    lines_per_iMCU_row;
582
  /* Calculate the number of lines that remain to be skipped after skipping all
583
   * of the full iMCU rows that we can.  We will not read these lines unless we
584
   * have to.
585
   */
586
66.6k
  lines_to_read = lines_after_iMCU_row - lines_to_skip;
587
588
  /* For images requiring multiple scans (progressive, non-interleaved, etc.),
589
   * all of the entropy decoding occurs in jpeg_start_decompress(), assuming
590
   * that the input data source is non-suspending.  This makes skipping easy.
591
   */
592
66.6k
  if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) {
593
53.3k
    if (cinfo->upsample->need_context_rows) {
594
20.6k
      cinfo->output_scanline += lines_to_skip;
595
20.6k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
596
20.6k
      main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
597
      /* It is complex to properly move to the middle of a context block, so
598
       * read the remaining lines instead of skipping them.
599
       */
600
20.6k
      read_and_discard_scanlines(cinfo, lines_to_read);
601
32.6k
    } else {
602
32.6k
      cinfo->output_scanline += lines_to_skip;
603
32.6k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
604
32.6k
      increment_simple_rowgroup_ctr(cinfo, lines_to_read);
605
32.6k
    }
606
53.3k
    if (!master->using_merged_upsample)
607
53.3k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
608
53.3k
    return num_lines;
609
53.3k
  }
610
611
  /* Skip the iMCU rows that we can safely skip. */
612
24.0k
  for (i = 0; i < lines_to_skip; i += lines_per_iMCU_row) {
613
22.1k
    for (y = 0; y < coef->MCU_rows_per_iMCU_row; y++) {
614
1.78M
      for (x = 0; x < cinfo->MCUs_per_row; x++) {
615
        /* Calling decode_mcu() with a NULL pointer causes it to discard the
616
         * decoded coefficients.  This is ~5% faster for large subsets, but
617
         * it's tough to tell a difference for smaller images.
618
         */
619
1.77M
        if (!cinfo->entropy->insufficient_data)
620
586k
          cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
621
1.77M
        (*cinfo->entropy->decode_mcu) (cinfo, NULL);
622
1.77M
      }
623
11.4k
    }
624
10.6k
    cinfo->input_iMCU_row++;
625
10.6k
    cinfo->output_iMCU_row++;
626
10.6k
    if (cinfo->input_iMCU_row < cinfo->total_iMCU_rows)
627
10.6k
      start_iMCU_row(cinfo);
628
0
    else
629
0
      (*cinfo->inputctl->finish_input_pass) (cinfo);
630
10.6k
  }
631
13.3k
  cinfo->output_scanline += lines_to_skip;
632
633
13.3k
  if (cinfo->upsample->need_context_rows) {
634
    /* Context-based upsampling keeps track of iMCU rows. */
635
1.13k
    main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
636
637
    /* It is complex to properly move to the middle of a context block, so
638
     * read the remaining lines instead of skipping them.
639
     */
640
1.13k
    read_and_discard_scanlines(cinfo, lines_to_read);
641
12.2k
  } else {
642
12.2k
    increment_simple_rowgroup_ctr(cinfo, lines_to_read);
643
12.2k
  }
644
645
  /* Since skipping lines involves skipping the upsampling step, the value of
646
   * "rows_to_go" will become invalid unless we set it here.  NOTE: This is a
647
   * bit odd, since "rows_to_go" seems to be redundantly keeping track of
648
   * output_scanline.
649
   */
650
13.3k
  if (!master->using_merged_upsample)
651
13.2k
    upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
652
653
  /* Always skip the requested number of lines. */
654
13.3k
  return num_lines;
655
66.6k
}
jpeg12_skip_scanlines
Line
Count
Source
474
2.42k
{
475
2.42k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
476
2.42k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
477
2.42k
  my_master_ptr master = (my_master_ptr)cinfo->master;
478
2.42k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
479
2.42k
  JDIMENSION i, x;
480
2.42k
  int y;
481
2.42k
  JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
482
2.42k
  JDIMENSION lines_to_skip, lines_to_read;
483
484
2.42k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
485
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
486
487
2.42k
  if (cinfo->master->lossless)
488
0
    ERREXIT(cinfo, JERR_NOTIMPL);
489
490
  /* Two-pass color quantization is not supported. */
491
2.42k
  if (cinfo->quantize_colors && cinfo->two_pass_quantize)
492
0
    ERREXIT(cinfo, JERR_NOTIMPL);
493
494
2.42k
  if (cinfo->global_state != DSTATE_SCANNING)
495
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
496
497
  /* Do not skip past the bottom of the image. */
498
2.42k
  if ((unsigned long long)cinfo->output_scanline + num_lines >=
499
2.42k
      cinfo->output_height) {
500
1.16k
    num_lines = cinfo->output_height - cinfo->output_scanline;
501
1.16k
    cinfo->output_scanline = cinfo->output_height;
502
1.16k
    (*cinfo->inputctl->finish_input_pass) (cinfo);
503
1.16k
    cinfo->inputctl->eoi_reached = TRUE;
504
1.16k
    return num_lines;
505
1.16k
  }
506
507
1.25k
  if (num_lines == 0)
508
0
    return 0;
509
510
1.25k
  lines_per_iMCU_row = cinfo->_min_DCT_scaled_size * cinfo->max_v_samp_factor;
511
1.25k
  lines_left_in_iMCU_row =
512
1.25k
    (lines_per_iMCU_row - (cinfo->output_scanline % lines_per_iMCU_row)) %
513
1.25k
    lines_per_iMCU_row;
514
1.25k
  lines_after_iMCU_row = num_lines - lines_left_in_iMCU_row;
515
516
  /* Skip the lines remaining in the current iMCU row.  When upsampling
517
   * requires context rows, we need the previous and next rows in order to read
518
   * the current row.  This adds some complexity.
519
   */
520
1.25k
  if (cinfo->upsample->need_context_rows) {
521
    /* If the skipped lines would not move us past the current iMCU row, we
522
     * read the lines and ignore them.  There might be a faster way of doing
523
     * this, but we are facing increasing complexity for diminishing returns.
524
     * The increasing complexity would be a by-product of meddling with the
525
     * state machine used to skip context rows.  Near the end of an iMCU row,
526
     * the next iMCU row may have already been entropy-decoded.  In this unique
527
     * case, we will read the next iMCU row if we cannot skip past it as well.
528
     */
529
56
    if ((num_lines < lines_left_in_iMCU_row + 1) ||
530
56
        (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full &&
531
0
         lines_after_iMCU_row < lines_per_iMCU_row + 1)) {
532
0
      read_and_discard_scanlines(cinfo, num_lines);
533
0
      return num_lines;
534
0
    }
535
536
    /* If the next iMCU row has already been entropy-decoded, make sure that
537
     * we do not skip too far.
538
     */
539
56
    if (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full) {
540
0
      cinfo->output_scanline += lines_left_in_iMCU_row + lines_per_iMCU_row;
541
0
      lines_after_iMCU_row -= lines_per_iMCU_row;
542
56
    } else {
543
56
      cinfo->output_scanline += lines_left_in_iMCU_row;
544
56
    }
545
546
    /* If we have just completed the first block, adjust the buffer pointers */
547
56
    if (main_ptr->iMCU_row_ctr == 0 ||
548
0
        (main_ptr->iMCU_row_ctr == 1 && lines_left_in_iMCU_row > 2))
549
56
      set_wraparound_pointers(cinfo);
550
56
    main_ptr->buffer_full = FALSE;
551
56
    main_ptr->rowgroup_ctr = 0;
552
56
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
553
56
    if (!master->using_merged_upsample) {
554
56
      upsample->next_row_out = cinfo->max_v_samp_factor;
555
56
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
556
56
    }
557
56
  }
558
559
  /* Skipping is much simpler when context rows are not required. */
560
1.20k
  else {
561
1.20k
    if (num_lines < lines_left_in_iMCU_row) {
562
0
      increment_simple_rowgroup_ctr(cinfo, num_lines);
563
0
      return num_lines;
564
1.20k
    } else {
565
1.20k
      cinfo->output_scanline += lines_left_in_iMCU_row;
566
1.20k
      main_ptr->buffer_full = FALSE;
567
1.20k
      main_ptr->rowgroup_ctr = 0;
568
1.20k
      if (!master->using_merged_upsample) {
569
1.20k
        upsample->next_row_out = cinfo->max_v_samp_factor;
570
1.20k
        upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
571
1.20k
      }
572
1.20k
    }
573
1.20k
  }
574
575
  /* Calculate how many full iMCU rows we can skip. */
576
1.25k
  if (cinfo->upsample->need_context_rows)
577
56
    lines_to_skip = ((lines_after_iMCU_row - 1) / lines_per_iMCU_row) *
578
56
                    lines_per_iMCU_row;
579
1.20k
  else
580
1.20k
    lines_to_skip = (lines_after_iMCU_row / lines_per_iMCU_row) *
581
1.20k
                    lines_per_iMCU_row;
582
  /* Calculate the number of lines that remain to be skipped after skipping all
583
   * of the full iMCU rows that we can.  We will not read these lines unless we
584
   * have to.
585
   */
586
1.25k
  lines_to_read = lines_after_iMCU_row - lines_to_skip;
587
588
  /* For images requiring multiple scans (progressive, non-interleaved, etc.),
589
   * all of the entropy decoding occurs in jpeg_start_decompress(), assuming
590
   * that the input data source is non-suspending.  This makes skipping easy.
591
   */
592
1.25k
  if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) {
593
883
    if (cinfo->upsample->need_context_rows) {
594
11
      cinfo->output_scanline += lines_to_skip;
595
11
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
596
11
      main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
597
      /* It is complex to properly move to the middle of a context block, so
598
       * read the remaining lines instead of skipping them.
599
       */
600
11
      read_and_discard_scanlines(cinfo, lines_to_read);
601
872
    } else {
602
872
      cinfo->output_scanline += lines_to_skip;
603
872
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
604
872
      increment_simple_rowgroup_ctr(cinfo, lines_to_read);
605
872
    }
606
883
    if (!master->using_merged_upsample)
607
883
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
608
883
    return num_lines;
609
883
  }
610
611
  /* Skip the iMCU rows that we can safely skip. */
612
887
  for (i = 0; i < lines_to_skip; i += lines_per_iMCU_row) {
613
1.21k
    for (y = 0; y < coef->MCU_rows_per_iMCU_row; y++) {
614
115k
      for (x = 0; x < cinfo->MCUs_per_row; x++) {
615
        /* Calling decode_mcu() with a NULL pointer causes it to discard the
616
         * decoded coefficients.  This is ~5% faster for large subsets, but
617
         * it's tough to tell a difference for smaller images.
618
         */
619
114k
        if (!cinfo->entropy->insufficient_data)
620
75.7k
          cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
621
114k
        (*cinfo->entropy->decode_mcu) (cinfo, NULL);
622
114k
      }
623
702
    }
624
512
    cinfo->input_iMCU_row++;
625
512
    cinfo->output_iMCU_row++;
626
512
    if (cinfo->input_iMCU_row < cinfo->total_iMCU_rows)
627
512
      start_iMCU_row(cinfo);
628
0
    else
629
0
      (*cinfo->inputctl->finish_input_pass) (cinfo);
630
512
  }
631
375
  cinfo->output_scanline += lines_to_skip;
632
633
375
  if (cinfo->upsample->need_context_rows) {
634
    /* Context-based upsampling keeps track of iMCU rows. */
635
45
    main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
636
637
    /* It is complex to properly move to the middle of a context block, so
638
     * read the remaining lines instead of skipping them.
639
     */
640
45
    read_and_discard_scanlines(cinfo, lines_to_read);
641
330
  } else {
642
330
    increment_simple_rowgroup_ctr(cinfo, lines_to_read);
643
330
  }
644
645
  /* Since skipping lines involves skipping the upsampling step, the value of
646
   * "rows_to_go" will become invalid unless we set it here.  NOTE: This is a
647
   * bit odd, since "rows_to_go" seems to be redundantly keeping track of
648
   * output_scanline.
649
   */
650
375
  if (!master->using_merged_upsample)
651
375
    upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
652
653
  /* Always skip the requested number of lines. */
654
375
  return num_lines;
655
1.25k
}
jpeg_skip_scanlines
Line
Count
Source
474
97.6k
{
475
97.6k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
476
97.6k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
477
97.6k
  my_master_ptr master = (my_master_ptr)cinfo->master;
478
97.6k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
479
97.6k
  JDIMENSION i, x;
480
97.6k
  int y;
481
97.6k
  JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
482
97.6k
  JDIMENSION lines_to_skip, lines_to_read;
483
484
97.6k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
485
122
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
486
487
97.6k
  if (cinfo->master->lossless)
488
0
    ERREXIT(cinfo, JERR_NOTIMPL);
489
490
  /* Two-pass color quantization is not supported. */
491
97.6k
  if (cinfo->quantize_colors && cinfo->two_pass_quantize)
492
0
    ERREXIT(cinfo, JERR_NOTIMPL);
493
494
97.6k
  if (cinfo->global_state != DSTATE_SCANNING)
495
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
496
497
  /* Do not skip past the bottom of the image. */
498
97.6k
  if ((unsigned long long)cinfo->output_scanline + num_lines >=
499
97.6k
      cinfo->output_height) {
500
4.88k
    num_lines = cinfo->output_height - cinfo->output_scanline;
501
4.88k
    cinfo->output_scanline = cinfo->output_height;
502
4.88k
    (*cinfo->inputctl->finish_input_pass) (cinfo);
503
4.88k
    cinfo->inputctl->eoi_reached = TRUE;
504
4.88k
    return num_lines;
505
4.88k
  }
506
507
92.7k
  if (num_lines == 0)
508
0
    return 0;
509
510
92.7k
  lines_per_iMCU_row = cinfo->_min_DCT_scaled_size * cinfo->max_v_samp_factor;
511
92.7k
  lines_left_in_iMCU_row =
512
92.7k
    (lines_per_iMCU_row - (cinfo->output_scanline % lines_per_iMCU_row)) %
513
92.7k
    lines_per_iMCU_row;
514
92.7k
  lines_after_iMCU_row = num_lines - lines_left_in_iMCU_row;
515
516
  /* Skip the lines remaining in the current iMCU row.  When upsampling
517
   * requires context rows, we need the previous and next rows in order to read
518
   * the current row.  This adds some complexity.
519
   */
520
92.7k
  if (cinfo->upsample->need_context_rows) {
521
    /* If the skipped lines would not move us past the current iMCU row, we
522
     * read the lines and ignore them.  There might be a faster way of doing
523
     * this, but we are facing increasing complexity for diminishing returns.
524
     * The increasing complexity would be a by-product of meddling with the
525
     * state machine used to skip context rows.  Near the end of an iMCU row,
526
     * the next iMCU row may have already been entropy-decoded.  In this unique
527
     * case, we will read the next iMCU row if we cannot skip past it as well.
528
     */
529
41.0k
    if ((num_lines < lines_left_in_iMCU_row + 1) ||
530
34.8k
        (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full &&
531
19.3k
         lines_after_iMCU_row < lines_per_iMCU_row + 1)) {
532
19.3k
      read_and_discard_scanlines(cinfo, num_lines);
533
19.3k
      return num_lines;
534
19.3k
    }
535
536
    /* If the next iMCU row has already been entropy-decoded, make sure that
537
     * we do not skip too far.
538
     */
539
21.7k
    if (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full) {
540
0
      cinfo->output_scanline += lines_left_in_iMCU_row + lines_per_iMCU_row;
541
0
      lines_after_iMCU_row -= lines_per_iMCU_row;
542
21.7k
    } else {
543
21.7k
      cinfo->output_scanline += lines_left_in_iMCU_row;
544
21.7k
    }
545
546
    /* If we have just completed the first block, adjust the buffer pointers */
547
21.7k
    if (main_ptr->iMCU_row_ctr == 0 ||
548
0
        (main_ptr->iMCU_row_ctr == 1 && lines_left_in_iMCU_row > 2))
549
21.7k
      set_wraparound_pointers(cinfo);
550
21.7k
    main_ptr->buffer_full = FALSE;
551
21.7k
    main_ptr->rowgroup_ctr = 0;
552
21.7k
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
553
21.7k
    if (!master->using_merged_upsample) {
554
21.7k
      upsample->next_row_out = cinfo->max_v_samp_factor;
555
21.7k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
556
21.7k
    }
557
21.7k
  }
558
559
  /* Skipping is much simpler when context rows are not required. */
560
51.7k
  else {
561
51.7k
    if (num_lines < lines_left_in_iMCU_row) {
562
8.06k
      increment_simple_rowgroup_ctr(cinfo, num_lines);
563
8.06k
      return num_lines;
564
43.6k
    } else {
565
43.6k
      cinfo->output_scanline += lines_left_in_iMCU_row;
566
43.6k
      main_ptr->buffer_full = FALSE;
567
43.6k
      main_ptr->rowgroup_ctr = 0;
568
43.6k
      if (!master->using_merged_upsample) {
569
43.5k
        upsample->next_row_out = cinfo->max_v_samp_factor;
570
43.5k
        upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
571
43.5k
      }
572
43.6k
    }
573
51.7k
  }
574
575
  /* Calculate how many full iMCU rows we can skip. */
576
65.3k
  if (cinfo->upsample->need_context_rows)
577
21.7k
    lines_to_skip = ((lines_after_iMCU_row - 1) / lines_per_iMCU_row) *
578
21.7k
                    lines_per_iMCU_row;
579
43.6k
  else
580
43.6k
    lines_to_skip = (lines_after_iMCU_row / lines_per_iMCU_row) *
581
43.6k
                    lines_per_iMCU_row;
582
  /* Calculate the number of lines that remain to be skipped after skipping all
583
   * of the full iMCU rows that we can.  We will not read these lines unless we
584
   * have to.
585
   */
586
65.3k
  lines_to_read = lines_after_iMCU_row - lines_to_skip;
587
588
  /* For images requiring multiple scans (progressive, non-interleaved, etc.),
589
   * all of the entropy decoding occurs in jpeg_start_decompress(), assuming
590
   * that the input data source is non-suspending.  This makes skipping easy.
591
   */
592
65.3k
  if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) {
593
52.4k
    if (cinfo->upsample->need_context_rows) {
594
20.6k
      cinfo->output_scanline += lines_to_skip;
595
20.6k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
596
20.6k
      main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
597
      /* It is complex to properly move to the middle of a context block, so
598
       * read the remaining lines instead of skipping them.
599
       */
600
20.6k
      read_and_discard_scanlines(cinfo, lines_to_read);
601
31.7k
    } else {
602
31.7k
      cinfo->output_scanline += lines_to_skip;
603
31.7k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
604
31.7k
      increment_simple_rowgroup_ctr(cinfo, lines_to_read);
605
31.7k
    }
606
52.4k
    if (!master->using_merged_upsample)
607
52.4k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
608
52.4k
    return num_lines;
609
52.4k
  }
610
611
  /* Skip the iMCU rows that we can safely skip. */
612
23.1k
  for (i = 0; i < lines_to_skip; i += lines_per_iMCU_row) {
613
20.9k
    for (y = 0; y < coef->MCU_rows_per_iMCU_row; y++) {
614
1.66M
      for (x = 0; x < cinfo->MCUs_per_row; x++) {
615
        /* Calling decode_mcu() with a NULL pointer causes it to discard the
616
         * decoded coefficients.  This is ~5% faster for large subsets, but
617
         * it's tough to tell a difference for smaller images.
618
         */
619
1.65M
        if (!cinfo->entropy->insufficient_data)
620
510k
          cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
621
1.65M
        (*cinfo->entropy->decode_mcu) (cinfo, NULL);
622
1.65M
      }
623
10.7k
    }
624
10.1k
    cinfo->input_iMCU_row++;
625
10.1k
    cinfo->output_iMCU_row++;
626
10.1k
    if (cinfo->input_iMCU_row < cinfo->total_iMCU_rows)
627
10.1k
      start_iMCU_row(cinfo);
628
0
    else
629
0
      (*cinfo->inputctl->finish_input_pass) (cinfo);
630
10.1k
  }
631
12.9k
  cinfo->output_scanline += lines_to_skip;
632
633
12.9k
  if (cinfo->upsample->need_context_rows) {
634
    /* Context-based upsampling keeps track of iMCU rows. */
635
1.08k
    main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
636
637
    /* It is complex to properly move to the middle of a context block, so
638
     * read the remaining lines instead of skipping them.
639
     */
640
1.08k
    read_and_discard_scanlines(cinfo, lines_to_read);
641
11.8k
  } else {
642
11.8k
    increment_simple_rowgroup_ctr(cinfo, lines_to_read);
643
11.8k
  }
644
645
  /* Since skipping lines involves skipping the upsampling step, the value of
646
   * "rows_to_go" will become invalid unless we set it here.  NOTE: This is a
647
   * bit odd, since "rows_to_go" seems to be redundantly keeping track of
648
   * output_scanline.
649
   */
650
12.9k
  if (!master->using_merged_upsample)
651
12.8k
    upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
652
653
  /* Always skip the requested number of lines. */
654
12.9k
  return num_lines;
655
65.3k
}
656
657
/*
658
 * Alternate entry point to read raw data.
659
 * Processes exactly one iMCU row per call, unless suspended.
660
 */
661
662
GLOBAL(JDIMENSION)
663
_jpeg_read_raw_data(j_decompress_ptr cinfo, _JSAMPIMAGE data,
664
                    JDIMENSION max_lines)
665
7.06M
{
666
7.06M
  JDIMENSION lines_per_iMCU_row;
667
668
7.06M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
669
7.39k
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
670
671
7.06M
  if (cinfo->master->lossless)
672
2.08k
    ERREXIT(cinfo, JERR_NOTIMPL);
673
674
7.06M
  if (cinfo->global_state != DSTATE_RAW_OK)
675
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
676
7.06M
  if (cinfo->output_scanline >= cinfo->output_height) {
677
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
678
0
    return 0;
679
0
  }
680
681
  /* Call progress monitor hook if present */
682
7.06M
  if (cinfo->progress != NULL) {
683
7.05M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
684
7.05M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
685
7.05M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
686
7.05M
  }
687
688
  /* Verify that at least one iMCU row can be returned. */
689
7.06M
  lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size;
690
7.06M
  if (max_lines < lines_per_iMCU_row)
691
0
    ERREXIT(cinfo, JERR_BUFFER_SIZE);
692
693
  /* Decompress directly into user's buffer. */
694
7.06M
  if (cinfo->coef->_decompress_data == NULL)
695
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
696
7.06M
  if (!(*cinfo->coef->_decompress_data) (cinfo, data))
697
0
    return 0;                   /* suspension forced, can do nothing more */
698
699
  /* OK, we processed one iMCU row. */
700
7.06M
  cinfo->output_scanline += lines_per_iMCU_row;
701
7.06M
  return lines_per_iMCU_row;
702
7.06M
}
Unexecuted instantiation: jpeg12_read_raw_data
jpeg_read_raw_data
Line
Count
Source
665
7.06M
{
666
7.06M
  JDIMENSION lines_per_iMCU_row;
667
668
7.06M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
669
7.39k
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
670
671
7.06M
  if (cinfo->master->lossless)
672
2.08k
    ERREXIT(cinfo, JERR_NOTIMPL);
673
674
7.06M
  if (cinfo->global_state != DSTATE_RAW_OK)
675
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
676
7.06M
  if (cinfo->output_scanline >= cinfo->output_height) {
677
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
678
0
    return 0;
679
0
  }
680
681
  /* Call progress monitor hook if present */
682
7.06M
  if (cinfo->progress != NULL) {
683
7.05M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
684
7.05M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
685
7.05M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
686
7.05M
  }
687
688
  /* Verify that at least one iMCU row can be returned. */
689
7.06M
  lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size;
690
7.06M
  if (max_lines < lines_per_iMCU_row)
691
0
    ERREXIT(cinfo, JERR_BUFFER_SIZE);
692
693
  /* Decompress directly into user's buffer. */
694
7.06M
  if (cinfo->coef->_decompress_data == NULL)
695
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
696
7.06M
  if (!(*cinfo->coef->_decompress_data) (cinfo, data))
697
0
    return 0;                   /* suspension forced, can do nothing more */
698
699
  /* OK, we processed one iMCU row. */
700
7.06M
  cinfo->output_scanline += lines_per_iMCU_row;
701
7.06M
  return lines_per_iMCU_row;
702
7.06M
}
703
704
#endif /* BITS_IN_JSAMPLE != 16 */
705
706
707
#if BITS_IN_JSAMPLE == 8
708
709
/* Additional entry points for buffered-image mode. */
710
711
#ifdef D_MULTISCAN_FILES_SUPPORTED
712
713
/*
714
 * Initialize for an output pass in buffered-image mode.
715
 */
716
717
GLOBAL(boolean)
718
jpeg_start_output(j_decompress_ptr cinfo, int scan_number)
719
56.7k
{
720
56.7k
  if (cinfo->global_state != DSTATE_BUFIMAGE &&
721
0
      cinfo->global_state != DSTATE_PRESCAN)
722
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
723
  /* Limit scan number to valid range */
724
56.7k
  if (scan_number <= 0)
725
0
    scan_number = 1;
726
56.7k
  if (cinfo->inputctl->eoi_reached && scan_number > cinfo->input_scan_number)
727
0
    scan_number = cinfo->input_scan_number;
728
56.7k
  cinfo->output_scan_number = scan_number;
729
  /* Perform any dummy output passes, and set up for the real pass */
730
56.7k
  return output_pass_setup(cinfo);
731
56.7k
}
732
733
734
/*
735
 * Finish up after an output pass in buffered-image mode.
736
 *
737
 * Returns FALSE if suspended.  The return value need be inspected only if
738
 * a suspending data source is used.
739
 */
740
741
GLOBAL(boolean)
742
jpeg_finish_output(j_decompress_ptr cinfo)
743
56.2k
{
744
56.2k
  if ((cinfo->global_state == DSTATE_SCANNING ||
745
56.2k
       cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
746
    /* Terminate this pass. */
747
    /* We do not require the whole pass to have been completed. */
748
56.2k
    (*cinfo->master->finish_output_pass) (cinfo);
749
56.2k
    cinfo->global_state = DSTATE_BUFPOST;
750
56.2k
  } else if (cinfo->global_state != DSTATE_BUFPOST) {
751
    /* BUFPOST = repeat call after a suspension, anything else is error */
752
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
753
0
  }
754
  /* Read markers looking for SOS or EOI */
755
102k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
756
55.8k
         !cinfo->inputctl->eoi_reached) {
757
46.7k
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
758
61
      return FALSE;             /* Suspend, come back later */
759
46.7k
  }
760
56.1k
  cinfo->global_state = DSTATE_BUFIMAGE;
761
56.1k
  return TRUE;
762
56.2k
}
763
764
#endif /* D_MULTISCAN_FILES_SUPPORTED */
765
766
#endif /* BITS_IN_JSAMPLE == 8 */