Coverage Report

Created: 2026-09-03 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo/src/jdcoefct.c
Line
Count
Source
1
/*
2
 * jdcoefct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1997, Thomas G. Lane.
6
 * libjpeg-turbo Modifications:
7
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
8
 * Copyright (C) 2010, 2015-2016, 2019-2020, 2022-2026, D. R. Commander.
9
 * Copyright (C) 2015, 2020, Google, Inc.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the coefficient buffer controller for decompression.
14
 * This controller is the top level of the lossy JPEG decompressor proper.
15
 * The coefficient buffer lies between entropy decoding and inverse-DCT steps.
16
 *
17
 * In buffered-image mode, this controller is the interface between
18
 * input-oriented processing and output-oriented processing.
19
 * Also, the input side (only) is used when reading a file for transcoding.
20
 */
21
22
#include "jinclude.h"
23
#include "jdcoefct.h"
24
#include "jpegapicomp.h"
25
#include "jsamplecomp.h"
26
#ifdef WITH_PROFILE
27
#include "tjutil.h"
28
#endif
29
30
31
/* Forward declarations */
32
METHODDEF(int) decompress_onepass(j_decompress_ptr cinfo,
33
                                  _JSAMPIMAGE output_buf);
34
#ifdef D_MULTISCAN_FILES_SUPPORTED
35
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
36
#endif
37
#ifdef BLOCK_SMOOTHING_SUPPORTED
38
LOCAL(boolean) smoothing_ok(j_decompress_ptr cinfo);
39
METHODDEF(int) decompress_smooth_data(j_decompress_ptr cinfo,
40
                                      _JSAMPIMAGE output_buf);
41
#endif
42
43
44
/*
45
 * Initialize for an input processing pass.
46
 */
47
48
METHODDEF(void)
49
start_input_pass(j_decompress_ptr cinfo)
50
97.7k
{
51
97.7k
  cinfo->input_iMCU_row = 0;
52
97.7k
  start_iMCU_row(cinfo);
53
97.7k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
50
85.4k
{
51
85.4k
  cinfo->input_iMCU_row = 0;
52
85.4k
  start_iMCU_row(cinfo);
53
85.4k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
50
12.2k
{
51
12.2k
  cinfo->input_iMCU_row = 0;
52
12.2k
  start_iMCU_row(cinfo);
53
12.2k
}
54
55
56
/*
57
 * Initialize for an output processing pass.
58
 */
59
60
METHODDEF(void)
61
start_output_pass(j_decompress_ptr cinfo)
62
32.8k
{
63
32.8k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
32.8k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
65
66
  /* If multipass, check to see whether to use block smoothing on this pass */
67
32.8k
  if (coef->pub.coef_arrays != NULL) {
68
13.7k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
8.83k
      coef->pub._decompress_data = decompress_smooth_data;
70
4.87k
    else
71
4.87k
      coef->pub._decompress_data = decompress_data;
72
13.7k
  }
73
32.8k
#endif
74
32.8k
  cinfo->output_iMCU_row = 0;
75
32.8k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
62
31.4k
{
63
31.4k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
31.4k
  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
31.4k
  if (coef->pub.coef_arrays != NULL) {
68
12.4k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
8.39k
      coef->pub._decompress_data = decompress_smooth_data;
70
4.06k
    else
71
4.06k
      coef->pub._decompress_data = decompress_data;
72
12.4k
  }
73
31.4k
#endif
74
31.4k
  cinfo->output_iMCU_row = 0;
75
31.4k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
62
1.37k
{
63
1.37k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
1.37k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
65
66
  /* If multipass, check to see whether to use block smoothing on this pass */
67
1.37k
  if (coef->pub.coef_arrays != NULL) {
68
1.24k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
443
      coef->pub._decompress_data = decompress_smooth_data;
70
805
    else
71
805
      coef->pub._decompress_data = decompress_data;
72
1.24k
  }
73
1.37k
#endif
74
1.37k
  cinfo->output_iMCU_row = 0;
75
1.37k
}
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
1.13M
{
91
1.13M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
1.13M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
1.13M
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
1.13M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
1.13M
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
1.13M
  _JSAMPARRAY output_ptr;
97
1.13M
  JDIMENSION start_col, output_col;
98
1.13M
  jpeg_component_info *compptr;
99
1.13M
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
2.58M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
1.44M
       yoffset++) {
104
14.3M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
12.8M
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
12.8M
      jzero_far((void *)coef->MCU_buffer[0],
108
12.8M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
12.8M
      if (!cinfo->entropy->insufficient_data)
110
12.8M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
12.8M
      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.8M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
12.8M
          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.8M
        blkn = 0;               /* index of current DCT block within MCU */
142
34.7M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
21.8M
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
21.8M
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
21.8M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
21.8M
          useful_width = (MCU_col_num < last_MCU_col) ?
151
19.0M
                         compptr->MCU_width : compptr->last_col_width;
152
21.8M
          output_ptr = output_buf[compptr->component_index] +
153
21.8M
                       yoffset * compptr->_DCT_scaled_size;
154
21.8M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
21.8M
                      compptr->MCU_sample_width;
156
48.2M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
26.3M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
23.6M
                yoffset + yindex < compptr->last_row_height) {
159
23.6M
              output_col = start_col;
160
48.7M
              for (xindex = 0; xindex < useful_width; xindex++) {
161
#ifdef WITH_PROFILE
162
                cinfo->master->start = getTime();
163
#endif
164
25.1M
                (*inverse_DCT) (cinfo, compptr,
165
25.1M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
25.1M
                                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
25.1M
                output_col += compptr->_DCT_scaled_size;
173
25.1M
              }
174
23.6M
            }
175
26.3M
            blkn += compptr->MCU_width;
176
26.3M
            output_ptr += compptr->_DCT_scaled_size;
177
26.3M
          }
178
21.8M
        }
179
12.8M
      }
180
12.8M
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
1.44M
    coef->MCU_ctr = 0;
183
1.44M
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
1.13M
  cinfo->output_iMCU_row++;
186
1.13M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
1.12M
    start_iMCU_row(cinfo);
188
1.12M
    return JPEG_ROW_COMPLETED;
189
1.12M
  }
190
  /* Completed the scan */
191
19.0k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
19.0k
  return JPEG_SCAN_COMPLETED;
193
1.13M
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
90
1.13M
{
91
1.13M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
1.13M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
1.13M
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
1.13M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
1.13M
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
1.13M
  _JSAMPARRAY output_ptr;
97
1.13M
  JDIMENSION start_col, output_col;
98
1.13M
  jpeg_component_info *compptr;
99
1.13M
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
2.58M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
1.44M
       yoffset++) {
104
14.3M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
12.8M
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
12.8M
      jzero_far((void *)coef->MCU_buffer[0],
108
12.8M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
12.8M
      if (!cinfo->entropy->insufficient_data)
110
12.8M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
12.8M
      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.8M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
12.8M
          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.8M
        blkn = 0;               /* index of current DCT block within MCU */
142
34.7M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
21.8M
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
21.8M
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
21.8M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
21.8M
          useful_width = (MCU_col_num < last_MCU_col) ?
151
19.0M
                         compptr->MCU_width : compptr->last_col_width;
152
21.8M
          output_ptr = output_buf[compptr->component_index] +
153
21.8M
                       yoffset * compptr->_DCT_scaled_size;
154
21.8M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
21.8M
                      compptr->MCU_sample_width;
156
48.2M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
26.3M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
23.6M
                yoffset + yindex < compptr->last_row_height) {
159
23.6M
              output_col = start_col;
160
48.7M
              for (xindex = 0; xindex < useful_width; xindex++) {
161
#ifdef WITH_PROFILE
162
                cinfo->master->start = getTime();
163
#endif
164
25.1M
                (*inverse_DCT) (cinfo, compptr,
165
25.1M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
25.1M
                                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
25.1M
                output_col += compptr->_DCT_scaled_size;
173
25.1M
              }
174
23.6M
            }
175
26.3M
            blkn += compptr->MCU_width;
176
26.3M
            output_ptr += compptr->_DCT_scaled_size;
177
26.3M
          }
178
21.8M
        }
179
12.8M
      }
180
12.8M
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
1.44M
    coef->MCU_ctr = 0;
183
1.44M
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
1.13M
  cinfo->output_iMCU_row++;
186
1.13M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
1.12M
    start_iMCU_row(cinfo);
188
1.12M
    return JPEG_ROW_COMPLETED;
189
1.12M
  }
