Coverage Report

Created: 2025-08-09 06:49

/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
106k
{
48
106k
  cinfo->input_iMCU_row = 0;
49
106k
  start_iMCU_row(cinfo);
50
106k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
47
87.4k
{
48
87.4k
  cinfo->input_iMCU_row = 0;
49
87.4k
  start_iMCU_row(cinfo);
50
87.4k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
47
18.8k
{
48
18.8k
  cinfo->input_iMCU_row = 0;
49
18.8k
  start_iMCU_row(cinfo);
50
18.8k
}
51
52
53
/*
54
 * Initialize for an output processing pass.
55
 */
56
57
METHODDEF(void)
58
start_output_pass(j_decompress_ptr cinfo)
59
7.63k
{
60
7.63k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
7.63k
  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
7.63k
  if (coef->pub.coef_arrays != NULL) {
65
6.05k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
1.73k
      coef->pub._decompress_data = decompress_smooth_data;
67
4.32k
    else
68
4.32k
      coef->pub._decompress_data = decompress_data;
69
6.05k
  }
70
7.63k
#endif
71
7.63k
  cinfo->output_iMCU_row = 0;
72
7.63k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
59
4.77k
{
60
4.77k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
4.77k
  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
4.77k
  if (coef->pub.coef_arrays != NULL) {
65
3.65k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
1.13k
      coef->pub._decompress_data = decompress_smooth_data;
67
2.52k
    else
68
2.52k
      coef->pub._decompress_data = decompress_data;
69
3.65k
  }
70
4.77k
#endif
71
4.77k
  cinfo->output_iMCU_row = 0;
72
4.77k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
59
2.86k
{
60
2.86k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
2.86k
  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.86k
  if (coef->pub.coef_arrays != NULL) {
65
2.40k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
606
      coef->pub._decompress_data = decompress_smooth_data;
67
1.79k
    else
68
1.79k
      coef->pub._decompress_data = decompress_data;
69
2.40k
  }
70
2.86k
#endif
71
2.86k
  cinfo->output_iMCU_row = 0;
72
2.86k
}
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
519k
{
88
519k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
519k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
519k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
519k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
519k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
519k
  _JSAMPARRAY output_ptr;
94
519k
  JDIMENSION start_col, output_col;
95
519k
  jpeg_component_info *compptr;
96
519k
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
1.36M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
841k
       yoffset++) {
101
9.37M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
8.53M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
8.53M
      jzero_far((void *)coef->MCU_buffer[0],
105
8.53M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
8.53M
      if (!cinfo->entropy->insufficient_data)
107
3.50M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
8.53M
      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
8.53M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
8.53M
          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
8.53M
        blkn = 0;               /* index of current DCT block within MCU */
126
17.3M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
8.76M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
8.76M
          if (!compptr->component_needed) {
130
14.8k
            blkn += compptr->MCU_blocks;
131
14.8k
            continue;
132
14.8k
          }
133
8.75M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
8.75M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
7.89M
                         compptr->MCU_width : compptr->last_col_width;
136
8.75M
          output_ptr = output_buf[compptr->component_index] +
137
8.75M
                       yoffset * compptr->_DCT_scaled_size;
138
8.75M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
8.75M
                      compptr->MCU_sample_width;
140
17.6M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
8.90M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
8.90M
                yoffset + yindex < compptr->last_row_height) {
143
8.86M
              output_col = start_col;
144
17.9M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
9.09M
                (*inverse_DCT) (cinfo, compptr,
146
9.09M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
9.09M
                                output_ptr, output_col);
148
9.09M
                output_col += compptr->_DCT_scaled_size;
149
9.09M
              }
150
8.86M
            }
151
8.90M
            blkn += compptr->MCU_width;
152
8.90M
            output_ptr += compptr->_DCT_scaled_size;
153
8.90M
          }
154
8.75M
        }
155
8.53M
      }
156
8.53M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
841k
    coef->MCU_ctr = 0;
159
841k
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
519k
  cinfo->output_iMCU_row++;
162
519k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
517k
    start_iMCU_row(cinfo);
164
517k
    return JPEG_ROW_COMPLETED;
165
517k
  }
166
  /* Completed the scan */
167
1.56k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
1.56k
  return JPEG_SCAN_COMPLETED;
169
519k
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
87
304k
{
88
304k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
304k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
304k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
304k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
304k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
304k
  _JSAMPARRAY output_ptr;
94
304k
  JDIMENSION start_col, output_col;
95
304k
  jpeg_component_info *compptr;
96
304k
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
765k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
460k
       yoffset++) {
101
6.34M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
5.88M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
5.88M
      jzero_far((void *)coef->MCU_buffer[0],
105
5.88M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
5.88M
      if (!cinfo->entropy->insufficient_data)
107
1.10M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
5.88M
      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
5.88M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
5.88M
          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
5.88M
        blkn = 0;               /* index of current DCT block within MCU */
126
11.9M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
6.07M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
6.07M
          if (!compptr->component_needed) {
130
6.49k
            blkn += compptr->MCU_blocks;
131
6.49k
            continue;
132
6.49k
          }
133
6.07M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
6.07M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
5.59M
                         compptr->MCU_width : compptr->last_col_width;
136
6.07M
          output_ptr = output_buf[compptr->component_index] +
137
6.07M
                       yoffset * compptr->_DCT_scaled_size;
138
6.07M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
6.07M
                      compptr->MCU_sample_width;
140
12.2M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
6.18M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
6.18M
                yoffset + yindex < compptr->last_row_height) {
143
6.16M
              output_col = start_col;
144
12.4M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
6.33M
                (*inverse_DCT) (cinfo, compptr,
146
6.33M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
6.33M
                                output_ptr, output_col);
148
6.33M
                output_col += compptr->_DCT_scaled_size;
149
6.33M
              }
150
6.16M
            }
151
6.18M
            blkn += compptr->MCU_width;
152
6.18M
            output_ptr += compptr->_DCT_scaled_size;
153
6.18M
          }
154
6.07M
        }
155
5.88M
      }
156
5.88M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
460k
    coef->MCU_ctr = 0;
159
460k
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
304k
  cinfo->output_iMCU_row++;
162
304k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
303k
    start_iMCU_row(cinfo);
164
303k
    return JPEG_ROW_COMPLETED;
165
303k
  }
166
  /* Completed the scan */
167
1.12k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
1.12k
  return JPEG_SCAN_COMPLETED;
169
304k
}
jdcoefct-12.c:decompress_onepass
Line
Count
Source
87
214k
{
88
214k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
214k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
214k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
214k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
214k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
214k
  _JSAMPARRAY output_ptr;
94
214k
  JDIMENSION start_col, output_col;
95
214k
  jpeg_component_info *compptr;
96
214k
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
595k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
380k
       yoffset++) {
101
3.02M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
2.64M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
2.64M
      jzero_far((void *)coef->MCU_buffer[0],
105
2.64M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
2.64M
      if (!cinfo->entropy->insufficient_data)
107
2.40M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
2.64M
      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.64M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
2.64M
          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.64M
        blkn = 0;               /* index of current DCT block within MCU */
126
5.33M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
2.68M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
2.68M
          if (!compptr->component_needed) {
130
8.31k
            blkn += compptr->MCU_blocks;
131
8.31k
            continue;
132
8.31k
          }
133
2.68M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
2.68M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
2.29M
                         compptr->MCU_width : compptr->last_col_width;
136
2.68M
          output_ptr = output_buf[compptr->component_index] +
137
2.68M
                       yoffset * compptr->_DCT_scaled_size;
138
2.68M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
2.68M
                      compptr->MCU_sample_width;
140
5.39M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
2.71M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
2.71M
                yoffset + yindex < compptr->last_row_height) {
143
2.69M
              output_col = start_col;
144
5.46M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
2.76M
                (*inverse_DCT) (cinfo, compptr,
146
2.76M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
2.76M
                                output_ptr, output_col);
148
2.76M
                output_col += compptr->_DCT_scaled_size;
149
2.76M
              }
150
2.69M
            }
151
2.71M
            blkn += compptr->MCU_width;
