Coverage Report

Created: 2025-08-03 06:58

/src/libjpeg-turbo.main/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
21.3k
{
48
21.3k
  cinfo->input_iMCU_row = 0;
49
21.3k
  start_iMCU_row(cinfo);
50
21.3k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
47
19.9k
{
48
19.9k
  cinfo->input_iMCU_row = 0;
49
19.9k
  start_iMCU_row(cinfo);
50
19.9k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
47
1.41k
{
48
1.41k
  cinfo->input_iMCU_row = 0;
49
1.41k
  start_iMCU_row(cinfo);
50
1.41k
}
51
52
53
/*
54
 * Initialize for an output processing pass.
55
 */
56
57
METHODDEF(void)
58
start_output_pass(j_decompress_ptr cinfo)
59
3.10k
{
60
3.10k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
3.10k
  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
3.10k
  if (coef->pub.coef_arrays != NULL) {
65
2.40k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
662
      coef->pub._decompress_data = decompress_smooth_data;
67
1.74k
    else
68
1.74k
      coef->pub._decompress_data = decompress_data;
69
2.40k
  }
70
3.10k
#endif
71
3.10k
  cinfo->output_iMCU_row = 0;
72
3.10k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
59
2.79k
{
60
2.79k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
2.79k
  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
2.79k
  if (coef->pub.coef_arrays != NULL) {
65
2.11k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
619
      coef->pub._decompress_data = decompress_smooth_data;
67
1.49k
    else
68
1.49k
      coef->pub._decompress_data = decompress_data;
69
2.11k
  }
70
2.79k
#endif
71
2.79k
  cinfo->output_iMCU_row = 0;
72
2.79k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
59
311
{
60
311
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
311
  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
311
  if (coef->pub.coef_arrays != NULL) {
65
296
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
43
      coef->pub._decompress_data = decompress_smooth_data;
67
253
    else
68
253
      coef->pub._decompress_data = decompress_data;
69
296
  }
70
311
#endif
71
311
  cinfo->output_iMCU_row = 0;
72
311
}
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
130k
{
88
130k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
130k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
130k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
130k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
130k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
130k
  _JSAMPARRAY output_ptr;
94
130k
  JDIMENSION start_col, output_col;
95
130k
  jpeg_component_info *compptr;
96
130k
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
327k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
196k
       yoffset++) {
101
3.62M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
3.43M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
3.43M
      jzero_far((void *)coef->MCU_buffer[0],
105
3.43M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
3.43M
      if (!cinfo->entropy->insufficient_data)
107
570k
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
3.43M
      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
3.43M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
3.43M
          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
3.43M
        blkn = 0;               /* index of current DCT block within MCU */
126
6.91M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
3.48M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
3.48M
          if (!compptr->component_needed) {
130
0
            blkn += compptr->MCU_blocks;
131
0
            continue;
132
0
          }
133
3.48M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
3.48M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
3.28M
                         compptr->MCU_width : compptr->last_col_width;
136
3.48M
          output_ptr = output_buf[compptr->component_index] +
137
3.48M
                       yoffset * compptr->_DCT_scaled_size;
138
3.48M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
3.48M
                      compptr->MCU_sample_width;
140
7.02M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
3.53M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
3.53M
                yoffset + yindex < compptr->last_row_height) {
143
3.53M
              output_col = start_col;
144
7.10M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
3.57M
                (*inverse_DCT) (cinfo, compptr,
146
3.57M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
3.57M
                                output_ptr, output_col);
148
3.57M
                output_col += compptr->_DCT_scaled_size;
149
3.57M
              }
150
3.53M
            }
151
3.53M
            blkn += compptr->MCU_width;
152
3.53M
            output_ptr += compptr->_DCT_scaled_size;
153
3.53M
          }
154
3.48M
        }
155
3.43M
      }
156
3.43M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
196k
    coef->MCU_ctr = 0;
159
196k
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
130k
  cinfo->output_iMCU_row++;
162
130k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
129k
    start_iMCU_row(cinfo);
164
129k
    return JPEG_ROW_COMPLETED;
165
129k
  }
166
  /* Completed the scan */
167
681
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
681
  return JPEG_SCAN_COMPLETED;
169
130k
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
87
130k
{
88
130k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
130k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
130k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
130k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
130k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
130k
  _JSAMPARRAY output_ptr;
94
130k
  JDIMENSION start_col, output_col;
95
130k
  jpeg_component_info *compptr;
96
130k
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
327k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
196k
       yoffset++) {
101
3.62M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
3.43M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
3.43M
      jzero_far((void *)coef->MCU_buffer[0],
105
3.43M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
3.43M
      if (!cinfo->entropy->insufficient_data)
107
570k
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
3.43M
      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
3.43M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
3.43M
          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
3.43M
        blkn = 0;               /* index of current DCT block within MCU */
126
6.91M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
3.48M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
3.48M
          if (!compptr->component_needed) {
130
0
            blkn += compptr->MCU_blocks;
131
0
            continue;
132
0
          }
133
3.48M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
3.48M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
3.28M
                         compptr->MCU_width : compptr->last_col_width;
136
3.48M
          output_ptr = output_buf[compptr->component_index] +
137
3.48M
                       yoffset * compptr->_DCT_scaled_size;
138
3.48M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
3.48M
                      compptr->MCU_sample_width;
140
7.02M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
3.53M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
3.53M
                yoffset + yindex < compptr->last_row_height) {
143
3.53M
              output_col = start_col;
144
7.10M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
3.57M
                (*inverse_DCT) (cinfo, compptr,
146
3.57M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
3.57M
                                output_ptr, output_col);
148
3.57M
                output_col += compptr->_DCT_scaled_size;
149
3.57M
              }
150
3.53M
            }
151
3.53M
            blkn += compptr->MCU_width;
152
3.53M
            output_ptr += compptr->_DCT_scaled_size;
153
3.53M
          }
154
3.48M
        }
155
3.43M
      }
156
3.43M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
196k
    coef->MCU_ctr = 0;
