Coverage Report

Created: 2026-10-28 07:04

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
3.38k
{
51
3.38k
  cinfo->input_iMCU_row = 0;
52
3.38k
  start_iMCU_row(cinfo);
53
3.38k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
50
3.23k
{
51
3.23k
  cinfo->input_iMCU_row = 0;
52
3.23k
  start_iMCU_row(cinfo);
53
3.23k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
50
155
{
51
155
  cinfo->input_iMCU_row = 0;
52
155
  start_iMCU_row(cinfo);
53
155
}
54
55
56
/*
57
 * Initialize for an output processing pass.
58
 */
59
60
METHODDEF(void)
61
start_output_pass(j_decompress_ptr cinfo)
62
1.36k
{
63
1.36k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
1.36k
  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.36k
  if (coef->pub.coef_arrays != NULL) {
68
617
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
428
      coef->pub._decompress_data = decompress_smooth_data;
70
189
    else
71
189
      coef->pub._decompress_data = decompress_data;
72
617
  }
73
1.36k
#endif
74
1.36k
  cinfo->output_iMCU_row = 0;
75
1.36k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
62
1.35k
{
63
1.35k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
1.35k
  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.35k
  if (coef->pub.coef_arrays != NULL) {
68
601
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
425
      coef->pub._decompress_data = decompress_smooth_data;
70
176
    else
71
176
      coef->pub._decompress_data = decompress_data;
72
601
  }
73
1.35k
#endif
74
1.35k
  cinfo->output_iMCU_row = 0;
75
1.35k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
62
18
{
63
18
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
18
  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
18
  if (coef->pub.coef_arrays != NULL) {
68
16
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
3
      coef->pub._decompress_data = decompress_smooth_data;
70
13
    else
71
13
      coef->pub._decompress_data = decompress_data;
72
16
  }
73
18
#endif
74
18
  cinfo->output_iMCU_row = 0;
75
18
}
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
6.68k
{
91
6.68k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
6.68k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
6.68k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
6.68k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
6.68k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
6.68k
  _JSAMPARRAY output_ptr;
97
6.68k
  JDIMENSION start_col, output_col;
98
6.68k
  jpeg_component_info *compptr;
99
6.68k
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
19.7k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
13.0k
       yoffset++) {
104
553k
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
540k
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
540k
      jzero_far((void *)coef->MCU_buffer[0],
108
540k
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
540k
      if (!cinfo->entropy->insufficient_data)
110
540k
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
540k
      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
540k
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
540k
          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
540k
        blkn = 0;               /* index of current DCT block within MCU */
142
1.08M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
540k
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
540k
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
540k
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
540k
          useful_width = (MCU_col_num < last_MCU_col) ?
151
527k
                         compptr->MCU_width : compptr->last_col_width;
152
540k
          output_ptr = output_buf[compptr->component_index] +
153
540k
                       yoffset * compptr->_DCT_scaled_size;
154
540k
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
540k
                      compptr->MCU_sample_width;
156
1.08M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
540k
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
540k
                yoffset + yindex < compptr->last_row_height) {
159
540k
              output_col = start_col;
160
1.08M
              for (xindex = 0; xindex < useful_width; xindex++) {
161
#ifdef WITH_PROFILE
162
                cinfo->master->start = getTime();
163
#endif
164
540k
                (*inverse_DCT) (cinfo, compptr,
165
540k
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
540k
                                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
540k
                output_col += compptr->_DCT_scaled_size;
173
540k
              }
174
540k
            }
175
540k
            blkn += compptr->MCU_width;
176
540k
            output_ptr += compptr->_DCT_scaled_size;
177
540k
          }
178
540k
        }
179
540k
      }
180
540k
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
13.0k
    coef->MCU_ctr = 0;
183
13.0k
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
6.68k
  cinfo->output_iMCU_row++;
186
6.68k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
5.93k
    start_iMCU_row(cinfo);
188
5.93k
    return JPEG_ROW_COMPLETED;
189
5.93k
  }
190
  /* Completed the scan */
191
749
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
749
  return JPEG_SCAN_COMPLETED;
193
6.68k
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
90
6.68k
{
91
6.68k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
6.68k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
6.68k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
6.68k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
6.68k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
6.68k
  _JSAMPARRAY output_ptr;
97
6.68k
  JDIMENSION start_col, output_col;
98
6.68k
  jpeg_component_info *compptr;
99
6.68k
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
19.7k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
13.0k
       yoffset++) {
104
553k
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
540k
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
540k
      jzero_far((void *)coef->MCU_buffer[0],
108
540k
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
540k
      if (!cinfo->entropy->insufficient_data)
110
540k
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
540k
      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
540k
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
540k
          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
540k
        blkn = 0;               /* index of current DCT block within MCU */
142
1.08M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
540k
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
540k
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
540k
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
540k
          useful_width = (MCU_col_num < last_MCU_col) ?
151
527k
                         compptr->MCU_width : compptr->last_col_width;
152
540k
          output_ptr = output_buf[compptr->component_index] +
153
540k
                       yoffset * compptr->_DCT_scaled_size;
154
540k
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
540k
                      compptr->MCU_sample_width;
156
1.08M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
540k
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
540k
                yoffset + yindex < compptr->last_row_height) {
159
540k
              output_col = start_col;
160
1.08M
              for (xindex = 0; xindex < useful_width; xindex++) {
161
#ifdef WITH_PROFILE
162
                cinfo->master->start = getTime();
163
#endif
164
540k
                (*inverse_DCT) (cinfo, compptr,
165
540k
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
540k
                                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
540k
                output_col += compptr->_DCT_scaled_size;
173
540k
              }
174
540k
            }
175
540k
            blkn += compptr->MCU_width;
176
540k
            output_ptr += compptr->_DCT_scaled_size;
177
540k
          }
178
540k
        }
179
540k
      }
180
540k
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
13.0k
    coef->MCU_ctr = 0;
183
13.0k
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
6.68k
  cinfo->output_iMCU_row++;
186
6.68k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
5.93k
    start_iMCU_row(cinfo);
188
5.93k
    return JPEG_ROW_COMPLETED;
189
5.93k
  }
190
  /* Completed the scan */
191
749
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
749
  return JPEG_SCAN_COMPLETED;
