Coverage Report

Created: 2026-06-16 06:38

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
6.71k
{
51
6.71k
  cinfo->input_iMCU_row = 0;
52
6.71k
  start_iMCU_row(cinfo);
53
6.71k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
50
4.79k
{
51
4.79k
  cinfo->input_iMCU_row = 0;
52
4.79k
  start_iMCU_row(cinfo);
53
4.79k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
50
1.92k
{
51
1.92k
  cinfo->input_iMCU_row = 0;
52
1.92k
  start_iMCU_row(cinfo);
53
1.92k
}
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.67k
{
63
1.67k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
1.67k
  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.67k
  if (coef->pub.coef_arrays != NULL) {
68
785
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
488
      coef->pub._decompress_data = decompress_smooth_data;
70
297
    else
71
297
      coef->pub._decompress_data = decompress_data;
72
785
  }
73
1.67k
#endif
74
1.67k
  cinfo->output_iMCU_row = 0;
75
1.67k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
62
1.57k
{
63
1.57k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
1.57k
  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.57k
  if (coef->pub.coef_arrays != NULL) {
68
691
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
440
      coef->pub._decompress_data = decompress_smooth_data;
70
251
    else
71
251
      coef->pub._decompress_data = decompress_data;
72
691
  }
73
1.57k
#endif
74
1.57k
  cinfo->output_iMCU_row = 0;
75
1.57k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
62
100
{
63
100
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
100
  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
100
  if (coef->pub.coef_arrays != NULL) {
68
94
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
48
      coef->pub._decompress_data = decompress_smooth_data;
70
46
    else
71
46
      coef->pub._decompress_data = decompress_data;
72
94
  }
73
100
#endif
74
100
  cinfo->output_iMCU_row = 0;
75
100
}
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
243k
{
91
243k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
243k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
243k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
243k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
243k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
243k
  _JSAMPARRAY output_ptr;
97
243k
  JDIMENSION start_col, output_col;
98
243k
  jpeg_component_info *compptr;
99
243k
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
645k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
401k
       yoffset++) {
104
1.10M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
707k
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
707k
      jzero_far((void *)coef->MCU_buffer[0],
108
707k
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
707k
      if (!cinfo->entropy->insufficient_data)
110
707k
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
707k
      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
707k
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
707k
          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
707k
        blkn = 0;               /* index of current DCT block within MCU */
142
1.45M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
743k
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
743k
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
743k
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
743k
          useful_width = (MCU_col_num < last_MCU_col) ?
151
404k
                         compptr->MCU_width : compptr->last_col_width;
152
743k
          output_ptr = output_buf[compptr->component_index] +
153
743k
                       yoffset * compptr->_DCT_scaled_size;
154
743k
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
743k
                      compptr->MCU_sample_width;
156
1.50M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
758k
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
749k
                yoffset + yindex < compptr->last_row_height) {
159
749k
              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
788k
                (*inverse_DCT) (cinfo, compptr,
165
788k
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
788k
                                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
788k
                output_col += compptr->_DCT_scaled_size;
173
788k
              }
174
749k
            }
175
758k
            blkn += compptr->MCU_width;
176
758k
            output_ptr += compptr->_DCT_scaled_size;
177
758k
          }
178
743k
        }
179
707k
      }
180
707k
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
401k
    coef->MCU_ctr = 0;
183
401k
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
243k
  cinfo->output_iMCU_row++;
186
243k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
242k
    start_iMCU_row(cinfo);
188
242k
    return JPEG_ROW_COMPLETED;
189
242k
  }
190
  /* Completed the scan */
191
884
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
884
  return JPEG_SCAN_COMPLETED;
193
243k
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
90
243k
{
91
243k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
243k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
243k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
243k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
243k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
243k
  _JSAMPARRAY output_ptr;
97
243k
  JDIMENSION start_col, output_col;
98
243k
  jpeg_component_info *compptr;
99
243k
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
645k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
401k
       yoffset++) {
104
1.10M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
707k
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
707k
      jzero_far((void *)coef->MCU_buffer[0],
108
707k
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
707k
      if (!cinfo->entropy->insufficient_data)
110
707k
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
707k
      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
707k
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
707k
          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
707k
        blkn = 0;               /* index of current DCT block within MCU */
142
1.45M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
743k
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
743k
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
743k
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
743k
          useful_width = (MCU_col_num < last_MCU_col) ?
151
404k
                         compptr->MCU_width : compptr->last_col_width;
152
743k
          output_ptr = output_buf[compptr->component_index] +
153
743k
                       yoffset * compptr->_DCT_scaled_size;
154
743k
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
743k
                      compptr->MCU_sample_width;
156
1.50M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
758k
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
749k
                yoffset + yindex < compptr->last_row_height) {
159
749k
              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
788k
                (*inverse_DCT) (cinfo, compptr,
165
788k
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
788k
                                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
788k
                output_col += compptr->_DCT_scaled_size;
173
788k
              }
174
749k
            }
175
758k
            blkn += compptr->MCU_width;
176
758k
            output_ptr += compptr->_DCT_scaled_size;
177
758k
          }
178
743k
        }
179
707k
      }
180
707k
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
401k
    coef->MCU_ctr = 0;
183
401k
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
243k
  cinfo->output_iMCU_row++;
186
243k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
242k
    start_iMCU_row(cinfo);
188
242k
    return JPEG_ROW_COMPLETED;
189
242k
  }
190
  /* Completed the scan */
191
884
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
884
  return JPEG_SCAN_COMPLETED;