152
2.71M
            output_ptr += compptr->_DCT_scaled_size;
153
2.71M
          }
154
2.68M
        }
155
2.64M
      }
156
2.64M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
380k
    coef->MCU_ctr = 0;
159
380k
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
214k
  cinfo->output_iMCU_row++;
162
214k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
214k
    start_iMCU_row(cinfo);
164
214k
    return JPEG_ROW_COMPLETED;
165
214k
  }
166
  /* Completed the scan */
167
441
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
441
  return JPEG_SCAN_COMPLETED;
169
214k
}
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
32.8M
{
195
32.8M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
32.8M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
32.8M
  int blkn, ci, xindex, yindex, yoffset;
198
32.8M
  JDIMENSION start_col;
199
32.8M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
32.8M
  JBLOCKROW buffer_ptr;
201
32.8M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
69.2M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
36.4M
    compptr = cinfo->cur_comp_info[ci];
206
36.4M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
36.4M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
36.4M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
36.4M
       (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
36.4M
  }
215
216
  /* Loop to process one whole iMCU row */
217
70.2M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
37.3M
       yoffset++) {
219
414M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
377M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
377M
      blkn = 0;                 /* index of current DCT block within MCU */
223
803M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
425M
        compptr = cinfo->cur_comp_info[ci];
225
425M
        start_col = MCU_col_num * compptr->MCU_width;
226
893M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
467M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
1.01G
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
548M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
548M
          }
231
467M
        }
232
425M
      }
233
377M
      if (!cinfo->entropy->insufficient_data)
234
133M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
377M
      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
377M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
37.3M
    coef->MCU_ctr = 0;
245
37.3M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
32.8M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
32.7M
    start_iMCU_row(cinfo);
249
32.7M
    return JPEG_ROW_COMPLETED;
250
32.7M
  }
251
  /* Completed the scan */
252
103k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
103k
  return JPEG_SCAN_COMPLETED;
254
32.8M
}
jdcoefct-8.c:consume_data
Line
Count
Source
194
26.8M
{
195
26.8M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
26.8M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
26.8M
  int blkn, ci, xindex, yindex, yoffset;
198
26.8M
  JDIMENSION start_col;
199
26.8M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
26.8M
  JBLOCKROW buffer_ptr;
201
26.8M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
56.7M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
29.9M
    compptr = cinfo->cur_comp_info[ci];
206
29.9M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
29.9M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
29.9M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
29.9M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
210
    /* Note: entropy decoder expects buffer to be zeroed,
211
     * but this is handled automatically by the memory manager
212
     * because we requested a pre-zeroed array.
213
     */
214
29.9M
  }
215
216
  /* Loop to process one whole iMCU row */
217
56.7M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
29.9M
       yoffset++) {
219
365M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
335M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
335M
      blkn = 0;                 /* index of current DCT block within MCU */
223
713M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
378M
        compptr = cinfo->cur_comp_info[ci];
225
378M
        start_col = MCU_col_num * compptr->MCU_width;
226
792M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
414M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
907M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
493M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
493M
          }
231
414M
        }
232
378M
      }
233
335M
      if (!cinfo->entropy->insufficient_data)
234
104M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
335M
      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
335M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
29.9M
    coef->MCU_ctr = 0;
245
29.9M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
26.8M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
26.7M
    start_iMCU_row(cinfo);
249
26.7M
    return JPEG_ROW_COMPLETED;
250
26.7M
  }
251
  /* Completed the scan */
252
85.2k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
85.2k
  return JPEG_SCAN_COMPLETED;
254
26.8M
}
jdcoefct-12.c:consume_data
Line
Count
Source
194
6.03M
{
195
6.03M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
6.03M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
6.03M
  int blkn, ci, xindex, yindex, yoffset;
198
6.03M
  JDIMENSION start_col;
199
6.03M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
6.03M
  JBLOCKROW buffer_ptr;
201
6.03M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
12.4M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
6.44M
    compptr = cinfo->cur_comp_info[ci];
206
6.44M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
6.44M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
6.44M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
6.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
6.44M
  }
215
216
  /* Loop to process one whole iMCU row */
217
13.4M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
7.39M
       yoffset++) {
219
49.0M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
41.7M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
41.7M
      blkn = 0;                 /* index of current DCT block within MCU */
223
89.0M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
47.3M
        compptr = cinfo->cur_comp_info[ci];
225
47.3M
        start_col = MCU_col_num * compptr->MCU_width;
226
100M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
53.4M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
108M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
55.0M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
55.0M
          }
231
53.4M
        }
232
47.3M
      }
233
41.7M
      if (!cinfo->entropy->insufficient_data)
234
29.2M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
41.7M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
237
        /* Suspension forced; update state counters and exit */
238
0
        coef->MCU_vert_offset = yoffset;
239
0
        coef->MCU_ctr = MCU_col_num;
240
0
        return JPEG_SUSPENDED;
241
0
      }
242
41.7M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
7.39M
    coef->MCU_ctr = 0;
245
7.39M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
6.03M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
6.02M
    start_iMCU_row(cinfo);
249
6.02M
    return JPEG_ROW_COMPLETED;
250
6.02M
  }
251
  /* Completed the scan */
252
18.3k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
18.3k
  return JPEG_SCAN_COMPLETED;
254
6.03M
}
255
256
257
/*
258
 * Decompress and return some data in the multi-pass case.
259
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
260
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
261
 *
262
 * NB: output_buf contains a plane for each component in image.
263
 */
264
265
METHODDEF(int)
266
decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
267
1.19M
{
268
1.19M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
1.19M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
1.19M
  JDIMENSION block_num;
271
1.19M
  int ci, block_row, block_rows;
272
1.19M
  JBLOCKARRAY buffer;
273
1.19M
  JBLOCKROW buffer_ptr;
274
1.19M
  _JSAMPARRAY output_ptr;
275
1.19M
  JDIMENSION output_col;
276
1.19M
  jpeg_component_info *compptr;
277
1.19M
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
1.19M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
1.19M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
1.19M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
283
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
284
0
      return JPEG_SUSPENDED;
285
0
  }
286
287
  /* OK, output from the virtual arrays. */
288
3.60M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
2.41M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
2.41M
    if (!compptr->component_needed)
292
104k
      continue;
293
    /* Align the virtual buffer for this component. */
294
2.30M
    buffer = (*cinfo->mem->access_virt_barray)
295
2.30M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
2.30M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
2.30M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
2.30M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
2.30M
      block_rows = compptr->v_samp_factor;
301
8.30k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
8.30k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
8.30k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
8.30k
    }
306
2.30M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
2.30M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
5.30M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
2.99M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
2.99M
      output_col = 0;
312
2.99M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
30.0M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
27.0M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
27.0M
                        output_col);
316
27.0M
        buffer_ptr++;
317
27.0M
        output_col += compptr->_DCT_scaled_size;
318
27.0M
      }
319
2.99M
      output_ptr += compptr->_DCT_scaled_size;
320
2.99M
    }
321
2.30M
  }
322
323
1.19M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
1.18M
    return JPEG_ROW_COMPLETED;
325
4.07k
  return JPEG_SCAN_COMPLETED;
326
1.19M
}
jdcoefct-8.c:decompress_data
Line
Count
Source
267
966k
{
268
966k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
966k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
966k
  JDIMENSION block_num;
271
966k
  int ci, block_row, block_rows;
272
966k
  JBLOCKARRAY buffer;
273
966k
  JBLOCKROW buffer_ptr;
274
966k
  _JSAMPARRAY output_ptr;
275
966k
  JDIMENSION output_col;
276
966k
  jpeg_component_info *compptr;
277
966k
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
966k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
966k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
966k
          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
2.90M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
1.94M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
1.94M
    if (!compptr->component_needed)
292
49.0k
      continue;
293
    /* Align the virtual buffer for this component. */
294
1.89M
    buffer = (*cinfo->mem->access_virt_barray)
295
1.89M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
1.89M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
1.89M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
1.89M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
1.88M
      block_rows = compptr->v_samp_factor;
301
4.98k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
4.98k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
4.98k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
4.98k
    }
