Coverage Report

Created: 2026-08-31 06:55

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
13.2k
{
51
13.2k
  cinfo->input_iMCU_row = 0;
52
13.2k
  start_iMCU_row(cinfo);
53
13.2k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
50
12.0k
{
51
12.0k
  cinfo->input_iMCU_row = 0;
52
12.0k
  start_iMCU_row(cinfo);
53
12.0k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
50
1.22k
{
51
1.22k
  cinfo->input_iMCU_row = 0;
52
1.22k
  start_iMCU_row(cinfo);
53
1.22k
}
54
55
56
/*
57
 * Initialize for an output processing pass.
58
 */
59
60
METHODDEF(void)
61
start_output_pass(j_decompress_ptr cinfo)
62
4.22k
{
63
4.22k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
4.22k
  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
4.22k
  if (coef->pub.coef_arrays != NULL) {
68
1.93k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
1.00k
      coef->pub._decompress_data = decompress_smooth_data;
70
929
    else
71
929
      coef->pub._decompress_data = decompress_data;
72
1.93k
  }
73
4.22k
#endif
74
4.22k
  cinfo->output_iMCU_row = 0;
75
4.22k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
62
4.01k
{
63
4.01k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
4.01k
  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
4.01k
  if (coef->pub.coef_arrays != NULL) {
68
1.73k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
912
      coef->pub._decompress_data = decompress_smooth_data;
70
825
    else
71
825
      coef->pub._decompress_data = decompress_data;
72
1.73k
  }
73
4.01k
#endif
74
4.01k
  cinfo->output_iMCU_row = 0;
75
4.01k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
62
211
{
63
211
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
211
  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
211
  if (coef->pub.coef_arrays != NULL) {
68
201
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
97
      coef->pub._decompress_data = decompress_smooth_data;
70
104
    else
71
104
      coef->pub._decompress_data = decompress_data;
72
201
  }
73
211
#endif
74
211
  cinfo->output_iMCU_row = 0;
75
211
}
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
50.9k
{
91
50.9k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
50.9k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
50.9k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
50.9k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
50.9k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
50.9k
  _JSAMPARRAY output_ptr;
97
50.9k
  JDIMENSION start_col, output_col;
98
50.9k
  jpeg_component_info *compptr;
99
50.9k
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
103k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
52.3k
       yoffset++) {
104
1.41M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
1.36M
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
1.36M
      jzero_far((void *)coef->MCU_buffer[0],
108
1.36M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
1.36M
      if (!cinfo->entropy->insufficient_data)
110
1.36M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
1.36M
      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
1.36M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
1.36M
          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
1.36M
        blkn = 0;               /* index of current DCT block within MCU */
142
4.80M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
3.44M
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
3.44M
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
3.44M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
3.44M
          useful_width = (MCU_col_num < last_MCU_col) ?
151
3.25M
                         compptr->MCU_width : compptr->last_col_width;
152
3.44M
          output_ptr = output_buf[compptr->component_index] +
153
3.44M
                       yoffset * compptr->_DCT_scaled_size;
154
3.44M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
3.44M
                      compptr->MCU_sample_width;
156
7.06M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
3.62M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
3.59M
                yoffset + yindex < compptr->last_row_height) {
159
3.59M
              output_col = start_col;
160
7.29M
              for (xindex = 0; xindex < useful_width; xindex++) {
161
#ifdef WITH_PROFILE
162
                cinfo->master->start = getTime();
163
#endif
164
3.69M
                (*inverse_DCT) (cinfo, compptr,
165
3.69M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
3.69M
                                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
3.69M
                output_col += compptr->_DCT_scaled_size;
173
3.69M
              }
174
3.59M
            }
175
3.62M
            blkn += compptr->MCU_width;
176
3.62M
            output_ptr += compptr->_DCT_scaled_size;
177
3.62M
          }
178
3.44M
        }
179
1.36M
      }
180
1.36M
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
52.3k
    coef->MCU_ctr = 0;
183
52.3k
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
50.9k
  cinfo->output_iMCU_row++;
186
50.9k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
48.6k
    start_iMCU_row(cinfo);
188
48.6k
    return JPEG_ROW_COMPLETED;
189
48.6k
  }
190
  /* Completed the scan */
191
2.27k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
2.27k
  return JPEG_SCAN_COMPLETED;
193
50.9k
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
90
50.9k
{
91
50.9k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
50.9k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
50.9k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
50.9k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
50.9k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
50.9k
  _JSAMPARRAY output_ptr;
97
50.9k
  JDIMENSION start_col, output_col;
98
50.9k
  jpeg_component_info *compptr;
99
50.9k
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
103k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
52.3k
       yoffset++) {
104
1.41M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
1.36M
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
1.36M
      jzero_far((void *)coef->MCU_buffer[0],
108
1.36M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
1.36M
      if (!cinfo->entropy->insufficient_data)
110
1.36M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
1.36M
      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
1.36M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
1.36M
          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
1.36M
        blkn = 0;               /* index of current DCT block within MCU */
142
4.80M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
3.44M
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
3.44M
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
3.44M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
3.44M
          useful_width = (MCU_col_num < last_MCU_col) ?
151
3.25M
                         compptr->MCU_width : compptr->last_col_width;
152
3.44M
          output_ptr = output_buf[compptr->component_index] +
153
3.44M
                       yoffset * compptr->_DCT_scaled_size;
154
3.44M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
3.44M
                      compptr->MCU_sample_width;
156
7.06M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
3.62M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
3.59M
                yoffset + yindex < compptr->last_row_height) {
159
3.59M
              output_col = start_col;
160
7.29M
              for (xindex = 0; xindex < useful_width; xindex++) {
161
#ifdef WITH_PROFILE
162
                cinfo->master->start = getTime();
163
#endif
164
3.69M
                (*inverse_DCT) (cinfo, compptr,
165
3.69M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
3.69M
                                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
3.69M
                output_col += compptr->_DCT_scaled_size;
173
3.69M
              }
174
3.59M
            }
175
3.62M
            blkn += compptr->MCU_width;
176
3.62M
            output_ptr += compptr->_DCT_scaled_size;
177
3.62M
          }
178
3.44M
        }
179
1.36M
      }
180
1.36M
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
52.3k
    coef->MCU_ctr = 0;
183
52.3k
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
50.9k
  cinfo->output_iMCU_row++;
186
50.9k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
48.6k
    start_iMCU_row(cinfo);
188
48.6k
    return JPEG_ROW_COMPLETED;
189
48.6k
  }
