Coverage Report

Created: 2025-08-29 06:57

/src/libjpeg-turbo/src/jdcoefct.c
Line
Count
Source (jump to first uncovered line)
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-2024, 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
27
28
/* Forward declarations */
29
METHODDEF(int) decompress_onepass(j_decompress_ptr cinfo,
30
                                  _JSAMPIMAGE output_buf);
31
#ifdef D_MULTISCAN_FILES_SUPPORTED
32
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
33
#endif
34
#ifdef BLOCK_SMOOTHING_SUPPORTED
35
LOCAL(boolean) smoothing_ok(j_decompress_ptr cinfo);
36
METHODDEF(int) decompress_smooth_data(j_decompress_ptr cinfo,
37
                                      _JSAMPIMAGE output_buf);
38
#endif
39
40
41
/*
42
 * Initialize for an input processing pass.
43
 */
44
45
METHODDEF(void)
46
start_input_pass(j_decompress_ptr cinfo)
47
103k
{
48
103k
  cinfo->input_iMCU_row = 0;
49
103k
  start_iMCU_row(cinfo);
50
103k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
47
93.4k
{
48
93.4k
  cinfo->input_iMCU_row = 0;
49
93.4k
  start_iMCU_row(cinfo);
50
93.4k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
47
9.87k
{
48
9.87k
  cinfo->input_iMCU_row = 0;
49
9.87k
  start_iMCU_row(cinfo);
50
9.87k
}
51
52
53
/*
54
 * Initialize for an output processing pass.
55
 */
56
57
METHODDEF(void)
58
start_output_pass(j_decompress_ptr cinfo)
59
31.1k
{
60
31.1k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
31.1k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
62
63
  /* If multipass, check to see whether to use block smoothing on this pass */
64
31.1k
  if (coef->pub.coef_arrays != NULL) {
65
14.9k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
9.78k
      coef->pub._decompress_data = decompress_smooth_data;
67
5.13k
    else
68
5.13k
      coef->pub._decompress_data = decompress_data;
69
14.9k
  }
70
31.1k
#endif
71
31.1k
  cinfo->output_iMCU_row = 0;
72
31.1k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
59
30.1k
{
60
30.1k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
30.1k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
62
63
  /* If multipass, check to see whether to use block smoothing on this pass */
64
30.1k
  if (coef->pub.coef_arrays != NULL) {
65
14.0k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
9.49k
      coef->pub._decompress_data = decompress_smooth_data;
67
4.51k
    else
68
4.51k
      coef->pub._decompress_data = decompress_data;
69
14.0k
  }
70
30.1k
#endif
71
30.1k
  cinfo->output_iMCU_row = 0;
72
30.1k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
59
1.00k
{
60
1.00k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
1.00k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
62
63
  /* If multipass, check to see whether to use block smoothing on this pass */
64
1.00k
  if (coef->pub.coef_arrays != NULL) {
65
911
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
293
      coef->pub._decompress_data = decompress_smooth_data;
67
618
    else
68
618
      coef->pub._decompress_data = decompress_data;
69
911
  }
70
1.00k
#endif
71
1.00k
  cinfo->output_iMCU_row = 0;
72
1.00k
}
73
74
75
/*
76
 * Decompress and return some data in the single-pass case.
77
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
78
 * Input and output must run in lockstep since we have only a one-MCU buffer.
79
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
80
 *
81
 * NB: output_buf contains a plane for each component in image,
82
 * which we index according to the component's SOF position.
83
 */
84
85
METHODDEF(int)
86
decompress_onepass(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
87
2.66M
{
88
2.66M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
2.66M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
2.66M
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
2.66M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
2.66M
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
2.66M
  _JSAMPARRAY output_ptr;
94
2.66M
  JDIMENSION start_col, output_col;
95
2.66M
  jpeg_component_info *compptr;
96
2.66M
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
5.66M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
2.99M
       yoffset++) {
101
43.6M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
40.6M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
40.6M
      jzero_far((void *)coef->MCU_buffer[0],
105
40.6M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
40.6M
      if (!cinfo->entropy->insufficient_data)
107
40.6M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
40.6M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
109
        /* Suspension forced; update state counters and exit */
110
0
        coef->MCU_vert_offset = yoffset;
111
0
        coef->MCU_ctr = MCU_col_num;
112
0
        return JPEG_SUSPENDED;
113
0
      }
114
115
      /* Only perform the IDCT on blocks that are contained within the desired
116
       * cropping region.
117
       */
118
40.6M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
40.6M
          MCU_col_num <= cinfo->master->last_iMCU_col) {
120
        /* Determine where data should go in output_buf and do the IDCT thing.
121
         * We skip dummy blocks at the right and bottom edges (but blkn gets
122
         * incremented past them!).  Note the inner loop relies on having
123
         * allocated the MCU_buffer[] blocks sequentially.
124
         */
125
40.6M
        blkn = 0;               /* index of current DCT block within MCU */
126
124M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
83.6M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
83.6M
          if (!compptr->component_needed) {
130
0
            blkn += compptr->MCU_blocks;
131
0
            continue;
132
0
          }
133
83.6M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
83.6M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
76.1M
                         compptr->MCU_width : compptr->last_col_width;
136
83.6M
          output_ptr = output_buf[compptr->component_index] +
137
83.6M
                       yoffset * compptr->_DCT_scaled_size;
138
83.6M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
83.6M
                      compptr->MCU_sample_width;
140
177M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
94.1M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
94.1M
                yoffset + yindex < compptr->last_row_height) {
143
93.1M
              output_col = start_col;
144
195M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
102M
                (*inverse_DCT) (cinfo, compptr,
146
102M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
102M
                                output_ptr, output_col);
148
102M
                output_col += compptr->_DCT_scaled_size;
149
102M
              }
150
93.1M
            }
151
94.1M
            blkn += compptr->MCU_width;
152
94.1M
            output_ptr += compptr->_DCT_scaled_size;
153
94.1M
          }
154
83.6M
        }
155
40.6M
      }
156
40.6M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
2.99M
    coef->MCU_ctr = 0;
159
2.99M
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
2.66M
  cinfo->output_iMCU_row++;
162
2.66M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
2.64M
    start_iMCU_row(cinfo);
164
2.64M
    return JPEG_ROW_COMPLETED;
165
2.64M
  }
166
  /* Completed the scan */
167
16.1k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
16.1k
  return JPEG_SCAN_COMPLETED;