190
  /* Completed the scan */
191
19.0k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
19.0k
  return JPEG_SCAN_COMPLETED;
193
1.13M
}
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
6.22M
{
219
6.22M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
6.22M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
6.22M
  int blkn, ci, xindex, yindex, yoffset;
222
6.22M
  JDIMENSION start_col;
223
6.22M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
6.22M
  JBLOCKROW buffer_ptr;
225
6.22M
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
15.9M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
9.68M
    compptr = cinfo->cur_comp_info[ci];
230
9.68M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
9.68M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
9.68M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
9.68M
       (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.68M
  }
239
240
  /* Loop to process one whole iMCU row */
241
15.9M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
9.67M
       yoffset++) {
243
105M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
96.1M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
96.1M
      blkn = 0;                 /* index of current DCT block within MCU */
247
225M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
129M
        compptr = cinfo->cur_comp_info[ci];
249
129M
        start_col = MCU_col_num * compptr->MCU_width;
250
276M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
147M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
312M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
165M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
165M
          }
255
147M
        }
256
129M
      }
257
96.1M
      if (!cinfo->entropy->insufficient_data)
258
96.1M
        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
96.1M
      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
96.1M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
9.67M
    coef->MCU_ctr = 0;
282
9.67M
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
6.22M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
6.14M
    start_iMCU_row(cinfo);
286
6.14M
    return JPEG_ROW_COMPLETED;
287
6.14M
  }
288
  /* Completed the scan */
289
78.5k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
78.5k
  return JPEG_SCAN_COMPLETED;
291
6.22M
}
jdcoefct-8.c:consume_data
Line
Count
Source
218
5.38M
{
219
5.38M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
5.38M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
5.38M
  int blkn, ci, xindex, yindex, yoffset;
222
5.38M
  JDIMENSION start_col;
223
5.38M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
5.38M
  JBLOCKROW buffer_ptr;
225
5.38M
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
13.5M
  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
13.7M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
8.37M
       yoffset++) {
243
90.6M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
82.2M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
82.2M
      blkn = 0;                 /* index of current DCT block within MCU */
247
189M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
107M
        compptr = cinfo->cur_comp_info[ci];
249
107M
        start_col = MCU_col_num * compptr->MCU_width;
250
228M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
120M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
253M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
133M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
133M
          }
255
120M
        }
256
107M
      }
257
82.2M
      if (!cinfo->entropy->insufficient_data)
258
82.2M
        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
82.2M
      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
82.2M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
8.37M
    coef->MCU_ctr = 0;
282
8.37M
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
5.38M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
5.31M
    start_iMCU_row(cinfo);
286
5.31M
    return JPEG_ROW_COMPLETED;
287
5.31M
  }
288
  /* Completed the scan */
289
66.4k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
66.4k
  return JPEG_SCAN_COMPLETED;
291
5.38M
}
jdcoefct-12.c:consume_data
Line
Count
Source
218
841k
{
219
841k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
841k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
841k
  int blkn, ci, xindex, yindex, yoffset;
222
841k
  JDIMENSION start_col;
223
841k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
841k
  JBLOCKROW buffer_ptr;
225
841k
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
2.40M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
1.56M
    compptr = cinfo->cur_comp_info[ci];
230
1.56M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
1.56M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
1.56M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
1.56M
       (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.56M
  }
239
240
  /* Loop to process one whole iMCU row */
241
2.14M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
1.30M
       yoffset++) {
243
15.2M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
13.9M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
13.9M
      blkn = 0;                 /* index of current DCT block within MCU */
247
35.5M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
21.6M
        compptr = cinfo->cur_comp_info[ci];
249
21.6M
        start_col = MCU_col_num * compptr->MCU_width;
250
48.2M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
26.5M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
58.8M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
32.2M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
32.2M
          }
255
26.5M
        }
256
21.6M
      }
257
13.9M
      if (!cinfo->entropy->insufficient_data)
258
13.9M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
259
      /* Try to fetch the MCU. */
260
#ifdef WITH_PROFILE
261
      cinfo->master->start = getTime();
262
#endif
263
13.9M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
264
        /* Suspension forced; update state counters and exit */
265
0
        coef->MCU_vert_offset = yoffset;
266
0
        coef->MCU_ctr = MCU_col_num;
267
#ifdef WITH_PROFILE
268
        cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
269
        cinfo->master->entropy_mcoeffs +=
270
          (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
271
#endif
272
0
        return JPEG_SUSPENDED;
273
0
      }
274
#ifdef WITH_PROFILE
275
      cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
276
      cinfo->master->entropy_mcoeffs +=
277
        (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
278
#endif
279
13.9M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
1.30M
    coef->MCU_ctr = 0;
282
1.30M
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
841k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
829k
    start_iMCU_row(cinfo);
286
829k
    return JPEG_ROW_COMPLETED;
287
829k
  }