190
  /* Completed the scan */
191
2.27k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
2.27k
  return JPEG_SCAN_COMPLETED;
193
50.9k
}
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
992k
{
219
992k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
992k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
992k
  int blkn, ci, xindex, yindex, yoffset;
222
992k
  JDIMENSION start_col;
223
992k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
992k
  JBLOCKROW buffer_ptr;
225
992k
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
2.05M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
1.05M
    compptr = cinfo->cur_comp_info[ci];
230
1.05M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
1.05M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
1.05M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
1.05M
       (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
1.05M
  }
239
240
  /* Loop to process one whole iMCU row */
241
2.49M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
1.50M
       yoffset++) {
243
18.4M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
16.9M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
16.9M
      blkn = 0;                 /* index of current DCT block within MCU */
247
36.8M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
19.8M
        compptr = cinfo->cur_comp_info[ci];
249
19.8M
        start_col = MCU_col_num * compptr->MCU_width;
250
42.0M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
22.1M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
46.1M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
23.9M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
23.9M
          }
255
22.1M
        }
256
19.8M
      }
257
16.9M
      if (!cinfo->entropy->insufficient_data)
258
16.9M
        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
16.9M
      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
16.9M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
1.50M
    coef->MCU_ctr = 0;
282
1.50M
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
992k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
981k
    start_iMCU_row(cinfo);
286
981k
    return JPEG_ROW_COMPLETED;
287
981k
  }
288
  /* Completed the scan */
289
10.9k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
10.9k
  return JPEG_SCAN_COMPLETED;
291
992k
}
jdcoefct-8.c:consume_data
Line
Count
Source
218
904k
{
219
904k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
904k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
904k
  int blkn, ci, xindex, yindex, yoffset;
222
904k
  JDIMENSION start_col;
223
904k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
904k
  JBLOCKROW buffer_ptr;
225
904k
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
1.86M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
957k
    compptr = cinfo->cur_comp_info[ci];
230
957k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
957k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
957k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
957k
       (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
957k
  }
239
240
  /* Loop to process one whole iMCU row */
241
2.24M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
1.33M
       yoffset++) {
243
16.8M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
15.4M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
15.4M
      blkn = 0;                 /* index of current DCT block within MCU */
247
33.3M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
17.8M
        compptr = cinfo->cur_comp_info[ci];
249
17.8M
        start_col = MCU_col_num * compptr->MCU_width;
250
37.9M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
20.0M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
41.5M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
21.4M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
21.4M
          }
255
20.0M
        }
256
17.8M
      }
257
15.4M
      if (!cinfo->entropy->insufficient_data)
258
15.4M
        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
15.4M
      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
15.4M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
1.33M
    coef->MCU_ctr = 0;
282
1.33M
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
904k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
894k
    start_iMCU_row(cinfo);
286
894k
    return JPEG_ROW_COMPLETED;
287
894k
  }
288
  /* Completed the scan */
289
9.76k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
9.76k
  return JPEG_SCAN_COMPLETED;
291
904k
}
jdcoefct-12.c:consume_data
Line
Count
Source
218
87.8k
{
219
87.8k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
87.8k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
87.8k
  int blkn, ci, xindex, yindex, yoffset;
222
87.8k
  JDIMENSION start_col;
223
87.8k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
87.8k
  JBLOCKROW buffer_ptr;
225
87.8k
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
189k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
101k
    compptr = cinfo->cur_comp_info[ci];
230
101k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
101k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
101k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
101k
       (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
101k
  }
239
240
  /* Loop to process one whole iMCU row */
241
256k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
168k
       yoffset++) {
243
1.67M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
1.50M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
1.50M
      blkn = 0;                 /* index of current DCT block within MCU */
247
3.44M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
1.93M
        compptr = cinfo->cur_comp_info[ci];
249
1.93M
        start_col = MCU_col_num * compptr->MCU_width;
250
4.05M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
2.11M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
4.58M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
2.47M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
2.47M
          }
255
2.11M
        }
256
1.93M
      }
257
1.50M
      if (!cinfo->entropy->insufficient_data)
258
1.50M
        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.50M
      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.50M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
168k
    coef->MCU_ctr = 0;
282
168k
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
87.8k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
86.6k
    start_iMCU_row(cinfo);
286
86.6k
    return JPEG_ROW_COMPLETED;
287
86.6k
  }
288
  /* Completed the scan */
289
1.21k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
1.21k
  return JPEG_SCAN_COMPLETED;
291
87.8k
}
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
128k
{
305
128k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
128k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
128k
  JDIMENSION block_num;
308
128k
  int ci, block_row, block_rows;
309
128k
  JBLOCKARRAY buffer;
310
128k
  JBLOCKROW buffer_ptr;
311
128k
  _JSAMPARRAY output_ptr;
312
128k
  JDIMENSION output_col;
313
128k
  jpeg_component_info *compptr;
314
128k
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
128k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
128k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
128k
          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
271k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
143k
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
143k
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
143k
    buffer = (*cinfo->mem->access_virt_barray)
332
143k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
143k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
143k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
143k
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
141k
      block_rows = compptr->v_samp_factor;
338
2.01k
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
2.01k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
2.01k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
2.01k
    }
343
143k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
143k
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
335k
    for (block_row = 0; block_row < block_rows; block_row++) {
347
192k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
192k
      output_col = 0;
349
192k
      for (block_num = cinfo->master->first_MCU_col[ci];
350
2.17M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
1.98M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
1.98M
                        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
1.98M
        buffer_ptr++;
361
1.98M
        output_col += compptr->_DCT_scaled_size;
362
1.98M
      }
363
192k
      output_ptr += compptr->_DCT_scaled_size;
364
192k
    }
365
143k
  }
366
367
128k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
127k
    return JPEG_ROW_COMPLETED;
369
825
  return JPEG_SCAN_COMPLETED;