306
1.89M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
1.89M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
4.27M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
2.38M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
2.38M
      output_col = 0;
312
2.38M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
24.1M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
21.7M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
21.7M
                        output_col);
316
21.7M
        buffer_ptr++;
317
21.7M
        output_col += compptr->_DCT_scaled_size;
318
21.7M
      }
319
2.38M
      output_ptr += compptr->_DCT_scaled_size;
320
2.38M
    }
321
1.89M
  }
322
323
966k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
964k
    return JPEG_ROW_COMPLETED;
325
2.52k
  return JPEG_SCAN_COMPLETED;
326
966k
}
jdcoefct-12.c:decompress_data
Line
Count
Source
267
224k
{
268
224k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
224k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
224k
  JDIMENSION block_num;
271
224k
  int ci, block_row, block_rows;
272
224k
  JBLOCKARRAY buffer;
273
224k
  JBLOCKROW buffer_ptr;
274
224k
  _JSAMPARRAY output_ptr;
275
224k
  JDIMENSION output_col;
276
224k
  jpeg_component_info *compptr;
277
224k
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
224k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
224k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
224k
          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
695k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
470k
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
470k
    if (!compptr->component_needed)
292
55.0k
      continue;
293
    /* Align the virtual buffer for this component. */
294
415k
    buffer = (*cinfo->mem->access_virt_barray)
295
415k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
415k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
415k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
415k
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
412k
      block_rows = compptr->v_samp_factor;
301
3.31k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
3.31k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
3.31k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
3.31k
    }
306
415k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
415k
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
1.02M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
609k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
609k
      output_col = 0;
312
609k
      for (block_num = cinfo->master->first_MCU_col[ci];
313
5.87M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
5.26M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
5.26M
                        output_col);
316
5.26M
        buffer_ptr++;
317
5.26M
        output_col += compptr->_DCT_scaled_size;
318
5.26M
      }
319
609k
      output_ptr += compptr->_DCT_scaled_size;
320
609k
    }
321
415k
  }
322
323
224k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
223k
    return JPEG_ROW_COMPLETED;
325
1.55k
  return JPEG_SCAN_COMPLETED;
326
224k
}
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
1.05M
#define Q01_POS  1
342
1.05M
#define Q10_POS  8
343
1.05M
#define Q20_POS  16
344
1.05M
#define Q11_POS  9
345
1.05M
#define Q02_POS  2
346
809k
#define Q03_POS  3
347
809k
#define Q12_POS  10
348
808k
#define Q21_POS  17
349
808k
#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
6.05k
{
362
6.05k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
6.05k
  boolean smoothing_useful = FALSE;
364
6.05k
  int ci, coefi;
365
6.05k
  jpeg_component_info *compptr;
366
6.05k
  JQUANT_TBL *qtable;
367
6.05k
  int *coef_bits, *prev_coef_bits;
368
6.05k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
6.05k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
1.78k
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
4.27k
  if (coef->coef_bits_latch == NULL)
375
4.27k
    coef->coef_bits_latch = (int *)
376
4.27k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
4.27k
                                  cinfo->num_components * 2 *
378
4.27k
                                  (SAVED_COEFS * sizeof(int)));
379
4.27k
  coef_bits_latch = coef->coef_bits_latch;
380
4.27k
  prev_coef_bits_latch =
381
4.27k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
6.63k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
4.86k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
4.86k
    if ((qtable = compptr->quant_table) == NULL)
387
516
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
4.34k
    if (qtable->quantval[0] == 0 ||
390
4.34k
        qtable->quantval[Q01_POS] == 0 ||
391
4.34k
        qtable->quantval[Q10_POS] == 0 ||
392
4.34k
        qtable->quantval[Q20_POS] == 0 ||
393
4.34k
        qtable->quantval[Q11_POS] == 0 ||
394
4.34k
        qtable->quantval[Q02_POS] == 0 ||
395
4.34k
        qtable->quantval[Q03_POS] == 0 ||
396
4.34k
        qtable->quantval[Q12_POS] == 0 ||
397
4.34k
        qtable->quantval[Q21_POS] == 0 ||
398
4.34k
        qtable->quantval[Q30_POS] == 0)
399
1.79k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
2.55k
    coef_bits = cinfo->coef_bits[ci];
402
2.55k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
2.55k
    if (coef_bits[0] < 0)
404
194
      return FALSE;
405
2.36k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
23.6k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
21.2k
      if (cinfo->input_scan_number > 1)
409
10.3k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
10.8k
      else
411
10.8k
        prev_coef_bits_latch[coefi] = -1;
412
21.2k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
21.2k
      if (coef_bits[coefi] != 0)
414
19.9k
        smoothing_useful = TRUE;
415
21.2k
    }
416
2.36k
    coef_bits_latch += SAVED_COEFS;
417
2.36k
    prev_coef_bits_latch += SAVED_COEFS;
418
2.36k
  }
419
420
1.77k
  return smoothing_useful;
421
4.27k
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
361
3.65k
{
362
3.65k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
3.65k
  boolean smoothing_useful = FALSE;
364
3.65k
  int ci, coefi;
365
3.65k
  jpeg_component_info *compptr;
366
3.65k
  JQUANT_TBL *qtable;
367
3.65k
  int *coef_bits, *prev_coef_bits;
368
3.65k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
3.65k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
719
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
2.93k
  if (coef->coef_bits_latch == NULL)
375
2.93k
    coef->coef_bits_latch = (int *)
376
2.93k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
2.93k
                                  cinfo->num_components * 2 *
378
2.93k
                                  (SAVED_COEFS * sizeof(int)));
379
2.93k
  coef_bits_latch = coef->coef_bits_latch;
380
2.93k
  prev_coef_bits_latch =
381
2.93k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
4.48k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
3.34k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
3.34k
    if ((qtable = compptr->quant_table) == NULL)
387
385
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
2.95k
    if (qtable->quantval[0] == 0 ||
390
2.95k
        qtable->quantval[Q01_POS] == 0 ||
391
2.95k
        qtable->quantval[Q10_POS] == 0 ||
392
2.95k
        qtable->quantval[Q20_POS] == 0 ||
393
2.95k
        qtable->quantval[Q11_POS] == 0 ||
394
2.95k
        qtable->quantval[Q02_POS] == 0 ||
395
2.95k
        qtable->quantval[Q03_POS] == 0 ||
396
2.95k
        qtable->quantval[Q12_POS] == 0 ||
397
2.95k
        qtable->quantval[Q21_POS] == 0 ||
398
2.95k
        qtable->quantval[Q30_POS] == 0)
399
1.26k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
1.68k
    coef_bits = cinfo->coef_bits[ci];
402
1.68k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
1.68k
    if (coef_bits[0] < 0)
404
136
      return FALSE;
405
1.55k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
15.5k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
13.9k
      if (cinfo->input_scan_number > 1)
409
7.02k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
6.94k
      else
411
6.94k
        prev_coef_bits_latch[coefi] = -1;
412
13.9k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
13.9k
      if (coef_bits[coefi] != 0)
414
13.2k
        smoothing_useful = TRUE;
415
13.9k
    }
416
1.55k
    coef_bits_latch += SAVED_COEFS;
417
1.55k
    prev_coef_bits_latch += SAVED_COEFS;
418
1.55k
  }
419
420
1.14k
  return smoothing_useful;
421
2.93k
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
361
2.40k
{
362
2.40k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
2.40k
  boolean smoothing_useful = FALSE;
364
2.40k
  int ci, coefi;
365
2.40k
  jpeg_component_info *compptr;
366
2.40k
  JQUANT_TBL *qtable;
367
2.40k
  int *coef_bits, *prev_coef_bits;
368
2.40k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
2.40k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
1.06k
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
1.33k
  if (coef->coef_bits_latch == NULL)
375
1.33k
    coef->coef_bits_latch = (int *)
376
1.33k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
1.33k
                                  cinfo->num_components * 2 *
378
1.33k
                                  (SAVED_COEFS * sizeof(int)));
379
1.33k
  coef_bits_latch = coef->coef_bits_latch;
