Coverage Report

Created: 2025-07-01 06:26

/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
22.2k
{
48
22.2k
  cinfo->input_iMCU_row = 0;
49
22.2k
  start_iMCU_row(cinfo);
50
22.2k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
47
20.8k
{
48
20.8k
  cinfo->input_iMCU_row = 0;
49
20.8k
  start_iMCU_row(cinfo);
50
20.8k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
47
1.39k
{
48
1.39k
  cinfo->input_iMCU_row = 0;
49
1.39k
  start_iMCU_row(cinfo);
50
1.39k
}
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.08k
{
60
3.08k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
3.08k
  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.08k
  if (coef->pub.coef_arrays != NULL) {
65
2.39k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
659
      coef->pub._decompress_data = decompress_smooth_data;
67
1.73k
    else
68
1.73k
      coef->pub._decompress_data = decompress_data;
69
2.39k
  }
70
3.08k
#endif
71
3.08k
  cinfo->output_iMCU_row = 0;
72
3.08k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
59
2.78k
{
60
2.78k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
2.78k
  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.78k
  if (coef->pub.coef_arrays != NULL) {
65
2.10k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
618
      coef->pub._decompress_data = decompress_smooth_data;
67
1.48k
    else
68
1.48k
      coef->pub._decompress_data = decompress_data;
69
2.10k
  }
70
2.78k
#endif
71
2.78k
  cinfo->output_iMCU_row = 0;
72
2.78k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
59
303
{
60
303
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
303
  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
303
  if (coef->pub.coef_arrays != NULL) {
65
290
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
41
      coef->pub._decompress_data = decompress_smooth_data;
67
249
    else
68
249
      coef->pub._decompress_data = decompress_data;
69
290
  }
70
303
#endif
71
303
  cinfo->output_iMCU_row = 0;
72
303
}
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
126k
{
88
126k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
126k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
126k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
126k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
126k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
126k
  _JSAMPARRAY output_ptr;
94
126k
  JDIMENSION start_col, output_col;
95
126k
  jpeg_component_info *compptr;
96
126k
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
320k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
194k
       yoffset++) {
101
3.59M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
3.39M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
3.39M
      jzero_far((void *)coef->MCU_buffer[0],
105
3.39M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
3.39M
      if (!cinfo->entropy->insufficient_data)
107
525k
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
3.39M
      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.39M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
3.39M
          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.39M
        blkn = 0;               /* index of current DCT block within MCU */
126
6.85M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
3.45M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
3.45M
          if (!compptr->component_needed) {
130
0
            blkn += compptr->MCU_blocks;
131
0
            continue;
132
0
          }
133
3.45M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
3.45M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
3.25M
                         compptr->MCU_width : compptr->last_col_width;
136
3.45M
          output_ptr = output_buf[compptr->component_index] +
137
3.45M
                       yoffset * compptr->_DCT_scaled_size;
138
3.45M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
3.45M
                      compptr->MCU_sample_width;
140
6.95M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
3.50M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
3.50M
                yoffset + yindex < compptr->last_row_height) {
143
3.49M
              output_col = start_col;
144
7.03M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
3.53M
                (*inverse_DCT) (cinfo, compptr,
146
3.53M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
3.53M
                                output_ptr, output_col);
148
3.53M
                output_col += compptr->_DCT_scaled_size;
149
3.53M
              }
150
3.49M
            }
151
3.50M
            blkn += compptr->MCU_width;
152
3.50M
            output_ptr += compptr->_DCT_scaled_size;
153
3.50M
          }
154
3.45M
        }
155
3.39M
      }
156
3.39M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
194k
    coef->MCU_ctr = 0;
159
194k
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
126k
  cinfo->output_iMCU_row++;
162
126k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
125k
    start_iMCU_row(cinfo);
164
125k
    return JPEG_ROW_COMPLETED;
165
125k
  }
166
  /* Completed the scan */
167
679
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
679
  return JPEG_SCAN_COMPLETED;
169
126k
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
87
126k
{
88
126k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
126k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
126k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
126k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
126k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
126k
  _JSAMPARRAY output_ptr;
94
126k
  JDIMENSION start_col, output_col;
95
126k
  jpeg_component_info *compptr;
96
126k
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
320k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
194k
       yoffset++) {
101
3.59M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
3.39M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
3.39M
      jzero_far((void *)coef->MCU_buffer[0],
105
3.39M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
3.39M
      if (!cinfo->entropy->insufficient_data)
107
525k
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
3.39M
      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.39M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
3.39M
          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.39M
        blkn = 0;               /* index of current DCT block within MCU */
126
6.85M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
3.45M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
3.45M
          if (!compptr->component_needed) {
130
0
            blkn += compptr->MCU_blocks;
131
0
            continue;
132
0
          }
133
3.45M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
3.45M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
3.25M
                         compptr->MCU_width : compptr->last_col_width;
136
3.45M
          output_ptr = output_buf[compptr->component_index] +
137
3.45M
                       yoffset * compptr->_DCT_scaled_size;
138
3.45M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
3.45M
                      compptr->MCU_sample_width;
140
6.95M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
3.50M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
3.50M
                yoffset + yindex < compptr->last_row_height) {
143
3.49M
              output_col = start_col;
144
7.03M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
3.53M
                (*inverse_DCT) (cinfo, compptr,
146
3.53M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
3.53M
                                output_ptr, output_col);
148
3.53M
                output_col += compptr->_DCT_scaled_size;
149
3.53M
              }
150
3.49M
            }
151
3.50M
            blkn += compptr->MCU_width;
152
3.50M
            output_ptr += compptr->_DCT_scaled_size;
153
3.50M
          }
154
3.45M
        }
155
3.39M
      }
156
3.39M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
194k
    coef->MCU_ctr = 0;
159
194k
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
126k
  cinfo->output_iMCU_row++;
162
126k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
125k
    start_iMCU_row(cinfo);
