Coverage Report

Created: 2026-06-10 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/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
63.2k
{
51
63.2k
  cinfo->input_iMCU_row = 0;
52
63.2k
  start_iMCU_row(cinfo);
53
63.2k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
50
62.1k
{
51
62.1k
  cinfo->input_iMCU_row = 0;
52
62.1k
  start_iMCU_row(cinfo);
53
62.1k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
50
1.13k
{
51
1.13k
  cinfo->input_iMCU_row = 0;
52
1.13k
  start_iMCU_row(cinfo);
53
1.13k
}
54
55
56
/*
57
 * Initialize for an output processing pass.
58
 */
59
60
METHODDEF(void)
61
start_output_pass(j_decompress_ptr cinfo)
62
32.6k
{
63
32.6k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
32.6k
  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
32.6k
  if (coef->pub.coef_arrays != NULL) {
68
27.2k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
7.20k
      coef->pub._decompress_data = decompress_smooth_data;
70
20.0k
    else
71
20.0k
      coef->pub._decompress_data = decompress_data;
72
27.2k
  }
73
32.6k
#endif
74
32.6k
  cinfo->output_iMCU_row = 0;
75
32.6k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
62
32.5k
{
63
32.5k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
32.5k
  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
32.5k
  if (coef->pub.coef_arrays != NULL) {
68
27.1k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
7.17k
      coef->pub._decompress_data = decompress_smooth_data;
70
20.0k
    else
71
20.0k
      coef->pub._decompress_data = decompress_data;
72
27.1k
  }
73
32.5k
#endif
74
32.5k
  cinfo->output_iMCU_row = 0;
75
32.5k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
62
90
{
63
90
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
90
  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
90
  if (coef->pub.coef_arrays != NULL) {
68
78
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
38
      coef->pub._decompress_data = decompress_smooth_data;
70
40
    else
71
40
      coef->pub._decompress_data = decompress_data;
72
78
  }
73
90
#endif
74
90
  cinfo->output_iMCU_row = 0;
75
90
}
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
8.27M
{
91
8.27M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
8.27M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
8.27M
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
8.27M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
8.27M
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
8.27M
  _JSAMPARRAY output_ptr;
97
8.27M
  JDIMENSION start_col, output_col;
98
8.27M
  jpeg_component_info *compptr;
99
8.27M
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
17.4M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
9.16M
       yoffset++) {
104
25.4M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
16.3M
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
16.3M
      jzero_far((void *)coef->MCU_buffer[0],
108
16.3M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
16.3M
      if (!cinfo->entropy->insufficient_data)
110
11.5M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
16.3M
      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
16.3M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
16.3M
          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
16.3M
        blkn = 0;               /* index of current DCT block within MCU */
142
50.6M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
34.3M
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
34.3M
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
34.3M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
34.3M
          useful_width = (MCU_col_num < last_MCU_col) ?
151
24.0M
                         compptr->MCU_width : compptr->last_col_width;
152
34.3M
          output_ptr = output_buf[compptr->component_index] +
153
34.3M
                       yoffset * compptr->_DCT_scaled_size;
154
34.3M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
34.3M
                      compptr->MCU_sample_width;
156
72.1M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
37.7M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
37.2M
                yoffset + yindex < compptr->last_row_height) {
159
37.2M
              output_col = start_col;
160
79.4M
              for (xindex = 0; xindex < useful_width; xindex++) {
161
#ifdef WITH_PROFILE
162
                cinfo->master->start = getTime();
163
#endif
164
42.2M
                (*inverse_DCT) (cinfo, compptr,
165
42.2M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
42.2M
                                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
42.2M
                output_col += compptr->_DCT_scaled_size;
173
42.2M
              }
174
37.2M
            }
175
37.7M
            blkn += compptr->MCU_width;
176
37.7M
            output_ptr += compptr->_DCT_scaled_size;
177
37.7M
          }
178
34.3M
        }
179
16.3M
      }
180
16.3M
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
9.16M
    coef->MCU_ctr = 0;
183
9.16M
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
8.27M
  cinfo->output_iMCU_row++;
186
8.27M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
8.27M
    start_iMCU_row(cinfo);
188
8.27M
    return JPEG_ROW_COMPLETED;
189
8.27M
  }
190
  /* Completed the scan */
191
4.88k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
4.88k
  return JPEG_SCAN_COMPLETED;
193
8.27M
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
90
8.27M
{
91
8.27M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
8.27M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
8.27M
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
8.27M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
8.27M
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
8.27M
  _JSAMPARRAY output_ptr;
97
8.27M
  JDIMENSION start_col, output_col;
98
8.27M
  jpeg_component_info *compptr;
99
8.27M
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
17.4M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
9.16M
       yoffset++) {
104
25.4M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
16.3M
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
16.3M
      jzero_far((void *)coef->MCU_buffer[0],
108
16.3M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
16.3M
      if (!cinfo->entropy->insufficient_data)
110
11.5M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
16.3M
      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
16.3M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
16.3M
          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
16.3M
        blkn = 0;               /* index of current DCT block within MCU */
142
50.6M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
34.3M
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
34.3M
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
34.3M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
34.3M
          useful_width = (MCU_col_num < last_MCU_col) ?
151
24.0M
                         compptr->MCU_width : compptr->last_col_width;
152
34.3M
          output_ptr = output_buf[compptr->component_index] +
153
34.3M
                       yoffset * compptr->_DCT_scaled_size;
154
34.3M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
34.3M
                      compptr->MCU_sample_width;
156
72.1M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
37.7M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
37.2M
                yoffset + yindex < compptr->last_row_height) {
159
37.2M
              output_col = start_col;
160
79.4M
              for (xindex = 0; xindex < useful_width; xindex++) {
161
#ifdef WITH_PROFILE
162
                cinfo->master->start = getTime();
163
#endif
164
42.2M
                (*inverse_DCT) (cinfo, compptr,
165
42.2M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
42.2M
                                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
42.2M
                output_col += compptr->_DCT_scaled_size;
173
42.2M
              }
174
37.2M
            }
175
37.7M
            blkn += compptr->MCU_width;
176
37.7M
            output_ptr += compptr->_DCT_scaled_size;
177
37.7M
          }
178
34.3M
        }
179
16.3M
      }
180
16.3M
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
9.16M
    coef->MCU_ctr = 0;
183
9.16M
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
8.27M
  cinfo->output_iMCU_row++;
186
8.27M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
8.27M
    start_iMCU_row(cinfo);
188
8.27M
    return JPEG_ROW_COMPLETED;
189
8.27M
  }
