Coverage Report

Created: 2025-07-11 07:00

/src/libjpeg-turbo/src/jdcoefct.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * jdcoefct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1997, Thomas G. Lane.
6
 * libjpeg-turbo Modifications:
7
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
8
 * Copyright (C) 2010, 2015-2016, 2019-2020, 2022-2024, D. R. Commander.
9
 * Copyright (C) 2015, 2020, Google, Inc.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the coefficient buffer controller for decompression.
14
 * This controller is the top level of the lossy JPEG decompressor proper.
15
 * The coefficient buffer lies between entropy decoding and inverse-DCT steps.
16
 *
17
 * In buffered-image mode, this controller is the interface between
18
 * input-oriented processing and output-oriented processing.
19
 * Also, the input side (only) is used when reading a file for transcoding.
20
 */
21
22
#include "jinclude.h"
23
#include "jdcoefct.h"
24
#include "jpegapicomp.h"
25
#include "jsamplecomp.h"
26
27
28
/* Forward declarations */
29
METHODDEF(int) decompress_onepass(j_decompress_ptr cinfo,
30
                                  _JSAMPIMAGE output_buf);
31
#ifdef D_MULTISCAN_FILES_SUPPORTED
32
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
33
#endif
34
#ifdef BLOCK_SMOOTHING_SUPPORTED
35
LOCAL(boolean) smoothing_ok(j_decompress_ptr cinfo);
36
METHODDEF(int) decompress_smooth_data(j_decompress_ptr cinfo,
37
                                      _JSAMPIMAGE output_buf);
38
#endif
39
40
41
/*
42
 * Initialize for an input processing pass.
43
 */
44
45
METHODDEF(void)
46
start_input_pass(j_decompress_ptr cinfo)
47
8.19k
{
48
8.19k
  cinfo->input_iMCU_row = 0;
49
8.19k
  start_iMCU_row(cinfo);
50
8.19k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
47
6.93k
{
48
6.93k
  cinfo->input_iMCU_row = 0;
49
6.93k
  start_iMCU_row(cinfo);
50
6.93k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
47
1.26k
{
48
1.26k
  cinfo->input_iMCU_row = 0;
49
1.26k
  start_iMCU_row(cinfo);
50
1.26k
}
51
52
53
/*
54
 * Initialize for an output processing pass.
55
 */
56
57
METHODDEF(void)
58
start_output_pass(j_decompress_ptr cinfo)
59
2.38k
{
60
2.38k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
2.38k
  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.38k
  if (coef->pub.coef_arrays != NULL) {
65
607
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
442
      coef->pub._decompress_data = decompress_smooth_data;
67
165
    else
68
165
      coef->pub._decompress_data = decompress_data;
69
607
  }
70
2.38k
#endif
71
2.38k
  cinfo->output_iMCU_row = 0;
72
2.38k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
59
2.35k
{
60
2.35k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
2.35k
  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.35k
  if (coef->pub.coef_arrays != NULL) {
65
583
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
436
      coef->pub._decompress_data = decompress_smooth_data;
67
147
    else
68
147
      coef->pub._decompress_data = decompress_data;
69
583
  }
70
2.35k
#endif
71
2.35k
  cinfo->output_iMCU_row = 0;
72
2.35k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
59
31
{
60
31
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
31
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
62
63
  /* If multipass, check to see whether to use block smoothing on this pass */
64
31
  if (coef->pub.coef_arrays != NULL) {
65
24
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
6
      coef->pub._decompress_data = decompress_smooth_data;
67
18
    else
68
18
      coef->pub._decompress_data = decompress_data;
69
24
  }
70
31
#endif
71
31
  cinfo->output_iMCU_row = 0;
72
31
}
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
127k
{
88
127k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
127k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
127k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
127k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
127k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
127k
  _JSAMPARRAY output_ptr;
94
127k
  JDIMENSION start_col, output_col;
95
127k
  jpeg_component_info *compptr;
96
127k
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
254k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
127k
       yoffset++) {
101
2.21M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
2.09M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
2.09M
      jzero_far((void *)coef->MCU_buffer[0],
105
2.09M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
2.09M
      if (!cinfo->entropy->insufficient_data)
107
2.09M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
2.09M
      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
2.09M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
2.09M
          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
2.09M
        blkn = 0;               /* index of current DCT block within MCU */
126
7.79M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
5.69M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
5.69M
          if (!compptr->component_needed) {
130
0
            blkn += compptr->MCU_blocks;
131
0
            continue;
132
0
          }
133
5.69M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
5.69M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
5.33M
                         compptr->MCU_width : compptr->last_col_width;
136
5.69M
          output_ptr = output_buf[compptr->component_index] +
137
5.69M
                       yoffset * compptr->_DCT_scaled_size;
138
5.69M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
5.69M
                      compptr->MCU_sample_width;
140
13.6M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
7.99M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
7.99M
                yoffset + yindex < compptr->last_row_height) {
143
7.85M
              output_col = start_col;
144
18.9M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
11.0M
                (*inverse_DCT) (cinfo, compptr,
146
11.0M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
11.0M
                                output_ptr, output_col);
148
11.0M
                output_col += compptr->_DCT_scaled_size;
149
11.0M
              }
150
7.85M
            }
151
7.99M
            blkn += compptr->MCU_width;
152
7.99M
            output_ptr += compptr->_DCT_scaled_size;
153
7.99M
          }
154
5.69M
        }
155
2.09M
      }
156
2.09M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
127k
    coef->MCU_ctr = 0;
159
127k
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
127k
  cinfo->output_iMCU_row++;
162
127k
  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
1.76k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
1.76k
  return JPEG_SCAN_COMPLETED;
169
127k
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
87
127k
{
88
127k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
127k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
127k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
127k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
127k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
127k
  _JSAMPARRAY output_ptr;
94
127k
  JDIMENSION start_col, output_col;
95
127k
  jpeg_component_info *compptr;
96
127k
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
254k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
127k
       yoffset++) {
101
2.21M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
2.09M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
2.09M
      jzero_far((void *)coef->MCU_buffer[0],
105
2.09M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
2.09M
      if (!cinfo->entropy->insufficient_data)
107
2.09M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
2.09M
      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
2.09M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
2.09M
          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
2.09M
        blkn = 0;               /* index of current DCT block within MCU */
126
7.79M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
5.69M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
5.69M
          if (!compptr->component_needed) {
130
0
            blkn += compptr->MCU_blocks;
131
0
            continue;
132
0
          }
133
5.69M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
5.69M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
5.33M
                         compptr->MCU_width : compptr->last_col_width;
136
5.69M
          output_ptr = output_buf[compptr->component_index] +
137
5.69M
                       yoffset * compptr->_DCT_scaled_size;
138
5.69M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
5.69M
                      compptr->MCU_sample_width;
140
13.6M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
7.99M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
7.99M
                yoffset + yindex < compptr->last_row_height) {
143
7.85M
              output_col = start_col;
144
18.9M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
11.0M
                (*inverse_DCT) (cinfo, compptr,
146
11.0M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
11.0M
                                output_ptr, output_col);
148
11.0M
                output_col += compptr->_DCT_scaled_size;
149
11.0M
              }
150
7.85M
            }
151
7.99M
            blkn += compptr->MCU_width;
152
7.99M
            output_ptr += compptr->_DCT_scaled_size;
153
7.99M
          }