164
125k
    return JPEG_ROW_COMPLETED;
165
125k
  }
166
  /* Completed the scan */
167
679
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
679
  return JPEG_SCAN_COMPLETED;
169
126k
}
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
4.16M
{
195
4.16M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
4.16M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
4.16M
  int blkn, ci, xindex, yindex, yoffset;
198
4.16M
  JDIMENSION start_col;
199
4.16M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
4.16M
  JBLOCKROW buffer_ptr;
201
4.16M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
8.60M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
4.44M
    compptr = cinfo->cur_comp_info[ci];
206
4.44M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
4.44M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
4.44M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
4.44M
       (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
4.44M
  }
215
216
  /* Loop to process one whole iMCU row */
217
8.71M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
4.55M
       yoffset++) {
219
89.5M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
84.9M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
84.9M
      blkn = 0;                 /* index of current DCT block within MCU */
223
177M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
92.9M
        compptr = cinfo->cur_comp_info[ci];
225
92.9M
        start_col = MCU_col_num * compptr->MCU_width;
226
196M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
103M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
221M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
117M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
117M
          }
231
103M
        }
232
92.9M
      }
233
84.9M
      if (!cinfo->entropy->insufficient_data)
234
43.0M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
84.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
84.9M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
4.55M
    coef->MCU_ctr = 0;
245
4.55M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
4.16M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
4.14M
    start_iMCU_row(cinfo);
249
4.14M
    return JPEG_ROW_COMPLETED;
250
4.14M
  }
251
  /* Completed the scan */
252
20.5k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
20.5k
  return JPEG_SCAN_COMPLETED;
254
4.16M
}
jdcoefct-8.c:consume_data
Line
Count
Source
194
3.51M
{
195
3.51M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
3.51M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
3.51M
  int blkn, ci, xindex, yindex, yoffset;
198
3.51M
  JDIMENSION start_col;
199
3.51M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
3.51M
  JBLOCKROW buffer_ptr;
201
3.51M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
7.29M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
3.77M
    compptr = cinfo->cur_comp_info[ci];
206
3.77M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
3.77M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
3.77M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
3.77M
       (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.77M
  }
215
216
  /* Loop to process one whole iMCU row */
217
7.40M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
3.88M
       yoffset++) {
219
83.5M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
79.6M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
79.6M
      blkn = 0;                 /* index of current DCT block within MCU */
223
166M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
87.2M
        compptr = cinfo->cur_comp_info[ci];
225
87.2M
        start_col = MCU_col_num * compptr->MCU_width;
226
185M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
97.9M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
209M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
111M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
111M
          }
231
97.9M
        }
232
87.2M
      }
233
79.6M
      if (!cinfo->entropy->insufficient_data)
234
41.0M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
79.6M
      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
79.6M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
3.88M
    coef->MCU_ctr = 0;
245
3.88M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
3.51M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
3.49M
    start_iMCU_row(cinfo);
249
3.49M
    return JPEG_ROW_COMPLETED;
250
3.49M
  }
251
  /* Completed the scan */
252
19.1k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
19.1k
  return JPEG_SCAN_COMPLETED;
254
3.51M
}
jdcoefct-12.c:consume_data
Line
Count
Source
194
645k
{
195
645k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
645k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
645k
  int blkn, ci, xindex, yindex, yoffset;
198
645k
  JDIMENSION start_col;
199
645k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
645k
  JBLOCKROW buffer_ptr;
201
645k
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
1.31M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
666k
    compptr = cinfo->cur_comp_info[ci];
206
666k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
666k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
666k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
666k
       (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
666k
  }
215
216
  /* Loop to process one whole iMCU row */
217
1.31M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
672k
       yoffset++) {
219
5.97M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
5.30M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
5.30M
      blkn = 0;                 /* index of current DCT block within MCU */
223
10.9M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
5.69M
        compptr = cinfo->cur_comp_info[ci];
225
5.69M
        start_col = MCU_col_num * compptr->MCU_width;
226
11.5M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
5.89M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
12.0M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
6.12M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
6.12M
          }
231
5.89M
        }
232
5.69M
      }
233
5.30M
      if (!cinfo->entropy->insufficient_data)
234
2.01M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
5.30M
      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.30M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
672k
    coef->MCU_ctr = 0;
245
672k
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
645k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
644k
    start_iMCU_row(cinfo);
249
644k
    return JPEG_ROW_COMPLETED;
250
644k
  }
251
  /* Completed the scan */
252
1.37k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
1.37k
  return JPEG_SCAN_COMPLETED;
254
645k
}
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
576k
{
268
576k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
576k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
576k
  JDIMENSION block_num;
271
576k
  int ci, block_row, block_rows;
272
576k
  JBLOCKARRAY buffer;
273
576k
  JBLOCKROW buffer_ptr;
274
576k
  _JSAMPARRAY output_ptr;
275
576k
  JDIMENSION output_col;
276
576k
  jpeg_component_info *compptr;
277
576k
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
576k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
576k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
576k
          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.77M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
1.19M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
1.19M
    if (!compptr->component_needed)
292
0
      continue;
293
    /* Align the virtual buffer for this component. */
294
1.19M
    buffer = (*cinfo->mem->access_virt_barray)
295
1.19M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
1.19M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
1.19M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
1.19M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
1.19M
      block_rows = compptr->v_samp_factor;
301
3.04k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
3.04k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
3.04k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
3.04k
    }
306
1.19M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
1.19M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
2.55M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
1.35M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
1.35M
      output_col = 0;
312
1.35M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
14.5M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
13.2M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
13.2M
                        output_col);
316
13.2M
        buffer_ptr++;
317
13.2M
        output_col += compptr->_DCT_scaled_size;
318
13.2M
      }
319
1.35M
      output_ptr += compptr->_DCT_scaled_size;
320
1.35M
    }
321
1.19M
  }
