Coverage Report

Created: 2026-08-31 07:17

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
40.3k
{
51
40.3k
  cinfo->input_iMCU_row = 0;
52
40.3k
  start_iMCU_row(cinfo);
53
40.3k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
50
35.4k
{
51
35.4k
  cinfo->input_iMCU_row = 0;
52
35.4k
  start_iMCU_row(cinfo);
53
35.4k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
50
4.87k
{
51
4.87k
  cinfo->input_iMCU_row = 0;
52
4.87k
  start_iMCU_row(cinfo);
53
4.87k
}
54
55
56
/*
57
 * Initialize for an output processing pass.
58
 */
59
60
METHODDEF(void)
61
start_output_pass(j_decompress_ptr cinfo)
62
7.48k
{
63
7.48k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
7.48k
  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
7.48k
  if (coef->pub.coef_arrays != NULL) {
68
5.23k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
1.86k
      coef->pub._decompress_data = decompress_smooth_data;
70
3.37k
    else
71
3.37k
      coef->pub._decompress_data = decompress_data;
72
5.23k
  }
73
7.48k
#endif
74
7.48k
  cinfo->output_iMCU_row = 0;
75
7.48k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
62
6.48k
{
63
6.48k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
6.48k
  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
6.48k
  if (coef->pub.coef_arrays != NULL) {
68
4.29k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
1.70k
      coef->pub._decompress_data = decompress_smooth_data;
70
2.58k
    else
71
2.58k
      coef->pub._decompress_data = decompress_data;
72
4.29k
  }
73
6.48k
#endif
74
6.48k
  cinfo->output_iMCU_row = 0;
75
6.48k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
62
997
{
63
997
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
997
  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
997
  if (coef->pub.coef_arrays != NULL) {
68
945
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
160
      coef->pub._decompress_data = decompress_smooth_data;
70
785
    else
71
785
      coef->pub._decompress_data = decompress_data;
72
945
  }
73
997
#endif
74
997
  cinfo->output_iMCU_row = 0;
75
997
}
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
526k
{
91
526k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
526k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
526k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
526k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
526k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
526k
  _JSAMPARRAY output_ptr;
97
526k
  JDIMENSION start_col, output_col;
98
526k
  jpeg_component_info *compptr;
99
526k
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
1.35M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
830k
       yoffset++) {
104
12.9M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
12.1M
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
12.1M
      jzero_far((void *)coef->MCU_buffer[0],
108
12.1M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
12.1M
      if (!cinfo->entropy->insufficient_data)
110
1.99M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
12.1M
      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
12.1M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
12.1M
          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
12.1M
        blkn = 0;               /* index of current DCT block within MCU */
142
24.5M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
12.3M
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
12.3M
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
12.3M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
12.3M
          useful_width = (MCU_col_num < last_MCU_col) ?
151
11.4M
                         compptr->MCU_width : compptr->last_col_width;
152
12.3M
          output_ptr = output_buf[compptr->component_index] +
153
12.3M
                       yoffset * compptr->_DCT_scaled_size;
154
12.3M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
12.3M
                      compptr->MCU_sample_width;
156
24.8M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
12.5M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
12.5M
                yoffset + yindex < compptr->last_row_height) {
159
12.5M
              output_col = start_col;
160
25.1M
              for (xindex = 0; xindex < useful_width; xindex++) {
161
#ifdef WITH_PROFILE
162
                cinfo->master->start = getTime();
163
#endif
164
12.6M
                (*inverse_DCT) (cinfo, compptr,
165
12.6M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
12.6M
                                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
12.6M
                output_col += compptr->_DCT_scaled_size;
173
12.6M
              }
174
12.5M
            }
175
12.5M
            blkn += compptr->MCU_width;
176
12.5M
            output_ptr += compptr->_DCT_scaled_size;
177
12.5M
          }
178
12.3M
        }
179
12.1M
      }
180
12.1M
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
830k
    coef->MCU_ctr = 0;
183
830k
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
526k
  cinfo->output_iMCU_row++;
186
526k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
524k
    start_iMCU_row(cinfo);
188
524k
    return JPEG_ROW_COMPLETED;
189
524k
  }
190
  /* Completed the scan */
191
2.19k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
2.19k
  return JPEG_SCAN_COMPLETED;
193
526k
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
90
526k
{
91
526k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
526k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
526k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
526k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
526k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
526k
  _JSAMPARRAY output_ptr;
97
526k
  JDIMENSION start_col, output_col;
98
526k
  jpeg_component_info *compptr;
99
526k
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
1.35M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
830k
       yoffset++) {
104
12.9M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
12.1M
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
12.1M
      jzero_far((void *)coef->MCU_buffer[0],
108
12.1M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
12.1M
      if (!cinfo->entropy->insufficient_data)
110
1.99M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
12.1M
      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
12.1M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
12.1M
          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
12.1M
        blkn = 0;               /* index of current DCT block within MCU */
142
24.5M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
12.3M
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
12.3M
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
12.3M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
12.3M
          useful_width = (MCU_col_num < last_MCU_col) ?
151
11.4M
                         compptr->MCU_width : compptr->last_col_width;
152
12.3M
          output_ptr = output_buf[compptr->component_index] +
153
12.3M
                       yoffset * compptr->_DCT_scaled_size;
154
12.3M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
12.3M
                      compptr->MCU_sample_width;
156
24.8M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
12.5M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
12.5M
                yoffset + yindex < compptr->last_row_height) {
159
12.5M
              output_col = start_col;
160
25.1M
              for (xindex = 0; xindex < useful_width; xindex++) {
161
#ifdef WITH_PROFILE
162
                cinfo->master->start = getTime();
163
#endif
164
12.6M
                (*inverse_DCT) (cinfo, compptr,
165
12.6M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
12.6M
                                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
12.6M
                output_col += compptr->_DCT_scaled_size;
173
12.6M
              }
174
12.5M
            }
175
12.5M
            blkn += compptr->MCU_width;
176
12.5M
            output_ptr += compptr->_DCT_scaled_size;
177
12.5M
          }
178
12.3M
        }
179
12.1M
      }
180
12.1M
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
830k
    coef->MCU_ctr = 0;
183
830k
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
526k
  cinfo->output_iMCU_row++;
186
526k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
524k
    start_iMCU_row(cinfo);
188
524k
    return JPEG_ROW_COMPLETED;
189
524k
  }
190
  /* Completed the scan */
191
2.19k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
2.19k
  return JPEG_SCAN_COMPLETED;