169
2.66M
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
87
2.66M
{
88
2.66M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
2.66M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
2.66M
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
2.66M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
2.66M
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
2.66M
  _JSAMPARRAY output_ptr;
94
2.66M
  JDIMENSION start_col, output_col;
95
2.66M
  jpeg_component_info *compptr;
96
2.66M
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
5.66M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
2.99M
       yoffset++) {
101
43.6M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
40.6M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
40.6M
      jzero_far((void *)coef->MCU_buffer[0],
105
40.6M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
40.6M
      if (!cinfo->entropy->insufficient_data)
107
40.6M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
40.6M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
109
        /* Suspension forced; update state counters and exit */
110
0
        coef->MCU_vert_offset = yoffset;
111
0
        coef->MCU_ctr = MCU_col_num;
112
0
        return JPEG_SUSPENDED;
113
0
      }
114
115
      /* Only perform the IDCT on blocks that are contained within the desired
116
       * cropping region.
117
       */
118
40.6M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
40.6M
          MCU_col_num <= cinfo->master->last_iMCU_col) {
120
        /* Determine where data should go in output_buf and do the IDCT thing.
121
         * We skip dummy blocks at the right and bottom edges (but blkn gets
122
         * incremented past them!).  Note the inner loop relies on having
123
         * allocated the MCU_buffer[] blocks sequentially.
124
         */
125
40.6M
        blkn = 0;               /* index of current DCT block within MCU */
126
124M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
83.6M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
83.6M
          if (!compptr->component_needed) {
130
0
            blkn += compptr->MCU_blocks;
131
0
            continue;
132
0
          }
133
83.6M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
83.6M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
76.1M
                         compptr->MCU_width : compptr->last_col_width;
136
83.6M
          output_ptr = output_buf[compptr->component_index] +
137
83.6M
                       yoffset * compptr->_DCT_scaled_size;
138
83.6M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
83.6M
                      compptr->MCU_sample_width;
140
177M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
94.1M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
94.1M
                yoffset + yindex < compptr->last_row_height) {
143
93.1M
              output_col = start_col;
144
195M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
102M
                (*inverse_DCT) (cinfo, compptr,
146
102M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
102M
                                output_ptr, output_col);
148
102M
                output_col += compptr->_DCT_scaled_size;
149
102M
              }
150
93.1M
            }
151
94.1M
            blkn += compptr->MCU_width;
152
94.1M
            output_ptr += compptr->_DCT_scaled_size;
153
94.1M
          }
154
83.6M
        }
155
40.6M
      }
156
40.6M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
2.99M
    coef->MCU_ctr = 0;
159
2.99M
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
2.66M
  cinfo->output_iMCU_row++;
162
2.66M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
2.64M
    start_iMCU_row(cinfo);
164
2.64M
    return JPEG_ROW_COMPLETED;
165
2.64M
  }
166
  /* Completed the scan */
167
16.1k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
16.1k
  return JPEG_SCAN_COMPLETED;
169
2.66M
}
Unexecuted instantiation: jdcoefct-12.c:decompress_onepass
170
171
172
/*
173
 * Dummy consume-input routine for single-pass operation.
174
 */
175
176
METHODDEF(int)
177
dummy_consume_data(j_decompress_ptr cinfo)
178
0
{
179
0
  return JPEG_SUSPENDED;        /* Always indicate nothing was done */
180
0
}
Unexecuted instantiation: jdcoefct-8.c:dummy_consume_data
Unexecuted instantiation: jdcoefct-12.c:dummy_consume_data
181
182
183
#ifdef D_MULTISCAN_FILES_SUPPORTED
184
185
/*
186
 * Consume input data and store it in the full-image coefficient buffer.
187
 * We read as much as one fully interleaved MCU row ("iMCU" row) per call,
188
 * ie, v_samp_factor block rows for each component in the scan.
189
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
190
 */
191
192
METHODDEF(int)
193
consume_data(j_decompress_ptr cinfo)
194
15.0M
{
195
15.0M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
15.0M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
15.0M
  int blkn, ci, xindex, yindex, yoffset;
198
15.0M
  JDIMENSION start_col;
199
15.0M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
15.0M
  JBLOCKROW buffer_ptr;
201
15.0M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
43.6M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
28.6M
    compptr = cinfo->cur_comp_info[ci];
206
28.6M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
28.6M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
28.6M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
28.6M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
210
    /* Note: entropy decoder expects buffer to be zeroed,
211
     * but this is handled automatically by the memory manager
212
     * because we requested a pre-zeroed array.
213
     */
214
28.6M
  }
215
216
  /* Loop to process one whole iMCU row */
217
36.4M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
21.4M
       yoffset++) {
219
340M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
319M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
319M
      blkn = 0;                 /* index of current DCT block within MCU */
223
810M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
490M
        compptr = cinfo->cur_comp_info[ci];
225
490M
        start_col = MCU_col_num * compptr->MCU_width;
226
1.07G
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
579M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
1.23G
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
650M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
650M
          }
231
579M
        }
232
490M
      }
233
319M
      if (!cinfo->entropy->insufficient_data)
234
319M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
319M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
237
        /* Suspension forced; update state counters and exit */
238
0
        coef->MCU_vert_offset = yoffset;
239
0
        coef->MCU_ctr = MCU_col_num;
240
0
        return JPEG_SUSPENDED;
241
0
      }
242
319M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
21.4M
    coef->MCU_ctr = 0;
245
21.4M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
15.0M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
14.9M
    start_iMCU_row(cinfo);
249
14.9M
    return JPEG_ROW_COMPLETED;
250
14.9M
  }
251
  /* Completed the scan */
252
87.1k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
87.1k
  return JPEG_SCAN_COMPLETED;
254
15.0M
}
jdcoefct-8.c:consume_data
Line
Count
Source
194
12.2M
{
195
12.2M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
12.2M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
12.2M
  int blkn, ci, xindex, yindex, yoffset;
198
12.2M
  JDIMENSION start_col;
199
12.2M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
12.2M
  JBLOCKROW buffer_ptr;
201
12.2M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
33.1M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
20.9M
    compptr = cinfo->cur_comp_info[ci];
206
20.9M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
20.9M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
20.9M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
20.9M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
210
    /* Note: entropy decoder expects buffer to be zeroed,
211
     * but this is handled automatically by the memory manager
212
     * because we requested a pre-zeroed array.
213
     */
214
20.9M
  }
215
216
  /* Loop to process one whole iMCU row */
217
30.3M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
18.1M
       yoffset++) {
219
295M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
277M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
277M
      blkn = 0;                 /* index of current DCT block within MCU */
223
696M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
418M
        compptr = cinfo->cur_comp_info[ci];
225
418M
        start_col = MCU_col_num * compptr->MCU_width;
226
908M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
489M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
1.03G
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
544M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
544M
          }
231
489M
        }
232
418M
      }
233
277M
      if (!cinfo->entropy->insufficient_data)
234
277M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
277M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
237
        /* Suspension forced; update state counters and exit */
238
0
        coef->MCU_vert_offset = yoffset;
239
0
        coef->MCU_ctr = MCU_col_num;
240
0
        return JPEG_SUSPENDED;
241
0
      }
242
277M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
18.1M
    coef->MCU_ctr = 0;
245
18.1M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
12.2M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
12.1M
    start_iMCU_row(cinfo);
249
12.1M
    return JPEG_ROW_COMPLETED;
250
12.1M
  }
251
  /* Completed the scan */
252
77.3k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
77.3k
  return JPEG_SCAN_COMPLETED;
254
12.2M
}
jdcoefct-12.c:consume_data
Line
Count
Source
194
2.79M
{
195
2.79M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
2.79M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
2.79M
  int blkn, ci, xindex, yindex, yoffset;
198
2.79M
  JDIMENSION start_col;
199
2.79M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
2.79M
  JBLOCKROW buffer_ptr;
201
2.79M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
10.5M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
7.72M
    compptr = cinfo->cur_comp_info[ci];
206
7.72M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
7.72M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
7.72M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
7.72M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
210
    /* Note: entropy decoder expects buffer to be zeroed,
211
     * but this is handled automatically by the memory manager
212
     * because we requested a pre-zeroed array.
213
     */
214
7.72M
  }
215
216
  /* Loop to process one whole iMCU row */
217
6.06M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
3.26M
       yoffset++) {
219
45.0M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
41.7M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
41.7M
      blkn = 0;                 /* index of current DCT block within MCU */
223
114M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
72.5M
        compptr = cinfo->cur_comp_info[ci];
225
72.5M
        start_col = MCU_col_num * compptr->MCU_width;
226
162M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
90.0M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
195M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
105M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
105M
          }
