Coverage Report

Created: 2026-05-30 07:16

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
172k
{
54
172k
  if (cinfo->global_state == DSTATE_READY) {
55
    /* First call: initialize master control, select active modules */
56
172k
    jinit_master_decompress(cinfo);
57
172k
    if (cinfo->buffered_image) {
58
      /* No more work here; expecting jpeg_start_output next */
59
24.8k
      cinfo->global_state = DSTATE_BUFIMAGE;
60
24.8k
      return TRUE;
61
24.8k
    }
62
147k
    cinfo->global_state = DSTATE_PRELOAD;
63
147k
  }
64
147k
  if (cinfo->global_state == DSTATE_PRELOAD) {
65
    /* If file has multiple scans, absorb them all into the coef buffer */
66
91.7k
    if (cinfo->inputctl->has_multiple_scans) {
67
64.3k
#ifdef D_MULTISCAN_FILES_SUPPORTED
68
325M
      for (;;) {
69
325M
        int retcode;
70
        /* Call progress monitor hook if present */
71
325M
        if (cinfo->progress != NULL)
72
325M
          (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
73
        /* Absorb some more input */
74
325M
        retcode = (*cinfo->inputctl->consume_input) (cinfo);
75
325M
        if (retcode == JPEG_SUSPENDED)
76
0
          return FALSE;
77
325M
        if (retcode == JPEG_REACHED_EOI)
78
51.3k
          break;
79
        /* Advance progress counter if appropriate */
80
325M
        if (cinfo->progress != NULL &&
81
325M
            (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
82
325M
          if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
83
            /* jdmaster underestimated number of scans; ratchet up one scan */
84
213k
            cinfo->progress->pass_limit += (long)cinfo->total_iMCU_rows;
85
213k
          }
86
325M
        }
87
325M
      }
88
#else
89
      ERREXIT(cinfo, JERR_NOT_COMPILED);
90
#endif /* D_MULTISCAN_FILES_SUPPORTED */
91
64.3k
    }
92
91.7k
    cinfo->output_scan_number = cinfo->input_scan_number;
93
91.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
147k
  return output_pass_setup(cinfo);
97
147k
}
98
99
100
/*
101
 * Set up for an output pass, and perform any dummy pass(es) needed.
102
 * Common subroutine for jpeg_start_decompress and jpeg_start_output.
103
 * Entry: global_state = DSTATE_PRESCAN only if previously suspended.
104
 * Exit: If done, returns TRUE and sets global_state for proper output mode.
105
 *       If suspended, returns FALSE and sets global_state = DSTATE_PRESCAN.
106
 */
107
108
LOCAL(boolean)
109
output_pass_setup(j_decompress_ptr cinfo)
110
21.2k
{
111
21.2k
  if (cinfo->global_state != DSTATE_PRESCAN) {
112
    /* First call: do pass setup */
113
21.2k
    (*cinfo->master->prepare_for_output_pass) (cinfo);
114
21.2k
    cinfo->output_scanline = 0;
115
21.2k
    cinfo->global_state = DSTATE_PRESCAN;
116
21.2k
  }
117
  /* Loop over any required dummy passes */
118
21.2k
  while (cinfo->master->is_dummy_pass) {
119
0
#ifdef QUANT_2PASS_SUPPORTED
120
    /* Crank through the dummy pass */
121
0
    while (cinfo->output_scanline < cinfo->output_height) {
122
0
      JDIMENSION last_scanline;
123
      /* Call progress monitor hook if present */
124
0
      if (cinfo->progress != NULL) {
125
0
        cinfo->progress->pass_counter = (long)cinfo->output_scanline;
126
0
        cinfo->progress->pass_limit = (long)cinfo->output_height;
127
0
        (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
128
0
      }
129
      /* Process some data */
130
0
      last_scanline = cinfo->output_scanline;
131
0
      if (cinfo->data_precision == 16) {
132
0
#ifdef D_LOSSLESS_SUPPORTED
133
0
        if (cinfo->main->process_data_16 == NULL)
134
0
          ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
135
0
        (*cinfo->main->process_data_16) (cinfo, (J16SAMPARRAY)NULL,
136
0
                                         &cinfo->output_scanline,
137
0
                                         (JDIMENSION)0);
138
#else
139
        ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
140
#endif
141
0
      } else if (cinfo->data_precision == 12) {
142
0
        if (cinfo->main->process_data_12 == NULL)
143
0
          ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
144
0
        (*cinfo->main->process_data_12) (cinfo, (J12SAMPARRAY)NULL,
145
0
                                         &cinfo->output_scanline,
146
0
                                         (JDIMENSION)0);
147
0
      } else {
148
0
        if (cinfo->main->process_data == NULL)
149
0
          ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
150
0
        (*cinfo->main->process_data) (cinfo, (JSAMPARRAY)NULL,
151
0
                                      &cinfo->output_scanline, (JDIMENSION)0);
152
0
      }
153
0
      if (cinfo->output_scanline == last_scanline)
154
0
        return FALSE;           /* No progress made, must suspend */
155
0
    }
156
    /* Finish up dummy pass, and set up for another one */
157
0
    (*cinfo->master->finish_output_pass) (cinfo);
158
0
    (*cinfo->master->prepare_for_output_pass) (cinfo);
159
0
    cinfo->output_scanline = 0;
160
#else
161
    ERREXIT(cinfo, JERR_NOT_COMPILED);
162
#endif /* QUANT_2PASS_SUPPORTED */
163
0
  }
164
  /* Ready for application to drive output pass through
165
   * _jpeg_read_scanlines or _jpeg_read_raw_data.
166
   */
167
21.2k
  cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
168
21.2k
  return TRUE;
169
21.2k
}
170
171
#endif /* BITS_IN_JSAMPLE == 8 */
172
173
174
#if BITS_IN_JSAMPLE != 16
175
176
/*
177
 * Enable partial scanline decompression
178
 *
179
 * Must be called after jpeg_start_decompress() and before any calls to
180
 * _jpeg_read_scanlines() or _jpeg_skip_scanlines().
181
 *
182
 * Refer to libjpeg.txt for more information.
183
 */
184
185
GLOBAL(void)
186
_jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
187
                    JDIMENSION *width)
188
4.20k
{
189
4.20k
  int ci, align, orig_downsampled_width;
190
4.20k
  JDIMENSION input_xoffset;
191
4.20k
  boolean reinit_upsampler = FALSE;
192
4.20k
  jpeg_component_info *compptr;
193
4.20k
#ifdef UPSAMPLE_MERGING_SUPPORTED
194
4.20k
  my_master_ptr master = (my_master_ptr)cinfo->master;
195
4.20k
#endif
196
197
4.20k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
198
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
199
200
4.20k
  if (cinfo->master->lossless || cinfo->raw_data_out)
201
0
    ERREXIT(cinfo, JERR_NOTIMPL);
202
203
4.20k
  if ((cinfo->global_state != DSTATE_SCANNING &&
204
4.20k
       cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0)
205
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
206
207
4.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
4.20k
  if (*width == 0 ||
212
4.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
4.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
4.20k
  if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1)
238
3.64k
    align = cinfo->_min_DCT_scaled_size;
239
567
  else
240
567
    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.20k
  input_xoffset = *xoffset;
244
4.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
4.20k
  *width = *width + input_xoffset - *xoffset;
252
4.20k
  cinfo->output_width = *width;
253
4.20k
#ifdef UPSAMPLE_MERGING_SUPPORTED
254
4.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
4.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
4.20k
  cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align;
265
4.20k
  cinfo->master->last_iMCU_col =
266
4.20k
    (JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width),
267
4.20k
                              (long)align) - 1;
268
269
9.58k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
270
5.37k
       ci++, compptr++) {
271
5.37k
    int hsf = (cinfo->comps_in_scan == 1 && cinfo->num_components == 1) ?
272
3.64k
              1 : compptr->h_samp_factor;
273
274
    /* Set downsampled_width to the new output width. */
275
5.37k
    orig_downsampled_width = compptr->downsampled_width;
276
5.37k
    compptr->downsampled_width =
277
5.37k
      (JDIMENSION)jdiv_round_up((long)cinfo->output_width *
278
5.37k
                                (long)(compptr->h_samp_factor *
279
5.37k
                                       compptr->_DCT_scaled_size),
280
5.37k
                                (long)(cinfo->max_h_samp_factor *
281
5.37k
                                       cinfo->_min_DCT_scaled_size));
282
5.37k
    if (compptr->downsampled_width < 2 && orig_downsampled_width >= 2)
283
0
      reinit_upsampler = TRUE;
284
285
    /* Set the first and last iMCU columns that we must decompress.  These
286
     * values will be used in multi-scan decompressions.
287
     */
288
5.37k
    cinfo->master->first_MCU_col[ci] =
289
5.37k
      (JDIMENSION)(long)(*xoffset * hsf) / (long)align;
290
5.37k
    cinfo->master->last_MCU_col[ci] =
291
5.37k
      (JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf),
292
5.37k
                                (long)align) - 1;
293
5.37k
  }
294
295
4.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
4.20k
}
jpeg12_crop_scanline
Line
Count
Source
188
2.13k
{
189
2.13k
  int ci, align, orig_downsampled_width;
190
2.13k
  JDIMENSION input_xoffset;
191
2.13k
  boolean reinit_upsampler = FALSE;
192
2.13k
  jpeg_component_info *compptr;
193
2.13k
#ifdef UPSAMPLE_MERGING_SUPPORTED
194
2.13k
  my_master_ptr master = (my_master_ptr)cinfo->master;
195
2.13k
#endif
196
197
2.13k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
198
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
199
200
2.13k
  if (cinfo->master->lossless || cinfo->raw_data_out)
201
0
    ERREXIT(cinfo, JERR_NOTIMPL);
202
203
2.13k
  if ((cinfo->global_state != DSTATE_SCANNING &&
204
2.13k
       cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0)
205
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
206
207
2.13k
  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.13k
  if (*width == 0 ||
212
2.13k
      (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.13k
  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.13k
  if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1)
238
1.78k
    align = cinfo->_min_DCT_scaled_size;
239
349
  else
240
349
    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.13k
  input_xoffset = *xoffset;
244
2.13k
  *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.13k
  *width = *width + input_xoffset - *xoffset;
252
2.13k
  cinfo->output_width = *width;
253
2.13k
#ifdef UPSAMPLE_MERGING_SUPPORTED
254
2.13k
  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.13k
#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.13k
  cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align;
265
2.13k
  cinfo->master->last_iMCU_col =
266
2.13k
    (JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width),
267
2.13k
                              (long)align) - 1;
268
269
4.97k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
270
2.84k
       ci++, compptr++) {
271
2.84k
    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.84k
    orig_downsampled_width = compptr->downsampled_width;
276
2.84k
    compptr->downsampled_width =
277
2.84k
      (JDIMENSION)jdiv_round_up((long)cinfo->output_width *
278
2.84k
                                (long)(compptr->h_samp_factor *
279
2.84k
                                       compptr->_DCT_scaled_size),
280
2.84k
                                (long)(cinfo->max_h_samp_factor *
281
2.84k
                                       cinfo->_min_DCT_scaled_size));
282
2.84k
    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.84k
    cinfo->master->first_MCU_col[ci] =
289
2.84k
      (JDIMENSION)(long)(*xoffset * hsf) / (long)align;
290
2.84k
    cinfo->master->last_MCU_col[ci] =
291
2.84k
      (JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf),
292
2.84k
                                (long)align) - 1;
293
2.84k
  }