193
526k
}
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
8.75M
{
219
8.75M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
8.75M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
8.75M
  int blkn, ci, xindex, yindex, yoffset;
222
8.75M
  JDIMENSION start_col;
223
8.75M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
8.75M
  JBLOCKROW buffer_ptr;
225
8.75M
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
18.5M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
9.78M
    compptr = cinfo->cur_comp_info[ci];
230
9.78M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
9.78M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
9.78M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
9.78M
       (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
9.78M
  }
239
240
  /* Loop to process one whole iMCU row */
241
19.3M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
10.5M
       yoffset++) {
243
133M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
122M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
122M
      blkn = 0;                 /* index of current DCT block within MCU */
247
263M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
140M
        compptr = cinfo->cur_comp_info[ci];
249
140M
        start_col = MCU_col_num * compptr->MCU_width;
250
298M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
158M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
348M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
190M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
190M
          }
255
158M
        }
256
140M
      }
257
122M
      if (!cinfo->entropy->insufficient_data)
258
79.6M
        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
122M
      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
122M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
10.5M
    coef->MCU_ctr = 0;
282
10.5M
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
8.75M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
8.71M
    start_iMCU_row(cinfo);
286
8.71M
    return JPEG_ROW_COMPLETED;
287
8.71M
  }
288
  /* Completed the scan */
289
37.4k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
37.4k
  return JPEG_SCAN_COMPLETED;
291
8.75M
}
jdcoefct-8.c:consume_data
Line
Count
Source
218
7.13M
{
219
7.13M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
7.13M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
7.13M
  int blkn, ci, xindex, yindex, yoffset;
222
7.13M
  JDIMENSION start_col;
223
7.13M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
7.13M
  JBLOCKROW buffer_ptr;
225
7.13M
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
15.2M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
8.12M
    compptr = cinfo->cur_comp_info[ci];
230
8.12M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
8.12M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
8.12M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
8.12M
       (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
8.12M
  }
239
240
  /* Loop to process one whole iMCU row */
241
16.0M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
8.87M
       yoffset++) {
243
118M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
110M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
110M
      blkn = 0;                 /* index of current DCT block within MCU */
247
237M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
127M
        compptr = cinfo->cur_comp_info[ci];
249
127M
        start_col = MCU_col_num * compptr->MCU_width;
250
271M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
144M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
320M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
175M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
175M
          }
255
144M
        }
256
127M
      }
257
110M
      if (!cinfo->entropy->insufficient_data)
258
74.0M
        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
110M
      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
110M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
8.87M
    coef->MCU_ctr = 0;
282
8.87M
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
7.13M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
7.10M
    start_iMCU_row(cinfo);
286
7.10M
    return JPEG_ROW_COMPLETED;
287
7.10M
  }
288
  /* Completed the scan */
289
32.6k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
32.6k
  return JPEG_SCAN_COMPLETED;
291
7.13M
}
jdcoefct-12.c:consume_data
Line
Count
Source
218
1.61M
{
219
1.61M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
1.61M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
1.61M
  int blkn, ci, xindex, yindex, yoffset;
222
1.61M
  JDIMENSION start_col;
223
1.61M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
1.61M
  JBLOCKROW buffer_ptr;
225
1.61M
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
3.28M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
1.66M
    compptr = cinfo->cur_comp_info[ci];
230
1.66M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
1.66M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
1.66M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
1.66M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
234
    /* Note: entropy decoder expects buffer to be zeroed,
235
     * but this is handled automatically by the memory manager
236
     * because we requested a pre-zeroed array.
237
     */
238
1.66M
  }
239
240
  /* Loop to process one whole iMCU row */
241
3.30M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
1.68M
       yoffset++) {
243
14.2M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
12.5M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
12.5M
      blkn = 0;                 /* index of current DCT block within MCU */
247
26.0M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
13.5M
        compptr = cinfo->cur_comp_info[ci];
249
13.5M
        start_col = MCU_col_num * compptr->MCU_width;
250
27.5M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
14.0M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
28.7M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
14.7M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
14.7M
          }
255
14.0M
        }
256
13.5M
      }
257
12.5M
      if (!cinfo->entropy->insufficient_data)
258
5.55M
        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
12.5M
      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
12.5M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
1.68M
    coef->MCU_ctr = 0;
282
1.68M
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
1.61M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
1.61M
    start_iMCU_row(cinfo);
286
1.61M
    return JPEG_ROW_COMPLETED;
287
1.61M
  }
288
  /* Completed the scan */
289
4.81k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
4.81k
  return JPEG_SCAN_COMPLETED;
291
1.61M
}
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
1.17M
{
305
1.17M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
1.17M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
1.17M
  JDIMENSION block_num;
308
1.17M
  int ci, block_row, block_rows;
309
1.17M
  JBLOCKARRAY buffer;
310
1.17M
  JBLOCKROW buffer_ptr;
311
1.17M
  _JSAMPARRAY output_ptr;
312
1.17M
  JDIMENSION output_col;
313
1.17M
  jpeg_component_info *compptr;
314
1.17M
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
1.17M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
1.17M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
1.17M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
320
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
321
0
      return JPEG_SUSPENDED;
322
0
  }
323
324
  /* OK, output from the virtual arrays. */
325
3.69M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
2.52M
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
2.52M
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
2.52M
    buffer = (*cinfo->mem->access_virt_barray)
332
2.52M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
2.52M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
2.52M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
2.52M
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
2.51M
      block_rows = compptr->v_samp_factor;
338
5.15k
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
5.15k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
5.15k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
5.15k
    }
343
2.52M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
2.52M
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
5.43M
    for (block_row = 0; block_row < block_rows; block_row++) {
347
2.91M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
2.91M
      output_col = 0;
349
2.91M
      for (block_num = cinfo->master->first_MCU_col[ci];
350
24.1M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
21.2M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
21.2M
                        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
21.2M
        buffer_ptr++;
361
21.2M
        output_col += compptr->_DCT_scaled_size;
362
21.2M
      }
363
2.91M
      output_ptr += compptr->_DCT_scaled_size;
364
2.91M
    }
365
2.52M
  }
366
367
1.17M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
1.17M
    return JPEG_ROW_COMPLETED;
369
2.58k
  return JPEG_SCAN_COMPLETED;