322
323
576k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
575k
    return JPEG_ROW_COMPLETED;
325
1.48k
  return JPEG_SCAN_COMPLETED;
326
576k
}
jdcoefct-8.c:decompress_data
Line
Count
Source
267
576k
{
268
576k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
576k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
576k
  JDIMENSION block_num;
271
576k
  int ci, block_row, block_rows;
272
576k
  JBLOCKARRAY buffer;
273
576k
  JBLOCKROW buffer_ptr;
274
576k
  _JSAMPARRAY output_ptr;
275
576k
  JDIMENSION output_col;
276
576k
  jpeg_component_info *compptr;
277
576k
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
576k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
576k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
576k
          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.77M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
1.19M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
1.19M
    if (!compptr->component_needed)
292
0
      continue;
293
    /* Align the virtual buffer for this component. */
294
1.19M
    buffer = (*cinfo->mem->access_virt_barray)
295
1.19M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
1.19M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
1.19M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
1.19M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
1.19M
      block_rows = compptr->v_samp_factor;
301
3.04k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
3.04k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
3.04k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
3.04k
    }
306
1.19M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
1.19M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
2.55M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
1.35M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
1.35M
      output_col = 0;
312
1.35M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
14.5M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
13.2M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
13.2M
                        output_col);
316
13.2M
        buffer_ptr++;
317
13.2M
        output_col += compptr->_DCT_scaled_size;
318
13.2M
      }
319
1.35M
      output_ptr += compptr->_DCT_scaled_size;
320
1.35M
    }
321
1.19M
  }
322
323
576k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
575k
    return JPEG_ROW_COMPLETED;
325
1.48k
  return JPEG_SCAN_COMPLETED;
326
576k
}
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
390k
#define Q01_POS  1
342
390k
#define Q10_POS  8
343
390k
#define Q20_POS  16
344
390k
#define Q11_POS  9
345
390k
#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.39k
{
362
2.39k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
2.39k
  boolean smoothing_useful = FALSE;
364
2.39k
  int ci, coefi;
365
2.39k
  jpeg_component_info *compptr;
366
2.39k
  JQUANT_TBL *qtable;
367
2.39k
  int *coef_bits, *prev_coef_bits;
368
2.39k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
2.39k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
437
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
1.95k
  if (coef->coef_bits_latch == NULL)
375
1.95k
    coef->coef_bits_latch = (int *)
376
1.95k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
1.95k
                                  cinfo->num_components * 2 *
378
1.95k
                                  (SAVED_COEFS * sizeof(int)));
379
1.95k
  coef_bits_latch = coef->coef_bits_latch;
380
1.95k
  prev_coef_bits_latch =
381
1.95k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
2.87k
  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
287
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
1.92k
    if (qtable->quantval[0] == 0 ||
390
1.92k
        qtable->quantval[Q01_POS] == 0 ||
391
1.92k
        qtable->quantval[Q10_POS] == 0 ||
392
1.92k
        qtable->quantval[Q20_POS] == 0 ||
393
1.92k
        qtable->quantval[Q11_POS] == 0 ||
394
1.92k
        qtable->quantval[Q02_POS] == 0 ||
395
1.92k
        qtable->quantval[Q03_POS] == 0 ||
396
1.92k
        qtable->quantval[Q12_POS] == 0 ||
397
1.92k
        qtable->quantval[Q21_POS] == 0 ||
398
1.92k
        qtable->quantval[Q30_POS] == 0)
399
902
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
1.02k
    coef_bits = cinfo->coef_bits[ci];
402
1.02k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
1.02k
    if (coef_bits[0] < 0)
404
97
      return FALSE;
405
924
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
9.24k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
8.31k
      if (cinfo->input_scan_number > 1)
409
4.37k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
3.94k
      else
411
3.94k
        prev_coef_bits_latch[coefi] = -1;
412
8.31k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
8.31k
      if (coef_bits[coefi] != 0)
414
7.85k
        smoothing_useful = TRUE;
415
8.31k
    }
416
924
    coef_bits_latch += SAVED_COEFS;
417
924
    prev_coef_bits_latch += SAVED_COEFS;
418
924
  }
419
420
669
  return smoothing_useful;
421
1.95k
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
361
2.10k
{
362
2.10k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
2.10k
  boolean smoothing_useful = FALSE;
364
2.10k
  int ci, coefi;
365
2.10k
  jpeg_component_info *compptr;
366
2.10k
  JQUANT_TBL *qtable;
367
2.10k
  int *coef_bits, *prev_coef_bits;
368
2.10k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
2.10k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
389
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
1.71k
  if (coef->coef_bits_latch == NULL)
375
1.71k
    coef->coef_bits_latch = (int *)
376
1.71k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
1.71k
                                  cinfo->num_components * 2 *
378
1.71k
                                  (SAVED_COEFS * sizeof(int)));
379
1.71k
  coef_bits_latch = coef->coef_bits_latch;
380
1.71k
  prev_coef_bits_latch =
381
1.71k
    &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.94k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
1.94k
    if ((qtable = compptr->quant_table) == NULL)
387
270
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
1.67k
    if (qtable->quantval[0] == 0 ||
390
1.67k
        qtable->quantval[Q01_POS] == 0 ||
391
1.67k
        qtable->quantval[Q10_POS] == 0 ||
392
1.67k
        qtable->quantval[Q20_POS] == 0 ||
393
1.67k
        qtable->quantval[Q11_POS] == 0 ||
394
1.67k
        qtable->quantval[Q02_POS] == 0 ||
395
1.67k
        qtable->quantval[Q03_POS] == 0 ||
396
1.67k
        qtable->quantval[Q12_POS] == 0 ||
397
1.67k
        qtable->quantval[Q21_POS] == 0 ||
398
1.67k
        qtable->quantval[Q30_POS] == 0)
399
736
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
943
    coef_bits = cinfo->coef_bits[ci];
402
943
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
943
    if (coef_bits[0] < 0)