154
5.69M
        }
155
2.09M
      }
156
2.09M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
127k
    coef->MCU_ctr = 0;
159
127k
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
127k
  cinfo->output_iMCU_row++;
162
127k
  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
1.76k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
1.76k
  return JPEG_SCAN_COMPLETED;
169
127k
}
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
1.24M
{
195
1.24M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
1.24M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
1.24M
  int blkn, ci, xindex, yindex, yoffset;
198
1.24M
  JDIMENSION start_col;
199
1.24M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
1.24M
  JBLOCKROW buffer_ptr;
201
1.24M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
3.99M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
2.75M
    compptr = cinfo->cur_comp_info[ci];
206
2.75M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
2.75M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
2.75M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
2.75M
       (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
2.75M
  }
215
216
  /* Loop to process one whole iMCU row */
217
2.78M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
1.54M
       yoffset++) {
219
21.1M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
19.5M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
19.5M
      blkn = 0;                 /* index of current DCT block within MCU */
223
51.0M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
31.4M
        compptr = cinfo->cur_comp_info[ci];
225
31.4M
        start_col = MCU_col_num * compptr->MCU_width;
226
72.9M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
41.4M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
95.4M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
53.9M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
53.9M
          }
231
41.4M
        }
232
31.4M
      }
233
19.5M
      if (!cinfo->entropy->insufficient_data)
234
19.5M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
19.5M
      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
19.5M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
1.54M
    coef->MCU_ctr = 0;
245
1.54M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
1.24M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
1.23M
    start_iMCU_row(cinfo);
249
1.23M
    return JPEG_ROW_COMPLETED;
250
1.23M
  }
251
  /* Completed the scan */
252
6.41k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
6.41k
  return JPEG_SCAN_COMPLETED;
254
1.24M
}
jdcoefct-8.c:consume_data
Line
Count
Source
194
687k
{
195
687k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
687k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
687k
  int blkn, ci, xindex, yindex, yoffset;
198
687k
  JDIMENSION start_col;
199
687k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
687k
  JBLOCKROW buffer_ptr;
201
687k
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
2.39M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
1.70M
    compptr = cinfo->cur_comp_info[ci];
206
1.70M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
1.70M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
1.70M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
1.70M
       (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
1.70M
  }
215
216
  /* Loop to process one whole iMCU row */
217
1.39M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
703k
       yoffset++) {
219
9.52M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
8.81M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
8.81M
      blkn = 0;                 /* index of current DCT block within MCU */
223
27.4M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
18.6M
        compptr = cinfo->cur_comp_info[ci];
225
18.6M
        start_col = MCU_col_num * compptr->MCU_width;
226
46.2M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
27.6M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
61.9M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
34.3M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
34.3M
          }
231
27.6M
        }
232
18.6M
      }
233
8.81M
      if (!cinfo->entropy->insufficient_data)
234
8.81M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
8.81M
      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
8.81M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
703k
    coef->MCU_ctr = 0;
245
703k
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
687k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
682k
    start_iMCU_row(cinfo);
249
682k
    return JPEG_ROW_COMPLETED;
250
682k
  }
251
  /* Completed the scan */
252
5.16k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
5.16k
  return JPEG_SCAN_COMPLETED;
254
687k
}
jdcoefct-12.c:consume_data
Line
Count
Source
194
553k
{
195
553k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
553k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
553k
  int blkn, ci, xindex, yindex, yoffset;
198
553k
  JDIMENSION start_col;
199
553k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
553k
  JBLOCKROW buffer_ptr;
201
553k
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
1.59M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
1.04M
    compptr = cinfo->cur_comp_info[ci];
206
1.04M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
1.04M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
1.04M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
1.04M
       (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
1.04M
  }
215
216
  /* Loop to process one whole iMCU row */
217
1.39M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
845k
       yoffset++) {
219
11.5M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
10.7M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
10.7M
      blkn = 0;                 /* index of current DCT block within MCU */
223
23.5M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
12.7M
        compptr = cinfo->cur_comp_info[ci];
225
12.7M
        start_col = MCU_col_num * compptr->MCU_width;
226
26.6M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
13.8M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
33.4M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
19.6M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
19.6M
          }
231
13.8M
        }
232
12.7M
      }
233
10.7M
      if (!cinfo->entropy->insufficient_data)
234
10.7M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
10.7M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
237
        /* Suspension forced; update state counters and exit */
238
0
        coef->MCU_vert_offset = yoffset;
239
0
        coef->MCU_ctr = MCU_col_num;
240
0
        return JPEG_SUSPENDED;
241
0
      }
242
10.7M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
845k
    coef->MCU_ctr = 0;
245
845k
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
553k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
551k
    start_iMCU_row(cinfo);
249
551k
    return JPEG_ROW_COMPLETED;
250
551k
  }
251
  /* Completed the scan */
252
1.25k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
1.25k
  return JPEG_SCAN_COMPLETED;