193
243k
}
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
753k
{
219
753k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
753k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
753k
  int blkn, ci, xindex, yindex, yoffset;
222
753k
  JDIMENSION start_col;
223
753k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
753k
  JBLOCKROW buffer_ptr;
225
753k
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
1.64M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
894k
    compptr = cinfo->cur_comp_info[ci];
230
894k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
894k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
894k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
894k
       (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
894k
  }
239
240
  /* Loop to process one whole iMCU row */
241
1.95M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
1.20M
       yoffset++) {
243
7.83M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
6.63M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
6.63M
      blkn = 0;                 /* index of current DCT block within MCU */
247
13.7M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
7.08M
        compptr = cinfo->cur_comp_info[ci];
249
7.08M
        start_col = MCU_col_num * compptr->MCU_width;
250
14.7M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
7.68M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
16.2M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
8.59M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
8.59M
          }
255
7.68M
        }
256
7.08M
      }
257
6.63M
      if (!cinfo->entropy->insufficient_data)
258
6.63M
        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
6.63M
      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
6.63M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
1.20M
    coef->MCU_ctr = 0;
282
1.20M
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
753k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
747k
    start_iMCU_row(cinfo);
286
747k
    return JPEG_ROW_COMPLETED;
287
747k
  }
288
  /* Completed the scan */
289
5.82k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
5.82k
  return JPEG_SCAN_COMPLETED;
291
753k
}
jdcoefct-8.c:consume_data
Line
Count
Source
218
501k
{
219
501k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
501k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
501k
  int blkn, ci, xindex, yindex, yoffset;
222
501k
  JDIMENSION start_col;
223
501k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
501k
  JBLOCKROW buffer_ptr;
225
501k
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
1.02M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
522k
    compptr = cinfo->cur_comp_info[ci];
230
522k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
522k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
522k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
522k
       (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
522k
  }
239
240
  /* Loop to process one whole iMCU row */
241
1.29M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
789k
       yoffset++) {
243
6.37M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
5.58M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
5.58M
      blkn = 0;                 /* index of current DCT block within MCU */
247
11.3M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
5.74M
        compptr = cinfo->cur_comp_info[ci];
249
5.74M
        start_col = MCU_col_num * compptr->MCU_width;
250
11.6M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
5.88M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
11.9M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
6.08M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
6.08M
          }
255
5.88M
        }
256
5.74M
      }
257
5.58M
      if (!cinfo->entropy->insufficient_data)
258
5.58M
        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
5.58M
      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
5.58M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
789k
    coef->MCU_ctr = 0;
282
789k
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
501k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
497k
    start_iMCU_row(cinfo);
286
497k
    return JPEG_ROW_COMPLETED;
287
497k
  }
288
  /* Completed the scan */
289
3.91k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
3.91k
  return JPEG_SCAN_COMPLETED;
291
501k
}
jdcoefct-12.c:consume_data
Line
Count
Source
218
251k
{
219
251k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
251k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
251k
  int blkn, ci, xindex, yindex, yoffset;
222
251k
  JDIMENSION start_col;
223
251k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
251k
  JBLOCKROW buffer_ptr;
225
251k
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
623k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
371k
    compptr = cinfo->cur_comp_info[ci];
230
371k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
371k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
371k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
371k
       (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
371k
  }
239
240
  /* Loop to process one whole iMCU row */
241
662k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
410k
       yoffset++) {
243
1.46M
    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
2.39M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
1.34M
        compptr = cinfo->cur_comp_info[ci];
249
1.34M
        start_col = MCU_col_num * compptr->MCU_width;
250
3.13M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
1.79M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
4.29M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
2.50M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
2.50M
          }
255
1.79M
        }
256
1.34M
      }
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
410k
    coef->MCU_ctr = 0;
282
410k
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
251k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
249k
    start_iMCU_row(cinfo);
286
249k
    return JPEG_ROW_COMPLETED;
287
249k
  }
288
  /* Completed the scan */
289
1.91k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
1.91k
  return JPEG_SCAN_COMPLETED;
291
251k
}
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
43.8k
{
305
43.8k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
43.8k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
43.8k
  JDIMENSION block_num;
308
43.8k
  int ci, block_row, block_rows;
309
43.8k
  JBLOCKARRAY buffer;
310
43.8k
  JBLOCKROW buffer_ptr;
311
43.8k
  _JSAMPARRAY output_ptr;
312
43.8k
  JDIMENSION output_col;
313
43.8k
  jpeg_component_info *compptr;
314
43.8k
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
43.8k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
43.8k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
43.8k
          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
118k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
74.6k
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
74.6k
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
74.6k
    buffer = (*cinfo->mem->access_virt_barray)
332
74.6k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
74.6k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
74.6k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
74.6k
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
74.0k
      block_rows = compptr->v_samp_factor;
338
547
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
547
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
547
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
547
    }
343
74.6k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
74.6k
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
218k
    for (block_row = 0; block_row < block_rows; block_row++) {
347
143k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
143k
      output_col = 0;
349
143k
      for (block_num = cinfo->master->first_MCU_col[ci];
350
1.02M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
883k
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
883k
                        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
883k
        buffer_ptr++;
361
883k
        output_col += compptr->_DCT_scaled_size;
362
883k
      }
363
143k
      output_ptr += compptr->_DCT_scaled_size;
364
143k
    }
365
74.6k
  }
366
367
43.8k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
43.5k
    return JPEG_ROW_COMPLETED;
369
251
  return JPEG_SCAN_COMPLETED;
370
43.8k
}
jdcoefct-8.c:decompress_data
Line
Count
Source
304
43.8k
{
305
43.8k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
43.8k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
43.8k
  JDIMENSION block_num;
308
43.8k
  int ci, block_row, block_rows;
309
43.8k
  JBLOCKARRAY buffer;
310
43.8k
  JBLOCKROW buffer_ptr;
311
43.8k
  _JSAMPARRAY output_ptr;
312
43.8k
  JDIMENSION output_col;
313
43.8k
  jpeg_component_info *compptr;
314
43.8k
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
43.8k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
43.8k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
43.8k
          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
118k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
74.6k
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
74.6k
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
74.6k
    buffer = (*cinfo->mem->access_virt_barray)
332
74.6k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
74.6k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
74.6k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
74.6k
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
74.0k
      block_rows = compptr->v_samp_factor;
338
547
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
547
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
547
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
547
    }