190
  /* Completed the scan */
191
4.88k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
4.88k
  return JPEG_SCAN_COMPLETED;
193
8.27M
}
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
14.1M
{
219
14.1M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
14.1M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
14.1M
  int blkn, ci, xindex, yindex, yoffset;
222
14.1M
  JDIMENSION start_col;
223
14.1M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
14.1M
  JBLOCKROW buffer_ptr;
225
14.1M
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
35.2M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
21.1M
    compptr = cinfo->cur_comp_info[ci];
230
21.1M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
21.1M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
21.1M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
21.1M
       (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
21.1M
  }
239
240
  /* Loop to process one whole iMCU row */
241
33.7M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
19.6M
       yoffset++) {
243
137M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
118M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
118M
      blkn = 0;                 /* index of current DCT block within MCU */
247
252M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
134M
        compptr = cinfo->cur_comp_info[ci];
249
134M
        start_col = MCU_col_num * compptr->MCU_width;
250
276M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
142M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
304M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
162M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
162M
          }
255
142M
        }
256
134M
      }
257
118M
      if (!cinfo->entropy->insufficient_data)
258
66.5M
        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
118M
      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
118M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
19.6M
    coef->MCU_ctr = 0;
282
19.6M
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
14.1M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
14.0M
    start_iMCU_row(cinfo);
286
14.0M
    return JPEG_ROW_COMPLETED;
287
14.0M
  }
288
  /* Completed the scan */
289
57.3k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
57.3k
  return JPEG_SCAN_COMPLETED;
291
14.1M
}
jdcoefct-8.c:consume_data
Line
Count
Source
218
13.7M
{
219
13.7M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
13.7M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
13.7M
  int blkn, ci, xindex, yindex, yoffset;
222
13.7M
  JDIMENSION start_col;
223
13.7M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
13.7M
  JBLOCKROW buffer_ptr;
225
13.7M
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
34.3M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
20.5M
    compptr = cinfo->cur_comp_info[ci];
230
20.5M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
20.5M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
20.5M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
20.5M
       (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
20.5M
  }
239
240
  /* Loop to process one whole iMCU row */
241
32.9M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
19.1M
       yoffset++) {
243
133M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
113M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
113M
      blkn = 0;                 /* index of current DCT block within MCU */
247
243M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
129M
        compptr = cinfo->cur_comp_info[ci];
249
129M
        start_col = MCU_col_num * compptr->MCU_width;
250
266M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
136M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
293M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
156M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
156M
          }
255
136M
        }
256
129M
      }
257
113M
      if (!cinfo->entropy->insufficient_data)
258
62.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
113M
      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
113M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
19.1M
    coef->MCU_ctr = 0;
282
19.1M
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
13.7M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
13.6M
    start_iMCU_row(cinfo);
286
13.6M
    return JPEG_ROW_COMPLETED;
287
13.6M
  }
288
  /* Completed the scan */
289
56.3k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
56.3k
  return JPEG_SCAN_COMPLETED;
291
13.7M
}
jdcoefct-12.c:consume_data
Line
Count
Source
218
362k
{
219
362k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
362k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
362k
  int blkn, ci, xindex, yindex, yoffset;
222
362k
  JDIMENSION start_col;
223
362k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
362k
  JBLOCKROW buffer_ptr;
225
362k
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
913k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
550k
    compptr = cinfo->cur_comp_info[ci];
230
550k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
550k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
550k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
550k
       (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
550k
  }
239
240
  /* Loop to process one whole iMCU row */
241
792k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
430k
       yoffset++) {
243
4.81M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
4.38M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
4.38M
      blkn = 0;                 /* index of current DCT block within MCU */
247
9.14M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
4.76M
        compptr = cinfo->cur_comp_info[ci];
249
4.76M
        start_col = MCU_col_num * compptr->MCU_width;
250
10.0M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
5.29M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
10.9M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
5.63M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
5.63M
          }
255
5.29M
        }
256
4.76M
      }
257
4.38M
      if (!cinfo->entropy->insufficient_data)
258
3.64M
        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
4.38M
      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
4.38M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
430k
    coef->MCU_ctr = 0;
282
430k
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
362k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
361k
    start_iMCU_row(cinfo);
286
361k
    return JPEG_ROW_COMPLETED;
287
361k
  }
288
  /* Completed the scan */
289
1.04k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
1.04k
  return JPEG_SCAN_COMPLETED;
291
362k
}
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
3.38M
{
305
3.38M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
3.38M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
3.38M
  JDIMENSION block_num;
308
3.38M
  int ci, block_row, block_rows;
309
3.38M
  JBLOCKARRAY buffer;
310
3.38M
  JBLOCKROW buffer_ptr;
311
3.38M
  _JSAMPARRAY output_ptr;
312
3.38M
  JDIMENSION output_col;
313
3.38M
  jpeg_component_info *compptr;
314
3.38M
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
6.73M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
6.73M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
6.73M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
320
3.34M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
321
0
      return JPEG_SUSPENDED;
322
3.34M
  }
323
324
  /* OK, output from the virtual arrays. */
325
11.4M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
8.05M
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
8.05M
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
8.05M
    buffer = (*cinfo->mem->access_virt_barray)
332
8.05M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
8.05M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
8.05M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
8.05M
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
8.00M
      block_rows = compptr->v_samp_factor;
338
54.5k
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
54.5k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
54.5k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
54.5k
    }
343
8.05M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
8.05M
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
18.4M
    for (block_row = 0; block_row < block_rows; block_row++) {
347
10.4M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
10.4M
      output_col = 0;
349
10.4M
      for (block_num = cinfo->master->first_MCU_col[ci];
350
84.2M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
73.8M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
73.8M
                        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
73.8M
        buffer_ptr++;
361
73.8M
        output_col += compptr->_DCT_scaled_size;
362
73.8M
      }
363
10.4M
      output_ptr += compptr->_DCT_scaled_size;
364
10.4M
    }
365
8.05M
  }
366
367
3.38M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
3.36M
    return JPEG_ROW_COMPLETED;
369
19.5k
  return JPEG_SCAN_COMPLETED;
370
3.38M
}
jdcoefct-8.c:decompress_data
Line
Count
Source
304
3.38M
{
305
3.38M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
3.38M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
3.38M
  JDIMENSION block_num;
308
3.38M
  int ci, block_row, block_rows;
309
3.38M
  JBLOCKARRAY buffer;
310
3.38M
  JBLOCKROW buffer_ptr;
311
3.38M
  _JSAMPARRAY output_ptr;
312
3.38M
  JDIMENSION output_col;
313
3.38M
  jpeg_component_info *compptr;
314
3.38M
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
6.73M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
6.73M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
6.73M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
320
3.34M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
321
0
      return JPEG_SUSPENDED;
322
3.34M
  }