193
6.68k
}
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
61.9k
{
219
61.9k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
61.9k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
61.9k
  int blkn, ci, xindex, yindex, yoffset;
222
61.9k
  JDIMENSION start_col;
223
61.9k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
61.9k
  JBLOCKROW buffer_ptr;
225
61.9k
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
123k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
61.9k
    compptr = cinfo->cur_comp_info[ci];
230
61.9k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
61.9k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
61.9k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
61.9k
       (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
61.9k
  }
239
240
  /* Loop to process one whole iMCU row */
241
185k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
123k
       yoffset++) {
243
6.39M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
6.26M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
6.26M
      blkn = 0;                 /* index of current DCT block within MCU */
247
12.5M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
6.26M
        compptr = cinfo->cur_comp_info[ci];
249
6.26M
        start_col = MCU_col_num * compptr->MCU_width;
250
12.5M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
6.26M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
12.5M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
6.26M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
6.26M
          }
255
6.26M
        }
256
6.26M
      }
257
6.26M
      if (!cinfo->entropy->insufficient_data)
258
6.26M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
259
      /* Try to fetch the MCU. */
260
#ifdef WITH_PROFILE
261
      cinfo->master->start = getTime();
262
#endif
263
6.26M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
264
        /* Suspension forced; update state counters and exit */
265
0
        coef->MCU_vert_offset = yoffset;
266
0
        coef->MCU_ctr = MCU_col_num;
267
#ifdef WITH_PROFILE
268
        cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
269
        cinfo->master->entropy_mcoeffs +=
270
          (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
271
#endif
272
0
        return JPEG_SUSPENDED;
273
0
      }
274
#ifdef WITH_PROFILE
275
      cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
276
      cinfo->master->entropy_mcoeffs +=
277
        (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
278
#endif
279
6.26M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
123k
    coef->MCU_ctr = 0;
282
123k
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
61.9k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
59.3k
    start_iMCU_row(cinfo);
286
59.3k
    return JPEG_ROW_COMPLETED;
287
59.3k
  }
288
  /* Completed the scan */
289
2.63k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
2.63k
  return JPEG_SCAN_COMPLETED;
291
61.9k
}
jdcoefct-8.c:consume_data
Line
Count
Source
218
57.3k
{
219
57.3k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
57.3k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
57.3k
  int blkn, ci, xindex, yindex, yoffset;
222
57.3k
  JDIMENSION start_col;
223
57.3k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
57.3k
  JBLOCKROW buffer_ptr;
225
57.3k
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
114k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
57.3k
    compptr = cinfo->cur_comp_info[ci];
230
57.3k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
57.3k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
57.3k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
57.3k
       (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
57.3k
  }
239
240
  /* Loop to process one whole iMCU row */
241
171k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
114k
       yoffset++) {
243
5.95M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
5.84M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
5.84M
      blkn = 0;                 /* index of current DCT block within MCU */
247
11.6M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
5.84M
        compptr = cinfo->cur_comp_info[ci];
249
5.84M
        start_col = MCU_col_num * compptr->MCU_width;
250
11.6M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
5.84M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
11.6M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
5.84M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
5.84M
          }
255
5.84M
        }
256
5.84M
      }
257
5.84M
      if (!cinfo->entropy->insufficient_data)
258
5.84M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
259
      /* Try to fetch the MCU. */
260
#ifdef WITH_PROFILE
261
      cinfo->master->start = getTime();
262
#endif
263
5.84M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
264
        /* Suspension forced; update state counters and exit */
265
0
        coef->MCU_vert_offset = yoffset;
266
0
        coef->MCU_ctr = MCU_col_num;
267
#ifdef WITH_PROFILE
268
        cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
269
        cinfo->master->entropy_mcoeffs +=
270
          (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
271
#endif
272
0
        return JPEG_SUSPENDED;
273
0
      }
274
#ifdef WITH_PROFILE
275
      cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
276
      cinfo->master->entropy_mcoeffs +=
277
        (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
278
#endif
279
5.84M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
114k
    coef->MCU_ctr = 0;
282
114k
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
57.3k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
54.8k
    start_iMCU_row(cinfo);
286
54.8k
    return JPEG_ROW_COMPLETED;
287
54.8k
  }
288
  /* Completed the scan */
289
2.48k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
2.48k
  return JPEG_SCAN_COMPLETED;
291
57.3k
}
jdcoefct-12.c:consume_data
Line
Count
Source
218
4.60k
{
219
4.60k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
4.60k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
4.60k
  int blkn, ci, xindex, yindex, yoffset;
222
4.60k
  JDIMENSION start_col;
223
4.60k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
4.60k
  JBLOCKROW buffer_ptr;
225
4.60k
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
9.20k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
4.60k
    compptr = cinfo->cur_comp_info[ci];
230
4.60k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
4.60k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
4.60k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
4.60k
       (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
4.60k
  }
239
240
  /* Loop to process one whole iMCU row */
241
13.8k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
9.20k
       yoffset++) {
243
432k
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
423k
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
423k
      blkn = 0;                 /* index of current DCT block within MCU */
247
846k
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
423k
        compptr = cinfo->cur_comp_info[ci];
249
423k
        start_col = MCU_col_num * compptr->MCU_width;
250
846k
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
423k
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
846k
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
423k
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
423k
          }
255
423k
        }
256
423k
      }
257
423k
      if (!cinfo->entropy->insufficient_data)
258
423k
        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
423k
      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
423k
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
9.20k
    coef->MCU_ctr = 0;
282
9.20k
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
4.60k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
4.44k
    start_iMCU_row(cinfo);
286
4.44k
    return JPEG_ROW_COMPLETED;
287
4.44k
  }
288
  /* Completed the scan */
289
153
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
153
  return JPEG_SCAN_COMPLETED;
291
4.60k
}
292
293
294
/*
295
 * Decompress and return some data in the multi-pass case.
296
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
297
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
298
 *
299
 * NB: output_buf contains a plane for each component in image.
300
 */
301
302
METHODDEF(int)
303
decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
304
3.99k
{
305
3.99k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
3.99k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
3.99k
  JDIMENSION block_num;
308
3.99k
  int ci, block_row, block_rows;
309
3.99k
  JBLOCKARRAY buffer;
310
3.99k
  JBLOCKROW buffer_ptr;
311
3.99k
  _JSAMPARRAY output_ptr;
312
3.99k
  JDIMENSION output_col;
313
3.99k
  jpeg_component_info *compptr;
314
3.99k
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
3.99k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
3.99k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
3.99k
          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
7.98k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
3.99k
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
3.99k
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
3.99k
    buffer = (*cinfo->mem->access_virt_barray)
332
3.99k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
3.99k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
3.99k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
3.99k
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
3.81k
      block_rows = compptr->v_samp_factor;
338
176
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
176
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
176
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
176
    }