159
196k
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
130k
  cinfo->output_iMCU_row++;
162
130k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
129k
    start_iMCU_row(cinfo);
164
129k
    return JPEG_ROW_COMPLETED;
165
129k
  }
166
  /* Completed the scan */
167
681
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
681
  return JPEG_SCAN_COMPLETED;
169
130k
}
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
3.64M
{
195
3.64M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
3.64M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
3.64M
  int blkn, ci, xindex, yindex, yoffset;
198
3.64M
  JDIMENSION start_col;
199
3.64M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
3.64M
  JBLOCKROW buffer_ptr;
201
3.64M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
7.55M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
3.91M
    compptr = cinfo->cur_comp_info[ci];
206
3.91M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
3.91M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
3.91M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
3.91M
       (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
3.91M
  }
215
216
  /* Loop to process one whole iMCU row */
217
7.68M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
4.04M
       yoffset++) {
219
86.0M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
81.9M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
81.9M
      blkn = 0;                 /* index of current DCT block within MCU */
223
171M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
89.7M
        compptr = cinfo->cur_comp_info[ci];
225
89.7M
        start_col = MCU_col_num * compptr->MCU_width;
226
189M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
100M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
213M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
113M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
113M
          }
231
100M
        }
232
89.7M
      }
233
81.9M
      if (!cinfo->entropy->insufficient_data)
234
40.6M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
81.9M
      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
81.9M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
4.04M
    coef->MCU_ctr = 0;
245
4.04M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
3.64M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
3.62M
    start_iMCU_row(cinfo);
249
3.62M
    return JPEG_ROW_COMPLETED;
250
3.62M
  }
251
  /* Completed the scan */
252
19.6k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
19.6k
  return JPEG_SCAN_COMPLETED;
254
3.64M
}
jdcoefct-8.c:consume_data
Line
Count
Source
194
2.82M
{
195
2.82M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
2.82M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
2.82M
  int blkn, ci, xindex, yindex, yoffset;
198
2.82M
  JDIMENSION start_col;
199
2.82M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
2.82M
  JBLOCKROW buffer_ptr;
201
2.82M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
5.89M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
3.07M
    compptr = cinfo->cur_comp_info[ci];
206
3.07M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
3.07M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
3.07M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
3.07M
       (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
3.07M
  }
215
216
  /* Loop to process one whole iMCU row */
217
6.01M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
3.19M
       yoffset++) {
219
79.3M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
76.1M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
76.1M
      blkn = 0;                 /* index of current DCT block within MCU */
223
159M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
83.4M
        compptr = cinfo->cur_comp_info[ci];
225
83.4M
        start_col = MCU_col_num * compptr->MCU_width;
226
177M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
93.7M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
200M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
107M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
107M
          }
231
93.7M
        }
232
83.4M
      }
233
76.1M
      if (!cinfo->entropy->insufficient_data)
234
38.0M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
76.1M
      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
76.1M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
3.19M
    coef->MCU_ctr = 0;
245
3.19M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
2.82M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
2.80M
    start_iMCU_row(cinfo);
249
2.80M
    return JPEG_ROW_COMPLETED;
250
2.80M
  }
251
  /* Completed the scan */
252
18.2k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
18.2k
  return JPEG_SCAN_COMPLETED;
254
2.82M
}
jdcoefct-12.c:consume_data
Line
Count
Source
194
821k
{
195
821k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
821k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
821k
  int blkn, ci, xindex, yindex, yoffset;
198
821k
  JDIMENSION start_col;
199
821k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
821k
  JBLOCKROW buffer_ptr;
201
821k
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
1.66M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
840k
    compptr = cinfo->cur_comp_info[ci];
206
840k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
840k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
840k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
840k
       (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
840k
  }
215
216
  /* Loop to process one whole iMCU row */
217
1.67M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
851k
       yoffset++) {
219
6.69M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
5.84M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
5.84M
      blkn = 0;                 /* index of current DCT block within MCU */
223
12.1M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
6.26M
        compptr = cinfo->cur_comp_info[ci];
225
6.26M
        start_col = MCU_col_num * compptr->MCU_width;
226
12.7M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
6.47M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
13.2M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
6.73M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
6.73M
          }
231
6.47M
        }
232
6.26M
      }
233
5.84M
      if (!cinfo->entropy->insufficient_data)
234
2.56M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
5.84M
      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
5.84M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
851k
    coef->MCU_ctr = 0;
245
851k
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
821k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
820k
    start_iMCU_row(cinfo);
249
820k
    return JPEG_ROW_COMPLETED;
250
820k
  }
251
  /* Completed the scan */
252
1.39k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
1.39k
  return JPEG_SCAN_COMPLETED;
254
821k
}
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
580k
{
268
580k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
580k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
580k
  JDIMENSION block_num;
271
580k
  int ci, block_row, block_rows;
272
580k
  JBLOCKARRAY buffer;
273
580k
  JBLOCKROW buffer_ptr;
274
580k
  _JSAMPARRAY output_ptr;
275
580k
  JDIMENSION output_col;
276
580k
  jpeg_component_info *compptr;
277
580k
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
580k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
580k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
580k
          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
1.82M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
1.24M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
1.24M
    if (!compptr->component_needed)
292
0
      continue;
293
    /* Align the virtual buffer for this component. */
294
1.24M
    buffer = (*cinfo->mem->access_virt_barray)
295
1.24M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
1.24M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
1.24M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
1.24M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
1.24M
      block_rows = compptr->v_samp_factor;
301
3.07k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
3.07k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
3.07k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
3.07k
    }
306
1.24M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
1.24M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
2.68M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
1.43M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
1.43M
      output_col = 0;
312
1.43M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
14.4M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
13.0M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
13.0M
                        output_col);
316
13.0M
        buffer_ptr++;
317
13.0M
        output_col += compptr->_DCT_scaled_size;
318
13.0M
      }
319
1.43M
      output_ptr += compptr->_DCT_scaled_size;
320
1.43M
    }
321
1.24M
  }
322
323
580k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
579k
    return JPEG_ROW_COMPLETED;