323
324
  /* OK, output from the virtual arrays. */
325
11.4M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
8.05M
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
8.05M
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
8.05M
    buffer = (*cinfo->mem->access_virt_barray)
332
8.05M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
8.05M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
8.05M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
8.05M
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
8.00M
      block_rows = compptr->v_samp_factor;
338
54.5k
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
54.5k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
54.5k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
54.5k
    }
343
8.05M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
8.05M
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
18.4M
    for (block_row = 0; block_row < block_rows; block_row++) {
347
10.4M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
10.4M
      output_col = 0;
349
10.4M
      for (block_num = cinfo->master->first_MCU_col[ci];
350
84.2M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
73.8M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
73.8M
                        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
73.8M
        buffer_ptr++;
361
73.8M
        output_col += compptr->_DCT_scaled_size;
362
73.8M
      }
363
10.4M
      output_ptr += compptr->_DCT_scaled_size;
364
10.4M
    }
365
8.05M
  }
366
367
3.38M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
3.36M
    return JPEG_ROW_COMPLETED;
369
19.5k
  return JPEG_SCAN_COMPLETED;
370
3.38M
}
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
6.81M
#define Q01_POS  1
386
6.81M
#define Q10_POS  8
387
6.81M
#define Q20_POS  16
388
6.81M
#define Q11_POS  9
389
6.81M
#define Q02_POS  2
390
3.65M
#define Q03_POS  3
391
3.65M
#define Q12_POS  10
392
3.64M
#define Q21_POS  17
393
3.64M
#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
27.2k
{
406
27.2k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
27.2k
  boolean smoothing_useful = FALSE;
408
27.2k
  int ci, coefi;
409
27.2k
  jpeg_component_info *compptr;
410
27.2k
  JQUANT_TBL *qtable;
411
27.2k
  int *coef_bits, *prev_coef_bits;
412
27.2k
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
27.2k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
12.5k
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
14.7k
  if (coef->coef_bits_latch == NULL)
419
4.33k
    coef->coef_bits_latch = (int *)
420
4.33k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
4.33k
                                  cinfo->num_components * 2 *
422
4.33k
                                  (SAVED_COEFS * sizeof(int)));
423
14.7k
  coef_bits_latch = coef->coef_bits_latch;
424
14.7k
  prev_coef_bits_latch =
425
14.7k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
30.3k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
23.0k
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
23.0k
    if ((qtable = compptr->quant_table) == NULL)
431
1.81k
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
21.2k
    if (qtable->quantval[0] == 0 ||
434
20.9k
        qtable->quantval[Q01_POS] == 0 ||
435
20.5k
        qtable->quantval[Q10_POS] == 0 ||
436
20.2k
        qtable->quantval[Q20_POS] == 0 ||
437
19.8k
        qtable->quantval[Q11_POS] == 0 ||
438
19.5k
        qtable->quantval[Q02_POS] == 0 ||
439
19.3k
        qtable->quantval[Q03_POS] == 0 ||
440
18.9k
        qtable->quantval[Q12_POS] == 0 ||
441
17.4k
        qtable->quantval[Q21_POS] == 0 ||
442
16.8k
        qtable->quantval[Q30_POS] == 0)
443
4.89k
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
16.3k
    coef_bits = cinfo->coef_bits[ci];
446
16.3k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
16.3k
    if (coef_bits[0] < 0)
448
770
      return FALSE;
449
15.5k
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
155k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
140k
      if (cinfo->input_scan_number > 1)
453
137k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
2.81k
      else
455
2.81k
        prev_coef_bits_latch[coefi] = -1;
456
140k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
140k
      if (coef_bits[coefi] != 0)
458
137k
        smoothing_useful = TRUE;
459
140k
    }
460
15.5k
    coef_bits_latch += SAVED_COEFS;
461
15.5k
    prev_coef_bits_latch += SAVED_COEFS;
462
15.5k
  }
463
464
7.26k
  return smoothing_useful;
465
14.7k
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
405
27.1k
{
406
27.1k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
27.1k
  boolean smoothing_useful = FALSE;
408
27.1k
  int ci, coefi;
409
27.1k
  jpeg_component_info *compptr;
410
27.1k
  JQUANT_TBL *qtable;
411
27.1k
  int *coef_bits, *prev_coef_bits;
412
27.1k
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
27.1k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
12.4k
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
14.6k
  if (coef->coef_bits_latch == NULL)
419
4.26k
    coef->coef_bits_latch = (int *)
420
4.26k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
4.26k
                                  cinfo->num_components * 2 *
422
4.26k
                                  (SAVED_COEFS * sizeof(int)));
423
14.6k
  coef_bits_latch = coef->coef_bits_latch;
424
14.6k
  prev_coef_bits_latch =
425
14.6k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
30.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
22.9k
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
22.9k
    if ((qtable = compptr->quant_table) == NULL)
431
1.81k
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
21.1k
    if (qtable->quantval[0] == 0 ||
434
20.9k
        qtable->quantval[Q01_POS] == 0 ||
435
20.5k
        qtable->quantval[Q10_POS] == 0 ||
436
20.2k
        qtable->quantval[Q20_POS] == 0 ||
437
19.7k
        qtable->quantval[Q11_POS] == 0 ||
438
19.5k
        qtable->quantval[Q02_POS] == 0 ||
439
19.2k
        qtable->quantval[Q03_POS] == 0 ||
440
18.9k
        qtable->quantval[Q12_POS] == 0 ||
441
17.4k
        qtable->quantval[Q21_POS] == 0 ||
442
16.7k
        qtable->quantval[Q30_POS] == 0)
443
4.87k
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
16.2k
    coef_bits = cinfo->coef_bits[ci];
446
16.2k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
16.2k
    if (coef_bits[0] < 0)
448
769
      return FALSE;
449
15.5k
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
155k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
139k
      if (cinfo->input_scan_number > 1)
453
137k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
2.73k
      else
455
2.73k
        prev_coef_bits_latch[coefi] = -1;
456
139k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
139k
      if (coef_bits[coefi] != 0)
458
136k
        smoothing_useful = TRUE;
459
139k
    }
460
15.5k
    coef_bits_latch += SAVED_COEFS;