254
553k
}
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
21.9k
{
268
21.9k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
21.9k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
21.9k
  JDIMENSION block_num;
271
21.9k
  int ci, block_row, block_rows;
272
21.9k
  JBLOCKARRAY buffer;
273
21.9k
  JBLOCKROW buffer_ptr;
274
21.9k
  _JSAMPARRAY output_ptr;
275
21.9k
  JDIMENSION output_col;
276
21.9k
  jpeg_component_info *compptr;
277
21.9k
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
21.9k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
21.9k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
21.9k
          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
87.9k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
66.0k
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
66.0k
    if (!compptr->component_needed)
292
0
      continue;
293
    /* Align the virtual buffer for this component. */
294
66.0k
    buffer = (*cinfo->mem->access_virt_barray)
295
66.0k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
66.0k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
66.0k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
66.0k
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
65.5k
      block_rows = compptr->v_samp_factor;
301
442
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
442
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
442
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
442
    }
306
66.0k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
66.0k
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
170k
    for (block_row = 0; block_row < block_rows; block_row++) {
310
104k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
104k
      output_col = 0;
312
104k
      for (block_num = cinfo->master->first_MCU_col[ci];
313
1.29M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
1.19M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
1.19M
                        output_col);
316
1.19M
        buffer_ptr++;
317
1.19M
        output_col += compptr->_DCT_scaled_size;
318
1.19M
      }
319
104k
      output_ptr += compptr->_DCT_scaled_size;
320
104k
    }
321
66.0k
  }
322
323
21.9k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
21.7k
    return JPEG_ROW_COMPLETED;
325
147
  return JPEG_SCAN_COMPLETED;
326
21.9k
}
jdcoefct-8.c:decompress_data
Line
Count
Source
267
21.9k
{
268
21.9k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
21.9k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
21.9k
  JDIMENSION block_num;
271
21.9k
  int ci, block_row, block_rows;
272
21.9k
  JBLOCKARRAY buffer;
273
21.9k
  JBLOCKROW buffer_ptr;
274
21.9k
  _JSAMPARRAY output_ptr;
275
21.9k
  JDIMENSION output_col;
276
21.9k
  jpeg_component_info *compptr;
277
21.9k
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
21.9k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
21.9k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
21.9k
          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
87.9k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
66.0k
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
66.0k
    if (!compptr->component_needed)
292
0
      continue;
293
    /* Align the virtual buffer for this component. */
294
66.0k
    buffer = (*cinfo->mem->access_virt_barray)
295
66.0k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
66.0k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
66.0k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
66.0k
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
65.5k
      block_rows = compptr->v_samp_factor;
301
442
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
442
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
442
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
442
    }
306
66.0k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
66.0k
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
170k
    for (block_row = 0; block_row < block_rows; block_row++) {
310
104k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
104k
      output_col = 0;
312
104k
      for (block_num = cinfo->master->first_MCU_col[ci];
313
1.29M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
1.19M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
1.19M
                        output_col);
316
1.19M
        buffer_ptr++;
317
1.19M
        output_col += compptr->_DCT_scaled_size;
318
1.19M
      }
319
104k
      output_ptr += compptr->_DCT_scaled_size;
320
104k
    }
321
66.0k
  }
322
323
21.9k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
21.7k
    return JPEG_ROW_COMPLETED;
325
147
  return JPEG_SCAN_COMPLETED;
326
21.9k
}
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
524k
#define Q01_POS  1
342
524k
#define Q10_POS  8
343
524k
#define Q20_POS  16
344
524k
#define Q11_POS  9
345
524k
#define Q02_POS  2
346
423k
#define Q03_POS  3
347
423k
#define Q12_POS  10
348
423k
#define Q21_POS  17
349
423k
#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
607
{
362
607
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
607
  boolean smoothing_useful = FALSE;
364
607
  int ci, coefi;
365
607
  jpeg_component_info *compptr;
366
607
  JQUANT_TBL *qtable;
367
607
  int *coef_bits, *prev_coef_bits;
368
607
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
607
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
2
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
605
  if (coef->coef_bits_latch == NULL)
375
605
    coef->coef_bits_latch = (int *)
376
605
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
605
                                  cinfo->num_components * 2 *
378
605
                                  (SAVED_COEFS * sizeof(int)));
379
605
  coef_bits_latch = coef->coef_bits_latch;
380
605
  prev_coef_bits_latch =
381
605
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
2.25k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
1.71k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
1.71k
    if ((qtable = compptr->quant_table) == NULL)
387
5
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
1.71k
    if (qtable->quantval[0] == 0 ||
390
1.71k
        qtable->quantval[Q01_POS] == 0 ||
391
1.71k
        qtable->quantval[Q10_POS] == 0 ||
392
1.71k
        qtable->quantval[Q20_POS] == 0 ||
393
1.71k
        qtable->quantval[Q11_POS] == 0 ||
394
1.71k
        qtable->quantval[Q02_POS] == 0 ||
395
1.71k
        qtable->quantval[Q03_POS] == 0 ||
396
1.71k
        qtable->quantval[Q12_POS] == 0 ||
397
1.71k
        qtable->quantval[Q21_POS] == 0 ||
398
1.71k
        qtable->quantval[Q30_POS] == 0)
399
66
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
1.64k
    coef_bits = cinfo->coef_bits[ci];
402
1.64k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
1.64k
    if (coef_bits[0] < 0)
404
0
      return FALSE;
405
1.64k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
16.4k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
14.8k
      if (cinfo->input_scan_number > 1)
409
10.3k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
4.50k
      else
411
4.50k
        prev_coef_bits_latch[coefi] = -1;
412
14.8k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
14.8k
      if (coef_bits[coefi] != 0)
414
12.1k
        smoothing_useful = TRUE;
415
14.8k
    }
416
1.64k
    coef_bits_latch += SAVED_COEFS;
417
1.64k
    prev_coef_bits_latch += SAVED_COEFS;
418
1.64k
  }
419
420
534
  return smoothing_useful;
421
605
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
361
583
{
362
583
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
583
  boolean smoothing_useful = FALSE;
364
583
  int ci, coefi;
365
583
  jpeg_component_info *compptr;
366
583
  JQUANT_TBL *qtable;
367
583
  int *coef_bits, *prev_coef_bits;
368
583
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
583
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
2
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
581
  if (coef->coef_bits_latch == NULL)
375
581
    coef->coef_bits_latch = (int *)
376
581
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
581
                                  cinfo->num_components * 2 *
378
581
                                  (SAVED_COEFS * sizeof(int)));
379
581
  coef_bits_latch = coef->coef_bits_latch;
380
581
  prev_coef_bits_latch =
