Coverage Report

Created: 2026-06-16 06:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo/src/jdcoefct.c
Line
Count
Source
1
/*
2
 * jdcoefct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1997, Thomas G. Lane.
6
 * libjpeg-turbo Modifications:
7
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
8
 * Copyright (C) 2010, 2015-2016, 2019-2020, 2022-2026, D. R. Commander.
9
 * Copyright (C) 2015, 2020, Google, Inc.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the coefficient buffer controller for decompression.
14
 * This controller is the top level of the lossy JPEG decompressor proper.
15
 * The coefficient buffer lies between entropy decoding and inverse-DCT steps.
16
 *
17
 * In buffered-image mode, this controller is the interface between
18
 * input-oriented processing and output-oriented processing.
19
 * Also, the input side (only) is used when reading a file for transcoding.
20
 */
21
22
#include "jinclude.h"
23
#include "jdcoefct.h"
24
#include "jpegapicomp.h"
25
#include "jsamplecomp.h"
26
#ifdef WITH_PROFILE
27
#include "tjutil.h"
28
#endif
29
30
31
/* Forward declarations */
32
METHODDEF(int) decompress_onepass(j_decompress_ptr cinfo,
33
                                  _JSAMPIMAGE output_buf);
34
#ifdef D_MULTISCAN_FILES_SUPPORTED
35
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
36
#endif
37
#ifdef BLOCK_SMOOTHING_SUPPORTED
38
LOCAL(boolean) smoothing_ok(j_decompress_ptr cinfo);
39
METHODDEF(int) decompress_smooth_data(j_decompress_ptr cinfo,
40
                                      _JSAMPIMAGE output_buf);
41
#endif
42
43
44
/*
45
 * Initialize for an input processing pass.
46
 */
47
48
METHODDEF(void)
49
start_input_pass(j_decompress_ptr cinfo)
50
5.81k
{
51
5.81k
  cinfo->input_iMCU_row = 0;
52
5.81k
  start_iMCU_row(cinfo);
53
5.81k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
50
4.95k
{
51
4.95k
  cinfo->input_iMCU_row = 0;
52
4.95k
  start_iMCU_row(cinfo);
53
4.95k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
50
856
{
51
856
  cinfo->input_iMCU_row = 0;
52
856
  start_iMCU_row(cinfo);
53
856
}
54
55
56
/*
57
 * Initialize for an output processing pass.
58
 */
59
60
METHODDEF(void)
61
start_output_pass(j_decompress_ptr cinfo)
62
1.89k
{
63
1.89k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
1.89k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
65
66
  /* If multipass, check to see whether to use block smoothing on this pass */
67
1.89k
  if (coef->pub.coef_arrays != NULL) {
68
489
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
301
      coef->pub._decompress_data = decompress_smooth_data;
70
188
    else
71
188
      coef->pub._decompress_data = decompress_data;
72
489
  }
73
1.89k
#endif
74
1.89k
  cinfo->output_iMCU_row = 0;
75
1.89k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
62
1.78k
{
63
1.78k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
1.78k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
65
66
  /* If multipass, check to see whether to use block smoothing on this pass */
67
1.78k
  if (coef->pub.coef_arrays != NULL) {
68
391
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
276
      coef->pub._decompress_data = decompress_smooth_data;
70
115
    else
71
115
      coef->pub._decompress_data = decompress_data;
72
391
  }
73
1.78k
#endif
74
1.78k
  cinfo->output_iMCU_row = 0;
75
1.78k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
62
108
{
63
108
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
108
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
65
66
  /* If multipass, check to see whether to use block smoothing on this pass */
67
108
  if (coef->pub.coef_arrays != NULL) {
68
98
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
25
      coef->pub._decompress_data = decompress_smooth_data;
70
73
    else
71
73
      coef->pub._decompress_data = decompress_data;
72
98
  }
73
108
#endif
74
108
  cinfo->output_iMCU_row = 0;
75
108
}
76
77
78
/*
79
 * Decompress and return some data in the single-pass case.
80
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
81
 * Input and output must run in lockstep since we have only a one-MCU buffer.
82
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
83
 *
84
 * NB: output_buf contains a plane for each component in image,
85
 * which we index according to the component's SOF position.
86
 */
87
88
METHODDEF(int)
89
decompress_onepass(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
90
16.4k
{
91
16.4k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
16.4k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
16.4k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
16.4k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
16.4k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
16.4k
  _JSAMPARRAY output_ptr;
97
16.4k
  JDIMENSION start_col, output_col;
98
16.4k
  jpeg_component_info *compptr;
99
16.4k
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
34.4k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
17.9k
       yoffset++) {
104
326k
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
308k
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
308k
      jzero_far((void *)coef->MCU_buffer[0],
108
308k
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
308k
      if (!cinfo->entropy->insufficient_data)
110
308k
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
308k
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
115
        /* Suspension forced; update state counters and exit */
116
0
        coef->MCU_vert_offset = yoffset;
117
0
        coef->MCU_ctr = MCU_col_num;
118
#ifdef WITH_PROFILE
119
        cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
120
        cinfo->master->entropy_mcoeffs +=
121
          (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
122
#endif
123
0
        return JPEG_SUSPENDED;
124
0
      }
125
#ifdef WITH_PROFILE
126
      cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
127
      cinfo->master->entropy_mcoeffs +=
128
        (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
129
#endif
130
131
      /* Only perform the IDCT on blocks that are contained within the desired
132
       * cropping region.
133
       */
134
308k
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
307k
          MCU_col_num <= cinfo->master->last_iMCU_col) {
136
        /* Determine where data should go in output_buf and do the IDCT thing.
137
         * We skip dummy blocks at the right and bottom edges (but blkn gets
138
         * incremented past them!).  Note the inner loop relies on having
139
         * allocated the MCU_buffer[] blocks sequentially.
140
         */
141
307k
        blkn = 0;               /* index of current DCT block within MCU */
142
824k
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
517k
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
517k
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
517k
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
517k
          useful_width = (MCU_col_num < last_MCU_col) ?
151
473k
                         compptr->MCU_width : compptr->last_col_width;
152
517k
          output_ptr = output_buf[compptr->component_index] +
153
517k
                       yoffset * compptr->_DCT_scaled_size;
154
517k
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
517k
                      compptr->MCU_sample_width;
156
1.36M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
848k
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
707k
                yoffset + yindex < compptr->last_row_height) {
159
707k
              output_col = start_col;
160
1.53M
              for (xindex = 0; xindex < useful_width; xindex++) {
161
#ifdef WITH_PROFILE
162
                cinfo->master->start = getTime();
163
#endif
164
832k
                (*inverse_DCT) (cinfo, compptr,
165
832k
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
832k
                                output_ptr, output_col);
167
#ifdef WITH_PROFILE
168
                cinfo->master->idct_elapsed +=
169
                  getTime() - cinfo->master->start;
170
                cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
171
#endif
172
832k
                output_col += compptr->_DCT_scaled_size;
173
832k
              }
174
707k
            }
175
848k
            blkn += compptr->MCU_width;
176
848k
            output_ptr += compptr->_DCT_scaled_size;
177
848k
          }
178
517k
        }
179
307k
      }
180
308k
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
17.9k
    coef->MCU_ctr = 0;
183
17.9k
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
16.4k
  cinfo->output_iMCU_row++;
186
16.4k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
15.0k
    start_iMCU_row(cinfo);
188
15.0k
    return JPEG_ROW_COMPLETED;
189
15.0k
  }
190
  /* Completed the scan */
191
1.39k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
1.39k
  return JPEG_SCAN_COMPLETED;
193
16.4k
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
90
16.4k
{
91
16.4k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
16.4k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
16.4k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
16.4k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
16.4k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
16.4k
  _JSAMPARRAY output_ptr;
97
16.4k
  JDIMENSION start_col, output_col;
98
16.4k
  jpeg_component_info *compptr;
99
16.4k
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
34.4k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
17.9k
       yoffset++) {
104
326k
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
308k
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
308k
      jzero_far((void *)coef->MCU_buffer[0],
108
308k
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
308k
      if (!cinfo->entropy->insufficient_data)
110
308k
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
308k
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
115
        /* Suspension forced; update state counters and exit */
116
0
        coef->MCU_vert_offset = yoffset;
117
0
        coef->MCU_ctr = MCU_col_num;
118
#ifdef WITH_PROFILE
119
        cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
120
        cinfo->master->entropy_mcoeffs +=
121
          (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
122
#endif
123
0
        return JPEG_SUSPENDED;
124
0
      }
125
#ifdef WITH_PROFILE
126
      cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
127
      cinfo->master->entropy_mcoeffs +=
128
        (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
129
#endif
130
131
      /* Only perform the IDCT on blocks that are contained within the desired
132
       * cropping region.
133
       */
134
308k
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
307k
          MCU_col_num <= cinfo->master->last_iMCU_col) {
136
        /* Determine where data should go in output_buf and do the IDCT thing.
137
         * We skip dummy blocks at the right and bottom edges (but blkn gets
138
         * incremented past them!).  Note the inner loop relies on having
139
         * allocated the MCU_buffer[] blocks sequentially.
140
         */
141
307k
        blkn = 0;               /* index of current DCT block within MCU */
142
824k
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
517k
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
517k
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
517k
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
517k
          useful_width = (MCU_col_num < last_MCU_col) ?
151
473k
                         compptr->MCU_width : compptr->last_col_width;
152
517k
          output_ptr = output_buf[compptr->component_index] +
153
517k
                       yoffset * compptr->_DCT_scaled_size;
154
517k
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
517k
                      compptr->MCU_sample_width;
156
1.36M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
848k
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
707k
                yoffset + yindex < compptr->last_row_height) {
159
707k
              output_col = start_col;
160
1.53M
              for (xindex = 0; xindex < useful_width; xindex++) {
161
#ifdef WITH_PROFILE
162
                cinfo->master->start = getTime();
163
#endif
164
832k
                (*inverse_DCT) (cinfo, compptr,
165
832k
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
832k
                                output_ptr, output_col);
167
#ifdef WITH_PROFILE
168
                cinfo->master->idct_elapsed +=
169
                  getTime() - cinfo->master->start;
170
                cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
171
#endif
172
832k
                output_col += compptr->_DCT_scaled_size;
173
832k
              }
174
707k
            }
175
848k
            blkn += compptr->MCU_width;
176
848k
            output_ptr += compptr->_DCT_scaled_size;
177
848k
          }
178
517k
        }
179
307k
      }
180
308k
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
17.9k
    coef->MCU_ctr = 0;
183
17.9k
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
16.4k
  cinfo->output_iMCU_row++;
186
16.4k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
15.0k
    start_iMCU_row(cinfo);
188
15.0k
    return JPEG_ROW_COMPLETED;
189
15.0k
  }
190
  /* Completed the scan */
191
1.39k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
1.39k
  return JPEG_SCAN_COMPLETED;
193
16.4k
}
Unexecuted instantiation: jdcoefct-12.c:decompress_onepass
194
195
196
/*
197
 * Dummy consume-input routine for single-pass operation.
198
 */