370
128k
}
jdcoefct-8.c:decompress_data
Line
Count
Source
304
128k
{
305
128k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
128k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
128k
  JDIMENSION block_num;
308
128k
  int ci, block_row, block_rows;
309
128k
  JBLOCKARRAY buffer;
310
128k
  JBLOCKROW buffer_ptr;
311
128k
  _JSAMPARRAY output_ptr;
312
128k
  JDIMENSION output_col;
313
128k
  jpeg_component_info *compptr;
314
128k
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
128k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
128k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
128k
          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
271k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
143k
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
143k
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
143k
    buffer = (*cinfo->mem->access_virt_barray)
332
143k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
143k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
143k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
143k
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
141k
      block_rows = compptr->v_samp_factor;
338
2.01k
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
2.01k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
2.01k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
2.01k
    }
343
143k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
143k
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
335k
    for (block_row = 0; block_row < block_rows; block_row++) {
347
192k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
192k
      output_col = 0;
349
192k
      for (block_num = cinfo->master->first_MCU_col[ci];
350
2.17M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
1.98M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
1.98M
                        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
1.98M
        buffer_ptr++;
361
1.98M
        output_col += compptr->_DCT_scaled_size;
362
1.98M
      }
363
192k
      output_ptr += compptr->_DCT_scaled_size;
364
192k
    }
365
143k
  }
366
367
128k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
127k
    return JPEG_ROW_COMPLETED;
369
825
  return JPEG_SCAN_COMPLETED;
370
128k
}
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
87.9k
#define Q01_POS  1
386
87.8k
#define Q10_POS  8
387
87.8k
#define Q20_POS  16
388
87.8k
#define Q11_POS  9
389
87.6k
#define Q02_POS  2
390
41.4k
#define Q03_POS  3
391
41.4k
#define Q12_POS  10
392
41.4k
#define Q21_POS  17
393
41.3k
#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
1.93k
{
406
1.93k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
1.93k
  boolean smoothing_useful = FALSE;
408
1.93k
  int ci, coefi;
409
1.93k
  jpeg_component_info *compptr;
410
1.93k
  JQUANT_TBL *qtable;
411
1.93k
  int *coef_bits, *prev_coef_bits;
412
1.93k
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
1.93k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
12
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
1.92k
  if (coef->coef_bits_latch == NULL)
419
1.92k
    coef->coef_bits_latch = (int *)
420
1.92k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
1.92k
                                  cinfo->num_components * 2 *
422
1.92k
                                  (SAVED_COEFS * sizeof(int)));
423
1.92k
  coef_bits_latch = coef->coef_bits_latch;
424
1.92k
  prev_coef_bits_latch =
425
1.92k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
4.77k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
3.33k
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
3.33k
    if ((qtable = compptr->quant_table) == NULL)
431
49
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
3.28k
    if (qtable->quantval[0] == 0 ||
434
3.24k
        qtable->quantval[Q01_POS] == 0 ||
435
3.22k
        qtable->quantval[Q10_POS] == 0 ||
436
3.18k
        qtable->quantval[Q20_POS] == 0 ||
437
3.15k
        qtable->quantval[Q11_POS] == 0 ||
438
3.01k
        qtable->quantval[Q02_POS] == 0 ||
439
2.96k
        qtable->quantval[Q03_POS] == 0 ||
440
2.92k
        qtable->quantval[Q12_POS] == 0 ||
441
2.90k
        qtable->quantval[Q21_POS] == 0 ||
442
2.86k
        qtable->quantval[Q30_POS] == 0)
443
441
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
2.84k
    coef_bits = cinfo->coef_bits[ci];
446
2.84k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
2.84k
    if (coef_bits[0] < 0)
448
0
      return FALSE;
449
2.84k
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
28.4k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
25.6k
      if (cinfo->input_scan_number > 1)
453
17.8k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
7.73k
      else
455
7.73k
        prev_coef_bits_latch[coefi] = -1;
456
25.6k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
25.6k
      if (coef_bits[coefi] != 0)
458
13.7k
        smoothing_useful = TRUE;
459
25.6k
    }
460
2.84k
    coef_bits_latch += SAVED_COEFS;
461
2.84k
    prev_coef_bits_latch += SAVED_COEFS;
462
2.84k
  }
463
464
1.43k
  return smoothing_useful;
465
1.92k
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
405
1.73k
{
406
1.73k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
1.73k
  boolean smoothing_useful = FALSE;
408
1.73k
  int ci, coefi;
409
1.73k
  jpeg_component_info *compptr;
410
1.73k
  JQUANT_TBL *qtable;
411
1.73k
  int *coef_bits, *prev_coef_bits;
412
1.73k
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
1.73k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
6
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
1.73k
  if (coef->coef_bits_latch == NULL)
419
1.73k
    coef->coef_bits_latch = (int *)
420
1.73k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
1.73k
                                  cinfo->num_components * 2 *
422
1.73k
                                  (SAVED_COEFS * sizeof(int)));
423
1.73k
  coef_bits_latch = coef->coef_bits_latch;
424
1.73k
  prev_coef_bits_latch =
425
1.73k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
4.24k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
2.91k
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
2.91k
    if ((qtable = compptr->quant_table) == NULL)
431
46
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
2.86k
    if (qtable->quantval[0] == 0 ||
434
2.83k
        qtable->quantval[Q01_POS] == 0 ||
435
2.81k
        qtable->quantval[Q10_POS] == 0 ||
436
2.79k
        qtable->quantval[Q20_POS] == 0 ||
437
2.76k
        qtable->quantval[Q11_POS] == 0 ||
438
2.64k
        qtable->quantval[Q02_POS] == 0 ||
439
2.61k
        qtable->quantval[Q03_POS] == 0 ||
440
2.57k
        qtable->quantval[Q12_POS] == 0 ||
441
2.56k
        qtable->quantval[Q21_POS] == 0 ||
442
2.52k
        qtable->quantval[Q30_POS] == 0)
443
350
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
2.51k
    coef_bits = cinfo->coef_bits[ci];
446
2.51k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
2.51k
    if (coef_bits[0] < 0)
448
0
      return FALSE;
449
2.51k
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
25.1k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
22.6k
      if (cinfo->input_scan_number > 1)
453
16.4k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
6.25k
      else
455
6.25k
        prev_coef_bits_latch[coefi] = -1;