381
581
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
2.19k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
1.67k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
1.67k
    if ((qtable = compptr->quant_table) == NULL)
387
4
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
1.66k
    if (qtable->quantval[0] == 0 ||
390
1.66k
        qtable->quantval[Q01_POS] == 0 ||
391
1.66k
        qtable->quantval[Q10_POS] == 0 ||
392
1.66k
        qtable->quantval[Q20_POS] == 0 ||
393
1.66k
        qtable->quantval[Q11_POS] == 0 ||
394
1.66k
        qtable->quantval[Q02_POS] == 0 ||
395
1.66k
        qtable->quantval[Q03_POS] == 0 ||
396
1.66k
        qtable->quantval[Q12_POS] == 0 ||
397
1.66k
        qtable->quantval[Q21_POS] == 0 ||
398
1.66k
        qtable->quantval[Q30_POS] == 0)
399
49
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
1.61k
    coef_bits = cinfo->coef_bits[ci];
402
1.61k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
1.61k
    if (coef_bits[0] < 0)
404
0
      return FALSE;
405
1.61k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
16.1k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
14.5k
      if (cinfo->input_scan_number > 1)
409
10.1k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
4.38k
      else
411
4.38k
        prev_coef_bits_latch[coefi] = -1;
412
14.5k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
14.5k
      if (coef_bits[coefi] != 0)
414
11.9k
        smoothing_useful = TRUE;
415
14.5k
    }
416
1.61k
    coef_bits_latch += SAVED_COEFS;
417
1.61k
    prev_coef_bits_latch += SAVED_COEFS;
418
1.61k
  }
419
420
528
  return smoothing_useful;
421
581
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
361
24
{
362
24
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
24
  boolean smoothing_useful = FALSE;
364
24
  int ci, coefi;
365
24
  jpeg_component_info *compptr;
366
24
  JQUANT_TBL *qtable;
367
24
  int *coef_bits, *prev_coef_bits;
368
24
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
24
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
0
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
24
  if (coef->coef_bits_latch == NULL)
375
24
    coef->coef_bits_latch = (int *)
376
24
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
24
                                  cinfo->num_components * 2 *
378
24
                                  (SAVED_COEFS * sizeof(int)));
379
24
  coef_bits_latch = coef->coef_bits_latch;
380
24
  prev_coef_bits_latch =
381
24
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
55
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
49
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
49
    if ((qtable = compptr->quant_table) == NULL)
387
1
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
48
    if (qtable->quantval[0] == 0 ||
390
48
        qtable->quantval[Q01_POS] == 0 ||
391
48
        qtable->quantval[Q10_POS] == 0 ||
392
48
        qtable->quantval[Q20_POS] == 0 ||
393
48
        qtable->quantval[Q11_POS] == 0 ||
394
48
        qtable->quantval[Q02_POS] == 0 ||
395
48
        qtable->quantval[Q03_POS] == 0 ||
396
48
        qtable->quantval[Q12_POS] == 0 ||
397
48
        qtable->quantval[Q21_POS] == 0 ||
398
48
        qtable->quantval[Q30_POS] == 0)
399
17
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
31
    coef_bits = cinfo->coef_bits[ci];
402
31
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
31
    if (coef_bits[0] < 0)
404
0
      return FALSE;
405
31
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
310
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
279
      if (cinfo->input_scan_number > 1)
409
162
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
117
      else
411
117
        prev_coef_bits_latch[coefi] = -1;
412
279
      coef_bits_latch[coefi] = coef_bits[coefi];
413
279
      if (coef_bits[coefi] != 0)
414
216
        smoothing_useful = TRUE;
415
279
    }
416
31
    coef_bits_latch += SAVED_COEFS;
417
31
    prev_coef_bits_latch += SAVED_COEFS;
418
31
  }
419
420
6
  return smoothing_useful;
421
24
}
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
172k
{
431
172k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
172k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
172k
  JDIMENSION block_num, last_block_column;
434
172k
  int ci, block_row, block_rows, access_rows, image_block_row,
435
172k
    image_block_rows;
436
172k
  JBLOCKARRAY buffer;
437
172k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
172k
  JBLOCKROW next_block_row, next_next_block_row;
439
172k
  _JSAMPARRAY output_ptr;
440
172k
  JDIMENSION output_col;
441
172k
  jpeg_component_info *compptr;
442
172k
  _inverse_DCT_method_ptr inverse_DCT;
443
172k
  boolean change_dc;
444
172k
  JCOEF *workspace;
445
172k
  int *coef_bits;
446
172k
  JQUANT_TBL *quanttbl;
447
172k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
172k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
172k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
172k
      DC25;
451
172k
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
172k
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
172k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
172k
         !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
695k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
523k
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
523k
    if (!compptr->component_needed)
478
0
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
523k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
520k
      block_rows = compptr->v_samp_factor;
482
520k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
520k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
1.25k
      block_rows = compptr->v_samp_factor;
485
1.25k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
1.31k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
1.31k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
1.31k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
1.31k
      access_rows = block_rows; /* this iMCU row only */
491
1.31k
    }
492
    /* Align the virtual buffer for this component. */
493
523k
    if (cinfo->output_iMCU_row > 1) {
494
520k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
520k
      buffer = (*cinfo->mem->access_virt_barray)
496
520k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
520k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
520k
         (JDIMENSION)access_rows, FALSE);
499
520k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
520k
    } else if (cinfo->output_iMCU_row > 0) {
501
1.25k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
1.25k
      buffer = (*cinfo->mem->access_virt_barray)
503
1.25k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
1.25k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
1.25k
         (JDIMENSION)access_rows, FALSE);
506
1.25k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
1.31k
    } else {
508
1.31k
      buffer = (*cinfo->mem->access_virt_barray)
509
1.31k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
1.31k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
1.31k
    }
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
523k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
0
      coef_bits =
518
0
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
523k
    else
520
523k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
523k
    change_dc =
524
523k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
523k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
523k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
523k
    quanttbl = compptr->quant_table;
529
523k
    Q00 = quanttbl->quantval[0];
530
523k
    Q01 = quanttbl->quantval[Q01_POS];
531
523k
    Q10 = quanttbl->quantval[Q10_POS];
532
523k
    Q20 = quanttbl->quantval[Q20_POS];