380
1.33k
  prev_coef_bits_latch =
381
1.33k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
2.14k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
1.51k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
1.51k
    if ((qtable = compptr->quant_table) == NULL)
387
131
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
1.38k
    if (qtable->quantval[0] == 0 ||
390
1.38k
        qtable->quantval[Q01_POS] == 0 ||
391
1.38k
        qtable->quantval[Q10_POS] == 0 ||
392
1.38k
        qtable->quantval[Q20_POS] == 0 ||
393
1.38k
        qtable->quantval[Q11_POS] == 0 ||
394
1.38k
        qtable->quantval[Q02_POS] == 0 ||
395
1.38k
        qtable->quantval[Q03_POS] == 0 ||
396
1.38k
        qtable->quantval[Q12_POS] == 0 ||
397
1.38k
        qtable->quantval[Q21_POS] == 0 ||
398
1.38k
        qtable->quantval[Q30_POS] == 0)
399
522
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
865
    coef_bits = cinfo->coef_bits[ci];
402
865
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
865
    if (coef_bits[0] < 0)
404
58
      return FALSE;
405
807
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
8.07k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
7.26k
      if (cinfo->input_scan_number > 1)
409
3.34k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
3.91k
      else
411
3.91k
        prev_coef_bits_latch[coefi] = -1;
412
7.26k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
7.26k
      if (coef_bits[coefi] != 0)
414
6.65k
        smoothing_useful = TRUE;
415
7.26k
    }
416
807
    coef_bits_latch += SAVED_COEFS;
417
807
    prev_coef_bits_latch += SAVED_COEFS;
418
807
  }
419
420
626
  return smoothing_useful;
421
1.33k
}
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
740k
{
431
740k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
740k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
740k
  JDIMENSION block_num, last_block_column;
434
740k
  int ci, block_row, block_rows, access_rows, image_block_row,
435
740k
    image_block_rows;
436
740k
  JBLOCKARRAY buffer;
437
740k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
740k
  JBLOCKROW next_block_row, next_next_block_row;
439
740k
  _JSAMPARRAY output_ptr;
440
740k
  JDIMENSION output_col;
441
740k
  jpeg_component_info *compptr;
442
740k
  _inverse_DCT_method_ptr inverse_DCT;
443
740k
  boolean change_dc;
444
740k
  JCOEF *workspace;
445
740k
  int *coef_bits;
446
740k
  JQUANT_TBL *quanttbl;
447
740k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
740k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
740k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
740k
      DC25;
451
740k
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
740k
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
740k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
740k
         !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
1.80M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
1.06M
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
1.06M
    if (!compptr->component_needed)
478
14.5k
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
1.04M
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
1.04M
      block_rows = compptr->v_samp_factor;
482
1.04M
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
1.04M
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
1.92k
      block_rows = compptr->v_samp_factor;
485
1.92k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
2.14k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
2.14k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
2.14k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
2.14k
      access_rows = block_rows; /* this iMCU row only */
491
2.14k
    }
492
    /* Align the virtual buffer for this component. */
493
1.04M
    if (cinfo->output_iMCU_row > 1) {
494
1.04M
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
1.04M
      buffer = (*cinfo->mem->access_virt_barray)
496
1.04M
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
1.04M
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
1.04M
         (JDIMENSION)access_rows, FALSE);
499
1.04M
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
1.04M
    } else if (cinfo->output_iMCU_row > 0) {
501
1.92k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
1.92k
      buffer = (*cinfo->mem->access_virt_barray)
503
1.92k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
1.92k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
1.92k
         (JDIMENSION)access_rows, FALSE);
506
1.92k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
2.14k
    } else {
508
2.14k
      buffer = (*cinfo->mem->access_virt_barray)
509
2.14k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
2.14k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
2.14k
    }
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
1.04M
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
544k
      coef_bits =
518
544k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
504k
    else
520
504k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
1.04M
    change_dc =
524
1.04M
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
1.04M
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
1.04M
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
1.04M
    quanttbl = compptr->quant_table;
529
1.04M
    Q00 = quanttbl->quantval[0];
530
1.04M
    Q01 = quanttbl->quantval[Q01_POS];
531
1.04M
    Q10 = quanttbl->quantval[Q10_POS];
532
1.04M
    Q20 = quanttbl->quantval[Q20_POS];
533
1.04M
    Q11 = quanttbl->quantval[Q11_POS];
534
1.04M
    Q02 = quanttbl->quantval[Q02_POS];
535
1.04M
    if (change_dc) {
536
806k
      Q03 = quanttbl->quantval[Q03_POS];
537
806k
      Q12 = quanttbl->quantval[Q12_POS];
538
806k
      Q21 = quanttbl->quantval[Q21_POS];
539
806k
      Q30 = quanttbl->quantval[Q30_POS];
540
806k
    }
541
1.04M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
1.04M
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
1.04M
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
2.54M
    for (block_row = 0; block_row < block_rows; block_row++) {
546
1.49M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
1.49M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
1.49M
      if (image_block_row > 0)
550
1.48M
        prev_block_row =
551
1.48M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
2.14k
      else
553
2.14k
        prev_block_row = buffer_ptr;
554
555
1.49M
      if (image_block_row > 1)
556
1.48M
        prev_prev_block_row =
557
1.48M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
4.21k
      else
559
4.21k
        prev_prev_block_row = prev_block_row;
560
561
1.49M
      if (image_block_row < image_block_rows - 1)
562
1.48M
        next_block_row =
563
1.48M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
2.14k
      else
565
2.14k
        next_block_row = buffer_ptr;
566
567
1.49M
      if (image_block_row < image_block_rows - 2)
568
1.48M
        next_next_block_row =
569
1.48M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
3.71k
      else
571
3.71k
        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
1.49M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
1.49M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
1.49M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
1.49M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
1.49M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
1.49M
      output_col = 0;
582
1.49M
      last_block_column = compptr->width_in_blocks - 1;
583
1.49M
      for (block_num = cinfo->master->first_MCU_col[ci];
584
14.2M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
12.7M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
12.7M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
12.7M
            block_num < last_block_column) {
590
858k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
858k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
858k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
858k
          DC19 = DC20 = (int)next_block_row[1][0];
594
858k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
858k
        }
596
12.7M
        if (block_num + 1 < last_block_column) {
597
10.3M
          DC05 = (int)prev_prev_block_row[2][0];
598
10.3M
          DC10 = (int)prev_block_row[2][0];
599
10.3M
          DC15 = (int)buffer_ptr[2][0];
600
10.3M
          DC20 = (int)next_block_row[2][0];
601
10.3M
          DC25 = (int)next_next_block_row[2][0];
602
10.3M
        }
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.7M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
12.0M
          num = Q00 * (change_dc ?
616
8.39M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
8.39M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
8.39M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
8.39M
                 DC21 - DC22 + DC24 + DC25) :
620
12.0M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
12.0M
          if (num >= 0) {
622
9.31M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
9.31M
            if (Al > 0 && pred >= (1 << Al))
624
747k
              pred = (1 << Al) - 1;
625
9.31M
          } else {
626
2.74M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
2.74M
            if (Al > 0 && pred >= (1 << Al))
628
613k
              pred = (1 << Al) - 1;
629
2.74M
            pred = -pred;
630
2.74M
          }
631
12.0M
          workspace[1] = (JCOEF)pred;
632
12.0M
        }
633
        /* AC10 */
634
12.7M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
12.1M
          num = Q00 * (change_dc ?
636
8.39M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
8.39M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
8.39M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
8.39M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
12.1M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
12.1M
          if (num >= 0) {
642
8.75M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
8.75M
            if (Al > 0 && pred >= (1 << Al))
644
1.05M
              pred = (1 << Al) - 1;
645
8.75M
          } else {
646
3.42M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
3.42M
            if (Al > 0 && pred >= (1 << Al))
648
938k
              pred = (1 << Al) - 1;
649
3.42M
            pred = -pred;
650
3.42M
          }
651
12.1M
          workspace[8] = (JCOEF)pred;
652
12.1M
        }
653
        /* AC20 */