370
1.17M
}
jdcoefct-8.c:decompress_data
Line
Count
Source
304
1.17M
{
305
1.17M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
1.17M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
1.17M
  JDIMENSION block_num;
308
1.17M
  int ci, block_row, block_rows;
309
1.17M
  JBLOCKARRAY buffer;
310
1.17M
  JBLOCKROW buffer_ptr;
311
1.17M
  _JSAMPARRAY output_ptr;
312
1.17M
  JDIMENSION output_col;
313
1.17M
  jpeg_component_info *compptr;
314
1.17M
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
1.17M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
1.17M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
1.17M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
320
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
321
0
      return JPEG_SUSPENDED;
322
0
  }
323
324
  /* OK, output from the virtual arrays. */
325
3.69M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
2.52M
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
2.52M
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
2.52M
    buffer = (*cinfo->mem->access_virt_barray)
332
2.52M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
2.52M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
2.52M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
2.52M
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
2.51M
      block_rows = compptr->v_samp_factor;
338
5.15k
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
5.15k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
5.15k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
5.15k
    }
343
2.52M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
2.52M
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
5.43M
    for (block_row = 0; block_row < block_rows; block_row++) {
347
2.91M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
2.91M
      output_col = 0;
349
2.91M
      for (block_num = cinfo->master->first_MCU_col[ci];
350
24.1M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
21.2M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
21.2M
                        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
21.2M
        buffer_ptr++;
361
21.2M
        output_col += compptr->_DCT_scaled_size;
362
21.2M
      }
363
2.91M
      output_ptr += compptr->_DCT_scaled_size;
364
2.91M
    }
365
2.52M
  }
366
367
1.17M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
1.17M
    return JPEG_ROW_COMPLETED;
369
2.58k
  return JPEG_SCAN_COMPLETED;
370
1.17M
}
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
1.00M
#define Q01_POS  1
386
1.00M
#define Q10_POS  8
387
1.00M
#define Q20_POS  16
388
1.00M
#define Q11_POS  9
389
1.00M
#define Q02_POS  2
390
719k
#define Q03_POS  3
391
719k
#define Q12_POS  10
392
719k
#define Q21_POS  17
393
719k
#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
5.23k
{
406
5.23k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
5.23k
  boolean smoothing_useful = FALSE;
408
5.23k
  int ci, coefi;
409
5.23k
  jpeg_component_info *compptr;
410
5.23k
  JQUANT_TBL *qtable;
411
5.23k
  int *coef_bits, *prev_coef_bits;
412
5.23k
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
5.23k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
818
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
4.41k
  if (coef->coef_bits_latch == NULL)
419
4.41k
    coef->coef_bits_latch = (int *)
420
4.41k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
4.41k
                                  cinfo->num_components * 2 *
422
4.41k
                                  (SAVED_COEFS * sizeof(int)));
423
4.41k
  coef_bits_latch = coef->coef_bits_latch;
424
4.41k
  prev_coef_bits_latch =
425
4.41k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
6.95k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
5.08k
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
5.08k
    if ((qtable = compptr->quant_table) == NULL)
431
418
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
4.67k
    if (qtable->quantval[0] == 0 ||
434
4.39k
        qtable->quantval[Q01_POS] == 0 ||
435
4.22k
        qtable->quantval[Q10_POS] == 0 ||
436
4.00k
        qtable->quantval[Q20_POS] == 0 ||
437
3.83k
        qtable->quantval[Q11_POS] == 0 ||
438
3.59k
        qtable->quantval[Q02_POS] == 0 ||
439
3.48k
        qtable->quantval[Q03_POS] == 0 ||
440
3.26k
        qtable->quantval[Q12_POS] == 0 ||
441
3.15k
        qtable->quantval[Q21_POS] == 0 ||
442
3.02k
        qtable->quantval[Q30_POS] == 0)
443
1.77k
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
2.89k
    coef_bits = cinfo->coef_bits[ci];
446
2.89k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
2.89k
    if (coef_bits[0] < 0)
448
356
      return FALSE;
449
2.53k
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
25.3k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
22.8k
      if (cinfo->input_scan_number > 1)
453
13.4k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
9.40k
      else
455
9.40k
        prev_coef_bits_latch[coefi] = -1;
456
22.8k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
22.8k
      if (coef_bits[coefi] != 0)
458
21.6k
        smoothing_useful = TRUE;
459
22.8k
    }
460
2.53k
    coef_bits_latch += SAVED_COEFS;
461
2.53k
    prev_coef_bits_latch += SAVED_COEFS;
462
2.53k
  }
463
464
1.86k
  return smoothing_useful;
465
4.41k
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
405
4.29k
{
406
4.29k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
4.29k
  boolean smoothing_useful = FALSE;
408
4.29k
  int ci, coefi;
409
4.29k
  jpeg_component_info *compptr;
410
4.29k
  JQUANT_TBL *qtable;
411
4.29k
  int *coef_bits, *prev_coef_bits;
412
4.29k
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
4.29k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
661
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
3.63k
  if (coef->coef_bits_latch == NULL)
419
3.63k
    coef->coef_bits_latch = (int *)
420
3.63k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
3.63k
                                  cinfo->num_components * 2 *
422
3.63k
                                  (SAVED_COEFS * sizeof(int)));
423
3.63k
  coef_bits_latch = coef->coef_bits_latch;
424
3.63k
  prev_coef_bits_latch =
425
3.63k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
5.94k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
4.23k
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
4.23k
    if ((qtable = compptr->quant_table) == NULL)
431
374
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
3.86k
    if (qtable->quantval[0] == 0 ||
434
3.68k
        qtable->quantval[Q01_POS] == 0 ||
435
3.54k
        qtable->quantval[Q10_POS] == 0 ||
436
3.41k
        qtable->quantval[Q20_POS] == 0 ||
437
3.29k
        qtable->quantval[Q11_POS] == 0 ||
438
3.11k
        qtable->quantval[Q02_POS] == 0 ||
439
3.02k
        qtable->quantval[Q03_POS] == 0 ||
440
2.84k
        qtable->quantval[Q12_POS] == 0 ||
441
2.77k
        qtable->quantval[Q21_POS] == 0 ||
442
2.68k
        qtable->quantval[Q30_POS] == 0)
443
1.28k
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
2.57k
    coef_bits = cinfo->coef_bits[ci];
446
2.57k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
2.57k
    if (coef_bits[0] < 0)
448
268
      return FALSE;
449
2.31k
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
23.1k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
20.7k
      if (cinfo->input_scan_number > 1)
453
12.7k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
8.03k
      else
455
8.03k
        prev_coef_bits_latch[coefi] = -1;
456
20.7k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
20.7k
      if (coef_bits[coefi] != 0)
