Coverage Report

Created: 2026-08-31 07:19

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
174k
{
54
174k
  if (cinfo->global_state == DSTATE_READY) {
55
    /* First call: initialize master control, select active modules */
56
174k
    jinit_master_decompress(cinfo);
57
174k
    if (cinfo->buffered_image) {
58
      /* No more work here; expecting jpeg_start_output next */
59
24.9k
      cinfo->global_state = DSTATE_BUFIMAGE;
60
24.9k
      return TRUE;
61
24.9k
    }
62
149k
    cinfo->global_state = DSTATE_PRELOAD;
63
149k
  }
64
149k
  if (cinfo->global_state == DSTATE_PRELOAD) {
65
    /* If file has multiple scans, absorb them all into the coef buffer */
66
90.7k
    if (cinfo->inputctl->has_multiple_scans) {
67
60.8k
#ifdef D_MULTISCAN_FILES_SUPPORTED
68
354M
      for (;;) {
69
354M
        int retcode;
70
        /* Call progress monitor hook if present */
71
354M
        if (cinfo->progress != NULL)
72
354M
          (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
73
        /* Absorb some more input */
74
354M
        retcode = (*cinfo->inputctl->consume_input) (cinfo);
75
354M
        if (retcode == JPEG_SUSPENDED)
76
0
          return FALSE;
77
354M
        if (retcode == JPEG_REACHED_EOI)
78
49.2k
          break;
79
        /* Advance progress counter if appropriate */
80
354M
        if (cinfo->progress != NULL &&
81
354M
            (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
82
354M
          if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
83
            /* jdmaster underestimated number of scans; ratchet up one scan */
84
191k
            cinfo->progress->pass_limit += (long)cinfo->total_iMCU_rows;
85
191k
          }
86
354M
        }
87
354M
      }
88
#else
89
      ERREXIT(cinfo, JERR_NOT_COMPILED);
90
#endif /* D_MULTISCAN_FILES_SUPPORTED */
91
60.8k
    }
92
90.7k
    cinfo->output_scan_number = cinfo->input_scan_number;
93
90.7k
  } 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
149k
  return output_pass_setup(cinfo);
97
149k
}
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
20.9k
{
111
20.9k
  if (cinfo->global_state != DSTATE_PRESCAN) {
112
    /* First call: do pass setup */
113
20.9k
    (*cinfo->master->prepare_for_output_pass) (cinfo);
114
20.9k
    cinfo->output_scanline = 0;
115
20.9k
    cinfo->global_state = DSTATE_PRESCAN;
116
20.9k
  }
117
  /* Loop over any required dummy passes */
118
20.9k
  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
20.9k
  cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
168
20.9k
  return TRUE;
169
20.9k
}
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.37k
{
189
4.37k
  int ci, align, orig_downsampled_width;
190
4.37k
  JDIMENSION input_xoffset;
191
4.37k
  boolean reinit_upsampler = FALSE;
192
4.37k
  jpeg_component_info *compptr;
193
4.37k
#ifdef UPSAMPLE_MERGING_SUPPORTED
194
4.37k
  my_master_ptr master = (my_master_ptr)cinfo->master;
195
4.37k
#endif
196
197
4.37k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
198
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
199
200
4.37k
  if (cinfo->master->lossless || cinfo->raw_data_out)
201
0
    ERREXIT(cinfo, JERR_NOTIMPL);
202
203
4.37k
  if ((cinfo->global_state != DSTATE_SCANNING &&
204
4.37k
       cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0)
205
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
206
207
4.37k
  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.37k
  if (*width == 0 ||
212
4.37k
      (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.37k
  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.37k
  if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1)
238
4.00k
    align = cinfo->_min_DCT_scaled_size;
239
367
  else
240
367
    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.37k
  input_xoffset = *xoffset;
244
4.37k
  *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.37k
  *width = *width + input_xoffset - *xoffset;
252
4.37k
  cinfo->output_width = *width;
253
4.37k
#ifdef UPSAMPLE_MERGING_SUPPORTED
254
4.37k
  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.37k
#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.37k
  cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align;
265
4.37k
  cinfo->master->last_iMCU_col =
266
4.37k
    (JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width),
267
4.37k
                              (long)align) - 1;
268
269
9.54k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
270
5.16k
       ci++, compptr++) {
271
5.16k
    int hsf = (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) ?
272
4.00k
              1 : compptr->h_samp_factor;
273
274
    /* Set downsampled_width to the new output width. */
275
5.16k
    orig_downsampled_width = compptr->downsampled_width;
276
5.16k
    compptr->downsampled_width =
277
5.16k
      (JDIMENSION)jdiv_round_up((long)cinfo->output_width *
278
5.16k
                                (long)(compptr->h_samp_factor *
279
5.16k
                                       compptr->_DCT_scaled_size),
280
5.16k
                                (long)(cinfo->max_h_samp_factor *
281
5.16k
                                       cinfo->_min_DCT_scaled_size));
282
5.16k
    if (compptr->downsampled_width < 2 && orig_downsampled_width >= 2 &&
283
0
        !master->using_merged_upsample)
284
0
      reinit_upsampler = TRUE;
285
286
    /* Set the first and last iMCU columns that we must decompress.  These
287
     * values will be used in multi-scan decompressions.
288
     */
289
5.16k
    cinfo->master->first_MCU_col[ci] =
290
5.16k
      (JDIMENSION)(long)(*xoffset * hsf) / (long)align;
291
5.16k
    cinfo->master->last_MCU_col[ci] =
292
5.16k
      (JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf),
293
5.16k
                                (long)align) - 1;
294
5.16k
  }
295
296
4.37k
  if (reinit_upsampler) {
297
0
    cinfo->master->jinit_upsampler_no_alloc = TRUE;
298
0
    _jinit_upsampler(cinfo);
299
0
    cinfo->master->jinit_upsampler_no_alloc = FALSE;
300
0
  }
301
4.37k
}
jpeg12_crop_scanline
Line
Count
Source
188
2.08k
{
189
2.08k
  int ci, align, orig_downsampled_width;
190
2.08k
  JDIMENSION input_xoffset;
191
2.08k
  boolean reinit_upsampler = FALSE;
192
2.08k
  jpeg_component_info *compptr;
193
2.08k
#ifdef UPSAMPLE_MERGING_SUPPORTED
194
2.08k
  my_master_ptr master = (my_master_ptr)cinfo->master;
195
2.08k
#endif
196
197
2.08k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
198
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
199
200
2.08k
  if (cinfo->master->lossless || cinfo->raw_data_out)
201
0
    ERREXIT(cinfo, JERR_NOTIMPL);
202
203
2.08k
  if ((cinfo->global_state != DSTATE_SCANNING &&
204
2.08k
       cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0)
205
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
206
207
2.08k
  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.08k
  if (*width == 0 ||
212
2.08k
      (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.08k
  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.08k
  if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1)
238
1.88k
    align = cinfo->_min_DCT_scaled_size;
239
204
  else
240
204
    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.08k
  input_xoffset = *xoffset;
244
2.08k
  *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.08k
  *width = *width + input_xoffset - *xoffset;
252
2.08k
  cinfo->output_width = *width;
253
2.08k
#ifdef UPSAMPLE_MERGING_SUPPORTED
254
2.08k
  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.08k
#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.08k
  cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align;
265
2.08k
  cinfo->master->last_iMCU_col =
266
2.08k
    (JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width),
267
2.08k
                              (long)align) - 1;
268
269
4.61k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
270
2.52k
       ci++, compptr++) {
271
2.52k
    int hsf = (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) ?
272
1.88k
              1 : compptr->h_samp_factor;
273
274
    /* Set downsampled_width to the new output width. */
275
2.52k
    orig_downsampled_width = compptr->downsampled_width;
276
2.52k
    compptr->downsampled_width =
277
2.52k
      (JDIMENSION)jdiv_round_up((long)cinfo->output_width *
278
2.52k
                                (long)(compptr->h_samp_factor *
279
2.52k
                                       compptr->_DCT_scaled_size),
280
2.52k
                                (long)(cinfo->max_h_samp_factor *
281
2.52k
                                       cinfo->_min_DCT_scaled_size));
282
2.52k
    if (compptr->downsampled_width < 2 && orig_downsampled_width >= 2 &&
283
0
        !master->using_merged_upsample)
284
0
      reinit_upsampler = TRUE;
285
286
    /* Set the first and last iMCU columns that we must decompress.  These
287
     * values will be used in multi-scan decompressions.
288
     */
289
2.52k
    cinfo->master->first_MCU_col[ci] =
290
2.52k
      (JDIMENSION)(long)(*xoffset * hsf) / (long)align;
291
2.52k
    cinfo->master->last_MCU_col[ci] =
292
2.52k
      (JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf),
293
2.52k
                                (long)align) - 1;
294
2.52k
  }