199
200
METHODDEF(int)
201
dummy_consume_data(j_decompress_ptr cinfo)
202
0
{
203
0
  return JPEG_SUSPENDED;        /* Always indicate nothing was done */
204
0
}
Unexecuted instantiation: jdcoefct-8.c:dummy_consume_data
Unexecuted instantiation: jdcoefct-12.c:dummy_consume_data
205
206
207
#ifdef D_MULTISCAN_FILES_SUPPORTED
208
209
/*
210
 * Consume input data and store it in the full-image coefficient buffer.
211
 * We read as much as one fully interleaved MCU row ("iMCU" row) per call,
212
 * ie, v_samp_factor block rows for each component in the scan.
213
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
214
 */
215
216
METHODDEF(int)
217
consume_data(j_decompress_ptr cinfo)
218
156k
{
219
156k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
156k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
156k
  int blkn, ci, xindex, yindex, yoffset;
222
156k
  JDIMENSION start_col;
223
156k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
156k
  JBLOCKROW buffer_ptr;
225
156k
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
574k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
418k
    compptr = cinfo->cur_comp_info[ci];
230
418k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
418k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
418k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
418k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
234
    /* Note: entropy decoder expects buffer to be zeroed,
235
     * but this is handled automatically by the memory manager
236
     * because we requested a pre-zeroed array.
237
     */
238
418k
  }
239
240
  /* Loop to process one whole iMCU row */
241
343k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
186k
       yoffset++) {
243
3.12M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
2.93M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
2.93M
      blkn = 0;                 /* index of current DCT block within MCU */
247
8.01M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
5.07M
        compptr = cinfo->cur_comp_info[ci];
249
5.07M
        start_col = MCU_col_num * compptr->MCU_width;
250
11.2M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
6.18M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
13.4M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
7.21M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
7.21M
          }
255
6.18M
        }
256
5.07M
      }
257
2.93M
      if (!cinfo->entropy->insufficient_data)
258
2.93M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
259
      /* Try to fetch the MCU. */
260
#ifdef WITH_PROFILE
261
      cinfo->master->start = getTime();
262
#endif
263
2.93M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
264
        /* Suspension forced; update state counters and exit */
265
0
        coef->MCU_vert_offset = yoffset;
266
0
        coef->MCU_ctr = MCU_col_num;
267
#ifdef WITH_PROFILE
268
        cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
269
        cinfo->master->entropy_mcoeffs +=
270
          (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
271
#endif
272
0
        return JPEG_SUSPENDED;
273
0
      }
274
#ifdef WITH_PROFILE
275
      cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
276
      cinfo->master->entropy_mcoeffs +=
277
        (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
278
#endif
279
2.93M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
186k
    coef->MCU_ctr = 0;
282
186k
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
156k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
152k
    start_iMCU_row(cinfo);
286
152k
    return JPEG_ROW_COMPLETED;
287
152k
  }
288
  /* Completed the scan */
289
4.40k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
4.40k
  return JPEG_SCAN_COMPLETED;
291
156k
}
jdcoefct-8.c:consume_data
Line
Count
Source
218
134k
{
219
134k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
134k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
134k
  int blkn, ci, xindex, yindex, yoffset;
222
134k
  JDIMENSION start_col;
223
134k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
134k
  JBLOCKROW buffer_ptr;
225
134k
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
518k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
384k
    compptr = cinfo->cur_comp_info[ci];
230
384k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
384k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
384k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
384k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
234
    /* Note: entropy decoder expects buffer to be zeroed,
235
     * but this is handled automatically by the memory manager
236
     * because we requested a pre-zeroed array.
237
     */
238
384k
  }
239
240
  /* Loop to process one whole iMCU row */
241
283k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
148k
       yoffset++) {
243
2.03M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
1.88M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
1.88M
      blkn = 0;                 /* index of current DCT block within MCU */
247
4.99M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
3.11M
        compptr = cinfo->cur_comp_info[ci];
249
3.11M
        start_col = MCU_col_num * compptr->MCU_width;
250
6.58M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
3.47M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
7.37M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
3.90M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
3.90M
          }
255
3.47M
        }
256
3.11M
      }
257
1.88M
      if (!cinfo->entropy->insufficient_data)
258
1.88M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
259
      /* Try to fetch the MCU. */
260
#ifdef WITH_PROFILE
261
      cinfo->master->start = getTime();
262
#endif
263
1.88M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
264
        /* Suspension forced; update state counters and exit */
265
0
        coef->MCU_vert_offset = yoffset;