343
74.6k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
74.6k
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
218k
    for (block_row = 0; block_row < block_rows; block_row++) {
347
143k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
143k
      output_col = 0;
349
143k
      for (block_num = cinfo->master->first_MCU_col[ci];
350
1.02M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
883k
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
883k
                        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
883k
        buffer_ptr++;
361
883k
        output_col += compptr->_DCT_scaled_size;
362
883k
      }
363
143k
      output_ptr += compptr->_DCT_scaled_size;
364
143k
    }
365
74.6k
  }
366
367
43.8k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
43.5k
    return JPEG_ROW_COMPLETED;
369
251
  return JPEG_SCAN_COMPLETED;
370
43.8k
}
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
149k
#define Q01_POS  1
386
149k
#define Q10_POS  8
387
149k
#define Q20_POS  16
388
149k
#define Q11_POS  9
389
149k
#define Q02_POS  2
390
81.5k
#define Q03_POS  3
391
81.5k
#define Q12_POS  10
392
81.5k
#define Q21_POS  17
393
81.5k
#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
785
{
406
785
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
785
  boolean smoothing_useful = FALSE;
408
785
  int ci, coefi;
409
785
  jpeg_component_info *compptr;
410
785
  JQUANT_TBL *qtable;
411
785
  int *coef_bits, *prev_coef_bits;
412
785
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
785
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
53
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
732
  if (coef->coef_bits_latch == NULL)
419
732
    coef->coef_bits_latch = (int *)
420
732
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
732
                                  cinfo->num_components * 2 *
422
732
                                  (SAVED_COEFS * sizeof(int)));
423
732
  coef_bits_latch = coef->coef_bits_latch;
424
732
  prev_coef_bits_latch =
425
732
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
1.30k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
813
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
813
    if ((qtable = compptr->quant_table) == NULL)
431
56
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
757
    if (qtable->quantval[0] == 0 ||
434
742
        qtable->quantval[Q01_POS] == 0 ||
435
693
        qtable->quantval[Q10_POS] == 0 ||
436
682
        qtable->quantval[Q20_POS] == 0 ||
437
646
        qtable->quantval[Q11_POS] == 0 ||
438
628
        qtable->quantval[Q02_POS] == 0 ||
439
621
        qtable->quantval[Q03_POS] == 0 ||
440
611
        qtable->quantval[Q12_POS] == 0 ||
441
599
        qtable->quantval[Q21_POS] == 0 ||
442
586
        qtable->quantval[Q30_POS] == 0)
443
183
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
574
    coef_bits = cinfo->coef_bits[ci];
446
574
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
574
    if (coef_bits[0] < 0)
448
0
      return FALSE;
449
574
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
5.74k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
5.16k
      if (cinfo->input_scan_number > 1)
453
2.51k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
2.65k
      else
455
2.65k
        prev_coef_bits_latch[coefi] = -1;
456
5.16k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
5.16k
      if (coef_bits[coefi] != 0)
458
4.83k
        smoothing_useful = TRUE;
459
5.16k
    }
460
574
    coef_bits_latch += SAVED_COEFS;
461
574
    prev_coef_bits_latch += SAVED_COEFS;
462
574
  }
463
464
493
  return smoothing_useful;
465
732
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
405
691
{
406
691
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
691
  boolean smoothing_useful = FALSE;
408
691
  int ci, coefi;
409
691
  jpeg_component_info *compptr;
410
691
  JQUANT_TBL *qtable;
411
691
  int *coef_bits, *prev_coef_bits;
412
691
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
691
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
48
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
643
  if (coef->coef_bits_latch == NULL)
419
643
    coef->coef_bits_latch = (int *)
420
643
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
643
                                  cinfo->num_components * 2 *
422
643
                                  (SAVED_COEFS * sizeof(int)));
423
643
  coef_bits_latch = coef->coef_bits_latch;
424
643
  prev_coef_bits_latch =
425
643
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
1.14k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
699
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
699
    if ((qtable = compptr->quant_table) == NULL)
431
50
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
649
    if (qtable->quantval[0] == 0 ||
434
639
        qtable->quantval[Q01_POS] == 0 ||
435
592
        qtable->quantval[Q10_POS] == 0 ||
436
583
        qtable->quantval[Q20_POS] == 0 ||
437
549
        qtable->quantval[Q11_POS] == 0 ||
438
536
        qtable->quantval[Q02_POS] == 0 ||
439
532
        qtable->quantval[Q03_POS] == 0 ||
440
527
        qtable->quantval[Q12_POS] == 0 ||
441
518
        qtable->quantval[Q21_POS] == 0 ||
442
508
        qtable->quantval[Q30_POS] == 0)
443
150
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
499
    coef_bits = cinfo->coef_bits[ci];
446
499
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
499
    if (coef_bits[0] < 0)
448
0
      return FALSE;
449
499
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
4.99k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
4.49k
      if (cinfo->input_scan_number > 1)
453
2.19k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
2.29k
      else
455
2.29k
        prev_coef_bits_latch[coefi] = -1;
456
4.49k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
4.49k
      if (coef_bits[coefi] != 0)
458
4.26k
        smoothing_useful = TRUE;
459
4.49k
    }
460
499
    coef_bits_latch += SAVED_COEFS;
461
499
    prev_coef_bits_latch += SAVED_COEFS;
462
499
  }
463
464
443
  return smoothing_useful;