295
296
2.08k
  if (reinit_upsampler) {
297
0
    cinfo->master->jinit_upsampler_no_alloc = TRUE;
298
0
    _jinit_upsampler(cinfo);
299
0
    cinfo->master->jinit_upsampler_no_alloc = FALSE;
300
0
  }
301
2.08k
}
jpeg_crop_scanline
Line
Count
Source
188
2.28k
{
189
2.28k
  int ci, align, orig_downsampled_width;
190
2.28k
  JDIMENSION input_xoffset;
191
2.28k
  boolean reinit_upsampler = FALSE;
192
2.28k
  jpeg_component_info *compptr;
193
2.28k
#ifdef UPSAMPLE_MERGING_SUPPORTED
194
2.28k
  my_master_ptr master = (my_master_ptr)cinfo->master;
195
2.28k
#endif
196
197
2.28k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
198
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
199
200
2.28k
  if (cinfo->master->lossless || cinfo->raw_data_out)
201
0
    ERREXIT(cinfo, JERR_NOTIMPL);
202
203
2.28k
  if ((cinfo->global_state != DSTATE_SCANNING &&
204
2.28k
       cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0)
205
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
206
207
2.28k
  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.28k
  if (*width == 0 ||
212
2.28k
      (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.28k
  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.28k
  if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1)
238
2.12k
    align = cinfo->_min_DCT_scaled_size;
239
163
  else
240
163
    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.28k
  input_xoffset = *xoffset;
244
2.28k
  *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.28k
  *width = *width + input_xoffset - *xoffset;
252
2.28k
  cinfo->output_width = *width;
253
2.28k
#ifdef UPSAMPLE_MERGING_SUPPORTED
254
2.28k
  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.28k
#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.28k
  cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align;
265
2.28k
  cinfo->master->last_iMCU_col =
266
2.28k
    (JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width),
267
2.28k
                              (long)align) - 1;
268
269
4.92k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
270
2.64k
       ci++, compptr++) {
271
2.64k
    int hsf = (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) ?
272
2.12k
              1 : compptr->h_samp_factor;
273
274
    /* Set downsampled_width to the new output width. */
275
2.64k
    orig_downsampled_width = compptr->downsampled_width;
276
2.64k
    compptr->downsampled_width =
277
2.64k
      (JDIMENSION)jdiv_round_up((long)cinfo->output_width *
278
2.64k
                                (long)(compptr->h_samp_factor *
279
2.64k
                                       compptr->_DCT_scaled_size),
280
2.64k
                                (long)(cinfo->max_h_samp_factor *
281
2.64k
                                       cinfo->_min_DCT_scaled_size));
282
2.64k
    if (compptr->downsampled_width < 2 && orig_downsampled_width >= 2 &&
283
0
        !master->using_merged_upsample)
284
0
      reinit_upsampler = TRUE;
285
286
    /* Set the first and last iMCU columns that we must decompress.  These
287
     * values will be used in multi-scan decompressions.
288
     */
289
2.64k
    cinfo->master->first_MCU_col[ci] =
290
2.64k
      (JDIMENSION)(long)(*xoffset * hsf) / (long)align;
291
2.64k
    cinfo->master->last_MCU_col[ci] =
292
2.64k
      (JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf),
293
2.64k
                                (long)align) - 1;
294
2.64k
  }
295
296
2.28k
  if (reinit_upsampler) {
297
0
    cinfo->master->jinit_upsampler_no_alloc = TRUE;
298
0
    _jinit_upsampler(cinfo);
299
0
    cinfo->master->jinit_upsampler_no_alloc = FALSE;
300
0
  }
301
2.28k
}
302
303
#endif /* BITS_IN_JSAMPLE != 16 */
304
305
306
/*
307
 * Read some scanlines of data from the JPEG decompressor.
308
 *
309
 * The return value will be the number of lines actually read.
310
 * This may be less than the number requested in several cases,
311
 * including bottom of image, data source suspension, and operating
312
 * modes that emit multiple scanlines at a time.
313
 *
314
 * Note: we warn about excess calls to _jpeg_read_scanlines() since
315
 * this likely signals an application programmer error.  However,
316
 * an oversize buffer (max_lines > scanlines remaining) is not an error.
317
 */
318
319
GLOBAL(JDIMENSION)
320
_jpeg_read_scanlines(j_decompress_ptr cinfo, _JSAMPARRAY scanlines,
321
                     JDIMENSION max_lines)