456
22.6k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
22.6k
      if (coef_bits[coefi] != 0)
458
11.1k
        smoothing_useful = TRUE;
459
22.6k
    }
460
2.51k
    coef_bits_latch += SAVED_COEFS;
461
2.51k
    prev_coef_bits_latch += SAVED_COEFS;
462
2.51k
  }
463
464
1.33k
  return smoothing_useful;
465
1.73k
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
405
201
{
406
201
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
201
  boolean smoothing_useful = FALSE;
408
201
  int ci, coefi;
409
201
  jpeg_component_info *compptr;
410
201
  JQUANT_TBL *qtable;
411
201
  int *coef_bits, *prev_coef_bits;
412
201
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
201
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
6
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
195
  if (coef->coef_bits_latch == NULL)
419
195
    coef->coef_bits_latch = (int *)
420
195
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
195
                                  cinfo->num_components * 2 *
422
195
                                  (SAVED_COEFS * sizeof(int)));
423
195
  coef_bits_latch = coef->coef_bits_latch;
424
195
  prev_coef_bits_latch =
425
195
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
523
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
422
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
422
    if ((qtable = compptr->quant_table) == NULL)
431
3
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
419
    if (qtable->quantval[0] == 0 ||
434
413
        qtable->quantval[Q01_POS] == 0 ||
435
406
        qtable->quantval[Q10_POS] == 0 ||
436
396
        qtable->quantval[Q20_POS] == 0 ||
437
384
        qtable->quantval[Q11_POS] == 0 ||
438
367
        qtable->quantval[Q02_POS] == 0 ||
439
357
        qtable->quantval[Q03_POS] == 0 ||
440
351
        qtable->quantval[Q12_POS] == 0 ||
441
345
        qtable->quantval[Q21_POS] == 0 ||
442
339
        qtable->quantval[Q30_POS] == 0)
443
91
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
328
    coef_bits = cinfo->coef_bits[ci];
446
328
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
328
    if (coef_bits[0] < 0)
448
0
      return FALSE;
449
328
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
3.28k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
2.95k
      if (cinfo->input_scan_number > 1)
453
1.47k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
1.47k
      else
455
1.47k
        prev_coef_bits_latch[coefi] = -1;
456
2.95k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
2.95k
      if (coef_bits[coefi] != 0)
458
2.59k
        smoothing_useful = TRUE;
459
2.95k
    }
460
328
    coef_bits_latch += SAVED_COEFS;
461
328
    prev_coef_bits_latch += SAVED_COEFS;
462
328
  }
463
464
101
  return smoothing_useful;
465
195
}
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
81.2k
{
475
81.2k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
81.2k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
81.2k
  JDIMENSION block_num, last_block_column;
478
81.2k
  int ci, block_row, block_rows, access_rows, image_block_row,
479
81.2k
    image_block_rows;
480
81.2k
  JBLOCKARRAY buffer;
481
81.2k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
81.2k
  JBLOCKROW next_block_row, next_next_block_row;
483
81.2k
  _JSAMPARRAY output_ptr;
484
81.2k
  JDIMENSION output_col;
485
81.2k
  jpeg_component_info *compptr;
486
81.2k
  _inverse_DCT_method_ptr inverse_DCT;
487
81.2k
  boolean change_dc;
488
81.2k
  JCOEF *workspace;
489
81.2k
  int *coef_bits;
490
81.2k
  JQUANT_TBL *quanttbl;
491
81.2k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
81.2k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
81.2k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
81.2k
      DC25;
495
81.2k
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
81.2k
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
81.2k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
81.2k
         !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
165k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
84.6k
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
84.6k
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
84.6k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
82.4k
      block_rows = compptr->v_samp_factor;
526
82.4k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
82.4k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
977
      block_rows = compptr->v_samp_factor;
529
977
      access_rows = block_rows * 2; /* this and next iMCU row */
530
1.28k
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
1.28k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
1.28k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
1.28k
      access_rows = block_rows; /* this iMCU row only */
535
1.28k
    }
536
    /* Align the virtual buffer for this component. */
537
84.6k
    if (cinfo->output_iMCU_row > 1) {
538
82.4k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
82.4k
      buffer = (*cinfo->mem->access_virt_barray)
540
82.4k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
82.4k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
82.4k
         (JDIMENSION)access_rows, FALSE);
543
82.4k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
82.4k
    } else if (cinfo->output_iMCU_row > 0) {
545
977
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
977
      buffer = (*cinfo->mem->access_virt_barray)
547
977
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
977
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
977
         (JDIMENSION)access_rows, FALSE);
550
977
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
1.28k
    } else {
552
1.28k
      buffer = (*cinfo->mem->access_virt_barray)
553
1.28k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
1.28k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
1.28k
    }
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
84.6k
    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
84.6k
    else
564
84.6k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
565
566
    /* We only do DC interpolation if no AC coefficient data is available. */
567
84.6k
    change_dc =
568
84.6k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
55.2k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
52.0k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
84.6k
    quanttbl = compptr->quant_table;
573
84.6k
    Q00 = quanttbl->quantval[0];
574
84.6k
    Q01 = quanttbl->quantval[Q01_POS];
575
84.6k
    Q10 = quanttbl->quantval[Q10_POS];
576
84.6k
    Q20 = quanttbl->quantval[Q20_POS];
577
84.6k
    Q11 = quanttbl->quantval[Q11_POS];
578
84.6k
    Q02 = quanttbl->quantval[Q02_POS];
579
84.6k
    if (change_dc) {
580
38.4k
      Q03 = quanttbl->quantval[Q03_POS];
581
38.4k
      Q12 = quanttbl->quantval[Q12_POS];
582
38.4k
      Q21 = quanttbl->quantval[Q21_POS];
583
38.4k
      Q30 = quanttbl->quantval[Q30_POS];
584
38.4k
    }