343
3.99k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
3.99k
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
11.8k
    for (block_row = 0; block_row < block_rows; block_row++) {
347
7.81k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
7.81k
      output_col = 0;
349
7.81k
      for (block_num = cinfo->master->first_MCU_col[ci];
350
423k
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
415k
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
415k
                        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
415k
        buffer_ptr++;
361
415k
        output_col += compptr->_DCT_scaled_size;
362
415k
      }
363
7.81k
      output_ptr += compptr->_DCT_scaled_size;
364
7.81k
    }
365
3.99k
  }
366
367
3.99k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
3.81k
    return JPEG_ROW_COMPLETED;
369
176
  return JPEG_SCAN_COMPLETED;
370
3.99k
}
jdcoefct-8.c:decompress_data
Line
Count
Source
304
3.99k
{
305
3.99k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
3.99k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
3.99k
  JDIMENSION block_num;
308
3.99k
  int ci, block_row, block_rows;
309
3.99k
  JBLOCKARRAY buffer;
310
3.99k
  JBLOCKROW buffer_ptr;
311
3.99k
  _JSAMPARRAY output_ptr;
312
3.99k
  JDIMENSION output_col;
313
3.99k
  jpeg_component_info *compptr;
314
3.99k
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
3.99k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
3.99k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
3.99k
          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
7.98k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
3.99k
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
3.99k
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
3.99k
    buffer = (*cinfo->mem->access_virt_barray)
332
3.99k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
3.99k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
3.99k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
3.99k
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
3.81k
      block_rows = compptr->v_samp_factor;
338
176
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
176
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
176
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
176
    }
343
3.99k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
3.99k
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
11.8k
    for (block_row = 0; block_row < block_rows; block_row++) {
347
7.81k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
7.81k
      output_col = 0;
349
7.81k
      for (block_num = cinfo->master->first_MCU_col[ci];
350
423k
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
415k
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
415k
                        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
415k
        buffer_ptr++;
361
415k
        output_col += compptr->_DCT_scaled_size;
362
415k
      }
363
7.81k
      output_ptr += compptr->_DCT_scaled_size;
364
7.81k
    }
365
3.99k
  }
366
367
3.99k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
3.81k
    return JPEG_ROW_COMPLETED;
369
176
  return JPEG_SCAN_COMPLETED;
370
3.99k
}
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
20.6k
#define Q01_POS  1
386
20.6k
#define Q10_POS  8
387
20.6k
#define Q20_POS  16
388
20.6k
#define Q11_POS  9
389
20.5k
#define Q02_POS  2
390
16.2k
#define Q03_POS  3
391
16.2k
#define Q12_POS  10
392
16.2k
#define Q21_POS  17
393
16.2k
#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
617
{
406
617
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
617
  boolean smoothing_useful = FALSE;
408
617
  int ci, coefi;
409
617
  jpeg_component_info *compptr;
410
617
  JQUANT_TBL *qtable;
411
617
  int *coef_bits, *prev_coef_bits;
412
617
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
617
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
0
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
617
  if (coef->coef_bits_latch == NULL)
419
617
    coef->coef_bits_latch = (int *)
420
617
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
617
                                  cinfo->num_components * 2 *
422
617
                                  (SAVED_COEFS * sizeof(int)));
423
617
  coef_bits_latch = coef->coef_bits_latch;
424
617
  prev_coef_bits_latch =
425
617
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
1.08k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
617
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
617
    if ((qtable = compptr->quant_table) == NULL)
431
0
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
617
    if (qtable->quantval[0] == 0 ||
434
602
        qtable->quantval[Q01_POS] == 0 ||
435
582
        qtable->quantval[Q10_POS] == 0 ||
436
566
        qtable->quantval[Q20_POS] == 0 ||
437
547
        qtable->quantval[Q11_POS] == 0 ||
438
534
        qtable->quantval[Q02_POS] == 0 ||
439
523
        qtable->quantval[Q03_POS] == 0 ||
440
512
        qtable->quantval[Q12_POS] == 0 ||
441
496
        qtable->quantval[Q21_POS] == 0 ||
442
482
        qtable->quantval[Q30_POS] == 0)
443
150
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
467
    coef_bits = cinfo->coef_bits[ci];
446
467
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
467
    if (coef_bits[0] < 0)
448
0
      return FALSE;
449
467
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
4.67k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
4.20k
      if (cinfo->input_scan_number > 1)
453
2.80k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
1.39k
      else
455
1.39k
        prev_coef_bits_latch[coefi] = -1;
456
4.20k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
4.20k
      if (coef_bits[coefi] != 0)
458
3.47k
        smoothing_useful = TRUE;
459
4.20k
    }
460
467
    coef_bits_latch += SAVED_COEFS;
461
467
    prev_coef_bits_latch += SAVED_COEFS;
462
467
  }
463
464
467
  return smoothing_useful;
465
617
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
405
601
{
406
601
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
601
  boolean smoothing_useful = FALSE;
408
601
  int ci, coefi;
409
601
  jpeg_component_info *compptr;
410
601
  JQUANT_TBL *qtable;
411
601
  int *coef_bits, *prev_coef_bits;
412
601
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
601
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
0
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
601
  if (coef->coef_bits_latch == NULL)
419
601
    coef->coef_bits_latch = (int *)
420
601
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
601
                                  cinfo->num_components * 2 *
422
601
                                  (SAVED_COEFS * sizeof(int)));
423
601
  coef_bits_latch = coef->coef_bits_latch;
424
601
  prev_coef_bits_latch =
425
601
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
1.06k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
601
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
601
    if ((qtable = compptr->quant_table) == NULL)
431
0
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
601
    if (qtable->quantval[0] == 0 ||
434
587
        qtable->quantval[Q01_POS] == 0 ||
435
568
        qtable->quantval[Q10_POS] == 0 ||
436
553
        qtable->quantval[Q20_POS] == 0 ||
437
535
        qtable->quantval[Q11_POS] == 0 ||
438
523
        qtable->quantval[Q02_POS] == 0 ||
439
513
        qtable->quantval[Q03_POS] == 0 ||
440
503
        qtable->quantval[Q12_POS] == 0 ||
441
488
        qtable->quantval[Q21_POS] == 0 ||
442
475
        qtable->quantval[Q30_POS] == 0)