288
  /* Completed the scan */
289
12.1k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
12.1k
  return JPEG_SCAN_COMPLETED;
291
841k
}
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
460k
{
305
460k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
460k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
460k
  JDIMENSION block_num;
308
460k
  int ci, block_row, block_rows;
309
460k
  JBLOCKARRAY buffer;
310
460k
  JBLOCKROW buffer_ptr;
311
460k
  _JSAMPARRAY output_ptr;
312
460k
  JDIMENSION output_col;
313
460k
  jpeg_component_info *compptr;
314
460k
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
460k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
460k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
460k
          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
1.29M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
834k
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
834k
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
834k
    buffer = (*cinfo->mem->access_virt_barray)
332
834k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
834k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
834k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
834k
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
824k
      block_rows = compptr->v_samp_factor;
338
10.6k
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
10.6k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
10.6k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
10.6k
    }
343
834k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
834k
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
2.20M
    for (block_row = 0; block_row < block_rows; block_row++) {
347
1.37M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
1.37M
      output_col = 0;
349
1.37M
      for (block_num = cinfo->master->first_MCU_col[ci];
350
12.3M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
10.9M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
10.9M
                        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
10.9M
        buffer_ptr++;
361
10.9M
        output_col += compptr->_DCT_scaled_size;
362
10.9M
      }
363
1.37M
      output_ptr += compptr->_DCT_scaled_size;
364
1.37M
    }
365
834k
  }
366
367
460k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
456k
    return JPEG_ROW_COMPLETED;
369
4.06k
  return JPEG_SCAN_COMPLETED;
370
460k
}
jdcoefct-8.c:decompress_data
Line
Count
Source
304
460k
{
305
460k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
460k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
460k
  JDIMENSION block_num;
308
460k
  int ci, block_row, block_rows;
309
460k
  JBLOCKARRAY buffer;
310
460k
  JBLOCKROW buffer_ptr;
311
460k
  _JSAMPARRAY output_ptr;
312
460k
  JDIMENSION output_col;
313
460k
  jpeg_component_info *compptr;
314
460k
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
460k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
460k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
460k
          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
1.29M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
834k
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
834k
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
834k
    buffer = (*cinfo->mem->access_virt_barray)
332
834k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
834k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
834k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
834k
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
824k
      block_rows = compptr->v_samp_factor;
338
10.6k
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
10.6k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
10.6k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
10.6k
    }
343
834k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
834k
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
2.20M
    for (block_row = 0; block_row < block_rows; block_row++) {
347
1.37M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
1.37M
      output_col = 0;
349
1.37M
      for (block_num = cinfo->master->first_MCU_col[ci];
350
12.3M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
10.9M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
10.9M
                        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
10.9M
        buffer_ptr++;
361
10.9M
        output_col += compptr->_DCT_scaled_size;
362
10.9M
      }
363
1.37M
      output_ptr += compptr->_DCT_scaled_size;
364
1.37M
    }
365
834k
  }
366
367
460k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
456k
    return JPEG_ROW_COMPLETED;
369
4.06k
  return JPEG_SCAN_COMPLETED;
370
460k
}
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.91M
#define Q01_POS  1
386
1.91M
#define Q10_POS  8
387
1.91M
#define Q20_POS  16
388
1.91M
#define Q11_POS  9
389
1.91M
#define Q02_POS  2
390
1.42M
#define Q03_POS  3
391
1.42M
#define Q12_POS  10
392
1.42M
#define Q21_POS  17
393
1.42M
#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
13.7k
{
406
13.7k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
13.7k
  boolean smoothing_useful = FALSE;
408
13.7k
  int ci, coefi;
409
13.7k
  jpeg_component_info *compptr;
410
13.7k
  JQUANT_TBL *qtable;
411
13.7k
  int *coef_bits, *prev_coef_bits;
412
13.7k
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
13.7k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
139
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
13.5k
  if (coef->coef_bits_latch == NULL)
419
13.5k
    coef->coef_bits_latch = (int *)
420
13.5k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
13.5k
                                  cinfo->num_components * 2 *
422
13.5k
                                  (SAVED_COEFS * sizeof(int)));
423
13.5k
  coef_bits_latch = coef->coef_bits_latch;
424
13.5k
  prev_coef_bits_latch =
425
13.5k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
38.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
28.0k
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
28.0k
    if ((qtable = compptr->quant_table) == NULL)
431
306
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
27.7k
    if (qtable->quantval[0] == 0 ||
434
27.4k
        qtable->quantval[Q01_POS] == 0 ||
435
27.2k
        qtable->quantval[Q10_POS] == 0 ||
436
26.9k
        qtable->quantval[Q20_POS] == 0 ||
437
26.6k
        qtable->quantval[Q11_POS] == 0 ||
438
26.2k
        qtable->quantval[Q02_POS] == 0 ||
439
25.9k
        qtable->quantval[Q03_POS] == 0 ||
440
25.7k
        qtable->quantval[Q12_POS] == 0 ||
441
25.5k
        qtable->quantval[Q21_POS] == 0 ||
442
25.3k
        qtable->quantval[Q30_POS] == 0)
443
2.65k
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
25.0k
    coef_bits = cinfo->coef_bits[ci];
446
25.0k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
25.0k
    if (coef_bits[0] < 0)
448
0
      return FALSE;
449
25.0k
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
250k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
225k
      if (cinfo->input_scan_number > 1)
453
152k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
73.3k
      else
455
73.3k
        prev_coef_bits_latch[coefi] = -1;
456
225k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
225k
      if (coef_bits[coefi] != 0)
458
171k
        smoothing_useful = TRUE;
459
225k
    }
460
25.0k
    coef_bits_latch += SAVED_COEFS;
461
25.0k
    prev_coef_bits_latch += SAVED_COEFS;
462
25.0k
  }
463
464
10.6k
  return smoothing_useful;
465
13.5k
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
405
12.4k
{
406
12.4k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
12.4k
  boolean smoothing_useful = FALSE;
408
12.4k
  int ci, coefi;
409
12.4k
  jpeg_component_info *compptr;
410
12.4k
  JQUANT_TBL *qtable;
411
12.4k
  int *coef_bits, *prev_coef_bits;
412
12.4k
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
12.4k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
95
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
12.3k
  if (coef->coef_bits_latch == NULL)
419
12.3k
    coef->coef_bits_latch = (int *)
420
12.3k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
12.3k
                                  cinfo->num_components * 2 *
422
12.3k
                                  (SAVED_COEFS * sizeof(int)));