266
0
        coef->MCU_ctr = MCU_col_num;
267
#ifdef WITH_PROFILE
268
        cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
269
        cinfo->master->entropy_mcoeffs +=
270
          (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
271
#endif
272
0
        return JPEG_SUSPENDED;
273
0
      }
274
#ifdef WITH_PROFILE
275
      cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
276
      cinfo->master->entropy_mcoeffs +=
277
        (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
278
#endif
279
1.88M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
148k
    coef->MCU_ctr = 0;
282
148k
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
134k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
130k
    start_iMCU_row(cinfo);
286
130k
    return JPEG_ROW_COMPLETED;
287
130k
  }
288
  /* Completed the scan */
289
3.56k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
3.56k
  return JPEG_SCAN_COMPLETED;
291
134k
}
jdcoefct-12.c:consume_data
Line
Count
Source
218
22.0k
{
219
22.0k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
22.0k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
22.0k
  int blkn, ci, xindex, yindex, yoffset;
222
22.0k
  JDIMENSION start_col;
223
22.0k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
22.0k
  JBLOCKROW buffer_ptr;
225
22.0k
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
55.9k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
33.9k
    compptr = cinfo->cur_comp_info[ci];
230
33.9k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
33.9k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
33.9k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
33.9k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
234
    /* Note: entropy decoder expects buffer to be zeroed,
235
     * but this is handled automatically by the memory manager
236
     * because we requested a pre-zeroed array.
237
     */
238
33.9k
  }
239
240
  /* Loop to process one whole iMCU row */
241
59.6k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
37.5k
       yoffset++) {
243
1.08M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
1.05M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
1.05M
      blkn = 0;                 /* index of current DCT block within MCU */
247
3.01M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
1.96M
        compptr = cinfo->cur_comp_info[ci];
249
1.96M
        start_col = MCU_col_num * compptr->MCU_width;
250
4.67M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
2.71M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
6.02M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
3.31M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
3.31M
          }
255
2.71M
        }
256
1.96M
      }
257
1.05M
      if (!cinfo->entropy->insufficient_data)
258
1.05M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
259
      /* Try to fetch the MCU. */
260
#ifdef WITH_PROFILE
261
      cinfo->master->start = getTime();
262
#endif
263
1.05M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
264
        /* Suspension forced; update state counters and exit */
265
0
        coef->MCU_vert_offset = yoffset;
266
0
        coef->MCU_ctr = MCU_col_num;
267
#ifdef WITH_PROFILE
268
        cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
269
        cinfo->master->entropy_mcoeffs +=
270
          (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
271
#endif
272
0
        return JPEG_SUSPENDED;
273
0
      }
274
#ifdef WITH_PROFILE
275
      cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
276
      cinfo->master->entropy_mcoeffs +=
277
        (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
278
#endif
279
1.05M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
37.5k
    coef->MCU_ctr = 0;
282
37.5k
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
22.0k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
21.1k
    start_iMCU_row(cinfo);
286
21.1k
    return JPEG_ROW_COMPLETED;
287
21.1k
  }
288
  /* Completed the scan */
289
846
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
846
  return JPEG_SCAN_COMPLETED;
291
22.0k
}
292
293
294
/*
295
 * Decompress and return some data in the multi-pass case.
296
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
297
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
298
 *
299
 * NB: output_buf contains a plane for each component in image.
300
 */
301
302
METHODDEF(int)
303
decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
304
9.51k
{
305
9.51k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
9.51k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
9.51k
  JDIMENSION block_num;
308
9.51k
  int ci, block_row, block_rows;
309
9.51k
  JBLOCKARRAY buffer;
310
9.51k
  JBLOCKROW buffer_ptr;
311
9.51k
  _JSAMPARRAY output_ptr;
312
9.51k
  JDIMENSION output_col;
313
9.51k
  jpeg_component_info *compptr;
314
9.51k
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
9.51k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
9.51k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
9.51k
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
320
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
321
0
      return JPEG_SUSPENDED;
322
0
  }
323
324
  /* OK, output from the virtual arrays. */
325
24.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
14.4k
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
14.4k
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
14.4k
    buffer = (*cinfo->mem->access_virt_barray)
332
14.4k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
14.4k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
14.4k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
14.4k
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
14.1k
      block_rows = compptr->v_samp_factor;
338
298
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
298
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
298
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
298
    }
343
14.4k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
14.4k
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
32.8k
    for (block_row = 0; block_row < block_rows; block_row++) {
347
18.3k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
18.3k
      output_col = 0;
349
18.3k
      for (block_num = cinfo->master->first_MCU_col[ci];
350
190k
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
171k
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
171k
                        output_col);
356
#ifdef WITH_PROFILE
357
        cinfo->master->idct_elapsed += getTime() - cinfo->master->start;
358
        cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
359
#endif
360
171k
        buffer_ptr++;
361
171k
        output_col += compptr->_DCT_scaled_size;
362
171k
      }
363
18.3k
      output_ptr += compptr->_DCT_scaled_size;
364
18.3k
    }
365
14.4k
  }
366
367
9.51k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
9.39k
    return JPEG_ROW_COMPLETED;
369
115
  return JPEG_SCAN_COMPLETED;
370
9.51k
}
jdcoefct-8.c:decompress_data
Line
Count
Source
304
9.51k
{
305
9.51k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
9.51k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
9.51k
  JDIMENSION block_num;
308
9.51k
  int ci, block_row, block_rows;
309
9.51k
  JBLOCKARRAY buffer;
310
9.51k
  JBLOCKROW buffer_ptr;
311
9.51k
  _JSAMPARRAY output_ptr;
312
9.51k
  JDIMENSION output_col;
313
9.51k
  jpeg_component_info *compptr;
314
9.51k
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
9.51k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
9.51k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
9.51k
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
320
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
321
0
      return JPEG_SUSPENDED;
322
0
  }
323
324
  /* OK, output from the virtual arrays. */
325
24.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
14.4k
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
14.4k
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
14.4k
    buffer = (*cinfo->mem->access_virt_barray)
332
14.4k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
14.4k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
14.4k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
14.4k
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
14.1k
      block_rows = compptr->v_samp_factor;
338
298
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
298
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
298
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
298
    }
343
14.4k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
14.4k
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
32.8k
    for (block_row = 0; block_row < block_rows; block_row++) {
347
18.3k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
18.3k
      output_col = 0;
349
18.3k
      for (block_num = cinfo->master->first_MCU_col[ci];
350
190k
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
171k
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
171k
                        output_col);
356
#ifdef WITH_PROFILE
357
        cinfo->master->idct_elapsed += getTime() - cinfo->master->start;
358
        cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
359
#endif
360
171k
        buffer_ptr++;
361
171k
        output_col += compptr->_DCT_scaled_size;
362
171k
      }
363
18.3k
      output_ptr += compptr->_DCT_scaled_size;
364
18.3k
    }
365
14.4k
  }
366
367
9.51k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
9.39k
    return JPEG_ROW_COMPLETED;
369
115
  return JPEG_SCAN_COMPLETED;
370
9.51k
}
Unexecuted instantiation: jdcoefct-12.c:decompress_data
371
372
#endif /* D_MULTISCAN_FILES_SUPPORTED */
373
374
375
#ifdef BLOCK_SMOOTHING_SUPPORTED
376
377
/*
378
 * This code applies interblock smoothing; the first 9 AC coefficients are
379
 * estimated from the DC values of a DCT block and its 24 neighboring blocks.
380
 * We apply smoothing only for progressive JPEG decoding, and only if
381
 * the coefficients it can estimate are not yet known to full precision.
382
 */