404
80
      return FALSE;
405
863
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
8.63k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
7.76k
      if (cinfo->input_scan_number > 1)
409
4.17k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
3.59k
      else
411
3.59k
        prev_coef_bits_latch[coefi] = -1;
412
7.76k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
7.76k
      if (coef_bits[coefi] != 0)
414
7.36k
        smoothing_useful = TRUE;
415
7.76k
    }
416
863
    coef_bits_latch += SAVED_COEFS;
417
863
    prev_coef_bits_latch += SAVED_COEFS;
418
863
  }
419
420
627
  return smoothing_useful;
421
1.71k
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
361
290
{
362
290
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
290
  boolean smoothing_useful = FALSE;
364
290
  int ci, coefi;
365
290
  jpeg_component_info *compptr;
366
290
  JQUANT_TBL *qtable;
367
290
  int *coef_bits, *prev_coef_bits;
368
290
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
290
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
48
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
242
  if (coef->coef_bits_latch == NULL)
375
242
    coef->coef_bits_latch = (int *)
376
242
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
242
                                  cinfo->num_components * 2 *
378
242
                                  (SAVED_COEFS * sizeof(int)));
379
242
  coef_bits_latch = coef->coef_bits_latch;
380
242
  prev_coef_bits_latch =
381
242
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
303
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
261
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
261
    if ((qtable = compptr->quant_table) == NULL)
387
17
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
244
    if (qtable->quantval[0] == 0 ||
390
244
        qtable->quantval[Q01_POS] == 0 ||
391
244
        qtable->quantval[Q10_POS] == 0 ||
392
244
        qtable->quantval[Q20_POS] == 0 ||
393
244
        qtable->quantval[Q11_POS] == 0 ||
394
244
        qtable->quantval[Q02_POS] == 0 ||
395
244
        qtable->quantval[Q03_POS] == 0 ||
396
244
        qtable->quantval[Q12_POS] == 0 ||
397
244
        qtable->quantval[Q21_POS] == 0 ||
398
244
        qtable->quantval[Q30_POS] == 0)
399
166
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
78
    coef_bits = cinfo->coef_bits[ci];
402
78
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
78
    if (coef_bits[0] < 0)
404
17
      return FALSE;
405
61
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
610
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
549
      if (cinfo->input_scan_number > 1)
409
198
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
351
      else
411
351
        prev_coef_bits_latch[coefi] = -1;
412
549
      coef_bits_latch[coefi] = coef_bits[coefi];
413
549
      if (coef_bits[coefi] != 0)
414
488
        smoothing_useful = TRUE;
415
549
    }
416
61
    coef_bits_latch += SAVED_COEFS;
417
61
    prev_coef_bits_latch += SAVED_COEFS;
418
61
  }
419
420
42
  return smoothing_useful;
421
242
}
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
283k
{
431
283k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
283k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
283k
  JDIMENSION block_num, last_block_column;
434
283k
  int ci, block_row, block_rows, access_rows, image_block_row,
435
283k
    image_block_rows;
436
283k
  JBLOCKARRAY buffer;
437
283k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
283k
  JBLOCKROW next_block_row, next_next_block_row;
439
283k
  _JSAMPARRAY output_ptr;
440
283k
  JDIMENSION output_col;
441
283k
  jpeg_component_info *compptr;
442
283k
  _inverse_DCT_method_ptr inverse_DCT;
443
283k
  boolean change_dc;
444
283k
  JCOEF *workspace;
445
283k
  int *coef_bits;
446
283k
  JQUANT_TBL *quanttbl;
447
283k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
283k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
283k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
283k
      DC25;
451
283k
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
283k
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
283k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
283k
         !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
672k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
388k
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
388k
    if (!compptr->component_needed)
478
0
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
388k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
387k
      block_rows = compptr->v_samp_factor;
482
387k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
387k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
732
      block_rows = compptr->v_samp_factor;
485
732
      access_rows = block_rows * 2; /* this and next iMCU row */
486
800
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
800
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
800
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
800
      access_rows = block_rows; /* this iMCU row only */
491
800
    }
492
    /* Align the virtual buffer for this component. */
493
388k
    if (cinfo->output_iMCU_row > 1) {
494
387k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
387k
      buffer = (*cinfo->mem->access_virt_barray)
496
387k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
387k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
387k
         (JDIMENSION)access_rows, FALSE);
499
387k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
387k
    } else if (cinfo->output_iMCU_row > 0) {
501
732
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
732
      buffer = (*cinfo->mem->access_virt_barray)
503
732
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
732
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
732
         (JDIMENSION)access_rows, FALSE);
506
732
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
800
    } else {
508
800
      buffer = (*cinfo->mem->access_virt_barray)
509
800
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
800
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
800
    }
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
388k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
193k
      coef_bits =
518
193k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
195k
    else
520
195k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
388k
    change_dc =
524
388k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
388k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
388k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
388k
    quanttbl = compptr->quant_table;
529
388k
    Q00 = quanttbl->quantval[0];
530
388k
    Q01 = quanttbl->quantval[Q01_POS];
531
388k
    Q10 = quanttbl->quantval[Q10_POS];
532
388k
    Q20 = quanttbl->quantval[Q20_POS];
533
388k
    Q11 = quanttbl->quantval[Q11_POS];
534
388k
    Q02 = quanttbl->quantval[Q02_POS];
535
388k
    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