458
19.7k
        smoothing_useful = TRUE;
459
20.7k
    }
460
2.31k
    coef_bits_latch += SAVED_COEFS;
461
2.31k
    prev_coef_bits_latch += SAVED_COEFS;
462
2.31k
  }
463
464
1.70k
  return smoothing_useful;
465
3.63k
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
405
945
{
406
945
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
945
  boolean smoothing_useful = FALSE;
408
945
  int ci, coefi;
409
945
  jpeg_component_info *compptr;
410
945
  JQUANT_TBL *qtable;
411
945
  int *coef_bits, *prev_coef_bits;
412
945
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
945
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
157
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
788
  if (coef->coef_bits_latch == NULL)
419
788
    coef->coef_bits_latch = (int *)
420
788
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
788
                                  cinfo->num_components * 2 *
422
788
                                  (SAVED_COEFS * sizeof(int)));
423
788
  coef_bits_latch = coef->coef_bits_latch;
424
788
  prev_coef_bits_latch =
425
788
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
1.01k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
852
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
852
    if ((qtable = compptr->quant_table) == NULL)
431
44
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
808
    if (qtable->quantval[0] == 0 ||
434
716
        qtable->quantval[Q01_POS] == 0 ||
435
680
        qtable->quantval[Q10_POS] == 0 ||
436
584
        qtable->quantval[Q20_POS] == 0 ||
437
540
        qtable->quantval[Q11_POS] == 0 ||
438
480
        qtable->quantval[Q02_POS] == 0 ||
439
464
        qtable->quantval[Q03_POS] == 0 ||
440
424
        qtable->quantval[Q12_POS] == 0 ||
441
388
        qtable->quantval[Q21_POS] == 0 ||
442
340
        qtable->quantval[Q30_POS] == 0)
443
492
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
316
    coef_bits = cinfo->coef_bits[ci];
446
316
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
316
    if (coef_bits[0] < 0)
448
88
      return FALSE;
449
228
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
2.28k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
2.05k
      if (cinfo->input_scan_number > 1)
453
684
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
1.36k
      else
455
1.36k
        prev_coef_bits_latch[coefi] = -1;
456
2.05k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
2.05k
      if (coef_bits[coefi] != 0)
458
1.91k
        smoothing_useful = TRUE;
459
2.05k
    }
460
228
    coef_bits_latch += SAVED_COEFS;
461
228
    prev_coef_bits_latch += SAVED_COEFS;
462
228
  }
463
464
164
  return smoothing_useful;
465
788
}
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
792k
{
475
792k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
792k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
792k
  JDIMENSION block_num, last_block_column;
478
792k
  int ci, block_row, block_rows, access_rows, image_block_row,
479
792k
    image_block_rows;
480
792k
  JBLOCKARRAY buffer;
481
792k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
792k
  JBLOCKROW next_block_row, next_next_block_row;
483
792k
  _JSAMPARRAY output_ptr;
484
792k
  JDIMENSION output_col;
485
792k
  jpeg_component_info *compptr;
486
792k
  _inverse_DCT_method_ptr inverse_DCT;
487
792k
  boolean change_dc;
488
792k
  JCOEF *workspace;
489
792k
  int *coef_bits;
490
792k
  JQUANT_TBL *quanttbl;
491
792k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
792k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
792k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
792k
      DC25;
495
792k
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
792k
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
792k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
792k
         !cinfo->inputctl->eoi_reached) {
503
0
    if (cinfo->input_scan_number == cinfo->output_scan_number) {
504
      /* If input is working on current scan, we ordinarily want it to
505
       * have completed the current row.  But if input scan is DC,
506
       * we want it to keep two rows ahead so that next two block rows' DC
507
       * values are up to date.
508
       */
509
0
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
510
0
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
511
0
        break;
512
0
    }
513
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
514
0
      return JPEG_SUSPENDED;
515
0
  }
516
517
  /* OK, output from the virtual arrays. */
518
1.79M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
1.00M
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
1.00M
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
1.00M
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
998k
      block_rows = compptr->v_samp_factor;
526
998k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
998k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
2.02k
      block_rows = compptr->v_samp_factor;
529
2.02k
      access_rows = block_rows * 2; /* this and next iMCU row */
530
2.21k
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
2.21k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
2.21k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
2.21k
      access_rows = block_rows; /* this iMCU row only */
535
2.21k
    }
536
    /* Align the virtual buffer for this component. */
537
1.00M
    if (cinfo->output_iMCU_row > 1) {
538
998k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
998k
      buffer = (*cinfo->mem->access_virt_barray)
540
998k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
998k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
998k
         (JDIMENSION)access_rows, FALSE);
543
998k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
998k
    } else if (cinfo->output_iMCU_row > 0) {
545
2.02k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
2.02k
      buffer = (*cinfo->mem->access_virt_barray)
547
2.02k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
2.02k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
2.02k
         (JDIMENSION)access_rows, FALSE);
550
2.02k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
2.21k
    } else {
552
2.21k
      buffer = (*cinfo->mem->access_virt_barray)
553
2.21k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
2.21k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
2.21k
    }
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
1.00M
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
561
475k
      coef_bits =
562
475k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
563
526k
    else
564
526k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
565
566
    /* We only do DC interpolation if no AC coefficient data is available. */
567
1.00M
    change_dc =
568
1.00M
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
843k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
742k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
1.00M
    quanttbl = compptr->quant_table;
573
1.00M
    Q00 = quanttbl->quantval[0];
574
1.00M
    Q01 = quanttbl->quantval[Q01_POS];
575
1.00M
    Q10 = quanttbl->quantval[Q10_POS];
576
1.00M
    Q20 = quanttbl->quantval[Q20_POS];
577
1.00M
    Q11 = quanttbl->quantval[Q11_POS];
578
1.00M
    Q02 = quanttbl->quantval[Q02_POS];
579
1.00M
    if (change_dc) {
580
716k
      Q03 = quanttbl->quantval[Q03_POS];
581
716k
      Q12 = quanttbl->quantval[Q12_POS];
582
716k
      Q21 = quanttbl->quantval[Q21_POS];
583
716k
      Q30 = quanttbl->quantval[Q30_POS];
584
716k
    }