383
384
/* Natural-order array positions of the first 9 zigzag-order coefficients */
385
29.3k
#define Q01_POS  1
386
29.3k
#define Q10_POS  8
387
29.3k
#define Q20_POS  16
388
29.3k
#define Q11_POS  9
389
29.3k
#define Q02_POS  2
390
25.5k
#define Q03_POS  3
391
25.5k
#define Q12_POS  10
392
25.5k
#define Q21_POS  17
393
25.4k
#define Q30_POS  24
394
395
/*
396
 * Determine whether block smoothing is applicable and safe.
397
 * We also latch the current states of the coef_bits[] entries for the
398
 * AC coefficients; otherwise, if the input side of the decompressor
399
 * advances into a new scan, we might think the coefficients are known
400
 * more accurately than they really are.
401
 */
402
403
LOCAL(boolean)
404
smoothing_ok(j_decompress_ptr cinfo)
405
489
{
406
489
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
489
  boolean smoothing_useful = FALSE;
408
489
  int ci, coefi;
409
489
  jpeg_component_info *compptr;
410
489
  JQUANT_TBL *qtable;
411
489
  int *coef_bits, *prev_coef_bits;
412
489
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
489
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
12
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
477
  if (coef->coef_bits_latch == NULL)
419
477
    coef->coef_bits_latch = (int *)
420
477
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
477
                                  cinfo->num_components * 2 *
422
477
                                  (SAVED_COEFS * sizeof(int)));
423
477
  coef_bits_latch = coef->coef_bits_latch;
424
477
  prev_coef_bits_latch =
425
477
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
1.29k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
953
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
953
    if ((qtable = compptr->quant_table) == NULL)
431
5
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
948
    if (qtable->quantval[0] == 0 ||
434
922
        qtable->quantval[Q01_POS] == 0 ||
435
919
        qtable->quantval[Q10_POS] == 0 ||
436
906
        qtable->quantval[Q20_POS] == 0 ||
437
898
        qtable->quantval[Q11_POS] == 0 ||
438
887
        qtable->quantval[Q02_POS] == 0 ||
439
885
        qtable->quantval[Q03_POS] == 0 ||
440
866
        qtable->quantval[Q12_POS] == 0 ||
441
854
        qtable->quantval[Q21_POS] == 0 ||
442
839
        qtable->quantval[Q30_POS] == 0)
443
131
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
817
    coef_bits = cinfo->coef_bits[ci];
446
817
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
817
    if (coef_bits[0] < 0)
448
0
      return FALSE;
449
817
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
8.17k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
7.35k
      if (cinfo->input_scan_number > 1)
453
5.20k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
2.15k
      else
455
2.15k
        prev_coef_bits_latch[coefi] = -1;
456
7.35k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
7.35k
      if (coef_bits[coefi] != 0)
458
6.08k
        smoothing_useful = TRUE;
459
7.35k
    }
460
817
    coef_bits_latch += SAVED_COEFS;
461
817
    prev_coef_bits_latch += SAVED_COEFS;
462
817
  }
463
464
341
  return smoothing_useful;
465
477
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
405
391
{
406
391
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
391
  boolean smoothing_useful = FALSE;
408
391
  int ci, coefi;
409
391
  jpeg_component_info *compptr;
410
391
  JQUANT_TBL *qtable;
411
391
  int *coef_bits, *prev_coef_bits;
412
391
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
391
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
11
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
380
  if (coef->coef_bits_latch == NULL)
419
380
    coef->coef_bits_latch = (int *)
420
380
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
380
                                  cinfo->num_components * 2 *
422
380
                                  (SAVED_COEFS * sizeof(int)));
423
380
  coef_bits_latch = coef->coef_bits_latch;
424
380
  prev_coef_bits_latch =
425
380
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
1.10k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
796
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
796
    if ((qtable = compptr->quant_table) == NULL)
431
4
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
792
    if (qtable->quantval[0] == 0 ||
434
784
        qtable->quantval[Q01_POS] == 0 ||
435
782
        qtable->quantval[Q10_POS] == 0 ||
436
781
        qtable->quantval[Q20_POS] == 0 ||
437
779
        qtable->quantval[Q11_POS] == 0 ||
438
769
        qtable->quantval[Q02_POS] == 0 ||
439
768
        qtable->quantval[Q03_POS] == 0 ||
440
760
        qtable->quantval[Q12_POS] == 0 ||
441
751
        qtable->quantval[Q21_POS] == 0 ||
442
743
        qtable->quantval[Q30_POS] == 0)
443
64
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
728
    coef_bits = cinfo->coef_bits[ci];
446
728
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
728
    if (coef_bits[0] < 0)
448
0
      return FALSE;
449
728
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
7.28k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
6.55k
      if (cinfo->input_scan_number > 1)
453
4.86k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
1.69k
      else
455
1.69k
        prev_coef_bits_latch[coefi] = -1;
456
6.55k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
6.55k
      if (coef_bits[coefi] != 0)
458
5.35k
        smoothing_useful = TRUE;
459
6.55k
    }
460
728
    coef_bits_latch += SAVED_COEFS;
461
728
    prev_coef_bits_latch += SAVED_COEFS;
462
728
  }
463
464
312
  return smoothing_useful;
465
380
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
405
98
{
406
98
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
98
  boolean smoothing_useful = FALSE;
408
98
  int ci, coefi;
409
98
  jpeg_component_info *compptr;
410
98
  JQUANT_TBL *qtable;
411
98
  int *coef_bits, *prev_coef_bits;
412
98
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
98
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
1
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
97
  if (coef->coef_bits_latch == NULL)
419
97
    coef->coef_bits_latch = (int *)
420
97
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
97
                                  cinfo->num_components * 2 *
422
97
                                  (SAVED_COEFS * sizeof(int)));
423
97
  coef_bits_latch = coef->coef_bits_latch;
424
97
  prev_coef_bits_latch =
425
97
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
186
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
157
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
157
    if ((qtable = compptr->quant_table) == NULL)
431
1
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
156
    if (qtable->quantval[0] == 0 ||
434
138
        qtable->quantval[Q01_POS] == 0 ||
435
137
        qtable->quantval[Q10_POS] == 0 ||
436
125
        qtable->quantval[Q20_POS] == 0 ||
437
119
        qtable->quantval[Q11_POS] == 0 ||
438
118
        qtable->quantval[Q02_POS] == 0 ||
439
117
        qtable->quantval[Q03_POS] == 0 ||
440
106
        qtable->quantval[Q12_POS] == 0 ||
441
103
        qtable->quantval[Q21_POS] == 0 ||
442
96
        qtable->quantval[Q30_POS] == 0)
443
67
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
89
    coef_bits = cinfo->coef_bits[ci];
446
89
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
89
    if (coef_bits[0] < 0)
448
0
      return FALSE;
449
89
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
890
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
801
      if (cinfo->input_scan_number > 1)
453
342
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
459
      else
455
459
        prev_coef_bits_latch[coefi] = -1;
456
801
      coef_bits_latch[coefi] = coef_bits[coefi];
457
801
      if (coef_bits[coefi] != 0)
458
731
        smoothing_useful = TRUE;
459
801
    }
460
89
    coef_bits_latch += SAVED_COEFS;
461
89
    prev_coef_bits_latch += SAVED_COEFS;
462
89
  }
463
464
29
  return smoothing_useful;
465
97
}
466
467
468
/*
469
 * Variant of decompress_data for use when doing block smoothing.
470
 */