654
12.7M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
12.1M
          num = Q00 * (change_dc ?
656
8.39M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
8.39M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
12.1M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
12.1M
          if (num >= 0) {
660
7.75M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
7.75M
            if (Al > 0 && pred >= (1 << Al))
662
933k
              pred = (1 << Al) - 1;
663
7.75M
          } else {
664
4.40M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
4.40M
            if (Al > 0 && pred >= (1 << Al))
666
952k
              pred = (1 << Al) - 1;
667
4.40M
            pred = -pred;
668
4.40M
          }
669
12.1M
          workspace[16] = (JCOEF)pred;
670
12.1M
        }
671
        /* AC11 */
672
12.7M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
12.1M
          num = Q00 * (change_dc ?
674
8.39M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
8.39M
                 9 * DC19 + DC21 - DC25) :
676
12.1M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
3.79M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
12.1M
          if (num >= 0) {
679
9.89M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
9.89M
            if (Al > 0 && pred >= (1 << Al))
681
414k
              pred = (1 << Al) - 1;
682
9.89M
          } else {
683
2.30M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
2.30M
            if (Al > 0 && pred >= (1 << Al))
685
424k
              pred = (1 << Al) - 1;
686
2.30M
            pred = -pred;
687
2.30M
          }
688
12.1M
          workspace[9] = (JCOEF)pred;
689
12.1M
        }
690
        /* AC02 */
691
12.7M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
12.2M
          num = Q00 * (change_dc ?
693
8.39M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
8.39M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
12.2M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
12.2M
          if (num >= 0) {
697
7.85M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
7.85M
            if (Al > 0 && pred >= (1 << Al))
699
598k
              pred = (1 << Al) - 1;
700
7.85M
          } else {
701
4.35M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
4.35M
            if (Al > 0 && pred >= (1 << Al))
703
610k
              pred = (1 << Al) - 1;
704
4.35M
            pred = -pred;
705
4.35M
          }
706
12.2M
          workspace[2] = (JCOEF)pred;
707
12.2M
        }
708
12.7M
        if (change_dc) {
709
          /* AC03 */
710
8.39M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
8.39M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
8.39M
            if (num >= 0) {
713
6.86M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
6.86M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
6.86M
            } else {
717
1.52M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
1.52M
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
1.52M
              pred = -pred;
721
1.52M
            }
722
8.39M
            workspace[3] = (JCOEF)pred;
723
8.39M
          }
724
          /* AC12 */
725
8.39M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
8.39M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
8.39M
            if (num >= 0) {
728
5.37M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
5.37M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
5.37M
            } else {
732
3.01M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
3.01M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
3.01M
              pred = -pred;
736
3.01M
            }
737
8.39M
            workspace[10] = (JCOEF)pred;
738
8.39M
          }
739
          /* AC21 */
740
8.39M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
8.39M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
8.39M
            if (num >= 0) {
743
4.81M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
4.81M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
4.81M
            } else {
747
3.57M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
3.57M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
3.57M
              pred = -pred;
751
3.57M
            }
752
8.39M
            workspace[17] = (JCOEF)pred;
753
8.39M
          }
754
          /* AC30 */
755
8.39M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
8.39M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
8.39M
            if (num >= 0) {
758
6.40M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
6.40M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
6.40M
            } else {
762
1.99M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
1.99M
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
1.99M
              pred = -pred;
766
1.99M
            }
767
8.39M
            workspace[24] = (JCOEF)pred;
768
8.39M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
8.39M
          num = Q00 *
773
8.39M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
8.39M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
8.39M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
8.39M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
8.39M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
8.39M
          if (num >= 0) {
779
5.42M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
5.42M
          } else {
781
2.96M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
2.96M
            pred = -pred;
783
2.96M
          }
784
8.39M
          workspace[0] = (JCOEF)pred;
785
8.39M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
12.7M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
12.7M
                        output_col);
790
        /* Advance for next column */
791
12.7M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
12.7M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
12.7M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
12.7M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
12.7M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
12.7M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
12.7M
          prev_prev_block_row++, next_next_block_row++;
798
12.7M
        output_col += compptr->_DCT_scaled_size;
799
12.7M
      }
800
1.49M
      output_ptr += compptr->_DCT_scaled_size;
801
1.49M
    }
802
1.04M
  }
803
804
740k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
738k
    return JPEG_ROW_COMPLETED;
806
1.69k
  return JPEG_SCAN_COMPLETED;
807
740k
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
430
483k
{
431
483k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
483k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
483k
  JDIMENSION block_num, last_block_column;
434
483k
  int ci, block_row, block_rows, access_rows, image_block_row,
435
483k
    image_block_rows;
436
483k
  JBLOCKARRAY buffer;
437
483k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
483k
  JBLOCKROW next_block_row, next_next_block_row;
439
483k
  _JSAMPARRAY output_ptr;
440
483k
  JDIMENSION output_col;
441
483k
  jpeg_component_info *compptr;
442
483k
  _inverse_DCT_method_ptr inverse_DCT;
443
483k
  boolean change_dc;
444
483k
  JCOEF *workspace;
445
483k
  int *coef_bits;
446
483k
  JQUANT_TBL *quanttbl;
447
483k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
483k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
483k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
483k
      DC25;
451
483k
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
483k
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
483k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
483k
         !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
1.17M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
686k
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
686k
    if (!compptr->component_needed)
478
3.60k
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
682k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
680k
      block_rows = compptr->v_samp_factor;
482
680k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
680k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
1.27k
      block_rows = compptr->v_samp_factor;
485
1.27k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
1.44k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
1.44k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
1.44k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
1.44k
      access_rows = block_rows; /* this iMCU row only */
491
1.44k
    }
492
    /* Align the virtual buffer for this component. */
493
682k
    if (cinfo->output_iMCU_row > 1) {
494
680k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
680k
      buffer = (*cinfo->mem->access_virt_barray)
496
680k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
680k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
680k
         (JDIMENSION)access_rows, FALSE);
499
680k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
680k
    } else if (cinfo->output_iMCU_row > 0) {
501
1.27k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
1.27k
      buffer = (*cinfo->mem->access_virt_barray)
503
1.27k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
1.27k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
1.27k
         (JDIMENSION)access_rows, FALSE);
506
1.27k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
1.44k
    } else {
508
1.44k
      buffer = (*cinfo->mem->access_virt_barray)
509
1.44k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
1.44k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
1.44k
    }
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
682k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
367k
      coef_bits =
518
367k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
315k
    else
520
315k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
682k
    change_dc =
524
682k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
682k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
682k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
682k
    quanttbl = compptr->quant_table;
529
682k
    Q00 = quanttbl->quantval[0];
530
682k
    Q01 = quanttbl->quantval[Q01_POS];
531
682k
    Q10 = quanttbl->quantval[Q10_POS];
532
682k
    Q20 = quanttbl->quantval[Q20_POS];
533
682k
    Q11 = quanttbl->quantval[Q11_POS];
534
682k
    Q02 = quanttbl->quantval[Q02_POS];
535
682k
    if (change_dc) {
536
547k
      Q03 = quanttbl->quantval[Q03_POS];
537
547k
      Q12 = quanttbl->quantval[Q12_POS];
538
547k
      Q21 = quanttbl->quantval[Q21_POS];
539
547k
      Q30 = quanttbl->quantval[Q30_POS];
540
547k
    }