325
1.49k
  return JPEG_SCAN_COMPLETED;
326
580k
}
jdcoefct-8.c:decompress_data
Line
Count
Source
267
580k
{
268
580k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
580k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
580k
  JDIMENSION block_num;
271
580k
  int ci, block_row, block_rows;
272
580k
  JBLOCKARRAY buffer;
273
580k
  JBLOCKROW buffer_ptr;
274
580k
  _JSAMPARRAY output_ptr;
275
580k
  JDIMENSION output_col;
276
580k
  jpeg_component_info *compptr;
277
580k
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
580k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
580k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
580k
          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
1.82M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
1.24M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
1.24M
    if (!compptr->component_needed)
292
0
      continue;
293
    /* Align the virtual buffer for this component. */
294
1.24M
    buffer = (*cinfo->mem->access_virt_barray)
295
1.24M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
1.24M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
1.24M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
1.24M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
1.24M
      block_rows = compptr->v_samp_factor;
301
3.07k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
3.07k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
3.07k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
3.07k
    }
306
1.24M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
1.24M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
2.68M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
1.43M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
1.43M
      output_col = 0;
312
1.43M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
14.4M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
13.0M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
13.0M
                        output_col);
316
13.0M
        buffer_ptr++;
317
13.0M
        output_col += compptr->_DCT_scaled_size;
318
13.0M
      }
319
1.43M
      output_ptr += compptr->_DCT_scaled_size;
320
1.43M
    }
321
1.24M
  }
322
323
580k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
579k
    return JPEG_ROW_COMPLETED;
325
1.49k
  return JPEG_SCAN_COMPLETED;
326
580k
}
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
391k
#define Q01_POS  1
342
391k
#define Q10_POS  8
343
391k
#define Q20_POS  16
344
391k
#define Q11_POS  9
345
391k
#define Q02_POS  2
346
308k
#define Q03_POS  3
347
308k
#define Q12_POS  10
348
308k
#define Q21_POS  17
349
308k
#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
2.40k
{
362
2.40k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
2.40k
  boolean smoothing_useful = FALSE;
364
2.40k
  int ci, coefi;
365
2.40k
  jpeg_component_info *compptr;
366
2.40k
  JQUANT_TBL *qtable;
367
2.40k
  int *coef_bits, *prev_coef_bits;
368
2.40k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
2.40k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
440
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
1.96k
  if (coef->coef_bits_latch == NULL)
375
1.96k
    coef->coef_bits_latch = (int *)
376
1.96k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
1.96k
                                  cinfo->num_components * 2 *
378
1.96k
                                  (SAVED_COEFS * sizeof(int)));
379
1.96k
  coef_bits_latch = coef->coef_bits_latch;
380
1.96k
  prev_coef_bits_latch =
381
1.96k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
2.88k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
2.21k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
2.21k
    if ((qtable = compptr->quant_table) == NULL)
387
283
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
1.93k
    if (qtable->quantval[0] == 0 ||
390
1.93k
        qtable->quantval[Q01_POS] == 0 ||
391
1.93k
        qtable->quantval[Q10_POS] == 0 ||
392
1.93k
        qtable->quantval[Q20_POS] == 0 ||
393
1.93k
        qtable->quantval[Q11_POS] == 0 ||
394
1.93k
        qtable->quantval[Q02_POS] == 0 ||
395
1.93k
        qtable->quantval[Q03_POS] == 0 ||
396
1.93k
        qtable->quantval[Q12_POS] == 0 ||
397
1.93k
        qtable->quantval[Q21_POS] == 0 ||
398
1.93k
        qtable->quantval[Q30_POS] == 0)
399
918
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
1.01k
    coef_bits = cinfo->coef_bits[ci];
402
1.01k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
1.01k
    if (coef_bits[0] < 0)
404
95
      return FALSE;
405
917
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
9.17k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
8.25k
      if (cinfo->input_scan_number > 1)
409
4.32k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
3.92k
      else
411
3.92k
        prev_coef_bits_latch[coefi] = -1;
412
8.25k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
8.25k
      if (coef_bits[coefi] != 0)
414
7.79k
        smoothing_useful = TRUE;
415
8.25k
    }
416
917
    coef_bits_latch += SAVED_COEFS;
417
917
    prev_coef_bits_latch += SAVED_COEFS;
418
917
  }
419
420
673
  return smoothing_useful;
421
1.96k
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
361
2.11k
{
362
2.11k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
2.11k
  boolean smoothing_useful = FALSE;
364
2.11k
  int ci, coefi;
365
2.11k
  jpeg_component_info *compptr;
366
2.11k
  JQUANT_TBL *qtable;
367
2.11k
  int *coef_bits, *prev_coef_bits;
368
2.11k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
2.11k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
390
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
1.72k
  if (coef->coef_bits_latch == NULL)
375
1.72k
    coef->coef_bits_latch = (int *)
376
1.72k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
1.72k
                                  cinfo->num_components * 2 *
378
1.72k
                                  (SAVED_COEFS * sizeof(int)));
379
1.72k
  coef_bits_latch = coef->coef_bits_latch;
380
1.72k
  prev_coef_bits_latch =
381
1.72k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
2.57k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
1.95k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
1.95k
    if ((qtable = compptr->quant_table) == NULL)
387
266
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
1.68k
    if (qtable->quantval[0] == 0 ||
390
1.68k
        qtable->quantval[Q01_POS] == 0 ||
391
1.68k
        qtable->quantval[Q10_POS] == 0 ||
392
1.68k
        qtable->quantval[Q20_POS] == 0 ||
393
1.68k
        qtable->quantval[Q11_POS] == 0 ||
394
1.68k
        qtable->quantval[Q02_POS] == 0 ||
395
1.68k
        qtable->quantval[Q03_POS] == 0 ||
396
1.68k
        qtable->quantval[Q12_POS] == 0 ||
397
1.68k
        qtable->quantval[Q21_POS] == 0 ||
398
1.68k
        qtable->quantval[Q30_POS] == 0)