465
643
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
405
94
{
406
94
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
94
  boolean smoothing_useful = FALSE;
408
94
  int ci, coefi;
409
94
  jpeg_component_info *compptr;
410
94
  JQUANT_TBL *qtable;
411
94
  int *coef_bits, *prev_coef_bits;
412
94
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
94
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
5
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
89
  if (coef->coef_bits_latch == NULL)
419
89
    coef->coef_bits_latch = (int *)
420
89
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
89
                                  cinfo->num_components * 2 *
422
89
                                  (SAVED_COEFS * sizeof(int)));
423
89
  coef_bits_latch = coef->coef_bits_latch;
424
89
  prev_coef_bits_latch =
425
89
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
164
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
114
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
114
    if ((qtable = compptr->quant_table) == NULL)
431
6
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
108
    if (qtable->quantval[0] == 0 ||
434
103
        qtable->quantval[Q01_POS] == 0 ||
435
101
        qtable->quantval[Q10_POS] == 0 ||
436
99
        qtable->quantval[Q20_POS] == 0 ||
437
97
        qtable->quantval[Q11_POS] == 0 ||
438
92
        qtable->quantval[Q02_POS] == 0 ||
439
89
        qtable->quantval[Q03_POS] == 0 ||
440
84
        qtable->quantval[Q12_POS] == 0 ||
441
81
        qtable->quantval[Q21_POS] == 0 ||
442
78
        qtable->quantval[Q30_POS] == 0)
443
33
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
75
    coef_bits = cinfo->coef_bits[ci];
446
75
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
75
    if (coef_bits[0] < 0)
448
0
      return FALSE;
449
75
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
750
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
675
      if (cinfo->input_scan_number > 1)
453
315
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
360
      else
455
360
        prev_coef_bits_latch[coefi] = -1;
456
675
      coef_bits_latch[coefi] = coef_bits[coefi];
457
675
      if (coef_bits[coefi] != 0)
458
568
        smoothing_useful = TRUE;
459
675
    }
460
75
    coef_bits_latch += SAVED_COEFS;
461
75
    prev_coef_bits_latch += SAVED_COEFS;
462
75
  }
463
464
50
  return smoothing_useful;
465
89
}
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
145k
{
475
145k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
145k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
145k
  JDIMENSION block_num, last_block_column;
478
145k
  int ci, block_row, block_rows, access_rows, image_block_row,
479
145k
    image_block_rows;
480
145k
  JBLOCKARRAY buffer;
481
145k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
145k
  JBLOCKROW next_block_row, next_next_block_row;
483
145k
  _JSAMPARRAY output_ptr;
484
145k
  JDIMENSION output_col;
485
145k
  jpeg_component_info *compptr;
486
145k
  _inverse_DCT_method_ptr inverse_DCT;
487
145k
  boolean change_dc;
488
145k
  JCOEF *workspace;
489
145k
  int *coef_bits;
490
145k
  JQUANT_TBL *quanttbl;
491
145k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
145k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
145k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
145k
      DC25;
495
145k
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
145k
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
145k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
145k
         !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
294k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
149k
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
149k
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
149k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
148k
      block_rows = compptr->v_samp_factor;
526
148k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
148k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
414
      block_rows = compptr->v_samp_factor;
529
414
      access_rows = block_rows * 2; /* this and next iMCU row */
530
476
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
476
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
476
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
476
      access_rows = block_rows; /* this iMCU row only */
535
476
    }
536
    /* Align the virtual buffer for this component. */
537
149k
    if (cinfo->output_iMCU_row > 1) {
538
148k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
148k
      buffer = (*cinfo->mem->access_virt_barray)
540
148k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
148k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
148k
         (JDIMENSION)access_rows, FALSE);
543
148k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
148k
    } else if (cinfo->output_iMCU_row > 0) {
545
414
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
414
      buffer = (*cinfo->mem->access_virt_barray)
547
414
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
414
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
414
         (JDIMENSION)access_rows, FALSE);
550
414
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
476
    } else {
552
476
      buffer = (*cinfo->mem->access_virt_barray)
553
476
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
476
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
476
    }
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
149k
    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
149k
    else
564
149k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
565
566
    /* We only do DC interpolation if no AC coefficient data is available. */
567
149k
    change_dc =
568
149k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
120k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
91.3k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
149k
    quanttbl = compptr->quant_table;
573
149k
    Q00 = quanttbl->quantval[0];
574
149k
    Q01 = quanttbl->quantval[Q01_POS];
575
149k
    Q10 = quanttbl->quantval[Q10_POS];
576
149k
    Q20 = quanttbl->quantval[Q20_POS];
577
149k
    Q11 = quanttbl->quantval[Q11_POS];
578
149k
    Q02 = quanttbl->quantval[Q02_POS];
579
149k
    if (change_dc) {
580
80.9k
      Q03 = quanttbl->quantval[Q03_POS];
581
80.9k
      Q12 = quanttbl->quantval[Q12_POS];
582
80.9k
      Q21 = quanttbl->quantval[Q21_POS];
583
80.9k
      Q30 = quanttbl->quantval[Q30_POS];
584
80.9k
    }