585
84.6k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
84.6k
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
84.6k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
248k
    for (block_row = 0; block_row < block_rows; block_row++) {
590
163k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
163k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
163k
      if (image_block_row > 0)
594
162k
        prev_block_row =
595
162k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
1.28k
      else
597
1.28k
        prev_block_row = buffer_ptr;
598
599
163k
      if (image_block_row > 1)
600
161k
        prev_prev_block_row =
601
161k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
2.38k
      else
603
2.38k
        prev_prev_block_row = prev_block_row;
604
605
163k
      if (image_block_row < image_block_rows - 1)
606
162k
        next_block_row =
607
162k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
1.28k
      else
609
1.28k
        next_block_row = buffer_ptr;
610
611
163k
      if (image_block_row < image_block_rows - 2)
612
161k
        next_next_block_row =
613
161k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
1.85k
      else
615
1.85k
        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
163k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
163k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
163k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
163k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
163k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
163k
      output_col = 0;
626
163k
      last_block_column = compptr->width_in_blocks - 1;
627
163k
      for (block_num = cinfo->master->first_MCU_col[ci];
628
3.96M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
3.79M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
3.79M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
163k
            block_num < last_block_column) {
634
91.2k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
91.2k
          DC09 = DC10 = (int)prev_block_row[1][0];
636
91.2k
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
91.2k
          DC19 = DC20 = (int)next_block_row[1][0];
638
91.2k
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
91.2k
        }
640
3.79M
        if (block_num + 1 < last_block_column) {
641
3.54M
          DC05 = (int)prev_prev_block_row[2][0];
642
3.54M
          DC10 = (int)prev_block_row[2][0];
643
3.54M
          DC15 = (int)buffer_ptr[2][0];
644
3.54M
          DC20 = (int)next_block_row[2][0];
645
3.54M
          DC25 = (int)next_next_block_row[2][0];
646
3.54M
        }
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
3.79M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
3.52M
          num = Q00 * (change_dc ?
660
2.36M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
2.36M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
2.36M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
2.36M
                 DC21 - DC22 + DC24 + DC25) :
664
3.52M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
3.52M
          if (num >= 0) {
666
2.14M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
2.14M
            if (Al > 0 && pred >= (1 << Al))
668
9.68k
              pred = (1 << Al) - 1;
669
2.14M
          } else {
670
1.38M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
1.38M
            if (Al > 0 && pred >= (1 << Al))
672
7.18k
              pred = (1 << Al) - 1;
673
1.38M
            pred = -pred;
674
1.38M
          }
675
3.52M
          workspace[1] = (JCOEF)pred;
676
3.52M
        }
677
        /* AC10 */
678
3.79M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
3.57M
          num = Q00 * (change_dc ?
680
2.36M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
2.36M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
2.36M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
2.36M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
3.57M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
3.57M
          if (num >= 0) {
686
2.36M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
2.36M
            if (Al > 0 && pred >= (1 << Al))
688
121k
              pred = (1 << Al) - 1;
689
2.36M
          } else {
690
1.21M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
1.21M
            if (Al > 0 && pred >= (1 << Al))
692
78.5k
              pred = (1 << Al) - 1;
693
1.21M
            pred = -pred;
694
1.21M
          }
695
3.57M
          workspace[8] = (JCOEF)pred;
696
3.57M
        }
697
        /* AC20 */
698
3.79M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
3.57M
          num = Q00 * (change_dc ?
700
2.36M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
2.36M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
3.57M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
3.57M
          if (num >= 0) {
704
1.92M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
1.92M
            if (Al > 0 && pred >= (1 << Al))
706
39.0k
              pred = (1 << Al) - 1;
707
1.92M
          } else {
708
1.65M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
1.65M
            if (Al > 0 && pred >= (1 << Al))
710
39.1k
              pred = (1 << Al) - 1;
711
1.65M
            pred = -pred;
712
1.65M
          }
713
3.57M
          workspace[16] = (JCOEF)pred;
714
3.57M
        }
715
        /* AC11 */
716
3.79M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
3.50M
          num = Q00 * (change_dc ?
718
2.36M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
2.36M
                 9 * DC19 + DC21 - DC25) :
720
3.50M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
1.13M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
3.50M
          if (num >= 0) {
723
2.18M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
2.18M
            if (Al > 0 && pred >= (1 << Al))
725
13.6k
              pred = (1 << Al) - 1;
726
2.18M
          } else {
727
1.31M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
1.31M
            if (Al > 0 && pred >= (1 << Al))
729
13.3k
              pred = (1 << Al) - 1;
730
1.31M
            pred = -pred;
731
1.31M
          }
732
3.50M
          workspace[9] = (JCOEF)pred;
733
3.50M
        }
734
        /* AC02 */
735
3.79M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
3.50M
          num = Q00 * (change_dc ?
737
2.36M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
2.36M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
3.50M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
3.50M
          if (num >= 0) {
741
1.94M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
1.94M
            if (Al > 0 && pred >= (1 << Al))
743
13.2k
              pred = (1 << Al) - 1;
744
1.94M
          } else {
745
1.56M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
1.56M
            if (Al > 0 && pred >= (1 << Al))
747
12.7k
              pred = (1 << Al) - 1;
748
1.56M
            pred = -pred;
749
1.56M
          }
750
3.50M
          workspace[2] = (JCOEF)pred;
751
3.50M
        }
752
3.79M
        if (change_dc) {
753
          /* AC03 */
754
2.36M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
2.36M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
2.36M
            if (num >= 0) {
757
1.48M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
1.48M
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
1.48M
            } else {
761
883k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
883k
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
883k
              pred = -pred;
765
883k
            }
766
2.36M
            workspace[3] = (JCOEF)pred;
767
2.36M
          }
768
          /* AC12 */
769
2.36M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
2.36M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
2.36M
            if (num >= 0) {
772
1.25M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
1.25M
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
1.25M
            } else {
776
1.11M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
1.11M
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
1.11M
              pred = -pred;
780
1.11M
            }
781
2.36M
            workspace[10] = (JCOEF)pred;
782
2.36M
          }
783
          /* AC21 */
784
2.36M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
2.36M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
2.36M
            if (num >= 0) {
787
1.29M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
1.29M
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
1.29M
            } else {
791
1.07M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
1.07M
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
1.07M
              pred = -pred;
795
1.07M
            }
796
2.36M
            workspace[17] = (JCOEF)pred;
797
2.36M
          }
798
          /* AC30 */
799
2.36M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
2.36M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
2.36M
            if (num >= 0) {
802
1.51M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
1.51M
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
1.51M
            } else {
806
855k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
855k
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
855k
              pred = -pred;
810
855k
            }