231
90.0M
        }
232
72.5M
      }
233
41.7M
      if (!cinfo->entropy->insufficient_data)
234
41.7M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
41.7M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
237
        /* Suspension forced; update state counters and exit */
238
0
        coef->MCU_vert_offset = yoffset;
239
0
        coef->MCU_ctr = MCU_col_num;
240
0
        return JPEG_SUSPENDED;
241
0
      }
242
41.7M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
3.26M
    coef->MCU_ctr = 0;
245
3.26M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
2.79M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
2.78M
    start_iMCU_row(cinfo);
249
2.78M
    return JPEG_ROW_COMPLETED;
250
2.78M
  }
251
  /* Completed the scan */
252
9.77k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
9.77k
  return JPEG_SCAN_COMPLETED;
254
2.79M
}
255
256
257
/*
258
 * Decompress and return some data in the multi-pass case.
259
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
260
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
261
 *
262
 * NB: output_buf contains a plane for each component in image.
263
 */
264
265
METHODDEF(int)
266
decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
267
1.01M
{
268
1.01M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
1.01M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
1.01M
  JDIMENSION block_num;
271
1.01M
  int ci, block_row, block_rows;
272
1.01M
  JBLOCKARRAY buffer;
273
1.01M
  JBLOCKROW buffer_ptr;
274
1.01M
  _JSAMPARRAY output_ptr;
275
1.01M
  JDIMENSION output_col;
276
1.01M
  jpeg_component_info *compptr;
277
1.01M
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
1.01M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
1.01M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
1.01M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
283
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
284
0
      return JPEG_SUSPENDED;
285
0
  }
286
287
  /* OK, output from the virtual arrays. */
288
3.19M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
2.18M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
2.18M
    if (!compptr->component_needed)
292
0
      continue;
293
    /* Align the virtual buffer for this component. */
294
2.18M
    buffer = (*cinfo->mem->access_virt_barray)
295
2.18M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
2.18M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
2.18M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
2.18M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
2.17M
      block_rows = compptr->v_samp_factor;
301
12.8k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
12.8k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
12.8k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
12.8k
    }
306
2.18M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
2.18M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
5.52M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
3.34M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
3.34M
      output_col = 0;
312
3.34M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
47.0M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
43.7M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
43.7M
                        output_col);
316
43.7M
        buffer_ptr++;
317
43.7M
        output_col += compptr->_DCT_scaled_size;
318
43.7M
      }
319
3.34M
      output_ptr += compptr->_DCT_scaled_size;
320
3.34M
    }
321
2.18M
  }
322
323
1.01M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
1.01M
    return JPEG_ROW_COMPLETED;
325
4.51k
  return JPEG_SCAN_COMPLETED;
326
1.01M
}
jdcoefct-8.c:decompress_data
Line
Count
Source
267
1.01M
{
268
1.01M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
1.01M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
1.01M
  JDIMENSION block_num;
271
1.01M
  int ci, block_row, block_rows;
272
1.01M
  JBLOCKARRAY buffer;
273
1.01M
  JBLOCKROW buffer_ptr;
274
1.01M
  _JSAMPARRAY output_ptr;
275
1.01M
  JDIMENSION output_col;
276
1.01M
  jpeg_component_info *compptr;
277
1.01M
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
1.01M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
1.01M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
1.01M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
283
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
284
0
      return JPEG_SUSPENDED;
285
0
  }
286
287
  /* OK, output from the virtual arrays. */
288
3.19M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
2.18M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
2.18M
    if (!compptr->component_needed)
292
0
      continue;
293
    /* Align the virtual buffer for this component. */
294
2.18M
    buffer = (*cinfo->mem->access_virt_barray)
295
2.18M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
2.18M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
2.18M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
2.18M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
2.17M
      block_rows = compptr->v_samp_factor;
301
12.8k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
12.8k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
12.8k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
12.8k
    }
306
2.18M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
2.18M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
5.52M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
3.34M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
3.34M
      output_col = 0;
312
3.34M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
47.0M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
43.7M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
43.7M
                        output_col);
316
43.7M
        buffer_ptr++;
317
43.7M
        output_col += compptr->_DCT_scaled_size;
318
43.7M
      }
319
3.34M
      output_ptr += compptr->_DCT_scaled_size;
320
3.34M
    }
321
2.18M
  }
322
323
1.01M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
1.01M
    return JPEG_ROW_COMPLETED;
325
4.51k
  return JPEG_SCAN_COMPLETED;
326
1.01M
}
Unexecuted instantiation: jdcoefct-12.c:decompress_data
327
328
#endif /* D_MULTISCAN_FILES_SUPPORTED */
329
330
331
#ifdef BLOCK_SMOOTHING_SUPPORTED
332
333
/*
334
 * This code applies interblock smoothing; the first 9 AC coefficients are
335
 * estimated from the DC values of a DCT block and its 24 neighboring blocks.
336
 * We apply smoothing only for progressive JPEG decoding, and only if
337
 * the coefficients it can estimate are not yet known to full precision.
338
 */
339
340
/* Natural-order array positions of the first 9 zigzag-order coefficients */
341
7.93M
#define Q01_POS  1
342
7.93M
#define Q10_POS  8
343
7.93M
#define Q20_POS  16
344
7.93M
#define Q11_POS  9
345
7.93M
#define Q02_POS  2
346
6.08M
#define Q03_POS  3
347
6.08M
#define Q12_POS  10
348
6.07M
#define Q21_POS  17
349
6.07M
#define Q30_POS  24
350
351
/*
352
 * Determine whether block smoothing is applicable and safe.
353
 * We also latch the current states of the coef_bits[] entries for the
354
 * AC coefficients; otherwise, if the input side of the decompressor
355
 * advances into a new scan, we might think the coefficients are known
356
 * more accurately than they really are.
357
 */
358
359
LOCAL(boolean)
360
smoothing_ok(j_decompress_ptr cinfo)
361
14.9k
{
362
14.9k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
14.9k
  boolean smoothing_useful = FALSE;
364
14.9k
  int ci, coefi;
365
14.9k
  jpeg_component_info *compptr;
366
14.9k
  JQUANT_TBL *qtable;
367
14.9k
  int *coef_bits, *prev_coef_bits;
368
14.9k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
14.9k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
94
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
14.8k
  if (coef->coef_bits_latch == NULL)
375
14.8k
    coef->coef_bits_latch = (int *)
376
14.8k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
14.8k
                                  cinfo->num_components * 2 *
378
14.8k
                                  (SAVED_COEFS * sizeof(int)));
379
14.8k
  coef_bits_latch = coef->coef_bits_latch;
380
14.8k
  prev_coef_bits_latch =
381
14.8k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
49.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
36.8k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
36.8k
    if ((qtable = compptr->quant_table) == NULL)
387
258
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
36.5k
    if (qtable->quantval[0] == 0 ||
390
36.5k
        qtable->quantval[Q01_POS] == 0 ||
391
36.5k
        qtable->quantval[Q10_POS] == 0 ||
392
36.5k
        qtable->quantval[Q20_POS] == 0 ||
393
36.5k
        qtable->quantval[Q11_POS] == 0 ||
394
36.5k
        qtable->quantval[Q02_POS] == 0 ||
395
36.5k
        qtable->quantval[Q03_POS] == 0 ||
396
36.5k
        qtable->quantval[Q12_POS] == 0 ||
397
36.5k
        qtable->quantval[Q21_POS] == 0 ||
398
36.5k
        qtable->quantval[Q30_POS] == 0)