322
26.8M
{
323
26.8M
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
324
26.8M
  JDIMENSION row_ctr;
325
326
26.8M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
327
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
328
329
26.8M
  if (cinfo->global_state != DSTATE_SCANNING)
330
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
331
26.8M
  if (cinfo->output_scanline >= cinfo->output_height) {
332
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
333
0
    return 0;
334
0
  }
335
336
  /* Call progress monitor hook if present */
337
26.8M
  if (cinfo->progress != NULL) {
338
26.8M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
339
26.8M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
340
26.8M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
341
26.8M
  }
342
343
  /* Process some data */
344
26.8M
  row_ctr = 0;
345
26.8M
  if (cinfo->main->_process_data == NULL)
346
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
347
26.8M
  (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
348
26.8M
  cinfo->output_scanline += row_ctr;
349
26.8M
  return row_ctr;
350
#else
351
  ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
352
  return 0;
353
#endif
354
26.8M
}
jpeg12_read_scanlines
Line
Count
Source
322
9.89M
{
323
9.89M
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
324
9.89M
  JDIMENSION row_ctr;
325
326
9.89M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
327
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
328
329
9.89M
  if (cinfo->global_state != DSTATE_SCANNING)
330
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
331
9.89M
  if (cinfo->output_scanline >= cinfo->output_height) {
332
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
333
0
    return 0;
334
0
  }
335
336
  /* Call progress monitor hook if present */
337
9.89M
  if (cinfo->progress != NULL) {
338
9.89M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
339
9.89M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
340
9.89M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
341
9.89M
  }
342
343
  /* Process some data */
344
9.89M
  row_ctr = 0;
345
9.89M
  if (cinfo->main->_process_data == NULL)
346
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
347
9.89M
  (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
348
9.89M
  cinfo->output_scanline += row_ctr;
349
9.89M
  return row_ctr;
350
#else
351
  ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
352
  return 0;
353
#endif
354
9.89M
}
jpeg16_read_scanlines
Line
Count
Source
322
2.30M
{
323
2.30M
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
324
2.30M
  JDIMENSION row_ctr;
325
326
2.30M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
327
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
328
329
2.30M
  if (cinfo->global_state != DSTATE_SCANNING)
330
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
331
2.30M
  if (cinfo->output_scanline >= cinfo->output_height) {
332
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
333
0
    return 0;
334
0
  }
335
336
  /* Call progress monitor hook if present */
337
2.30M
  if (cinfo->progress != NULL) {
338
2.30M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
339
2.30M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
340
2.30M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
341
2.30M
  }
342
343
  /* Process some data */
344
2.30M
  row_ctr = 0;
345
2.30M
  if (cinfo->main->_process_data == NULL)
346
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
347
2.30M
  (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
348
2.30M
  cinfo->output_scanline += row_ctr;
349
2.30M
  return row_ctr;
350
#else
351
  ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
352
  return 0;
353
#endif
354
2.30M
}
jpeg_read_scanlines
Line
Count
Source
322
14.6M
{
323
14.6M
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
324
14.6M
  JDIMENSION row_ctr;
325
326
14.6M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
327
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
328
329
14.6M
  if (cinfo->global_state != DSTATE_SCANNING)
330
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
331
14.6M
  if (cinfo->output_scanline >= cinfo->output_height) {
332
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
333
0
    return 0;
334
0
  }
335
336
  /* Call progress monitor hook if present */
337
14.6M
  if (cinfo->progress != NULL) {
338
14.6M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
339
14.6M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
340
14.6M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
341
14.6M
  }
342
343
  /* Process some data */
344
14.6M
  row_ctr = 0;
345
14.6M
  if (cinfo->main->_process_data == NULL)
346
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
347
14.6M
  (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
348
14.6M
  cinfo->output_scanline += row_ctr;
349
14.6M
  return row_ctr;
350
#else
351
  ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
352
  return 0;
353
#endif
354
14.6M
}
355
356
357
#if BITS_IN_JSAMPLE != 16
358
359
/* Dummy color convert function used by _jpeg_skip_scanlines() */
360
LOCAL(void)
361
noop_convert(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
362
             JDIMENSION input_row, _JSAMPARRAY output_buf, int num_rows)
363
32
{
364
32
}
365
366
367
/* Dummy quantize function used by _jpeg_skip_scanlines() */
368
LOCAL(void)
369
noop_quantize(j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
370
              _JSAMPARRAY output_buf, int num_rows)
371
0
{
372
0
}
373
374
375
/*
376
 * In some cases, it is best to call _jpeg_read_scanlines() and discard the
377
 * output, rather than skipping the scanlines, because this allows us to
378
 * maintain the internal state of the context-based upsampler.  In these cases,
379
 * we set up and tear down a dummy color converter in order to avoid valgrind
380
 * errors and to achieve the best possible performance.
381
 */
382
383
LOCAL(void)
384
read_and_discard_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
385
63
{
386
63
  JDIMENSION n;
387
63
#ifdef UPSAMPLE_MERGING_SUPPORTED
388
63
  my_master_ptr master = (my_master_ptr)cinfo->master;
389
63
#endif
390
63
  _JSAMPLE dummy_sample[1] = { 0 };
391
63
  _JSAMPROW dummy_row = dummy_sample;
392
63
  _JSAMPARRAY scanlines = NULL;
393
63
  void (*color_convert) (j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
394
63
                         JDIMENSION input_row, _JSAMPARRAY output_buf,
395
63
                         int num_rows) = NULL;
396
63
  void (*color_quantize) (j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
397
63
                          _JSAMPARRAY output_buf, int num_rows) = NULL;
398
399
63
  if (cinfo->cconvert &&
400
63
#ifdef UPSAMPLE_MERGING_SUPPORTED
401
63
      !master->using_merged_upsample &&
402
63
#endif
403
63
      cinfo->cconvert->_color_convert) {
404
63
    color_convert = cinfo->cconvert->_color_convert;
405
63
    cinfo->cconvert->_color_convert = noop_convert;
406
    /* This just prevents UBSan from complaining about adding 0 to a NULL
407
     * pointer.  The pointer isn't actually used.
408
     */
409
63
    scanlines = &dummy_row;
410
63
  }
411
412
63
  if (cinfo->quantize_colors && cinfo->cquantize &&
413
0
      cinfo->cquantize->_color_quantize) {
414
0
    color_quantize = cinfo->cquantize->_color_quantize;
415
0
    cinfo->cquantize->_color_quantize = noop_quantize;
416
0
  }
417
418
63
#ifdef UPSAMPLE_MERGING_SUPPORTED
419
63
  if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) {
420
0
    my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
421
0
    scanlines = &upsample->spare_row;
422
0
  }
423
63
#endif
424
425
95
  for (n = 0; n < num_lines; n++)
426
32
    _jpeg_read_scanlines(cinfo, scanlines, 1);
427
428
63
  if (color_convert)
429
63
    cinfo->cconvert->_color_convert = color_convert;
430
431
63
  if (color_quantize)
432
0
    cinfo->cquantize->_color_quantize = color_quantize;
433
63
}
434
435
436
/*
437
 * Called by _jpeg_skip_scanlines().  This partially skips a decompress block
438
 * by incrementing the rowgroup counter.
439
 */
440
441
LOCAL(void)
442
increment_simple_rowgroup_ctr(j_decompress_ptr cinfo, JDIMENSION rows)
443
61
{
444
61
  JDIMENSION rows_left;
445
61
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
446
61
  my_master_ptr master = (my_master_ptr)cinfo->master;
447
448
61
  if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) {
449
0
    read_and_discard_scanlines(cinfo, rows);
450
0
    return;
451
0
  }
452
453
  /* Increment the counter to the next row group after the skipped rows. */
454
61
  main_ptr->rowgroup_ctr += rows / cinfo->max_v_samp_factor;
455
456
  /* Partially skipping a row group would involve modifying the internal state
457
   * of the upsampler, so read the remaining rows into a dummy buffer instead.
458
   */
459
61
  rows_left = rows % cinfo->max_v_samp_factor;
460
61
  cinfo->output_scanline += rows - rows_left;
461
462
61
  read_and_discard_scanlines(cinfo, rows_left);
463
61
}
464
465
/*
466
 * Skips some scanlines of data from the JPEG decompressor.
467
 *
468
 * The return value will be the number of lines actually skipped.  If skipping
469
 * num_lines would move beyond the end of the image, then the actual number of
470
 * lines remaining in the image is returned.  Otherwise, the return value will
471
 * be equal to num_lines.
472
 *
473
 * Refer to libjpeg.txt for more information.
474
 */
475
476
GLOBAL(JDIMENSION)
477
_jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
478
95.1k
{
479
95.1k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
480
95.1k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
481
95.1k
  my_master_ptr master = (my_master_ptr)cinfo->master;
482
95.1k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
483
95.1k
  JDIMENSION i, x;
484
95.1k
  int y;
485
95.1k
  JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
486
95.1k
  JDIMENSION lines_to_skip, lines_to_read;
487
488
95.1k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
489
183
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
490
491
95.1k
  if (cinfo->master->lossless)
492
0
    ERREXIT(cinfo, JERR_NOTIMPL);
493
494
  /* Two-pass color quantization is not supported. */
495
95.1k
  if (cinfo->quantize_colors && cinfo->two_pass_quantize)
496
0
    ERREXIT(cinfo, JERR_NOTIMPL);
497
498
95.1k
  if (cinfo->global_state != DSTATE_SCANNING)
499
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
500
501
  /* Do not skip past the bottom of the image. */
502
95.1k
  if ((unsigned long long)cinfo->output_scanline + num_lines >=
503
95.1k
      cinfo->output_height) {
504
6.80k
    num_lines = cinfo->output_height - cinfo->output_scanline;
505
6.80k
    cinfo->output_scanline = cinfo->output_height;
506
6.80k
    (*cinfo->inputctl->finish_input_pass) (cinfo);
507
6.80k
    cinfo->inputctl->eoi_reached = TRUE;
508
6.80k
    return num_lines;
509
6.80k
  }
510
511
88.3k
  if (num_lines == 0)
512
0
    return 0;
513
514
88.3k
  lines_per_iMCU_row = cinfo->_min_DCT_scaled_size * cinfo->max_v_samp_factor;
515
88.3k
  lines_left_in_iMCU_row =
516
88.3k
    (lines_per_iMCU_row - (cinfo->output_scanline % lines_per_iMCU_row)) %
517
88.3k
    lines_per_iMCU_row;
518
88.3k
  lines_after_iMCU_row = num_lines - lines_left_in_iMCU_row;
519
520
  /* Skip the lines remaining in the current iMCU row.  When upsampling
521
   * requires context rows, we need the previous and next rows in order to read
522
   * the current row.  This adds some complexity.
523
   */
524
88.3k
  if (cinfo->upsample->need_context_rows) {
525
    /* If the skipped lines would not move us past the current iMCU row, we
526
     * read the lines and ignore them.  There might be a faster way of doing
527
     * this, but we are facing increasing complexity for diminishing returns.
528
     * The increasing complexity would be a by-product of meddling with the
529
     * state machine used to skip context rows.  Near the end of an iMCU row,
530
     * the next iMCU row may have already been entropy-decoded.  In this unique
531
     * case, we will read the next iMCU row if we cannot skip past it as well.
532
     */
533
38.8k
    if ((num_lines < lines_left_in_iMCU_row + 1) ||
534
34.0k
        (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full &&
535
16.8k
         lines_after_iMCU_row < lines_per_iMCU_row + 1)) {
536
16.8k
      read_and_discard_scanlines(cinfo, num_lines);
537
16.8k
      return num_lines;
538
16.8k
    }
539
540
    /* If the next iMCU row has already been entropy-decoded, make sure that
541
     * we do not skip too far.
542
     */
543
22.0k
    if (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full) {
544
0
      cinfo->output_scanline += lines_left_in_iMCU_row + lines_per_iMCU_row;
545
0
      lines_after_iMCU_row -= lines_per_iMCU_row;
546
22.0k
    } else {
547
22.0k
      cinfo->output_scanline += lines_left_in_iMCU_row;
548
22.0k
    }
549
550
    /* If we have just completed the first block, adjust the buffer pointers */
551
22.0k
    if (main_ptr->iMCU_row_ctr == 0 ||
552
0
        (main_ptr->iMCU_row_ctr == 1 && lines_left_in_iMCU_row > 2))
553
22.0k
      set_wraparound_pointers(cinfo);
554
22.0k
    main_ptr->buffer_full = FALSE;
555
22.0k
    main_ptr->rowgroup_ctr = 0;
556
22.0k
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
557
22.0k
    if (!master->using_merged_upsample) {
558
22.0k
      upsample->next_row_out = cinfo->max_v_samp_factor;
559
22.0k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
560
22.0k
    }
561
22.0k
  }
562
563
  /* Skipping is much simpler when context rows are not required. */
564
49.4k
  else {
565
49.4k
    if (num_lines < lines_left_in_iMCU_row) {
566
4.74k
      increment_simple_rowgroup_ctr(cinfo, num_lines);
567
4.74k
      return num_lines;
568
44.6k
    } else {
569
44.6k
      cinfo->output_scanline += lines_left_in_iMCU_row;
570
44.6k
      main_ptr->buffer_full = FALSE;
571
44.6k
      main_ptr->rowgroup_ctr = 0;
572
44.6k
      if (!master->using_merged_upsample) {
573
44.5k
        upsample->next_row_out = cinfo->max_v_samp_factor;
574
44.5k
        upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
575
44.5k
      }
576
44.6k
    }
577
49.4k
  }
578
579
  /* Calculate how many full iMCU rows we can skip. */
580
66.6k
  if (cinfo->upsample->need_context_rows)
581
22.0k
    lines_to_skip = ((lines_after_iMCU_row - 1) / lines_per_iMCU_row) *
582
22.0k
                    lines_per_iMCU_row;
583
44.6k
  else
584
44.6k
    lines_to_skip = (lines_after_iMCU_row / lines_per_iMCU_row) *
585
44.6k
                    lines_per_iMCU_row;
586
  /* Calculate the number of lines that remain to be skipped after skipping all
587
   * of the full iMCU rows that we can.  We will not read these lines unless we
588
   * have to.
589
   */
590
66.6k
  lines_to_read = lines_after_iMCU_row - lines_to_skip;
591
592
  /* For images requiring multiple scans (progressive, non-interleaved, etc.),
593
   * all of the entropy decoding occurs in jpeg_start_decompress(), assuming
594
   * that the input data source is non-suspending.  This makes skipping easy.
595
   */
596
66.6k
  if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) {
597
52.2k
    if (cinfo->upsample->need_context_rows) {
598
20.8k
      cinfo->output_scanline += lines_to_skip;
599
20.8k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
600
20.8k
      main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
601
      /* It is complex to properly move to the middle of a context block, so
602
       * read the remaining lines instead of skipping them.
603
       */
604
20.8k
      read_and_discard_scanlines(cinfo, lines_to_read);
605
31.3k
    } else {
606
31.3k
      cinfo->output_scanline += lines_to_skip;
607
31.3k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
608
31.3k
      increment_simple_rowgroup_ctr(cinfo, lines_to_read);
609
31.3k
    }
610
52.2k
    if (!master->using_merged_upsample)
611
52.2k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
612
52.2k
    return num_lines;
613
52.2k
  }
614
615
  /* Skip the iMCU rows that we can safely skip. */
616
25.5k
  for (i = 0; i < lines_to_skip; i += lines_per_iMCU_row) {
617
23.4k
    for (y = 0; y < coef->MCU_rows_per_iMCU_row; y++) {
618
4.63M
      for (x = 0; x < cinfo->MCUs_per_row; x++) {
619
        /* Calling decode_mcu() with a NULL pointer causes it to discard the
620
         * decoded coefficients.  This is ~5% faster for large subsets, but
621
         * it's tough to tell a difference for smaller images.
622
         */
623
4.62M
        if (!cinfo->entropy->insufficient_data)
624
2.04M
          cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
625
4.62M
        (*cinfo->entropy->decode_mcu) (cinfo, NULL);
626
4.62M
      }
627
12.3k
    }
628
11.0k
    cinfo->input_iMCU_row++;
629
11.0k
    cinfo->output_iMCU_row++;
630
11.0k
    if (cinfo->input_iMCU_row < cinfo->total_iMCU_rows)
631
11.0k
      start_iMCU_row(cinfo);
632
0
    else
633
0
      (*cinfo->inputctl->finish_input_pass) (cinfo);
634
11.0k
  }
635
14.4k
  cinfo->output_scanline += lines_to_skip;
636
637
14.4k
  if (cinfo->upsample->need_context_rows) {
638
    /* Context-based upsampling keeps track of iMCU rows. */
639
1.10k
    main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
640
641
    /* It is complex to properly move to the middle of a context block, so
642
     * read the remaining lines instead of skipping them.
643
     */
644
1.10k
    read_and_discard_scanlines(cinfo, lines_to_read);
645
13.3k
  } else {
646
13.3k
    increment_simple_rowgroup_ctr(cinfo, lines_to_read);
647
13.3k
  }
648
649
  /* Since skipping lines involves skipping the upsampling step, the value of
650
   * "rows_to_go" will become invalid unless we set it here.  NOTE: This is a
651
   * bit odd, since "rows_to_go" seems to be redundantly keeping track of
652
   * output_scanline.
653
   */
654
14.4k
  if (!master->using_merged_upsample)
655
14.2k
    upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
656
657
  /* Always skip the requested number of lines. */
658
14.4k
  return num_lines;
659
66.6k
}
jpeg12_skip_scanlines
Line
Count
Source
478
4.13k
{
479
4.13k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
480
4.13k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
481
4.13k
  my_master_ptr master = (my_master_ptr)cinfo->master;
482
4.13k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
483
4.13k
  JDIMENSION i, x;
484
4.13k
  int y;
485
4.13k
  JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
486
4.13k
  JDIMENSION lines_to_skip, lines_to_read;
487
488
4.13k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
489
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
490
491
4.13k
  if (cinfo->master->lossless)
492
0
    ERREXIT(cinfo, JERR_NOTIMPL);
493
494
  /* Two-pass color quantization is not supported. */
495
4.13k
  if (cinfo->quantize_colors && cinfo->two_pass_quantize)
496
0
    ERREXIT(cinfo, JERR_NOTIMPL);
497
498
4.13k
  if (cinfo->global_state != DSTATE_SCANNING)
499
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
500
501
  /* Do not skip past the bottom of the image. */
502
4.13k
  if ((unsigned long long)cinfo->output_scanline + num_lines >=
503
4.13k
      cinfo->output_height) {
504
2.06k
    num_lines = cinfo->output_height - cinfo->output_scanline;
505
2.06k
    cinfo->output_scanline = cinfo->output_height;
506
2.06k
    (*cinfo->inputctl->finish_input_pass) (cinfo);
507
2.06k
    cinfo->inputctl->eoi_reached = TRUE;
508
2.06k
    return num_lines;
509
2.06k
  }
510
511
2.07k
  if (num_lines == 0)
512
0
    return 0;
513
514
2.07k
  lines_per_iMCU_row = cinfo->_min_DCT_scaled_size * cinfo->max_v_samp_factor;
515
2.07k
  lines_left_in_iMCU_row =
516
2.07k
    (lines_per_iMCU_row - (cinfo->output_scanline % lines_per_iMCU_row)) %
517
2.07k
    lines_per_iMCU_row;
518
2.07k
  lines_after_iMCU_row = num_lines - lines_left_in_iMCU_row;
519
520
  /* Skip the lines remaining in the current iMCU row.  When upsampling
521
   * requires context rows, we need the previous and next rows in order to read
522
   * the current row.  This adds some complexity.
523
   */
524
2.07k
  if (cinfo->upsample->need_context_rows) {
525
    /* If the skipped lines would not move us past the current iMCU row, we
526
     * read the lines and ignore them.  There might be a faster way of doing
527
     * this, but we are facing increasing complexity for diminishing returns.
528
     * The increasing complexity would be a by-product of meddling with the
529
     * state machine used to skip context rows.  Near the end of an iMCU row,
530
     * the next iMCU row may have already been entropy-decoded.  In this unique
531
     * case, we will read the next iMCU row if we cannot skip past it as well.
532
     */
533
54
    if ((num_lines < lines_left_in_iMCU_row + 1) ||
534
54
        (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full &&
535
0
         lines_after_iMCU_row < lines_per_iMCU_row + 1)) {
536
0
      read_and_discard_scanlines(cinfo, num_lines);
537
0
      return num_lines;
538
0
    }
539
540
    /* If the next iMCU row has already been entropy-decoded, make sure that
541
     * we do not skip too far.
542
     */
543
54
    if (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full) {
544
0
      cinfo->output_scanline += lines_left_in_iMCU_row + lines_per_iMCU_row;
545
0
      lines_after_iMCU_row -= lines_per_iMCU_row;
546
54
    } else {
547
54
      cinfo->output_scanline += lines_left_in_iMCU_row;
548
54
    }
549
550
    /* If we have just completed the first block, adjust the buffer pointers */
551
54
    if (main_ptr->iMCU_row_ctr == 0 ||
552
0
        (main_ptr->iMCU_row_ctr == 1 && lines_left_in_iMCU_row > 2))
553
54
      set_wraparound_pointers(cinfo);
554
54
    main_ptr->buffer_full = FALSE;
555
54
    main_ptr->rowgroup_ctr = 0;
556
54
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
557
54
    if (!master->using_merged_upsample) {
558
54
      upsample->next_row_out = cinfo->max_v_samp_factor;
559
54
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
560
54
    }
561
54
  }
562
563
  /* Skipping is much simpler when context rows are not required. */
564
2.02k
  else {
565
2.02k
    if (num_lines < lines_left_in_iMCU_row) {
566
0
      increment_simple_rowgroup_ctr(cinfo, num_lines);
567
0
      return num_lines;
568
2.02k
    } else {
569
2.02k
      cinfo->output_scanline += lines_left_in_iMCU_row;
570
2.02k
      main_ptr->buffer_full = FALSE;
571
2.02k
      main_ptr->rowgroup_ctr = 0;
572
2.02k
      if (!master->using_merged_upsample) {
573
2.02k
        upsample->next_row_out = cinfo->max_v_samp_factor;
574
2.02k
        upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
575
2.02k
      }
576
2.02k
    }
577
2.02k
  }
578
579
  /* Calculate how many full iMCU rows we can skip. */
580
2.07k
  if (cinfo->upsample->need_context_rows)
581
54
    lines_to_skip = ((lines_after_iMCU_row - 1) / lines_per_iMCU_row) *
582
54
                    lines_per_iMCU_row;
583
2.02k
  else
584
2.02k
    lines_to_skip = (lines_after_iMCU_row / lines_per_iMCU_row) *
585
2.02k
                    lines_per_iMCU_row;
586
  /* Calculate the number of lines that remain to be skipped after skipping all
587
   * of the full iMCU rows that we can.  We will not read these lines unless we
588
   * have to.
589
   */
590
2.07k
  lines_to_read = lines_after_iMCU_row - lines_to_skip;
591
592
  /* For images requiring multiple scans (progressive, non-interleaved, etc.),
593
   * all of the entropy decoding occurs in jpeg_start_decompress(), assuming
594
   * that the input data source is non-suspending.  This makes skipping easy.
595
   */
596
2.07k
  if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) {
597
1.20k
    if (cinfo->upsample->need_context_rows) {
598
10
      cinfo->output_scanline += lines_to_skip;
599
10
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
600
10
      main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
601
      /* It is complex to properly move to the middle of a context block, so
602
       * read the remaining lines instead of skipping them.
603
       */
604
10
      read_and_discard_scanlines(cinfo, lines_to_read);
605
1.19k
    } else {
606
1.19k
      cinfo->output_scanline += lines_to_skip;
607
1.19k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
608
1.19k
      increment_simple_rowgroup_ctr(cinfo, lines_to_read);
609
1.19k
    }
610
1.20k
    if (!master->using_merged_upsample)
611
1.20k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
612
1.20k
    return num_lines;
613
1.20k
  }
614
615
  /* Skip the iMCU rows that we can safely skip. */
616
2.20k
  for (i = 0; i < lines_to_skip; i += lines_per_iMCU_row) {
617
3.37k
    for (y = 0; y < coef->MCU_rows_per_iMCU_row; y++) {
618
292k
      for (x = 0; x < cinfo->MCUs_per_row; x++) {
619
        /* Calling decode_mcu() with a NULL pointer causes it to discard the
620
         * decoded coefficients.  This is ~5% faster for large subsets, but
621
         * it's tough to tell a difference for smaller images.
622
         */
623
290k
        if (!cinfo->entropy->insufficient_data)
624
109k
          cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
625
290k
        (*cinfo->entropy->decode_mcu) (cinfo, NULL);
626
290k
      }
627
2.04k
    }
628
1.32k
    cinfo->input_iMCU_row++;
629
1.32k
    cinfo->output_iMCU_row++;
630
1.32k
    if (cinfo->input_iMCU_row < cinfo->total_iMCU_rows)
631
1.32k
      start_iMCU_row(cinfo);
632
0
    else
633
0
      (*cinfo->inputctl->finish_input_pass) (cinfo);
634
1.32k
  }
635
878
  cinfo->output_scanline += lines_to_skip;
636
637
878
  if (cinfo->upsample->need_context_rows) {
638
    /* Context-based upsampling keeps track of iMCU rows. */
639
44
    main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
640
641
    /* It is complex to properly move to the middle of a context block, so
642
     * read the remaining lines instead of skipping them.
643
     */
644
44
    read_and_discard_scanlines(cinfo, lines_to_read);
645
834
  } else {
646
834
    increment_simple_rowgroup_ctr(cinfo, lines_to_read);
647
834
  }
648
649
  /* Since skipping lines involves skipping the upsampling step, the value of
650
   * "rows_to_go" will become invalid unless we set it here.  NOTE: This is a
651
   * bit odd, since "rows_to_go" seems to be redundantly keeping track of
652
   * output_scanline.
653
   */
654
878
  if (!master->using_merged_upsample)
655
878
    upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
656
657
  /* Always skip the requested number of lines. */
658
878
  return num_lines;
659
2.07k
}
jpeg_skip_scanlines
Line
Count
Source
478
90.9k
{
479
90.9k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
480
90.9k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
481
90.9k
  my_master_ptr master = (my_master_ptr)cinfo->master;
482
90.9k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
483
90.9k
  JDIMENSION i, x;
484
90.9k
  int y;
485
90.9k
  JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
486
90.9k
  JDIMENSION lines_to_skip, lines_to_read;
487
488
90.9k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
489
183
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
490
491
90.9k
  if (cinfo->master->lossless)
492
0
    ERREXIT(cinfo, JERR_NOTIMPL);
493
494
  /* Two-pass color quantization is not supported. */
495
90.9k
  if (cinfo->quantize_colors && cinfo->two_pass_quantize)
496
0
    ERREXIT(cinfo, JERR_NOTIMPL);
497
498
90.9k
  if (cinfo->global_state != DSTATE_SCANNING)
499
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
500
501
  /* Do not skip past the bottom of the image. */
502
90.9k
  if ((unsigned long long)cinfo->output_scanline + num_lines >=
503
90.9k
      cinfo->output_height) {
504
4.74k
    num_lines = cinfo->output_height - cinfo->output_scanline;
505
4.74k
    cinfo->output_scanline = cinfo->output_height;
506
4.74k
    (*cinfo->inputctl->finish_input_pass) (cinfo);
507
4.74k
    cinfo->inputctl->eoi_reached = TRUE;
508
4.74k
    return num_lines;
509
4.74k
  }
510
511
86.2k
  if (num_lines == 0)
512
0
    return 0;
513
514
86.2k
  lines_per_iMCU_row = cinfo->_min_DCT_scaled_size * cinfo->max_v_samp_factor;
515
86.2k
  lines_left_in_iMCU_row =
516
86.2k
    (lines_per_iMCU_row - (cinfo->output_scanline % lines_per_iMCU_row)) %
517
86.2k
    lines_per_iMCU_row;
518
86.2k
  lines_after_iMCU_row = num_lines - lines_left_in_iMCU_row;
519
520
  /* Skip the lines remaining in the current iMCU row.  When upsampling
521
   * requires context rows, we need the previous and next rows in order to read
522
   * the current row.  This adds some complexity.
523
   */
524
86.2k
  if (cinfo->upsample->need_context_rows) {
525
    /* If the skipped lines would not move us past the current iMCU row, we
526
     * read the lines and ignore them.  There might be a faster way of doing
527
     * this, but we are facing increasing complexity for diminishing returns.
528
     * The increasing complexity would be a by-product of meddling with the
529
     * state machine used to skip context rows.  Near the end of an iMCU row,
530
     * the next iMCU row may have already been entropy-decoded.  In this unique
531
     * case, we will read the next iMCU row if we cannot skip past it as well.
532
     */
533
38.8k
    if ((num_lines < lines_left_in_iMCU_row + 1) ||
534
34.0k
        (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full &&
535
16.8k
         lines_after_iMCU_row < lines_per_iMCU_row + 1)) {
536
16.8k
      read_and_discard_scanlines(cinfo, num_lines);
537
16.8k
      return num_lines;
538
16.8k
    }
539
540
    /* If the next iMCU row has already been entropy-decoded, make sure that
541
     * we do not skip too far.
542
     */
543
21.9k
    if (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full) {
544
0
      cinfo->output_scanline += lines_left_in_iMCU_row + lines_per_iMCU_row;
545
0
      lines_after_iMCU_row -= lines_per_iMCU_row;
546
21.9k
    } else {
547
21.9k
      cinfo->output_scanline += lines_left_in_iMCU_row;
548
21.9k
    }
549
550
    /* If we have just completed the first block, adjust the buffer pointers */
551
21.9k
    if (main_ptr->iMCU_row_ctr == 0 ||
552
0
        (main_ptr->iMCU_row_ctr == 1 && lines_left_in_iMCU_row > 2))
553
21.9k
      set_wraparound_pointers(cinfo);
554
21.9k
    main_ptr->buffer_full = FALSE;
555
21.9k
    main_ptr->rowgroup_ctr = 0;
556
21.9k
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
557
21.9k
    if (!master->using_merged_upsample) {
558
21.9k
      upsample->next_row_out = cinfo->max_v_samp_factor;
559
21.9k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
560
21.9k
    }
561
21.9k
  }
562
563
  /* Skipping is much simpler when context rows are not required. */
564
47.4k
  else {
565
47.4k
    if (num_lines < lines_left_in_iMCU_row) {
566
4.74k
      increment_simple_rowgroup_ctr(cinfo, num_lines);
567
4.74k
      return num_lines;
568
42.6k
    } else {
569
42.6k
      cinfo->output_scanline += lines_left_in_iMCU_row;
570
42.6k
      main_ptr->buffer_full = FALSE;
571
42.6k
      main_ptr->rowgroup_ctr = 0;
572
42.6k
      if (!master->using_merged_upsample) {
573
42.4k
        upsample->next_row_out = cinfo->max_v_samp_factor;
574
42.4k
        upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
575
42.4k
      }
576
42.6k
    }
577
47.4k
  }
578
579
  /* Calculate how many full iMCU rows we can skip. */
580
64.6k
  if (cinfo->upsample->need_context_rows)
581
21.9k
    lines_to_skip = ((lines_after_iMCU_row - 1) / lines_per_iMCU_row) *
582
21.9k
                    lines_per_iMCU_row;
583
42.6k
  else
584
42.6k
    lines_to_skip = (lines_after_iMCU_row / lines_per_iMCU_row) *
585
42.6k
                    lines_per_iMCU_row;
586
  /* Calculate the number of lines that remain to be skipped after skipping all
587
   * of the full iMCU rows that we can.  We will not read these lines unless we
588
   * have to.
589
   */
590
64.6k
  lines_to_read = lines_after_iMCU_row - lines_to_skip;
591
592
  /* For images requiring multiple scans (progressive, non-interleaved, etc.),
593
   * all of the entropy decoding occurs in jpeg_start_decompress(), assuming
594
   * that the input data source is non-suspending.  This makes skipping easy.
595
   */
596
64.6k
  if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) {
597
51.0k
    if (cinfo->upsample->need_context_rows) {
598
20.8k
      cinfo->output_scanline += lines_to_skip;
599
20.8k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
600
20.8k
      main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
601
      /* It is complex to properly move to the middle of a context block, so
602
       * read the remaining lines instead of skipping them.
603
       */
604
20.8k
      read_and_discard_scanlines(cinfo, lines_to_read);
605
30.1k
    } else {
606
30.1k
      cinfo->output_scanline += lines_to_skip;
607
30.1k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
608
30.1k
      increment_simple_rowgroup_ctr(cinfo, lines_to_read);
609
30.1k
    }
610
51.0k
    if (!master->using_merged_upsample)
611
51.0k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
612
51.0k
    return num_lines;
613
51.0k
  }