423
12.3k
  coef_bits_latch = coef->coef_bits_latch;
424
12.3k
  prev_coef_bits_latch =
425
12.3k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
36.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
25.9k
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
25.9k
    if ((qtable = compptr->quant_table) == NULL)
431
266
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
25.6k
    if (qtable->quantval[0] == 0 ||
434
25.4k
        qtable->quantval[Q01_POS] == 0 ||
435
25.2k
        qtable->quantval[Q10_POS] == 0 ||
436
25.1k
        qtable->quantval[Q20_POS] == 0 ||
437
24.8k
        qtable->quantval[Q11_POS] == 0 ||
438
24.5k
        qtable->quantval[Q02_POS] == 0 ||
439
24.3k
        qtable->quantval[Q03_POS] == 0 ||
440
24.1k
        qtable->quantval[Q12_POS] == 0 ||
441
24.0k
        qtable->quantval[Q21_POS] == 0 ||
442
23.8k
        qtable->quantval[Q30_POS] == 0)
443
1.95k
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
23.6k
    coef_bits = cinfo->coef_bits[ci];
446
23.6k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
23.6k
    if (coef_bits[0] < 0)
448
0
      return FALSE;
449
23.6k
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
236k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
213k
      if (cinfo->input_scan_number > 1)
453
146k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
66.8k
      else
455
66.8k
        prev_coef_bits_latch[coefi] = -1;
456
213k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
213k
      if (coef_bits[coefi] != 0)
458
161k
        smoothing_useful = TRUE;
459
213k
    }
460
23.6k
    coef_bits_latch += SAVED_COEFS;
461
23.6k
    prev_coef_bits_latch += SAVED_COEFS;
462
23.6k
  }
463
464
10.1k
  return smoothing_useful;
465
12.3k
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
405
1.24k
{
406
1.24k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
1.24k
  boolean smoothing_useful = FALSE;
408
1.24k
  int ci, coefi;
409
1.24k
  jpeg_component_info *compptr;
410
1.24k
  JQUANT_TBL *qtable;
411
1.24k
  int *coef_bits, *prev_coef_bits;
412
1.24k
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
1.24k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
44
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
1.20k
  if (coef->coef_bits_latch == NULL)
419
1.20k
    coef->coef_bits_latch = (int *)
420
1.20k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
1.20k
                                  cinfo->num_components * 2 *
422
1.20k
                                  (SAVED_COEFS * sizeof(int)));
423
1.20k
  coef_bits_latch = coef->coef_bits_latch;
424
1.20k
  prev_coef_bits_latch =
425
1.20k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
2.56k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
2.10k
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
2.10k
    if ((qtable = compptr->quant_table) == NULL)
431
40
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
2.06k
    if (qtable->quantval[0] == 0 ||
434
1.98k
        qtable->quantval[Q01_POS] == 0 ||
435
1.94k
        qtable->quantval[Q10_POS] == 0 ||
436
1.82k
        qtable->quantval[Q20_POS] == 0 ||
437
1.76k
        qtable->quantval[Q11_POS] == 0 ||
438
1.70k
        qtable->quantval[Q02_POS] == 0 ||
439
1.63k
        qtable->quantval[Q03_POS] == 0 ||
440
1.57k
        qtable->quantval[Q12_POS] == 0 ||
441
1.51k
        qtable->quantval[Q21_POS] == 0 ||
442
1.45k
        qtable->quantval[Q30_POS] == 0)
443
698
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
1.36k
    coef_bits = cinfo->coef_bits[ci];
446
1.36k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
1.36k
    if (coef_bits[0] < 0)
448
0
      return FALSE;
449
1.36k
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
13.6k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
12.2k
      if (cinfo->input_scan_number > 1)
453
5.82k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
6.43k
      else
455
6.43k
        prev_coef_bits_latch[coefi] = -1;
456
12.2k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
12.2k
      if (coef_bits[coefi] != 0)
458
10.8k
        smoothing_useful = TRUE;
459
12.2k
    }
460
1.36k
    coef_bits_latch += SAVED_COEFS;
461
1.36k
    prev_coef_bits_latch += SAVED_COEFS;
462
1.36k
  }
463
464
466
  return smoothing_useful;
465
1.20k
}
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
975k
{
475
975k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
975k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
975k
  JDIMENSION block_num, last_block_column;
478
975k
  int ci, block_row, block_rows, access_rows, image_block_row,
479
975k
    image_block_rows;
480
975k
  JBLOCKARRAY buffer;
481
975k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
975k
  JBLOCKROW next_block_row, next_next_block_row;
483
975k
  _JSAMPARRAY output_ptr;
484
975k
  JDIMENSION output_col;
485
975k
  jpeg_component_info *compptr;
486
975k
  _inverse_DCT_method_ptr inverse_DCT;
487
975k
  boolean change_dc;
488
975k
  JCOEF *workspace;
489
975k
  int *coef_bits;
490
975k
  JQUANT_TBL *quanttbl;
491
975k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
975k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
975k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
975k
      DC25;
495
975k
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
975k
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
975k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
975k
         !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
2.86M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
1.88M
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
1.88M
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
1.88M
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
1.85M
      block_rows = compptr->v_samp_factor;
526
1.85M
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
1.85M
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
14.8k
      block_rows = compptr->v_samp_factor;
529
14.8k
      access_rows = block_rows * 2; /* this and next iMCU row */
530
18.0k
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
18.0k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
18.0k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
18.0k
      access_rows = block_rows; /* this iMCU row only */
535
18.0k
    }
536
    /* Align the virtual buffer for this component. */
537
1.88M
    if (cinfo->output_iMCU_row > 1) {
538
1.85M
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
1.85M
      buffer = (*cinfo->mem->access_virt_barray)
540
1.85M
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
1.85M
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
1.85M
         (JDIMENSION)access_rows, FALSE);
543
1.85M
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
1.85M
    } else if (cinfo->output_iMCU_row > 0) {
545
14.8k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
14.8k
      buffer = (*cinfo->mem->access_virt_barray)
547
14.8k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
14.8k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
14.8k
         (JDIMENSION)access_rows, FALSE);
550
14.8k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
18.0k
    } else {
552
18.0k
      buffer = (*cinfo->mem->access_virt_barray)
553
18.0k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
18.0k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
18.0k
    }
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.88M
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
561
0
      coef_bits =
562
0
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
563
1.88M
    else
564
1.88M
      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.88M
    change_dc =
568
1.88M
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
1.53M
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
1.44M
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
1.88M
    quanttbl = compptr->quant_table;
573
1.88M
    Q00 = quanttbl->quantval[0];