399
751
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
933
    coef_bits = cinfo->coef_bits[ci];
402
933
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
933
    if (coef_bits[0] < 0)
404
78
      return FALSE;
405
855
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
8.55k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
7.69k
      if (cinfo->input_scan_number > 1)
409
4.12k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
3.57k
      else
411
3.57k
        prev_coef_bits_latch[coefi] = -1;
412
7.69k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
7.69k
      if (coef_bits[coefi] != 0)
414
7.31k
        smoothing_useful = TRUE;
415
7.69k
    }
416
855
    coef_bits_latch += SAVED_COEFS;
417
855
    prev_coef_bits_latch += SAVED_COEFS;
418
855
  }
419
420
628
  return smoothing_useful;
421
1.72k
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
361
296
{
362
296
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
296
  boolean smoothing_useful = FALSE;
364
296
  int ci, coefi;
365
296
  jpeg_component_info *compptr;
366
296
  JQUANT_TBL *qtable;
367
296
  int *coef_bits, *prev_coef_bits;
368
296
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
296
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
50
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
246
  if (coef->coef_bits_latch == NULL)
375
246
    coef->coef_bits_latch = (int *)
376
246
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
246
                                  cinfo->num_components * 2 *
378
246
                                  (SAVED_COEFS * sizeof(int)));
379
246
  coef_bits_latch = coef->coef_bits_latch;
380
246
  prev_coef_bits_latch =
381
246
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
308
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
263
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
263
    if ((qtable = compptr->quant_table) == NULL)
387
17
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
246
    if (qtable->quantval[0] == 0 ||
390
246
        qtable->quantval[Q01_POS] == 0 ||
391
246
        qtable->quantval[Q10_POS] == 0 ||
392
246
        qtable->quantval[Q20_POS] == 0 ||
393
246
        qtable->quantval[Q11_POS] == 0 ||
394
246
        qtable->quantval[Q02_POS] == 0 ||
395
246
        qtable->quantval[Q03_POS] == 0 ||
396
246
        qtable->quantval[Q12_POS] == 0 ||
397
246
        qtable->quantval[Q21_POS] == 0 ||
398
246
        qtable->quantval[Q30_POS] == 0)
399
167
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
79
    coef_bits = cinfo->coef_bits[ci];
402
79
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
79
    if (coef_bits[0] < 0)
404
17
      return FALSE;
405
62
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
620
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
558
      if (cinfo->input_scan_number > 1)
409
207
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
351
      else
411
351
        prev_coef_bits_latch[coefi] = -1;
412
558
      coef_bits_latch[coefi] = coef_bits[coefi];
413
558
      if (coef_bits[coefi] != 0)
414
482
        smoothing_useful = TRUE;
415
558
    }
416
62
    coef_bits_latch += SAVED_COEFS;
417
62
    prev_coef_bits_latch += SAVED_COEFS;
418
62
  }
419
420
45
  return smoothing_useful;
421
246
}
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
286k
{
431
286k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
286k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
286k
  JDIMENSION block_num, last_block_column;
434
286k
  int ci, block_row, block_rows, access_rows, image_block_row,
435
286k
    image_block_rows;
436
286k
  JBLOCKARRAY buffer;
437
286k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
286k
  JBLOCKROW next_block_row, next_next_block_row;
439
286k
  _JSAMPARRAY output_ptr;
440
286k
  JDIMENSION output_col;
441
286k
  jpeg_component_info *compptr;
442
286k
  _inverse_DCT_method_ptr inverse_DCT;
443
286k
  boolean change_dc;
444
286k
  JCOEF *workspace;
445
286k
  int *coef_bits;
446
286k
  JQUANT_TBL *quanttbl;
447
286k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
286k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
286k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
286k
      DC25;
451
286k
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
286k
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
286k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
286k
         !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
676k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
390k
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
390k
    if (!compptr->component_needed)
478
0
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
390k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
388k
      block_rows = compptr->v_samp_factor;
482
388k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
388k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
719
      block_rows = compptr->v_samp_factor;
485
719
      access_rows = block_rows * 2; /* this and next iMCU row */
486
795
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
795
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
795
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
795
      access_rows = block_rows; /* this iMCU row only */
491
795
    }
492
    /* Align the virtual buffer for this component. */
493
390k
    if (cinfo->output_iMCU_row > 1) {
494
388k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
388k
      buffer = (*cinfo->mem->access_virt_barray)
496
388k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
388k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
388k
         (JDIMENSION)access_rows, FALSE);
499
388k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
388k
    } else if (cinfo->output_iMCU_row > 0) {
501
719
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
719
      buffer = (*cinfo->mem->access_virt_barray)
503
719
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
719
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
719
         (JDIMENSION)access_rows, FALSE);
506
719
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
795
    } else {
508
795
      buffer = (*cinfo->mem->access_virt_barray)
509
795
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
795
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
795
    }
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
390k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
192k
      coef_bits =
518
192k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
197k
    else
520
197k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
390k
    change_dc =
524
390k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
390k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
390k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
390k
    quanttbl = compptr->quant_table;
529
390k
    Q00 = quanttbl->quantval[0];
530
390k
    Q01 = quanttbl->quantval[Q01_POS];
531
390k
    Q10 = quanttbl->quantval[Q10_POS];
532
390k
    Q20 = quanttbl->quantval[Q20_POS];
533
390k
    Q11 = quanttbl->quantval[Q11_POS];
534
390k
    Q02 = quanttbl->quantval[Q02_POS];
535
390k
    if (change_dc) {
536
307k
      Q03 = quanttbl->quantval[Q03_POS];
537
307k
      Q12 = quanttbl->quantval[Q12_POS];
538
307k
      Q21 = quanttbl->quantval[Q21_POS];
539
307k
      Q30 = quanttbl->quantval[Q30_POS];
540
307k
    }