399
2.32k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
34.2k
    coef_bits = cinfo->coef_bits[ci];
402
34.2k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
34.2k
    if (coef_bits[0] < 0)
404
0
      return FALSE;
405
34.2k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
342k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
308k
      if (cinfo->input_scan_number > 1)
409
199k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
108k
      else
411
108k
        prev_coef_bits_latch[coefi] = -1;
412
308k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
308k
      if (coef_bits[coefi] != 0)
414
236k
        smoothing_useful = TRUE;
415
308k
    }
416
34.2k
    coef_bits_latch += SAVED_COEFS;
417
34.2k
    prev_coef_bits_latch += SAVED_COEFS;
418
34.2k
  }
419
420
12.2k
  return smoothing_useful;
421
14.8k
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
361
14.0k
{
362
14.0k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
14.0k
  boolean smoothing_useful = FALSE;
364
14.0k
  int ci, coefi;
365
14.0k
  jpeg_component_info *compptr;
366
14.0k
  JQUANT_TBL *qtable;
367
14.0k
  int *coef_bits, *prev_coef_bits;
368
14.0k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
14.0k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
73
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
13.9k
  if (coef->coef_bits_latch == NULL)
375
13.9k
    coef->coef_bits_latch = (int *)
376
13.9k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
13.9k
                                  cinfo->num_components * 2 *
378
13.9k
                                  (SAVED_COEFS * sizeof(int)));
379
13.9k
  coef_bits_latch = coef->coef_bits_latch;
380
13.9k
  prev_coef_bits_latch =
381
13.9k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
47.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
35.3k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
35.3k
    if ((qtable = compptr->quant_table) == NULL)
387
227
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
35.0k
    if (qtable->quantval[0] == 0 ||
390
35.0k
        qtable->quantval[Q01_POS] == 0 ||
391
35.0k
        qtable->quantval[Q10_POS] == 0 ||
392
35.0k
        qtable->quantval[Q20_POS] == 0 ||
393
35.0k
        qtable->quantval[Q11_POS] == 0 ||
394
35.0k
        qtable->quantval[Q02_POS] == 0 ||
395
35.0k
        qtable->quantval[Q03_POS] == 0 ||
396
35.0k
        qtable->quantval[Q12_POS] == 0 ||
397
35.0k
        qtable->quantval[Q21_POS] == 0 ||
398
35.0k
        qtable->quantval[Q30_POS] == 0)
399
1.76k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
33.3k
    coef_bits = cinfo->coef_bits[ci];
402
33.3k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
33.3k
    if (coef_bits[0] < 0)
404
0
      return FALSE;
405
33.3k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
333k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
299k
      if (cinfo->input_scan_number > 1)
409
195k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
104k
      else
411
104k
        prev_coef_bits_latch[coefi] = -1;
412
299k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
299k
      if (coef_bits[coefi] != 0)
414
229k
        smoothing_useful = TRUE;
415
299k
    }
416
33.3k
    coef_bits_latch += SAVED_COEFS;
417
33.3k
    prev_coef_bits_latch += SAVED_COEFS;
418
33.3k
  }
419
420
11.9k
  return smoothing_useful;
421
13.9k
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
361
911
{
362
911
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
911
  boolean smoothing_useful = FALSE;
364
911
  int ci, coefi;
365
911
  jpeg_component_info *compptr;
366
911
  JQUANT_TBL *qtable;
367
911
  int *coef_bits, *prev_coef_bits;
368
911
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
911
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
21
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
890
  if (coef->coef_bits_latch == NULL)
375
890
    coef->coef_bits_latch = (int *)
376
890
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
890
                                  cinfo->num_components * 2 *
378
890
                                  (SAVED_COEFS * sizeof(int)));
379
890
  coef_bits_latch = coef->coef_bits_latch;
380
890
  prev_coef_bits_latch =
381
890
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
1.83k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
1.53k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
1.53k
    if ((qtable = compptr->quant_table) == NULL)
387
31
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
1.50k
    if (qtable->quantval[0] == 0 ||
390
1.50k
        qtable->quantval[Q01_POS] == 0 ||
391
1.50k
        qtable->quantval[Q10_POS] == 0 ||
392
1.50k
        qtable->quantval[Q20_POS] == 0 ||
393
1.50k
        qtable->quantval[Q11_POS] == 0 ||
394
1.50k
        qtable->quantval[Q02_POS] == 0 ||
395
1.50k
        qtable->quantval[Q03_POS] == 0 ||
396
1.50k
        qtable->quantval[Q12_POS] == 0 ||
397
1.50k
        qtable->quantval[Q21_POS] == 0 ||
398
1.50k
        qtable->quantval[Q30_POS] == 0)
399
561
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
942
    coef_bits = cinfo->coef_bits[ci];
402
942
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
942
    if (coef_bits[0] < 0)
404
0
      return FALSE;
405
942
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
9.42k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
8.47k
      if (cinfo->input_scan_number > 1)
409
4.16k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
4.31k
      else
411
4.31k
        prev_coef_bits_latch[coefi] = -1;
412
8.47k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
8.47k
      if (coef_bits[coefi] != 0)
414
7.72k
        smoothing_useful = TRUE;
415
8.47k
    }
416
942
    coef_bits_latch += SAVED_COEFS;
417
942
    prev_coef_bits_latch += SAVED_COEFS;
418
942
  }
419
420
298
  return smoothing_useful;
421
890
}
422
423
424
/*
425
 * Variant of decompress_data for use when doing block smoothing.
426
 */
427
428
METHODDEF(int)
429
decompress_smooth_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
430
4.13M
{
431
4.13M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
4.13M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
4.13M
  JDIMENSION block_num, last_block_column;
434
4.13M
  int ci, block_row, block_rows, access_rows, image_block_row,
435
4.13M
    image_block_rows;
436
4.13M
  JBLOCKARRAY buffer;
437
4.13M
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
4.13M
  JBLOCKROW next_block_row, next_next_block_row;
439
4.13M
  _JSAMPARRAY output_ptr;
440
4.13M
  JDIMENSION output_col;
441
4.13M
  jpeg_component_info *compptr;
442
4.13M
  _inverse_DCT_method_ptr inverse_DCT;
443
4.13M
  boolean change_dc;
444
4.13M
  JCOEF *workspace;
445
4.13M
  int *coef_bits;
446
4.13M
  JQUANT_TBL *quanttbl;
447
4.13M
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
4.13M
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
4.13M
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
4.13M
      DC25;
451
4.13M
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
4.13M
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
4.13M
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
4.13M
         !cinfo->inputctl->eoi_reached) {
459
0
    if (cinfo->input_scan_number == cinfo->output_scan_number) {
460
      /* If input is working on current scan, we ordinarily want it to
461
       * have completed the current row.  But if input scan is DC,
462
       * we want it to keep two rows ahead so that next two block rows' DC
463
       * values are up to date.
464
       */
465
0
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
466
0
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
467
0
        break;
468
0
    }
469
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
470
0
      return JPEG_SUSPENDED;
471
0
  }
472
473
  /* OK, output from the virtual arrays. */
474
12.0M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
7.90M
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
7.90M
    if (!compptr->component_needed)
478
0
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
7.90M
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
7.85M
      block_rows = compptr->v_samp_factor;
482
7.85M
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
7.85M
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
20.5k
      block_rows = compptr->v_samp_factor;