574
1.88M
    Q01 = quanttbl->quantval[Q01_POS];
575
1.88M
    Q10 = quanttbl->quantval[Q10_POS];
576
1.88M
    Q20 = quanttbl->quantval[Q20_POS];
577
1.88M
    Q11 = quanttbl->quantval[Q11_POS];
578
1.88M
    Q02 = quanttbl->quantval[Q02_POS];
579
1.88M
    if (change_dc) {
580
1.40M
      Q03 = quanttbl->quantval[Q03_POS];
581
1.40M
      Q12 = quanttbl->quantval[Q12_POS];
582
1.40M
      Q21 = quanttbl->quantval[Q21_POS];
583
1.40M
      Q30 = quanttbl->quantval[Q30_POS];
584
1.40M
    }
585
1.88M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
1.88M
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
1.88M
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
4.81M
    for (block_row = 0; block_row < block_rows; block_row++) {
590
2.92M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
2.92M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
2.92M
      if (image_block_row > 0)
594
2.91M
        prev_block_row =
595
2.91M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
18.0k
      else
597
18.0k
        prev_block_row = buffer_ptr;
598
599
2.92M
      if (image_block_row > 1)
600
2.89M
        prev_prev_block_row =
601
2.89M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
33.7k
      else
603
33.7k
        prev_prev_block_row = prev_block_row;
604
605
2.92M
      if (image_block_row < image_block_rows - 1)
606
2.91M
        next_block_row =
607
2.91M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
18.0k
      else
609
18.0k
        next_block_row = buffer_ptr;
610
611
2.92M
      if (image_block_row < image_block_rows - 2)
612
2.89M
        next_next_block_row =
613
2.89M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
30.2k
      else
615
30.2k
        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
2.92M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
2.92M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
2.92M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
2.92M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
2.92M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
2.92M
      output_col = 0;
626
2.92M
      last_block_column = compptr->width_in_blocks - 1;
627
2.92M
      for (block_num = cinfo->master->first_MCU_col[ci];
628
38.0M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
35.1M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
35.1M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
2.92M
            block_num < last_block_column) {
634
1.19M
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
1.19M
          DC09 = DC10 = (int)prev_block_row[1][0];
636
1.19M
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
1.19M
          DC19 = DC20 = (int)next_block_row[1][0];
638
1.19M
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
1.19M
        }
640
35.1M
        if (block_num + 1 < last_block_column) {
641
31.0M
          DC05 = (int)prev_prev_block_row[2][0];
642
31.0M
          DC10 = (int)prev_block_row[2][0];
643
31.0M
          DC15 = (int)buffer_ptr[2][0];
644
31.0M
          DC20 = (int)next_block_row[2][0];
645
31.0M
          DC25 = (int)next_next_block_row[2][0];
646
31.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
35.1M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
31.8M
          num = Q00 * (change_dc ?
660
24.4M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
24.4M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
24.4M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
24.4M
                 DC21 - DC22 + DC24 + DC25) :
664
31.8M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
31.8M
          if (num >= 0) {
666
19.9M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
19.9M
            if (Al > 0 && pred >= (1 << Al))
668
540k
              pred = (1 << Al) - 1;
669
19.9M
          } else {
670
11.8M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
11.8M
            if (Al > 0 && pred >= (1 << Al))
672
409k
              pred = (1 << Al) - 1;
673
11.8M
            pred = -pred;
674
11.8M
          }
675
31.8M
          workspace[1] = (JCOEF)pred;
676
31.8M
        }
677
        /* AC10 */
678
35.1M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
31.9M
          num = Q00 * (change_dc ?
680
24.4M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
24.4M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
24.4M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
24.4M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
31.9M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
31.9M
          if (num >= 0) {
686
23.1M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
23.1M
            if (Al > 0 && pred >= (1 << Al))
688
1.11M
              pred = (1 << Al) - 1;
689
23.1M
          } else {
690
8.79M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
8.79M
            if (Al > 0 && pred >= (1 << Al))
692
861k
              pred = (1 << Al) - 1;
693
8.79M
            pred = -pred;
694
8.79M
          }
695
31.9M
          workspace[8] = (JCOEF)pred;
696
31.9M
        }
697
        /* AC20 */
698
35.1M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
31.9M
          num = Q00 * (change_dc ?
700
24.4M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
24.4M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
31.9M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
31.9M
          if (num >= 0) {
704
19.4M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
19.4M
            if (Al > 0 && pred >= (1 << Al))
706
785k
              pred = (1 << Al) - 1;
707
19.4M
          } else {
708
12.4M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
12.4M
            if (Al > 0 && pred >= (1 << Al))
710
774k
              pred = (1 << Al) - 1;
711
12.4M
            pred = -pred;
712
12.4M
          }
713
31.9M
          workspace[16] = (JCOEF)pred;
714
31.9M
        }
715
        /* AC11 */
716
35.1M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
31.6M
          num = Q00 * (change_dc ?
718
24.4M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
24.4M
                 9 * DC19 + DC21 - DC25) :
720
31.6M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
7.25M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
31.6M
          if (num >= 0) {
723
23.5M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
23.5M
            if (Al > 0 && pred >= (1 << Al))
725
343k
              pred = (1 << Al) - 1;
726
23.5M
          } else {
727
8.17M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
8.17M
            if (Al > 0 && pred >= (1 << Al))
729
343k
              pred = (1 << Al) - 1;
730
8.17M
            pred = -pred;
731
8.17M
          }
732
31.6M
          workspace[9] = (JCOEF)pred;
733
31.6M
        }
734
        /* AC02 */
735
35.1M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
31.8M
          num = Q00 * (change_dc ?
737
24.4M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
24.4M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
31.8M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
31.8M
          if (num >= 0) {
741
19.4M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
19.4M
            if (Al > 0 && pred >= (1 << Al))
743
449k
              pred = (1 << Al) - 1;
744
19.4M
          } else {
745
12.4M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
12.4M
            if (Al > 0 && pred >= (1 << Al))
747
457k
              pred = (1 << Al) - 1;
748
12.4M
            pred = -pred;
749
12.4M
          }
750
31.8M
          workspace[2] = (JCOEF)pred;
751
31.8M
        }
752
35.1M
        if (change_dc) {
753
          /* AC03 */
754
24.4M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
24.4M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
24.4M
            if (num >= 0) {
757
16.0M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
16.0M
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
16.0M
            } else {
761
8.36M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
8.36M
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
8.36M
              pred = -pred;
765
8.36M
            }
766
24.4M
            workspace[3] = (JCOEF)pred;
767
24.4M
          }
768
          /* AC12 */