388k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
388k
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
388k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
889k
    for (block_row = 0; block_row < block_rows; block_row++) {
546
501k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
501k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
501k
      if (image_block_row > 0)
550
500k
        prev_block_row =
551
500k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
800
      else
553
800
        prev_block_row = buffer_ptr;
554
555
501k
      if (image_block_row > 1)
556
499k
        prev_prev_block_row =
557
499k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
1.58k
      else
559
1.58k
        prev_prev_block_row = prev_block_row;
560
561
501k
      if (image_block_row < image_block_rows - 1)
562
500k
        next_block_row =
563
500k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
800
      else
565
800
        next_block_row = buffer_ptr;
566
567
501k
      if (image_block_row < image_block_rows - 2)
568
499k
        next_next_block_row =
569
499k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
1.47k
      else
571
1.47k
        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
501k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
501k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
501k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
501k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
501k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
501k
      output_col = 0;
582
501k
      last_block_column = compptr->width_in_blocks - 1;
583
501k
      for (block_num = cinfo->master->first_MCU_col[ci];
584
5.24M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
4.74M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
4.74M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
4.74M
            block_num < last_block_column) {
590
335k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
335k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
335k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
335k
          DC19 = DC20 = (int)next_block_row[1][0];
594
335k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
335k
        }
596
4.74M
        if (block_num + 1 < last_block_column) {
597
3.90M
          DC05 = (int)prev_prev_block_row[2][0];
598
3.90M
          DC10 = (int)prev_block_row[2][0];
599
3.90M
          DC15 = (int)buffer_ptr[2][0];
600
3.90M
          DC20 = (int)next_block_row[2][0];
601
3.90M
          DC25 = (int)next_next_block_row[2][0];
602
3.90M
        }
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.74M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
4.57M
          num = Q00 * (change_dc ?
616
3.23M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
3.23M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
3.23M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
3.23M
                 DC21 - DC22 + DC24 + DC25) :
620
4.57M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
4.57M
          if (num >= 0) {
622
3.59M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
3.59M
            if (Al > 0 && pred >= (1 << Al))
624
196k
              pred = (1 << Al) - 1;
625
3.59M
          } else {
626
983k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
983k
            if (Al > 0 && pred >= (1 << Al))
628
180k
              pred = (1 << Al) - 1;
629
983k
            pred = -pred;
630
983k
          }
631
4.57M
          workspace[1] = (JCOEF)pred;
632
4.57M
        }
633
        /* AC10 */
634
4.74M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
4.63M
          num = Q00 * (change_dc ?
636
3.23M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
3.23M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
3.23M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
3.23M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
4.63M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
4.63M
          if (num >= 0) {
642
3.42M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
3.42M
            if (Al > 0 && pred >= (1 << Al))
644
436k
              pred = (1 << Al) - 1;
645
3.42M
          } else {
646
1.20M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
1.20M
            if (Al > 0 && pred >= (1 << Al))
648
290k
              pred = (1 << Al) - 1;
649
1.20M
            pred = -pred;
650
1.20M
          }
651
4.63M
          workspace[8] = (JCOEF)pred;
652
4.63M
        }
653
        /* AC20 */
654
4.74M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
4.58M
          num = Q00 * (change_dc ?
656
3.23M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
3.23M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
4.58M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
4.58M
          if (num >= 0) {
660
2.99M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
2.99M
            if (Al > 0 && pred >= (1 << Al))
662
311k
              pred = (1 << Al) - 1;
663
2.99M
          } else {
664
1.59M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
1.59M
            if (Al > 0 && pred >= (1 << Al))
666
316k
              pred = (1 << Al) - 1;
667
1.59M
            pred = -pred;
668
1.59M
          }
669
4.58M
          workspace[16] = (JCOEF)pred;
670
4.58M
        }
671
        /* AC11 */
672
4.74M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
4.60M
          num = Q00 * (change_dc ?
674
3.23M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
3.23M
                 9 * DC19 + DC21 - DC25) :
676
4.60M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
1.36M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
4.60M
          if (num >= 0) {
679
3.82M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
3.82M
            if (Al > 0 && pred >= (1 << Al))
681
113k
              pred = (1 << Al) - 1;
682
3.82M
          } else {
683
777k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
777k
            if (Al > 0 && pred >= (1 << Al))
685
122k
              pred = (1 << Al) - 1;
686
777k
            pred = -pred;
687
777k
          }
688
4.60M
          workspace[9] = (JCOEF)pred;
689
4.60M
        }
690
        /* AC02 */
691
4.74M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
4.59M
          num = Q00 * (change_dc ?
693
3.23M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
3.23M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
4.59M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
4.59M
          if (num >= 0) {
697
2.99M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
2.99M
            if (Al > 0 && pred >= (1 << Al))
699
151k
              pred = (1 << Al) - 1;
700
2.99M
          } else {
701
1.59M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
1.59M
            if (Al > 0 && pred >= (1 << Al))
703
148k
              pred = (1 << Al) - 1;
704
1.59M
            pred = -pred;
705
1.59M
          }
706
4.59M
          workspace[2] = (JCOEF)pred;
707
4.59M
        }
708
4.74M
        if (change_dc) {
709
          /* AC03 */
710
3.23M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
3.23M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
3.23M
            if (num >= 0) {
713
2.65M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
2.65M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
2.65M
            } else {
717
575k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
575k
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
575k
              pred = -pred;
721
575k
            }
722
3.23M
            workspace[3] = (JCOEF)pred;
723
3.23M
          }
724
          /* AC12 */
725
3.23M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
3.23M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
3.23M
            if (num >= 0) {
728
2.12M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
2.12M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
2.12M
            } else {
732
1.10M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
1.10M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
1.10M
              pred = -pred;
736
1.10M
            }
737
3.23M
            workspace[10] = (JCOEF)pred;
738
3.23M
          }
739
          /* AC21 */
740
3.23M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
3.23M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
3.23M
            if (num >= 0) {
743
1.84M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
1.84M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
1.84M
            } else {
747
1.39M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
1.39M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
1.39M
              pred = -pred;
751
1.39M
            }
752
3.23M
            workspace[17] = (JCOEF)pred;
753
3.23M
          }
754
          /* AC30 */
755
3.23M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
3.23M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
3.23M
            if (num >= 0) {
758
2.48M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
2.48M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
2.48M
            } else {
762
746k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
746k
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
746k
              pred = -pred;
766
746k
            }