485
20.5k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
25.4k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
25.4k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
25.4k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
25.4k
      access_rows = block_rows; /* this iMCU row only */
491
25.4k
    }
492
    /* Align the virtual buffer for this component. */
493
7.90M
    if (cinfo->output_iMCU_row > 1) {
494
7.85M
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
7.85M
      buffer = (*cinfo->mem->access_virt_barray)
496
7.85M
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
7.85M
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
7.85M
         (JDIMENSION)access_rows, FALSE);
499
7.85M
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
7.85M
    } else if (cinfo->output_iMCU_row > 0) {
501
20.5k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
20.5k
      buffer = (*cinfo->mem->access_virt_barray)
503
20.5k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
20.5k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
20.5k
         (JDIMENSION)access_rows, FALSE);
506
20.5k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
25.4k
    } else {
508
25.4k
      buffer = (*cinfo->mem->access_virt_barray)
509
25.4k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
25.4k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
25.4k
    }
512
    /* Fetch component-dependent info.
513
     * If the current scan is incomplete, then we use the component-dependent
514
     * info from the previous scan.
515
     */
516
7.90M
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
0
      coef_bits =
518
0
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
7.90M
    else
520
7.90M
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
7.90M
    change_dc =
524
7.90M
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
7.90M
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
7.90M
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
7.90M
    quanttbl = compptr->quant_table;
529
7.90M
    Q00 = quanttbl->quantval[0];
530
7.90M
    Q01 = quanttbl->quantval[Q01_POS];
531
7.90M
    Q10 = quanttbl->quantval[Q10_POS];
532
7.90M
    Q20 = quanttbl->quantval[Q20_POS];
533
7.90M
    Q11 = quanttbl->quantval[Q11_POS];
534
7.90M
    Q02 = quanttbl->quantval[Q02_POS];
535
7.90M
    if (change_dc) {
536
6.04M
      Q03 = quanttbl->quantval[Q03_POS];
537
6.04M
      Q12 = quanttbl->quantval[Q12_POS];
538
6.04M
      Q21 = quanttbl->quantval[Q21_POS];
539
6.04M
      Q30 = quanttbl->quantval[Q30_POS];
540
6.04M
    }
541
7.90M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
7.90M
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
7.90M
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
20.0M
    for (block_row = 0; block_row < block_rows; block_row++) {
546
12.1M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
12.1M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
12.1M
      if (image_block_row > 0)
550
12.1M
        prev_block_row =
551
12.1M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
25.4k
      else
553
25.4k
        prev_block_row = buffer_ptr;
554
555
12.1M
      if (image_block_row > 1)
556
12.0M
        prev_prev_block_row =
557
12.0M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
46.7k
      else
559
46.7k
        prev_prev_block_row = prev_block_row;
560
561
12.1M
      if (image_block_row < image_block_rows - 1)
562
12.1M
        next_block_row =
563
12.1M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
25.4k
      else
565
25.4k
        next_block_row = buffer_ptr;
566
567
12.1M
      if (image_block_row < image_block_rows - 2)
568
12.0M
        next_next_block_row =
569
12.0M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
41.6k
      else
571
41.6k
        next_next_block_row = next_block_row;
572
573
      /* We fetch the surrounding DC values using a sliding-register approach.
574
       * Initialize all 25 here so as to do the right thing on narrow pics.
575
       */
576
12.1M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
12.1M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
12.1M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
12.1M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
12.1M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
12.1M
      output_col = 0;
582
12.1M
      last_block_column = compptr->width_in_blocks - 1;
583
12.1M
      for (block_num = cinfo->master->first_MCU_col[ci];
584
218M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
206M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
206M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
206M
            block_num < last_block_column) {
590
9.15M
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
9.15M
          DC09 = DC10 = (int)prev_block_row[1][0];
592
9.15M
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
9.15M
          DC19 = DC20 = (int)next_block_row[1][0];
594
9.15M
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
9.15M
        }
596
206M
        if (block_num + 1 < last_block_column) {
597
185M
          DC05 = (int)prev_prev_block_row[2][0];
598
185M
          DC10 = (int)prev_block_row[2][0];
599
185M
          DC15 = (int)buffer_ptr[2][0];
600
185M
          DC20 = (int)next_block_row[2][0];
601
185M
          DC25 = (int)next_next_block_row[2][0];
602
185M
        }
603
        /* If DC interpolation is enabled, compute coefficient estimates using
604
         * a Gaussian-like kernel, keeping the averages of the DC values.
605
         *
606
         * If DC interpolation is disabled, compute coefficient estimates using
607
         * an algorithm similar to the one described in Section K.8 of the JPEG
608
         * standard, except applied to a 5x5 window rather than a 3x3 window.
609
         *
610
         * An estimate is applied only if the coefficient is still zero and is
611
         * not known to be fully accurate.
612
         */
613
        /* AC01 */
614
206M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
195M
          num = Q00 * (change_dc ?
616
160M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
160M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
160M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
160M
                 DC21 - DC22 + DC24 + DC25) :
620
195M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
195M
          if (num >= 0) {
622
124M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
124M
            if (Al > 0 && pred >= (1 << Al))
624
4.98M
              pred = (1 << Al) - 1;
625
124M
          } else {
626
70.7M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
70.7M
            if (Al > 0 && pred >= (1 << Al))
628
3.10M
              pred = (1 << Al) - 1;
629
70.7M
            pred = -pred;
630
70.7M
          }
631
195M
          workspace[1] = (JCOEF)pred;
632
195M
        }
633
        /* AC10 */
634
206M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
196M
          num = Q00 * (change_dc ?
636
160M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
160M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
160M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
160M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
196M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
196M
          if (num >= 0) {
642
128M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
128M
            if (Al > 0 && pred >= (1 << Al))
644
8.80M
              pred = (1 << Al) - 1;
645
128M
          } else {
646
68.1M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
68.1M
            if (Al > 0 && pred >= (1 << Al))
648
7.41M
              pred = (1 << Al) - 1;
649
68.1M
            pred = -pred;
650
68.1M
          }
651
196M
          workspace[8] = (JCOEF)pred;
652
196M
        }
653
        /* AC20 */
654
206M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
196M
          num = Q00 * (change_dc ?
656
160M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
160M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
196M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
196M
          if (num >= 0) {
660
120M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
120M
            if (Al > 0 && pred >= (1 << Al))
662
6.85M
              pred = (1 << Al) - 1;
663
120M
          } else {
664
75.8M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
75.8M
            if (Al > 0 && pred >= (1 << Al))
666
6.98M
              pred = (1 << Al) - 1;
667
75.8M
            pred = -pred;
668
75.8M
          }
669
196M
          workspace[16] = (JCOEF)pred;
670
196M
        }
671
        /* AC11 */
672
206M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
197M
          num = Q00 * (change_dc ?
674
160M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
160M
                 9 * DC19 + DC21 - DC25) :
676
197M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
36.6M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
197M
          if (num >= 0) {
679
155M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
155M
            if (Al > 0 && pred >= (1 << Al))
681
2.86M
              pred = (1 << Al) - 1;
682
155M
          } else {
683
41.0M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
41.0M
            if (Al > 0 && pred >= (1 << Al))
685
2.98M
              pred = (1 << Al) - 1;
686
41.0M
            pred = -pred;
687
41.0M
          }
688
197M
          workspace[9] = (JCOEF)pred;
689
197M
        }
690
        /* AC02 */