533
523k
    Q11 = quanttbl->quantval[Q11_POS];
534
523k
    Q02 = quanttbl->quantval[Q02_POS];
535
523k
    if (change_dc) {
536
421k
      Q03 = quanttbl->quantval[Q03_POS];
537
421k
      Q12 = quanttbl->quantval[Q12_POS];
538
421k
      Q21 = quanttbl->quantval[Q21_POS];
539
421k
      Q30 = quanttbl->quantval[Q30_POS];
540
421k
    }
541
523k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
523k
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
523k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
1.44M
    for (block_row = 0; block_row < block_rows; block_row++) {
546
923k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
923k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
923k
      if (image_block_row > 0)
550
922k
        prev_block_row =
551
922k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
1.31k
      else
553
1.31k
        prev_block_row = buffer_ptr;
554
555
923k
      if (image_block_row > 1)
556
920k
        prev_prev_block_row =
557
920k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
2.57k
      else
559
2.57k
        prev_prev_block_row = prev_block_row;
560
561
923k
      if (image_block_row < image_block_rows - 1)
562
922k
        next_block_row =
563
922k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
1.31k
      else
565
1.31k
        next_block_row = buffer_ptr;
566
567
923k
      if (image_block_row < image_block_rows - 2)
568
921k
        next_next_block_row =
569
921k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
2.53k
      else
571
2.53k
        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
923k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
923k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
923k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
923k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
923k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
923k
      output_col = 0;
582
923k
      last_block_column = compptr->width_in_blocks - 1;
583
923k
      for (block_num = cinfo->master->first_MCU_col[ci];
584
12.9M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
12.0M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
12.0M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
12.0M
            block_num < last_block_column) {
590
915k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
915k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
915k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
915k
          DC19 = DC20 = (int)next_block_row[1][0];
594
915k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
915k
        }
596
12.0M
        if (block_num + 1 < last_block_column) {
597
10.1M
          DC05 = (int)prev_prev_block_row[2][0];
598
10.1M
          DC10 = (int)prev_block_row[2][0];
599
10.1M
          DC15 = (int)buffer_ptr[2][0];
600
10.1M
          DC20 = (int)next_block_row[2][0];
601
10.1M
          DC25 = (int)next_next_block_row[2][0];
602
10.1M
        }
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
12.0M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
11.6M
          num = Q00 * (change_dc ?
616
10.8M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
10.8M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
10.8M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
10.8M
                 DC21 - DC22 + DC24 + DC25) :
620
11.6M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
11.6M
          if (num >= 0) {
622
8.39M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
8.39M
            if (Al > 0 && pred >= (1 << Al))
624
4.61k
              pred = (1 << Al) - 1;
625
8.39M
          } else {
626
3.21M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
3.21M
            if (Al > 0 && pred >= (1 << Al))
628
5.77k
              pred = (1 << Al) - 1;
629
3.21M
            pred = -pred;
630
3.21M
          }
631
11.6M
          workspace[1] = (JCOEF)pred;
632
11.6M
        }
633
        /* AC10 */
634
12.0M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
11.7M
          num = Q00 * (change_dc ?
636
10.8M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
10.8M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
10.8M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
10.8M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
11.7M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
11.7M
          if (num >= 0) {
642
8.29M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
8.29M
            if (Al > 0 && pred >= (1 << Al))
644
215k
              pred = (1 << Al) - 1;
645
8.29M
          } else {
646
3.46M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
3.46M
            if (Al > 0 && pred >= (1 << Al))
648
39.5k
              pred = (1 << Al) - 1;
649
3.46M
            pred = -pred;
650
3.46M
          }
651
11.7M
          workspace[8] = (JCOEF)pred;
652
11.7M
        }
653
        /* AC20 */
654
12.0M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
11.7M
          num = Q00 * (change_dc ?
656
10.8M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
10.8M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
11.7M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
11.7M
          if (num >= 0) {
660
8.12M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
8.12M
            if (Al > 0 && pred >= (1 << Al))
662
27.2k
              pred = (1 << Al) - 1;
663
8.12M
          } else {
664
3.67M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
3.67M
            if (Al > 0 && pred >= (1 << Al))
666
26.5k
              pred = (1 << Al) - 1;
667
3.67M
            pred = -pred;
668
3.67M
          }
669
11.7M
          workspace[16] = (JCOEF)pred;
670
11.7M
        }
671
        /* AC11 */
672
12.0M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
11.8M
          num = Q00 * (change_dc ?
674
10.8M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
10.8M
                 9 * DC19 + DC21 - DC25) :
676
11.8M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
1.07M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
11.8M
          if (num >= 0) {
679
9.75M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
9.75M
            if (Al > 0 && pred >= (1 << Al))
681
43.3k
              pred = (1 << Al) - 1;
682
9.75M
          } else {
683
2.12M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
2.12M
            if (Al > 0 && pred >= (1 << Al))
685
44.7k
              pred = (1 << Al) - 1;
686
2.12M
            pred = -pred;
687
2.12M
          }
688
11.8M
          workspace[9] = (JCOEF)pred;
689
11.8M
        }
690
        /* AC02 */
691
12.0M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
11.8M
          num = Q00 * (change_dc ?
693
10.8M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
10.8M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
11.8M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
11.8M
          if (num >= 0) {
697
8.35M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
8.35M
            if (Al > 0 && pred >= (1 << Al))
699
11.2k
              pred = (1 << Al) - 1;
700
8.35M
          } else {
701
3.54M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
3.54M
            if (Al > 0 && pred >= (1 << Al))
703
14.1k
              pred = (1 << Al) - 1;
704
3.54M
            pred = -pred;
705
3.54M
          }
706
11.8M
          workspace[2] = (JCOEF)pred;
707
11.8M
        }
708
12.0M
        if (change_dc) {
709
          /* AC03 */
710
10.8M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
10.8M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
10.8M
            if (num >= 0) {
713
8.03M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
8.03M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
8.03M
            } else {
717
2.77M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
2.77M
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
2.77M
              pred = -pred;
721
2.77M
            }
722
10.8M
            workspace[3] = (JCOEF)pred;
723
10.8M
          }
724
          /* AC12 */
725
10.8M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
10.8M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
10.8M
            if (num >= 0) {
728
7.38M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
7.38M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
7.38M
            } else {
732
3.42M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
3.42M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
3.42M
              pred = -pred;
736
3.42M
            }