471
472
METHODDEF(int)
473
decompress_smooth_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
474
10.9k
{
475
10.9k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
10.9k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
10.9k
  JDIMENSION block_num, last_block_column;
478
10.9k
  int ci, block_row, block_rows, access_rows, image_block_row,
479
10.9k
    image_block_rows;
480
10.9k
  JBLOCKARRAY buffer;
481
10.9k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
10.9k
  JBLOCKROW next_block_row, next_next_block_row;
483
10.9k
  _JSAMPARRAY output_ptr;
484
10.9k
  JDIMENSION output_col;
485
10.9k
  jpeg_component_info *compptr;
486
10.9k
  _inverse_DCT_method_ptr inverse_DCT;
487
10.9k
  boolean change_dc;
488
10.9k
  JCOEF *workspace;
489
10.9k
  int *coef_bits;
490
10.9k
  JQUANT_TBL *quanttbl;
491
10.9k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
10.9k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
10.9k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
10.9k
      DC25;
495
10.9k
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
10.9k
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
10.9k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
10.9k
         !cinfo->inputctl->eoi_reached) {
503
0
    if (cinfo->input_scan_number == cinfo->output_scan_number) {
504
      /* If input is working on current scan, we ordinarily want it to
505
       * have completed the current row.  But if input scan is DC,
506
       * we want it to keep two rows ahead so that next two block rows' DC
507
       * values are up to date.
508
       */
509
0
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
510
0
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
511
0
        break;
512
0
    }
513
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
514
0
      return JPEG_SUSPENDED;
515
0
  }
516
517
  /* OK, output from the virtual arrays. */
518
39.4k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
28.4k
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
28.4k
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
28.4k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
27.3k
      block_rows = compptr->v_samp_factor;
526
27.3k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
27.3k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
450
      block_rows = compptr->v_samp_factor;
529
450
      access_rows = block_rows * 2; /* this and next iMCU row */
530
606
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
606
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
606
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
606
      access_rows = block_rows; /* this iMCU row only */
535
606
    }
536
    /* Align the virtual buffer for this component. */
537
28.4k
    if (cinfo->output_iMCU_row > 1) {
538
27.3k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
27.3k
      buffer = (*cinfo->mem->access_virt_barray)
540
27.3k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
27.3k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
27.3k
         (JDIMENSION)access_rows, FALSE);
543
27.3k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
27.3k
    } else if (cinfo->output_iMCU_row > 0) {
545
450
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
450
      buffer = (*cinfo->mem->access_virt_barray)
547
450
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
450
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
450
         (JDIMENSION)access_rows, FALSE);
550
450
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
606
    } else {
552
606
      buffer = (*cinfo->mem->access_virt_barray)
553
606
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
606
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
606
    }
556
    /* Fetch component-dependent info.
557
     * If the current scan is incomplete, then we use the component-dependent
558
     * info from the previous scan.
559
     */
560
28.4k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
561
0
      coef_bits =
562
0
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
563
28.4k
    else
564
28.4k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
565
566
    /* We only do DC interpolation if no AC coefficient data is available. */
567
28.4k
    change_dc =
568
28.4k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
26.2k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
25.3k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
28.4k
    quanttbl = compptr->quant_table;
573
28.4k
    Q00 = quanttbl->quantval[0];
574
28.4k
    Q01 = quanttbl->quantval[Q01_POS];
575
28.4k
    Q10 = quanttbl->quantval[Q10_POS];
576
28.4k
    Q20 = quanttbl->quantval[Q20_POS];
577
28.4k
    Q11 = quanttbl->quantval[Q11_POS];
578
28.4k
    Q02 = quanttbl->quantval[Q02_POS];
579
28.4k
    if (change_dc) {
580
24.6k
      Q03 = quanttbl->quantval[Q03_POS];
581
24.6k
      Q12 = quanttbl->quantval[Q12_POS];
582
24.6k
      Q21 = quanttbl->quantval[Q21_POS];
583
24.6k
      Q30 = quanttbl->quantval[Q30_POS];
584
24.6k
    }
585
28.4k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
28.4k
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
28.4k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
67.3k
    for (block_row = 0; block_row < block_rows; block_row++) {
590
38.8k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
38.8k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
38.8k
      if (image_block_row > 0)
594
38.2k
        prev_block_row =
595
38.2k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
606
      else
597
606
        prev_block_row = buffer_ptr;
598
599
38.8k
      if (image_block_row > 1)
600
37.7k
        prev_prev_block_row =
601
37.7k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
1.08k
      else
603
1.08k
        prev_prev_block_row = prev_block_row;
604
605
38.8k
      if (image_block_row < image_block_rows - 1)
606
38.2k
        next_block_row =
607
38.2k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
606
      else
609
606
        next_block_row = buffer_ptr;
610
611
38.8k
      if (image_block_row < image_block_rows - 2)
612
37.9k
        next_next_block_row =
613
37.9k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
950
      else
615
950
        next_next_block_row = next_block_row;
616
617
      /* We fetch the surrounding DC values using a sliding-register approach.
618
       * Initialize all 25 here so as to do the right thing on narrow pics.
619
       */
620
38.8k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
38.8k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
38.8k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
38.8k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
38.8k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
38.8k
      output_col = 0;
626
38.8k
      last_block_column = compptr->width_in_blocks - 1;
627
38.8k
      for (block_num = cinfo->master->first_MCU_col[ci];
628
659k
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
620k
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
620k
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
38.8k
            block_num < last_block_column) {
634
24.5k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
24.5k
          DC09 = DC10 = (int)prev_block_row[1][0];
636
24.5k
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
24.5k
          DC19 = DC20 = (int)next_block_row[1][0];
638
24.5k
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
24.5k
        }
640
620k
        if (block_num + 1 < last_block_column) {
641
557k
          DC05 = (int)prev_prev_block_row[2][0];
642
557k
          DC10 = (int)prev_block_row[2][0];
643
557k
          DC15 = (int)buffer_ptr[2][0];
644
557k
          DC20 = (int)next_block_row[2][0];
645
557k
          DC25 = (int)next_next_block_row[2][0];
646
557k
        }
647
        /* If DC interpolation is enabled, compute coefficient estimates using
648
         * a Gaussian-like kernel, keeping the averages of the DC values.
649
         *
650
         * If DC interpolation is disabled, compute coefficient estimates using
651
         * an algorithm similar to the one described in Section K.8 of the JPEG
652
         * standard, except applied to a 5x5 window rather than a 3x3 window.
653
         *
654
         * An estimate is applied only if the coefficient is still zero and is
655
         * not known to be fully accurate.
656
         */
657
        /* AC01 */
658
620k
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
592k
          num = Q00 * (change_dc ?
660
418k
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
418k
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
418k
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
418k
                 DC21 - DC22 + DC24 + DC25) :
664
592k
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
592k
          if (num >= 0) {
666
377k
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
377k
            if (Al > 0 && pred >= (1 << Al))
668
4.14k
              pred = (1 << Al) - 1;
669
377k
          } else {
670
214k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
214k
            if (Al > 0 && pred >= (1 << Al))
672
4.53k
              pred = (1 << Al) - 1;
673
214k
            pred = -pred;
674
214k
          }
675
592k
          workspace[1] = (JCOEF)pred;
676
592k
        }
677
        /* AC10 */
678
620k
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
580k
          num = Q00 * (change_dc ?
680
418k
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
418k
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
418k
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
418k
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
580k
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
580k
          if (num >= 0) {
686
427k
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
427k
            if (Al > 0 && pred >= (1 << Al))
688
26.7k
              pred = (1 << Al) - 1;
689
427k
          } else {
690
153k
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
153k
            if (Al > 0 && pred >= (1 << Al))
692
11.0k
              pred = (1 << Al) - 1;
693
153k
            pred = -pred;
694
153k
          }
695
580k
          workspace[8] = (JCOEF)pred;
696
580k
        }
697
        /* AC20 */
698
620k
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
591k
          num = Q00 * (change_dc ?
700
418k
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
418k
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
591k
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
591k
          if (num >= 0) {
704
362k
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
362k
            if (Al > 0 && pred >= (1 << Al))
706
13.6k
              pred = (1 << Al) - 1;
707
362k
          } else {
708
228k
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
228k
            if (Al > 0 && pred >= (1 << Al))
710
14.8k
              pred = (1 << Al) - 1;
711
228k
            pred = -pred;
712
228k
          }
713
591k
          workspace[16] = (JCOEF)pred;
714
591k
        }