461
15.5k
    prev_coef_bits_latch += SAVED_COEFS;
462
15.5k
  }
463
464
7.22k
  return smoothing_useful;
465
14.6k
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
405
78
{
406
78
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
78
  boolean smoothing_useful = FALSE;
408
78
  int ci, coefi;
409
78
  jpeg_component_info *compptr;
410
78
  JQUANT_TBL *qtable;
411
78
  int *coef_bits, *prev_coef_bits;
412
78
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
78
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
12
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
66
  if (coef->coef_bits_latch == NULL)
419
66
    coef->coef_bits_latch = (int *)
420
66
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
66
                                  cinfo->num_components * 2 *
422
66
                                  (SAVED_COEFS * sizeof(int)));
423
66
  coef_bits_latch = coef->coef_bits_latch;
424
66
  prev_coef_bits_latch =
425
66
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
118
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
79
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
79
    if ((qtable = compptr->quant_table) == NULL)
431
3
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
76
    if (qtable->quantval[0] == 0 ||
434
75
        qtable->quantval[Q01_POS] == 0 ||
435
73
        qtable->quantval[Q10_POS] == 0 ||
436
72
        qtable->quantval[Q20_POS] == 0 ||
437
69
        qtable->quantval[Q11_POS] == 0 ||
438
67
        qtable->quantval[Q02_POS] == 0 ||
439
66
        qtable->quantval[Q03_POS] == 0 ||
440
64
        qtable->quantval[Q12_POS] == 0 ||
441
61
        qtable->quantval[Q21_POS] == 0 ||
442
59
        qtable->quantval[Q30_POS] == 0)
443
23
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
53
    coef_bits = cinfo->coef_bits[ci];
446
53
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
53
    if (coef_bits[0] < 0)
448
1
      return FALSE;
449
52
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
520
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
468
      if (cinfo->input_scan_number > 1)
453
387
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
81
      else
455
81
        prev_coef_bits_latch[coefi] = -1;
456
468
      coef_bits_latch[coefi] = coef_bits[coefi];
457
468
      if (coef_bits[coefi] != 0)
458
432
        smoothing_useful = TRUE;
459
468
    }
460
52
    coef_bits_latch += SAVED_COEFS;
461
52
    prev_coef_bits_latch += SAVED_COEFS;
462
52
  }
463
464
39
  return smoothing_useful;
465
66
}
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
2.60M
{
475
2.60M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
2.60M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
2.60M
  JDIMENSION block_num, last_block_column;
478
2.60M
  int ci, block_row, block_rows, access_rows, image_block_row,
479
2.60M
    image_block_rows;
480
2.60M
  JBLOCKARRAY buffer;
481
2.60M
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
2.60M
  JBLOCKROW next_block_row, next_next_block_row;
483
2.60M
  _JSAMPARRAY output_ptr;
484
2.60M
  JDIMENSION output_col;
485
2.60M
  jpeg_component_info *compptr;
486
2.60M
  _inverse_DCT_method_ptr inverse_DCT;
487
2.60M
  boolean change_dc;
488
2.60M
  JCOEF *workspace;
489
2.60M
  int *coef_bits;
490
2.60M
  JQUANT_TBL *quanttbl;
491
2.60M
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
2.60M
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
2.60M
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
2.60M
      DC25;
495
2.60M
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
2.60M
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
5.14M
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
5.13M
         !cinfo->inputctl->eoi_reached) {
503
5.13M
    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
5.13M
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
510
5.13M
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
511
2.58M
        break;
512
5.13M
    }
513
2.55M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
514
12.3k
      return JPEG_SUSPENDED;
515
2.55M
  }
516
517
  /* OK, output from the virtual arrays. */
518
9.38M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
6.79M
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
6.79M
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
6.79M
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
6.77M
      block_rows = compptr->v_samp_factor;
526
6.77M
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
6.77M
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
8.72k
      block_rows = compptr->v_samp_factor;
529
8.72k
      access_rows = block_rows * 2; /* this and next iMCU row */
530
10.2k
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
10.2k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
10.2k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
10.2k
      access_rows = block_rows; /* this iMCU row only */
535
10.2k
    }
536
    /* Align the virtual buffer for this component. */
537
6.79M
    if (cinfo->output_iMCU_row > 1) {
538
6.77M
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
6.77M
      buffer = (*cinfo->mem->access_virt_barray)
540
6.77M
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
6.77M
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
6.77M
         (JDIMENSION)access_rows, FALSE);
543
6.77M
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
6.77M
    } else if (cinfo->output_iMCU_row > 0) {
545
9.01k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
9.01k
      buffer = (*cinfo->mem->access_virt_barray)
547
9.01k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
9.01k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
9.01k
         (JDIMENSION)access_rows, FALSE);
550
9.01k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
9.29k
    } else {
552
9.29k
      buffer = (*cinfo->mem->access_virt_barray)
553
9.29k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
9.29k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
9.29k
    }
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
6.79M
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
561
4.61M
      coef_bits =
562
4.61M
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
563
2.17M
    else
564
2.17M
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
565
566
    /* We only do DC interpolation if no AC coefficient data is available. */
567
6.79M
    change_dc =
568
6.79M
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
4.25M
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
3.65M
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
6.79M
    quanttbl = compptr->quant_table;
573
6.79M
    Q00 = quanttbl->quantval[0];
574
6.79M
    Q01 = quanttbl->quantval[Q01_POS];
575
6.79M
    Q10 = quanttbl->quantval[Q10_POS];
576
6.79M
    Q20 = quanttbl->quantval[Q20_POS];
577
6.79M
    Q11 = quanttbl->quantval[Q11_POS];
578
6.79M
    Q02 = quanttbl->quantval[Q02_POS];
579
6.79M
    if (change_dc) {
580
3.63M
      Q03 = quanttbl->quantval[Q03_POS];
581
3.63M
      Q12 = quanttbl->quantval[Q12_POS];
582
3.63M
      Q21 = quanttbl->quantval[Q21_POS];
583
3.63M
      Q30 = quanttbl->quantval[Q30_POS];
584
3.63M
    }