541
390k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
390k
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
390k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
898k
    for (block_row = 0; block_row < block_rows; block_row++) {
546
507k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
507k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
507k
      if (image_block_row > 0)
550
507k
        prev_block_row =
551
507k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
795
      else
553
795
        prev_block_row = buffer_ptr;
554
555
507k
      if (image_block_row > 1)
556
506k
        prev_prev_block_row =
557
506k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
1.57k
      else
559
1.57k
        prev_prev_block_row = prev_block_row;
560
561
507k
      if (image_block_row < image_block_rows - 1)
562
507k
        next_block_row =
563
507k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
795
      else
565
795
        next_block_row = buffer_ptr;
566
567
507k
      if (image_block_row < image_block_rows - 2)
568
506k
        next_next_block_row =
569
506k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
1.46k
      else
571
1.46k
        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
507k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
507k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
507k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
507k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
507k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
507k
      output_col = 0;
582
507k
      last_block_column = compptr->width_in_blocks - 1;
583
507k
      for (block_num = cinfo->master->first_MCU_col[ci];
584
5.17M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
4.66M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
4.66M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
4.66M
            block_num < last_block_column) {
590
340k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
340k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
340k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
340k
          DC19 = DC20 = (int)next_block_row[1][0];
594
340k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
340k
        }
596
4.66M
        if (block_num + 1 < last_block_column) {
597
3.82M
          DC05 = (int)prev_prev_block_row[2][0];
598
3.82M
          DC10 = (int)prev_block_row[2][0];
599
3.82M
          DC15 = (int)buffer_ptr[2][0];
600
3.82M
          DC20 = (int)next_block_row[2][0];
601
3.82M
          DC25 = (int)next_next_block_row[2][0];
602
3.82M
        }
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
4.66M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
4.51M
          num = Q00 * (change_dc ?
616
3.19M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
3.19M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
3.19M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
3.19M
                 DC21 - DC22 + DC24 + DC25) :
620
4.51M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
4.51M
          if (num >= 0) {
622
3.56M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
3.56M
            if (Al > 0 && pred >= (1 << Al))
624
192k
              pred = (1 << Al) - 1;
625
3.56M
          } else {
626
957k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
957k
            if (Al > 0 && pred >= (1 << Al))
628
181k
              pred = (1 << Al) - 1;
629
957k
            pred = -pred;
630
957k
          }
631
4.51M
          workspace[1] = (JCOEF)pred;
632
4.51M
        }
633
        /* AC10 */
634
4.66M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
4.55M
          num = Q00 * (change_dc ?
636
3.19M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
3.19M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
3.19M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
3.19M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
4.55M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
4.55M
          if (num >= 0) {
642
3.36M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
3.36M
            if (Al > 0 && pred >= (1 << Al))
644
397k
              pred = (1 << Al) - 1;
645
3.36M
          } else {
646
1.19M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
1.19M
            if (Al > 0 && pred >= (1 << Al))
648
279k
              pred = (1 << Al) - 1;
649
1.19M
            pred = -pred;
650
1.19M
          }
651
4.55M
          workspace[8] = (JCOEF)pred;
652
4.55M
        }
653
        /* AC20 */
654
4.66M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
4.51M
          num = Q00 * (change_dc ?
656
3.19M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
3.19M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
4.51M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
4.51M
          if (num >= 0) {
660
2.97M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
2.97M
            if (Al > 0 && pred >= (1 << Al))
662
291k
              pred = (1 << Al) - 1;
663
2.97M
          } else {
664
1.53M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
1.53M
            if (Al > 0 && pred >= (1 << Al))
666
296k
              pred = (1 << Al) - 1;
667
1.53M
            pred = -pred;
668
1.53M
          }
669
4.51M
          workspace[16] = (JCOEF)pred;
670
4.51M
        }
671
        /* AC11 */
672
4.66M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
4.52M
          num = Q00 * (change_dc ?
674
3.19M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
3.19M
                 9 * DC19 + DC21 - DC25) :
676
4.52M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
1.32M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
4.52M
          if (num >= 0) {
679
3.78M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
3.78M
            if (Al > 0 && pred >= (1 << Al))
681
116k
              pred = (1 << Al) - 1;
682
3.78M
          } else {
683
743k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
743k
            if (Al > 0 && pred >= (1 << Al))
685
123k
              pred = (1 << Al) - 1;
686
743k
            pred = -pred;
687
743k
          }
688
4.52M
          workspace[9] = (JCOEF)pred;
689
4.52M
        }
690
        /* AC02 */
691
4.66M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
4.52M
          num = Q00 * (change_dc ?
693
3.19M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
3.19M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
4.52M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
4.52M
          if (num >= 0) {
697
2.96M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
2.96M
            if (Al > 0 && pred >= (1 << Al))
699
157k
              pred = (1 << Al) - 1;
700
2.96M
          } else {
701
1.55M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
1.55M
            if (Al > 0 && pred >= (1 << Al))
703
154k
              pred = (1 << Al) - 1;
704
1.55M
            pred = -pred;
705
1.55M
          }
706
4.52M
          workspace[2] = (JCOEF)pred;
707
4.52M
        }
708
4.66M
        if (change_dc) {
709
          /* AC03 */
710
3.19M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
3.19M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
3.19M
            if (num >= 0) {
713
2.64M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
2.64M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
2.64M
            } else {
717
552k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
552k
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
552k
              pred = -pred;
721
552k
            }
722
3.19M
            workspace[3] = (JCOEF)pred;
723
3.19M
          }
724
          /* AC12 */
725
3.19M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
3.19M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
3.19M
            if (num >= 0) {
728
2.10M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
2.10M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
2.10M
            } else {
732
1.09M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
1.09M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
1.09M
              pred = -pred;
736
1.09M
            }
737
3.19M
            workspace[10] = (JCOEF)pred;
738
3.19M
          }
739
          /* AC21 */
740
3.19M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
3.19M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
3.19M
            if (num >= 0) {
743
1.83M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
1.83M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
1.83M
            } else {
747
1.36M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
1.36M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
1.36M
              pred = -pred;
751
1.36M
            }
752
3.19M
            workspace[17] = (JCOEF)pred;
753
3.19M
          }
754
          /* AC30 */