769
24.4M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
24.4M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
24.4M
            if (num >= 0) {
772
16.2M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
16.2M
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
16.2M
            } else {
776
8.18M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
8.18M
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
8.18M
              pred = -pred;
780
8.18M
            }
781
24.4M
            workspace[10] = (JCOEF)pred;
782
24.4M
          }
783
          /* AC21 */
784
24.4M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
24.4M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
24.4M
            if (num >= 0) {
787
14.8M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
14.8M
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
14.8M
            } else {
791
9.62M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
9.62M
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
9.62M
              pred = -pred;
795
9.62M
            }
796
24.4M
            workspace[17] = (JCOEF)pred;
797
24.4M
          }
798
          /* AC30 */
799
24.4M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
24.4M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
24.4M
            if (num >= 0) {
802
18.0M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
18.0M
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
18.0M
            } else {
806
6.36M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
6.36M
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
6.36M
              pred = -pred;
810
6.36M
            }
811
24.4M
            workspace[24] = (JCOEF)pred;
812
24.4M
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
24.4M
          num = Q00 *
817
24.4M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
24.4M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
24.4M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
24.4M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
24.4M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
24.4M
          if (num >= 0) {
823
11.2M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
13.1M
          } else {
825
13.1M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
13.1M
            pred = -pred;
827
13.1M
          }
828
24.4M
          workspace[0] = (JCOEF)pred;
829
24.4M
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
35.1M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
35.1M
                        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
35.1M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
35.1M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
35.1M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
35.1M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
35.1M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
35.1M
        buffer_ptr++, prev_block_row++, next_block_row++,
848
35.1M
          prev_prev_block_row++, next_next_block_row++;
849
35.1M
        output_col += compptr->_DCT_scaled_size;
850
35.1M
      }
851
2.92M
      output_ptr += compptr->_DCT_scaled_size;
852
2.92M
    }
853
1.88M
  }
854
855
975k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
967k
    return JPEG_ROW_COMPLETED;
857
8.39k
  return JPEG_SCAN_COMPLETED;
858
975k
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
474
975k
{
475
975k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
975k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
975k
  JDIMENSION block_num, last_block_column;
478
975k
  int ci, block_row, block_rows, access_rows, image_block_row,
479
975k
    image_block_rows;
480
975k
  JBLOCKARRAY buffer;
481
975k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
975k
  JBLOCKROW next_block_row, next_next_block_row;
483
975k
  _JSAMPARRAY output_ptr;
484
975k
  JDIMENSION output_col;
485
975k
  jpeg_component_info *compptr;
486
975k
  _inverse_DCT_method_ptr inverse_DCT;
487
975k
  boolean change_dc;
488
975k
  JCOEF *workspace;
489
975k
  int *coef_bits;
490
975k
  JQUANT_TBL *quanttbl;
491
975k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
975k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
975k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
975k
      DC25;
495
975k
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
975k
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
975k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
975k
         !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
2.86M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
1.88M
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
1.88M
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
1.88M
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
1.85M
      block_rows = compptr->v_samp_factor;
526
1.85M
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
1.85M
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
14.8k
      block_rows = compptr->v_samp_factor;
529
14.8k
      access_rows = block_rows * 2; /* this and next iMCU row */
530
18.0k
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
18.0k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
18.0k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
18.0k
      access_rows = block_rows; /* this iMCU row only */
535
18.0k
    }
536
    /* Align the virtual buffer for this component. */
537
1.88M
    if (cinfo->output_iMCU_row > 1) {
538
1.85M
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
1.85M
      buffer = (*cinfo->mem->access_virt_barray)
540
1.85M
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
1.85M
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
1.85M
         (JDIMENSION)access_rows, FALSE);
543
1.85M
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
1.85M
    } else if (cinfo->output_iMCU_row > 0) {
545
14.8k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
14.8k
      buffer = (*cinfo->mem->access_virt_barray)
547
14.8k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
14.8k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
14.8k
         (JDIMENSION)access_rows, FALSE);
550
14.8k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
18.0k
    } else {
552
18.0k
      buffer = (*cinfo->mem->access_virt_barray)
553
18.0k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
18.0k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
18.0k
    }
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.88M
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
561
0
      coef_bits =
562
0
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
563
1.88M
    else
564
1.88M
      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.88M
    change_dc =
568
1.88M
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
1.53M
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
1.44M
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
1.88M
    quanttbl = compptr->quant_table;
573
1.88M
    Q00 = quanttbl->quantval[0];
574
1.88M
    Q01 = quanttbl->quantval[Q01_POS];
575
1.88M
    Q10 = quanttbl->quantval[Q10_POS];
576
1.88M
    Q20 = quanttbl->quantval[Q20_POS];
577
1.88M
    Q11 = quanttbl->quantval[Q11_POS];
578
1.88M
    Q02 = quanttbl->quantval[Q02_POS];
579
1.88M
    if (change_dc) {
580
1.40M
      Q03 = quanttbl->quantval[Q03_POS];
581
1.40M
      Q12 = quanttbl->quantval[Q12_POS];
582
1.40M
      Q21 = quanttbl->quantval[Q21_POS];
583
1.40M
      Q30 = quanttbl->quantval[Q30_POS];
584
1.40M
    }