767
3.23M
            workspace[24] = (JCOEF)pred;
768
3.23M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
3.23M
          num = Q00 *
773
3.23M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
3.23M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
3.23M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
3.23M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
3.23M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
3.23M
          if (num >= 0) {
779
2.05M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
2.05M
          } else {
781
1.18M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
1.18M
            pred = -pred;
783
1.18M
          }
784
3.23M
          workspace[0] = (JCOEF)pred;
785
3.23M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
4.74M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
4.74M
                        output_col);
790
        /* Advance for next column */
791
4.74M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
4.74M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
4.74M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
4.74M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
4.74M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
4.74M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
4.74M
          prev_prev_block_row++, next_next_block_row++;
798
4.74M
        output_col += compptr->_DCT_scaled_size;
799
4.74M
      }
800
501k
      output_ptr += compptr->_DCT_scaled_size;
801
501k
    }
802
388k
  }
803
804
283k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
283k
    return JPEG_ROW_COMPLETED;
806
618
  return JPEG_SCAN_COMPLETED;
807
283k
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
430
283k
{
431
283k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
283k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
283k
  JDIMENSION block_num, last_block_column;
434
283k
  int ci, block_row, block_rows, access_rows, image_block_row,
435
283k
    image_block_rows;
436
283k
  JBLOCKARRAY buffer;
437
283k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
283k
  JBLOCKROW next_block_row, next_next_block_row;
439
283k
  _JSAMPARRAY output_ptr;
440
283k
  JDIMENSION output_col;
441
283k
  jpeg_component_info *compptr;
442
283k
  _inverse_DCT_method_ptr inverse_DCT;
443
283k
  boolean change_dc;
444
283k
  JCOEF *workspace;
445
283k
  int *coef_bits;
446
283k
  JQUANT_TBL *quanttbl;
447
283k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
283k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
283k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
283k
      DC25;
451
283k
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
283k
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
283k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
283k
         !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
672k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
388k
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
388k
    if (!compptr->component_needed)
478
0
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
388k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
387k
      block_rows = compptr->v_samp_factor;
482
387k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
387k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
732
      block_rows = compptr->v_samp_factor;
485
732
      access_rows = block_rows * 2; /* this and next iMCU row */
486
800
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
800
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
800
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
800
      access_rows = block_rows; /* this iMCU row only */
491
800
    }
492
    /* Align the virtual buffer for this component. */
493
388k
    if (cinfo->output_iMCU_row > 1) {
494
387k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
387k
      buffer = (*cinfo->mem->access_virt_barray)
496
387k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
387k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
387k
         (JDIMENSION)access_rows, FALSE);
499
387k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
387k
    } else if (cinfo->output_iMCU_row > 0) {
501
732
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
732
      buffer = (*cinfo->mem->access_virt_barray)
503
732
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
732
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
732
         (JDIMENSION)access_rows, FALSE);
506
732
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
800
    } else {
508
800
      buffer = (*cinfo->mem->access_virt_barray)
509
800
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
800
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
800
    }
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
388k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
193k
      coef_bits =
518
193k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
195k
    else
520
195k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
388k
    change_dc =
524
388k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
388k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
388k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
388k
    quanttbl = compptr->quant_table;
529
388k
    Q00 = quanttbl->quantval[0];
530
388k
    Q01 = quanttbl->quantval[Q01_POS];
531
388k
    Q10 = quanttbl->quantval[Q10_POS];
532
388k
    Q20 = quanttbl->quantval[Q20_POS];
533
388k
    Q11 = quanttbl->quantval[Q11_POS];
534
388k
    Q02 = quanttbl->quantval[Q02_POS];
535
388k
    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
388k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
388k
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
388k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
889k
    for (block_row = 0; block_row < block_rows; block_row++) {
546
501k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
501k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
501k
      if (image_block_row > 0)
550
500k
        prev_block_row =
551
500k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
800
      else
553
800
        prev_block_row = buffer_ptr;
554
555
501k
      if (image_block_row > 1)
556
499k
        prev_prev_block_row =
557
499k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
1.58k
      else
559
1.58k
        prev_prev_block_row = prev_block_row;
560
561
501k
      if (image_block_row < image_block_rows - 1)
562
500k
        next_block_row =
563
500k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
800
      else
565
800
        next_block_row = buffer_ptr;
566
567
501k
      if (image_block_row < image_block_rows - 2)
568
499k
        next_next_block_row =
569
499k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
1.47k
      else
571
1.47k
        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
501k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
501k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
501k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
501k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
501k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
501k
      output_col = 0;
582
501k
      last_block_column = compptr->width_in_blocks - 1;
583
501k
      for (block_num = cinfo->master->first_MCU_col[ci];
584
5.24M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
4.74M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
4.74M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
4.74M
            block_num < last_block_column) {
590
335k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
335k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
335k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
335k
          DC19 = DC20 = (int)next_block_row[1][0];
594
335k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
335k
        }
596
4.74M
        if (block_num + 1 < last_block_column) {
597
3.90M
          DC05 = (int)prev_prev_block_row[2][0];
598
3.90M
          DC10 = (int)prev_block_row[2][0];
599
3.90M
          DC15 = (int)buffer_ptr[2][0];
600
3.90M
          DC20 = (int)next_block_row[2][0];
601
3.90M
          DC25 = (int)next_next_block_row[2][0];
602
3.90M
        }
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.74M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
4.57M
          num = Q00 * (change_dc ?
616
3.23M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
3.23M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
3.23M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
3.23M
                 DC21 - DC22 + DC24 + DC25) :
620
4.57M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
4.57M
          if (num >= 0) {
622
3.59M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
3.59M
            if (Al > 0 && pred >= (1 << Al))
624
196k
              pred = (1 << Al) - 1;
625
3.59M
          } else {
626
983k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
983k
            if (Al > 0 && pred >= (1 << Al))
628
180k
              pred = (1 << Al) - 1;
629
983k
            pred = -pred;
630
983k
          }
631
4.57M
          workspace[1] = (JCOEF)pred;
632
4.57M
        }