614
615
  /* Skip the iMCU rows that we can safely skip. */
616
23.3k
  for (i = 0; i < lines_to_skip; i += lines_per_iMCU_row) {
617
20.0k
    for (y = 0; y < coef->MCU_rows_per_iMCU_row; y++) {
618
4.34M
      for (x = 0; x < cinfo->MCUs_per_row; x++) {
619
        /* Calling decode_mcu() with a NULL pointer causes it to discard the
620
         * decoded coefficients.  This is ~5% faster for large subsets, but
621
         * it's tough to tell a difference for smaller images.
622
         */
623
4.33M
        if (!cinfo->entropy->insufficient_data)
624
1.93M
          cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
625
4.33M
        (*cinfo->entropy->decode_mcu) (cinfo, NULL);
626
4.33M
      }
627
10.2k
    }
628
9.73k
    cinfo->input_iMCU_row++;
629
9.73k
    cinfo->output_iMCU_row++;
630
9.73k
    if (cinfo->input_iMCU_row < cinfo->total_iMCU_rows)
631
9.73k
      start_iMCU_row(cinfo);
632
0
    else
633
0
      (*cinfo->inputctl->finish_input_pass) (cinfo);
634
9.73k
  }
635
13.5k
  cinfo->output_scanline += lines_to_skip;