585
6.79M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
6.79M
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
6.79M
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
14.7M
    for (block_row = 0; block_row < block_rows; block_row++) {
590
7.90M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
7.90M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
7.90M
      if (image_block_row > 0)
594
7.89M
        prev_block_row =
595
7.89M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
9.29k
      else
597
9.29k
        prev_block_row = buffer_ptr;
598
599
7.90M
      if (image_block_row > 1)
600
7.88M
        prev_prev_block_row =
601
7.88M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
21.4k
      else
603
21.4k
        prev_prev_block_row = prev_block_row;
604
605
7.90M
      if (image_block_row < image_block_rows - 1)
606
7.89M
        next_block_row =
607
7.89M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
10.2k
      else
609
10.2k
        next_block_row = buffer_ptr;
610
611
7.90M
      if (image_block_row < image_block_rows - 2)
612
7.89M
        next_next_block_row =
613
7.89M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
17.1k
      else
615
17.1k
        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
7.90M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
7.90M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
7.90M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
7.90M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
7.90M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
7.90M
      output_col = 0;
626
7.90M
      last_block_column = compptr->width_in_blocks - 1;
627
7.90M
      for (block_num = cinfo->master->first_MCU_col[ci];
628
33.8M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
25.9M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
25.9M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
7.90M
            block_num < last_block_column) {
634
5.20M
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
5.20M
          DC09 = DC10 = (int)prev_block_row[1][0];
636
5.20M
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
5.20M
          DC19 = DC20 = (int)next_block_row[1][0];
638
5.20M
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
5.20M
        }
640
25.9M
        if (block_num + 1 < last_block_column) {
641
12.8M
          DC05 = (int)prev_prev_block_row[2][0];
642
12.8M
          DC10 = (int)prev_block_row[2][0];
643
12.8M
          DC15 = (int)buffer_ptr[2][0];
644
12.8M
          DC20 = (int)next_block_row[2][0];
645
12.8M
          DC25 = (int)next_next_block_row[2][0];
646
12.8M
        }
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
25.9M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
21.1M
          num = Q00 * (change_dc ?
660
10.5M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
10.5M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
10.5M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
10.5M
                 DC21 - DC22 + DC24 + DC25) :
664
21.1M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
21.1M
          if (num >= 0) {
666
15.6M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
15.6M
            if (Al > 0 && pred >= (1 << Al))
668
1.69M
              pred = (1 << Al) - 1;
669
15.6M
          } else {
670
5.45M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
5.45M
            if (Al > 0 && pred >= (1 << Al))
672
1.09M
              pred = (1 << Al) - 1;
673
5.45M
            pred = -pred;
674
5.45M
          }
675
21.1M
          workspace[1] = (JCOEF)pred;
676
21.1M
        }
677
        /* AC10 */
678
25.9M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
21.3M
          num = Q00 * (change_dc ?
680
10.5M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
10.5M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
10.5M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
10.5M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
21.3M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
21.3M
          if (num >= 0) {
686
14.9M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
14.9M
            if (Al > 0 && pred >= (1 << Al))
688
2.47M
              pred = (1 << Al) - 1;
689
14.9M
          } else {
690
6.39M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
6.39M
            if (Al > 0 && pred >= (1 << Al))
692
2.24M
              pred = (1 << Al) - 1;
693
6.39M
            pred = -pred;
694
6.39M
          }
695
21.3M
          workspace[8] = (JCOEF)pred;
696
21.3M
        }
697
        /* AC20 */
698
25.9M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
21.3M
          num = Q00 * (change_dc ?
700
10.5M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
10.5M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
21.3M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
21.3M
          if (num >= 0) {
704
13.8M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
13.8M
            if (Al > 0 && pred >= (1 << Al))
706
2.44M
              pred = (1 << Al) - 1;
707
13.8M
          } else {
708
7.50M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
7.50M
            if (Al > 0 && pred >= (1 << Al))
710
2.41M
              pred = (1 << Al) - 1;
711
7.50M
            pred = -pred;
712
7.50M
          }
713
21.3M
          workspace[16] = (JCOEF)pred;
714
21.3M
        }
715
        /* AC11 */
716
25.9M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
21.4M
          num = Q00 * (change_dc ?
718
10.5M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
10.5M
                 9 * DC19 + DC21 - DC25) :
720
21.4M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
10.8M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
21.4M
          if (num >= 0) {
723
16.4M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
16.4M
            if (Al > 0 && pred >= (1 << Al))
725
1.09M
              pred = (1 << Al) - 1;
726
16.4M
          } else {
727
4.99M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
4.99M
            if (Al > 0 && pred >= (1 << Al))
729
1.09M
              pred = (1 << Al) - 1;
730
4.99M
            pred = -pred;
731
4.99M
          }
732
21.4M
          workspace[9] = (JCOEF)pred;
733
21.4M
        }
734
        /* AC02 */
735
25.9M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
21.3M
          num = Q00 * (change_dc ?
737
10.5M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
10.5M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
21.3M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
21.3M
          if (num >= 0) {
741
14.1M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
14.1M
            if (Al > 0 && pred >= (1 << Al))
743
1.10M
              pred = (1 << Al) - 1;
744
14.1M
          } else {
745
7.26M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
7.26M
            if (Al > 0 && pred >= (1 << Al))
747
1.07M
              pred = (1 << Al) - 1;
748
7.26M
            pred = -pred;
749
7.26M
          }
750
21.3M
          workspace[2] = (JCOEF)pred;
751
21.3M
        }
752
25.9M
        if (change_dc) {
753
          /* AC03 */
754
10.5M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
10.5M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
10.5M
            if (num >= 0) {
757
8.47M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
8.47M
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
8.47M
            } else {
761
2.12M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
2.12M
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
2.12M
              pred = -pred;
765
2.12M
            }
766
10.5M
            workspace[3] = (JCOEF)pred;
767
10.5M
          }
768
          /* AC12 */
769
10.5M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
10.5M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
10.5M
            if (num >= 0) {
772
7.31M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
7.31M
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
7.31M
            } else {
776
3.28M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
3.28M
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
3.28M
              pred = -pred;
780
3.28M
            }
781
10.5M
            workspace[10] = (JCOEF)pred;
782
10.5M
          }
783
          /* AC21 */
784
10.5M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
10.5M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
10.5M
            if (num >= 0) {
787
7.84M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
7.84M
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
7.84M
            } else {
791
2.75M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
2.75M
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
2.75M
              pred = -pred;
795
2.75M
            }
796
10.5M
            workspace[17] = (JCOEF)pred;
797
10.5M
          }
798
          /* AC30 */
799
10.5M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
10.5M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
10.5M
            if (num >= 0) {
802
8.28M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
8.28M
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
8.28M
            } else {
806
2.31M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
2.31M
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
2.31M
              pred = -pred;
810
2.31M
            }
811
10.5M
            workspace[24] = (JCOEF)pred;