585
1.00M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
1.00M
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
1.00M
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
2.28M
    for (block_row = 0; block_row < block_rows; block_row++) {
590
1.28M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
1.28M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
1.28M
      if (image_block_row > 0)
594
1.27M
        prev_block_row =
595
1.27M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
2.21k
      else
597
2.21k
        prev_block_row = buffer_ptr;
598
599
1.28M
      if (image_block_row > 1)
600
1.27M
        prev_prev_block_row =
601
1.27M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
4.36k
      else
603
4.36k
        prev_prev_block_row = prev_block_row;
604
605
1.28M
      if (image_block_row < image_block_rows - 1)
606
1.27M
        next_block_row =
607
1.27M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
2.21k
      else
609
2.21k
        next_block_row = buffer_ptr;
610
611
1.28M
      if (image_block_row < image_block_rows - 2)
612
1.27M
        next_next_block_row =
613
1.27M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
3.97k
      else
615
3.97k
        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
1.28M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
1.28M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
1.28M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
1.28M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
1.28M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
1.28M
      output_col = 0;
626
1.28M
      last_block_column = compptr->width_in_blocks - 1;
627
1.28M
      for (block_num = cinfo->master->first_MCU_col[ci];
628
14.5M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
13.3M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
13.3M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
1.28M
            block_num < last_block_column) {
634
1.01M
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
1.01M
          DC09 = DC10 = (int)prev_block_row[1][0];
636
1.01M
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
1.01M
          DC19 = DC20 = (int)next_block_row[1][0];
638
1.01M
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
1.01M
        }
640
13.3M
        if (block_num + 1 < last_block_column) {
641
11.0M
          DC05 = (int)prev_prev_block_row[2][0];
642
11.0M
          DC10 = (int)prev_block_row[2][0];
643
11.0M
          DC15 = (int)buffer_ptr[2][0];
644
11.0M
          DC20 = (int)next_block_row[2][0];
645
11.0M
          DC25 = (int)next_next_block_row[2][0];
646
11.0M
        }
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
13.3M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
12.6M
          num = Q00 * (change_dc ?
660
7.90M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
7.90M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
7.90M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
7.90M
                 DC21 - DC22 + DC24 + DC25) :
664
12.6M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
12.6M
          if (num >= 0) {
666
9.63M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
9.63M
            if (Al > 0 && pred >= (1 << Al))
668
684k
              pred = (1 << Al) - 1;
669
9.63M
          } else {
670
2.99M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
2.99M
            if (Al > 0 && pred >= (1 << Al))
672
603k
              pred = (1 << Al) - 1;
673
2.99M
            pred = -pred;
674
2.99M
          }
675
12.6M
          workspace[1] = (JCOEF)pred;
676
12.6M
        }
677
        /* AC10 */
678
13.3M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
12.6M
          num = Q00 * (change_dc ?
680
7.90M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
7.90M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
7.90M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
7.90M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
12.6M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
12.6M
          if (num >= 0) {
686
9.01M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
9.01M
            if (Al > 0 && pred >= (1 << Al))
688
1.18M
              pred = (1 << Al) - 1;
689
9.01M
          } else {
690
3.62M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
3.62M
            if (Al > 0 && pred >= (1 << Al))
692
1.06M
              pred = (1 << Al) - 1;
693
3.62M
            pred = -pred;
694
3.62M
          }
695
12.6M
          workspace[8] = (JCOEF)pred;
696
12.6M
        }
697
        /* AC20 */
698
13.3M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
12.8M
          num = Q00 * (change_dc ?
700
7.90M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
7.90M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
12.8M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
12.8M
          if (num >= 0) {
704
8.51M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
8.51M
            if (Al > 0 && pred >= (1 << Al))
706
1.10M
              pred = (1 << Al) - 1;
707
8.51M
          } else {
708
4.28M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
4.28M
            if (Al > 0 && pred >= (1 << Al))
710
1.11M
              pred = (1 << Al) - 1;
711
4.28M
            pred = -pred;
712
4.28M
          }
713
12.8M
          workspace[16] = (JCOEF)pred;
714
12.8M
        }
715
        /* AC11 */
716
13.3M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
12.7M
          num = Q00 * (change_dc ?
718
7.90M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
7.90M
                 9 * DC19 + DC21 - DC25) :
720
12.7M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
4.84M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
12.7M
          if (num >= 0) {
723
10.1M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
10.1M
            if (Al > 0 && pred >= (1 << Al))
725
428k
              pred = (1 << Al) - 1;
726
10.1M
          } else {
727
2.64M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
2.64M
            if (Al > 0 && pred >= (1 << Al))
729
462k
              pred = (1 << Al) - 1;
730
2.64M
            pred = -pred;
731
2.64M
          }
732
12.7M
          workspace[9] = (JCOEF)pred;
733
12.7M
        }
734
        /* AC02 */
735
13.3M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
12.7M
          num = Q00 * (change_dc ?
737
7.90M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
7.90M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
12.7M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
12.7M
          if (num >= 0) {
741
8.42M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
8.42M
            if (Al > 0 && pred >= (1 << Al))
743
610k
              pred = (1 << Al) - 1;
744
8.42M
          } else {
745
4.29M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
4.29M
            if (Al > 0 && pred >= (1 << Al))
747
612k
              pred = (1 << Al) - 1;
748
4.29M
            pred = -pred;
749
4.29M
          }
750
12.7M
          workspace[2] = (JCOEF)pred;
751
12.7M
        }
752
13.3M
        if (change_dc) {
753
          /* AC03 */
754
7.90M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
7.90M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
7.90M
            if (num >= 0) {
757
6.38M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
6.38M
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
6.38M
            } else {
761
1.51M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
1.51M
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
1.51M
              pred = -pred;
765
1.51M
            }
766
7.90M
            workspace[3] = (JCOEF)pred;
767
7.90M
          }
768
          /* AC12 */
769
7.90M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
7.90M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
7.90M
            if (num >= 0) {
772
5.62M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
5.62M
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
5.62M
            } else {
776
2.27M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
2.27M
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
2.27M
              pred = -pred;
780
2.27M
            }
781
7.90M
            workspace[10] = (JCOEF)pred;
782
7.90M
          }
783
          /* AC21 */
784
7.90M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
7.90M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
7.90M
            if (num >= 0) {
787
4.99M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
4.99M
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
4.99M
            } else {
791
2.91M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
2.91M
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
2.91M
              pred = -pred;
795
2.91M
            }
796
7.90M
            workspace[17] = (JCOEF)pred;
797
7.90M
          }
798
          /* AC30 */
799
7.90M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
7.90M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
7.90M
            if (num >= 0) {
802
5.95M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
5.95M
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
5.95M
            } else {
806
1.94M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
1.94M
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
1.94M
              pred = -pred;
810
1.94M
            }