585
149k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
149k
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
149k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
402k
    for (block_row = 0; block_row < block_rows; block_row++) {
590
253k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
253k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
253k
      if (image_block_row > 0)
594
252k
        prev_block_row =
595
252k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
476
      else
597
476
        prev_block_row = buffer_ptr;
598
599
253k
      if (image_block_row > 1)
600
252k
        prev_prev_block_row =
601
252k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
928
      else
603
928
        prev_prev_block_row = prev_block_row;
604
605
253k
      if (image_block_row < image_block_rows - 1)
606
252k
        next_block_row =
607
252k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
476
      else
609
476
        next_block_row = buffer_ptr;
610
611
253k
      if (image_block_row < image_block_rows - 2)
612
252k
        next_next_block_row =
613
252k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
828
      else
615
828
        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
253k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
253k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
253k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
253k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
253k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
253k
      output_col = 0;
626
253k
      last_block_column = compptr->width_in_blocks - 1;
627
253k
      for (block_num = cinfo->master->first_MCU_col[ci];
628
1.70M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
1.45M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
1.45M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
253k
            block_num < last_block_column) {
634
111k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
111k
          DC09 = DC10 = (int)prev_block_row[1][0];
636
111k
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
111k
          DC19 = DC20 = (int)next_block_row[1][0];
638
111k
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
111k
        }
640
1.45M
        if (block_num + 1 < last_block_column) {
641
1.08M
          DC05 = (int)prev_prev_block_row[2][0];
642
1.08M
          DC10 = (int)prev_block_row[2][0];
643
1.08M
          DC15 = (int)buffer_ptr[2][0];
644
1.08M
          DC20 = (int)next_block_row[2][0];
645
1.08M
          DC25 = (int)next_next_block_row[2][0];
646
1.08M
        }
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
1.45M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
1.35M
          num = Q00 * (change_dc ?
660
850k
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
850k
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
850k
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
850k
                 DC21 - DC22 + DC24 + DC25) :
664
1.35M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
1.35M
          if (num >= 0) {
666
972k
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
972k
            if (Al > 0 && pred >= (1 << Al))
668
95.8k
              pred = (1 << Al) - 1;
669
972k
          } else {
670
382k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
382k
            if (Al > 0 && pred >= (1 << Al))
672
67.5k
              pred = (1 << Al) - 1;
673
382k
            pred = -pred;
674
382k
          }
675
1.35M
          workspace[1] = (JCOEF)pred;
676
1.35M
        }
677
        /* AC10 */
678
1.45M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
1.40M
          num = Q00 * (change_dc ?
680
850k
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
850k
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
850k
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
850k
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
1.40M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
1.40M
          if (num >= 0) {
686
980k
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
980k
            if (Al > 0 && pred >= (1 << Al))
688
139k
              pred = (1 << Al) - 1;
689
980k
          } else {
690
420k
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
420k
            if (Al > 0 && pred >= (1 << Al))
692
119k
              pred = (1 << Al) - 1;
693
420k
            pred = -pred;
694
420k
          }
695
1.40M
          workspace[8] = (JCOEF)pred;
696
1.40M
        }
697
        /* AC20 */
698
1.45M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
1.41M
          num = Q00 * (change_dc ?
700
850k
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
850k
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
1.41M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
1.41M
          if (num >= 0) {
704
808k
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
808k
            if (Al > 0 && pred >= (1 << Al))
706
114k
              pred = (1 << Al) - 1;
707
808k
          } else {
708
605k
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
605k
            if (Al > 0 && pred >= (1 << Al))
710
115k
              pred = (1 << Al) - 1;
711
605k
            pred = -pred;
712
605k
          }
713
1.41M
          workspace[16] = (JCOEF)pred;
714
1.41M
        }
715
        /* AC11 */
716
1.45M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
1.40M
          num = Q00 * (change_dc ?
718
850k
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
850k
                 9 * DC19 + DC21 - DC25) :
720
1.40M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
552k
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
1.40M
          if (num >= 0) {
723
1.06M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
1.06M
            if (Al > 0 && pred >= (1 << Al))
725
53.6k
              pred = (1 << Al) - 1;
726
1.06M
          } else {
727
341k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
341k
            if (Al > 0 && pred >= (1 << Al))
729
55.0k
              pred = (1 << Al) - 1;
730
341k
            pred = -pred;
731
341k
          }
732
1.40M
          workspace[9] = (JCOEF)pred;
733
1.40M
        }
734
        /* AC02 */
735
1.45M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
1.40M
          num = Q00 * (change_dc ?
737
850k
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
850k
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
1.40M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
1.40M
          if (num >= 0) {
741
784k
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
784k
            if (Al > 0 && pred >= (1 << Al))
743
76.9k
              pred = (1 << Al) - 1;
744
784k
          } else {
745
623k
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
623k
            if (Al > 0 && pred >= (1 << Al))
747
78.4k
              pred = (1 << Al) - 1;
748
623k
            pred = -pred;
749
623k
          }
750
1.40M
          workspace[2] = (JCOEF)pred;
751
1.40M
        }
752
1.45M
        if (change_dc) {
753
          /* AC03 */
754
850k
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
850k
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
850k
            if (num >= 0) {
757
609k
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
609k
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
609k
            } else {
761
241k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
241k
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
241k
              pred = -pred;
765
241k
            }
766
850k
            workspace[3] = (JCOEF)pred;
767
850k
          }
768
          /* AC12 */
769
850k
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
850k
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
850k
            if (num >= 0) {
772
372k
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
372k
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
478k
            } else {
776
478k
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
478k
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
478k
              pred = -pred;
780
478k
            }
781
850k
            workspace[10] = (JCOEF)pred;
782
850k
          }
783
          /* AC21 */
784
850k
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
850k
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
850k
            if (num >= 0) {
787
408k
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
408k
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
442k
            } else {
791
442k
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
442k
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
442k
              pred = -pred;
795
442k
            }
796
850k
            workspace[17] = (JCOEF)pred;
797
850k
          }
798
          /* AC30 */
799
850k
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
850k
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
850k
            if (num >= 0) {
802
604k
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
604k
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
604k
            } else {
806
246k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
246k
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
246k
              pred = -pred;
810
246k
            }
811
850k
            workspace[24] = (JCOEF)pred;
812
850k
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
850k
          num = Q00 *
817
850k
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
850k
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
850k
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
850k
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
850k
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
850k
          if (num >= 0) {
823
325k
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
525k
          } else {
825
525k
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
525k
            pred = -pred;
827
525k
          }