715
        /* AC11 */
716
620k
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
582k
          num = Q00 * (change_dc ?
718
418k
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
418k
                 9 * DC19 + DC21 - DC25) :
720
582k
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
163k
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
582k
          if (num >= 0) {
723
410k
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
410k
            if (Al > 0 && pred >= (1 << Al))
725
1.85k
              pred = (1 << Al) - 1;
726
410k
          } else {
727
171k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
171k
            if (Al > 0 && pred >= (1 << Al))
729
1.83k
              pred = (1 << Al) - 1;
730
171k
            pred = -pred;
731
171k
          }
732
582k
          workspace[9] = (JCOEF)pred;
733
582k
        }
734
        /* AC02 */
735
620k
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
586k
          num = Q00 * (change_dc ?
737
418k
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
418k
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
586k
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
586k
          if (num >= 0) {
741
350k
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
350k
            if (Al > 0 && pred >= (1 << Al))
743
3.59k
              pred = (1 << Al) - 1;
744
350k
          } else {
745
235k
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
235k
            if (Al > 0 && pred >= (1 << Al))
747
3.63k
              pred = (1 << Al) - 1;
748
235k
            pred = -pred;
749
235k
          }
750
586k
          workspace[2] = (JCOEF)pred;
751
586k
        }
752
620k
        if (change_dc) {
753
          /* AC03 */
754
418k
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
418k
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
418k
            if (num >= 0) {
757
287k
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
287k
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
287k
            } else {
761
131k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
131k
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
131k
              pred = -pred;
765
131k
            }
766
418k
            workspace[3] = (JCOEF)pred;
767
418k
          }
768
          /* AC12 */
769
418k
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
418k
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
418k
            if (num >= 0) {
772
252k
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
252k
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
252k
            } else {
776
165k
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
165k
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
165k
              pred = -pred;
780
165k
            }
781
418k
            workspace[10] = (JCOEF)pred;
782
418k
          }
783
          /* AC21 */
784
418k
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
418k
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
418k
            if (num >= 0) {
787
239k
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
239k
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
239k
            } else {
791
179k
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
179k
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
179k
              pred = -pred;
795
179k
            }
796
418k
            workspace[17] = (JCOEF)pred;
797
418k
          }
798
          /* AC30 */
799
418k
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
418k
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
418k
            if (num >= 0) {
802
313k
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
313k
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
313k
            } else {
806
104k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
104k
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
104k
              pred = -pred;
810
104k
            }
811
418k
            workspace[24] = (JCOEF)pred;
812
418k
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
418k
          num = Q00 *
817
418k
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
418k
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
418k
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
418k
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
418k
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
418k
          if (num >= 0) {
823
178k
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
240k
          } else {
825
240k
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
240k
            pred = -pred;
827
240k
          }
828
418k
          workspace[0] = (JCOEF)pred;
829
418k
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
620k
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
620k
                        output_col);
837
#ifdef WITH_PROFILE
838
        cinfo->master->idct_elapsed += getTime() - cinfo->master->start;
839
        cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
840
#endif
841
        /* Advance for next column */
842
620k
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
620k
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
620k
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
620k
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
620k
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
620k
        buffer_ptr++, prev_block_row++, next_block_row++,
848
620k
          prev_prev_block_row++, next_next_block_row++;
849
620k
        output_col += compptr->_DCT_scaled_size;
850
620k
      }
851
38.8k
      output_ptr += compptr->_DCT_scaled_size;
852
38.8k
    }
853
28.4k
  }
854
855
10.9k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
10.7k
    return JPEG_ROW_COMPLETED;
857
276
  return JPEG_SCAN_COMPLETED;
858
10.9k
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
474
10.9k
{
475
10.9k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
10.9k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
10.9k
  JDIMENSION block_num, last_block_column;
478
10.9k
  int ci, block_row, block_rows, access_rows, image_block_row,
479
10.9k
    image_block_rows;
480
10.9k
  JBLOCKARRAY buffer;
481
10.9k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
10.9k
  JBLOCKROW next_block_row, next_next_block_row;
483
10.9k
  _JSAMPARRAY output_ptr;
484
10.9k
  JDIMENSION output_col;
485
10.9k
  jpeg_component_info *compptr;
486
10.9k
  _inverse_DCT_method_ptr inverse_DCT;
487
10.9k
  boolean change_dc;
488
10.9k
  JCOEF *workspace;
489
10.9k
  int *coef_bits;
490
10.9k
  JQUANT_TBL *quanttbl;
491
10.9k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
10.9k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
10.9k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
10.9k
      DC25;
495
10.9k
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
10.9k
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
10.9k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
10.9k
         !cinfo->inputctl->eoi_reached) {
503
0
    if (cinfo->input_scan_number == cinfo->output_scan_number) {
504
      /* If input is working on current scan, we ordinarily want it to
505
       * have completed the current row.  But if input scan is DC,
506
       * we want it to keep two rows ahead so that next two block rows' DC
507
       * values are up to date.
508
       */
509
0
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
510
0
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
511
0
        break;
512
0
    }
513
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
514
0
      return JPEG_SUSPENDED;
515
0
  }
516
517
  /* OK, output from the virtual arrays. */
518
39.4k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
28.4k
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
28.4k
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
28.4k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
27.3k
      block_rows = compptr->v_samp_factor;
526
27.3k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
27.3k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
450
      block_rows = compptr->v_samp_factor;
529
450
      access_rows = block_rows * 2; /* this and next iMCU row */
530
606
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
606
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
606
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
606
      access_rows = block_rows; /* this iMCU row only */
535
606
    }
536
    /* Align the virtual buffer for this component. */
537
28.4k
    if (cinfo->output_iMCU_row > 1) {
538
27.3k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
27.3k
      buffer = (*cinfo->mem->access_virt_barray)
540
27.3k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
27.3k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
27.3k
         (JDIMENSION)access_rows, FALSE);
543
27.3k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
27.3k
    } else if (cinfo->output_iMCU_row > 0) {
545
450
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
450
      buffer = (*cinfo->mem->access_virt_barray)
547
450
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
450
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
450
         (JDIMENSION)access_rows, FALSE);
550
450
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
606
    } else {
552
606
      buffer = (*cinfo->mem->access_virt_barray)
553
606
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
606
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
606
    }
556
    /* Fetch component-dependent info.
557
     * If the current scan is incomplete, then we use the component-dependent
558
     * info from the previous scan.
559
     */
560
28.4k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
561
0
      coef_bits =
562
0
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
563
28.4k
    else
564
28.4k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
565
566
    /* We only do DC interpolation if no AC coefficient data is available. */
567
28.4k
    change_dc =
568
28.4k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
26.2k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
25.3k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
28.4k
    quanttbl = compptr->quant_table;
573
28.4k
    Q00 = quanttbl->quantval[0];
574
28.4k
    Q01 = quanttbl->quantval[Q01_POS];
575
28.4k
    Q10 = quanttbl->quantval[Q10_POS];
576
28.4k
    Q20 = quanttbl->quantval[Q20_POS];
577
28.4k
    Q11 = quanttbl->quantval[Q11_POS];
578
28.4k
    Q02 = quanttbl->quantval[Q02_POS];
579
28.4k
    if (change_dc) {
580
24.6k
      Q03 = quanttbl->quantval[Q03_POS];
581
24.6k
      Q12 = quanttbl->quantval[Q12_POS];
582
24.6k
      Q21 = quanttbl->quantval[Q21_POS];
583
24.6k
      Q30 = quanttbl->quantval[Q30_POS];
584
24.6k
    }