636
637
13.5k
  if (cinfo->upsample->need_context_rows) {
638
    /* Context-based upsampling keeps track of iMCU rows. */
639
1.06k
    main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
640
641
    /* It is complex to properly move to the middle of a context block, so
642
     * read the remaining lines instead of skipping them.
643
     */
644
1.06k
    read_and_discard_scanlines(cinfo, lines_to_read);
645
12.5k
  } else {
646
12.5k
    increment_simple_rowgroup_ctr(cinfo, lines_to_read);
647
12.5k
  }
648
649
  /* Since skipping lines involves skipping the upsampling step, the value of
650
   * "rows_to_go" will become invalid unless we set it here.  NOTE: This is a
651
   * bit odd, since "rows_to_go" seems to be redundantly keeping track of
652
   * output_scanline.
653
   */
654
13.5k
  if (!master->using_merged_upsample)
655
13.3k
    upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
656
657
  /* Always skip the requested number of lines. */
658
13.5k
  return num_lines;
659
64.6k
}
660
661
/*
662
 * Alternate entry point to read raw data.
663
 * Processes exactly one iMCU row per call, unless suspended.
664
 */
665
666
GLOBAL(JDIMENSION)
667
_jpeg_read_raw_data(j_decompress_ptr cinfo, _JSAMPIMAGE data,
668
                    JDIMENSION max_lines)