828
850k
          workspace[0] = (JCOEF)pred;
829
850k
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
1.45M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
1.45M
                        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
1.45M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
1.45M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
1.45M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
1.45M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
1.45M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
1.45M
        buffer_ptr++, prev_block_row++, next_block_row++,
848
1.45M
          prev_prev_block_row++, next_next_block_row++;
849
1.45M
        output_col += compptr->_DCT_scaled_size;
850
1.45M
      }
851
253k
      output_ptr += compptr->_DCT_scaled_size;
852
253k
    }
853
149k
  }
854
855
145k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
144k
    return JPEG_ROW_COMPLETED;
857
440
  return JPEG_SCAN_COMPLETED;
858
145k
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
474
145k
{
475
145k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
145k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
145k
  JDIMENSION block_num, last_block_column;
478
145k
  int ci, block_row, block_rows, access_rows, image_block_row,
479
145k
    image_block_rows;
480
145k
  JBLOCKARRAY buffer;
481
145k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
145k
  JBLOCKROW next_block_row, next_next_block_row;
483
145k
  _JSAMPARRAY output_ptr;
484
145k
  JDIMENSION output_col;
485
145k
  jpeg_component_info *compptr;
486
145k
  _inverse_DCT_method_ptr inverse_DCT;
487
145k
  boolean change_dc;
488
145k
  JCOEF *workspace;
489
145k
  int *coef_bits;
490
145k
  JQUANT_TBL *quanttbl;
491
145k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
145k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
145k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
145k
      DC25;
495
145k
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
145k
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
145k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
145k
         !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
294k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
149k
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
149k
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
149k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
148k
      block_rows = compptr->v_samp_factor;
526
148k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
148k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
414
      block_rows = compptr->v_samp_factor;
529
414
      access_rows = block_rows * 2; /* this and next iMCU row */
530
476
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
476
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
476
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
476
      access_rows = block_rows; /* this iMCU row only */
535
476
    }
536
    /* Align the virtual buffer for this component. */
537
149k
    if (cinfo->output_iMCU_row > 1) {
538
148k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
148k
      buffer = (*cinfo->mem->access_virt_barray)
540
148k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
148k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
148k
         (JDIMENSION)access_rows, FALSE);
543
148k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
148k
    } else if (cinfo->output_iMCU_row > 0) {
545
414
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
414
      buffer = (*cinfo->mem->access_virt_barray)
547
414
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
414
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
414
         (JDIMENSION)access_rows, FALSE);
550
414
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
476
    } else {
552
476
      buffer = (*cinfo->mem->access_virt_barray)
553
476
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
476
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
476
    }
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
149k
    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
149k
    else
564
149k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
565
566
    /* We only do DC interpolation if no AC coefficient data is available. */
567
149k
    change_dc =
568
149k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
120k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
91.3k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
149k
    quanttbl = compptr->quant_table;
573
149k
    Q00 = quanttbl->quantval[0];
574
149k
    Q01 = quanttbl->quantval[Q01_POS];
575
149k
    Q10 = quanttbl->quantval[Q10_POS];
576
149k
    Q20 = quanttbl->quantval[Q20_POS];
577
149k
    Q11 = quanttbl->quantval[Q11_POS];
578
149k
    Q02 = quanttbl->quantval[Q02_POS];
579
149k
    if (change_dc) {
580
80.9k
      Q03 = quanttbl->quantval[Q03_POS];
581
80.9k
      Q12 = quanttbl->quantval[Q12_POS];
582
80.9k
      Q21 = quanttbl->quantval[Q21_POS];
583
80.9k
      Q30 = quanttbl->quantval[Q30_POS];
584
80.9k
    }
585
149k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
149k
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
149k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
402k
    for (block_row = 0; block_row < block_rows; block_row++) {
590
253k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
253k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
253k
      if (image_block_row > 0)
594
252k
        prev_block_row =
595
252k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
476
      else
597
476
        prev_block_row = buffer_ptr;
598
599
253k
      if (image_block_row > 1)
600
252k
        prev_prev_block_row =
601
252k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
928
      else
603
928
        prev_prev_block_row = prev_block_row;
604
605
253k
      if (image_block_row < image_block_rows - 1)
606
252k
        next_block_row =
607
252k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
476
      else
609
476
        next_block_row = buffer_ptr;
610
611
253k
      if (image_block_row < image_block_rows - 2)
612
252k
        next_next_block_row =
613
252k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
828
      else
615
828
        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
253k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
253k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
253k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
253k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
253k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
253k
      output_col = 0;
626
253k
      last_block_column = compptr->width_in_blocks - 1;
627
253k
      for (block_num = cinfo->master->first_MCU_col[ci];
628
1.70M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
1.45M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
1.45M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
253k
            block_num < last_block_column) {
634
111k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
111k
          DC09 = DC10 = (int)prev_block_row[1][0];
636
111k
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
111k
          DC19 = DC20 = (int)next_block_row[1][0];
638
111k
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
111k
        }
640
1.45M
        if (block_num + 1 < last_block_column) {
641
1.08M
          DC05 = (int)prev_prev_block_row[2][0];
642
1.08M
          DC10 = (int)prev_block_row[2][0];
643
1.08M
          DC15 = (int)buffer_ptr[2][0];
644
1.08M
          DC20 = (int)next_block_row[2][0];
645
1.08M
          DC25 = (int)next_next_block_row[2][0];
646
1.08M
        }
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
1.45M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
1.35M
          num = Q00 * (change_dc ?
660
850k
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
850k
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
850k
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
850k
                 DC21 - DC22 + DC24 + DC25) :
664
1.35M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
1.35M
          if (num >= 0) {
666
972k
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
972k
            if (Al > 0 && pred >= (1 << Al))
668
95.8k
              pred = (1 << Al) - 1;
669
972k
          } else {
670
382k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
382k
            if (Al > 0 && pred >= (1 << Al))
672
67.5k
              pred = (1 << Al) - 1;
673
382k
            pred = -pred;
674
382k
          }
675
1.35M
          workspace[1] = (JCOEF)pred;
676
1.35M
        }