585
28.4k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
28.4k
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
28.4k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
67.3k
    for (block_row = 0; block_row < block_rows; block_row++) {
590
38.8k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
38.8k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
38.8k
      if (image_block_row > 0)
594
38.2k
        prev_block_row =
595
38.2k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
606
      else
597
606
        prev_block_row = buffer_ptr;
598
599
38.8k
      if (image_block_row > 1)
600
37.7k
        prev_prev_block_row =
601
37.7k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
1.08k
      else
603
1.08k
        prev_prev_block_row = prev_block_row;
604
605
38.8k
      if (image_block_row < image_block_rows - 1)
606
38.2k
        next_block_row =
607
38.2k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
606
      else
609
606
        next_block_row = buffer_ptr;
610
611
38.8k
      if (image_block_row < image_block_rows - 2)
612
37.9k
        next_next_block_row =
613
37.9k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
950
      else
615
950
        next_next_block_row = next_block_row;
616
617
      /* We fetch the surrounding DC values using a sliding-register approach.
618
       * Initialize all 25 here so as to do the right thing on narrow pics.
619
       */
620
38.8k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
38.8k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
38.8k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
38.8k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
38.8k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
38.8k
      output_col = 0;
626
38.8k
      last_block_column = compptr->width_in_blocks - 1;
627
38.8k
      for (block_num = cinfo->master->first_MCU_col[ci];
628
659k
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
620k
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
620k
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
38.8k
            block_num < last_block_column) {
634
24.5k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
24.5k
          DC09 = DC10 = (int)prev_block_row[1][0];
636
24.5k
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
24.5k
          DC19 = DC20 = (int)next_block_row[1][0];
638
24.5k
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
24.5k
        }
640
620k
        if (block_num + 1 < last_block_column) {
641
557k
          DC05 = (int)prev_prev_block_row[2][0];
642
557k
          DC10 = (int)prev_block_row[2][0];
643
557k
          DC15 = (int)buffer_ptr[2][0];
644
557k
          DC20 = (int)next_block_row[2][0];
645
557k
          DC25 = (int)next_next_block_row[2][0];
646
557k
        }
647
        /* If DC interpolation is enabled, compute coefficient estimates using
648
         * a Gaussian-like kernel, keeping the averages of the DC values.
649
         *
650
         * If DC interpolation is disabled, compute coefficient estimates using
651
         * an algorithm similar to the one described in Section K.8 of the JPEG
652
         * standard, except applied to a 5x5 window rather than a 3x3 window.
653
         *
654
         * An estimate is applied only if the coefficient is still zero and is
655
         * not known to be fully accurate.
656
         */
657
        /* AC01 */
658
620k
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
592k
          num = Q00 * (change_dc ?
660
418k
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
418k
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
418k
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
418k
                 DC21 - DC22 + DC24 + DC25) :
664
592k
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
592k
          if (num >= 0) {
666
377k
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
377k
            if (Al > 0 && pred >= (1 << Al))
668
4.14k
              pred = (1 << Al) - 1;
669
377k
          } else {
670
214k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
214k
            if (Al > 0 && pred >= (1 << Al))
672
4.53k
              pred = (1 << Al) - 1;
673
214k
            pred = -pred;
674
214k
          }
675
592k
          workspace[1] = (JCOEF)pred;
676
592k
        }
677
        /* AC10 */
678
620k
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
580k
          num = Q00 * (change_dc ?
680
418k
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
418k
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
418k
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
418k
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
580k
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
580k
          if (num >= 0) {
686
427k
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
427k
            if (Al > 0 && pred >= (1 << Al))
688
26.7k
              pred = (1 << Al) - 1;
689
427k
          } else {
690
153k
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
153k
            if (Al > 0 && pred >= (1 << Al))
692
11.0k
              pred = (1 << Al) - 1;
693
153k
            pred = -pred;
694
153k
          }
695
580k
          workspace[8] = (JCOEF)pred;
696
580k
        }
697
        /* AC20 */
698
620k
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
591k
          num = Q00 * (change_dc ?
700
418k
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
418k
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
591k
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
591k
          if (num >= 0) {
704
362k
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
362k
            if (Al > 0 && pred >= (1 << Al))
706
13.6k
              pred = (1 << Al) - 1;
707
362k
          } else {
708
228k
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
228k
            if (Al > 0 && pred >= (1 << Al))
710
14.8k
              pred = (1 << Al) - 1;
711
228k
            pred = -pred;
712
228k
          }
713
591k
          workspace[16] = (JCOEF)pred;
714
591k
        }
715
        /* AC11 */
716
620k
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
582k
          num = Q00 * (change_dc ?
718
418k
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
418k
                 9 * DC19 + DC21 - DC25) :
720
582k
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
163k
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
582k
          if (num >= 0) {
723
410k
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
410k
            if (Al > 0 && pred >= (1 << Al))
725
1.85k
              pred = (1 << Al) - 1;
726
410k
          } else {
727
171k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
171k
            if (Al > 0 && pred >= (1 << Al))
729
1.83k
              pred = (1 << Al) - 1;
730
171k
            pred = -pred;
731
171k
          }
732
582k
          workspace[9] = (JCOEF)pred;
733
582k
        }
734
        /* AC02 */
735
620k
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
586k
          num = Q00 * (change_dc ?
737
418k
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
418k
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
586k
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
586k
          if (num >= 0) {
741
350k
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
350k
            if (Al > 0 && pred >= (1 << Al))
743
3.59k
              pred = (1 << Al) - 1;
744
350k
          } else {
745
235k
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
235k
            if (Al > 0 && pred >= (1 << Al))
747
3.63k
              pred = (1 << Al) - 1;
748
235k
            pred = -pred;
749
235k
          }
750
586k
          workspace[2] = (JCOEF)pred;
751
586k
        }
752
620k
        if (change_dc) {
753
          /* AC03 */
754
418k
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
418k
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
418k
            if (num >= 0) {
757
287k
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
287k
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
287k
            } else {
761
131k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
131k
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
131k
              pred = -pred;
765
131k
            }
766
418k
            workspace[3] = (JCOEF)pred;
767
418k
          }
768
          /* AC12 */
769
418k
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
418k
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
418k
            if (num >= 0) {
772
252k
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
252k
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
252k
            } else {
776
165k
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
165k
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
165k
              pred = -pred;
780
165k
            }
781
418k
            workspace[10] = (JCOEF)pred;
782
418k
          }
783
          /* AC21 */
784
418k
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
418k
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
418k
            if (num >= 0) {
787
239k
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
239k
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
239k
            } else {
791
179k
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
179k
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
179k
              pred = -pred;
795
179k
            }
796
418k
            workspace[17] = (JCOEF)pred;
797
418k
          }
798
          /* AC30 */
799
418k
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
418k
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
418k
            if (num >= 0) {
802
313k
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
313k
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
313k
            } else {
806
104k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
104k
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
104k
              pred = -pred;
810
104k
            }
811
418k
            workspace[24] = (JCOEF)pred;
812
418k
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
418k
          num = Q00 *
817
418k
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
418k
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
418k
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
418k
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
418k
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
418k
          if (num >= 0) {
823
178k
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
240k
          } else {
825
240k
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
240k
            pred = -pred;
827
240k
          }
828
418k
          workspace[0] = (JCOEF)pred;
829
418k
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
620k
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
620k
                        output_col);
837
#ifdef WITH_PROFILE
838
        cinfo->master->idct_elapsed += getTime() - cinfo->master->start;
839
        cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
840
#endif
841
        /* Advance for next column */
842
620k
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
620k
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
620k
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
620k
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
620k
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
620k
        buffer_ptr++, prev_block_row++, next_block_row++,
848
620k
          prev_prev_block_row++, next_next_block_row++;
849
620k
        output_col += compptr->_DCT_scaled_size;
850
620k
      }
851
38.8k
      output_ptr += compptr->_DCT_scaled_size;
852
38.8k
    }