811
2.36M
            workspace[24] = (JCOEF)pred;
812
2.36M
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
2.36M
          num = Q00 *
817
2.36M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
2.36M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
2.36M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
2.36M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
2.36M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
2.36M
          if (num >= 0) {
823
1.06M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
1.30M
          } else {
825
1.30M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
1.30M
            pred = -pred;
827
1.30M
          }
828
2.36M
          workspace[0] = (JCOEF)pred;
829
2.36M
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
3.79M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
3.79M
                        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
3.79M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
3.79M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
3.79M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
3.79M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
3.79M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
3.79M
        buffer_ptr++, prev_block_row++, next_block_row++,
848
3.79M
          prev_prev_block_row++, next_next_block_row++;
849
3.79M
        output_col += compptr->_DCT_scaled_size;
850
3.79M
      }
851
163k
      output_ptr += compptr->_DCT_scaled_size;
852
163k
    }
853
84.6k
  }
854
855
81.2k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
80.3k
    return JPEG_ROW_COMPLETED;
857
912
  return JPEG_SCAN_COMPLETED;
858
81.2k
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
474
81.2k
{
475
81.2k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
81.2k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
81.2k
  JDIMENSION block_num, last_block_column;
478
81.2k
  int ci, block_row, block_rows, access_rows, image_block_row,
479
81.2k
    image_block_rows;
480
81.2k
  JBLOCKARRAY buffer;
481
81.2k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
81.2k
  JBLOCKROW next_block_row, next_next_block_row;
483
81.2k
  _JSAMPARRAY output_ptr;
484
81.2k
  JDIMENSION output_col;
485
81.2k
  jpeg_component_info *compptr;
486
81.2k
  _inverse_DCT_method_ptr inverse_DCT;
487
81.2k
  boolean change_dc;
488
81.2k
  JCOEF *workspace;
489
81.2k
  int *coef_bits;
490
81.2k
  JQUANT_TBL *quanttbl;
491
81.2k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
81.2k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
81.2k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
81.2k
      DC25;
495
81.2k
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
81.2k
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
81.2k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
81.2k
         !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
165k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
84.6k
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
84.6k
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
84.6k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
82.4k
      block_rows = compptr->v_samp_factor;
526
82.4k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
82.4k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
977
      block_rows = compptr->v_samp_factor;
529
977
      access_rows = block_rows * 2; /* this and next iMCU row */
530
1.28k
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
1.28k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
1.28k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
1.28k
      access_rows = block_rows; /* this iMCU row only */
535
1.28k
    }
536
    /* Align the virtual buffer for this component. */
537
84.6k
    if (cinfo->output_iMCU_row > 1) {
538
82.4k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
82.4k
      buffer = (*cinfo->mem->access_virt_barray)
540
82.4k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
82.4k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
82.4k
         (JDIMENSION)access_rows, FALSE);
543
82.4k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
82.4k
    } else if (cinfo->output_iMCU_row > 0) {
545
977
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
977
      buffer = (*cinfo->mem->access_virt_barray)
547
977
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
977
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
977
         (JDIMENSION)access_rows, FALSE);
550
977
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
1.28k
    } else {
552
1.28k
      buffer = (*cinfo->mem->access_virt_barray)
553
1.28k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
1.28k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
1.28k
    }
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
84.6k
    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
84.6k
    else
564
84.6k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
565
566
    /* We only do DC interpolation if no AC coefficient data is available. */
567
84.6k
    change_dc =
568
84.6k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
55.2k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
52.0k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
84.6k
    quanttbl = compptr->quant_table;
573
84.6k
    Q00 = quanttbl->quantval[0];
574
84.6k
    Q01 = quanttbl->quantval[Q01_POS];
575
84.6k
    Q10 = quanttbl->quantval[Q10_POS];
576
84.6k
    Q20 = quanttbl->quantval[Q20_POS];
577
84.6k
    Q11 = quanttbl->quantval[Q11_POS];
578
84.6k
    Q02 = quanttbl->quantval[Q02_POS];
579
84.6k
    if (change_dc) {
580
38.4k
      Q03 = quanttbl->quantval[Q03_POS];
581
38.4k
      Q12 = quanttbl->quantval[Q12_POS];
582
38.4k
      Q21 = quanttbl->quantval[Q21_POS];
583
38.4k
      Q30 = quanttbl->quantval[Q30_POS];
584
38.4k
    }
585
84.6k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
84.6k
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
84.6k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
248k
    for (block_row = 0; block_row < block_rows; block_row++) {
590
163k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
163k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
163k
      if (image_block_row > 0)
594
162k
        prev_block_row =
595
162k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
1.28k
      else
597
1.28k
        prev_block_row = buffer_ptr;
598
599
163k
      if (image_block_row > 1)
600
161k
        prev_prev_block_row =
601
161k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
2.38k
      else
603
2.38k
        prev_prev_block_row = prev_block_row;
604
605
163k
      if (image_block_row < image_block_rows - 1)
606
162k
        next_block_row =
607
162k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
1.28k
      else
609
1.28k
        next_block_row = buffer_ptr;
610
611
163k
      if (image_block_row < image_block_rows - 2)
612
161k
        next_next_block_row =
613
161k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
1.85k
      else
615
1.85k
        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
163k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
163k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
163k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
163k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
163k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
163k
      output_col = 0;
626
163k
      last_block_column = compptr->width_in_blocks - 1;
627
163k
      for (block_num = cinfo->master->first_MCU_col[ci];
628
3.96M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
3.79M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
3.79M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
163k
            block_num < last_block_column) {
634
91.2k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
91.2k
          DC09 = DC10 = (int)prev_block_row[1][0];
636
91.2k
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
91.2k
          DC19 = DC20 = (int)next_block_row[1][0];
638
91.2k
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
91.2k
        }
640
3.79M
        if (block_num + 1 < last_block_column) {
641
3.54M
          DC05 = (int)prev_prev_block_row[2][0];
642
3.54M
          DC10 = (int)prev_block_row[2][0];
643
3.54M
          DC15 = (int)buffer_ptr[2][0];
644
3.54M
          DC20 = (int)next_block_row[2][0];
645
3.54M
          DC25 = (int)next_next_block_row[2][0];
646
3.54M
        }
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
3.79M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
3.52M
          num = Q00 * (change_dc ?
660
2.36M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
2.36M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
2.36M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
2.36M
                 DC21 - DC22 + DC24 + DC25) :
664
3.52M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
3.52M
          if (num >= 0) {
666
2.14M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
2.14M
            if (Al > 0 && pred >= (1 << Al))
668
9.68k
              pred = (1 << Al) - 1;
669
2.14M
          } else {
670
1.38M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
1.38M
            if (Al > 0 && pred >= (1 << Al))
672
7.18k
              pred = (1 << Al) - 1;
673
1.38M
            pred = -pred;
674
1.38M
          }
675
3.52M
          workspace[1] = (JCOEF)pred;
676
3.52M
        }