585
1.88M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
1.88M
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
1.88M
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
4.81M
    for (block_row = 0; block_row < block_rows; block_row++) {
590
2.92M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
2.92M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
2.92M
      if (image_block_row > 0)
594
2.91M
        prev_block_row =
595
2.91M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
18.0k
      else
597
18.0k
        prev_block_row = buffer_ptr;
598
599
2.92M
      if (image_block_row > 1)
600
2.89M
        prev_prev_block_row =
601
2.89M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
33.7k
      else
603
33.7k
        prev_prev_block_row = prev_block_row;
604
605
2.92M
      if (image_block_row < image_block_rows - 1)
606
2.91M
        next_block_row =
607
2.91M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
18.0k
      else
609
18.0k
        next_block_row = buffer_ptr;
610
611
2.92M
      if (image_block_row < image_block_rows - 2)
612
2.89M
        next_next_block_row =
613
2.89M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
30.2k
      else
615
30.2k
        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
2.92M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
2.92M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
2.92M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
2.92M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
2.92M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
2.92M
      output_col = 0;
626
2.92M
      last_block_column = compptr->width_in_blocks - 1;
627
2.92M
      for (block_num = cinfo->master->first_MCU_col[ci];
628
38.0M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
35.1M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
35.1M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
2.92M
            block_num < last_block_column) {
634
1.19M
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
1.19M
          DC09 = DC10 = (int)prev_block_row[1][0];
636
1.19M
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
1.19M
          DC19 = DC20 = (int)next_block_row[1][0];
638
1.19M
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
1.19M
        }
640
35.1M
        if (block_num + 1 < last_block_column) {
641
31.0M
          DC05 = (int)prev_prev_block_row[2][0];
642
31.0M
          DC10 = (int)prev_block_row[2][0];
643
31.0M
          DC15 = (int)buffer_ptr[2][0];
644
31.0M
          DC20 = (int)next_block_row[2][0];
645
31.0M
          DC25 = (int)next_next_block_row[2][0];
646
31.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
35.1M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
31.8M
          num = Q00 * (change_dc ?
660
24.4M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
24.4M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
24.4M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
24.4M
                 DC21 - DC22 + DC24 + DC25) :
664
31.8M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
31.8M
          if (num >= 0) {
666
19.9M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
19.9M
            if (Al > 0 && pred >= (1 << Al))
668
540k
              pred = (1 << Al) - 1;
669
19.9M
          } else {
670
11.8M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
11.8M
            if (Al > 0 && pred >= (1 << Al))
672
409k
              pred = (1 << Al) - 1;
673
11.8M
            pred = -pred;
674
11.8M
          }
675
31.8M
          workspace[1] = (JCOEF)pred;
676
31.8M
        }
677
        /* AC10 */
678
35.1M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
31.9M
          num = Q00 * (change_dc ?
680
24.4M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
24.4M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
24.4M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
24.4M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
31.9M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
31.9M
          if (num >= 0) {
686
23.1M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
23.1M
            if (Al > 0 && pred >= (1 << Al))
688
1.11M
              pred = (1 << Al) - 1;
689
23.1M
          } else {
690
8.79M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
8.79M
            if (Al > 0 && pred >= (1 << Al))
692
861k
              pred = (1 << Al) - 1;
693
8.79M
            pred = -pred;
694
8.79M
          }
695
31.9M
          workspace[8] = (JCOEF)pred;
696
31.9M
        }
697
        /* AC20 */
698
35.1M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
31.9M
          num = Q00 * (change_dc ?
700
24.4M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
24.4M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
31.9M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
31.9M
          if (num >= 0) {
704
19.4M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
19.4M
            if (Al > 0 && pred >= (1 << Al))
706
785k
              pred = (1 << Al) - 1;
707
19.4M
          } else {
708
12.4M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
12.4M
            if (Al > 0 && pred >= (1 << Al))
710
774k
              pred = (1 << Al) - 1;
711
12.4M
            pred = -pred;
712
12.4M
          }
713
31.9M
          workspace[16] = (JCOEF)pred;
714
31.9M
        }
715
        /* AC11 */
716
35.1M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
31.6M
          num = Q00 * (change_dc ?
718
24.4M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
24.4M
                 9 * DC19 + DC21 - DC25) :
720
31.6M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
7.25M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
31.6M
          if (num >= 0) {
723
23.5M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
23.5M
            if (Al > 0 && pred >= (1 << Al))
725
343k
              pred = (1 << Al) - 1;
726
23.5M
          } else {
727
8.17M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
8.17M
            if (Al > 0 && pred >= (1 << Al))
729
343k
              pred = (1 << Al) - 1;
730
8.17M
            pred = -pred;
731
8.17M
          }
732
31.6M
          workspace[9] = (JCOEF)pred;
733
31.6M
        }
734
        /* AC02 */
735
35.1M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
31.8M
          num = Q00 * (change_dc ?
737
24.4M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
24.4M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
31.8M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
31.8M
          if (num >= 0) {
741
19.4M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
19.4M
            if (Al > 0 && pred >= (1 << Al))
743
449k
              pred = (1 << Al) - 1;
744
19.4M
          } else {
745
12.4M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
12.4M
            if (Al > 0 && pred >= (1 << Al))
747
457k
              pred = (1 << Al) - 1;
748
12.4M
            pred = -pred;
749
12.4M
          }
750
31.8M
          workspace[2] = (JCOEF)pred;
751
31.8M
        }
752
35.1M
        if (change_dc) {
753
          /* AC03 */
754
24.4M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
24.4M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
24.4M
            if (num >= 0) {
757
16.0M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
16.0M
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
16.0M
            } else {
761
8.36M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
8.36M
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
8.36M
              pred = -pred;
765
8.36M
            }
766
24.4M
            workspace[3] = (JCOEF)pred;
767
24.4M
          }
768
          /* AC12 */
769
24.4M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
24.4M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
24.4M
            if (num >= 0) {
772
16.2M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
16.2M
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
16.2M
            } else {
776
8.18M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
8.18M
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
8.18M
              pred = -pred;
780
8.18M
            }
781
24.4M
            workspace[10] = (JCOEF)pred;
782
24.4M
          }
783
          /* AC21 */
784
24.4M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
24.4M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
24.4M
            if (num >= 0) {
787
14.8M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
14.8M
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
14.8M
            } else {
791
9.62M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
9.62M
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
9.62M
              pred = -pred;
795
9.62M
            }
796
24.4M
            workspace[17] = (JCOEF)pred;
797
24.4M
          }
798
          /* AC30 */
799
24.4M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
24.4M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
24.4M
            if (num >= 0) {
802
18.0M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
18.0M
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
18.0M
            } else {
806
6.36M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
6.36M
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
6.36M
              pred = -pred;
810
6.36M
            }
811
24.4M
            workspace[24] = (JCOEF)pred;
812
24.4M
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
24.4M
          num = Q00 *
817
24.4M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
24.4M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
24.4M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
24.4M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
24.4M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
24.4M
          if (num >= 0) {
823
11.2M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
13.1M
          } else {
825
13.1M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
13.1M
            pred = -pred;
827
13.1M
          }
828
24.4M
          workspace[0] = (JCOEF)pred;
829
24.4M
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
35.1M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
35.1M
                        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
35.1M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
35.1M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
35.1M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
35.1M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
35.1M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
35.1M
        buffer_ptr++, prev_block_row++, next_block_row++,
848
35.1M
          prev_prev_block_row++, next_next_block_row++;
849
35.1M
        output_col += compptr->_DCT_scaled_size;
850
35.1M
      }
851
2.92M
      output_ptr += compptr->_DCT_scaled_size;
852
2.92M
    }
853
1.88M
  }
854
855
975k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
967k
    return JPEG_ROW_COMPLETED;
857
8.39k
  return JPEG_SCAN_COMPLETED;
858
975k
}
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
45.7k
{
870
45.7k
  my_coef_ptr coef;
871
872
45.7k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
45.7k
  coef = (my_coef_ptr)
876
45.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
45.7k
                                sizeof(my_coef_controller));