669
7.06M
{
670
7.06M
  JDIMENSION lines_per_iMCU_row;
671
672
7.06M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
673
9.05k
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
674
675
7.06M
  if (cinfo->master->lossless)
676
1.87k
    ERREXIT(cinfo, JERR_NOTIMPL);
677
678
7.06M
  if (cinfo->global_state != DSTATE_RAW_OK)
679
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
680
7.06M
  if (cinfo->output_scanline >= cinfo->output_height) {
681
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
682
0
    return 0;
683
0
  }
684
685
  /* Call progress monitor hook if present */
686
7.06M
  if (cinfo->progress != NULL) {
687
7.05M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
688
7.05M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
689
7.05M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
690
7.05M
  }
691
692
  /* Verify that at least one iMCU row can be returned. */
693
7.06M
  lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size;
694
7.06M
  if (max_lines < lines_per_iMCU_row)
695
0
    ERREXIT(cinfo, JERR_BUFFER_SIZE);
696
697
  /* Decompress directly into user's buffer. */
698
7.06M
  if (cinfo->coef->_decompress_data == NULL)
699
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
700
7.06M
  if (!(*cinfo->coef->_decompress_data) (cinfo, data))
701
0
    return 0;                   /* suspension forced, can do nothing more */
702
703
  /* OK, we processed one iMCU row. */
704
7.06M
  cinfo->output_scanline += lines_per_iMCU_row;
705
7.06M
  return lines_per_iMCU_row;
706
7.06M
}
Unexecuted instantiation: jpeg12_read_raw_data
jpeg_read_raw_data
Line
Count
Source
669
7.06M
{
670
7.06M
  JDIMENSION lines_per_iMCU_row;
671
672
7.06M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
673
9.05k
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
674
675
7.06M
  if (cinfo->master->lossless)
676
1.87k
    ERREXIT(cinfo, JERR_NOTIMPL);
677
678
7.06M
  if (cinfo->global_state != DSTATE_RAW_OK)
679
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
680
7.06M
  if (cinfo->output_scanline >= cinfo->output_height) {
681
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
682
0
    return 0;
683
0
  }
684
685
  /* Call progress monitor hook if present */
686
7.06M
  if (cinfo->progress != NULL) {
687
7.05M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
688
7.05M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
689
7.05M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
690
7.05M
  }
691
692
  /* Verify that at least one iMCU row can be returned. */
693
7.06M
  lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size;
694
7.06M
  if (max_lines < lines_per_iMCU_row)
695
0
    ERREXIT(cinfo, JERR_BUFFER_SIZE);
696
697
  /* Decompress directly into user's buffer. */
698
7.06M
  if (cinfo->coef->_decompress_data == NULL)
699
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
700
7.06M
  if (!(*cinfo->coef->_decompress_data) (cinfo, data))
701
0
    return 0;                   /* suspension forced, can do nothing more */
702
703
  /* OK, we processed one iMCU row. */
704
7.06M
  cinfo->output_scanline += lines_per_iMCU_row;
705
7.06M
  return lines_per_iMCU_row;
706
7.06M
}
707
708
#endif /* BITS_IN_JSAMPLE != 16 */
709
710
711
#if BITS_IN_JSAMPLE == 8
712
713
/* Additional entry points for buffered-image mode. */
714
715
#ifdef D_MULTISCAN_FILES_SUPPORTED
716
717
/*
718
 * Initialize for an output pass in buffered-image mode.
719
 */