541
682k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
682k
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
682k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
1.62M
    for (block_row = 0; block_row < block_rows; block_row++) {
546
940k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
940k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
940k
      if (image_block_row > 0)
550
939k
        prev_block_row =
551
939k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
1.44k
      else
553
1.44k
        prev_block_row = buffer_ptr;
554
555
940k
      if (image_block_row > 1)
556
937k
        prev_prev_block_row =
557
937k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
2.83k
      else
559
2.83k
        prev_prev_block_row = prev_block_row;
560
561
940k
      if (image_block_row < image_block_rows - 1)
562
939k
        next_block_row =
563
939k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
1.44k
      else
565
1.44k
        next_block_row = buffer_ptr;
566
567
940k
      if (image_block_row < image_block_rows - 2)
568
938k
        next_next_block_row =
569
938k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
2.56k
      else
571
2.56k
        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
940k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
940k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
940k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
940k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
940k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
940k
      output_col = 0;
582
940k
      last_block_column = compptr->width_in_blocks - 1;
583
940k
      for (block_num = cinfo->master->first_MCU_col[ci];
584
9.76M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
8.82M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
8.82M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
8.82M
            block_num < last_block_column) {
590
553k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
553k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
553k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
553k
          DC19 = DC20 = (int)next_block_row[1][0];
594
553k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
553k
        }
596
8.82M
        if (block_num + 1 < last_block_column) {
597
7.32M
          DC05 = (int)prev_prev_block_row[2][0];
598
7.32M
          DC10 = (int)prev_block_row[2][0];
599
7.32M
          DC15 = (int)buffer_ptr[2][0];
600
7.32M
          DC20 = (int)next_block_row[2][0];
601
7.32M
          DC25 = (int)next_next_block_row[2][0];
602
7.32M
        }
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
8.82M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
8.46M
          num = Q00 * (change_dc ?
616
5.88M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
5.88M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
5.88M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
5.88M
                 DC21 - DC22 + DC24 + DC25) :
620
8.46M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
8.46M
          if (num >= 0) {
622
6.61M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
6.61M
            if (Al > 0 && pred >= (1 << Al))
624
571k
              pred = (1 << Al) - 1;
625
6.61M
          } else {
626
1.84M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
1.84M
            if (Al > 0 && pred >= (1 << Al))
628
427k
              pred = (1 << Al) - 1;
629
1.84M
            pred = -pred;
630
1.84M
          }
631
8.46M
          workspace[1] = (JCOEF)pred;
632
8.46M
        }
633
        /* AC10 */
634
8.82M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
8.54M
          num = Q00 * (change_dc ?
636
5.88M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
5.88M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
5.88M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
5.88M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
8.54M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
8.54M
          if (num >= 0) {
642
6.12M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
6.12M
            if (Al > 0 && pred >= (1 << Al))
644
778k
              pred = (1 << Al) - 1;
645
6.12M
          } else {
646
2.41M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
2.41M
            if (Al > 0 && pred >= (1 << Al))
648
668k
              pred = (1 << Al) - 1;
649
2.41M
            pred = -pred;
650
2.41M
          }
651
8.54M
          workspace[8] = (JCOEF)pred;
652
8.54M
        }
653
        /* AC20 */
654
8.82M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
8.49M
          num = Q00 * (change_dc ?
656
5.88M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
5.88M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
8.49M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
8.49M
          if (num >= 0) {
660
5.53M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
5.53M
            if (Al > 0 && pred >= (1 << Al))
662
637k
              pred = (1 << Al) - 1;
663
5.53M
          } else {
664
2.95M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
2.95M
            if (Al > 0 && pred >= (1 << Al))
666
648k
              pred = (1 << Al) - 1;
667
2.95M
            pred = -pred;
668
2.95M
          }
669
8.49M
          workspace[16] = (JCOEF)pred;
670
8.49M
        }
671
        /* AC11 */
672
8.82M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
8.51M
          num = Q00 * (change_dc ?
674
5.88M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
5.88M
                 9 * DC19 + DC21 - DC25) :
676
8.51M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
2.63M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
8.51M
          if (num >= 0) {
679
7.00M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
7.00M
            if (Al > 0 && pred >= (1 << Al))
681
287k
              pred = (1 << Al) - 1;
682
7.00M
          } else {
683
1.50M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
1.50M
            if (Al > 0 && pred >= (1 << Al))
685
299k
              pred = (1 << Al) - 1;
686
1.50M
            pred = -pred;
687
1.50M
          }
688
8.51M
          workspace[9] = (JCOEF)pred;
689
8.51M
        }
690
        /* AC02 */
691
8.82M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
8.54M
          num = Q00 * (change_dc ?
693
5.88M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
5.88M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
8.54M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
8.54M
          if (num >= 0) {
697
5.59M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
5.59M
            if (Al > 0 && pred >= (1 << Al))
699
387k
              pred = (1 << Al) - 1;
700
5.59M
          } else {
701
2.94M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
2.94M
            if (Al > 0 && pred >= (1 << Al))
703
401k
              pred = (1 << Al) - 1;
704
2.94M
            pred = -pred;
705
2.94M
          }
706
8.54M
          workspace[2] = (JCOEF)pred;
707
8.54M
        }
708
8.82M
        if (change_dc) {
709
          /* AC03 */
710
5.88M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
5.88M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
5.88M
            if (num >= 0) {
713
4.85M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
4.85M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
4.85M
            } else {
717
1.02M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
1.02M
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
1.02M
              pred = -pred;
721
1.02M
            }
722
5.88M
            workspace[3] = (JCOEF)pred;
723
5.88M
          }
724
          /* AC12 */
725
5.88M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
5.88M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
5.88M
            if (num >= 0) {
728
3.98M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
3.98M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
3.98M
            } else {
732
1.89M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
1.89M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
1.89M
              pred = -pred;
736
1.89M
            }
737
5.88M
            workspace[10] = (JCOEF)pred;
738
5.88M
          }
739
          /* AC21 */
740
5.88M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
5.88M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
5.88M
            if (num >= 0) {
743
3.47M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
3.47M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
3.47M
            } else {
747
2.40M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
2.40M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
2.40M
              pred = -pred;
751
2.40M
            }
752
5.88M
            workspace[17] = (JCOEF)pred;
753
5.88M
          }
754
          /* AC30 */
755
5.88M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
5.88M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
5.88M
            if (num >= 0) {
758
4.46M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
4.46M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
4.46M
            } else {
762
1.41M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
1.41M
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
1.41M
              pred = -pred;
766
1.41M
            }
767
5.88M
            workspace[24] = (JCOEF)pred;
768
5.88M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
5.88M
          num = Q00 *
773
5.88M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
5.88M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
5.88M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
5.88M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
5.88M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
5.88M
          if (num >= 0) {
779
3.95M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
3.95M
          } else {
781
1.92M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
1.92M
            pred = -pred;
783
1.92M
          }
784
5.88M
          workspace[0] = (JCOEF)pred;
785
5.88M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
8.82M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
8.82M
                        output_col);
790
        /* Advance for next column */
791
8.82M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
8.82M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
8.82M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
8.82M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
8.82M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
8.82M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
8.82M
          prev_prev_block_row++, next_next_block_row++;
798
8.82M
        output_col += compptr->_DCT_scaled_size;
799
8.82M
      }
800
940k
      output_ptr += compptr->_DCT_scaled_size;
801
940k
    }
802
682k
  }
803
804
483k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
482k
    return JPEG_ROW_COMPLETED;
806
1.13k
  return JPEG_SCAN_COMPLETED;
807
483k
}
jdcoefct-12.c:decompress_smooth_data
Line
Count
Source
430
256k
{
431
256k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
256k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
256k
  JDIMENSION block_num, last_block_column;
434
256k
  int ci, block_row, block_rows, access_rows, image_block_row,
435
256k
    image_block_rows;
436
256k
  JBLOCKARRAY buffer;
437
256k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
256k
  JBLOCKROW next_block_row, next_next_block_row;
439
256k
  _JSAMPARRAY output_ptr;
440
256k
  JDIMENSION output_col;
441
256k
  jpeg_component_info *compptr;
442
256k
  _inverse_DCT_method_ptr inverse_DCT;
443
256k
  boolean change_dc;
444
256k
  JCOEF *workspace;
445
256k
  int *coef_bits;
446
256k
  JQUANT_TBL *quanttbl;
447
256k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
256k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
256k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
256k
      DC25;
451
256k
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
256k
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
256k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
256k
         !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
633k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
377k
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
377k
    if (!compptr->component_needed)
478
10.9k
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
366k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
364k
      block_rows = compptr->v_samp_factor;
482
364k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
364k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
644
      block_rows = compptr->v_samp_factor;
485
644
      access_rows = block_rows * 2; /* this and next iMCU row */
486
698
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
698
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
698
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
698
      access_rows = block_rows; /* this iMCU row only */
491
698
    }