443
140
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
461
    coef_bits = cinfo->coef_bits[ci];
446
461
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
461
    if (coef_bits[0] < 0)
448
0
      return FALSE;
449
461
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
4.61k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
4.14k
      if (cinfo->input_scan_number > 1)
453
2.76k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
1.38k
      else
455
1.38k
        prev_coef_bits_latch[coefi] = -1;
456
4.14k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
4.14k
      if (coef_bits[coefi] != 0)
458
3.44k
        smoothing_useful = TRUE;
459
4.14k
    }
460
461
    coef_bits_latch += SAVED_COEFS;
461
461
    prev_coef_bits_latch += SAVED_COEFS;
462
461
  }
463
464
461
  return smoothing_useful;
465
601
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
405
16
{
406
16
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
16
  boolean smoothing_useful = FALSE;
408
16
  int ci, coefi;
409
16
  jpeg_component_info *compptr;
410
16
  JQUANT_TBL *qtable;
411
16
  int *coef_bits, *prev_coef_bits;
412
16
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
16
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
0
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
16
  if (coef->coef_bits_latch == NULL)
419
16
    coef->coef_bits_latch = (int *)
420
16
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
16
                                  cinfo->num_components * 2 *
422
16
                                  (SAVED_COEFS * sizeof(int)));
423
16
  coef_bits_latch = coef->coef_bits_latch;
424
16
  prev_coef_bits_latch =
425
16
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
22
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
16
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
16
    if ((qtable = compptr->quant_table) == NULL)
431
0
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
16
    if (qtable->quantval[0] == 0 ||
434
15
        qtable->quantval[Q01_POS] == 0 ||
435
14
        qtable->quantval[Q10_POS] == 0 ||
436
13
        qtable->quantval[Q20_POS] == 0 ||
437
12
        qtable->quantval[Q11_POS] == 0 ||
438
11
        qtable->quantval[Q02_POS] == 0 ||
439
10
        qtable->quantval[Q03_POS] == 0 ||
440
9
        qtable->quantval[Q12_POS] == 0 ||
441
8
        qtable->quantval[Q21_POS] == 0 ||
442
7
        qtable->quantval[Q30_POS] == 0)
443
10
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
6
    coef_bits = cinfo->coef_bits[ci];
446
6
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
6
    if (coef_bits[0] < 0)
448
0
      return FALSE;
449
6
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
60
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
54
      if (cinfo->input_scan_number > 1)
453
45
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
9
      else
455
9
        prev_coef_bits_latch[coefi] = -1;
456
54
      coef_bits_latch[coefi] = coef_bits[coefi];
457
54
      if (coef_bits[coefi] != 0)
458
23
        smoothing_useful = TRUE;
459
54
    }
460
6
    coef_bits_latch += SAVED_COEFS;
461
6
    prev_coef_bits_latch += SAVED_COEFS;
462
6
  }
463
464
6
  return smoothing_useful;
465
16
}
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
20.0k
{
475
20.0k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
20.0k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
20.0k
  JDIMENSION block_num, last_block_column;
478
20.0k
  int ci, block_row, block_rows, access_rows, image_block_row,
479
20.0k
    image_block_rows;
480
20.0k
  JBLOCKARRAY buffer;
481
20.0k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
20.0k
  JBLOCKROW next_block_row, next_next_block_row;
483
20.0k
  _JSAMPARRAY output_ptr;
484
20.0k
  JDIMENSION output_col;
485
20.0k
  jpeg_component_info *compptr;
486
20.0k
  _inverse_DCT_method_ptr inverse_DCT;
487
20.0k
  boolean change_dc;
488
20.0k
  JCOEF *workspace;
489
20.0k
  int *coef_bits;
490
20.0k
  JQUANT_TBL *quanttbl;
491
20.0k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
20.0k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
20.0k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
20.0k
      DC25;
495
20.0k
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
20.0k
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
20.0k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
20.0k
         !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
40.1k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
20.0k
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
20.0k
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
20.0k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
19.2k
      block_rows = compptr->v_samp_factor;
526
19.2k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
19.2k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
372
      block_rows = compptr->v_samp_factor;
529
372
      access_rows = block_rows * 2; /* this and next iMCU row */
530
425
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
425
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
425
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
425
      access_rows = block_rows; /* this iMCU row only */
535
425
    }
536
    /* Align the virtual buffer for this component. */
537
20.0k
    if (cinfo->output_iMCU_row > 1) {
538
19.2k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
19.2k
      buffer = (*cinfo->mem->access_virt_barray)
540
19.2k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
19.2k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
19.2k
         (JDIMENSION)access_rows, FALSE);
543
19.2k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
19.2k
    } else if (cinfo->output_iMCU_row > 0) {
545
372
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
372
      buffer = (*cinfo->mem->access_virt_barray)
547
372
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
372
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
372
         (JDIMENSION)access_rows, FALSE);
550
372
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
425
    } else {
552
425
      buffer = (*cinfo->mem->access_virt_barray)
553
425
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
425
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
425
    }
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
20.0k
    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
20.0k
    else
564
20.0k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
565
566
    /* We only do DC interpolation if no AC coefficient data is available. */
567
20.0k
    change_dc =
568
20.0k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
16.6k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
16.0k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
20.0k
    quanttbl = compptr->quant_table;
573
20.0k
    Q00 = quanttbl->quantval[0];
574
20.0k
    Q01 = quanttbl->quantval[Q01_POS];
575
20.0k
    Q10 = quanttbl->quantval[Q10_POS];
576
20.0k
    Q20 = quanttbl->quantval[Q20_POS];
577
20.0k
    Q11 = quanttbl->quantval[Q11_POS];
578
20.0k
    Q02 = quanttbl->quantval[Q02_POS];
579
20.0k
    if (change_dc) {
580
15.7k
      Q03 = quanttbl->quantval[Q03_POS];
581
15.7k
      Q12 = quanttbl->quantval[Q12_POS];
582
15.7k
      Q21 = quanttbl->quantval[Q21_POS];
583
15.7k
      Q30 = quanttbl->quantval[Q30_POS];
584
15.7k
    }