737
10.8M
            workspace[10] = (JCOEF)pred;
738
10.8M
          }
739
          /* AC21 */
740
10.8M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
10.8M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
10.8M
            if (num >= 0) {
743
7.65M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
7.65M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
7.65M
            } else {
747
3.15M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
3.15M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
3.15M
              pred = -pred;
751
3.15M
            }
752
10.8M
            workspace[17] = (JCOEF)pred;
753
10.8M
          }
754
          /* AC30 */
755
10.8M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
10.8M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
10.8M
            if (num >= 0) {
758
7.78M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
7.78M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
7.78M
            } else {
762
3.02M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
3.02M
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
3.02M
              pred = -pred;
766
3.02M
            }
767
10.8M
            workspace[24] = (JCOEF)pred;
768
10.8M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
10.8M
          num = Q00 *
773
10.8M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
10.8M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
10.8M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
10.8M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
10.8M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
10.8M
          if (num >= 0) {
779
6.13M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
6.13M
          } else {
781
4.67M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
4.67M
            pred = -pred;
783
4.67M
          }
784
10.8M
          workspace[0] = (JCOEF)pred;
785
10.8M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
12.0M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
12.0M
                        output_col);
790
        /* Advance for next column */
791
12.0M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
12.0M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
12.0M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
12.0M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
12.0M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
12.0M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
12.0M
          prev_prev_block_row++, next_next_block_row++;
798
12.0M
        output_col += compptr->_DCT_scaled_size;
799
12.0M
      }
800
923k
      output_ptr += compptr->_DCT_scaled_size;
801
923k
    }
802
523k
  }
803
804
172k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
172k
    return JPEG_ROW_COMPLETED;
806
436
  return JPEG_SCAN_COMPLETED;
807
172k
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
430
172k
{
431
172k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
172k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
172k
  JDIMENSION block_num, last_block_column;
434
172k
  int ci, block_row, block_rows, access_rows, image_block_row,
435
172k
    image_block_rows;
436
172k
  JBLOCKARRAY buffer;
437
172k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
172k
  JBLOCKROW next_block_row, next_next_block_row;
439
172k
  _JSAMPARRAY output_ptr;
440
172k
  JDIMENSION output_col;
441
172k
  jpeg_component_info *compptr;
442
172k
  _inverse_DCT_method_ptr inverse_DCT;
443
172k
  boolean change_dc;
444
172k
  JCOEF *workspace;
445
172k
  int *coef_bits;
446
172k
  JQUANT_TBL *quanttbl;
447
172k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
172k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
172k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
172k
      DC25;
451
172k
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
172k
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
172k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
172k
         !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
695k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
523k
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
523k
    if (!compptr->component_needed)
478
0
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
523k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
520k
      block_rows = compptr->v_samp_factor;
482
520k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
520k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
1.25k
      block_rows = compptr->v_samp_factor;
485
1.25k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
1.31k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
1.31k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
1.31k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
1.31k
      access_rows = block_rows; /* this iMCU row only */
491
1.31k
    }
492
    /* Align the virtual buffer for this component. */
493
523k
    if (cinfo->output_iMCU_row > 1) {
494
520k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
520k
      buffer = (*cinfo->mem->access_virt_barray)
496
520k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
520k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
520k
         (JDIMENSION)access_rows, FALSE);
499
520k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
520k
    } else if (cinfo->output_iMCU_row > 0) {
501
1.25k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
1.25k
      buffer = (*cinfo->mem->access_virt_barray)
503
1.25k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
1.25k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
1.25k
         (JDIMENSION)access_rows, FALSE);
506
1.25k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
1.31k
    } else {
508
1.31k
      buffer = (*cinfo->mem->access_virt_barray)
509
1.31k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
1.31k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
1.31k
    }
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
523k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
0
      coef_bits =
518
0
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
523k
    else
520
523k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
523k
    change_dc =
524
523k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
523k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
523k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
523k
    quanttbl = compptr->quant_table;
529
523k
    Q00 = quanttbl->quantval[0];
530
523k
    Q01 = quanttbl->quantval[Q01_POS];
531
523k
    Q10 = quanttbl->quantval[Q10_POS];
532
523k
    Q20 = quanttbl->quantval[Q20_POS];
533
523k
    Q11 = quanttbl->quantval[Q11_POS];
534
523k
    Q02 = quanttbl->quantval[Q02_POS];
535
523k
    if (change_dc) {
536
421k
      Q03 = quanttbl->quantval[Q03_POS];
537
421k
      Q12 = quanttbl->quantval[Q12_POS];
538
421k
      Q21 = quanttbl->quantval[Q21_POS];
539
421k
      Q30 = quanttbl->quantval[Q30_POS];
540
421k
    }
541
523k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
523k
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
523k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
1.44M
    for (block_row = 0; block_row < block_rows; block_row++) {
546
923k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
923k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
923k
      if (image_block_row > 0)
550
922k
        prev_block_row =
551
922k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
1.31k
      else
553
1.31k
        prev_block_row = buffer_ptr;
554
555
923k
      if (image_block_row > 1)
556
920k
        prev_prev_block_row =
557
920k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
2.57k
      else
559
2.57k
        prev_prev_block_row = prev_block_row;
560
561
923k
      if (image_block_row < image_block_rows - 1)
562
922k
        next_block_row =
563
922k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
1.31k
      else
565
1.31k
        next_block_row = buffer_ptr;
566
567
923k
      if (image_block_row < image_block_rows - 2)
568
921k
        next_next_block_row =
569
921k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
2.53k
      else
571
2.53k
        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
923k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
923k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
923k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
923k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
923k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
923k
      output_col = 0;
582
923k
      last_block_column = compptr->width_in_blocks - 1;
583
923k
      for (block_num = cinfo->master->first_MCU_col[ci];
584
12.9M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
12.0M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
12.0M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
12.0M
            block_num < last_block_column) {
590
915k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
915k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
915k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
915k
          DC19 = DC20 = (int)next_block_row[1][0];
594
915k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
915k
        }
596
12.0M
        if (block_num + 1 < last_block_column) {
597
10.1M
          DC05 = (int)prev_prev_block_row[2][0];
598
10.1M
          DC10 = (int)prev_block_row[2][0];
599
10.1M
          DC15 = (int)buffer_ptr[2][0];
600
10.1M
          DC20 = (int)next_block_row[2][0];
601
10.1M
          DC25 = (int)next_next_block_row[2][0];
602
10.1M
        }
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
12.0M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
11.6M
          num = Q00 * (change_dc ?
616
10.8M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
10.8M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
10.8M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
10.8M
                 DC21 - DC22 + DC24 + DC25) :
620
11.6M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
11.6M
          if (num >= 0) {
622
8.39M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
8.39M
            if (Al > 0 && pred >= (1 << Al))
624
4.61k
              pred = (1 << Al) - 1;
625
8.39M
          } else {
626
3.21M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
3.21M
            if (Al > 0 && pred >= (1 << Al))
628
5.77k
              pred = (1 << Al) - 1;
629
3.21M
            pred = -pred;
630
3.21M
          }
631
11.6M
          workspace[1] = (JCOEF)pred;
632
11.6M
        }