812
10.5M
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
10.5M
          num = Q00 *
817
10.5M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
10.5M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
10.5M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
10.5M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
10.5M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
10.5M
          if (num >= 0) {
823
7.68M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
7.68M
          } else {
825
2.91M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
2.91M
            pred = -pred;
827
2.91M
          }
828
10.5M
          workspace[0] = (JCOEF)pred;
829
10.5M
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
25.9M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
25.9M
                        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
25.9M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
25.9M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
25.9M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
25.9M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
25.9M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
25.9M
        buffer_ptr++, prev_block_row++, next_block_row++,
848
25.9M
          prev_prev_block_row++, next_next_block_row++;
849
25.9M
        output_col += compptr->_DCT_scaled_size;
850
25.9M
      }
851
7.90M
      output_ptr += compptr->_DCT_scaled_size;
852
7.90M
    }
853
6.79M
  }
854
855
2.58M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
2.58M
    return JPEG_ROW_COMPLETED;
857
5.39k
  return JPEG_SCAN_COMPLETED;
858
2.58M
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
474
2.60M
{
475
2.60M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
2.60M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
2.60M
  JDIMENSION block_num, last_block_column;
478
2.60M
  int ci, block_row, block_rows, access_rows, image_block_row,
479
2.60M
    image_block_rows;
480
2.60M
  JBLOCKARRAY buffer;
481
2.60M
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
2.60M
  JBLOCKROW next_block_row, next_next_block_row;
483
2.60M
  _JSAMPARRAY output_ptr;
484
2.60M
  JDIMENSION output_col;
485
2.60M
  jpeg_component_info *compptr;
486
2.60M
  _inverse_DCT_method_ptr inverse_DCT;
487
2.60M
  boolean change_dc;
488
2.60M
  JCOEF *workspace;
489
2.60M
  int *coef_bits;
490
2.60M
  JQUANT_TBL *quanttbl;
491
2.60M
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
2.60M
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
2.60M
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
2.60M
      DC25;
495
2.60M
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
2.60M
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
5.14M
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
5.13M
         !cinfo->inputctl->eoi_reached) {
503
5.13M
    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
5.13M
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
510
5.13M
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
511
2.58M
        break;
512
5.13M
    }
513
2.55M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
514
12.3k
      return JPEG_SUSPENDED;
515
2.55M
  }
516
517
  /* OK, output from the virtual arrays. */
518
9.38M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
6.79M
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
6.79M
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
6.79M
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
6.77M
      block_rows = compptr->v_samp_factor;
526
6.77M
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
6.77M
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
8.72k
      block_rows = compptr->v_samp_factor;
529
8.72k
      access_rows = block_rows * 2; /* this and next iMCU row */
530
10.2k
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
10.2k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
10.2k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
10.2k
      access_rows = block_rows; /* this iMCU row only */
535
10.2k
    }
536
    /* Align the virtual buffer for this component. */
537
6.79M
    if (cinfo->output_iMCU_row > 1) {
538
6.77M
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
6.77M
      buffer = (*cinfo->mem->access_virt_barray)
540
6.77M
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
6.77M
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
6.77M
         (JDIMENSION)access_rows, FALSE);
543
6.77M
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
6.77M
    } else if (cinfo->output_iMCU_row > 0) {
545
9.01k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
9.01k
      buffer = (*cinfo->mem->access_virt_barray)
547
9.01k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
9.01k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
9.01k
         (JDIMENSION)access_rows, FALSE);
550
9.01k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
9.29k
    } else {
552
9.29k
      buffer = (*cinfo->mem->access_virt_barray)
553
9.29k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
9.29k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
9.29k
    }
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
6.79M
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
561
4.61M
      coef_bits =
562
4.61M
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
563
2.17M
    else
564
2.17M
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
565
566
    /* We only do DC interpolation if no AC coefficient data is available. */
567
6.79M
    change_dc =
568
6.79M
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
4.25M
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
3.65M
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
6.79M
    quanttbl = compptr->quant_table;
573
6.79M
    Q00 = quanttbl->quantval[0];
574
6.79M
    Q01 = quanttbl->quantval[Q01_POS];
575
6.79M
    Q10 = quanttbl->quantval[Q10_POS];
576
6.79M
    Q20 = quanttbl->quantval[Q20_POS];
577
6.79M
    Q11 = quanttbl->quantval[Q11_POS];
578
6.79M
    Q02 = quanttbl->quantval[Q02_POS];
579
6.79M
    if (change_dc) {
580
3.63M
      Q03 = quanttbl->quantval[Q03_POS];
581
3.63M
      Q12 = quanttbl->quantval[Q12_POS];
582
3.63M
      Q21 = quanttbl->quantval[Q21_POS];
583
3.63M
      Q30 = quanttbl->quantval[Q30_POS];
584
3.63M
    }
585
6.79M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
6.79M
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
6.79M
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
14.7M
    for (block_row = 0; block_row < block_rows; block_row++) {
590
7.90M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
7.90M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
7.90M
      if (image_block_row > 0)
594
7.89M
        prev_block_row =
595
7.89M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
9.29k
      else
597
9.29k
        prev_block_row = buffer_ptr;
598
599
7.90M
      if (image_block_row > 1)
600
7.88M
        prev_prev_block_row =
601
7.88M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
21.4k
      else
603
21.4k
        prev_prev_block_row = prev_block_row;
604
605
7.90M
      if (image_block_row < image_block_rows - 1)
606
7.89M
        next_block_row =
607
7.89M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
10.2k
      else
609
10.2k
        next_block_row = buffer_ptr;
610
611
7.90M
      if (image_block_row < image_block_rows - 2)
612
7.89M
        next_next_block_row =
613
7.89M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
17.1k
      else
615
17.1k
        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
7.90M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
7.90M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
7.90M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
7.90M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
7.90M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
7.90M
      output_col = 0;
626
7.90M
      last_block_column = compptr->width_in_blocks - 1;
627
7.90M
      for (block_num = cinfo->master->first_MCU_col[ci];
628
33.8M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
25.9M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
25.9M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
7.90M
            block_num < last_block_column) {
634
5.20M
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
5.20M
          DC09 = DC10 = (int)prev_block_row[1][0];
636
5.20M
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
5.20M
          DC19 = DC20 = (int)next_block_row[1][0];
638
5.20M
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
5.20M
        }
640
25.9M
        if (block_num + 1 < last_block_column) {
641
12.8M
          DC05 = (int)prev_prev_block_row[2][0];
642
12.8M
          DC10 = (int)prev_block_row[2][0];
643
12.8M
          DC15 = (int)buffer_ptr[2][0];
644
12.8M
          DC20 = (int)next_block_row[2][0];
645
12.8M
          DC25 = (int)next_next_block_row[2][0];
646
12.8M
        }
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
25.9M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
21.1M
          num = Q00 * (change_dc ?
660
10.5M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
10.5M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
10.5M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
10.5M
                 DC21 - DC22 + DC24 + DC25) :
664
21.1M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
21.1M
          if (num >= 0) {
666
15.6M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
15.6M
            if (Al > 0 && pred >= (1 << Al))
668
1.69M
              pred = (1 << Al) - 1;
669
15.6M
          } else {
670
5.45M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
5.45M
            if (Al > 0 && pred >= (1 << Al))
672
1.09M
              pred = (1 << Al) - 1;
673
5.45M
            pred = -pred;
674
5.45M
          }
675
21.1M
          workspace[1] = (JCOEF)pred;
676
21.1M
        }