585
20.0k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
20.0k
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
20.0k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
60.0k
    for (block_row = 0; block_row < block_rows; block_row++) {
590
40.0k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
40.0k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
40.0k
      if (image_block_row > 0)
594
39.5k
        prev_block_row =
595
39.5k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
425
      else
597
425
        prev_block_row = buffer_ptr;
598
599
40.0k
      if (image_block_row > 1)
600
39.1k
        prev_prev_block_row =
601
39.1k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
809
      else
603
809
        prev_prev_block_row = prev_block_row;
604
605
40.0k
      if (image_block_row < image_block_rows - 1)
606
39.5k
        next_block_row =
607
39.5k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
425
      else
609
425
        next_block_row = buffer_ptr;
610
611
40.0k
      if (image_block_row < image_block_rows - 2)
612
39.2k
        next_next_block_row =
613
39.2k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
758
      else
615
758
        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
40.0k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
40.0k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
40.0k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
40.0k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
40.0k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
40.0k
      output_col = 0;
626
40.0k
      last_block_column = compptr->width_in_blocks - 1;
627
40.0k
      for (block_num = cinfo->master->first_MCU_col[ci];
628
1.19M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
1.15M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
1.15M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
40.0k
            block_num < last_block_column) {
634
15.7k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
15.7k
          DC09 = DC10 = (int)prev_block_row[1][0];
636
15.7k
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
15.7k
          DC19 = DC20 = (int)next_block_row[1][0];
638
15.7k
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
15.7k
        }
640
1.15M
        if (block_num + 1 < last_block_column) {
641
1.09M
          DC05 = (int)prev_prev_block_row[2][0];
642
1.09M
          DC10 = (int)prev_block_row[2][0];
643
1.09M
          DC15 = (int)buffer_ptr[2][0];
644
1.09M
          DC20 = (int)next_block_row[2][0];
645
1.09M
          DC25 = (int)next_next_block_row[2][0];
646
1.09M
        }
647
        /* If DC interpolation is enabled, compute coefficient estimates using
648
         * a Gaussian-like kernel, keeping the averages of the DC values.
649
         *
650
         * If DC interpolation is disabled, compute coefficient estimates using
651
         * an algorithm similar to the one described in Section K.8 of the JPEG
652
         * standard, except applied to a 5x5 window rather than a 3x3 window.
653
         *
654
         * An estimate is applied only if the coefficient is still zero and is
655
         * not known to be fully accurate.
656
         */
657
        /* AC01 */
658
1.15M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
1.01M
          num = Q00 * (change_dc ?
660
398k
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
398k
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
398k
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
398k
                 DC21 - DC22 + DC24 + DC25) :
664
1.01M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
1.01M
          if (num >= 0) {
666
661k
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
661k
            if (Al > 0 && pred >= (1 << Al))
668
19.9k
              pred = (1 << Al) - 1;
669
661k
          } else {
670
356k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
356k
            if (Al > 0 && pred >= (1 << Al))
672
8.09k
              pred = (1 << Al) - 1;
673
356k
            pred = -pred;
674
356k
          }
675
1.01M
          workspace[1] = (JCOEF)pred;
676
1.01M
        }
677
        /* AC10 */
678
1.15M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
1.05M
          num = Q00 * (change_dc ?
680
398k
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
398k
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
398k
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
398k
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
1.05M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
1.05M
          if (num >= 0) {
686
863k
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
863k
            if (Al > 0 && pred >= (1 << Al))
688
177k
              pred = (1 << Al) - 1;
689
863k
          } else {
690
191k
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
191k
            if (Al > 0 && pred >= (1 << Al))
692
28.0k
              pred = (1 << Al) - 1;
693
191k
            pred = -pred;
694
191k
          }
695
1.05M
          workspace[8] = (JCOEF)pred;
696
1.05M
        }
697
        /* AC20 */
698
1.15M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
895k
          num = Q00 * (change_dc ?
700
398k
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
398k
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
895k
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
895k
          if (num >= 0) {
704
544k
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
544k
            if (Al > 0 && pred >= (1 << Al))
706
59.8k
              pred = (1 << Al) - 1;
707
544k
          } else {
708
351k
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
351k
            if (Al > 0 && pred >= (1 << Al))
710
58.7k
              pred = (1 << Al) - 1;
711
351k
            pred = -pred;
712
351k
          }
713
895k
          workspace[16] = (JCOEF)pred;
714
895k
        }
715
        /* AC11 */
716
1.15M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
844k
          num = Q00 * (change_dc ?
718
398k
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
398k
                 9 * DC19 + DC21 - DC25) :
720
844k
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
445k
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
844k
          if (num >= 0) {
723
549k
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
549k
            if (Al > 0 && pred >= (1 << Al))
725
6.34k
              pred = (1 << Al) - 1;
726
549k
          } else {
727
295k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
295k
            if (Al > 0 && pred >= (1 << Al))
729
6.35k
              pred = (1 << Al) - 1;
730
295k
            pred = -pred;
731
295k
          }
732
844k
          workspace[9] = (JCOEF)pred;
733
844k
        }
734
        /* AC02 */
735
1.15M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
863k
          num = Q00 * (change_dc ?
737
398k
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
398k
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
863k
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
863k
          if (num >= 0) {
741
483k
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
483k
            if (Al > 0 && pred >= (1 << Al))
743
3.64k
              pred = (1 << Al) - 1;
744
483k
          } else {
745
379k
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
379k
            if (Al > 0 && pred >= (1 << Al))
747
3.61k
              pred = (1 << Al) - 1;
748
379k
            pred = -pred;
749
379k
          }
750
863k
          workspace[2] = (JCOEF)pred;
751
863k
        }
752
1.15M
        if (change_dc) {
753
          /* AC03 */
754
398k
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
398k
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
398k
            if (num >= 0) {
757
286k
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
286k
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
286k
            } else {
761
112k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
112k
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
112k
              pred = -pred;
765
112k
            }
766
398k
            workspace[3] = (JCOEF)pred;
767
398k
          }
768
          /* AC12 */
769
398k
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
398k
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
398k
            if (num >= 0) {
772
145k
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
145k
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
253k
            } else {
776
253k
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
253k
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
253k
              pred = -pred;
780
253k
            }
781
398k
            workspace[10] = (JCOEF)pred;
782
398k
          }
783
          /* AC21 */