853
28.4k
  }
854
855
10.9k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
10.7k
    return JPEG_ROW_COMPLETED;
857
276
  return JPEG_SCAN_COMPLETED;
858
10.9k
}
Unexecuted instantiation: jdcoefct-12.c:decompress_smooth_data
859
860
#endif /* BLOCK_SMOOTHING_SUPPORTED */
861
862
863
/*
864
 * Initialize coefficient buffer controller.
865
 */
866
867
GLOBAL(void)
868
_jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
869
3.11k
{
870
3.11k
  my_coef_ptr coef;
871
872
3.11k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
3.11k
  coef = (my_coef_ptr)
876
3.11k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
3.11k
                                sizeof(my_coef_controller));
878
3.11k
  memset(coef, 0, sizeof(my_coef_controller));
879
3.11k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
3.11k
  coef->pub.start_input_pass = start_input_pass;
881
3.11k
  coef->pub.start_output_pass = start_output_pass;
882
3.11k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
3.11k
  coef->coef_bits_latch = NULL;
884
3.11k
#endif
885
886
  /* Create the coefficient buffer. */
887
3.11k
  if (need_full_buffer) {
888
1.58k
#ifdef D_MULTISCAN_FILES_SUPPORTED
889
    /* Allocate a full-image virtual array for each component, */
890
    /* padded to a multiple of samp_factor DCT blocks in each direction. */
891
    /* Note we ask for a pre-zeroed array. */
892
1.58k
    int ci, access_rows;
893
1.58k
    jpeg_component_info *compptr;
894
895
5.82k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
4.24k
         ci++, compptr++) {
897
4.24k
      access_rows = compptr->v_samp_factor;
898
4.24k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
4.24k
      if (cinfo->progressive_mode)
901
4.17k
        access_rows *= 5;
902
4.24k
#endif
903
4.24k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
4.24k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
4.24k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
4.24k
                               (long)compptr->h_samp_factor),
907
4.24k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
4.24k
                               (long)compptr->v_samp_factor),
909
4.24k
         (JDIMENSION)access_rows);
910
4.24k
    }
911
1.58k
    coef->pub.consume_data = consume_data;
912
1.58k
    coef->pub._decompress_data = decompress_data;
913
1.58k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
1.58k
  } else {
918
    /* We only need a single-MCU buffer. */
919
1.52k
    JBLOCKROW buffer;
920
1.52k
    int i;
921
922
1.52k
    buffer = (JBLOCKROW)
923
1.52k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
1.52k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
16.8k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
15.2k
      coef->MCU_buffer[i] = buffer + i;
927
15.2k
    }
928
1.52k
    coef->pub.consume_data = dummy_consume_data;
929
1.52k
    coef->pub._decompress_data = decompress_onepass;
930
1.52k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
1.52k
  }
932
933
  /* Allocate the workspace buffer */
934
3.11k
  coef->workspace = (JCOEF *)
935
3.11k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
3.11k
                                sizeof(JCOEF) * DCTSIZE2);
937
3.11k
}
jinit_d_coef_controller
Line
Count
Source
869
2.72k
{
870
2.72k
  my_coef_ptr coef;
871
872
2.72k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
2.72k
  coef = (my_coef_ptr)
876
2.72k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
2.72k
                                sizeof(my_coef_controller));
878
2.72k
  memset(coef, 0, sizeof(my_coef_controller));
879
2.72k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
2.72k
  coef->pub.start_input_pass = start_input_pass;
881
2.72k
  coef->pub.start_output_pass = start_output_pass;
882
2.72k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
2.72k
  coef->coef_bits_latch = NULL;
884
2.72k
#endif
885
886
  /* Create the coefficient buffer. */
887
2.72k
  if (need_full_buffer) {
888
1.20k
#ifdef D_MULTISCAN_FILES_SUPPORTED
889
    /* Allocate a full-image virtual array for each component, */
890
    /* padded to a multiple of samp_factor DCT blocks in each direction. */
891
    /* Note we ask for a pre-zeroed array. */
892
1.20k
    int ci, access_rows;
893
1.20k
    jpeg_component_info *compptr;
894
895
4.39k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
3.18k
         ci++, compptr++) {
897
3.18k
      access_rows = compptr->v_samp_factor;
898
3.18k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
3.18k
      if (cinfo->progressive_mode)
901
3.13k
        access_rows *= 5;
902
3.18k
#endif
903
3.18k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
3.18k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
3.18k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
3.18k
                               (long)compptr->h_samp_factor),
907
3.18k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
3.18k
                               (long)compptr->v_samp_factor),
909
3.18k
         (JDIMENSION)access_rows);
910
3.18k
    }
911
1.20k
    coef->pub.consume_data = consume_data;
912
1.20k
    coef->pub._decompress_data = decompress_data;
913
1.20k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
1.51k
  } else {
918
    /* We only need a single-MCU buffer. */
919
1.51k
    JBLOCKROW buffer;
920
1.51k
    int i;
921
922
1.51k
    buffer = (JBLOCKROW)
923
1.51k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
1.51k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
16.6k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
15.1k
      coef->MCU_buffer[i] = buffer + i;
927
15.1k
    }
928
1.51k
    coef->pub.consume_data = dummy_consume_data;
929
1.51k
    coef->pub._decompress_data = decompress_onepass;
930
1.51k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
1.51k
  }
932
933
  /* Allocate the workspace buffer */
934
2.72k
  coef->workspace = (JCOEF *)
935
2.72k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
2.72k
                                sizeof(JCOEF) * DCTSIZE2);
937
2.72k
}
j12init_d_coef_controller
Line
Count
Source
869
391
{
870
391
  my_coef_ptr coef;
871
872
391
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
391
  coef = (my_coef_ptr)
876
391
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
391
                                sizeof(my_coef_controller));
878
391
  memset(coef, 0, sizeof(my_coef_controller));
879
391
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
391
  coef->pub.start_input_pass = start_input_pass;
881
391
  coef->pub.start_output_pass = start_output_pass;
882
391
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
391
  coef->coef_bits_latch = NULL;
884
391
#endif
885
886
  /* Create the coefficient buffer. */
887
391
  if (need_full_buffer) {
888
376
#ifdef D_MULTISCAN_FILES_SUPPORTED
889
    /* Allocate a full-image virtual array for each component, */
890
    /* padded to a multiple of samp_factor DCT blocks in each direction. */
891
    /* Note we ask for a pre-zeroed array. */
892
376
    int ci, access_rows;
893
376
    jpeg_component_info *compptr;
894
895
1.43k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
1.06k
         ci++, compptr++) {
897
1.06k
      access_rows = compptr->v_samp_factor;
898
1.06k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
1.06k
      if (cinfo->progressive_mode)
901
1.03k
        access_rows *= 5;
902
1.06k
#endif
903
1.06k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
1.06k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
1.06k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
1.06k
                               (long)compptr->h_samp_factor),
907
1.06k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
1.06k
                               (long)compptr->v_samp_factor),
909
1.06k
         (JDIMENSION)access_rows);
910
1.06k
    }
911
376
    coef->pub.consume_data = consume_data;
912
376
    coef->pub._decompress_data = decompress_data;
913
376
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
376
  } else {
918
    /* We only need a single-MCU buffer. */
919
15
    JBLOCKROW buffer;
920
15
    int i;
921
922
15
    buffer = (JBLOCKROW)
923
15
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
15
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
165
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
150
      coef->MCU_buffer[i] = buffer + i;
927
150
    }
928
15
    coef->pub.consume_data = dummy_consume_data;
929
15
    coef->pub._decompress_data = decompress_onepass;
930
15
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
15
  }
932
933
  /* Allocate the workspace buffer */
934
391
  coef->workspace = (JCOEF *)
935
391
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
391
                                sizeof(JCOEF) * DCTSIZE2);
937
391
}