492
    /* Align the virtual buffer for this component. */
493
366k
    if (cinfo->output_iMCU_row > 1) {
494
364k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
364k
      buffer = (*cinfo->mem->access_virt_barray)
496
364k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
364k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
364k
         (JDIMENSION)access_rows, FALSE);
499
364k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
364k
    } else if (cinfo->output_iMCU_row > 0) {
501
644
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
644
      buffer = (*cinfo->mem->access_virt_barray)
503
644
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
644
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
644
         (JDIMENSION)access_rows, FALSE);
506
644
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
698
    } else {
508
698
      buffer = (*cinfo->mem->access_virt_barray)
509
698
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
698
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
698
    }
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
366k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
177k
      coef_bits =
518
177k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
188k
    else
520
188k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
366k
    change_dc =
524
366k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
366k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
366k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
366k
    quanttbl = compptr->quant_table;
529
366k
    Q00 = quanttbl->quantval[0];
530
366k
    Q01 = quanttbl->quantval[Q01_POS];
531
366k
    Q10 = quanttbl->quantval[Q10_POS];
532
366k
    Q20 = quanttbl->quantval[Q20_POS];
533
366k
    Q11 = quanttbl->quantval[Q11_POS];
534
366k
    Q02 = quanttbl->quantval[Q02_POS];
535
366k
    if (change_dc) {
536
258k
      Q03 = quanttbl->quantval[Q03_POS];
537
258k
      Q12 = quanttbl->quantval[Q12_POS];
538
258k
      Q21 = quanttbl->quantval[Q21_POS];
539
258k
      Q30 = quanttbl->quantval[Q30_POS];
540
258k
    }
541
366k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
366k
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
366k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
916k
    for (block_row = 0; block_row < block_rows; block_row++) {
546
550k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
550k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
550k
      if (image_block_row > 0)
550
549k
        prev_block_row =
551
549k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
698
      else
553
698
        prev_block_row = buffer_ptr;
554
555
550k
      if (image_block_row > 1)
556
549k
        prev_prev_block_row =
557
549k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
1.37k
      else
559
1.37k
        prev_prev_block_row = prev_block_row;
560
561
550k
      if (image_block_row < image_block_rows - 1)
562
549k
        next_block_row =
563
549k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
698
      else
565
698
        next_block_row = buffer_ptr;
566
567
550k
      if (image_block_row < image_block_rows - 2)
568
549k
        next_next_block_row =
569
549k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
1.15k
      else
571
1.15k
        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
550k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
550k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
550k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
550k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
550k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
550k
      output_col = 0;
582
550k
      last_block_column = compptr->width_in_blocks - 1;
583
550k
      for (block_num = cinfo->master->first_MCU_col[ci];
584
4.43M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
3.88M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
3.88M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
3.88M
            block_num < last_block_column) {
590
304k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
304k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
304k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
304k
          DC19 = DC20 = (int)next_block_row[1][0];
594
304k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
304k
        }
596
3.88M
        if (block_num + 1 < last_block_column) {
597
3.03M
          DC05 = (int)prev_prev_block_row[2][0];
598
3.03M
          DC10 = (int)prev_block_row[2][0];
599
3.03M
          DC15 = (int)buffer_ptr[2][0];
600
3.03M
          DC20 = (int)next_block_row[2][0];
601
3.03M
          DC25 = (int)next_next_block_row[2][0];
602
3.03M
        }
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
3.88M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
3.59M
          num = Q00 * (change_dc ?
616
2.51M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
2.51M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
2.51M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
2.51M
                 DC21 - DC22 + DC24 + DC25) :
620
3.59M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
3.59M
          if (num >= 0) {
622
2.69M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
2.69M
            if (Al > 0 && pred >= (1 << Al))
624
176k
              pred = (1 << Al) - 1;
625
2.69M
          } else {
626
895k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
895k
            if (Al > 0 && pred >= (1 << Al))
628
185k
              pred = (1 << Al) - 1;
629
895k
            pred = -pred;
630
895k
          }
631
3.59M
          workspace[1] = (JCOEF)pred;
632
3.59M
        }
633
        /* AC10 */
634
3.88M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
3.63M
          num = Q00 * (change_dc ?
636
2.51M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
2.51M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
2.51M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
2.51M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
3.63M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
3.63M
          if (num >= 0) {
642
2.63M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
2.63M
            if (Al > 0 && pred >= (1 << Al))
644
276k
              pred = (1 << Al) - 1;
645
2.63M
          } else {
646
1.00M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
1.00M
            if (Al > 0 && pred >= (1 << Al))
648
270k
              pred = (1 << Al) - 1;
649
1.00M
            pred = -pred;
650
1.00M
          }
651
3.63M
          workspace[8] = (JCOEF)pred;
652
3.63M
        }
653
        /* AC20 */
654
3.88M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
3.66M
          num = Q00 * (change_dc ?
656
2.51M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
2.51M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
3.66M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
3.66M
          if (num >= 0) {
660
2.21M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
2.21M
            if (Al > 0 && pred >= (1 << Al))
662
296k
              pred = (1 << Al) - 1;
663
2.21M
          } else {
664
1.44M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
1.44M
            if (Al > 0 && pred >= (1 << Al))
666
304k
              pred = (1 << Al) - 1;
667
1.44M
            pred = -pred;
668
1.44M
          }
669
3.66M
          workspace[16] = (JCOEF)pred;
670
3.66M
        }
671
        /* AC11 */
672
3.88M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
3.67M
          num = Q00 * (change_dc ?
674
2.51M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
2.51M
                 9 * DC19 + DC21 - DC25) :
676
3.67M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
1.16M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
3.67M
          if (num >= 0) {
679
2.88M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
2.88M
            if (Al > 0 && pred >= (1 << Al))
681
127k
              pred = (1 << Al) - 1;
682
2.88M
          } else {
683
793k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
793k
            if (Al > 0 && pred >= (1 << Al))
685
125k
              pred = (1 << Al) - 1;
686
793k
            pred = -pred;
687
793k
          }
688
3.67M
          workspace[9] = (JCOEF)pred;
689
3.67M
        }
690
        /* AC02 */
691
3.88M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
3.67M
          num = Q00 * (change_dc ?
693
2.51M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
2.51M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
3.67M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
3.67M
          if (num >= 0) {
697
2.26M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
2.26M
            if (Al > 0 && pred >= (1 << Al))
699
210k
              pred = (1 << Al) - 1;
700
2.26M
          } else {
701
1.40M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
1.40M
            if (Al > 0 && pred >= (1 << Al))
703
209k
              pred = (1 << Al) - 1;
704
1.40M
            pred = -pred;
705
1.40M
          }
706
3.67M
          workspace[2] = (JCOEF)pred;
707
3.67M
        }
708
3.88M
        if (change_dc) {
709
          /* AC03 */
710
2.51M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
2.51M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
2.51M
            if (num >= 0) {
713
2.00M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
2.00M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
2.00M
            } else {
717
504k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
504k
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
504k
              pred = -pred;
721
504k
            }
722
2.51M
            workspace[3] = (JCOEF)pred;
723
2.51M
          }
724
          /* AC12 */
725
2.51M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
2.51M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
2.51M
            if (num >= 0) {
728
1.39M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
1.39M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
1.39M
            } else {
732
1.12M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
1.12M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
1.12M
              pred = -pred;
736
1.12M
            }
737
2.51M
            workspace[10] = (JCOEF)pred;
738
2.51M
          }
739
          /* AC21 */
740
2.51M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
2.51M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
2.51M
            if (num >= 0) {
743
1.34M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
1.34M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
1.34M
            } else {
747
1.16M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
1.16M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
1.16M
              pred = -pred;
751
1.16M
            }
752
2.51M
            workspace[17] = (JCOEF)pred;
753
2.51M
          }
754
          /* AC30 */
755
2.51M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
2.51M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
2.51M
            if (num >= 0) {
758
1.93M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
1.93M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
1.93M
            } else {
762
572k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
572k
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
572k
              pred = -pred;
766
572k
            }