633
        /* AC10 */
634
12.0M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
11.7M
          num = Q00 * (change_dc ?
636
10.8M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
10.8M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
10.8M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
10.8M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
11.7M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
11.7M
          if (num >= 0) {
642
8.29M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
8.29M
            if (Al > 0 && pred >= (1 << Al))
644
215k
              pred = (1 << Al) - 1;
645
8.29M
          } else {
646
3.46M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
3.46M
            if (Al > 0 && pred >= (1 << Al))
648
39.5k
              pred = (1 << Al) - 1;
649
3.46M
            pred = -pred;
650
3.46M
          }
651
11.7M
          workspace[8] = (JCOEF)pred;
652
11.7M
        }
653
        /* AC20 */
654
12.0M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
11.7M
          num = Q00 * (change_dc ?
656
10.8M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
10.8M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
11.7M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
11.7M
          if (num >= 0) {
660
8.12M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
8.12M
            if (Al > 0 && pred >= (1 << Al))
662
27.2k
              pred = (1 << Al) - 1;
663
8.12M
          } else {
664
3.67M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
3.67M
            if (Al > 0 && pred >= (1 << Al))
666
26.5k
              pred = (1 << Al) - 1;
667
3.67M
            pred = -pred;
668
3.67M
          }
669
11.7M
          workspace[16] = (JCOEF)pred;
670
11.7M
        }
671
        /* AC11 */
672
12.0M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
11.8M
          num = Q00 * (change_dc ?
674
10.8M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
10.8M
                 9 * DC19 + DC21 - DC25) :
676
11.8M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
1.07M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
11.8M
          if (num >= 0) {
679
9.75M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
9.75M
            if (Al > 0 && pred >= (1 << Al))
681
43.3k
              pred = (1 << Al) - 1;
682
9.75M
          } else {
683
2.12M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
2.12M
            if (Al > 0 && pred >= (1 << Al))
685
44.7k
              pred = (1 << Al) - 1;
686
2.12M
            pred = -pred;
687
2.12M
          }
688
11.8M
          workspace[9] = (JCOEF)pred;
689
11.8M
        }
690
        /* AC02 */
691
12.0M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
11.8M
          num = Q00 * (change_dc ?
693
10.8M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
10.8M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
11.8M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
11.8M
          if (num >= 0) {
697
8.35M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
8.35M
            if (Al > 0 && pred >= (1 << Al))
699
11.2k
              pred = (1 << Al) - 1;
700
8.35M
          } else {
701
3.54M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
3.54M
            if (Al > 0 && pred >= (1 << Al))
703
14.1k
              pred = (1 << Al) - 1;
704
3.54M
            pred = -pred;
705
3.54M
          }
706
11.8M
          workspace[2] = (JCOEF)pred;
707
11.8M
        }
708
12.0M
        if (change_dc) {
709
          /* AC03 */
710
10.8M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
10.8M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
10.8M
            if (num >= 0) {
713
8.03M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
8.03M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
8.03M
            } else {
717
2.77M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
2.77M
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
2.77M
              pred = -pred;
721
2.77M
            }
722
10.8M
            workspace[3] = (JCOEF)pred;
723
10.8M
          }
724
          /* AC12 */
725
10.8M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
10.8M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
10.8M
            if (num >= 0) {
728
7.38M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
7.38M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
7.38M
            } else {
732
3.42M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
3.42M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
3.42M
              pred = -pred;
736
3.42M
            }
737
10.8M
            workspace[10] = (JCOEF)pred;
738
10.8M
          }
739
          /* AC21 */
740
10.8M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
10.8M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
10.8M
            if (num >= 0) {
743
7.65M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
7.65M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
7.65M
            } else {
747
3.15M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
3.15M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
3.15M
              pred = -pred;
751
3.15M
            }
752
10.8M
            workspace[17] = (JCOEF)pred;
753
10.8M
          }
754
          /* AC30 */
755
10.8M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
10.8M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
10.8M
            if (num >= 0) {
758
7.78M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
7.78M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
7.78M
            } else {
762
3.02M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
3.02M
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
3.02M
              pred = -pred;
766
3.02M
            }
767
10.8M
            workspace[24] = (JCOEF)pred;
768
10.8M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
10.8M
          num = Q00 *
773
10.8M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
10.8M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
10.8M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
10.8M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
10.8M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
10.8M
          if (num >= 0) {
779
6.13M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
6.13M
          } else {
781
4.67M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
4.67M
            pred = -pred;
783
4.67M
          }
784
10.8M
          workspace[0] = (JCOEF)pred;
785
10.8M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
12.0M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
12.0M
                        output_col);
790
        /* Advance for next column */
791
12.0M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
12.0M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
12.0M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
12.0M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
12.0M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
12.0M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
12.0M
          prev_prev_block_row++, next_next_block_row++;
798
12.0M
        output_col += compptr->_DCT_scaled_size;
799
12.0M
      }
800
923k
      output_ptr += compptr->_DCT_scaled_size;
801
923k
    }
802
523k
  }
803
804
172k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
172k
    return JPEG_ROW_COMPLETED;
806
436
  return JPEG_SCAN_COMPLETED;
807
172k
}
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
3.76k
{
819
3.76k
  my_coef_ptr coef;
820
821
3.76k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
3.76k
  coef = (my_coef_ptr)
825
3.76k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
3.76k
                                sizeof(my_coef_controller));