755
3.19M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
3.19M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
3.19M
            if (num >= 0) {
758
2.47M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
2.47M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
2.47M
            } else {
762
727k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
727k
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
727k
              pred = -pred;
766
727k
            }
767
3.19M
            workspace[24] = (JCOEF)pred;
768
3.19M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
3.19M
          num = Q00 *
773
3.19M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
3.19M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
3.19M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
3.19M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
3.19M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
3.19M
          if (num >= 0) {
779
2.02M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
2.02M
          } else {
781
1.17M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
1.17M
            pred = -pred;
783
1.17M
          }
784
3.19M
          workspace[0] = (JCOEF)pred;
785
3.19M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
4.66M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
4.66M
                        output_col);
790
        /* Advance for next column */
791
4.66M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
4.66M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
4.66M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
4.66M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
4.66M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
4.66M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
4.66M
          prev_prev_block_row++, next_next_block_row++;
798
4.66M
        output_col += compptr->_DCT_scaled_size;
799
4.66M
      }
800
507k
      output_ptr += compptr->_DCT_scaled_size;
801
507k
    }
802
390k
  }
803
804
286k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
286k
    return JPEG_ROW_COMPLETED;
806
619
  return JPEG_SCAN_COMPLETED;
807
286k
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
430
286k
{
431
286k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
286k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
286k
  JDIMENSION block_num, last_block_column;
434
286k
  int ci, block_row, block_rows, access_rows, image_block_row,
435
286k
    image_block_rows;
436
286k
  JBLOCKARRAY buffer;
437
286k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
286k
  JBLOCKROW next_block_row, next_next_block_row;
439
286k
  _JSAMPARRAY output_ptr;
440
286k
  JDIMENSION output_col;
441
286k
  jpeg_component_info *compptr;
442
286k
  _inverse_DCT_method_ptr inverse_DCT;
443
286k
  boolean change_dc;
444
286k
  JCOEF *workspace;
445
286k
  int *coef_bits;
446
286k
  JQUANT_TBL *quanttbl;
447
286k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
286k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
286k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
286k
      DC25;
451
286k
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
286k
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
286k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
286k
         !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
676k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
390k
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
390k
    if (!compptr->component_needed)
478
0
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
390k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
388k
      block_rows = compptr->v_samp_factor;
482
388k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
388k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
719
      block_rows = compptr->v_samp_factor;
485
719
      access_rows = block_rows * 2; /* this and next iMCU row */
486
795
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
795
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
795
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
795
      access_rows = block_rows; /* this iMCU row only */
491
795
    }
492
    /* Align the virtual buffer for this component. */
493
390k
    if (cinfo->output_iMCU_row > 1) {
494
388k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
388k
      buffer = (*cinfo->mem->access_virt_barray)
496
388k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
388k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
388k
         (JDIMENSION)access_rows, FALSE);
499
388k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
388k
    } else if (cinfo->output_iMCU_row > 0) {
501
719
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
719
      buffer = (*cinfo->mem->access_virt_barray)
503
719
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
719
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
719
         (JDIMENSION)access_rows, FALSE);
506
719
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
795
    } else {
508
795
      buffer = (*cinfo->mem->access_virt_barray)
509
795
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
795
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
795
    }
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
390k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
192k
      coef_bits =
518
192k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
197k
    else
520
197k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
390k
    change_dc =
524
390k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
390k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
390k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
390k
    quanttbl = compptr->quant_table;
529
390k
    Q00 = quanttbl->quantval[0];
530
390k
    Q01 = quanttbl->quantval[Q01_POS];
531
390k
    Q10 = quanttbl->quantval[Q10_POS];
532
390k
    Q20 = quanttbl->quantval[Q20_POS];
533
390k
    Q11 = quanttbl->quantval[Q11_POS];
534
390k
    Q02 = quanttbl->quantval[Q02_POS];
535
390k
    if (change_dc) {
536
307k
      Q03 = quanttbl->quantval[Q03_POS];
537
307k
      Q12 = quanttbl->quantval[Q12_POS];
538
307k
      Q21 = quanttbl->quantval[Q21_POS];
539
307k
      Q30 = quanttbl->quantval[Q30_POS];
540
307k
    }
541
390k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
390k
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
390k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
898k
    for (block_row = 0; block_row < block_rows; block_row++) {
546
507k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
507k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
507k
      if (image_block_row > 0)
550
507k
        prev_block_row =
551
507k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
795
      else
553
795
        prev_block_row = buffer_ptr;
554
555
507k
      if (image_block_row > 1)
556
506k
        prev_prev_block_row =
557
506k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
1.57k
      else
559
1.57k
        prev_prev_block_row = prev_block_row;
560
561
507k
      if (image_block_row < image_block_rows - 1)
562
507k
        next_block_row =
563
507k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
795
      else
565
795
        next_block_row = buffer_ptr;
566
567
507k
      if (image_block_row < image_block_rows - 2)
568
506k
        next_next_block_row =
569
506k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
1.46k
      else
571
1.46k
        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
507k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
507k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
507k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
507k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
507k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
507k
      output_col = 0;
582
507k
      last_block_column = compptr->width_in_blocks - 1;
583
507k
      for (block_num = cinfo->master->first_MCU_col[ci];
584
5.17M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
4.66M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
4.66M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
4.66M
            block_num < last_block_column) {
590
340k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
340k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
340k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
340k
          DC19 = DC20 = (int)next_block_row[1][0];
594
340k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
340k
        }
596
4.66M
        if (block_num + 1 < last_block_column) {
597
3.82M
          DC05 = (int)prev_prev_block_row[2][0];
598
3.82M
          DC10 = (int)prev_block_row[2][0];
599
3.82M
          DC15 = (int)buffer_ptr[2][0];
600
3.82M
          DC20 = (int)next_block_row[2][0];
601
3.82M
          DC25 = (int)next_next_block_row[2][0];
602
3.82M
        }
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
4.66M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
4.51M
          num = Q00 * (change_dc ?
616
3.19M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
3.19M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
3.19M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
3.19M
                 DC21 - DC22 + DC24 + DC25) :
620
4.51M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
4.51M
          if (num >= 0) {
622
3.56M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
3.56M
            if (Al > 0 && pred >= (1 << Al))
624
192k
              pred = (1 << Al) - 1;
625
3.56M
          } else {
626
957k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
957k
            if (Al > 0 && pred >= (1 << Al))
628
181k
              pred = (1 << Al) - 1;
629
957k
            pred = -pred;
630
957k
          }
631
4.51M
          workspace[1] = (JCOEF)pred;
632
4.51M
        }