677
        /* AC10 */
678
25.9M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
21.3M
          num = Q00 * (change_dc ?
680
10.5M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
10.5M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
10.5M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
10.5M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
21.3M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
21.3M
          if (num >= 0) {
686
14.9M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
14.9M
            if (Al > 0 && pred >= (1 << Al))
688
2.47M
              pred = (1 << Al) - 1;
689
14.9M
          } else {
690
6.39M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
6.39M
            if (Al > 0 && pred >= (1 << Al))
692
2.24M
              pred = (1 << Al) - 1;
693
6.39M
            pred = -pred;
694
6.39M
          }
695
21.3M
          workspace[8] = (JCOEF)pred;
696
21.3M
        }
697
        /* AC20 */
698
25.9M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
21.3M
          num = Q00 * (change_dc ?
700
10.5M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
10.5M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
21.3M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
21.3M
          if (num >= 0) {
704
13.8M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
13.8M
            if (Al > 0 && pred >= (1 << Al))
706
2.44M
              pred = (1 << Al) - 1;
707
13.8M
          } else {
708
7.50M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
7.50M
            if (Al > 0 && pred >= (1 << Al))
710
2.41M
              pred = (1 << Al) - 1;
711
7.50M
            pred = -pred;
712
7.50M
          }
713
21.3M
          workspace[16] = (JCOEF)pred;
714
21.3M
        }
715
        /* AC11 */
716
25.9M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
21.4M
          num = Q00 * (change_dc ?
718
10.5M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
10.5M
                 9 * DC19 + DC21 - DC25) :
720
21.4M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
10.8M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
21.4M
          if (num >= 0) {
723
16.4M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
16.4M
            if (Al > 0 && pred >= (1 << Al))
725
1.09M
              pred = (1 << Al) - 1;
726
16.4M
          } else {
727
4.99M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
4.99M
            if (Al > 0 && pred >= (1 << Al))
729
1.09M
              pred = (1 << Al) - 1;
730
4.99M
            pred = -pred;
731
4.99M
          }
732
21.4M
          workspace[9] = (JCOEF)pred;
733
21.4M
        }
734
        /* AC02 */
735
25.9M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
21.3M
          num = Q00 * (change_dc ?
737
10.5M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
10.5M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
21.3M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
21.3M
          if (num >= 0) {
741
14.1M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
14.1M
            if (Al > 0 && pred >= (1 << Al))
743
1.10M
              pred = (1 << Al) - 1;
744
14.1M
          } else {
745
7.26M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
7.26M
            if (Al > 0 && pred >= (1 << Al))
747
1.07M
              pred = (1 << Al) - 1;
748
7.26M
            pred = -pred;
749
7.26M
          }
750
21.3M
          workspace[2] = (JCOEF)pred;
751
21.3M
        }
752
25.9M
        if (change_dc) {
753
          /* AC03 */
754
10.5M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
10.5M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
10.5M
            if (num >= 0) {
757
8.47M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
8.47M
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
8.47M
            } else {
761
2.12M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
2.12M
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
2.12M
              pred = -pred;
765
2.12M
            }
766
10.5M
            workspace[3] = (JCOEF)pred;
767
10.5M
          }
768
          /* AC12 */
769
10.5M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
10.5M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
10.5M
            if (num >= 0) {
772
7.31M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
7.31M
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
7.31M
            } else {
776
3.28M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
3.28M
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
3.28M
              pred = -pred;
780
3.28M
            }
781
10.5M
            workspace[10] = (JCOEF)pred;
782
10.5M
          }
783
          /* AC21 */
784
10.5M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
10.5M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
10.5M
            if (num >= 0) {
787
7.84M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
7.84M
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
7.84M
            } else {
791
2.75M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
2.75M
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
2.75M
              pred = -pred;
795
2.75M
            }
796
10.5M
            workspace[17] = (JCOEF)pred;
797
10.5M
          }
798
          /* AC30 */
799
10.5M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
10.5M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
10.5M
            if (num >= 0) {
802
8.28M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
8.28M
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
8.28M
            } else {
806
2.31M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
2.31M
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
2.31M
              pred = -pred;
810
2.31M
            }
811
10.5M
            workspace[24] = (JCOEF)pred;
812
10.5M
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
10.5M
          num = Q00 *
817
10.5M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
10.5M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
10.5M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
10.5M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
10.5M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
10.5M
          if (num >= 0) {
823
7.68M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
7.68M
          } else {
825
2.91M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
2.91M
            pred = -pred;
827
2.91M
          }
828
10.5M
          workspace[0] = (JCOEF)pred;
829
10.5M
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
25.9M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
25.9M
                        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
25.9M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
25.9M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
25.9M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
25.9M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
25.9M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
25.9M
        buffer_ptr++, prev_block_row++, next_block_row++,
848
25.9M
          prev_prev_block_row++, next_next_block_row++;
849
25.9M
        output_col += compptr->_DCT_scaled_size;
850
25.9M
      }
851
7.90M
      output_ptr += compptr->_DCT_scaled_size;
852
7.90M
    }
853
6.79M
  }
854
855
2.58M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
2.58M
    return JPEG_ROW_COMPLETED;
857
5.39k
  return JPEG_SCAN_COMPLETED;
858
2.58M
}
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
17.4k
{
870
17.4k
  my_coef_ptr coef;
871
872
17.4k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
17.4k
  coef = (my_coef_ptr)
876
17.4k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
17.4k
                                sizeof(my_coef_controller));