811
7.90M
            workspace[24] = (JCOEF)pred;
812
7.90M
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
7.90M
          num = Q00 *
817
7.90M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
7.90M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
7.90M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
7.90M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
7.90M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
7.90M
          if (num >= 0) {
823
5.29M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
5.29M
          } else {
825
2.60M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
2.60M
            pred = -pred;
827
2.60M
          }
828
7.90M
          workspace[0] = (JCOEF)pred;
829
7.90M
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
13.3M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
13.3M
                        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
13.3M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
13.3M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
13.3M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
13.3M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
13.3M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
13.3M
        buffer_ptr++, prev_block_row++, next_block_row++,
848
13.3M
          prev_prev_block_row++, next_next_block_row++;
849
13.3M
        output_col += compptr->_DCT_scaled_size;
850
13.3M
      }
851
1.28M
      output_ptr += compptr->_DCT_scaled_size;
852
1.28M
    }
853
1.00M
  }
854
855
792k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
790k
    return JPEG_ROW_COMPLETED;
857
1.70k
  return JPEG_SCAN_COMPLETED;
858
792k
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
474
792k
{
475
792k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
792k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
792k
  JDIMENSION block_num, last_block_column;
478
792k
  int ci, block_row, block_rows, access_rows, image_block_row,
479
792k
    image_block_rows;
480
792k
  JBLOCKARRAY buffer;
481
792k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
792k
  JBLOCKROW next_block_row, next_next_block_row;
483
792k
  _JSAMPARRAY output_ptr;
484
792k
  JDIMENSION output_col;
485
792k
  jpeg_component_info *compptr;
486
792k
  _inverse_DCT_method_ptr inverse_DCT;
487
792k
  boolean change_dc;
488
792k
  JCOEF *workspace;
489
792k
  int *coef_bits;
490
792k
  JQUANT_TBL *quanttbl;
491
792k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
792k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
792k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
792k
      DC25;
495
792k
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
792k
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
792k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
792k
         !cinfo->inputctl->eoi_reached) {
503
0
    if (cinfo->input_scan_number == cinfo->output_scan_number) {
504
      /* If input is working on current scan, we ordinarily want it to
505
       * have completed the current row.  But if input scan is DC,
506
       * we want it to keep two rows ahead so that next two block rows' DC
507
       * values are up to date.
508
       */
509
0
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
510
0
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
511
0
        break;
512
0
    }
513
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
514
0
      return JPEG_SUSPENDED;
515
0
  }
516
517
  /* OK, output from the virtual arrays. */
518
1.79M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
1.00M
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
1.00M
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
1.00M
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
998k
      block_rows = compptr->v_samp_factor;
526
998k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
998k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
2.02k
      block_rows = compptr->v_samp_factor;
529
2.02k
      access_rows = block_rows * 2; /* this and next iMCU row */
530
2.21k
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
2.21k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
2.21k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
2.21k
      access_rows = block_rows; /* this iMCU row only */
535
2.21k
    }
536
    /* Align the virtual buffer for this component. */
537
1.00M
    if (cinfo->output_iMCU_row > 1) {
538
998k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
998k
      buffer = (*cinfo->mem->access_virt_barray)
540
998k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
998k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
998k
         (JDIMENSION)access_rows, FALSE);
543
998k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
998k
    } else if (cinfo->output_iMCU_row > 0) {
545
2.02k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
2.02k
      buffer = (*cinfo->mem->access_virt_barray)
547
2.02k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
2.02k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
2.02k
         (JDIMENSION)access_rows, FALSE);
550
2.02k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
2.21k
    } else {
552
2.21k
      buffer = (*cinfo->mem->access_virt_barray)
553
2.21k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
2.21k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
2.21k
    }
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
1.00M
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
561
475k
      coef_bits =
562
475k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
563
526k
    else
564
526k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
565
566
    /* We only do DC interpolation if no AC coefficient data is available. */
567
1.00M
    change_dc =
568
1.00M
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
843k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
742k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
1.00M
    quanttbl = compptr->quant_table;
573
1.00M
    Q00 = quanttbl->quantval[0];
574
1.00M
    Q01 = quanttbl->quantval[Q01_POS];
575
1.00M
    Q10 = quanttbl->quantval[Q10_POS];
576
1.00M
    Q20 = quanttbl->quantval[Q20_POS];
577
1.00M
    Q11 = quanttbl->quantval[Q11_POS];
578
1.00M
    Q02 = quanttbl->quantval[Q02_POS];
579
1.00M
    if (change_dc) {
580
716k
      Q03 = quanttbl->quantval[Q03_POS];
581
716k
      Q12 = quanttbl->quantval[Q12_POS];
582
716k
      Q21 = quanttbl->quantval[Q21_POS];
583
716k
      Q30 = quanttbl->quantval[Q30_POS];
584
716k
    }
585
1.00M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
1.00M
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
1.00M
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
2.28M
    for (block_row = 0; block_row < block_rows; block_row++) {
590
1.28M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
1.28M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
1.28M
      if (image_block_row > 0)
594
1.27M
        prev_block_row =
595
1.27M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
2.21k
      else
597
2.21k
        prev_block_row = buffer_ptr;
598
599
1.28M
      if (image_block_row > 1)
600
1.27M
        prev_prev_block_row =
601
1.27M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
4.36k
      else
603
4.36k
        prev_prev_block_row = prev_block_row;
604
605
1.28M
      if (image_block_row < image_block_rows - 1)
606
1.27M
        next_block_row =
607
1.27M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
2.21k
      else
609
2.21k
        next_block_row = buffer_ptr;
610
611
1.28M
      if (image_block_row < image_block_rows - 2)
612
1.27M
        next_next_block_row =
613
1.27M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
3.97k
      else
615
3.97k
        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
1.28M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
1.28M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
1.28M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
1.28M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
1.28M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
1.28M
      output_col = 0;
626
1.28M
      last_block_column = compptr->width_in_blocks - 1;
627
1.28M
      for (block_num = cinfo->master->first_MCU_col[ci];
628
14.5M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
13.3M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
13.3M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
1.28M
            block_num < last_block_column) {
634
1.01M
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
1.01M
          DC09 = DC10 = (int)prev_block_row[1][0];
636
1.01M
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
1.01M
          DC19 = DC20 = (int)next_block_row[1][0];
638
1.01M
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
1.01M
        }
640
13.3M
        if (block_num + 1 < last_block_column) {
641
11.0M
          DC05 = (int)prev_prev_block_row[2][0];
642
11.0M
          DC10 = (int)prev_block_row[2][0];
643
11.0M
          DC15 = (int)buffer_ptr[2][0];
644
11.0M
          DC20 = (int)next_block_row[2][0];
645
11.0M
          DC25 = (int)next_next_block_row[2][0];
646
11.0M
        }
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
13.3M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
12.6M
          num = Q00 * (change_dc ?
660
7.90M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
7.90M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
7.90M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
7.90M
                 DC21 - DC22 + DC24 + DC25) :
664
12.6M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
12.6M
          if (num >= 0) {
666
9.63M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
9.63M
            if (Al > 0 && pred >= (1 << Al))
668
684k
              pred = (1 << Al) - 1;
669
9.63M
          } else {
670
2.99M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
2.99M
            if (Al > 0 && pred >= (1 << Al))
672
603k
              pred = (1 << Al) - 1;
673
2.99M
            pred = -pred;
674
2.99M
          }
675
12.6M
          workspace[1] = (JCOEF)pred;
676
12.6M
        }