827
3.76k
  memset(coef, 0, sizeof(my_coef_controller));
828
3.76k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
3.76k
  coef->pub.start_input_pass = start_input_pass;
830
3.76k
  coef->pub.start_output_pass = start_output_pass;
831
3.76k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
3.76k
  coef->coef_bits_latch = NULL;
833
3.76k
#endif
834
835
  /* Create the coefficient buffer. */
836
3.76k
  if (need_full_buffer) {
837
1.85k
#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
1.85k
    int ci, access_rows;
842
1.85k
    jpeg_component_info *compptr;
843
844
7.42k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
5.57k
         ci++, compptr++) {
846
5.57k
      access_rows = compptr->v_samp_factor;
847
5.57k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
5.57k
      if (cinfo->progressive_mode)
850
5.53k
        access_rows *= 5;
851
5.57k
#endif
852
5.57k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
5.57k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
5.57k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
5.57k
                               (long)compptr->h_samp_factor),
856
5.57k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
5.57k
                               (long)compptr->v_samp_factor),
858
5.57k
         (JDIMENSION)access_rows);
859
5.57k
    }
860
1.85k
    coef->pub.consume_data = consume_data;
861
1.85k
    coef->pub._decompress_data = decompress_data;
862
1.85k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
1.90k
  } else {
867
    /* We only need a single-MCU buffer. */
868
1.90k
    JBLOCKROW buffer;
869
1.90k
    int i;
870
871
1.90k
    buffer = (JBLOCKROW)
872
1.90k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
1.90k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
20.9k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
19.0k
      coef->MCU_buffer[i] = buffer + i;
876
19.0k
    }
877
1.90k
    coef->pub.consume_data = dummy_consume_data;
878
1.90k
    coef->pub._decompress_data = decompress_onepass;
879
1.90k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
1.90k
  }
881
882
  /* Allocate the workspace buffer */
883
3.76k
  coef->workspace = (JCOEF *)
884
3.76k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
3.76k
                                sizeof(JCOEF) * DCTSIZE2);
886
3.76k
}
jinit_d_coef_controller
Line
Count
Source
818
3.45k
{
819
3.45k
  my_coef_ptr coef;
820
821
3.45k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
3.45k
  coef = (my_coef_ptr)
825
3.45k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
3.45k
                                sizeof(my_coef_controller));
827
3.45k
  memset(coef, 0, sizeof(my_coef_controller));
828
3.45k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
3.45k
  coef->pub.start_input_pass = start_input_pass;
830
3.45k
  coef->pub.start_output_pass = start_output_pass;
831
3.45k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
3.45k
  coef->coef_bits_latch = NULL;
833
3.45k
#endif
834
835
  /* Create the coefficient buffer. */
836
3.45k
  if (need_full_buffer) {
837
1.54k
#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
1.54k
    int ci, access_rows;
842
1.54k
    jpeg_component_info *compptr;
843
844
6.20k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
4.65k
         ci++, compptr++) {
846
4.65k
      access_rows = compptr->v_samp_factor;
847
4.65k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
4.65k
      if (cinfo->progressive_mode)
850
4.63k
        access_rows *= 5;
851
4.65k
#endif
852
4.65k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
4.65k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
4.65k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
4.65k
                               (long)compptr->h_samp_factor),
856
4.65k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
4.65k
                               (long)compptr->v_samp_factor),
858
4.65k
         (JDIMENSION)access_rows);
859
4.65k
    }
860
1.54k
    coef->pub.consume_data = consume_data;
861
1.54k
    coef->pub._decompress_data = decompress_data;
862
1.54k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
1.90k
  } else {
867
    /* We only need a single-MCU buffer. */
868
1.90k
    JBLOCKROW buffer;
869
1.90k
    int i;
870
871
1.90k
    buffer = (JBLOCKROW)
872
1.90k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
1.90k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
20.9k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
19.0k
      coef->MCU_buffer[i] = buffer + i;
876
19.0k
    }
877
1.90k
    coef->pub.consume_data = dummy_consume_data;
878
1.90k
    coef->pub._decompress_data = decompress_onepass;
879
1.90k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
1.90k
  }
881
882
  /* Allocate the workspace buffer */
883
3.45k
  coef->workspace = (JCOEF *)
884
3.45k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
3.45k
                                sizeof(JCOEF) * DCTSIZE2);
886
3.45k
}
j12init_d_coef_controller
Line
Count
Source
818
312
{
819
312
  my_coef_ptr coef;
820
821
312
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
312
  coef = (my_coef_ptr)
825
312
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
312
                                sizeof(my_coef_controller));
827
312
  memset(coef, 0, sizeof(my_coef_controller));
828
312
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
312
  coef->pub.start_input_pass = start_input_pass;
830
312
  coef->pub.start_output_pass = start_output_pass;
831
312
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
312
  coef->coef_bits_latch = NULL;
833
312
#endif
834
835
  /* Create the coefficient buffer. */
836
312
  if (need_full_buffer) {
837
304
#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
304
    int ci, access_rows;
842
304
    jpeg_component_info *compptr;
843
844
1.22k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
919
         ci++, compptr++) {
846
919
      access_rows = compptr->v_samp_factor;
847
919
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
919
      if (cinfo->progressive_mode)
850
895
        access_rows *= 5;
851
919
#endif
852
919
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
919
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
919
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
919
                               (long)compptr->h_samp_factor),
856
919
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
919
                               (long)compptr->v_samp_factor),
858
919
         (JDIMENSION)access_rows);
859
919
    }
860
304
    coef->pub.consume_data = consume_data;
861
304
    coef->pub._decompress_data = decompress_data;
862
304
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
304
  } else {
867
    /* We only need a single-MCU buffer. */
868
8
    JBLOCKROW buffer;
869
8
    int i;
870
871
8
    buffer = (JBLOCKROW)
872
8
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
8
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
88
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
80
      coef->MCU_buffer[i] = buffer + i;
876
80
    }
877
8
    coef->pub.consume_data = dummy_consume_data;
878
8
    coef->pub._decompress_data = decompress_onepass;
879
8
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
8
  }
881
882
  /* Allocate the workspace buffer */
883
312
  coef->workspace = (JCOEF *)
884
312
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
312
                                sizeof(JCOEF) * DCTSIZE2);
886
312
}