677
        /* AC10 */
678
3.79M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
3.57M
          num = Q00 * (change_dc ?
680
2.36M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
2.36M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
2.36M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
2.36M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
3.57M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
3.57M
          if (num >= 0) {
686
2.36M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
2.36M
            if (Al > 0 && pred >= (1 << Al))
688
121k
              pred = (1 << Al) - 1;
689
2.36M
          } else {
690
1.21M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
1.21M
            if (Al > 0 && pred >= (1 << Al))
692
78.5k
              pred = (1 << Al) - 1;
693
1.21M
            pred = -pred;
694
1.21M
          }
695
3.57M
          workspace[8] = (JCOEF)pred;
696
3.57M
        }
697
        /* AC20 */
698
3.79M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
3.57M
          num = Q00 * (change_dc ?
700
2.36M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
2.36M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
3.57M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
3.57M
          if (num >= 0) {
704
1.92M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
1.92M
            if (Al > 0 && pred >= (1 << Al))
706
39.0k
              pred = (1 << Al) - 1;
707
1.92M
          } else {
708
1.65M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
1.65M
            if (Al > 0 && pred >= (1 << Al))
710
39.1k
              pred = (1 << Al) - 1;
711
1.65M
            pred = -pred;
712
1.65M
          }
713
3.57M
          workspace[16] = (JCOEF)pred;
714
3.57M
        }
715
        /* AC11 */
716
3.79M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
3.50M
          num = Q00 * (change_dc ?
718
2.36M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
2.36M
                 9 * DC19 + DC21 - DC25) :
720
3.50M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
1.13M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
3.50M
          if (num >= 0) {
723
2.18M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
2.18M
            if (Al > 0 && pred >= (1 << Al))
725
13.6k
              pred = (1 << Al) - 1;
726
2.18M
          } else {
727
1.31M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
1.31M
            if (Al > 0 && pred >= (1 << Al))
729
13.3k
              pred = (1 << Al) - 1;
730
1.31M
            pred = -pred;
731
1.31M
          }
732
3.50M
          workspace[9] = (JCOEF)pred;
733
3.50M
        }
734
        /* AC02 */
735
3.79M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
3.50M
          num = Q00 * (change_dc ?
737
2.36M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
2.36M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
3.50M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
3.50M
          if (num >= 0) {
741
1.94M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
1.94M
            if (Al > 0 && pred >= (1 << Al))
743
13.2k
              pred = (1 << Al) - 1;
744
1.94M
          } else {
745
1.56M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
1.56M
            if (Al > 0 && pred >= (1 << Al))
747
12.7k
              pred = (1 << Al) - 1;
748
1.56M
            pred = -pred;
749
1.56M
          }
750
3.50M
          workspace[2] = (JCOEF)pred;
751
3.50M
        }
752
3.79M
        if (change_dc) {
753
          /* AC03 */
754
2.36M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
2.36M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
2.36M
            if (num >= 0) {
757
1.48M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
1.48M
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
1.48M
            } else {
761
883k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
883k
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
883k
              pred = -pred;
765
883k
            }
766
2.36M
            workspace[3] = (JCOEF)pred;
767
2.36M
          }
768
          /* AC12 */
769
2.36M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
2.36M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
2.36M
            if (num >= 0) {
772
1.25M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
1.25M
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
1.25M
            } else {
776
1.11M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
1.11M
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
1.11M
              pred = -pred;
780
1.11M
            }
781
2.36M
            workspace[10] = (JCOEF)pred;
782
2.36M
          }
783
          /* AC21 */
784
2.36M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
2.36M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
2.36M
            if (num >= 0) {
787
1.29M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
1.29M
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
1.29M
            } else {
791
1.07M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
1.07M
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
1.07M
              pred = -pred;
795
1.07M
            }
796
2.36M
            workspace[17] = (JCOEF)pred;
797
2.36M
          }
798
          /* AC30 */
799
2.36M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
2.36M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
2.36M
            if (num >= 0) {
802
1.51M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
1.51M
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
1.51M
            } else {
806
855k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
855k
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
855k
              pred = -pred;
810
855k
            }
811
2.36M
            workspace[24] = (JCOEF)pred;
812
2.36M
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
2.36M
          num = Q00 *
817
2.36M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
2.36M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
2.36M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
2.36M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
2.36M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
2.36M
          if (num >= 0) {
823
1.06M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
1.30M
          } else {
825
1.30M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
1.30M
            pred = -pred;
827
1.30M
          }
828
2.36M
          workspace[0] = (JCOEF)pred;
829
2.36M
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
3.79M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
3.79M
                        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
3.79M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
3.79M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
3.79M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
3.79M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
3.79M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
3.79M
        buffer_ptr++, prev_block_row++, next_block_row++,
848
3.79M
          prev_prev_block_row++, next_next_block_row++;
849
3.79M
        output_col += compptr->_DCT_scaled_size;
850
3.79M
      }
851
163k
      output_ptr += compptr->_DCT_scaled_size;
852
163k
    }
853
84.6k
  }
854
855
81.2k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
80.3k
    return JPEG_ROW_COMPLETED;
857
912
  return JPEG_SCAN_COMPLETED;
858
81.2k
}
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
5.52k
{
870
5.52k
  my_coef_ptr coef;
871
872
5.52k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
5.52k
  coef = (my_coef_ptr)
876
5.52k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
5.52k
                                sizeof(my_coef_controller));
878
5.52k
  memset(coef, 0, sizeof(my_coef_controller));
879
5.52k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
5.52k
  coef->pub.start_input_pass = start_input_pass;