691
206M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
195M
          num = Q00 * (change_dc ?
693
160M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
160M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
195M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
195M
          if (num >= 0) {
697
120M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
120M
            if (Al > 0 && pred >= (1 << Al))
699
3.43M
              pred = (1 << Al) - 1;
700
120M
          } else {
701
75.3M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
75.3M
            if (Al > 0 && pred >= (1 << Al))
703
3.37M
              pred = (1 << Al) - 1;
704
75.3M
            pred = -pred;
705
75.3M
          }
706
195M
          workspace[2] = (JCOEF)pred;
707
195M
        }
708
206M
        if (change_dc) {
709
          /* AC03 */
710
160M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
160M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
160M
            if (num >= 0) {
713
103M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
103M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
103M
            } else {
717
56.8M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
56.8M
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
56.8M
              pred = -pred;
721
56.8M
            }
722
160M
            workspace[3] = (JCOEF)pred;
723
160M
          }
724
          /* AC12 */
725
160M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
160M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
160M
            if (num >= 0) {
728
101M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
101M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
101M
            } else {
732
58.3M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
58.3M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
58.3M
              pred = -pred;
736
58.3M
            }
737
160M
            workspace[10] = (JCOEF)pred;
738
160M
          }
739
          /* AC21 */
740
160M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
160M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
160M
            if (num >= 0) {
743
98.6M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
98.6M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
98.6M
            } else {
747
61.7M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
61.7M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
61.7M
              pred = -pred;
751
61.7M
            }
752
160M
            workspace[17] = (JCOEF)pred;
753
160M
          }
754
          /* AC30 */
755
160M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
160M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
160M
            if (num >= 0) {
758
107M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
107M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
107M
            } else {
762
53.2M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
53.2M
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
53.2M
              pred = -pred;
766
53.2M
            }
767
160M
            workspace[24] = (JCOEF)pred;
768
160M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
160M
          num = Q00 *
773
160M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
160M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
160M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
160M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
160M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
160M
          if (num >= 0) {
779
79.4M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
80.9M
          } else {
781
80.9M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
80.9M
            pred = -pred;
783
80.9M
          }
784
160M
          workspace[0] = (JCOEF)pred;
785
160M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
206M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
206M
                        output_col);
790
        /* Advance for next column */
791
206M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
206M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
206M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
206M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
206M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
206M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
206M
          prev_prev_block_row++, next_next_block_row++;
798
206M
        output_col += compptr->_DCT_scaled_size;
799
206M
      }
800
12.1M
      output_ptr += compptr->_DCT_scaled_size;
801
12.1M
    }
802
7.90M
  }
803
804
4.13M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
4.12M
    return JPEG_ROW_COMPLETED;
806
9.49k
  return JPEG_SCAN_COMPLETED;
807
4.13M
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
430
4.13M
{
431
4.13M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
4.13M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
4.13M
  JDIMENSION block_num, last_block_column;
434
4.13M
  int ci, block_row, block_rows, access_rows, image_block_row,
435
4.13M
    image_block_rows;
436
4.13M
  JBLOCKARRAY buffer;
437
4.13M
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
4.13M
  JBLOCKROW next_block_row, next_next_block_row;
439
4.13M
  _JSAMPARRAY output_ptr;
440
4.13M
  JDIMENSION output_col;
441
4.13M
  jpeg_component_info *compptr;
442
4.13M
  _inverse_DCT_method_ptr inverse_DCT;
443
4.13M
  boolean change_dc;
444
4.13M
  JCOEF *workspace;
445
4.13M
  int *coef_bits;
446
4.13M
  JQUANT_TBL *quanttbl;
447
4.13M
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
4.13M
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
4.13M
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
4.13M
      DC25;
451
4.13M
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
4.13M
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
4.13M
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
4.13M
         !cinfo->inputctl->eoi_reached) {
459
0
    if (cinfo->input_scan_number == cinfo->output_scan_number) {
460
      /* If input is working on current scan, we ordinarily want it to
461
       * have completed the current row.  But if input scan is DC,
462
       * we want it to keep two rows ahead so that next two block rows' DC
463
       * values are up to date.
464
       */
465
0
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
466
0
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
467
0
        break;
468
0
    }
469
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
470
0
      return JPEG_SUSPENDED;
471
0
  }
472
473
  /* OK, output from the virtual arrays. */
474
12.0M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
7.90M
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
7.90M
    if (!compptr->component_needed)
478
0
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
7.90M
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
7.85M
      block_rows = compptr->v_samp_factor;
482
7.85M
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
7.85M
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
20.5k
      block_rows = compptr->v_samp_factor;
485
20.5k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
25.4k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
25.4k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
25.4k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
25.4k
      access_rows = block_rows; /* this iMCU row only */
491
25.4k
    }
492
    /* Align the virtual buffer for this component. */
493
7.90M
    if (cinfo->output_iMCU_row > 1) {
494
7.85M
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
7.85M
      buffer = (*cinfo->mem->access_virt_barray)
496
7.85M
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
7.85M
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
7.85M
         (JDIMENSION)access_rows, FALSE);
499
7.85M
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
7.85M
    } else if (cinfo->output_iMCU_row > 0) {
501
20.5k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
20.5k
      buffer = (*cinfo->mem->access_virt_barray)
503
20.5k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
20.5k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
20.5k
         (JDIMENSION)access_rows, FALSE);
506
20.5k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
25.4k
    } else {
508
25.4k
      buffer = (*cinfo->mem->access_virt_barray)
509
25.4k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
25.4k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
25.4k
    }
512
    /* Fetch component-dependent info.
513
     * If the current scan is incomplete, then we use the component-dependent
514
     * info from the previous scan.
515
     */
516
7.90M
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
0
      coef_bits =
518
0
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
7.90M
    else
520
7.90M
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
7.90M
    change_dc =
524
7.90M
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
7.90M
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
7.90M
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
7.90M
    quanttbl = compptr->quant_table;
529
7.90M
    Q00 = quanttbl->quantval[0];
530
7.90M
    Q01 = quanttbl->quantval[Q01_POS];
531
7.90M
    Q10 = quanttbl->quantval[Q10_POS];
532
7.90M
    Q20 = quanttbl->quantval[Q20_POS];
533
7.90M
    Q11 = quanttbl->quantval[Q11_POS];
534
7.90M
    Q02 = quanttbl->quantval[Q02_POS];
535
7.90M
    if (change_dc) {
536
6.04M
      Q03 = quanttbl->quantval[Q03_POS];
537
6.04M
      Q12 = quanttbl->quantval[Q12_POS];
538
6.04M
      Q21 = quanttbl->quantval[Q21_POS];
539
6.04M
      Q30 = quanttbl->quantval[Q30_POS];
540
6.04M
    }