633
        /* AC10 */
634
4.66M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
4.55M
          num = Q00 * (change_dc ?
636
3.19M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
3.19M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
3.19M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
3.19M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
4.55M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
4.55M
          if (num >= 0) {
642
3.36M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
3.36M
            if (Al > 0 && pred >= (1 << Al))
644
397k
              pred = (1 << Al) - 1;
645
3.36M
          } else {
646
1.19M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
1.19M
            if (Al > 0 && pred >= (1 << Al))
648
279k
              pred = (1 << Al) - 1;
649
1.19M
            pred = -pred;
650
1.19M
          }
651
4.55M
          workspace[8] = (JCOEF)pred;
652
4.55M
        }
653
        /* AC20 */
654
4.66M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
4.51M
          num = Q00 * (change_dc ?
656
3.19M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
3.19M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
4.51M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
4.51M
          if (num >= 0) {
660
2.97M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
2.97M
            if (Al > 0 && pred >= (1 << Al))
662
291k
              pred = (1 << Al) - 1;
663
2.97M
          } else {
664
1.53M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
1.53M
            if (Al > 0 && pred >= (1 << Al))
666
296k
              pred = (1 << Al) - 1;
667
1.53M
            pred = -pred;
668
1.53M
          }
669
4.51M
          workspace[16] = (JCOEF)pred;
670
4.51M
        }
671
        /* AC11 */
672
4.66M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
4.52M
          num = Q00 * (change_dc ?
674
3.19M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
3.19M
                 9 * DC19 + DC21 - DC25) :
676
4.52M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
1.32M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
4.52M
          if (num >= 0) {
679
3.78M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
3.78M
            if (Al > 0 && pred >= (1 << Al))
681
116k
              pred = (1 << Al) - 1;
682
3.78M
          } else {
683
743k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
743k
            if (Al > 0 && pred >= (1 << Al))
685
123k
              pred = (1 << Al) - 1;
686
743k
            pred = -pred;
687
743k
          }
688
4.52M
          workspace[9] = (JCOEF)pred;
689
4.52M
        }
690
        /* AC02 */
691
4.66M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
4.52M
          num = Q00 * (change_dc ?
693
3.19M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
3.19M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
4.52M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
4.52M
          if (num >= 0) {
697
2.96M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
2.96M
            if (Al > 0 && pred >= (1 << Al))
699
157k
              pred = (1 << Al) - 1;
700
2.96M
          } else {
701
1.55M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
1.55M
            if (Al > 0 && pred >= (1 << Al))
703
154k
              pred = (1 << Al) - 1;
704
1.55M
            pred = -pred;
705
1.55M
          }
706
4.52M
          workspace[2] = (JCOEF)pred;
707
4.52M
        }
708
4.66M
        if (change_dc) {
709
          /* AC03 */
710
3.19M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
3.19M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
3.19M
            if (num >= 0) {
713
2.64M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
2.64M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
2.64M
            } else {
717
552k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
552k
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
552k
              pred = -pred;
721
552k
            }
722
3.19M
            workspace[3] = (JCOEF)pred;
723
3.19M
          }
724
          /* AC12 */
725
3.19M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
3.19M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
3.19M
            if (num >= 0) {
728
2.10M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
2.10M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
2.10M
            } else {
732
1.09M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
1.09M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
1.09M
              pred = -pred;
736
1.09M
            }
737
3.19M
            workspace[10] = (JCOEF)pred;
738
3.19M
          }
739
          /* AC21 */
740
3.19M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
3.19M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
3.19M
            if (num >= 0) {
743
1.83M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
1.83M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
1.83M
            } else {
747
1.36M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
1.36M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
1.36M
              pred = -pred;
751
1.36M
            }
752
3.19M
            workspace[17] = (JCOEF)pred;
753
3.19M
          }
754
          /* AC30 */
755
3.19M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
3.19M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
3.19M
            if (num >= 0) {
758
2.47M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
2.47M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
2.47M
            } else {
762
727k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
727k
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
727k
              pred = -pred;
766
727k
            }
767
3.19M
            workspace[24] = (JCOEF)pred;
768
3.19M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
3.19M
          num = Q00 *
773
3.19M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
3.19M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
3.19M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
3.19M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
3.19M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
3.19M
          if (num >= 0) {
779
2.02M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
2.02M
          } else {
781
1.17M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
1.17M
            pred = -pred;
783
1.17M
          }
784
3.19M
          workspace[0] = (JCOEF)pred;
785
3.19M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
4.66M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
4.66M
                        output_col);
790
        /* Advance for next column */
791
4.66M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
4.66M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
4.66M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
4.66M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
4.66M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
4.66M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
4.66M
          prev_prev_block_row++, next_next_block_row++;
798
4.66M
        output_col += compptr->_DCT_scaled_size;
799
4.66M
      }
800
507k
      output_ptr += compptr->_DCT_scaled_size;
801
507k
    }
802
390k
  }
803
804
286k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
286k
    return JPEG_ROW_COMPLETED;
806
619
  return JPEG_SCAN_COMPLETED;
807
286k
}
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
5.04k
{
819
5.04k
  my_coef_ptr coef;
820
821
5.04k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
5.04k
  coef = (my_coef_ptr)
825
5.04k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
5.04k
                                sizeof(my_coef_controller));
827
5.04k
  memset(coef, 0, sizeof(my_coef_controller));
828
5.04k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
5.04k
  coef->pub.start_input_pass = start_input_pass;
830
5.04k
  coef->pub.start_output_pass = start_output_pass;