677
        /* AC10 */
678
13.3M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
12.6M
          num = Q00 * (change_dc ?
680
7.90M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
7.90M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
7.90M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
7.90M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
12.6M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
12.6M
          if (num >= 0) {
686
9.01M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
9.01M
            if (Al > 0 && pred >= (1 << Al))
688
1.18M
              pred = (1 << Al) - 1;
689
9.01M
          } else {
690
3.62M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
3.62M
            if (Al > 0 && pred >= (1 << Al))
692
1.06M
              pred = (1 << Al) - 1;
693
3.62M
            pred = -pred;
694
3.62M
          }
695
12.6M
          workspace[8] = (JCOEF)pred;
696
12.6M
        }
697
        /* AC20 */
698
13.3M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
12.8M
          num = Q00 * (change_dc ?
700
7.90M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
7.90M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
12.8M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
12.8M
          if (num >= 0) {
704
8.51M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
8.51M
            if (Al > 0 && pred >= (1 << Al))
706
1.10M
              pred = (1 << Al) - 1;
707
8.51M
          } else {
708
4.28M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
4.28M
            if (Al > 0 && pred >= (1 << Al))
710
1.11M
              pred = (1 << Al) - 1;
711
4.28M
            pred = -pred;
712
4.28M
          }
713
12.8M
          workspace[16] = (JCOEF)pred;
714
12.8M
        }
715
        /* AC11 */
716
13.3M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
12.7M
          num = Q00 * (change_dc ?
718
7.90M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
7.90M
                 9 * DC19 + DC21 - DC25) :
720
12.7M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
4.84M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
12.7M
          if (num >= 0) {
723
10.1M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
10.1M
            if (Al > 0 && pred >= (1 << Al))
725
428k
              pred = (1 << Al) - 1;
726
10.1M
          } else {
727
2.64M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
2.64M
            if (Al > 0 && pred >= (1 << Al))
729
462k
              pred = (1 << Al) - 1;
730
2.64M
            pred = -pred;
731
2.64M
          }
732
12.7M
          workspace[9] = (JCOEF)pred;
733
12.7M
        }
734
        /* AC02 */
735
13.3M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
12.7M
          num = Q00 * (change_dc ?
737
7.90M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
7.90M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
12.7M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
12.7M
          if (num >= 0) {
741
8.42M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
8.42M
            if (Al > 0 && pred >= (1 << Al))
743
610k
              pred = (1 << Al) - 1;
744
8.42M
          } else {
745
4.29M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
4.29M
            if (Al > 0 && pred >= (1 << Al))
747
612k
              pred = (1 << Al) - 1;
748
4.29M
            pred = -pred;
749
4.29M
          }
750
12.7M
          workspace[2] = (JCOEF)pred;
751
12.7M
        }
752
13.3M
        if (change_dc) {
753
          /* AC03 */
754
7.90M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
7.90M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
7.90M
            if (num >= 0) {
757
6.38M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
6.38M
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
6.38M
            } else {
761
1.51M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
1.51M
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
1.51M
              pred = -pred;
765
1.51M
            }
766
7.90M
            workspace[3] = (JCOEF)pred;
767
7.90M
          }
768
          /* AC12 */
769
7.90M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
7.90M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
7.90M
            if (num >= 0) {
772
5.62M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
5.62M
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
5.62M
            } else {
776
2.27M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
2.27M
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
2.27M
              pred = -pred;
780
2.27M
            }
781
7.90M
            workspace[10] = (JCOEF)pred;
782
7.90M
          }
783
          /* AC21 */
784
7.90M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
7.90M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
7.90M
            if (num >= 0) {
787
4.99M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
4.99M
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
4.99M
            } else {
791
2.91M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
2.91M
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
2.91M
              pred = -pred;
795
2.91M
            }
796
7.90M
            workspace[17] = (JCOEF)pred;
797
7.90M
          }
798
          /* AC30 */
799
7.90M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
7.90M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
7.90M
            if (num >= 0) {
802
5.95M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
5.95M
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
5.95M
            } else {
806
1.94M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
1.94M
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
1.94M
              pred = -pred;
810
1.94M
            }
811
7.90M
            workspace[24] = (JCOEF)pred;
812
7.90M
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
7.90M
          num = Q00 *
817
7.90M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
7.90M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
7.90M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
7.90M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
7.90M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
7.90M
          if (num >= 0) {
823
5.29M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
5.29M
          } else {
825
2.60M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
2.60M
            pred = -pred;
827
2.60M
          }
828
7.90M
          workspace[0] = (JCOEF)pred;
829
7.90M
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
13.3M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
13.3M
                        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
13.3M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
13.3M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
13.3M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
13.3M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
13.3M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
13.3M
        buffer_ptr++, prev_block_row++, next_block_row++,
848
13.3M
          prev_prev_block_row++, next_next_block_row++;
849
13.3M
        output_col += compptr->_DCT_scaled_size;
850
13.3M
      }
851
1.28M
      output_ptr += compptr->_DCT_scaled_size;
852
1.28M
    }
853
1.00M
  }
854
855
792k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
790k
    return JPEG_ROW_COMPLETED;
857
1.70k
  return JPEG_SCAN_COMPLETED;
858
792k
}
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
12.8k
{
870
12.8k
  my_coef_ptr coef;
871
872
12.8k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
12.8k
  coef = (my_coef_ptr)
876
12.8k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
12.8k
                                sizeof(my_coef_controller));
878
12.8k
  memset(coef, 0, sizeof(my_coef_controller));