541
7.90M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
7.90M
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
7.90M
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
20.0M
    for (block_row = 0; block_row < block_rows; block_row++) {
546
12.1M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
12.1M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
12.1M
      if (image_block_row > 0)
550
12.1M
        prev_block_row =
551
12.1M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
25.4k
      else
553
25.4k
        prev_block_row = buffer_ptr;
554
555
12.1M
      if (image_block_row > 1)
556
12.0M
        prev_prev_block_row =
557
12.0M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
46.7k
      else
559
46.7k
        prev_prev_block_row = prev_block_row;
560
561
12.1M
      if (image_block_row < image_block_rows - 1)
562
12.1M
        next_block_row =
563
12.1M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
25.4k
      else
565
25.4k
        next_block_row = buffer_ptr;
566
567
12.1M
      if (image_block_row < image_block_rows - 2)
568
12.0M
        next_next_block_row =
569
12.0M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
41.6k
      else
571
41.6k
        next_next_block_row = next_block_row;
572
573
      /* We fetch the surrounding DC values using a sliding-register approach.
574
       * Initialize all 25 here so as to do the right thing on narrow pics.
575
       */
576
12.1M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
12.1M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
12.1M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
12.1M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
12.1M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
12.1M
      output_col = 0;
582
12.1M
      last_block_column = compptr->width_in_blocks - 1;
583
12.1M
      for (block_num = cinfo->master->first_MCU_col[ci];
584
218M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
206M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
206M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
206M
            block_num < last_block_column) {
590
9.15M
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
9.15M
          DC09 = DC10 = (int)prev_block_row[1][0];
592
9.15M
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
9.15M
          DC19 = DC20 = (int)next_block_row[1][0];
594
9.15M
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
9.15M
        }
596
206M
        if (block_num + 1 < last_block_column) {
597
185M
          DC05 = (int)prev_prev_block_row[2][0];
598
185M
          DC10 = (int)prev_block_row[2][0];
599
185M
          DC15 = (int)buffer_ptr[2][0];
600
185M
          DC20 = (int)next_block_row[2][0];
601
185M
          DC25 = (int)next_next_block_row[2][0];
602
185M
        }
603
        /* If DC interpolation is enabled, compute coefficient estimates using
604
         * a Gaussian-like kernel, keeping the averages of the DC values.
605
         *
606
         * If DC interpolation is disabled, compute coefficient estimates using
607
         * an algorithm similar to the one described in Section K.8 of the JPEG
608
         * standard, except applied to a 5x5 window rather than a 3x3 window.
609
         *
610
         * An estimate is applied only if the coefficient is still zero and is
611
         * not known to be fully accurate.
612
         */
613
        /* AC01 */
614
206M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
195M
          num = Q00 * (change_dc ?
616
160M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
160M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
160M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
160M
                 DC21 - DC22 + DC24 + DC25) :
620
195M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
195M
          if (num >= 0) {
622
124M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
124M
            if (Al > 0 && pred >= (1 << Al))
624
4.98M
              pred = (1 << Al) - 1;
625
124M
          } else {
626
70.7M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
70.7M
            if (Al > 0 && pred >= (1 << Al))
628
3.10M
              pred = (1 << Al) - 1;
629
70.7M
            pred = -pred;
630
70.7M
          }
631
195M
          workspace[1] = (JCOEF)pred;
632
195M
        }
633
        /* AC10 */
634
206M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
196M
          num = Q00 * (change_dc ?
636
160M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
160M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
160M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
160M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
196M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
196M
          if (num >= 0) {
642
128M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
128M
            if (Al > 0 && pred >= (1 << Al))
644
8.80M
              pred = (1 << Al) - 1;
645
128M
          } else {
646
68.1M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
68.1M
            if (Al > 0 && pred >= (1 << Al))
648
7.41M
              pred = (1 << Al) - 1;
649
68.1M
            pred = -pred;
650
68.1M
          }
651
196M
          workspace[8] = (JCOEF)pred;
652
196M
        }
653
        /* AC20 */
654
206M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
196M
          num = Q00 * (change_dc ?
656
160M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
160M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
196M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
196M
          if (num >= 0) {
660
120M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
120M
            if (Al > 0 && pred >= (1 << Al))
662
6.85M
              pred = (1 << Al) - 1;
663
120M
          } else {
664
75.8M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
75.8M
            if (Al > 0 && pred >= (1 << Al))
666
6.98M
              pred = (1 << Al) - 1;
667
75.8M
            pred = -pred;
668
75.8M
          }
669
196M
          workspace[16] = (JCOEF)pred;
670
196M
        }
671
        /* AC11 */
672
206M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
197M
          num = Q00 * (change_dc ?
674
160M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
160M
                 9 * DC19 + DC21 - DC25) :
676
197M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
36.6M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
197M
          if (num >= 0) {
679
155M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
155M
            if (Al > 0 && pred >= (1 << Al))
681
2.86M
              pred = (1 << Al) - 1;
682
155M
          } else {
683
41.0M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
41.0M
            if (Al > 0 && pred >= (1 << Al))
685
2.98M
              pred = (1 << Al) - 1;
686
41.0M
            pred = -pred;
687
41.0M
          }
688
197M
          workspace[9] = (JCOEF)pred;
689
197M
        }
690
        /* AC02 */
691
206M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
195M
          num = Q00 * (change_dc ?
693
160M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
160M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
195M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
195M
          if (num >= 0) {
697
120M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
120M
            if (Al > 0 && pred >= (1 << Al))
699
3.43M
              pred = (1 << Al) - 1;
700
120M
          } else {
701
75.3M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
75.3M
            if (Al > 0 && pred >= (1 << Al))
703
3.37M
              pred = (1 << Al) - 1;
704
75.3M
            pred = -pred;
705
75.3M
          }
706
195M
          workspace[2] = (JCOEF)pred;
707
195M
        }
708
206M
        if (change_dc) {
709
          /* AC03 */
710
160M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
160M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
160M
            if (num >= 0) {
713
103M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
103M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
103M
            } else {
717
56.8M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
56.8M
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
56.8M
              pred = -pred;
721
56.8M
            }
722
160M
            workspace[3] = (JCOEF)pred;
723
160M
          }
724
          /* AC12 */
725
160M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
160M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
160M
            if (num >= 0) {
728
101M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
101M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
101M
            } else {
732
58.3M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
58.3M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
58.3M
              pred = -pred;
736
58.3M
            }
737
160M
            workspace[10] = (JCOEF)pred;
738
160M
          }
739
          /* AC21 */
740
160M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
160M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
160M
            if (num >= 0) {
743
98.6M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
98.6M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
98.6M
            } else {
747
61.7M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
61.7M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
61.7M
              pred = -pred;
751
61.7M
            }
752
160M
            workspace[17] = (JCOEF)pred;
753
160M
          }
754
          /* AC30 */
755
160M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
160M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
160M
            if (num >= 0) {
758
107M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
107M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
107M
            } else {
762
53.2M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
53.2M
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
53.2M
              pred = -pred;
766
53.2M
            }
767
160M
            workspace[24] = (JCOEF)pred;
768
160M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
160M
          num = Q00 *
773
160M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
160M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
160M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
160M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
160M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
160M
          if (num >= 0) {
779
79.4M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
80.9M
          } else {
781
80.9M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
80.9M
            pred = -pred;
783
80.9M
          }
784
160M
          workspace[0] = (JCOEF)pred;
785
160M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
206M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
206M
                        output_col);
790
        /* Advance for next column */
791
206M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
206M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
206M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
206M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
206M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
206M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
206M
          prev_prev_block_row++, next_next_block_row++;
798
206M
        output_col += compptr->_DCT_scaled_size;
799
206M
      }
800
12.1M
      output_ptr += compptr->_DCT_scaled_size;
801
12.1M
    }
802
7.90M
  }
803
804
4.13M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
4.12M
    return JPEG_ROW_COMPLETED;
806
9.49k
  return JPEG_SCAN_COMPLETED;
807
4.13M
}
Unexecuted instantiation: jdcoefct-12.c:decompress_smooth_data
808
809
#endif /* BLOCK_SMOOTHING_SUPPORTED */
810
811
812
/*
813
 * Initialize coefficient buffer controller.
814
 */