784
398k
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
398k
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
398k
            if (num >= 0) {
787
228k
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
228k
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
228k
            } else {
791
170k
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
170k
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
170k
              pred = -pred;
795
170k
            }
796
398k
            workspace[17] = (JCOEF)pred;
797
398k
          }
798
          /* AC30 */
799
398k
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
398k
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
398k
            if (num >= 0) {
802
284k
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
284k
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
284k
            } else {
806
113k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
113k
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
113k
              pred = -pred;
810
113k
            }
811
398k
            workspace[24] = (JCOEF)pred;
812
398k
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
398k
          num = Q00 *
817
398k
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
398k
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
398k
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
398k
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
398k
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
398k
          if (num >= 0) {
823
135k
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
263k
          } else {
825
263k
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
263k
            pred = -pred;
827
263k
          }
828
398k
          workspace[0] = (JCOEF)pred;
829
398k
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
1.15M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
1.15M
                        output_col);
837
#ifdef WITH_PROFILE
838
        cinfo->master->idct_elapsed += getTime() - cinfo->master->start;
839
        cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
840
#endif
841
        /* Advance for next column */
842
1.15M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
1.15M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
1.15M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
1.15M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
1.15M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
1.15M
        buffer_ptr++, prev_block_row++, next_block_row++,
848
1.15M
          prev_prev_block_row++, next_next_block_row++;
849
1.15M
        output_col += compptr->_DCT_scaled_size;
850
1.15M
      }
851
40.0k
      output_ptr += compptr->_DCT_scaled_size;
852
40.0k
    }
853
20.0k
  }
854
855
20.0k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
19.6k
    return JPEG_ROW_COMPLETED;
857
425
  return JPEG_SCAN_COMPLETED;
858
20.0k
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
474
20.0k
{
475
20.0k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
20.0k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
20.0k
  JDIMENSION block_num, last_block_column;
478
20.0k
  int ci, block_row, block_rows, access_rows, image_block_row,
479
20.0k
    image_block_rows;
480
20.0k
  JBLOCKARRAY buffer;
481
20.0k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
20.0k
  JBLOCKROW next_block_row, next_next_block_row;
483
20.0k
  _JSAMPARRAY output_ptr;
484
20.0k
  JDIMENSION output_col;
485
20.0k
  jpeg_component_info *compptr;
486
20.0k
  _inverse_DCT_method_ptr inverse_DCT;
487
20.0k
  boolean change_dc;
488
20.0k
  JCOEF *workspace;
489
20.0k
  int *coef_bits;
490
20.0k
  JQUANT_TBL *quanttbl;
491
20.0k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
20.0k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
20.0k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
20.0k
      DC25;
495
20.0k
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
20.0k
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
20.0k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
20.0k
         !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
40.1k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
20.0k
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
20.0k
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
20.0k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
19.2k
      block_rows = compptr->v_samp_factor;
526
19.2k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
19.2k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
372
      block_rows = compptr->v_samp_factor;
529
372
      access_rows = block_rows * 2; /* this and next iMCU row */
530
425
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
425
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
425
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
425
      access_rows = block_rows; /* this iMCU row only */
535
425
    }
536
    /* Align the virtual buffer for this component. */
537
20.0k
    if (cinfo->output_iMCU_row > 1) {
538
19.2k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
19.2k
      buffer = (*cinfo->mem->access_virt_barray)
540
19.2k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
19.2k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
19.2k
         (JDIMENSION)access_rows, FALSE);
543
19.2k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
19.2k
    } else if (cinfo->output_iMCU_row > 0) {
545
372
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
372
      buffer = (*cinfo->mem->access_virt_barray)
547
372
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
372
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
372
         (JDIMENSION)access_rows, FALSE);
550
372
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
425
    } else {
552
425
      buffer = (*cinfo->mem->access_virt_barray)
553
425
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
425
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
425
    }
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
20.0k
    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
20.0k
    else
564
20.0k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
565
566
    /* We only do DC interpolation if no AC coefficient data is available. */
567
20.0k
    change_dc =
568
20.0k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
16.6k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
16.0k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
20.0k
    quanttbl = compptr->quant_table;
573
20.0k
    Q00 = quanttbl->quantval[0];
574
20.0k
    Q01 = quanttbl->quantval[Q01_POS];
575
20.0k
    Q10 = quanttbl->quantval[Q10_POS];
576
20.0k
    Q20 = quanttbl->quantval[Q20_POS];
577
20.0k
    Q11 = quanttbl->quantval[Q11_POS];
578
20.0k
    Q02 = quanttbl->quantval[Q02_POS];
579
20.0k
    if (change_dc) {
580
15.7k
      Q03 = quanttbl->quantval[Q03_POS];
581
15.7k
      Q12 = quanttbl->quantval[Q12_POS];
582
15.7k
      Q21 = quanttbl->quantval[Q21_POS];
583
15.7k
      Q30 = quanttbl->quantval[Q30_POS];
584
15.7k
    }