881
5.52k
  coef->pub.start_output_pass = start_output_pass;
882
5.52k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
5.52k
  coef->coef_bits_latch = NULL;
884
5.52k
#endif
885
886
  /* Create the coefficient buffer. */
887
5.52k
  if (need_full_buffer) {
888
3.10k
#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
3.10k
    int ci, access_rows;
893
3.10k
    jpeg_component_info *compptr;
894
895
10.0k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
6.93k
         ci++, compptr++) {
897
6.93k
      access_rows = compptr->v_samp_factor;
898
6.93k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
6.93k
      if (cinfo->progressive_mode)
901
6.78k
        access_rows *= 5;
902
6.93k
#endif
903
6.93k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
6.93k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
6.93k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
6.93k
                               (long)compptr->h_samp_factor),
907
6.93k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
6.93k
                               (long)compptr->v_samp_factor),
909
6.93k
         (JDIMENSION)access_rows);
910
6.93k
    }
911
3.10k
    coef->pub.consume_data = consume_data;
912
3.10k
    coef->pub._decompress_data = decompress_data;
913
3.10k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
3.10k
  } else {
918
    /* We only need a single-MCU buffer. */
919
2.42k
    JBLOCKROW buffer;
920
2.42k
    int i;
921
922
2.42k
    buffer = (JBLOCKROW)
923
2.42k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
2.42k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
26.6k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
24.2k
      coef->MCU_buffer[i] = buffer + i;
927
24.2k
    }
928
2.42k
    coef->pub.consume_data = dummy_consume_data;
929
2.42k
    coef->pub._decompress_data = decompress_onepass;
930
2.42k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
2.42k
  }
932
933
  /* Allocate the workspace buffer */
934
5.52k
  coef->workspace = (JCOEF *)
935
5.52k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
5.52k
                                sizeof(JCOEF) * DCTSIZE2);
937
5.52k
}
jinit_d_coef_controller
Line
Count
Source
869
4.83k
{
870
4.83k
  my_coef_ptr coef;
871
872
4.83k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
4.83k
  coef = (my_coef_ptr)
876
4.83k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
4.83k
                                sizeof(my_coef_controller));
878
4.83k
  memset(coef, 0, sizeof(my_coef_controller));
879
4.83k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
4.83k
  coef->pub.start_input_pass = start_input_pass;
881
4.83k
  coef->pub.start_output_pass = start_output_pass;
882
4.83k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
4.83k
  coef->coef_bits_latch = NULL;
884
4.83k
#endif
885
886
  /* Create the coefficient buffer. */
887
4.83k
  if (need_full_buffer) {
888
2.43k
#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
2.43k
    int ci, access_rows;
893
2.43k
    jpeg_component_info *compptr;
894
895
7.49k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
5.06k
         ci++, compptr++) {
897
5.06k
      access_rows = compptr->v_samp_factor;
898
5.06k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
5.06k
      if (cinfo->progressive_mode)
901
5.02k
        access_rows *= 5;
902
5.06k
#endif
903
5.06k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
5.06k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
5.06k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
5.06k
                               (long)compptr->h_samp_factor),
907
5.06k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
5.06k
                               (long)compptr->v_samp_factor),
909
5.06k
         (JDIMENSION)access_rows);
910
5.06k
    }
911
2.43k
    coef->pub.consume_data = consume_data;
912
2.43k
    coef->pub._decompress_data = decompress_data;
913
2.43k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
2.43k
  } else {
918
    /* We only need a single-MCU buffer. */
919
2.39k
    JBLOCKROW buffer;
920
2.39k
    int i;
921
922
2.39k
    buffer = (JBLOCKROW)
923
2.39k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
2.39k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
26.3k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
23.9k
      coef->MCU_buffer[i] = buffer + i;
927
23.9k
    }
928
2.39k
    coef->pub.consume_data = dummy_consume_data;
929
2.39k
    coef->pub._decompress_data = decompress_onepass;
930
2.39k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
2.39k
  }
932
933
  /* Allocate the workspace buffer */
934
4.83k
  coef->workspace = (JCOEF *)
935
4.83k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
4.83k
                                sizeof(JCOEF) * DCTSIZE2);
937
4.83k
}
j12init_d_coef_controller
Line
Count
Source
869
698
{
870
698
  my_coef_ptr coef;
871
872
698
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
698
  coef = (my_coef_ptr)
876
698
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
698
                                sizeof(my_coef_controller));
878
698
  memset(coef, 0, sizeof(my_coef_controller));
879
698
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
698
  coef->pub.start_input_pass = start_input_pass;
881
698
  coef->pub.start_output_pass = start_output_pass;
882
698
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
698
  coef->coef_bits_latch = NULL;
884
698
#endif
885
886
  /* Create the coefficient buffer. */
887
698
  if (need_full_buffer) {
888
673
#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
673
    int ci, access_rows;
893
673
    jpeg_component_info *compptr;
894
895
2.54k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
1.86k
         ci++, compptr++) {
897
1.86k
      access_rows = compptr->v_samp_factor;
898
1.86k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
1.86k
      if (cinfo->progressive_mode)
901
1.76k
        access_rows *= 5;
902
1.86k
#endif
903
1.86k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
1.86k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
1.86k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
1.86k
                               (long)compptr->h_samp_factor),
907
1.86k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
1.86k
                               (long)compptr->v_samp_factor),
909
1.86k
         (JDIMENSION)access_rows);
910
1.86k
    }
911
673
    coef->pub.consume_data = consume_data;
912
673
    coef->pub._decompress_data = decompress_data;
913
673
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
673
  } else {
918
    /* We only need a single-MCU buffer. */
919
25
    JBLOCKROW buffer;
920
25
    int i;
921
922
25
    buffer = (JBLOCKROW)
923
25
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
25
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
275
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
250
      coef->MCU_buffer[i] = buffer + i;
927
250
    }
928
25
    coef->pub.consume_data = dummy_consume_data;
929
25
    coef->pub._decompress_data = decompress_onepass;
930
25
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
25
  }
932
933
  /* Allocate the workspace buffer */
934
698
  coef->workspace = (JCOEF *)
935
698
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
698
                                sizeof(JCOEF) * DCTSIZE2);
937
698
}