879
12.8k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
12.8k
  coef->pub.start_input_pass = start_input_pass;
881
12.8k
  coef->pub.start_output_pass = start_output_pass;
882
12.8k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
12.8k
  coef->coef_bits_latch = NULL;
884
12.8k
#endif
885
886
  /* Create the coefficient buffer. */
887
12.8k
  if (need_full_buffer) {
888
9.07k
#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
9.07k
    int ci, access_rows;
893
9.07k
    jpeg_component_info *compptr;
894
895
24.5k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
15.5k
         ci++, compptr++) {
897
15.5k
      access_rows = compptr->v_samp_factor;
898
15.5k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
15.5k
      if (cinfo->progressive_mode)
901
9.76k
        access_rows *= 5;
902
15.5k
#endif
903
15.5k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
15.5k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
15.5k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
15.5k
                               (long)compptr->h_samp_factor),
907
15.5k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
15.5k
                               (long)compptr->v_samp_factor),
909
15.5k
         (JDIMENSION)access_rows);
910
15.5k
    }
911
9.07k
    coef->pub.consume_data = consume_data;
912
9.07k
    coef->pub._decompress_data = decompress_data;
913
9.07k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
9.07k
  } else {
918
    /* We only need a single-MCU buffer. */
919
3.73k
    JBLOCKROW buffer;
920
3.73k
    int i;
921
922
3.73k
    buffer = (JBLOCKROW)
923
3.73k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
3.73k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
41.0k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
37.3k
      coef->MCU_buffer[i] = buffer + i;
927
37.3k
    }
928
3.73k
    coef->pub.consume_data = dummy_consume_data;
929
3.73k
    coef->pub._decompress_data = decompress_onepass;
930
3.73k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
3.73k
  }
932
933
  /* Allocate the workspace buffer */
934
12.8k
  coef->workspace = (JCOEF *)
935
12.8k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
12.8k
                                sizeof(JCOEF) * DCTSIZE2);
937
12.8k
}
jinit_d_coef_controller
Line
Count
Source
869
11.3k
{
870
11.3k
  my_coef_ptr coef;
871
872
11.3k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
11.3k
  coef = (my_coef_ptr)
876
11.3k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
11.3k
                                sizeof(my_coef_controller));
878
11.3k
  memset(coef, 0, sizeof(my_coef_controller));
879
11.3k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
11.3k
  coef->pub.start_input_pass = start_input_pass;
881
11.3k
  coef->pub.start_output_pass = start_output_pass;
882
11.3k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
11.3k
  coef->coef_bits_latch = NULL;
884
11.3k
#endif
885
886
  /* Create the coefficient buffer. */
887
11.3k
  if (need_full_buffer) {
888
7.66k
#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
7.66k
    int ci, access_rows;
893
7.66k
    jpeg_component_info *compptr;
894
895
20.5k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
12.8k
         ci++, compptr++) {
897
12.8k
      access_rows = compptr->v_samp_factor;
898
12.8k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
12.8k
      if (cinfo->progressive_mode)
901
8.54k
        access_rows *= 5;
902
12.8k
#endif
903
12.8k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
12.8k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
12.8k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
12.8k
                               (long)compptr->h_samp_factor),
907
12.8k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
12.8k
                               (long)compptr->v_samp_factor),
909
12.8k
         (JDIMENSION)access_rows);
910
12.8k
    }
911
7.66k
    coef->pub.consume_data = consume_data;
912
7.66k
    coef->pub._decompress_data = decompress_data;
913
7.66k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
7.66k
  } else {
918
    /* We only need a single-MCU buffer. */
919
3.65k
    JBLOCKROW buffer;
920
3.65k
    int i;
921
922
3.65k
    buffer = (JBLOCKROW)
923
3.65k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
3.65k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
40.2k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
36.5k
      coef->MCU_buffer[i] = buffer + i;
927
36.5k
    }
928
3.65k
    coef->pub.consume_data = dummy_consume_data;
929
3.65k
    coef->pub._decompress_data = decompress_onepass;
930
3.65k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
3.65k
  }
932
933
  /* Allocate the workspace buffer */
934
11.3k
  coef->workspace = (JCOEF *)
935
11.3k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
11.3k
                                sizeof(JCOEF) * DCTSIZE2);
937
11.3k
}
j12init_d_coef_controller
Line
Count
Source
869
1.48k
{
870
1.48k
  my_coef_ptr coef;
871
872
1.48k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
1.48k
  coef = (my_coef_ptr)
876
1.48k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
1.48k
                                sizeof(my_coef_controller));
878
1.48k
  memset(coef, 0, sizeof(my_coef_controller));
879
1.48k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
1.48k
  coef->pub.start_input_pass = start_input_pass;
881
1.48k
  coef->pub.start_output_pass = start_output_pass;
882
1.48k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
1.48k
  coef->coef_bits_latch = NULL;
884
1.48k
#endif
885
886
  /* Create the coefficient buffer. */
887
1.48k
  if (need_full_buffer) {
888
1.40k
#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.40k
    int ci, access_rows;
893
1.40k
    jpeg_component_info *compptr;
894
895
4.04k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
2.63k
         ci++, compptr++) {
897
2.63k
      access_rows = compptr->v_samp_factor;
898
2.63k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
2.63k
      if (cinfo->progressive_mode)
901
1.21k
        access_rows *= 5;
902
2.63k
#endif
903
2.63k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
2.63k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
2.63k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
2.63k
                               (long)compptr->h_samp_factor),
907
2.63k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
2.63k
                               (long)compptr->v_samp_factor),
909
2.63k
         (JDIMENSION)access_rows);
910
2.63k
    }
911
1.40k
    coef->pub.consume_data = consume_data;
912
1.40k
    coef->pub._decompress_data = decompress_data;
913
1.40k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
1.40k
  } else {
918
    /* We only need a single-MCU buffer. */
919
76
    JBLOCKROW buffer;
920
76
    int i;
921
922
76
    buffer = (JBLOCKROW)
923
76
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
76
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
836
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
760
      coef->MCU_buffer[i] = buffer + i;
927
760
    }
928
76
    coef->pub.consume_data = dummy_consume_data;
929
76
    coef->pub._decompress_data = decompress_onepass;
930
76
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
76
  }
932
933
  /* Allocate the workspace buffer */
934
1.48k
  coef->workspace = (JCOEF *)
935
1.48k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
1.48k
                                sizeof(JCOEF) * DCTSIZE2);
937
1.48k
}