585
20.0k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
20.0k
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
20.0k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
60.0k
    for (block_row = 0; block_row < block_rows; block_row++) {
590
40.0k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
40.0k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
40.0k
      if (image_block_row > 0)
594
39.5k
        prev_block_row =
595
39.5k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
425
      else
597
425
        prev_block_row = buffer_ptr;
598
599
40.0k
      if (image_block_row > 1)
600
39.1k
        prev_prev_block_row =
601
39.1k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
809
      else
603
809
        prev_prev_block_row = prev_block_row;
604
605
40.0k
      if (image_block_row < image_block_rows - 1)
606
39.5k
        next_block_row =
607
39.5k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
425
      else
609
425
        next_block_row = buffer_ptr;
610
611
40.0k
      if (image_block_row < image_block_rows - 2)
612
39.2k
        next_next_block_row =
613
39.2k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
758
      else
615
758
        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
40.0k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
40.0k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
40.0k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
40.0k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
40.0k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
40.0k
      output_col = 0;
626
40.0k
      last_block_column = compptr->width_in_blocks - 1;
627
40.0k
      for (block_num = cinfo->master->first_MCU_col[ci];
628
1.19M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
1.15M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
1.15M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
40.0k
            block_num < last_block_column) {
634
15.7k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
15.7k
          DC09 = DC10 = (int)prev_block_row[1][0];
636
15.7k
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
15.7k
          DC19 = DC20 = (int)next_block_row[1][0];
638
15.7k
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
15.7k
        }
640
1.15M
        if (block_num + 1 < last_block_column) {
641
1.09M
          DC05 = (int)prev_prev_block_row[2][0];
642
1.09M
          DC10 = (int)prev_block_row[2][0];
643
1.09M
          DC15 = (int)buffer_ptr[2][0];
644
1.09M
          DC20 = (int)next_block_row[2][0];
645
1.09M
          DC25 = (int)next_next_block_row[2][0];
646
1.09M
        }
647
        /* If DC interpolation is enabled, compute coefficient estimates using
648
         * a Gaussian-like kernel, keeping the averages of the DC values.
649
         *
650
         * If DC interpolation is disabled, compute coefficient estimates using
651
         * an algorithm similar to the one described in Section K.8 of the JPEG
652
         * standard, except applied to a 5x5 window rather than a 3x3 window.
653
         *
654
         * An estimate is applied only if the coefficient is still zero and is
655
         * not known to be fully accurate.
656
         */
657
        /* AC01 */
658
1.15M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
1.01M
          num = Q00 * (change_dc ?
660
398k
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
398k
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
398k
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
398k
                 DC21 - DC22 + DC24 + DC25) :
664
1.01M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
1.01M
          if (num >= 0) {
666
661k
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
661k
            if (Al > 0 && pred >= (1 << Al))
668
19.9k
              pred = (1 << Al) - 1;
669
661k
          } else {
670
356k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
356k
            if (Al > 0 && pred >= (1 << Al))
672
8.09k
              pred = (1 << Al) - 1;
673
356k
            pred = -pred;
674
356k
          }
675
1.01M
          workspace[1] = (JCOEF)pred;
676
1.01M
        }
677
        /* AC10 */
678
1.15M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
1.05M
          num = Q00 * (change_dc ?
680
398k
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
398k
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
398k
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
398k
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
1.05M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
1.05M
          if (num >= 0) {
686
863k
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
863k
            if (Al > 0 && pred >= (1 << Al))
688
177k
              pred = (1 << Al) - 1;
689
863k
          } else {
690
191k
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
191k
            if (Al > 0 && pred >= (1 << Al))
692
28.0k
              pred = (1 << Al) - 1;
693
191k
            pred = -pred;
694
191k
          }
695
1.05M
          workspace[8] = (JCOEF)pred;
696
1.05M
        }
697
        /* AC20 */
698
1.15M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
895k
          num = Q00 * (change_dc ?
700
398k
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
398k
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
895k
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
895k
          if (num >= 0) {
704
544k
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
544k
            if (Al > 0 && pred >= (1 << Al))
706
59.8k
              pred = (1 << Al) - 1;
707
544k
          } else {
708
351k
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
351k
            if (Al > 0 && pred >= (1 << Al))
710
58.7k
              pred = (1 << Al) - 1;
711
351k
            pred = -pred;
712
351k
          }
713
895k
          workspace[16] = (JCOEF)pred;
714
895k
        }
715
        /* AC11 */
716
1.15M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
844k
          num = Q00 * (change_dc ?
718
398k
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
398k
                 9 * DC19 + DC21 - DC25) :
720
844k
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
445k
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
844k
          if (num >= 0) {
723
549k
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
549k
            if (Al > 0 && pred >= (1 << Al))
725
6.34k
              pred = (1 << Al) - 1;
726
549k
          } else {
727
295k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
295k
            if (Al > 0 && pred >= (1 << Al))
729
6.35k
              pred = (1 << Al) - 1;
730
295k
            pred = -pred;
731
295k
          }
732
844k
          workspace[9] = (JCOEF)pred;
733
844k
        }
734
        /* AC02 */
735
1.15M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
863k
          num = Q00 * (change_dc ?
737
398k
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
398k
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
863k
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
863k
          if (num >= 0) {
741
483k
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
483k
            if (Al > 0 && pred >= (1 << Al))
743
3.64k
              pred = (1 << Al) - 1;
744
483k
          } else {
745
379k
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
379k
            if (Al > 0 && pred >= (1 << Al))
747
3.61k
              pred = (1 << Al) - 1;
748
379k
            pred = -pred;
749
379k
          }
750
863k
          workspace[2] = (JCOEF)pred;
751
863k
        }
752
1.15M
        if (change_dc) {
753
          /* AC03 */
754
398k
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
398k
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
398k
            if (num >= 0) {
757
286k
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
286k
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
286k
            } else {
761
112k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
112k
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
112k
              pred = -pred;
765
112k
            }
766
398k
            workspace[3] = (JCOEF)pred;
767
398k
          }
768
          /* AC12 */
769
398k
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
398k
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
398k
            if (num >= 0) {
772
145k
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
145k
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
253k
            } else {
776
253k
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
253k
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
253k
              pred = -pred;
780
253k
            }
781
398k
            workspace[10] = (JCOEF)pred;
782
398k
          }
783
          /* AC21 */
784
398k
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
398k
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
398k
            if (num >= 0) {
787
228k
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
228k
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
228k
            } else {
791
170k
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
170k
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
170k
              pred = -pred;
795
170k
            }
796
398k
            workspace[17] = (JCOEF)pred;
797
398k
          }
798
          /* AC30 */
799
398k
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
398k
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
398k
            if (num >= 0) {
802
284k
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
284k
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
284k
            } else {
806
113k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
113k
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
113k
              pred = -pred;
810
113k
            }
811
398k
            workspace[24] = (JCOEF)pred;
812
398k
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
398k
          num = Q00 *
817
398k
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
398k
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
398k
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
398k
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
398k
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
398k
          if (num >= 0) {
823
135k
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
263k
          } else {
825
263k
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
263k
            pred = -pred;
827
263k
          }
828
398k
          workspace[0] = (JCOEF)pred;
829
398k
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
1.15M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
1.15M
                        output_col);
837
#ifdef WITH_PROFILE
838
        cinfo->master->idct_elapsed += getTime() - cinfo->master->start;
839
        cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
840
#endif
841
        /* Advance for next column */
842
1.15M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
1.15M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
1.15M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
1.15M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
1.15M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
1.15M
        buffer_ptr++, prev_block_row++, next_block_row++,
848
1.15M
          prev_prev_block_row++, next_next_block_row++;
849
1.15M
        output_col += compptr->_DCT_scaled_size;
850
1.15M
      }