878
45.7k
  memset(coef, 0, sizeof(my_coef_controller));
879
45.7k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
45.7k
  coef->pub.start_input_pass = start_input_pass;
881
45.7k
  coef->pub.start_output_pass = start_output_pass;
882
45.7k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
45.7k
  coef->coef_bits_latch = NULL;
884
45.7k
#endif
885
886
  /* Create the coefficient buffer. */
887
45.7k
  if (need_full_buffer) {
888
25.5k
#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
25.5k
    int ci, access_rows;
893
25.5k
    jpeg_component_info *compptr;
894
895
88.0k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
62.4k
         ci++, compptr++) {
897
62.4k
      access_rows = compptr->v_samp_factor;
898
62.4k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
62.4k
      if (cinfo->progressive_mode)
901
59.7k
        access_rows *= 5;
902
62.4k
#endif
903
62.4k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
62.4k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
62.4k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
62.4k
                               (long)compptr->h_samp_factor),
907
62.4k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
62.4k
                               (long)compptr->v_samp_factor),
909
62.4k
         (JDIMENSION)access_rows);
910
62.4k
    }
911
25.5k
    coef->pub.consume_data = consume_data;
912
25.5k
    coef->pub._decompress_data = decompress_data;
913
25.5k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
25.5k
  } else {
918
    /* We only need a single-MCU buffer. */
919
20.2k
    JBLOCKROW buffer;
920
20.2k
    int i;
921
922
20.2k
    buffer = (JBLOCKROW)
923
20.2k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
20.2k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
222k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
202k
      coef->MCU_buffer[i] = buffer + i;
927
202k
    }
928
20.2k
    coef->pub.consume_data = dummy_consume_data;
929
20.2k
    coef->pub._decompress_data = decompress_onepass;
930
20.2k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
20.2k
  }
932
933
  /* Allocate the workspace buffer */
934
45.7k
  coef->workspace = (JCOEF *)
935
45.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
45.7k
                                sizeof(JCOEF) * DCTSIZE2);
937
45.7k
}
jinit_d_coef_controller
Line
Count
Source
869
40.8k
{
870
40.8k
  my_coef_ptr coef;
871
872
40.8k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
40.8k
  coef = (my_coef_ptr)
876
40.8k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
40.8k
                                sizeof(my_coef_controller));
878
40.8k
  memset(coef, 0, sizeof(my_coef_controller));
879
40.8k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
40.8k
  coef->pub.start_input_pass = start_input_pass;
881
40.8k
  coef->pub.start_output_pass = start_output_pass;
882
40.8k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
40.8k
  coef->coef_bits_latch = NULL;
884
40.8k
#endif
885
886
  /* Create the coefficient buffer. */
887
40.8k
  if (need_full_buffer) {
888
20.9k
#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
20.9k
    int ci, access_rows;
893
20.9k
    jpeg_component_info *compptr;
894
895
71.2k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
50.3k
         ci++, compptr++) {
897
50.3k
      access_rows = compptr->v_samp_factor;
898
50.3k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
50.3k
      if (cinfo->progressive_mode)
901
48.7k
        access_rows *= 5;
902
50.3k
#endif
903
50.3k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
50.3k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
50.3k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
50.3k
                               (long)compptr->h_samp_factor),
907
50.3k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
50.3k
                               (long)compptr->v_samp_factor),
909
50.3k
         (JDIMENSION)access_rows);
910
50.3k
    }
911
20.9k
    coef->pub.consume_data = consume_data;
912
20.9k
    coef->pub._decompress_data = decompress_data;
913
20.9k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
20.9k
  } else {
918
    /* We only need a single-MCU buffer. */
919
19.9k
    JBLOCKROW buffer;
920
19.9k
    int i;
921
922
19.9k
    buffer = (JBLOCKROW)
923
19.9k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
19.9k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
219k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
199k
      coef->MCU_buffer[i] = buffer + i;
927
199k
    }
928
19.9k
    coef->pub.consume_data = dummy_consume_data;
929
19.9k
    coef->pub._decompress_data = decompress_onepass;
930
19.9k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
19.9k
  }
932
933
  /* Allocate the workspace buffer */
934
40.8k
  coef->workspace = (JCOEF *)
935
40.8k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
40.8k
                                sizeof(JCOEF) * DCTSIZE2);
937
40.8k
}
j12init_d_coef_controller
Line
Count
Source
869
4.87k
{
870
4.87k
  my_coef_ptr coef;
871
872
4.87k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
4.87k
  coef = (my_coef_ptr)
876
4.87k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
4.87k
                                sizeof(my_coef_controller));
878
4.87k
  memset(coef, 0, sizeof(my_coef_controller));
879
4.87k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
4.87k
  coef->pub.start_input_pass = start_input_pass;
881
4.87k
  coef->pub.start_output_pass = start_output_pass;
882
4.87k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
4.87k
  coef->coef_bits_latch = NULL;
884
4.87k
#endif
885
886
  /* Create the coefficient buffer. */
887
4.87k
  if (need_full_buffer) {
888
4.61k
#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
4.61k
    int ci, access_rows;
893
4.61k
    jpeg_component_info *compptr;
894
895
16.7k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
12.1k
         ci++, compptr++) {
897
12.1k
      access_rows = compptr->v_samp_factor;
898
12.1k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
12.1k
      if (cinfo->progressive_mode)
901
11.0k
        access_rows *= 5;
902
12.1k
#endif
903
12.1k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
12.1k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
12.1k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
12.1k
                               (long)compptr->h_samp_factor),
907
12.1k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
12.1k
                               (long)compptr->v_samp_factor),
909
12.1k
         (JDIMENSION)access_rows);
910
12.1k
    }
911
4.61k
    coef->pub.consume_data = consume_data;
912
4.61k
    coef->pub._decompress_data = decompress_data;
913
4.61k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
4.61k
  } else {
918
    /* We only need a single-MCU buffer. */
919
258
    JBLOCKROW buffer;
920
258
    int i;
921
922
258
    buffer = (JBLOCKROW)
923
258
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
258
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
2.83k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
2.58k
      coef->MCU_buffer[i] = buffer + i;
927
2.58k
    }
928
258
    coef->pub.consume_data = dummy_consume_data;
929
258
    coef->pub._decompress_data = decompress_onepass;
930
258
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
258
  }
932
933
  /* Allocate the workspace buffer */
934
4.87k
  coef->workspace = (JCOEF *)
935
4.87k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
4.87k
                                sizeof(JCOEF) * DCTSIZE2);
937
4.87k
}