633
        /* AC10 */
634
4.74M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
4.63M
          num = Q00 * (change_dc ?
636
3.23M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
3.23M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
3.23M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
3.23M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
4.63M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
4.63M
          if (num >= 0) {
642
3.42M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
3.42M
            if (Al > 0 && pred >= (1 << Al))
644
436k
              pred = (1 << Al) - 1;
645
3.42M
          } else {
646
1.20M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
1.20M
            if (Al > 0 && pred >= (1 << Al))
648
290k
              pred = (1 << Al) - 1;
649
1.20M
            pred = -pred;
650
1.20M
          }
651
4.63M
          workspace[8] = (JCOEF)pred;
652
4.63M
        }
653
        /* AC20 */
654
4.74M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
4.58M
          num = Q00 * (change_dc ?
656
3.23M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
3.23M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
4.58M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
4.58M
          if (num >= 0) {
660
2.99M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
2.99M
            if (Al > 0 && pred >= (1 << Al))
662
311k
              pred = (1 << Al) - 1;
663
2.99M
          } else {
664
1.59M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
1.59M
            if (Al > 0 && pred >= (1 << Al))
666
316k
              pred = (1 << Al) - 1;
667
1.59M
            pred = -pred;
668
1.59M
          }
669
4.58M
          workspace[16] = (JCOEF)pred;
670
4.58M
        }
671
        /* AC11 */
672
4.74M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
4.60M
          num = Q00 * (change_dc ?
674
3.23M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
3.23M
                 9 * DC19 + DC21 - DC25) :
676
4.60M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
1.36M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
4.60M
          if (num >= 0) {
679
3.82M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
3.82M
            if (Al > 0 && pred >= (1 << Al))
681
113k
              pred = (1 << Al) - 1;
682
3.82M
          } else {
683
777k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
777k
            if (Al > 0 && pred >= (1 << Al))
685
122k
              pred = (1 << Al) - 1;
686
777k
            pred = -pred;
687
777k
          }
688
4.60M
          workspace[9] = (JCOEF)pred;
689
4.60M
        }
690
        /* AC02 */
691
4.74M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
4.59M
          num = Q00 * (change_dc ?
693
3.23M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
3.23M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
4.59M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
4.59M
          if (num >= 0) {
697
2.99M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
2.99M
            if (Al > 0 && pred >= (1 << Al))
699
151k
              pred = (1 << Al) - 1;
700
2.99M
          } else {
701
1.59M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
1.59M
            if (Al > 0 && pred >= (1 << Al))
703
148k
              pred = (1 << Al) - 1;
704
1.59M
            pred = -pred;
705
1.59M
          }
706
4.59M
          workspace[2] = (JCOEF)pred;
707
4.59M
        }
708
4.74M
        if (change_dc) {
709
          /* AC03 */
710
3.23M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
3.23M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
3.23M
            if (num >= 0) {
713
2.65M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
2.65M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
2.65M
            } else {
717
575k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
575k
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
575k
              pred = -pred;
721
575k
            }
722
3.23M
            workspace[3] = (JCOEF)pred;
723
3.23M
          }
724
          /* AC12 */
725
3.23M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
3.23M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
3.23M
            if (num >= 0) {
728
2.12M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
2.12M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
2.12M
            } else {
732
1.10M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
1.10M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
1.10M
              pred = -pred;
736
1.10M
            }
737
3.23M
            workspace[10] = (JCOEF)pred;
738
3.23M
          }
739
          /* AC21 */
740
3.23M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
3.23M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
3.23M
            if (num >= 0) {
743
1.84M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
1.84M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
1.84M
            } else {
747
1.39M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
1.39M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
1.39M
              pred = -pred;
751
1.39M
            }
752
3.23M
            workspace[17] = (JCOEF)pred;
753
3.23M
          }
754
          /* AC30 */
755
3.23M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
3.23M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
3.23M
            if (num >= 0) {
758
2.48M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
2.48M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
2.48M
            } else {
762
746k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
746k
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
746k
              pred = -pred;
766
746k
            }
767
3.23M
            workspace[24] = (JCOEF)pred;
768
3.23M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
3.23M
          num = Q00 *
773
3.23M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
3.23M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
3.23M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
3.23M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
3.23M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
3.23M
          if (num >= 0) {
779
2.05M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
2.05M
          } else {
781
1.18M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
1.18M
            pred = -pred;
783
1.18M
          }
784
3.23M
          workspace[0] = (JCOEF)pred;
785
3.23M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
4.74M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
4.74M
                        output_col);
790
        /* Advance for next column */
791
4.74M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
4.74M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
4.74M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
4.74M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
4.74M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
4.74M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
4.74M
          prev_prev_block_row++, next_next_block_row++;
798
4.74M
        output_col += compptr->_DCT_scaled_size;
799
4.74M
      }
800
501k
      output_ptr += compptr->_DCT_scaled_size;
801
501k
    }
802
388k
  }
803
804
283k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
283k
    return JPEG_ROW_COMPLETED;
806
618
  return JPEG_SCAN_COMPLETED;
807
283k
}
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.00k
{
819
5.00k
  my_coef_ptr coef;
820
821
5.00k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
5.00k
  coef = (my_coef_ptr)
825
5.00k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
5.00k
                                sizeof(my_coef_controller));
827
5.00k
  memset(coef, 0, sizeof(my_coef_controller));
828
5.00k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
5.00k
  coef->pub.start_input_pass = start_input_pass;
830
5.00k
  coef->pub.start_output_pass = start_output_pass;
831
5.00k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
5.00k
  coef->coef_bits_latch = NULL;
833
5.00k
#endif
834
835
  /* Create the coefficient buffer. */