720
721
GLOBAL(boolean)
722
jpeg_start_output(j_decompress_ptr cinfo, int scan_number)
723
51.5k
{
724
51.5k
  if (cinfo->global_state != DSTATE_BUFIMAGE &&
725
0
      cinfo->global_state != DSTATE_PRESCAN)
726
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
727
  /* Limit scan number to valid range */
728
51.5k
  if (scan_number <= 0)
729
0
    scan_number = 1;
730
51.5k
  if (cinfo->inputctl->eoi_reached && scan_number > cinfo->input_scan_number)
731
0
    scan_number = cinfo->input_scan_number;
732
51.5k
  cinfo->output_scan_number = scan_number;
733
  /* Perform any dummy output passes, and set up for the real pass */
734
51.5k
  return output_pass_setup(cinfo);
735
51.5k
}
736
737
738
/*
739
 * Finish up after an output pass in buffered-image mode.
740
 *
741
 * Returns FALSE if suspended.  The return value need be inspected only if
742
 * a suspending data source is used.
743
 */
744
745
GLOBAL(boolean)
746
jpeg_finish_output(j_decompress_ptr cinfo)
747
51.0k
{
748
51.0k
  if ((cinfo->global_state == DSTATE_SCANNING ||
749
51.0k
       cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
750
    /* Terminate this pass. */
751
    /* We do not require the whole pass to have been completed. */
752
51.0k
    (*cinfo->master->finish_output_pass) (cinfo);
753
51.0k
    cinfo->global_state = DSTATE_BUFPOST;
754
51.0k
  } else if (cinfo->global_state != DSTATE_BUFPOST) {
755
    /* BUFPOST = repeat call after a suspension, anything else is error */
756
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
757
0
  }
758
  /* Read markers looking for SOS or EOI */
759
88.0k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
760
46.4k
         !cinfo->inputctl->eoi_reached) {
761
37.2k
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
762
356
      return FALSE;             /* Suspend, come back later */
763
37.2k
  }
764
50.7k
  cinfo->global_state = DSTATE_BUFIMAGE;
765
50.7k
  return TRUE;
766
51.0k
}
767
768
#endif /* D_MULTISCAN_FILES_SUPPORTED */
769
770
#endif /* BITS_IN_JSAMPLE == 8 */