815
816
GLOBAL(void)
817
_jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
818
43.6k
{
819
43.6k
  my_coef_ptr coef;
820
821
43.6k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
43.6k
  coef = (my_coef_ptr)
825
43.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
43.6k
                                sizeof(my_coef_controller));
827
43.6k
  memset(coef, 0, sizeof(my_coef_controller));
828
43.6k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
43.6k
  coef->pub.start_input_pass = start_input_pass;
830
43.6k
  coef->pub.start_output_pass = start_output_pass;
831
43.6k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
43.6k
  coef->coef_bits_latch = NULL;
833
43.6k
#endif
834
835
  /* Create the coefficient buffer. */
836
43.6k
  if (need_full_buffer) {
837
26.4k
#ifdef D_MULTISCAN_FILES_SUPPORTED
838
    /* Allocate a full-image virtual array for each component, */
839
    /* padded to a multiple of samp_factor DCT blocks in each direction. */
840
    /* Note we ask for a pre-zeroed array. */
841
26.4k
    int ci, access_rows;
842
26.4k
    jpeg_component_info *compptr;
843
844
98.3k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
71.9k
         ci++, compptr++) {
846
71.9k
      access_rows = compptr->v_samp_factor;
847
71.9k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
71.9k
      if (cinfo->progressive_mode)
850
69.8k
        access_rows *= 5;
851
71.9k
#endif
852
71.9k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
71.9k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
71.9k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
71.9k
                               (long)compptr->h_samp_factor),
856
71.9k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
71.9k
                               (long)compptr->v_samp_factor),
858
71.9k
         (JDIMENSION)access_rows);
859
71.9k
    }
860
26.4k
    coef->pub.consume_data = consume_data;
861
26.4k
    coef->pub._decompress_data = decompress_data;
862
26.4k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
26.4k
  } else {
867
    /* We only need a single-MCU buffer. */
868
17.2k
    JBLOCKROW buffer;
869
17.2k
    int i;
870
871
17.2k
    buffer = (JBLOCKROW)
872
17.2k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
17.2k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
189k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
172k
      coef->MCU_buffer[i] = buffer + i;
876
172k
    }
877
17.2k
    coef->pub.consume_data = dummy_consume_data;
878
17.2k
    coef->pub._decompress_data = decompress_onepass;
879
17.2k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
17.2k
  }
881
882
  /* Allocate the workspace buffer */
883
43.6k
  coef->workspace = (JCOEF *)
884
43.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
43.6k
                                sizeof(JCOEF) * DCTSIZE2);
886
43.6k
}
jinit_d_coef_controller
Line
Count
Source
818
39.7k
{
819
39.7k
  my_coef_ptr coef;
820
821
39.7k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
39.7k
  coef = (my_coef_ptr)
825
39.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
39.7k
                                sizeof(my_coef_controller));
827
39.7k
  memset(coef, 0, sizeof(my_coef_controller));
828
39.7k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
39.7k
  coef->pub.start_input_pass = start_input_pass;
830
39.7k
  coef->pub.start_output_pass = start_output_pass;
831
39.7k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
39.7k
  coef->coef_bits_latch = NULL;
833
39.7k
#endif
834
835
  /* Create the coefficient buffer. */
836
39.7k
  if (need_full_buffer) {
837
22.7k
#ifdef D_MULTISCAN_FILES_SUPPORTED
838
    /* Allocate a full-image virtual array for each component, */
839
    /* padded to a multiple of samp_factor DCT blocks in each direction. */
840
    /* Note we ask for a pre-zeroed array. */
841
22.7k
    int ci, access_rows;
842
22.7k
    jpeg_component_info *compptr;
843
844
84.6k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
61.8k
         ci++, compptr++) {
846
61.8k
      access_rows = compptr->v_samp_factor;
847
61.8k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
61.8k
      if (cinfo->progressive_mode)
850
60.2k
        access_rows *= 5;
851
61.8k
#endif
852
61.8k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
61.8k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
61.8k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
61.8k
                               (long)compptr->h_samp_factor),
856
61.8k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
61.8k
                               (long)compptr->v_samp_factor),
858
61.8k
         (JDIMENSION)access_rows);
859
61.8k
    }
860
22.7k
    coef->pub.consume_data = consume_data;
861
22.7k
    coef->pub._decompress_data = decompress_data;
862
22.7k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
22.7k
  } else {
867
    /* We only need a single-MCU buffer. */
868
16.9k
    JBLOCKROW buffer;
869
16.9k
    int i;
870
871
16.9k
    buffer = (JBLOCKROW)
872
16.9k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
16.9k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
186k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
169k
      coef->MCU_buffer[i] = buffer + i;
876
169k
    }
877
16.9k
    coef->pub.consume_data = dummy_consume_data;
878
16.9k
    coef->pub._decompress_data = decompress_onepass;
879
16.9k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
16.9k
  }
881
882
  /* Allocate the workspace buffer */
883
39.7k
  coef->workspace = (JCOEF *)
884
39.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
39.7k
                                sizeof(JCOEF) * DCTSIZE2);
886
39.7k
}
j12init_d_coef_controller
Line
Count
Source
818
3.88k
{
819
3.88k
  my_coef_ptr coef;
820
821
3.88k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
3.88k
  coef = (my_coef_ptr)
825
3.88k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
3.88k
                                sizeof(my_coef_controller));
827
3.88k
  memset(coef, 0, sizeof(my_coef_controller));
828
3.88k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
3.88k
  coef->pub.start_input_pass = start_input_pass;
830
3.88k
  coef->pub.start_output_pass = start_output_pass;
831
3.88k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
3.88k
  coef->coef_bits_latch = NULL;
833
3.88k
#endif
834
835
  /* Create the coefficient buffer. */
836
3.88k
  if (need_full_buffer) {
837
3.64k
#ifdef D_MULTISCAN_FILES_SUPPORTED
838
    /* Allocate a full-image virtual array for each component, */
839
    /* padded to a multiple of samp_factor DCT blocks in each direction. */
840
    /* Note we ask for a pre-zeroed array. */
841
3.64k
    int ci, access_rows;
842
3.64k
    jpeg_component_info *compptr;
843
844
13.7k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
10.0k
         ci++, compptr++) {
846
10.0k
      access_rows = compptr->v_samp_factor;
847
10.0k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
10.0k
      if (cinfo->progressive_mode)
850
9.54k
        access_rows *= 5;
851
10.0k
#endif
852
10.0k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
10.0k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
10.0k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
10.0k
                               (long)compptr->h_samp_factor),
856
10.0k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
10.0k
                               (long)compptr->v_samp_factor),
858
10.0k
         (JDIMENSION)access_rows);
859
10.0k
    }
860
3.64k
    coef->pub.consume_data = consume_data;
861
3.64k
    coef->pub._decompress_data = decompress_data;
862
3.64k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
3.64k
  } else {
867
    /* We only need a single-MCU buffer. */
868
235
    JBLOCKROW buffer;
869
235
    int i;
870
871
235
    buffer = (JBLOCKROW)
872
235
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
235
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
2.58k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
2.35k
      coef->MCU_buffer[i] = buffer + i;
876
2.35k
    }
877
235
    coef->pub.consume_data = dummy_consume_data;
878
235
    coef->pub._decompress_data = decompress_onepass;
879
235
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
235
  }
881
882
  /* Allocate the workspace buffer */
883
3.88k
  coef->workspace = (JCOEF *)
884
3.88k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
3.88k
                                sizeof(JCOEF) * DCTSIZE2);
886
3.88k
}