878
17.4k
  memset(coef, 0, sizeof(my_coef_controller));
879
17.4k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
17.4k
  coef->pub.start_input_pass = start_input_pass;
881
17.4k
  coef->pub.start_output_pass = start_output_pass;
882
17.4k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
17.4k
  coef->coef_bits_latch = NULL;
884
17.4k
#endif
885
886
  /* Create the coefficient buffer. */
887
17.4k
  if (need_full_buffer) {
888
12.0k
#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
12.0k
    int ci, access_rows;
893
12.0k
    jpeg_component_info *compptr;
894
895
39.3k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
27.2k
         ci++, compptr++) {
897
27.2k
      access_rows = compptr->v_samp_factor;
898
27.2k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
27.2k
      if (cinfo->progressive_mode)
901
15.1k
        access_rows *= 5;
902
27.2k
#endif
903
27.2k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
27.2k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
27.2k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
27.2k
                               (long)compptr->h_samp_factor),
907
27.2k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
27.2k
                               (long)compptr->v_samp_factor),
909
27.2k
         (JDIMENSION)access_rows);
910
27.2k
    }
911
12.0k
    coef->pub.consume_data = consume_data;
912
12.0k
    coef->pub._decompress_data = decompress_data;
913
12.0k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
12.0k
  } else {
918
    /* We only need a single-MCU buffer. */
919
5.39k
    JBLOCKROW buffer;
920
5.39k
    int i;
921
922
5.39k
    buffer = (JBLOCKROW)
923
5.39k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
5.39k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
59.3k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
53.9k
      coef->MCU_buffer[i] = buffer + i;
927
53.9k
    }
928
5.39k
    coef->pub.consume_data = dummy_consume_data;
929
5.39k
    coef->pub._decompress_data = decompress_onepass;
930
5.39k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
5.39k
  }
932
933
  /* Allocate the workspace buffer */
934
17.4k
  coef->workspace = (JCOEF *)
935
17.4k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
17.4k
                                sizeof(JCOEF) * DCTSIZE2);
937
17.4k
}
jinit_d_coef_controller
Line
Count
Source
869
16.2k
{
870
16.2k
  my_coef_ptr coef;
871
872
16.2k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
16.2k
  coef = (my_coef_ptr)
876
16.2k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
16.2k
                                sizeof(my_coef_controller));
878
16.2k
  memset(coef, 0, sizeof(my_coef_controller));
879
16.2k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
16.2k
  coef->pub.start_input_pass = start_input_pass;
881
16.2k
  coef->pub.start_output_pass = start_output_pass;
882
16.2k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
16.2k
  coef->coef_bits_latch = NULL;
884
16.2k
#endif
885
886
  /* Create the coefficient buffer. */
887
16.2k
  if (need_full_buffer) {
888
10.8k
#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
10.8k
    int ci, access_rows;
893
10.8k
    jpeg_component_info *compptr;
894
895
35.8k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
25.0k
         ci++, compptr++) {
897
25.0k
      access_rows = compptr->v_samp_factor;
898
25.0k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
25.0k
      if (cinfo->progressive_mode)
901
13.6k
        access_rows *= 5;
902
25.0k
#endif
903
25.0k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
25.0k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
25.0k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
25.0k
                               (long)compptr->h_samp_factor),
907
25.0k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
25.0k
                               (long)compptr->v_samp_factor),
909
25.0k
         (JDIMENSION)access_rows);
910
25.0k
    }
911
10.8k
    coef->pub.consume_data = consume_data;
912
10.8k
    coef->pub._decompress_data = decompress_data;
913
10.8k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
10.8k
  } else {
918
    /* We only need a single-MCU buffer. */
919
5.38k
    JBLOCKROW buffer;
920
5.38k
    int i;
921
922
5.38k
    buffer = (JBLOCKROW)
923
5.38k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
5.38k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
59.1k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
53.8k
      coef->MCU_buffer[i] = buffer + i;
927
53.8k
    }
928
5.38k
    coef->pub.consume_data = dummy_consume_data;
929
5.38k
    coef->pub._decompress_data = decompress_onepass;
930
5.38k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
5.38k
  }
932
933
  /* Allocate the workspace buffer */
934
16.2k
  coef->workspace = (JCOEF *)
935
16.2k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
16.2k
                                sizeof(JCOEF) * DCTSIZE2);
937
16.2k
}
j12init_d_coef_controller
Line
Count
Source
869
1.15k
{
870
1.15k
  my_coef_ptr coef;
871
872
1.15k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
1.15k
  coef = (my_coef_ptr)
876
1.15k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
1.15k
                                sizeof(my_coef_controller));
878
1.15k
  memset(coef, 0, sizeof(my_coef_controller));
879
1.15k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
1.15k
  coef->pub.start_input_pass = start_input_pass;
881
1.15k
  coef->pub.start_output_pass = start_output_pass;
882
1.15k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
1.15k
  coef->coef_bits_latch = NULL;
884
1.15k
#endif
885
886
  /* Create the coefficient buffer. */
887
1.15k
  if (need_full_buffer) {
888
1.13k
#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.13k
    int ci, access_rows;
893
1.13k
    jpeg_component_info *compptr;
894
895
3.42k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
2.29k
         ci++, compptr++) {
897
2.29k
      access_rows = compptr->v_samp_factor;
898
2.29k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
2.29k
      if (cinfo->progressive_mode)
901
1.46k
        access_rows *= 5;
902
2.29k
#endif
903
2.29k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
2.29k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
2.29k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
2.29k
                               (long)compptr->h_samp_factor),
907
2.29k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
2.29k
                               (long)compptr->v_samp_factor),
909
2.29k
         (JDIMENSION)access_rows);
910
2.29k
    }
911
1.13k
    coef->pub.consume_data = consume_data;
912
1.13k
    coef->pub._decompress_data = decompress_data;
913
1.13k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
1.13k
  } else {
918
    /* We only need a single-MCU buffer. */
919
17
    JBLOCKROW buffer;
920
17
    int i;
921
922
17
    buffer = (JBLOCKROW)
923
17
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
17
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
187
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
170
      coef->MCU_buffer[i] = buffer + i;
927
170
    }
928
17
    coef->pub.consume_data = dummy_consume_data;
929
17
    coef->pub._decompress_data = decompress_onepass;
930
17
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
17
  }
932
933
  /* Allocate the workspace buffer */
934
1.15k
  coef->workspace = (JCOEF *)
935
1.15k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
1.15k
                                sizeof(JCOEF) * DCTSIZE2);
937
1.15k
}