767
2.51M
            workspace[24] = (JCOEF)pred;
768
2.51M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
2.51M
          num = Q00 *
773
2.51M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
2.51M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
2.51M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
2.51M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
2.51M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
2.51M
          if (num >= 0) {
779
1.46M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
1.46M
          } else {
781
1.04M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
1.04M
            pred = -pred;
783
1.04M
          }
784
2.51M
          workspace[0] = (JCOEF)pred;
785
2.51M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
3.88M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
3.88M
                        output_col);
790
        /* Advance for next column */
791
3.88M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
3.88M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
3.88M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
3.88M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
3.88M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
3.88M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
3.88M
          prev_prev_block_row++, next_next_block_row++;
798
3.88M
        output_col += compptr->_DCT_scaled_size;
799
3.88M
      }
800
550k
      output_ptr += compptr->_DCT_scaled_size;
801
550k
    }
802
366k
  }
803
804
256k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
255k
    return JPEG_ROW_COMPLETED;
806
568
  return JPEG_SCAN_COMPLETED;
807
256k
}
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
53.6k
{
819
53.6k
  my_coef_ptr coef;
820
821
53.6k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
36
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
53.6k
  coef = (my_coef_ptr)
825
53.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
53.6k
                                sizeof(my_coef_controller));
827
53.6k
  memset(coef, 0, sizeof(my_coef_controller));
828
53.6k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
53.6k
  coef->pub.start_input_pass = start_input_pass;
830
53.6k
  coef->pub.start_output_pass = start_output_pass;
831
53.6k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
53.6k
  coef->coef_bits_latch = NULL;
833
53.6k
#endif
834
835
  /* Create the coefficient buffer. */
836
53.6k
  if (need_full_buffer) {
837
48.0k
#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
48.0k
    int ci, access_rows;
842
48.0k
    jpeg_component_info *compptr;
843
844
133k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
85.8k
         ci++, compptr++) {
846
85.8k
      access_rows = compptr->v_samp_factor;
847
85.8k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
85.8k
      if (cinfo->progressive_mode)
850
37.9k
        access_rows *= 5;
851
85.8k
#endif
852
85.8k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
85.8k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
85.8k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
85.8k
                               (long)compptr->h_samp_factor),
856
85.8k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
85.8k
                               (long)compptr->v_samp_factor),
858
85.8k
         (JDIMENSION)access_rows);
859
85.8k
    }
860
48.0k
    coef->pub.consume_data = consume_data;
861
48.0k
    coef->pub._decompress_data = decompress_data;
862
48.0k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
48.0k
  } else {
867
    /* We only need a single-MCU buffer. */
868
5.56k
    JBLOCKROW buffer;
869
5.56k
    int i;
870
871
5.56k
    buffer = (JBLOCKROW)
872
5.56k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
5.56k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
60.8k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
55.2k
      coef->MCU_buffer[i] = buffer + i;
876
55.2k
    }
877
5.56k
    coef->pub.consume_data = dummy_consume_data;
878
5.56k
    coef->pub._decompress_data = decompress_onepass;
879
5.56k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
5.56k
  }
881
882
  /* Allocate the workspace buffer */
883
53.6k
  coef->workspace = (JCOEF *)
884
53.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
53.6k
                                sizeof(JCOEF) * DCTSIZE2);
886
53.6k
}
jinit_d_coef_controller
Line
Count
Source
818
41.1k
{
819
41.1k
  my_coef_ptr coef;
820
821
41.1k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
36
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
41.1k
  coef = (my_coef_ptr)
825
41.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
41.1k
                                sizeof(my_coef_controller));
827
41.1k
  memset(coef, 0, sizeof(my_coef_controller));
828
41.1k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
41.1k
  coef->pub.start_input_pass = start_input_pass;
830
41.1k
  coef->pub.start_output_pass = start_output_pass;
831
41.1k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
41.1k
  coef->coef_bits_latch = NULL;
833
41.1k
#endif
834
835
  /* Create the coefficient buffer. */
836
41.1k
  if (need_full_buffer) {
837
36.4k
#ifdef D_MULTISCAN_FILES_SUPPORTED
838
    /* Allocate a full-image virtual array for each component, */
839
    /* padded to a multiple of samp_factor DCT blocks in each direction. */
840
    /* Note we ask for a pre-zeroed array. */
841
36.4k
    int ci, access_rows;
842
36.4k
    jpeg_component_info *compptr;
843
844
99.8k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
63.4k
         ci++, compptr++) {
846
63.4k
      access_rows = compptr->v_samp_factor;
847
63.4k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
63.4k
      if (cinfo->progressive_mode)
850
30.4k
        access_rows *= 5;
851
63.4k
#endif
852
63.4k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
63.4k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
63.4k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
63.4k
                               (long)compptr->h_samp_factor),
856
63.4k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
63.4k
                               (long)compptr->v_samp_factor),
858
63.4k
         (JDIMENSION)access_rows);
859
63.4k
    }
860
36.4k
    coef->pub.consume_data = consume_data;
861
36.4k
    coef->pub._decompress_data = decompress_data;
862
36.4k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
36.4k
  } else {
867
    /* We only need a single-MCU buffer. */
868
4.62k
    JBLOCKROW buffer;
869
4.62k
    int i;
870
871
4.62k
    buffer = (JBLOCKROW)
872
4.62k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
4.62k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
50.5k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
45.8k
      coef->MCU_buffer[i] = buffer + i;
876
45.8k
    }
877
4.62k
    coef->pub.consume_data = dummy_consume_data;
878
4.62k
    coef->pub._decompress_data = decompress_onepass;
879
4.62k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
4.62k
  }
881
882
  /* Allocate the workspace buffer */
883
41.1k
  coef->workspace = (JCOEF *)
884
41.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
41.1k
                                sizeof(JCOEF) * DCTSIZE2);
886
41.1k
}
j12init_d_coef_controller
Line
Count
Source
818
12.5k
{
819
12.5k
  my_coef_ptr coef;
820
821
12.5k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
12.5k
  coef = (my_coef_ptr)
825
12.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
12.5k
                                sizeof(my_coef_controller));
827
12.5k
  memset(coef, 0, sizeof(my_coef_controller));
828
12.5k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
12.5k
  coef->pub.start_input_pass = start_input_pass;
830
12.5k
  coef->pub.start_output_pass = start_output_pass;
831
12.5k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
12.5k
  coef->coef_bits_latch = NULL;
833
12.5k
#endif
834
835
  /* Create the coefficient buffer. */
836
12.5k
  if (need_full_buffer) {
837
11.5k
#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
11.5k
    int ci, access_rows;
842
11.5k
    jpeg_component_info *compptr;
843
844
34.0k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
22.4k
         ci++, compptr++) {
846
22.4k
      access_rows = compptr->v_samp_factor;
847
22.4k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
22.4k
      if (cinfo->progressive_mode)
850
7.53k
        access_rows *= 5;
851
22.4k
#endif
852
22.4k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
22.4k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
22.4k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
22.4k
                               (long)compptr->h_samp_factor),
856
22.4k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
22.4k
                               (long)compptr->v_samp_factor),
858
22.4k
         (JDIMENSION)access_rows);
859
22.4k
    }
860
11.5k
    coef->pub.consume_data = consume_data;
861
11.5k
    coef->pub._decompress_data = decompress_data;
862
11.5k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
11.5k
  } else {
867
    /* We only need a single-MCU buffer. */
868
937
    JBLOCKROW buffer;
869
937
    int i;
870
871
937
    buffer = (JBLOCKROW)
872
937
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
937
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
10.3k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
9.37k
      coef->MCU_buffer[i] = buffer + i;
876
9.37k
    }
877
937
    coef->pub.consume_data = dummy_consume_data;
878
937
    coef->pub._decompress_data = decompress_onepass;
879
937
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
937
  }
881
882
  /* Allocate the workspace buffer */
883
12.5k
  coef->workspace = (JCOEF *)
884
12.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
12.5k
                                sizeof(JCOEF) * DCTSIZE2);
886
12.5k
}