677
        /* AC10 */
678
1.45M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
1.40M
          num = Q00 * (change_dc ?
680
850k
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
850k
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
850k
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
850k
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
1.40M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
1.40M
          if (num >= 0) {
686
980k
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
980k
            if (Al > 0 && pred >= (1 << Al))
688
139k
              pred = (1 << Al) - 1;
689
980k
          } else {
690
420k
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
420k
            if (Al > 0 && pred >= (1 << Al))
692
119k
              pred = (1 << Al) - 1;
693
420k
            pred = -pred;
694
420k
          }
695
1.40M
          workspace[8] = (JCOEF)pred;
696
1.40M
        }
697
        /* AC20 */
698
1.45M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
1.41M
          num = Q00 * (change_dc ?
700
850k
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
850k
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
1.41M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
1.41M
          if (num >= 0) {
704
808k
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
808k
            if (Al > 0 && pred >= (1 << Al))
706
114k
              pred = (1 << Al) - 1;
707
808k
          } else {
708
605k
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
605k
            if (Al > 0 && pred >= (1 << Al))
710
115k
              pred = (1 << Al) - 1;
711
605k
            pred = -pred;
712
605k
          }
713
1.41M
          workspace[16] = (JCOEF)pred;
714
1.41M
        }
715
        /* AC11 */
716
1.45M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
1.40M
          num = Q00 * (change_dc ?
718
850k
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
850k
                 9 * DC19 + DC21 - DC25) :
720
1.40M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
552k
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
1.40M
          if (num >= 0) {
723
1.06M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
1.06M
            if (Al > 0 && pred >= (1 << Al))
725
53.6k
              pred = (1 << Al) - 1;
726
1.06M
          } else {
727
341k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
341k
            if (Al > 0 && pred >= (1 << Al))
729
55.0k
              pred = (1 << Al) - 1;
730
341k
            pred = -pred;
731
341k
          }
732
1.40M
          workspace[9] = (JCOEF)pred;
733
1.40M
        }
734
        /* AC02 */
735
1.45M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
1.40M
          num = Q00 * (change_dc ?
737
850k
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
850k
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
1.40M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
1.40M
          if (num >= 0) {
741
784k
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
784k
            if (Al > 0 && pred >= (1 << Al))
743
76.9k
              pred = (1 << Al) - 1;
744
784k
          } else {
745
623k
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
623k
            if (Al > 0 && pred >= (1 << Al))
747
78.4k
              pred = (1 << Al) - 1;
748
623k
            pred = -pred;
749
623k
          }
750
1.40M
          workspace[2] = (JCOEF)pred;
751
1.40M
        }
752
1.45M
        if (change_dc) {
753
          /* AC03 */
754
850k
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
850k
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
850k
            if (num >= 0) {
757
609k
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
609k
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
609k
            } else {
761
241k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
241k
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
241k
              pred = -pred;
765
241k
            }
766
850k
            workspace[3] = (JCOEF)pred;
767
850k
          }
768
          /* AC12 */
769
850k
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
850k
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
850k
            if (num >= 0) {
772
372k
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
372k
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
478k
            } else {
776
478k
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
478k
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
478k
              pred = -pred;
780
478k
            }
781
850k
            workspace[10] = (JCOEF)pred;
782
850k
          }
783
          /* AC21 */
784
850k
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
850k
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
850k
            if (num >= 0) {
787
408k
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
408k
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
442k
            } else {
791
442k
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
442k
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
442k
              pred = -pred;
795
442k
            }
796
850k
            workspace[17] = (JCOEF)pred;
797
850k
          }
798
          /* AC30 */
799
850k
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
850k
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
850k
            if (num >= 0) {
802
604k
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
604k
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
604k
            } else {
806
246k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
246k
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
246k
              pred = -pred;
810
246k
            }
811
850k
            workspace[24] = (JCOEF)pred;
812
850k
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
850k
          num = Q00 *
817
850k
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
850k
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
850k
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
850k
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
850k
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
850k
          if (num >= 0) {
823
325k
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
525k
          } else {
825
525k
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
525k
            pred = -pred;
827
525k
          }
828
850k
          workspace[0] = (JCOEF)pred;
829
850k
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
1.45M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
1.45M
                        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
1.45M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
1.45M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
1.45M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
1.45M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
1.45M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
1.45M
        buffer_ptr++, prev_block_row++, next_block_row++,
848
1.45M
          prev_prev_block_row++, next_next_block_row++;
849
1.45M
        output_col += compptr->_DCT_scaled_size;
850
1.45M
      }
851
253k
      output_ptr += compptr->_DCT_scaled_size;
852
253k
    }
853
149k
  }
854
855
145k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
144k
    return JPEG_ROW_COMPLETED;
857
440
  return JPEG_SCAN_COMPLETED;
858
145k
}
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.04k
{
870
3.04k
  my_coef_ptr coef;
871
872
3.04k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
3.04k
  coef = (my_coef_ptr)
876
3.04k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
3.04k
                                sizeof(my_coef_controller));
878
3.04k
  memset(coef, 0, sizeof(my_coef_controller));
879
3.04k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
3.04k
  coef->pub.start_input_pass = start_input_pass;
881
3.04k
  coef->pub.start_output_pass = start_output_pass;
882
3.04k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
3.04k
  coef->coef_bits_latch = NULL;
884
3.04k
#endif
885
886
  /* Create the coefficient buffer. */