851
40.0k
      output_ptr += compptr->_DCT_scaled_size;
852
40.0k
    }
853
20.0k
  }
854
855
20.0k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
19.6k
    return JPEG_ROW_COMPLETED;
857
425
  return JPEG_SCAN_COMPLETED;
858
20.0k
}
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
1.69k
{
870
1.69k
  my_coef_ptr coef;
871
872
1.69k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
1.69k
  coef = (my_coef_ptr)
876
1.69k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
1.69k
                                sizeof(my_coef_controller));
878
1.69k
  memset(coef, 0, sizeof(my_coef_controller));
879
1.69k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
1.69k
  coef->pub.start_input_pass = start_input_pass;
881
1.69k
  coef->pub.start_output_pass = start_output_pass;
882
1.69k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
1.69k
  coef->coef_bits_latch = NULL;
884
1.69k
#endif
885
886
  /* Create the coefficient buffer. */
887
1.69k
  if (need_full_buffer) {
888
916
#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
916
    int ci, access_rows;
893
916
    jpeg_component_info *compptr;
894
895
1.88k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
964
         ci++, compptr++) {
897
964
      access_rows = compptr->v_samp_factor;
898
964
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
964
      if (cinfo->progressive_mode)
901
949
        access_rows *= 5;
902
964
#endif
903
964
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
964
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
964
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
964
                               (long)compptr->h_samp_factor),
907
964
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
964
                               (long)compptr->v_samp_factor),
909
964
         (JDIMENSION)access_rows);
910
964
    }
911
916
    coef->pub.consume_data = consume_data;
912
916
    coef->pub._decompress_data = decompress_data;
913
916
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
916
  } else {
918
    /* We only need a single-MCU buffer. */
919
775
    JBLOCKROW buffer;
920
775
    int i;
921
922
775
    buffer = (JBLOCKROW)
923
775
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
775
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
8.52k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
7.75k
      coef->MCU_buffer[i] = buffer + i;
927
7.75k
    }
928
775
    coef->pub.consume_data = dummy_consume_data;
929
775
    coef->pub._decompress_data = decompress_onepass;
930
775
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
775
  }
932
933
  /* Allocate the workspace buffer */
934
1.69k
  coef->workspace = (JCOEF *)
935
1.69k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
1.69k
                                sizeof(JCOEF) * DCTSIZE2);
937
1.69k
}
jinit_d_coef_controller
Line
Count
Source
869
1.62k
{
870
1.62k
  my_coef_ptr coef;
871
872
1.62k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
1.62k
  coef = (my_coef_ptr)
876
1.62k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
1.62k
                                sizeof(my_coef_controller));
878
1.62k
  memset(coef, 0, sizeof(my_coef_controller));
879
1.62k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
1.62k
  coef->pub.start_input_pass = start_input_pass;
881
1.62k
  coef->pub.start_output_pass = start_output_pass;
882
1.62k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
1.62k
  coef->coef_bits_latch = NULL;
884
1.62k
#endif
885
886
  /* Create the coefficient buffer. */
887
1.62k
  if (need_full_buffer) {
888
856
#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
856
    int ci, access_rows;
893
856
    jpeg_component_info *compptr;
894
895
1.73k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
878
         ci++, compptr++) {
897
878
      access_rows = compptr->v_samp_factor;
898
878
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
878
      if (cinfo->progressive_mode)
901
869
        access_rows *= 5;
902
878
#endif
903
878
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
878
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
878
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
878
                               (long)compptr->h_samp_factor),
907
878
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
878
                               (long)compptr->v_samp_factor),
909
878
         (JDIMENSION)access_rows);
910
878
    }
911
856
    coef->pub.consume_data = consume_data;
912
856
    coef->pub._decompress_data = decompress_data;
913
856
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
856
  } else {
918
    /* We only need a single-MCU buffer. */
919
772
    JBLOCKROW buffer;
920
772
    int i;
921
922
772
    buffer = (JBLOCKROW)
923
772
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
772
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
8.49k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
7.72k
      coef->MCU_buffer[i] = buffer + i;
927
7.72k
    }
928
772
    coef->pub.consume_data = dummy_consume_data;
929
772
    coef->pub._decompress_data = decompress_onepass;
930
772
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
772
  }
932
933
  /* Allocate the workspace buffer */
934
1.62k
  coef->workspace = (JCOEF *)
935
1.62k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
1.62k
                                sizeof(JCOEF) * DCTSIZE2);
937
1.62k
}
j12init_d_coef_controller
Line
Count
Source
869
63
{
870
63
  my_coef_ptr coef;
871
872
63
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
63
  coef = (my_coef_ptr)
876
63
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
63
                                sizeof(my_coef_controller));
878
63
  memset(coef, 0, sizeof(my_coef_controller));
879
63
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
63
  coef->pub.start_input_pass = start_input_pass;
881
63
  coef->pub.start_output_pass = start_output_pass;
882
63
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
63
  coef->coef_bits_latch = NULL;
884
63
#endif
885
886
  /* Create the coefficient buffer. */
887
63
  if (need_full_buffer) {
888
60
#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
60
    int ci, access_rows;
893
60
    jpeg_component_info *compptr;
894
895
146
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
86
         ci++, compptr++) {
897
86
      access_rows = compptr->v_samp_factor;
898
86
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
86
      if (cinfo->progressive_mode)
901
80
        access_rows *= 5;
902
86
#endif
903
86
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
86
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
86
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
86
                               (long)compptr->h_samp_factor),
907
86
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
86
                               (long)compptr->v_samp_factor),
909
86
         (JDIMENSION)access_rows);
910
86
    }
911
60
    coef->pub.consume_data = consume_data;
912
60
    coef->pub._decompress_data = decompress_data;
913
60
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
60
  } else {
918
    /* We only need a single-MCU buffer. */
919
3
    JBLOCKROW buffer;
920
3
    int i;
921
922
3
    buffer = (JBLOCKROW)
923
3
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
3
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
33
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
30
      coef->MCU_buffer[i] = buffer + i;
927
30
    }
928
3
    coef->pub.consume_data = dummy_consume_data;
929
3
    coef->pub._decompress_data = decompress_onepass;
930
3
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
3
  }
932
933
  /* Allocate the workspace buffer */
934
63
  coef->workspace = (JCOEF *)
935
63
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
63
                                sizeof(JCOEF) * DCTSIZE2);
937
63
}