836
5.00k
  if (need_full_buffer) {
837
3.15k
#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.15k
    int ci, access_rows;
842
3.15k
    jpeg_component_info *compptr;
843
844
8.66k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
5.51k
         ci++, compptr++) {
846
5.51k
      access_rows = compptr->v_samp_factor;
847
5.51k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
5.51k
      if (cinfo->progressive_mode)
850
3.74k
        access_rows *= 5;
851
5.51k
#endif
852
5.51k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
5.51k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
5.51k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
5.51k
                               (long)compptr->h_samp_factor),
856
5.51k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
5.51k
                               (long)compptr->v_samp_factor),
858
5.51k
         (JDIMENSION)access_rows);
859
5.51k
    }
860
3.15k
    coef->pub.consume_data = consume_data;
861
3.15k
    coef->pub._decompress_data = decompress_data;
862
3.15k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
3.15k
  } else {
867
    /* We only need a single-MCU buffer. */
868
1.85k
    JBLOCKROW buffer;
869
1.85k
    int i;
870
871
1.85k
    buffer = (JBLOCKROW)
872
1.85k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
1.85k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
20.4k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
18.5k
      coef->MCU_buffer[i] = buffer + i;
876
18.5k
    }
877
1.85k
    coef->pub.consume_data = dummy_consume_data;
878
1.85k
    coef->pub._decompress_data = decompress_onepass;
879
1.85k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
1.85k
  }
881
882
  /* Allocate the workspace buffer */
883
5.00k
  coef->workspace = (JCOEF *)
884
5.00k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
5.00k
                                sizeof(JCOEF) * DCTSIZE2);
886
5.00k
}
jinit_d_coef_controller
Line
Count
Source
818
4.65k
{
819
4.65k
  my_coef_ptr coef;
820
821
4.65k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
4.65k
  coef = (my_coef_ptr)
825
4.65k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
4.65k
                                sizeof(my_coef_controller));
827
4.65k
  memset(coef, 0, sizeof(my_coef_controller));
828
4.65k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
4.65k
  coef->pub.start_input_pass = start_input_pass;
830
4.65k
  coef->pub.start_output_pass = start_output_pass;
831
4.65k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
4.65k
  coef->coef_bits_latch = NULL;
833
4.65k
#endif
834
835
  /* Create the coefficient buffer. */
836
4.65k
  if (need_full_buffer) {
837
2.81k
#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.81k
    int ci, access_rows;
842
2.81k
    jpeg_component_info *compptr;
843
844
7.75k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
4.93k
         ci++, compptr++) {
846
4.93k
      access_rows = compptr->v_samp_factor;
847
4.93k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
4.93k
      if (cinfo->progressive_mode)
850
3.36k
        access_rows *= 5;
851
4.93k
#endif
852
4.93k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
4.93k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
4.93k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
4.93k
                               (long)compptr->h_samp_factor),
856
4.93k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
4.93k
                               (long)compptr->v_samp_factor),
858
4.93k
         (JDIMENSION)access_rows);
859
4.93k
    }
860
2.81k
    coef->pub.consume_data = consume_data;
861
2.81k
    coef->pub._decompress_data = decompress_data;
862
2.81k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
2.81k
  } else {
867
    /* We only need a single-MCU buffer. */
868
1.83k
    JBLOCKROW buffer;
869
1.83k
    int i;
870
871
1.83k
    buffer = (JBLOCKROW)
872
1.83k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
1.83k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
20.2k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
18.3k
      coef->MCU_buffer[i] = buffer + i;
876
18.3k
    }
877
1.83k
    coef->pub.consume_data = dummy_consume_data;
878
1.83k
    coef->pub._decompress_data = decompress_onepass;
879
1.83k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
1.83k
  }
881
882
  /* Allocate the workspace buffer */
883
4.65k
  coef->workspace = (JCOEF *)
884
4.65k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
4.65k
                                sizeof(JCOEF) * DCTSIZE2);
886
4.65k
}
j12init_d_coef_controller
Line
Count
Source
818
350
{
819
350
  my_coef_ptr coef;
820
821
350
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
350
  coef = (my_coef_ptr)
825
350
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
350
                                sizeof(my_coef_controller));
827
350
  memset(coef, 0, sizeof(my_coef_controller));
828
350
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
350
  coef->pub.start_input_pass = start_input_pass;
830
350
  coef->pub.start_output_pass = start_output_pass;
831
350
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
350
  coef->coef_bits_latch = NULL;
833
350
#endif
834
835
  /* Create the coefficient buffer. */
836
350
  if (need_full_buffer) {
837
332
#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
332
    int ci, access_rows;
842
332
    jpeg_component_info *compptr;
843
844
906
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
574
         ci++, compptr++) {
846
574
      access_rows = compptr->v_samp_factor;
847
574
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
574
      if (cinfo->progressive_mode)
850
376
        access_rows *= 5;
851
574
#endif
852
574
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
574
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
574
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
574
                               (long)compptr->h_samp_factor),
856
574
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
574
                               (long)compptr->v_samp_factor),
858
574
         (JDIMENSION)access_rows);
859
574
    }
860
332
    coef->pub.consume_data = consume_data;
861
332
    coef->pub._decompress_data = decompress_data;
862
332
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
332
  } else {
867
    /* We only need a single-MCU buffer. */
868
18
    JBLOCKROW buffer;
869
18
    int i;
870
871
18
    buffer = (JBLOCKROW)
872
18
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
18
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
198
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
180
      coef->MCU_buffer[i] = buffer + i;
876
180
    }
877
18
    coef->pub.consume_data = dummy_consume_data;
878
18
    coef->pub._decompress_data = decompress_onepass;
879
18
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
18
  }
881
882
  /* Allocate the workspace buffer */
883
350
  coef->workspace = (JCOEF *)
884
350
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
350
                                sizeof(JCOEF) * DCTSIZE2);
886
350
}