294
295
2.13k
  if (reinit_upsampler) {
296
0
    cinfo->master->jinit_upsampler_no_alloc = TRUE;
297
0
    _jinit_upsampler(cinfo);
298
0
    cinfo->master->jinit_upsampler_no_alloc = FALSE;
299
0
  }
300
2.13k
}
jpeg_crop_scanline
Line
Count
Source
188
2.07k
{
189
2.07k
  int ci, align, orig_downsampled_width;
190
2.07k
  JDIMENSION input_xoffset;
191
2.07k
  boolean reinit_upsampler = FALSE;
192
2.07k
  jpeg_component_info *compptr;
193
2.07k
#ifdef UPSAMPLE_MERGING_SUPPORTED
194
2.07k
  my_master_ptr master = (my_master_ptr)cinfo->master;
195
2.07k
#endif
196
197
2.07k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
198
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
199
200
2.07k
  if (cinfo->master->lossless || cinfo->raw_data_out)
201
0
    ERREXIT(cinfo, JERR_NOTIMPL);
202
203
2.07k
  if ((cinfo->global_state != DSTATE_SCANNING &&
204
2.07k
       cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0)
205
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
206
207
2.07k
  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.07k
  if (*width == 0 ||
212
2.07k
      (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.07k
  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.07k
  if (cinfo->comps_in_scan == 1 && cinfo->num_components == 1)
238
1.85k
    align = cinfo->_min_DCT_scaled_size;
239
218
  else
240
218
    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.07k
  input_xoffset = *xoffset;
244
2.07k
  *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.07k
  *width = *width + input_xoffset - *xoffset;
252
2.07k
  cinfo->output_width = *width;
253
2.07k
#ifdef UPSAMPLE_MERGING_SUPPORTED
254
2.07k
  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.07k
#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.07k
  cinfo->master->first_iMCU_col = (JDIMENSION)(long)(*xoffset) / (long)align;
265
2.07k
  cinfo->master->last_iMCU_col =
266
2.07k
    (JDIMENSION)jdiv_round_up((long)(*xoffset + cinfo->output_width),
267
2.07k
                              (long)align) - 1;
268
269
4.60k
  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.85k
              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
      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.52k
    cinfo->master->first_MCU_col[ci] =
289
2.52k
      (JDIMENSION)(long)(*xoffset * hsf) / (long)align;
290
2.52k
    cinfo->master->last_MCU_col[ci] =
291
2.52k
      (JDIMENSION)jdiv_round_up((long)((*xoffset + cinfo->output_width) * hsf),
292
2.52k
                                (long)align) - 1;
293
2.52k
  }
294
295
2.07k
  if (reinit_upsampler) {
296
0
    cinfo->master->jinit_upsampler_no_alloc = TRUE;
297
0
    _jinit_upsampler(cinfo);
298
0
    cinfo->master->jinit_upsampler_no_alloc = FALSE;
299
0
  }
300
2.07k
}
301
302
#endif /* BITS_IN_JSAMPLE != 16 */
303
304
305
/*
306
 * Read some scanlines of data from the JPEG decompressor.
307
 *
308
 * The return value will be the number of lines actually read.
309
 * This may be less than the number requested in several cases,
310
 * including bottom of image, data source suspension, and operating
311
 * modes that emit multiple scanlines at a time.
312
 *
313
 * Note: we warn about excess calls to _jpeg_read_scanlines() since
314
 * this likely signals an application programmer error.  However,
315
 * an oversize buffer (max_lines > scanlines remaining) is not an error.
316
 */
317
318
GLOBAL(JDIMENSION)
319
_jpeg_read_scanlines(j_decompress_ptr cinfo, _JSAMPARRAY scanlines,
320
                     JDIMENSION max_lines)
321
22.7M
{
322
22.7M
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
323
22.7M
  JDIMENSION row_ctr;
324
325
22.7M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
326
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
327
328
22.7M
  if (cinfo->global_state != DSTATE_SCANNING)
329
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
330
22.7M
  if (cinfo->output_scanline >= cinfo->output_height) {
331
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
332
0
    return 0;
333
0
  }
334
335
  /* Call progress monitor hook if present */
336
22.7M
  if (cinfo->progress != NULL) {
337
22.7M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
338
22.7M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
339
22.7M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
340
22.7M
  }
341
342
  /* Process some data */
343
22.7M
  row_ctr = 0;
344
22.7M
  if (cinfo->main->_process_data == NULL)
345
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
346
22.7M
  (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
347
22.7M
  cinfo->output_scanline += row_ctr;
348
22.7M
  return row_ctr;
349
#else
350
  ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
351
  return 0;
352
#endif
353
22.7M
}
jpeg12_read_scanlines
Line
Count
Source
321
8.73M
{
322
8.73M
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
323
8.73M
  JDIMENSION row_ctr;
324
325
8.73M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
326
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
327
328
8.73M
  if (cinfo->global_state != DSTATE_SCANNING)
329
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
330
8.73M
  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.73M
  if (cinfo->progress != NULL) {
337
8.73M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
338
8.73M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
339
8.73M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
340
8.73M
  }
341
342
  /* Process some data */
343
8.73M
  row_ctr = 0;
344
8.73M
  if (cinfo->main->_process_data == NULL)
345
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
346
8.73M
  (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
347
8.73M
  cinfo->output_scanline += row_ctr;
348
8.73M
  return row_ctr;
349
#else
350
  ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
351
  return 0;
352
#endif
353
8.73M
}
jpeg16_read_scanlines
Line
Count
Source
321
1.23M
{
322
1.23M
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
323
1.23M
  JDIMENSION row_ctr;
324
325
1.23M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
326
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
327
328
1.23M
  if (cinfo->global_state != DSTATE_SCANNING)
329
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
330
1.23M
  if (cinfo->output_scanline >= cinfo->output_height) {
331
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
332
0
    return 0;
333
0
  }
334
335
  /* Call progress monitor hook if present */
336
1.23M
  if (cinfo->progress != NULL) {
337
1.23M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
338
1.23M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
339
1.23M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
340
1.23M
  }
341
342
  /* Process some data */
343
1.23M
  row_ctr = 0;
344
1.23M
  if (cinfo->main->_process_data == NULL)
345
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
346
1.23M
  (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
347
1.23M
  cinfo->output_scanline += row_ctr;
348
1.23M
  return row_ctr;
349
#else
350
  ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
351
  return 0;
352
#endif
353
1.23M
}
jpeg_read_scanlines
Line
Count
Source
321
12.7M
{
322
12.7M
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
323
12.7M
  JDIMENSION row_ctr;
324
325
12.7M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
326
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
327
328
12.7M
  if (cinfo->global_state != DSTATE_SCANNING)
329
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
330
12.7M
  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.7M
  if (cinfo->progress != NULL) {
337
12.7M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
338
12.7M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
339
12.7M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
340
12.7M
  }
341
342
  /* Process some data */
343
12.7M
  row_ctr = 0;
344
12.7M
  if (cinfo->main->_process_data == NULL)
345
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
346
12.7M
  (*cinfo->main->_process_data) (cinfo, scanlines, &row_ctr, max_lines);
347
12.7M
  cinfo->output_scanline += row_ctr;
348
12.7M
  return row_ctr;
349
#else
350
  ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
351
  return 0;
352
#endif
353
12.7M
}
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
31
{
385
31
  JDIMENSION n;
386
31
#ifdef UPSAMPLE_MERGING_SUPPORTED
387
31
  my_master_ptr master = (my_master_ptr)cinfo->master;
388
31
#endif
389
31
  _JSAMPLE dummy_sample[1] = { 0 };
390
31
  _JSAMPROW dummy_row = dummy_sample;
391
31
  _JSAMPARRAY scanlines = NULL;
392
31
  void (*color_convert) (j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
393
31
                         JDIMENSION input_row, _JSAMPARRAY output_buf,
394
31
                         int num_rows) = NULL;
395
31
  void (*color_quantize) (j_decompress_ptr cinfo, _JSAMPARRAY input_buf,
396
31
                          _JSAMPARRAY output_buf, int num_rows) = NULL;
397
398
31
  if (cinfo->cconvert &&
399
31
#ifdef UPSAMPLE_MERGING_SUPPORTED
400
31
      !master->using_merged_upsample &&
401
31
#endif
402
31
      cinfo->cconvert->_color_convert) {
403
31
    color_convert = cinfo->cconvert->_color_convert;
404
31
    cinfo->cconvert->_color_convert = noop_convert;
405
    /* This just prevents UBSan from complaining about adding 0 to a NULL
406
     * pointer.  The pointer isn't actually used.
407
     */
408
31
    scanlines = &dummy_row;
409
31
  }
410
411
31
  if (cinfo->quantize_colors && cinfo->cquantize &&
412
0
      cinfo->cquantize->_color_quantize) {
413
0
    color_quantize = cinfo->cquantize->_color_quantize;
414
0
    cinfo->cquantize->_color_quantize = noop_quantize;
415
0
  }
416
417
31
#ifdef UPSAMPLE_MERGING_SUPPORTED
418
31
  if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) {
419
0
    my_merged_upsample_ptr upsample = (my_merged_upsample_ptr)cinfo->upsample;
420
0
    scanlines = &upsample->spare_row;
421
0
  }
422
31
#endif
423
424
31
  for (n = 0; n < num_lines; n++)
425
0
    _jpeg_read_scanlines(cinfo, scanlines, 1);
426
427
31
  if (color_convert)
428
31
    cinfo->cconvert->_color_convert = color_convert;
429
430
31
  if (color_quantize)
431
0
    cinfo->cquantize->_color_quantize = color_quantize;
432
31
}
433
434
435
/*
436
 * Called by _jpeg_skip_scanlines().  This partially skips a decompress block
437
 * by incrementing the rowgroup counter.
438
 */
439
440
LOCAL(void)
441
increment_simple_rowgroup_ctr(j_decompress_ptr cinfo, JDIMENSION rows)
442
31
{
443
31
  JDIMENSION rows_left;
444
31
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
445
31
  my_master_ptr master = (my_master_ptr)cinfo->master;
446
447
31
  if (master->using_merged_upsample && cinfo->max_v_samp_factor == 2) {
448
0
    read_and_discard_scanlines(cinfo, rows);
449
0
    return;
450
0
  }
451
452
  /* Increment the counter to the next row group after the skipped rows. */
453
31
  main_ptr->rowgroup_ctr += rows / cinfo->max_v_samp_factor;
454
455
  /* Partially skipping a row group would involve modifying the internal state
456
   * of the upsampler, so read the remaining rows into a dummy buffer instead.
457
   */
458
31
  rows_left = rows % cinfo->max_v_samp_factor;
459
31
  cinfo->output_scanline += rows - rows_left;
460
461
31
  read_and_discard_scanlines(cinfo, rows_left);
462
31
}
463
464
/*
465
 * Skips some scanlines of data from the JPEG decompressor.
466
 *
467
 * The return value will be the number of lines actually skipped.  If skipping
468
 * num_lines would move beyond the end of the image, then the actual number of
469
 * lines remaining in the image is returned.  Otherwise, the return value will
470
 * be equal to num_lines.
471
 *
472
 * Refer to libjpeg.txt for more information.
473
 */
474
475
GLOBAL(JDIMENSION)
476
_jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
477
101k
{
478
101k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
479
101k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
480
101k
  my_master_ptr master = (my_master_ptr)cinfo->master;
481
101k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
482
101k
  JDIMENSION i, x;
483
101k
  int y;
484
101k
  JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
485
101k
  JDIMENSION lines_to_skip, lines_to_read;
486
487
101k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
488
148
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
489
490
101k
  if (cinfo->master->lossless)
491
0
    ERREXIT(cinfo, JERR_NOTIMPL);
492
493
  /* Two-pass color quantization is not supported. */
494
101k
  if (cinfo->quantize_colors && cinfo->two_pass_quantize)
495
0
    ERREXIT(cinfo, JERR_NOTIMPL);
496
497
101k
  if (cinfo->global_state != DSTATE_SCANNING)
498
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
499
500
  /* Do not skip past the bottom of the image. */
501
101k
  if ((unsigned long long)cinfo->output_scanline + num_lines >=
502
101k
      cinfo->output_height) {
503
6.64k
    num_lines = cinfo->output_height - cinfo->output_scanline;
504
6.64k
    cinfo->output_scanline = cinfo->output_height;
505
6.64k
    (*cinfo->inputctl->finish_input_pass) (cinfo);
506
6.64k
    cinfo->inputctl->eoi_reached = TRUE;
507
6.64k
    return num_lines;
508
6.64k
  }
509
510
95.1k
  if (num_lines == 0)
511
0
    return 0;
512
513
95.1k
  lines_per_iMCU_row = cinfo->_min_DCT_scaled_size * cinfo->max_v_samp_factor;
514
95.1k
  lines_left_in_iMCU_row =
515
95.1k
    (lines_per_iMCU_row - (cinfo->output_scanline % lines_per_iMCU_row)) %
516
95.1k
    lines_per_iMCU_row;
517
95.1k
  lines_after_iMCU_row = num_lines - lines_left_in_iMCU_row;
518
519
  /* Skip the lines remaining in the current iMCU row.  When upsampling
520
   * requires context rows, we need the previous and next rows in order to read
521
   * the current row.  This adds some complexity.
522
   */
523
95.1k
  if (cinfo->upsample->need_context_rows) {
524
    /* If the skipped lines would not move us past the current iMCU row, we
525
     * read the lines and ignore them.  There might be a faster way of doing
526
     * this, but we are facing increasing complexity for diminishing returns.
527
     * The increasing complexity would be a by-product of meddling with the
528
     * state machine used to skip context rows.  Near the end of an iMCU row,
529
     * the next iMCU row may have already been entropy-decoded.  In this unique
530
     * case, we will read the next iMCU row if we cannot skip past it as well.
531
     */
532
36.4k
    if ((num_lines < lines_left_in_iMCU_row + 1) ||
533
31.9k
        (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full &&
534
16.1k
         lines_after_iMCU_row < lines_per_iMCU_row + 1)) {
535
16.1k
      read_and_discard_scanlines(cinfo, num_lines);
536
16.1k
      return num_lines;
537
16.1k
    }
538
539
    /* If the next iMCU row has already been entropy-decoded, make sure that
540
     * we do not skip too far.
541
     */
542
20.2k
    if (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full) {
543
0
      cinfo->output_scanline += lines_left_in_iMCU_row + lines_per_iMCU_row;
544
0
      lines_after_iMCU_row -= lines_per_iMCU_row;
545
20.2k
    } else {
546
20.2k
      cinfo->output_scanline += lines_left_in_iMCU_row;
547
20.2k
    }
548
549
    /* If we have just completed the first block, adjust the buffer pointers */
550
20.2k
    if (main_ptr->iMCU_row_ctr == 0 ||
551
0
        (main_ptr->iMCU_row_ctr == 1 && lines_left_in_iMCU_row > 2))
552
20.2k
      set_wraparound_pointers(cinfo);
553
20.2k
    main_ptr->buffer_full = FALSE;
554
20.2k
    main_ptr->rowgroup_ctr = 0;
555
20.2k
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
556
20.2k
    if (!master->using_merged_upsample) {
557
20.2k
      upsample->next_row_out = cinfo->max_v_samp_factor;
558
20.2k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
559
20.2k
    }
560
20.2k
  }
561
562
  /* Skipping is much simpler when context rows are not required. */
563
58.7k
  else {
564
58.7k
    if (num_lines < lines_left_in_iMCU_row) {
565
9.06k
      increment_simple_rowgroup_ctr(cinfo, num_lines);
566
9.06k
      return num_lines;
567
49.6k
    } else {
568
49.6k
      cinfo->output_scanline += lines_left_in_iMCU_row;
569
49.6k
      main_ptr->buffer_full = FALSE;
570
49.6k
      main_ptr->rowgroup_ctr = 0;
571
49.6k
      if (!master->using_merged_upsample) {
572
49.5k
        upsample->next_row_out = cinfo->max_v_samp_factor;
573
49.5k
        upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
574
49.5k
      }
575
49.6k
    }
576
58.7k
  }
577
578
  /* Calculate how many full iMCU rows we can skip. */
579
69.9k
  if (cinfo->upsample->need_context_rows)
580
20.2k
    lines_to_skip = ((lines_after_iMCU_row - 1) / lines_per_iMCU_row) *
581
20.2k
                    lines_per_iMCU_row;
582
49.6k
  else
583
49.6k
    lines_to_skip = (lines_after_iMCU_row / lines_per_iMCU_row) *
584
49.6k
                    lines_per_iMCU_row;
585
  /* Calculate the number of lines that remain to be skipped after skipping all
586
   * of the full iMCU rows that we can.  We will not read these lines unless we
587
   * have to.
588
   */
589
69.9k
  lines_to_read = lines_after_iMCU_row - lines_to_skip;
590
591
  /* For images requiring multiple scans (progressive, non-interleaved, etc.),
592
   * all of the entropy decoding occurs in jpeg_start_decompress(), assuming
593
   * that the input data source is non-suspending.  This makes skipping easy.
594
   */
595
69.9k
  if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) {
596
55.8k
    if (cinfo->upsample->need_context_rows) {
597
19.4k
      cinfo->output_scanline += lines_to_skip;
598
19.4k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
599
19.4k
      main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
600
      /* It is complex to properly move to the middle of a context block, so
601
       * read the remaining lines instead of skipping them.
602
       */
603
19.4k
      read_and_discard_scanlines(cinfo, lines_to_read);
604
36.3k
    } else {
605
36.3k
      cinfo->output_scanline += lines_to_skip;
606
36.3k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
607
36.3k
      increment_simple_rowgroup_ctr(cinfo, lines_to_read);
608
36.3k
    }
609
55.8k
    if (!master->using_merged_upsample)
610
55.8k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
611
55.8k
    return num_lines;
612
55.8k
  }
613
614
  /* Skip the iMCU rows that we can safely skip. */
615
25.7k
  for (i = 0; i < lines_to_skip; i += lines_per_iMCU_row) {
616
24.3k
    for (y = 0; y < coef->MCU_rows_per_iMCU_row; y++) {
617
3.67M
      for (x = 0; x < cinfo->MCUs_per_row; x++) {
618
        /* Calling decode_mcu() with a NULL pointer causes it to discard the
619
         * decoded coefficients.  This is ~5% faster for large subsets, but
620
         * it's tough to tell a difference for smaller images.
621
         */
622
3.65M
        if (!cinfo->entropy->insufficient_data)
623
1.14M
          cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
624
3.65M
        (*cinfo->entropy->decode_mcu) (cinfo, NULL);
625
3.65M
      }
626
12.7k
    }
627
11.6k
    cinfo->input_iMCU_row++;
628
11.6k
    cinfo->output_iMCU_row++;
629
11.6k
    if (cinfo->input_iMCU_row < cinfo->total_iMCU_rows)
630
11.6k
      start_iMCU_row(cinfo);
631
0
    else
632
0
      (*cinfo->inputctl->finish_input_pass) (cinfo);
633
11.6k
  }
634
14.0k
  cinfo->output_scanline += lines_to_skip;
635
636
14.0k
  if (cinfo->upsample->need_context_rows) {
637
    /* Context-based upsampling keeps track of iMCU rows. */
638
814
    main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
639
640
    /* It is complex to properly move to the middle of a context block, so
641
     * read the remaining lines instead of skipping them.
642
     */
643
814
    read_and_discard_scanlines(cinfo, lines_to_read);
644
13.2k
  } else {
645
13.2k
    increment_simple_rowgroup_ctr(cinfo, lines_to_read);
646
13.2k
  }
647
648
  /* Since skipping lines involves skipping the upsampling step, the value of
649
   * "rows_to_go" will become invalid unless we set it here.  NOTE: This is a
650
   * bit odd, since "rows_to_go" seems to be redundantly keeping track of
651
   * output_scanline.
652
   */
653
14.0k
  if (!master->using_merged_upsample)
654
13.9k
    upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
655
656
  /* Always skip the requested number of lines. */
657
14.0k
  return num_lines;
658
69.9k
}
jpeg12_skip_scanlines
Line
Count
Source
477
4.23k
{
478
4.23k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
479
4.23k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
480
4.23k
  my_master_ptr master = (my_master_ptr)cinfo->master;
481
4.23k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
482
4.23k
  JDIMENSION i, x;
483
4.23k
  int y;
484
4.23k
  JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
485
4.23k
  JDIMENSION lines_to_skip, lines_to_read;
486
487
4.23k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
488
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
489
490
4.23k
  if (cinfo->master->lossless)
491
0
    ERREXIT(cinfo, JERR_NOTIMPL);
492
493
  /* Two-pass color quantization is not supported. */
494
4.23k
  if (cinfo->quantize_colors && cinfo->two_pass_quantize)
495
0
    ERREXIT(cinfo, JERR_NOTIMPL);
496
497
4.23k
  if (cinfo->global_state != DSTATE_SCANNING)
498
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
499
500
  /* Do not skip past the bottom of the image. */
501
4.23k
  if ((unsigned long long)cinfo->output_scanline + num_lines >=
502
4.23k
      cinfo->output_height) {
503
2.10k
    num_lines = cinfo->output_height - cinfo->output_scanline;
504
2.10k
    cinfo->output_scanline = cinfo->output_height;
505
2.10k
    (*cinfo->inputctl->finish_input_pass) (cinfo);
506
2.10k
    cinfo->inputctl->eoi_reached = TRUE;
507
2.10k
    return num_lines;
508
2.10k
  }
509
510
2.12k
  if (num_lines == 0)
511
0
    return 0;
512
513
2.12k
  lines_per_iMCU_row = cinfo->_min_DCT_scaled_size * cinfo->max_v_samp_factor;
514
2.12k
  lines_left_in_iMCU_row =
515
2.12k
    (lines_per_iMCU_row - (cinfo->output_scanline % lines_per_iMCU_row)) %
516
2.12k
    lines_per_iMCU_row;
517
2.12k
  lines_after_iMCU_row = num_lines - lines_left_in_iMCU_row;
518
519
  /* Skip the lines remaining in the current iMCU row.  When upsampling
520
   * requires context rows, we need the previous and next rows in order to read
521
   * the current row.  This adds some complexity.
522
   */
523
2.12k
  if (cinfo->upsample->need_context_rows) {
524
    /* If the skipped lines would not move us past the current iMCU row, we
525
     * read the lines and ignore them.  There might be a faster way of doing
526
     * this, but we are facing increasing complexity for diminishing returns.
527
     * The increasing complexity would be a by-product of meddling with the
528
     * state machine used to skip context rows.  Near the end of an iMCU row,
529
     * the next iMCU row may have already been entropy-decoded.  In this unique
530
     * case, we will read the next iMCU row if we cannot skip past it as well.
531
     */
532
66
    if ((num_lines < lines_left_in_iMCU_row + 1) ||
533
66
        (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full &&
534
0
         lines_after_iMCU_row < lines_per_iMCU_row + 1)) {
535
0
      read_and_discard_scanlines(cinfo, num_lines);
536
0
      return num_lines;
537
0
    }
538
539
    /* If the next iMCU row has already been entropy-decoded, make sure that
540
     * we do not skip too far.
541
     */
542
66
    if (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full) {
543
0
      cinfo->output_scanline += lines_left_in_iMCU_row + lines_per_iMCU_row;
544
0
      lines_after_iMCU_row -= lines_per_iMCU_row;
545
66
    } else {
546
66
      cinfo->output_scanline += lines_left_in_iMCU_row;
547
66
    }
548
549
    /* If we have just completed the first block, adjust the buffer pointers */
550
66
    if (main_ptr->iMCU_row_ctr == 0 ||
551
0
        (main_ptr->iMCU_row_ctr == 1 && lines_left_in_iMCU_row > 2))
552
66
      set_wraparound_pointers(cinfo);
553
66
    main_ptr->buffer_full = FALSE;
554
66
    main_ptr->rowgroup_ctr = 0;
555
66
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
556
66
    if (!master->using_merged_upsample) {
557
66
      upsample->next_row_out = cinfo->max_v_samp_factor;
558
66
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
559
66
    }
560
66
  }
561
562
  /* Skipping is much simpler when context rows are not required. */
563
2.06k
  else {
564
2.06k
    if (num_lines < lines_left_in_iMCU_row) {
565
0
      increment_simple_rowgroup_ctr(cinfo, num_lines);
566
0
      return num_lines;
567
2.06k
    } else {
568
2.06k
      cinfo->output_scanline += lines_left_in_iMCU_row;
569
2.06k
      main_ptr->buffer_full = FALSE;
570
2.06k
      main_ptr->rowgroup_ctr = 0;
571
2.06k
      if (!master->using_merged_upsample) {
572
2.06k
        upsample->next_row_out = cinfo->max_v_samp_factor;
573
2.06k
        upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
574
2.06k
      }
575
2.06k
    }
576
2.06k
  }
577
578
  /* Calculate how many full iMCU rows we can skip. */
579
2.12k
  if (cinfo->upsample->need_context_rows)
580
66
    lines_to_skip = ((lines_after_iMCU_row - 1) / lines_per_iMCU_row) *
581
66
                    lines_per_iMCU_row;
582
2.06k
  else
583
2.06k
    lines_to_skip = (lines_after_iMCU_row / lines_per_iMCU_row) *
584
2.06k
                    lines_per_iMCU_row;
585
  /* Calculate the number of lines that remain to be skipped after skipping all
586
   * of the full iMCU rows that we can.  We will not read these lines unless we
587
   * have to.
588
   */
589
2.12k
  lines_to_read = lines_after_iMCU_row - lines_to_skip;
590
591
  /* For images requiring multiple scans (progressive, non-interleaved, etc.),
592
   * all of the entropy decoding occurs in jpeg_start_decompress(), assuming
593
   * that the input data source is non-suspending.  This makes skipping easy.
594
   */
595
2.12k
  if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) {
596
1.24k
    if (cinfo->upsample->need_context_rows) {
597
12
      cinfo->output_scanline += lines_to_skip;
598
12
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
599
12
      main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
600
      /* It is complex to properly move to the middle of a context block, so
601
       * read the remaining lines instead of skipping them.
602
       */
603
12
      read_and_discard_scanlines(cinfo, lines_to_read);
604
1.22k
    } else {
605
1.22k
      cinfo->output_scanline += lines_to_skip;
606
1.22k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
607
1.22k
      increment_simple_rowgroup_ctr(cinfo, lines_to_read);
608
1.22k
    }
609
1.24k
    if (!master->using_merged_upsample)
610
1.24k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
611
1.24k
    return num_lines;
612
1.24k
  }
613
614
  /* Skip the iMCU rows that we can safely skip. */
615
2.19k
  for (i = 0; i < lines_to_skip; i += lines_per_iMCU_row) {
616
3.34k
    for (y = 0; y < coef->MCU_rows_per_iMCU_row; y++) {
617
249k
      for (x = 0; x < cinfo->MCUs_per_row; x++) {
618
        /* Calling decode_mcu() with a NULL pointer causes it to discard the
619
         * decoded coefficients.  This is ~5% faster for large subsets, but
620
         * it's tough to tell a difference for smaller images.
621
         */
622
247k
        if (!cinfo->entropy->insufficient_data)
623
105k
          cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
624
247k
        (*cinfo->entropy->decode_mcu) (cinfo, NULL);
625
247k
      }
626
2.03k
    }
627
1.31k
    cinfo->input_iMCU_row++;
628
1.31k
    cinfo->output_iMCU_row++;
629
1.31k
    if (cinfo->input_iMCU_row < cinfo->total_iMCU_rows)
630
1.31k
      start_iMCU_row(cinfo);
631
0
    else
632
0
      (*cinfo->inputctl->finish_input_pass) (cinfo);
633
1.31k
  }
634
887
  cinfo->output_scanline += lines_to_skip;
635
636
887
  if (cinfo->upsample->need_context_rows) {
637
    /* Context-based upsampling keeps track of iMCU rows. */
638
54
    main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
639
640
    /* It is complex to properly move to the middle of a context block, so
641
     * read the remaining lines instead of skipping them.
642
     */
643
54
    read_and_discard_scanlines(cinfo, lines_to_read);
644
833
  } else {
645
833
    increment_simple_rowgroup_ctr(cinfo, lines_to_read);
646
833
  }
647
648
  /* Since skipping lines involves skipping the upsampling step, the value of
649
   * "rows_to_go" will become invalid unless we set it here.  NOTE: This is a
650
   * bit odd, since "rows_to_go" seems to be redundantly keeping track of
651
   * output_scanline.
652
   */
653
887
  if (!master->using_merged_upsample)
654
887
    upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
655
656
  /* Always skip the requested number of lines. */
657
887
  return num_lines;
658
2.12k
}
jpeg_skip_scanlines
Line
Count
Source
477
97.5k
{
478
97.5k
  my_main_ptr main_ptr = (my_main_ptr)cinfo->main;
479
97.5k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
480
97.5k
  my_master_ptr master = (my_master_ptr)cinfo->master;
481
97.5k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
482
97.5k
  JDIMENSION i, x;
483
97.5k
  int y;
484
97.5k
  JDIMENSION lines_per_iMCU_row, lines_left_in_iMCU_row, lines_after_iMCU_row;
485
97.5k
  JDIMENSION lines_to_skip, lines_to_read;
486
487
97.5k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
488
148
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
489
490
97.5k
  if (cinfo->master->lossless)
491
0
    ERREXIT(cinfo, JERR_NOTIMPL);
492
493
  /* Two-pass color quantization is not supported. */
494
97.5k
  if (cinfo->quantize_colors && cinfo->two_pass_quantize)
495
0
    ERREXIT(cinfo, JERR_NOTIMPL);
496
497
97.5k
  if (cinfo->global_state != DSTATE_SCANNING)
498
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
499
500
  /* Do not skip past the bottom of the image. */
501
97.5k
  if ((unsigned long long)cinfo->output_scanline + num_lines >=
502
97.5k
      cinfo->output_height) {
503
4.54k
    num_lines = cinfo->output_height - cinfo->output_scanline;
504
4.54k
    cinfo->output_scanline = cinfo->output_height;
505
4.54k
    (*cinfo->inputctl->finish_input_pass) (cinfo);
506
4.54k
    cinfo->inputctl->eoi_reached = TRUE;
507
4.54k
    return num_lines;
508
4.54k
  }
509
510
93.0k
  if (num_lines == 0)
511
0
    return 0;
512
513
93.0k
  lines_per_iMCU_row = cinfo->_min_DCT_scaled_size * cinfo->max_v_samp_factor;
514
93.0k
  lines_left_in_iMCU_row =
515
93.0k
    (lines_per_iMCU_row - (cinfo->output_scanline % lines_per_iMCU_row)) %
516
93.0k
    lines_per_iMCU_row;
517
93.0k
  lines_after_iMCU_row = num_lines - lines_left_in_iMCU_row;
518
519
  /* Skip the lines remaining in the current iMCU row.  When upsampling
520
   * requires context rows, we need the previous and next rows in order to read
521
   * the current row.  This adds some complexity.
522
   */
523
93.0k
  if (cinfo->upsample->need_context_rows) {
524
    /* If the skipped lines would not move us past the current iMCU row, we
525
     * read the lines and ignore them.  There might be a faster way of doing
526
     * this, but we are facing increasing complexity for diminishing returns.
527
     * The increasing complexity would be a by-product of meddling with the
528
     * state machine used to skip context rows.  Near the end of an iMCU row,
529
     * the next iMCU row may have already been entropy-decoded.  In this unique
530
     * case, we will read the next iMCU row if we cannot skip past it as well.
531
     */
532
36.3k
    if ((num_lines < lines_left_in_iMCU_row + 1) ||
533
31.8k
        (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full &&
534
16.1k
         lines_after_iMCU_row < lines_per_iMCU_row + 1)) {
535
16.1k
      read_and_discard_scanlines(cinfo, num_lines);
536
16.1k
      return num_lines;
537
16.1k
    }
538
539
    /* If the next iMCU row has already been entropy-decoded, make sure that
540
     * we do not skip too far.
541
     */
542
20.2k
    if (lines_left_in_iMCU_row <= 1 && main_ptr->buffer_full) {
543
0
      cinfo->output_scanline += lines_left_in_iMCU_row + lines_per_iMCU_row;
544
0
      lines_after_iMCU_row -= lines_per_iMCU_row;
545
20.2k
    } else {
546
20.2k
      cinfo->output_scanline += lines_left_in_iMCU_row;
547
20.2k
    }
548
549
    /* If we have just completed the first block, adjust the buffer pointers */
550
20.2k
    if (main_ptr->iMCU_row_ctr == 0 ||
551
0
        (main_ptr->iMCU_row_ctr == 1 && lines_left_in_iMCU_row > 2))
552
20.2k
      set_wraparound_pointers(cinfo);
553
20.2k
    main_ptr->buffer_full = FALSE;
554
20.2k
    main_ptr->rowgroup_ctr = 0;
555
20.2k
    main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
556
20.2k
    if (!master->using_merged_upsample) {
557
20.2k
      upsample->next_row_out = cinfo->max_v_samp_factor;
558
20.2k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
559
20.2k
    }
560
20.2k
  }
561
562
  /* Skipping is much simpler when context rows are not required. */
563
56.6k
  else {
564
56.6k
    if (num_lines < lines_left_in_iMCU_row) {
565
9.06k
      increment_simple_rowgroup_ctr(cinfo, num_lines);
566
9.06k
      return num_lines;
567
47.5k
    } else {
568
47.5k
      cinfo->output_scanline += lines_left_in_iMCU_row;
569
47.5k
      main_ptr->buffer_full = FALSE;
570
47.5k
      main_ptr->rowgroup_ctr = 0;
571
47.5k
      if (!master->using_merged_upsample) {
572
47.4k
        upsample->next_row_out = cinfo->max_v_samp_factor;
573
47.4k
        upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
574
47.4k
      }
575
47.5k
    }
576
56.6k
  }
577
578
  /* Calculate how many full iMCU rows we can skip. */
579
67.8k
  if (cinfo->upsample->need_context_rows)
580
20.2k
    lines_to_skip = ((lines_after_iMCU_row - 1) / lines_per_iMCU_row) *
581
20.2k
                    lines_per_iMCU_row;
582
47.5k
  else
583
47.5k
    lines_to_skip = (lines_after_iMCU_row / lines_per_iMCU_row) *
584
47.5k
                    lines_per_iMCU_row;
585
  /* Calculate the number of lines that remain to be skipped after skipping all
586
   * of the full iMCU rows that we can.  We will not read these lines unless we
587
   * have to.
588
   */
589
67.8k
  lines_to_read = lines_after_iMCU_row - lines_to_skip;
590
591
  /* For images requiring multiple scans (progressive, non-interleaved, etc.),
592
   * all of the entropy decoding occurs in jpeg_start_decompress(), assuming
593
   * that the input data source is non-suspending.  This makes skipping easy.
594
   */
595
67.8k
  if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) {
596
54.5k
    if (cinfo->upsample->need_context_rows) {
597
19.4k
      cinfo->output_scanline += lines_to_skip;
598
19.4k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
599
19.4k
      main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
600
      /* It is complex to properly move to the middle of a context block, so
601
       * read the remaining lines instead of skipping them.
602
       */
603
19.4k
      read_and_discard_scanlines(cinfo, lines_to_read);
604
35.1k
    } else {
605
35.1k
      cinfo->output_scanline += lines_to_skip;
606
35.1k
      cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;
607
35.1k
      increment_simple_rowgroup_ctr(cinfo, lines_to_read);
608
35.1k
    }
609
54.5k
    if (!master->using_merged_upsample)
610
54.5k
      upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
611
54.5k
    return num_lines;
612
54.5k
  }
613
614
  /* Skip the iMCU rows that we can safely skip. */
615
23.5k
  for (i = 0; i < lines_to_skip; i += lines_per_iMCU_row) {
616
21.0k
    for (y = 0; y < coef->MCU_rows_per_iMCU_row; y++) {
617
3.42M
      for (x = 0; x < cinfo->MCUs_per_row; x++) {
618
        /* Calling decode_mcu() with a NULL pointer causes it to discard the
619
         * decoded coefficients.  This is ~5% faster for large subsets, but
620
         * it's tough to tell a difference for smaller images.
621
         */
622
3.40M
        if (!cinfo->entropy->insufficient_data)
623
1.03M
          cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
624
3.40M
        (*cinfo->entropy->decode_mcu) (cinfo, NULL);
625
3.40M
      }
626
10.7k
    }
627
10.3k
    cinfo->input_iMCU_row++;
628
10.3k
    cinfo->output_iMCU_row++;
629
10.3k
    if (cinfo->input_iMCU_row < cinfo->total_iMCU_rows)
630
10.3k
      start_iMCU_row(cinfo);
631
0
    else
632
0
      (*cinfo->inputctl->finish_input_pass) (cinfo);
633
10.3k
  }
634
13.2k
  cinfo->output_scanline += lines_to_skip;
635
636
13.2k
  if (cinfo->upsample->need_context_rows) {
637
    /* Context-based upsampling keeps track of iMCU rows. */
638
760
    main_ptr->iMCU_row_ctr += lines_to_skip / lines_per_iMCU_row;
639
640
    /* It is complex to properly move to the middle of a context block, so
641
     * read the remaining lines instead of skipping them.
642
     */
643
760
    read_and_discard_scanlines(cinfo, lines_to_read);
644
12.4k
  } else {
645
12.4k
    increment_simple_rowgroup_ctr(cinfo, lines_to_read);
646
12.4k
  }
647
648
  /* Since skipping lines involves skipping the upsampling step, the value of
649
   * "rows_to_go" will become invalid unless we set it here.  NOTE: This is a
650
   * bit odd, since "rows_to_go" seems to be redundantly keeping track of
651
   * output_scanline.
652
   */
653
13.2k
  if (!master->using_merged_upsample)
654
13.0k
    upsample->rows_to_go = cinfo->output_height - cinfo->output_scanline;
655
656
  /* Always skip the requested number of lines. */
657
13.2k
  return num_lines;
658
67.8k
}
659
660
/*
661
 * Alternate entry point to read raw data.
662
 * Processes exactly one iMCU row per call, unless suspended.
663
 */
664
665
GLOBAL(JDIMENSION)
666
_jpeg_read_raw_data(j_decompress_ptr cinfo, _JSAMPIMAGE data,
667
                    JDIMENSION max_lines)
668
6.40M
{
669
6.40M
  JDIMENSION lines_per_iMCU_row;
670
671
6.40M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
672
9.00k
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
673
674
6.40M
  if (cinfo->master->lossless)
675
1.81k
    ERREXIT(cinfo, JERR_NOTIMPL);
676
677
6.40M
  if (cinfo->global_state != DSTATE_RAW_OK)
678
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
679
6.40M
  if (cinfo->output_scanline >= cinfo->output_height) {
680
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
681
0
    return 0;
682
0
  }
683
684
  /* Call progress monitor hook if present */
685
6.40M
  if (cinfo->progress != NULL) {
686
6.39M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
687
6.39M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
688
6.39M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
689
6.39M
  }
690
691
  /* Verify that at least one iMCU row can be returned. */
692
6.40M
  lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size;
693
6.40M
  if (max_lines < lines_per_iMCU_row)
694
0
    ERREXIT(cinfo, JERR_BUFFER_SIZE);
695
696
  /* Decompress directly into user's buffer. */
697
6.40M
  if (cinfo->coef->_decompress_data == NULL)
698
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
699
6.40M
  if (!(*cinfo->coef->_decompress_data) (cinfo, data))
700
0
    return 0;                   /* suspension forced, can do nothing more */
701
702
  /* OK, we processed one iMCU row. */
703
6.40M
  cinfo->output_scanline += lines_per_iMCU_row;
704
6.40M
  return lines_per_iMCU_row;
705
6.40M
}
Unexecuted instantiation: jpeg12_read_raw_data
jpeg_read_raw_data
Line
Count
Source
668
6.40M
{
669
6.40M
  JDIMENSION lines_per_iMCU_row;
670
671
6.40M
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
672
9.00k
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
673
674
6.40M
  if (cinfo->master->lossless)
675
1.81k
    ERREXIT(cinfo, JERR_NOTIMPL);
676
677
6.40M
  if (cinfo->global_state != DSTATE_RAW_OK)
678
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
679
6.40M
  if (cinfo->output_scanline >= cinfo->output_height) {
680
0
    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
681
0
    return 0;
682
0
  }
683
684
  /* Call progress monitor hook if present */
685
6.40M
  if (cinfo->progress != NULL) {
686
6.39M
    cinfo->progress->pass_counter = (long)cinfo->output_scanline;
687
6.39M
    cinfo->progress->pass_limit = (long)cinfo->output_height;
688
6.39M
    (*cinfo->progress->progress_monitor) ((j_common_ptr)cinfo);
689
6.39M
  }
690
691
  /* Verify that at least one iMCU row can be returned. */
692
6.40M
  lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->_min_DCT_scaled_size;
693
6.40M
  if (max_lines < lines_per_iMCU_row)
694
0
    ERREXIT(cinfo, JERR_BUFFER_SIZE);
695
696
  /* Decompress directly into user's buffer. */
697
6.40M
  if (cinfo->coef->_decompress_data == NULL)
698
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
699
6.40M
  if (!(*cinfo->coef->_decompress_data) (cinfo, data))
700
0
    return 0;                   /* suspension forced, can do nothing more */
701
702
  /* OK, we processed one iMCU row. */
703
6.40M
  cinfo->output_scanline += lines_per_iMCU_row;
704
6.40M
  return lines_per_iMCU_row;
705
6.40M
}
706
707
#endif /* BITS_IN_JSAMPLE != 16 */
708
709
710
#if BITS_IN_JSAMPLE == 8
711
712
/* Additional entry points for buffered-image mode. */
713
714
#ifdef D_MULTISCAN_FILES_SUPPORTED
715
716
/*
717
 * Initialize for an output pass in buffered-image mode.
718
 */
719
720
GLOBAL(boolean)
721
jpeg_start_output(j_decompress_ptr cinfo, int scan_number)
722
57.8k
{
723
57.8k
  if (cinfo->global_state != DSTATE_BUFIMAGE &&
724
0
      cinfo->global_state != DSTATE_PRESCAN)
725
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
726
  /* Limit scan number to valid range */
727
57.8k
  if (scan_number <= 0)
728
0
    scan_number = 1;
729
57.8k
  if (cinfo->inputctl->eoi_reached && scan_number > cinfo->input_scan_number)
730
0
    scan_number = cinfo->input_scan_number;
731
57.8k
  cinfo->output_scan_number = scan_number;
732
  /* Perform any dummy output passes, and set up for the real pass */
733
57.8k
  return output_pass_setup(cinfo);
734
57.8k
}
735
736
737
/*
738
 * Finish up after an output pass in buffered-image mode.
739
 *
740
 * Returns FALSE if suspended.  The return value need be inspected only if
741
 * a suspending data source is used.
742
 */
743
744
GLOBAL(boolean)
745
jpeg_finish_output(j_decompress_ptr cinfo)
746
57.4k
{
747
57.4k
  if ((cinfo->global_state == DSTATE_SCANNING ||
748
57.4k
       cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
749
    /* Terminate this pass. */
750
    /* We do not require the whole pass to have been completed. */
751
57.4k
    (*cinfo->master->finish_output_pass) (cinfo);
752
57.4k
    cinfo->global_state = DSTATE_BUFPOST;
753
57.4k
  } else if (cinfo->global_state != DSTATE_BUFPOST) {
754
    /* BUFPOST = repeat call after a suspension, anything else is error */
755
0
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
756
0
  }
757
  /* Read markers looking for SOS or EOI */
758
105k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
759
58.1k
         !cinfo->inputctl->eoi_reached) {
760
48.6k
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
761
161
      return FALSE;             /* Suspend, come back later */
762
48.6k
  }
763
57.2k
  cinfo->global_state = DSTATE_BUFIMAGE;
764
57.2k
  return TRUE;
765
57.4k
}
766
767
#endif /* D_MULTISCAN_FILES_SUPPORTED */
768
769
#endif /* BITS_IN_JSAMPLE == 8 */