831
5.04k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
5.04k
  coef->coef_bits_latch = NULL;
833
5.04k
#endif
834
835
  /* Create the coefficient buffer. */
836
5.04k
  if (need_full_buffer) {
837
3.17k
#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.17k
    int ci, access_rows;
842
3.17k
    jpeg_component_info *compptr;
843
844
8.73k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
5.55k
         ci++, compptr++) {
846
5.55k
      access_rows = compptr->v_samp_factor;
847
5.55k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
5.55k
      if (cinfo->progressive_mode)
850
3.77k
        access_rows *= 5;
851
5.55k
#endif
852
5.55k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
5.55k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
5.55k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
5.55k
                               (long)compptr->h_samp_factor),
856
5.55k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
5.55k
                               (long)compptr->v_samp_factor),
858
5.55k
         (JDIMENSION)access_rows);
859
5.55k
    }
860
3.17k
    coef->pub.consume_data = consume_data;
861
3.17k
    coef->pub._decompress_data = decompress_data;
862
3.17k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
3.17k
  } else {
867
    /* We only need a single-MCU buffer. */
868
1.86k
    JBLOCKROW buffer;
869
1.86k
    int i;
870
871
1.86k
    buffer = (JBLOCKROW)
872
1.86k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
1.86k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
20.4k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
18.6k
      coef->MCU_buffer[i] = buffer + i;
876
18.6k
    }
877
1.86k
    coef->pub.consume_data = dummy_consume_data;
878
1.86k
    coef->pub._decompress_data = decompress_onepass;
879
1.86k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
1.86k
  }
881
882
  /* Allocate the workspace buffer */
883
5.04k
  coef->workspace = (JCOEF *)
884
5.04k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
5.04k
                                sizeof(JCOEF) * DCTSIZE2);
886
5.04k
}
jinit_d_coef_controller
Line
Count
Source
818
4.68k
{
819
4.68k
  my_coef_ptr coef;
820
821
4.68k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
4.68k
  coef = (my_coef_ptr)
825
4.68k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
4.68k
                                sizeof(my_coef_controller));
827
4.68k
  memset(coef, 0, sizeof(my_coef_controller));
828
4.68k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
4.68k
  coef->pub.start_input_pass = start_input_pass;
830
4.68k
  coef->pub.start_output_pass = start_output_pass;
831
4.68k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
4.68k
  coef->coef_bits_latch = NULL;
833
4.68k
#endif
834
835
  /* Create the coefficient buffer. */
836
4.68k
  if (need_full_buffer) {
837
2.84k
#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
2.84k
    int ci, access_rows;
842
2.84k
    jpeg_component_info *compptr;
843
844
7.80k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
4.96k
         ci++, compptr++) {
846
4.96k
      access_rows = compptr->v_samp_factor;
847
4.96k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
4.96k
      if (cinfo->progressive_mode)
850
3.38k
        access_rows *= 5;
851
4.96k
#endif
852
4.96k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
4.96k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
4.96k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
4.96k
                               (long)compptr->h_samp_factor),
856
4.96k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
4.96k
                               (long)compptr->v_samp_factor),
858
4.96k
         (JDIMENSION)access_rows);
859
4.96k
    }
860
2.84k
    coef->pub.consume_data = consume_data;
861
2.84k
    coef->pub._decompress_data = decompress_data;
862
2.84k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
2.84k
  } else {
867
    /* We only need a single-MCU buffer. */
868
1.84k
    JBLOCKROW buffer;
869
1.84k
    int i;
870
871
1.84k
    buffer = (JBLOCKROW)
872
1.84k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
1.84k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
20.2k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
18.4k
      coef->MCU_buffer[i] = buffer + i;
876
18.4k
    }
877
1.84k
    coef->pub.consume_data = dummy_consume_data;
878
1.84k
    coef->pub._decompress_data = decompress_onepass;
879
1.84k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
1.84k
  }
881
882
  /* Allocate the workspace buffer */
883
4.68k
  coef->workspace = (JCOEF *)
884
4.68k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
4.68k
                                sizeof(JCOEF) * DCTSIZE2);
886
4.68k
}
j12init_d_coef_controller
Line
Count
Source
818
358
{
819
358
  my_coef_ptr coef;
820
821
358
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
358
  coef = (my_coef_ptr)
825
358
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
358
                                sizeof(my_coef_controller));
827
358
  memset(coef, 0, sizeof(my_coef_controller));
828
358
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
358
  coef->pub.start_input_pass = start_input_pass;
830
358
  coef->pub.start_output_pass = start_output_pass;
831
358
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
358
  coef->coef_bits_latch = NULL;
833
358
#endif
834
835
  /* Create the coefficient buffer. */
836
358
  if (need_full_buffer) {
837
338
#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
338
    int ci, access_rows;
842
338
    jpeg_component_info *compptr;
843
844
926
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
588
         ci++, compptr++) {
846
588
      access_rows = compptr->v_samp_factor;
847
588
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
588
      if (cinfo->progressive_mode)
850
390
        access_rows *= 5;
851
588
#endif
852
588
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
588
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
588
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
588
                               (long)compptr->h_samp_factor),
856
588
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
588
                               (long)compptr->v_samp_factor),
858
588
         (JDIMENSION)access_rows);
859
588
    }
860
338
    coef->pub.consume_data = consume_data;
861
338
    coef->pub._decompress_data = decompress_data;
862
338
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
338
  } else {
867
    /* We only need a single-MCU buffer. */
868
20
    JBLOCKROW buffer;
869
20
    int i;
870
871
20
    buffer = (JBLOCKROW)
872
20
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
20
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
220
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
200
      coef->MCU_buffer[i] = buffer + i;
876
200
    }
877
20
    coef->pub.consume_data = dummy_consume_data;
878
20
    coef->pub._decompress_data = decompress_onepass;
879
20
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
20
  }
881
882
  /* Allocate the workspace buffer */
883
358
  coef->workspace = (JCOEF *)
884
358
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
358
                                sizeof(JCOEF) * DCTSIZE2);
886
358
}