887
3.04k
  if (need_full_buffer) {
888
2.11k
#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.11k
    int ci, access_rows;
893
2.11k
    jpeg_component_info *compptr;
894
895
6.41k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
4.29k
         ci++, compptr++) {
897
4.29k
      access_rows = compptr->v_samp_factor;
898
4.29k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
4.29k
      if (cinfo->progressive_mode)
901
3.21k
        access_rows *= 5;
902
4.29k
#endif
903
4.29k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
4.29k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
4.29k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
4.29k
                               (long)compptr->h_samp_factor),
907
4.29k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
4.29k
                               (long)compptr->v_samp_factor),
909
4.29k
         (JDIMENSION)access_rows);
910
4.29k
    }
911
2.11k
    coef->pub.consume_data = consume_data;
912
2.11k
    coef->pub._decompress_data = decompress_data;
913
2.11k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
2.11k
  } else {
918
    /* We only need a single-MCU buffer. */
919
933
    JBLOCKROW buffer;
920
933
    int i;
921
922
933
    buffer = (JBLOCKROW)
923
933
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
933
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
10.2k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
9.33k
      coef->MCU_buffer[i] = buffer + i;
927
9.33k
    }
928
933
    coef->pub.consume_data = dummy_consume_data;
929
933
    coef->pub._decompress_data = decompress_onepass;
930
933
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
933
  }
932
933
  /* Allocate the workspace buffer */
934
3.04k
  coef->workspace = (JCOEF *)
935
3.04k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
3.04k
                                sizeof(JCOEF) * DCTSIZE2);
937
3.04k
}
jinit_d_coef_controller
Line
Count
Source
869
2.55k
{
870
2.55k
  my_coef_ptr coef;
871
872
2.55k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
2.55k
  coef = (my_coef_ptr)
876
2.55k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
2.55k
                                sizeof(my_coef_controller));
878
2.55k
  memset(coef, 0, sizeof(my_coef_controller));
879
2.55k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
2.55k
  coef->pub.start_input_pass = start_input_pass;
881
2.55k
  coef->pub.start_output_pass = start_output_pass;
882
2.55k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
2.55k
  coef->coef_bits_latch = NULL;
884
2.55k
#endif
885
886
  /* Create the coefficient buffer. */
887
2.55k
  if (need_full_buffer) {
888
1.63k
#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.63k
    int ci, access_rows;
893
1.63k
    jpeg_component_info *compptr;
894
895
4.75k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
3.12k
         ci++, compptr++) {
897
3.12k
      access_rows = compptr->v_samp_factor;
898
3.12k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
3.12k
      if (cinfo->progressive_mode)
901
2.39k
        access_rows *= 5;
902
3.12k
#endif
903
3.12k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
3.12k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
3.12k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
3.12k
                               (long)compptr->h_samp_factor),
907
3.12k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
3.12k
                               (long)compptr->v_samp_factor),
909
3.12k
         (JDIMENSION)access_rows);
910
3.12k
    }
911
1.63k
    coef->pub.consume_data = consume_data;
912
1.63k
    coef->pub._decompress_data = decompress_data;
913
1.63k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
1.63k
  } else {
918
    /* We only need a single-MCU buffer. */
919
924
    JBLOCKROW buffer;
920
924
    int i;
921
922
924
    buffer = (JBLOCKROW)
923
924
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
924
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
10.1k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
9.24k
      coef->MCU_buffer[i] = buffer + i;
927
9.24k
    }
928
924
    coef->pub.consume_data = dummy_consume_data;
929
924
    coef->pub._decompress_data = decompress_onepass;
930
924
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
924
  }
932
933
  /* Allocate the workspace buffer */
934
2.55k
  coef->workspace = (JCOEF *)
935
2.55k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
2.55k
                                sizeof(JCOEF) * DCTSIZE2);
937
2.55k
}
j12init_d_coef_controller
Line
Count
Source
869
494
{
870
494
  my_coef_ptr coef;
871
872
494
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
494
  coef = (my_coef_ptr)
876
494
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
494
                                sizeof(my_coef_controller));
878
494
  memset(coef, 0, sizeof(my_coef_controller));
879
494
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
494
  coef->pub.start_input_pass = start_input_pass;
881
494
  coef->pub.start_output_pass = start_output_pass;
882
494
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
494
  coef->coef_bits_latch = NULL;
884
494
#endif
885
886
  /* Create the coefficient buffer. */
887
494
  if (need_full_buffer) {
888
485
#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
485
    int ci, access_rows;
893
485
    jpeg_component_info *compptr;
894
895
1.65k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
1.17k
         ci++, compptr++) {
897
1.17k
      access_rows = compptr->v_samp_factor;
898
1.17k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
1.17k
      if (cinfo->progressive_mode)
901
811
        access_rows *= 5;
902
1.17k
#endif
903
1.17k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
1.17k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
1.17k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
1.17k
                               (long)compptr->h_samp_factor),
907
1.17k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
1.17k
                               (long)compptr->v_samp_factor),
909
1.17k
         (JDIMENSION)access_rows);
910
1.17k
    }
911
485
    coef->pub.consume_data = consume_data;
912
485
    coef->pub._decompress_data = decompress_data;
913
485
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
485
  } else {
918
    /* We only need a single-MCU buffer. */
919
9
    JBLOCKROW buffer;
920
9
    int i;
921
922
9
    buffer = (JBLOCKROW)
923
9
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
9
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
99
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
90
      coef->MCU_buffer[i] = buffer + i;
927
90
    }
928
9
    coef->pub.consume_data = dummy_consume_data;
929
9
    coef->pub._decompress_data = decompress_onepass;
930
9
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
9
  }
932
933
  /* Allocate the workspace buffer */
934
494
  coef->workspace = (JCOEF *)
935
494
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
494
                                sizeof(JCOEF) * DCTSIZE2);
937
494
}