Coverage Report

Created: 2026-03-12 08:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/src/jdcoefct.c
Line
Count
Source
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
456k
{
48
456k
  cinfo->input_iMCU_row = 0;
49
456k
  start_iMCU_row(cinfo);
50
456k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
47
424k
{
48
424k
  cinfo->input_iMCU_row = 0;
49
424k
  start_iMCU_row(cinfo);
50
424k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
47
31.4k
{
48
31.4k
  cinfo->input_iMCU_row = 0;
49
31.4k
  start_iMCU_row(cinfo);
50
31.4k
}
51
52
53
/*
54
 * Initialize for an output processing pass.
55
 */
56
57
METHODDEF(void)
58
start_output_pass(j_decompress_ptr cinfo)
59
102k
{
60
102k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
102k
  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
102k
  if (coef->pub.coef_arrays != NULL) {
65
81.9k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
26.8k
      coef->pub._decompress_data = decompress_smooth_data;
67
55.0k
    else
68
55.0k
      coef->pub._decompress_data = decompress_data;
69
81.9k
  }
70
102k
#endif
71
102k
  cinfo->output_iMCU_row = 0;
72
102k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
59
90.5k
{
60
90.5k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
90.5k
  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
90.5k
  if (coef->pub.coef_arrays != NULL) {
65
72.7k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
22.8k
      coef->pub._decompress_data = decompress_smooth_data;
67
49.8k
    else
68
49.8k
      coef->pub._decompress_data = decompress_data;
69
72.7k
  }
70
90.5k
#endif
71
90.5k
  cinfo->output_iMCU_row = 0;
72
90.5k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
59
11.7k
{
60
11.7k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
11.7k
  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
11.7k
  if (coef->pub.coef_arrays != NULL) {
65
9.15k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
3.97k
      coef->pub._decompress_data = decompress_smooth_data;
67
5.18k
    else
68
5.18k
      coef->pub._decompress_data = decompress_data;
69
9.15k
  }
70
11.7k
#endif
71
11.7k
  cinfo->output_iMCU_row = 0;
72
11.7k
}
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
13.3M
{
88
13.3M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
13.3M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
13.3M
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
13.3M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
13.3M
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
13.3M
  _JSAMPARRAY output_ptr;
94
13.3M
  JDIMENSION start_col, output_col;
95
13.3M
  jpeg_component_info *compptr;
96
13.3M
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
28.4M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
15.1M
       yoffset++) {
101
91.9M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
76.8M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
76.8M
      jzero_far((void *)coef->MCU_buffer[0],
105
76.8M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
76.8M
      if (!cinfo->entropy->insufficient_data)
107
25.9M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
76.8M
      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
76.8M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
76.7M
          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
74.4M
        blkn = 0;               /* index of current DCT block within MCU */
126
177M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
102M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
102M
          if (!compptr->component_needed) {
130
179k
            blkn += compptr->MCU_blocks;
131
179k
            continue;
132
179k
          }
133
102M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
102M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
66.9M
                         compptr->MCU_width : compptr->last_col_width;
136
102M
          output_ptr = output_buf[compptr->component_index] +
137
102M
                       yoffset * compptr->_DCT_scaled_size;
138
102M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
102M
                      compptr->MCU_sample_width;
140
209M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
107M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
106M
                yoffset + yindex < compptr->last_row_height) {
143
106M
              output_col = start_col;
144
216M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
109M
                (*inverse_DCT) (cinfo, compptr,
146
109M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
109M
                                output_ptr, output_col);
148
109M
                output_col += compptr->_DCT_scaled_size;
149
109M
              }
150
106M
            }
151
107M
            blkn += compptr->MCU_width;
152
107M
            output_ptr += compptr->_DCT_scaled_size;
153
107M
          }
154
102M
        }
155
74.4M
      }
156
76.8M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
15.1M
    coef->MCU_ctr = 0;
159
15.1M
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
13.3M
  cinfo->output_iMCU_row++;
162
13.3M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
13.3M
    start_iMCU_row(cinfo);
164
13.3M
    return JPEG_ROW_COMPLETED;
165
13.3M
  }
166
  /* Completed the scan */
167
17.7k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
17.7k
  return JPEG_SCAN_COMPLETED;
169
13.3M
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
87
12.7M
{
88
12.7M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
12.7M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
12.7M
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
12.7M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
12.7M
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
12.7M
  _JSAMPARRAY output_ptr;
94
12.7M
  JDIMENSION start_col, output_col;
95
12.7M
  jpeg_component_info *compptr;
96
12.7M
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
27.0M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
14.2M
       yoffset++) {
101
83.3M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
69.0M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
69.0M
      jzero_far((void *)coef->MCU_buffer[0],
105
69.0M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
69.0M
      if (!cinfo->entropy->insufficient_data)
107
21.0M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
69.0M
      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
69.0M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
69.0M
          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
67.3M
        blkn = 0;               /* index of current DCT block within MCU */
126
162M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
94.9M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
94.9M
          if (!compptr->component_needed) {
130
107k
            blkn += compptr->MCU_blocks;
131
107k
            continue;
132
107k
          }
133
94.8M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
94.8M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
60.1M
                         compptr->MCU_width : compptr->last_col_width;
136
94.8M
          output_ptr = output_buf[compptr->component_index] +
137
94.8M
                       yoffset * compptr->_DCT_scaled_size;
138
94.8M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
94.8M
                      compptr->MCU_sample_width;
140
193M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
98.7M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
98.2M
                yoffset + yindex < compptr->last_row_height) {
143
98.2M
              output_col = start_col;
144
199M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
100M
                (*inverse_DCT) (cinfo, compptr,
146
100M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
100M
                                output_ptr, output_col);
148
100M
                output_col += compptr->_DCT_scaled_size;
149
100M
              }
150
98.2M
            }
151
98.7M
            blkn += compptr->MCU_width;
152
98.7M
            output_ptr += compptr->_DCT_scaled_size;
153
98.7M
          }
154
94.8M
        }
155
67.3M
      }
156
69.0M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
14.2M
    coef->MCU_ctr = 0;
159
14.2M
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
12.7M
  cinfo->output_iMCU_row++;
162
12.7M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
12.7M
    start_iMCU_row(cinfo);
164
12.7M
    return JPEG_ROW_COMPLETED;
165
12.7M
  }
166
  /* Completed the scan */
167
15.6k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
15.6k
  return JPEG_SCAN_COMPLETED;
169
12.7M
}
jdcoefct-12.c:decompress_onepass
Line
Count
Source
87
543k
{
88
543k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
543k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
543k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
543k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
543k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
543k
  _JSAMPARRAY output_ptr;
94
543k
  JDIMENSION start_col, output_col;
95
543k
  jpeg_component_info *compptr;
96
543k
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
1.41M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
874k
       yoffset++) {
101
8.59M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
7.72M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
7.72M
      jzero_far((void *)coef->MCU_buffer[0],
105
7.72M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
7.72M
      if (!cinfo->entropy->insufficient_data)
107
4.85M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
7.72M
      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
7.72M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
7.69M
          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
7.08M
        blkn = 0;               /* index of current DCT block within MCU */
126
14.9M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
7.84M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
7.84M
          if (!compptr->component_needed) {
130
71.5k
            blkn += compptr->MCU_blocks;
131
71.5k
            continue;
132
71.5k
          }
133
7.77M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
7.77M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
6.84M
                         compptr->MCU_width : compptr->last_col_width;
136
7.77M
          output_ptr = output_buf[compptr->component_index] +
137
7.77M
                       yoffset * compptr->_DCT_scaled_size;
138
7.77M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
7.77M
                      compptr->MCU_sample_width;
140
16.2M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
8.47M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
8.36M
                yoffset + yindex < compptr->last_row_height) {
143
8.36M
              output_col = start_col;
144
17.1M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
8.76M
                (*inverse_DCT) (cinfo, compptr,
146
8.76M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
8.76M
                                output_ptr, output_col);
148
8.76M
                output_col += compptr->_DCT_scaled_size;
149
8.76M
              }
150
8.36M
            }
151
8.47M
            blkn += compptr->MCU_width;
152
8.47M
            output_ptr += compptr->_DCT_scaled_size;
153
8.47M
          }
154
7.77M
        }
155
7.08M
      }
156
7.72M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
874k
    coef->MCU_ctr = 0;
159
874k
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
543k
  cinfo->output_iMCU_row++;
162
543k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
541k
    start_iMCU_row(cinfo);
164
541k
    return JPEG_ROW_COMPLETED;
165
541k
  }
166
  /* Completed the scan */
167
2.18k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
2.18k
  return JPEG_SCAN_COMPLETED;
169
543k
}
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
129M
{
195
129M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
129M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
129M
  int blkn, ci, xindex, yindex, yoffset;
198
129M
  JDIMENSION start_col;
199
129M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
129M
  JBLOCKROW buffer_ptr;
201
129M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
276M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
147M
    compptr = cinfo->cur_comp_info[ci];
206
147M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
147M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
147M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
147M
       (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
147M
  }
215
216
  /* Loop to process one whole iMCU row */
217
304M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
174M
       yoffset++) {
219
1.31G
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
1.13G
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
1.13G
      blkn = 0;                 /* index of current DCT block within MCU */
223
2.38G
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
1.25G
        compptr = cinfo->cur_comp_info[ci];
225
1.25G
        start_col = MCU_col_num * compptr->MCU_width;
226
2.57G
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
1.32G
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
2.80G
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
1.48G
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
1.48G
          }
231
1.32G
        }
232
1.25G
      }
233
1.13G
      if (!cinfo->entropy->insufficient_data)
234
686M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
1.13G
      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
1.13G
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
174M
    coef->MCU_ctr = 0;
245
174M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
129M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
129M
    start_iMCU_row(cinfo);
249
129M
    return JPEG_ROW_COMPLETED;
250
129M
  }
251
  /* Completed the scan */
252
431k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
431k
  return JPEG_SCAN_COMPLETED;
254
129M
}
jdcoefct-8.c:consume_data
Line
Count
Source
194
118M
{
195
118M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
118M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
118M
  int blkn, ci, xindex, yindex, yoffset;
198
118M
  JDIMENSION start_col;
199
118M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
118M
  JBLOCKROW buffer_ptr;
201
118M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
252M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
134M
    compptr = cinfo->cur_comp_info[ci];
206
134M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
134M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
134M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
134M
       (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
134M
  }
215
216
  /* Loop to process one whole iMCU row */
217
280M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
161M
       yoffset++) {
219
1.19G
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
1.03G
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
1.03G
      blkn = 0;                 /* index of current DCT block within MCU */
223
2.16G
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
1.13G
        compptr = cinfo->cur_comp_info[ci];
225
1.13G
        start_col = MCU_col_num * compptr->MCU_width;
226
2.34G
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
1.20G
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
2.56G
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
1.35G
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
1.35G
          }
231
1.20G
        }
232
1.13G
      }
233
1.03G
      if (!cinfo->entropy->insufficient_data)
234
608M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
1.03G
      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
1.03G
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
161M
    coef->MCU_ctr = 0;
245
161M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
118M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
118M
    start_iMCU_row(cinfo);
249
118M
    return JPEG_ROW_COMPLETED;
250
118M
  }
251
  /* Completed the scan */
252
402k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
402k
  return JPEG_SCAN_COMPLETED;
254
118M
}
jdcoefct-12.c:consume_data
Line
Count
Source
194
10.9M
{
195
10.9M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
10.9M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
10.9M
  int blkn, ci, xindex, yindex, yoffset;
198
10.9M
  JDIMENSION start_col;
199
10.9M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
10.9M
  JBLOCKROW buffer_ptr;
201
10.9M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
24.0M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
13.0M
    compptr = cinfo->cur_comp_info[ci];
206
13.0M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
13.0M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
13.0M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
13.0M
       (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
13.0M
  }
215
216
  /* Loop to process one whole iMCU row */
217
24.3M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
13.3M
       yoffset++) {
219
119M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
105M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
105M
      blkn = 0;                 /* index of current DCT block within MCU */
223
218M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
112M
        compptr = cinfo->cur_comp_info[ci];
225
112M
        start_col = MCU_col_num * compptr->MCU_width;
226
232M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
119M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
245M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
125M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
125M
          }
231
119M
        }
232
112M
      }
233
105M
      if (!cinfo->entropy->insufficient_data)
234
78.7M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
105M
      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
105M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
13.3M
    coef->MCU_ctr = 0;
245
13.3M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
10.9M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
10.9M
    start_iMCU_row(cinfo);
249
10.9M
    return JPEG_ROW_COMPLETED;
250
10.9M
  }
251
  /* Completed the scan */
252
28.6k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
28.6k
  return JPEG_SCAN_COMPLETED;
254
10.9M
}
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
10.4M
{
268
10.4M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
10.4M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
10.4M
  JDIMENSION block_num;
271
10.4M
  int ci, block_row, block_rows;
272
10.4M
  JBLOCKARRAY buffer;
273
10.4M
  JBLOCKROW buffer_ptr;
274
10.4M
  _JSAMPARRAY output_ptr;
275
10.4M
  JDIMENSION output_col;
276
10.4M
  jpeg_component_info *compptr;
277
10.4M
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
15.7M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
15.7M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
15.7M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
283
5.26M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
284
0
      return JPEG_SUSPENDED;
285
5.26M
  }
286
287
  /* OK, output from the virtual arrays. */
288
34.5M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
24.0M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
24.0M
    if (!compptr->component_needed)
292
1.08M
      continue;
293
    /* Align the virtual buffer for this component. */
294
22.9M
    buffer = (*cinfo->mem->access_virt_barray)
295
22.9M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
22.9M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
22.9M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
22.9M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
22.8M
      block_rows = compptr->v_samp_factor;
301
130k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
130k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
130k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
130k
    }
306
22.9M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
22.9M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
57.4M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
34.5M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
34.5M
      output_col = 0;
312
34.5M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
214M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
180M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
180M
                        output_col);
316
180M
        buffer_ptr++;
317
180M
        output_col += compptr->_DCT_scaled_size;
318
180M
      }
319
34.5M
      output_ptr += compptr->_DCT_scaled_size;
320
34.5M
    }
321
22.9M
  }
322
323
10.4M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
10.4M
    return JPEG_ROW_COMPLETED;
325
52.6k
  return JPEG_SCAN_COMPLETED;
326
10.4M
}
jdcoefct-8.c:decompress_data
Line
Count
Source
267
9.28M
{
268
9.28M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
9.28M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
9.28M
  JDIMENSION block_num;
271
9.28M
  int ci, block_row, block_rows;
272
9.28M
  JBLOCKARRAY buffer;
273
9.28M
  JBLOCKROW buffer_ptr;
274
9.28M
  _JSAMPARRAY output_ptr;
275
9.28M
  JDIMENSION output_col;
276
9.28M
  jpeg_component_info *compptr;
277
9.28M
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
14.5M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
14.5M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
14.5M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
283
5.26M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
284
0
      return JPEG_SUSPENDED;
285
5.26M
  }
286
287
  /* OK, output from the virtual arrays. */
288
30.5M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
21.2M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
21.2M
    if (!compptr->component_needed)
292
674k
      continue;
293
    /* Align the virtual buffer for this component. */
294
20.5M
    buffer = (*cinfo->mem->access_virt_barray)
295
20.5M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
20.5M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
20.5M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
20.5M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
20.4M
      block_rows = compptr->v_samp_factor;
301
122k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
122k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
122k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
122k
    }
306
20.5M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
20.5M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
51.6M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
31.0M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
31.0M
      output_col = 0;
312
31.0M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
187M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
156M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
156M
                        output_col);
316
156M
        buffer_ptr++;
317
156M
        output_col += compptr->_DCT_scaled_size;
318
156M
      }
319
31.0M
      output_ptr += compptr->_DCT_scaled_size;
320
31.0M
    }
321
20.5M
  }
322
323
9.28M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
9.24M
    return JPEG_ROW_COMPLETED;
325
48.8k
  return JPEG_SCAN_COMPLETED;
326
9.28M
}
jdcoefct-12.c:decompress_data
Line
Count
Source
267
1.16M
{
268
1.16M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
1.16M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
1.16M
  JDIMENSION block_num;
271
1.16M
  int ci, block_row, block_rows;
272
1.16M
  JBLOCKARRAY buffer;
273
1.16M
  JBLOCKROW buffer_ptr;
274
1.16M
  _JSAMPARRAY output_ptr;
275
1.16M
  JDIMENSION output_col;
276
1.16M
  jpeg_component_info *compptr;
277
1.16M
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
1.16M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
1.16M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
1.16M
          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.97M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
2.81M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
2.81M
    if (!compptr->component_needed)
292
412k
      continue;
293
    /* Align the virtual buffer for this component. */
294
2.39M
    buffer = (*cinfo->mem->access_virt_barray)
295
2.39M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
2.39M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
2.39M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
2.39M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
2.39M
      block_rows = compptr->v_samp_factor;
301
7.77k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
7.77k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
7.77k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
7.77k
    }
306
2.39M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
2.39M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
5.81M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
3.41M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
3.41M
      output_col = 0;
312
3.41M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
27.5M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
24.1M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
24.1M
                        output_col);
316
24.1M
        buffer_ptr++;
317
24.1M
        output_col += compptr->_DCT_scaled_size;
318
24.1M
      }
319
3.41M
      output_ptr += compptr->_DCT_scaled_size;
320
3.41M
    }
321
2.39M
  }
322
323
1.16M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
1.16M
    return JPEG_ROW_COMPLETED;
325
3.79k
  return JPEG_SCAN_COMPLETED;
326
1.16M
}
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
16.0M
#define Q01_POS  1
342
16.0M
#define Q10_POS  8
343
16.0M
#define Q20_POS  16
344
16.0M
#define Q11_POS  9
345
16.0M
#define Q02_POS  2
346
8.50M
#define Q03_POS  3
347
8.49M
#define Q12_POS  10
348
8.49M
#define Q21_POS  17
349
8.49M
#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
81.9k
{
362
81.9k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
81.9k
  boolean smoothing_useful = FALSE;
364
81.9k
  int ci, coefi;
365
81.9k
  jpeg_component_info *compptr;
366
81.9k
  JQUANT_TBL *qtable;
367
81.9k
  int *coef_bits, *prev_coef_bits;
368
81.9k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
81.9k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
24.2k
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
57.6k
  if (coef->coef_bits_latch == NULL)
375
30.2k
    coef->coef_bits_latch = (int *)
376
30.2k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
30.2k
                                  cinfo->num_components * 2 *
378
30.2k
                                  (SAVED_COEFS * sizeof(int)));
379
57.6k
  coef_bits_latch = coef->coef_bits_latch;
380
57.6k
  prev_coef_bits_latch =
381
57.6k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
111k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
84.1k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
84.1k
    if ((qtable = compptr->quant_table) == NULL)
387
10.2k
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
73.9k
    if (qtable->quantval[0] == 0 ||
390
72.5k
        qtable->quantval[Q01_POS] == 0 ||
391
70.8k
        qtable->quantval[Q10_POS] == 0 ||
392
68.8k
        qtable->quantval[Q20_POS] == 0 ||
393
67.0k
        qtable->quantval[Q11_POS] == 0 ||
394
65.5k
        qtable->quantval[Q02_POS] == 0 ||
395
64.4k
        qtable->quantval[Q03_POS] == 0 ||
396
63.1k
        qtable->quantval[Q12_POS] == 0 ||
397
59.3k
        qtable->quantval[Q21_POS] == 0 ||
398
57.5k
        qtable->quantval[Q30_POS] == 0)
399
17.5k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
56.3k
    coef_bits = cinfo->coef_bits[ci];
402
56.3k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
56.3k
    if (coef_bits[0] < 0)
404
2.48k
      return FALSE;
405
53.8k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
538k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
484k
      if (cinfo->input_scan_number > 1)
409
420k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
63.9k
      else
411
63.9k
        prev_coef_bits_latch[coefi] = -1;
412
484k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
484k
      if (coef_bits[coefi] != 0)
414
469k
        smoothing_useful = TRUE;
415
484k
    }
416
53.8k
    coef_bits_latch += SAVED_COEFS;
417
53.8k
    prev_coef_bits_latch += SAVED_COEFS;
418
53.8k
  }
419
420
27.3k
  return smoothing_useful;
421
57.6k
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
361
72.7k
{
362
72.7k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
72.7k
  boolean smoothing_useful = FALSE;
364
72.7k
  int ci, coefi;
365
72.7k
  jpeg_component_info *compptr;
366
72.7k
  JQUANT_TBL *qtable;
367
72.7k
  int *coef_bits, *prev_coef_bits;
368
72.7k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
72.7k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
22.0k
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
50.7k
  if (coef->coef_bits_latch == NULL)
375
23.3k
    coef->coef_bits_latch = (int *)
376
23.3k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
23.3k
                                  cinfo->num_components * 2 *
378
23.3k
                                  (SAVED_COEFS * sizeof(int)));
379
50.7k
  coef_bits_latch = coef->coef_bits_latch;
380
50.7k
  prev_coef_bits_latch =
381
50.7k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
99.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
75.9k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
75.9k
    if ((qtable = compptr->quant_table) == NULL)
387
9.62k
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
66.2k
    if (qtable->quantval[0] == 0 ||
390
65.1k
        qtable->quantval[Q01_POS] == 0 ||
391
63.7k
        qtable->quantval[Q10_POS] == 0 ||
392
61.9k
        qtable->quantval[Q20_POS] == 0 ||
393
60.3k
        qtable->quantval[Q11_POS] == 0 ||
394
59.0k
        qtable->quantval[Q02_POS] == 0 ||
395
58.1k
        qtable->quantval[Q03_POS] == 0 ||
396
57.0k
        qtable->quantval[Q12_POS] == 0 ||
397
53.3k
        qtable->quantval[Q21_POS] == 0 ||
398
51.7k
        qtable->quantval[Q30_POS] == 0)
399
15.6k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
50.6k
    coef_bits = cinfo->coef_bits[ci];
402
50.6k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
50.6k
    if (coef_bits[0] < 0)
404
2.10k
      return FALSE;
405
48.5k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
485k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
436k
      if (cinfo->input_scan_number > 1)
409
392k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
43.9k
      else
411
43.9k
        prev_coef_bits_latch[coefi] = -1;
412
436k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
436k
      if (coef_bits[coefi] != 0)
414
423k
        smoothing_useful = TRUE;
415
436k
    }
416
48.5k
    coef_bits_latch += SAVED_COEFS;
417
48.5k
    prev_coef_bits_latch += SAVED_COEFS;
418
48.5k
  }
419
420
23.3k
  return smoothing_useful;
421
50.7k
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
361
9.15k
{
362
9.15k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
9.15k
  boolean smoothing_useful = FALSE;
364
9.15k
  int ci, coefi;
365
9.15k
  jpeg_component_info *compptr;
366
9.15k
  JQUANT_TBL *qtable;
367
9.15k
  int *coef_bits, *prev_coef_bits;
368
9.15k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
9.15k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
2.20k
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
6.94k
  if (coef->coef_bits_latch == NULL)
375
6.94k
    coef->coef_bits_latch = (int *)
376
6.94k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
6.94k
                                  cinfo->num_components * 2 *
378
6.94k
                                  (SAVED_COEFS * sizeof(int)));
379
6.94k
  coef_bits_latch = coef->coef_bits_latch;
380
6.94k
  prev_coef_bits_latch =
381
6.94k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
12.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
8.28k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
8.28k
    if ((qtable = compptr->quant_table) == NULL)
387
673
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
7.61k
    if (qtable->quantval[0] == 0 ||
390
7.33k
        qtable->quantval[Q01_POS] == 0 ||
391
7.08k
        qtable->quantval[Q10_POS] == 0 ||
392
6.84k
        qtable->quantval[Q20_POS] == 0 ||
393
6.70k
        qtable->quantval[Q11_POS] == 0 ||
394
6.49k
        qtable->quantval[Q02_POS] == 0 ||
395
6.31k
        qtable->quantval[Q03_POS] == 0 ||
396
6.16k
        qtable->quantval[Q12_POS] == 0 ||
397
5.98k
        qtable->quantval[Q21_POS] == 0 ||
398
5.83k
        qtable->quantval[Q30_POS] == 0)
399
1.91k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
5.70k
    coef_bits = cinfo->coef_bits[ci];
402
5.70k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
5.70k
    if (coef_bits[0] < 0)
404
383
      return FALSE;
405
5.31k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
53.1k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
47.8k
      if (cinfo->input_scan_number > 1)
409
27.9k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
19.9k
      else
411
19.9k
        prev_coef_bits_latch[coefi] = -1;
412
47.8k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
47.8k
      if (coef_bits[coefi] != 0)
414
45.8k
        smoothing_useful = TRUE;
415
47.8k
    }
416
5.31k
    coef_bits_latch += SAVED_COEFS;
417
5.31k
    prev_coef_bits_latch += SAVED_COEFS;
418
5.31k
  }
419
420
3.97k
  return smoothing_useful;
421
6.94k
}
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
8.12M
{
431
8.12M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
8.12M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
8.12M
  JDIMENSION block_num, last_block_column;
434
8.12M
  int ci, block_row, block_rows, access_rows, image_block_row,
435
8.12M
    image_block_rows;
436
8.12M
  JBLOCKARRAY buffer;
437
8.12M
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
8.12M
  JBLOCKROW next_block_row, next_next_block_row;
439
8.12M
  _JSAMPARRAY output_ptr;
440
8.12M
  JDIMENSION output_col;
441
8.12M
  jpeg_component_info *compptr;
442
8.12M
  _inverse_DCT_method_ptr inverse_DCT;
443
8.12M
  boolean change_dc;
444
8.12M
  JCOEF *workspace;
445
8.12M
  int *coef_bits;
446
8.12M
  JQUANT_TBL *quanttbl;
447
8.12M
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
8.12M
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
8.12M
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
8.12M
      DC25;
451
8.12M
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
8.12M
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
11.9M
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
11.9M
         !cinfo->inputctl->eoi_reached) {
459
7.60M
    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
7.60M
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
466
7.60M
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
467
3.79M
        break;
468
7.60M
    }
469
3.81M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
470
20.3k
      return JPEG_SUSPENDED;
471
3.81M
  }
472
473
  /* OK, output from the virtual arrays. */
474
24.6M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
16.5M
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
16.5M
    if (!compptr->component_needed)
478
552k
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
15.9M
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
15.9M
      block_rows = compptr->v_samp_factor;
482
15.9M
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
15.9M
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
37.8k
      block_rows = compptr->v_samp_factor;
485
37.8k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
41.2k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
41.2k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
41.2k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
41.2k
      access_rows = block_rows; /* this iMCU row only */
491
41.2k
    }
492
    /* Align the virtual buffer for this component. */
493
15.9M
    if (cinfo->output_iMCU_row > 1) {
494
15.9M
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
15.9M
      buffer = (*cinfo->mem->access_virt_barray)
496
15.9M
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
15.9M
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
15.9M
         (JDIMENSION)access_rows, FALSE);
499
15.9M
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
15.9M
    } else if (cinfo->output_iMCU_row > 0) {
501
40.9k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
40.9k
      buffer = (*cinfo->mem->access_virt_barray)
503
40.9k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
40.9k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
40.9k
         (JDIMENSION)access_rows, FALSE);
506
40.9k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
40.9k
    } else {
508
40.3k
      buffer = (*cinfo->mem->access_virt_barray)
509
40.3k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
40.3k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
40.3k
    }
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
15.9M
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
11.3M
      coef_bits =
518
11.3M
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
4.61M
    else
520
4.61M
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
15.9M
    change_dc =
524
15.9M
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
10.0M
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
8.79M
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
15.9M
    quanttbl = compptr->quant_table;
529
15.9M
    Q00 = quanttbl->quantval[0];
530
15.9M
    Q01 = quanttbl->quantval[Q01_POS];
531
15.9M
    Q10 = quanttbl->quantval[Q10_POS];
532
15.9M
    Q20 = quanttbl->quantval[Q20_POS];
533
15.9M
    Q11 = quanttbl->quantval[Q11_POS];
534
15.9M
    Q02 = quanttbl->quantval[Q02_POS];
535
15.9M
    if (change_dc) {
536
8.43M
      Q03 = quanttbl->quantval[Q03_POS];
537
8.43M
      Q12 = quanttbl->quantval[Q12_POS];
538
8.43M
      Q21 = quanttbl->quantval[Q21_POS];
539
8.43M
      Q30 = quanttbl->quantval[Q30_POS];
540
8.43M
    }
541
15.9M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
15.9M
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
15.9M
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
36.2M
    for (block_row = 0; block_row < block_rows; block_row++) {
546
20.2M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
20.2M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
20.2M
      if (image_block_row > 0)
550
20.2M
        prev_block_row =
551
20.2M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
40.3k
      else
553
40.3k
        prev_block_row = buffer_ptr;
554
555
20.2M
      if (image_block_row > 1)
556
20.1M
        prev_prev_block_row =
557
20.1M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
84.5k
      else
559
84.5k
        prev_prev_block_row = prev_block_row;
560
561
20.2M
      if (image_block_row < image_block_rows - 1)
562
20.2M
        next_block_row =
563
20.2M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
41.2k
      else
565
41.2k
        next_block_row = buffer_ptr;
566
567
20.2M
      if (image_block_row < image_block_rows - 2)
568
20.1M
        next_next_block_row =
569
20.1M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
72.1k
      else
571
72.1k
        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
20.2M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
20.2M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
20.2M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
20.2M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
20.2M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
20.2M
      output_col = 0;
582
20.2M
      last_block_column = compptr->width_in_blocks - 1;
583
20.2M
      for (block_num = cinfo->master->first_MCU_col[ci];
584
145M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
125M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
125M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
20.2M
            block_num < last_block_column) {
590
12.4M
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
12.4M
          DC09 = DC10 = (int)prev_block_row[1][0];
592
12.4M
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
12.4M
          DC19 = DC20 = (int)next_block_row[1][0];
594
12.4M
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
12.4M
        }
596
125M
        if (block_num + 1 < last_block_column) {
597
92.8M
          DC05 = (int)prev_prev_block_row[2][0];
598
92.8M
          DC10 = (int)prev_block_row[2][0];
599
92.8M
          DC15 = (int)buffer_ptr[2][0];
600
92.8M
          DC20 = (int)next_block_row[2][0];
601
92.8M
          DC25 = (int)next_next_block_row[2][0];
602
92.8M
        }
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
125M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
111M
          num = Q00 * (change_dc ?
616
72.7M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
72.7M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
72.7M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
72.7M
                 DC21 - DC22 + DC24 + DC25) :
620
111M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
111M
          if (num >= 0) {
622
83.2M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
83.2M
            if (Al > 0 && pred >= (1 << Al))
624
7.00M
              pred = (1 << Al) - 1;
625
83.2M
          } else {
626
28.0M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
28.0M
            if (Al > 0 && pred >= (1 << Al))
628
6.05M
              pred = (1 << Al) - 1;
629
28.0M
            pred = -pred;
630
28.0M
          }
631
111M
          workspace[1] = (JCOEF)pred;
632
111M
        }
633
        /* AC10 */
634
125M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
112M
          num = Q00 * (change_dc ?
636
72.7M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
72.7M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
72.7M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
72.7M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
112M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
112M
          if (num >= 0) {
642
74.8M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
74.8M
            if (Al > 0 && pred >= (1 << Al))
644
11.1M
              pred = (1 << Al) - 1;
645
74.8M
          } else {
646
37.5M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
37.5M
            if (Al > 0 && pred >= (1 << Al))
648
9.94M
              pred = (1 << Al) - 1;
649
37.5M
            pred = -pred;
650
37.5M
          }
651
112M
          workspace[8] = (JCOEF)pred;
652
112M
        }
653
        /* AC20 */
654
125M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
113M
          num = Q00 * (change_dc ?
656
72.7M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
72.7M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
113M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
113M
          if (num >= 0) {
660
71.6M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
71.6M
            if (Al > 0 && pred >= (1 << Al))
662
9.83M
              pred = (1 << Al) - 1;
663
71.6M
          } else {
664
41.8M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
41.8M
            if (Al > 0 && pred >= (1 << Al))
666
9.96M
              pred = (1 << Al) - 1;
667
41.8M
            pred = -pred;
668
41.8M
          }
669
113M
          workspace[16] = (JCOEF)pred;
670
113M
        }
671
        /* AC11 */
672
125M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
113M
          num = Q00 * (change_dc ?
674
72.7M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
72.7M
                 9 * DC19 + DC21 - DC25) :
676
113M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
41.0M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
113M
          if (num >= 0) {
679
85.4M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
85.4M
            if (Al > 0 && pred >= (1 << Al))
681
4.14M
              pred = (1 << Al) - 1;
682
85.4M
          } else {
683
28.3M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
28.3M
            if (Al > 0 && pred >= (1 << Al))
685
4.10M
              pred = (1 << Al) - 1;
686
28.3M
            pred = -pred;
687
28.3M
          }
688
113M
          workspace[9] = (JCOEF)pred;
689
113M
        }
690
        /* AC02 */
691
125M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
113M
          num = Q00 * (change_dc ?
693
72.7M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
72.7M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
113M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
113M
          if (num >= 0) {
697
73.6M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
73.6M
            if (Al > 0 && pred >= (1 << Al))
699
5.56M
              pred = (1 << Al) - 1;
700
73.6M
          } else {
701
39.9M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
39.9M
            if (Al > 0 && pred >= (1 << Al))
703
5.46M
              pred = (1 << Al) - 1;
704
39.9M
            pred = -pred;
705
39.9M
          }
706
113M
          workspace[2] = (JCOEF)pred;
707
113M
        }
708
125M
        if (change_dc) {
709
          /* AC03 */
710
72.7M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
72.7M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
72.7M
            if (num >= 0) {
713
58.8M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
58.8M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
58.8M
            } else {
717
13.9M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
13.9M
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
13.9M
              pred = -pred;
721
13.9M
            }
722
72.7M
            workspace[3] = (JCOEF)pred;
723
72.7M
          }
724
          /* AC12 */
725
72.7M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
72.7M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
72.7M
            if (num >= 0) {
728
45.3M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
45.3M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
45.3M
            } else {
732
27.4M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
27.4M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
27.4M
              pred = -pred;
736
27.4M
            }
737
72.7M
            workspace[10] = (JCOEF)pred;
738
72.7M
          }
739
          /* AC21 */
740
72.7M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
72.7M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
72.7M
            if (num >= 0) {
743
45.7M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
45.7M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
45.7M
            } else {
747
26.9M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
26.9M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
26.9M
              pred = -pred;
751
26.9M
            }
752
72.7M
            workspace[17] = (JCOEF)pred;
753
72.7M
          }
754
          /* AC30 */
755
72.7M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
72.7M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
72.7M
            if (num >= 0) {
758
54.9M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
54.9M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
54.9M
            } else {
762
17.8M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
17.8M
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
17.8M
              pred = -pred;
766
17.8M
            }
767
72.7M
            workspace[24] = (JCOEF)pred;
768
72.7M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
72.7M
          num = Q00 *
773
72.7M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
72.7M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
72.7M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
72.7M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
72.7M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
72.7M
          if (num >= 0) {
779
43.3M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
43.3M
          } else {
781
29.4M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
29.4M
            pred = -pred;
783
29.4M
          }
784
72.7M
          workspace[0] = (JCOEF)pred;
785
72.7M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
125M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
125M
                        output_col);
790
        /* Advance for next column */
791
125M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
125M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
125M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
125M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
125M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
125M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
125M
          prev_prev_block_row++, next_next_block_row++;
798
125M
        output_col += compptr->_DCT_scaled_size;
799
125M
      }
800
20.2M
      output_ptr += compptr->_DCT_scaled_size;
801
20.2M
    }
802
15.9M
  }
803
804
8.10M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
8.08M
    return JPEG_ROW_COMPLETED;
806
22.4k
  return JPEG_SCAN_COMPLETED;
807
8.10M
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
430
6.91M
{
431
6.91M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
6.91M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
6.91M
  JDIMENSION block_num, last_block_column;
434
6.91M
  int ci, block_row, block_rows, access_rows, image_block_row,
435
6.91M
    image_block_rows;
436
6.91M
  JBLOCKARRAY buffer;
437
6.91M
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
6.91M
  JBLOCKROW next_block_row, next_next_block_row;
439
6.91M
  _JSAMPARRAY output_ptr;
440
6.91M
  JDIMENSION output_col;
441
6.91M
  jpeg_component_info *compptr;
442
6.91M
  _inverse_DCT_method_ptr inverse_DCT;
443
6.91M
  boolean change_dc;
444
6.91M
  JCOEF *workspace;
445
6.91M
  int *coef_bits;
446
6.91M
  JQUANT_TBL *quanttbl;
447
6.91M
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
6.91M
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
6.91M
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
6.91M
      DC25;
451
6.91M
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
6.91M
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
10.7M
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
10.6M
         !cinfo->inputctl->eoi_reached) {
459
7.60M
    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
7.60M
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
466
7.60M
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
467
3.79M
        break;
468
7.60M
    }
469
3.81M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
470
20.3k
      return JPEG_SUSPENDED;
471
3.81M
  }
472
473
  /* OK, output from the virtual arrays. */
474
21.4M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
14.5M
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
14.5M
    if (!compptr->component_needed)
478
343k
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
14.1M
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
14.1M
      block_rows = compptr->v_samp_factor;
482
14.1M
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
14.1M
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
34.3k
      block_rows = compptr->v_samp_factor;
485
34.3k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
37.5k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
37.5k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
37.5k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
37.5k
      access_rows = block_rows; /* this iMCU row only */
491
37.5k
    }
492
    /* Align the virtual buffer for this component. */
493
14.1M
    if (cinfo->output_iMCU_row > 1) {
494
14.1M
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
14.1M
      buffer = (*cinfo->mem->access_virt_barray)
496
14.1M
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
14.1M
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
14.1M
         (JDIMENSION)access_rows, FALSE);
499
14.1M
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
14.1M
    } else if (cinfo->output_iMCU_row > 0) {
501
37.3k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
37.3k
      buffer = (*cinfo->mem->access_virt_barray)
503
37.3k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
37.3k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
37.3k
         (JDIMENSION)access_rows, FALSE);
506
37.3k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
37.3k
    } else {
508
36.5k
      buffer = (*cinfo->mem->access_virt_barray)
509
36.5k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
36.5k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
36.5k
    }
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
14.1M
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
10.2M
      coef_bits =
518
10.2M
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
3.90M
    else
520
3.90M
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
14.1M
    change_dc =
524
14.1M
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
8.84M
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
7.65M
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
14.1M
    quanttbl = compptr->quant_table;
529
14.1M
    Q00 = quanttbl->quantval[0];
530
14.1M
    Q01 = quanttbl->quantval[Q01_POS];
531
14.1M
    Q10 = quanttbl->quantval[Q10_POS];
532
14.1M
    Q20 = quanttbl->quantval[Q20_POS];
533
14.1M
    Q11 = quanttbl->quantval[Q11_POS];
534
14.1M
    Q02 = quanttbl->quantval[Q02_POS];
535
14.1M
    if (change_dc) {
536
7.32M
      Q03 = quanttbl->quantval[Q03_POS];
537
7.32M
      Q12 = quanttbl->quantval[Q12_POS];
538
7.32M
      Q21 = quanttbl->quantval[Q21_POS];
539
7.32M
      Q30 = quanttbl->quantval[Q30_POS];
540
7.32M
    }
541
14.1M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
14.1M
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
14.1M
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
31.8M
    for (block_row = 0; block_row < block_rows; block_row++) {
546
17.6M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
17.6M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
17.6M
      if (image_block_row > 0)
550
17.5M
        prev_block_row =
551
17.5M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
36.5k
      else
553
36.5k
        prev_block_row = buffer_ptr;
554
555
17.6M
      if (image_block_row > 1)
556
17.5M
        prev_prev_block_row =
557
17.5M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
77.2k
      else
559
77.2k
        prev_prev_block_row = prev_block_row;
560
561
17.6M
      if (image_block_row < image_block_rows - 1)
562
17.5M
        next_block_row =
563
17.5M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
37.5k
      else
565
37.5k
        next_block_row = buffer_ptr;
566
567
17.6M
      if (image_block_row < image_block_rows - 2)
568
17.5M
        next_next_block_row =
569
17.5M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
65.5k
      else
571
65.5k
        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
17.6M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
17.6M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
17.6M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
17.6M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
17.6M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
17.6M
      output_col = 0;
582
17.6M
      last_block_column = compptr->width_in_blocks - 1;
583
17.6M
      for (block_num = cinfo->master->first_MCU_col[ci];
584
120M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
103M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
103M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
17.6M
            block_num < last_block_column) {
590
11.2M
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
11.2M
          DC09 = DC10 = (int)prev_block_row[1][0];
592
11.2M
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
11.2M
          DC19 = DC20 = (int)next_block_row[1][0];
594
11.2M
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
11.2M
        }
596
103M
        if (block_num + 1 < last_block_column) {
597
74.4M
          DC05 = (int)prev_prev_block_row[2][0];
598
74.4M
          DC10 = (int)prev_block_row[2][0];
599
74.4M
          DC15 = (int)buffer_ptr[2][0];
600
74.4M
          DC20 = (int)next_block_row[2][0];
601
74.4M
          DC25 = (int)next_next_block_row[2][0];
602
74.4M
        }
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
103M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
90.9M
          num = Q00 * (change_dc ?
616
60.9M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
60.9M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
60.9M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
60.9M
                 DC21 - DC22 + DC24 + DC25) :
620
90.9M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
90.9M
          if (num >= 0) {
622
68.7M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
68.7M
            if (Al > 0 && pred >= (1 << Al))
624
5.39M
              pred = (1 << Al) - 1;
625
68.7M
          } else {
626
22.1M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
22.1M
            if (Al > 0 && pred >= (1 << Al))
628
4.73M
              pred = (1 << Al) - 1;
629
22.1M
            pred = -pred;
630
22.1M
          }
631
90.9M
          workspace[1] = (JCOEF)pred;
632
90.9M
        }
633
        /* AC10 */
634
103M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
91.7M
          num = Q00 * (change_dc ?
636
60.9M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
60.9M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
60.9M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
60.9M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
91.7M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
91.7M
          if (num >= 0) {
642
61.0M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
61.0M
            if (Al > 0 && pred >= (1 << Al))
644
8.11M
              pred = (1 << Al) - 1;
645
61.0M
          } else {
646
30.6M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
30.6M
            if (Al > 0 && pred >= (1 << Al))
648
7.64M
              pred = (1 << Al) - 1;
649
30.6M
            pred = -pred;
650
30.6M
          }
651
91.7M
          workspace[8] = (JCOEF)pred;
652
91.7M
        }
653
        /* AC20 */
654
103M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
92.7M
          num = Q00 * (change_dc ?
656
60.9M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
60.9M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
92.7M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
92.7M
          if (num >= 0) {
660
59.4M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
59.4M
            if (Al > 0 && pred >= (1 << Al))
662
7.38M
              pred = (1 << Al) - 1;
663
59.4M
          } else {
664
33.3M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
33.3M
            if (Al > 0 && pred >= (1 << Al))
666
7.43M
              pred = (1 << Al) - 1;
667
33.3M
            pred = -pred;
668
33.3M
          }
669
92.7M
          workspace[16] = (JCOEF)pred;
670
92.7M
        }
671
        /* AC11 */
672
103M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
92.9M
          num = Q00 * (change_dc ?
674
60.9M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
60.9M
                 9 * DC19 + DC21 - DC25) :
676
92.9M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
31.9M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
92.9M
          if (num >= 0) {
679
70.3M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
70.3M
            if (Al > 0 && pred >= (1 << Al))
681
3.31M
              pred = (1 << Al) - 1;
682
70.3M
          } else {
683
22.6M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
22.6M
            if (Al > 0 && pred >= (1 << Al))
685
3.30M
              pred = (1 << Al) - 1;
686
22.6M
            pred = -pred;
687
22.6M
          }
688
92.9M
          workspace[9] = (JCOEF)pred;
689
92.9M
        }
690
        /* AC02 */
691
103M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
92.6M
          num = Q00 * (change_dc ?
693
60.9M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
60.9M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
92.6M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
92.6M
          if (num >= 0) {
697
60.9M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
60.9M
            if (Al > 0 && pred >= (1 << Al))
699
4.05M
              pred = (1 << Al) - 1;
700
60.9M
          } else {
701
31.6M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
31.6M
            if (Al > 0 && pred >= (1 << Al))
703
3.97M
              pred = (1 << Al) - 1;
704
31.6M
            pred = -pred;
705
31.6M
          }
706
92.6M
          workspace[2] = (JCOEF)pred;
707
92.6M
        }
708
103M
        if (change_dc) {
709
          /* AC03 */
710
60.9M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
60.9M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
60.9M
            if (num >= 0) {
713
49.9M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
49.9M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
49.9M
            } else {
717
11.0M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
11.0M
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
11.0M
              pred = -pred;
721
11.0M
            }
722
60.9M
            workspace[3] = (JCOEF)pred;
723
60.9M
          }
724
          /* AC12 */
725
60.9M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
60.9M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
60.9M
            if (num >= 0) {
728
38.5M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
38.5M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
38.5M
            } else {
732
22.4M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
22.4M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
22.4M
              pred = -pred;
736
22.4M
            }
737
60.9M
            workspace[10] = (JCOEF)pred;
738
60.9M
          }
739
          /* AC21 */
740
60.9M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
60.9M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
60.9M
            if (num >= 0) {
743
39.0M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
39.0M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
39.0M
            } else {
747
21.8M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
21.8M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
21.8M
              pred = -pred;
751
21.8M
            }
752
60.9M
            workspace[17] = (JCOEF)pred;
753
60.9M
          }
754
          /* AC30 */
755
60.9M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
60.9M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
60.9M
            if (num >= 0) {
758
46.6M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
46.6M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
46.6M
            } else {
762
14.3M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
14.3M
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
14.3M
              pred = -pred;
766
14.3M
            }
767
60.9M
            workspace[24] = (JCOEF)pred;
768
60.9M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
60.9M
          num = Q00 *
773
60.9M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
60.9M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
60.9M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
60.9M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
60.9M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
60.9M
          if (num >= 0) {
779
36.5M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
36.5M
          } else {
781
24.3M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
24.3M
            pred = -pred;
783
24.3M
          }
784
60.9M
          workspace[0] = (JCOEF)pred;
785
60.9M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
103M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
103M
                        output_col);
790
        /* Advance for next column */
791
103M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
103M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
103M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
103M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
103M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
103M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
103M
          prev_prev_block_row++, next_next_block_row++;
798
103M
        output_col += compptr->_DCT_scaled_size;
799
103M
      }
800
17.6M
      output_ptr += compptr->_DCT_scaled_size;
801
17.6M
    }
802
14.1M
  }
803
804
6.89M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
6.87M
    return JPEG_ROW_COMPLETED;
806
19.4k
  return JPEG_SCAN_COMPLETED;
807
6.89M
}
jdcoefct-12.c:decompress_smooth_data
Line
Count
Source
430
1.21M
{
431
1.21M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
1.21M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
1.21M
  JDIMENSION block_num, last_block_column;
434
1.21M
  int ci, block_row, block_rows, access_rows, image_block_row,
435
1.21M
    image_block_rows;
436
1.21M
  JBLOCKARRAY buffer;
437
1.21M
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
1.21M
  JBLOCKROW next_block_row, next_next_block_row;
439
1.21M
  _JSAMPARRAY output_ptr;
440
1.21M
  JDIMENSION output_col;
441
1.21M
  jpeg_component_info *compptr;
442
1.21M
  _inverse_DCT_method_ptr inverse_DCT;
443
1.21M
  boolean change_dc;
444
1.21M
  JCOEF *workspace;
445
1.21M
  int *coef_bits;
446
1.21M
  JQUANT_TBL *quanttbl;
447
1.21M
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
1.21M
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
1.21M
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
1.21M
      DC25;
451
1.21M
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
1.21M
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
1.21M
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
1.21M
         !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
3.21M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
2.00M
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
2.00M
    if (!compptr->component_needed)
478
208k
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
1.79M
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
1.78M
      block_rows = compptr->v_samp_factor;
482
1.78M
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
1.78M
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
3.48k
      block_rows = compptr->v_samp_factor;
485
3.48k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
3.77k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
3.77k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
3.77k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
3.77k
      access_rows = block_rows; /* this iMCU row only */
491
3.77k
    }
492
    /* Align the virtual buffer for this component. */
493
1.79M
    if (cinfo->output_iMCU_row > 1) {
494
1.78M
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
1.78M
      buffer = (*cinfo->mem->access_virt_barray)
496
1.78M
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
1.78M
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
1.78M
         (JDIMENSION)access_rows, FALSE);
499
1.78M
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
1.78M
    } else if (cinfo->output_iMCU_row > 0) {
501
3.62k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
3.62k
      buffer = (*cinfo->mem->access_virt_barray)
503
3.62k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
3.62k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
3.62k
         (JDIMENSION)access_rows, FALSE);
506
3.62k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
3.77k
    } else {
508
3.77k
      buffer = (*cinfo->mem->access_virt_barray)
509
3.77k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
3.77k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
3.77k
    }
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.79M
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
1.08M
      coef_bits =
518
1.08M
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
715k
    else
520
715k
      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.79M
    change_dc =
524
1.79M
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
1.19M
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
1.13M
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
1.79M
    quanttbl = compptr->quant_table;
529
1.79M
    Q00 = quanttbl->quantval[0];
530
1.79M
    Q01 = quanttbl->quantval[Q01_POS];
531
1.79M
    Q10 = quanttbl->quantval[Q10_POS];
532
1.79M
    Q20 = quanttbl->quantval[Q20_POS];
533
1.79M
    Q11 = quanttbl->quantval[Q11_POS];
534
1.79M
    Q02 = quanttbl->quantval[Q02_POS];
535
1.79M
    if (change_dc) {
536
1.11M
      Q03 = quanttbl->quantval[Q03_POS];
537
1.11M
      Q12 = quanttbl->quantval[Q12_POS];
538
1.11M
      Q21 = quanttbl->quantval[Q21_POS];
539
1.11M
      Q30 = quanttbl->quantval[Q30_POS];
540
1.11M
    }
541
1.79M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
1.79M
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
1.79M
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
4.43M
    for (block_row = 0; block_row < block_rows; block_row++) {
546
2.63M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
2.63M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
2.63M
      if (image_block_row > 0)
550
2.63M
        prev_block_row =
551
2.63M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
3.77k
      else
553
3.77k
        prev_block_row = buffer_ptr;
554
555
2.63M
      if (image_block_row > 1)
556
2.62M
        prev_prev_block_row =
557
2.62M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
7.35k
      else
559
7.35k
        prev_prev_block_row = prev_block_row;
560
561
2.63M
      if (image_block_row < image_block_rows - 1)
562
2.63M
        next_block_row =
563
2.63M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
3.77k
      else
565
3.77k
        next_block_row = buffer_ptr;
566
567
2.63M
      if (image_block_row < image_block_rows - 2)
568
2.62M
        next_next_block_row =
569
2.62M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
6.56k
      else
571
6.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
2.63M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
2.63M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
2.63M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
2.63M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
2.63M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
2.63M
      output_col = 0;
582
2.63M
      last_block_column = compptr->width_in_blocks - 1;
583
2.63M
      for (block_num = cinfo->master->first_MCU_col[ci];
584
24.8M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
22.2M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
22.2M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
2.63M
            block_num < last_block_column) {
590
1.25M
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
1.25M
          DC09 = DC10 = (int)prev_block_row[1][0];
592
1.25M
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
1.25M
          DC19 = DC20 = (int)next_block_row[1][0];
594
1.25M
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
1.25M
        }
596
22.2M
        if (block_num + 1 < last_block_column) {
597
18.3M
          DC05 = (int)prev_prev_block_row[2][0];
598
18.3M
          DC10 = (int)prev_block_row[2][0];
599
18.3M
          DC15 = (int)buffer_ptr[2][0];
600
18.3M
          DC20 = (int)next_block_row[2][0];
601
18.3M
          DC25 = (int)next_next_block_row[2][0];
602
18.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
22.2M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
20.4M
          num = Q00 * (change_dc ?
616
11.8M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
11.8M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
11.8M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
11.8M
                 DC21 - DC22 + DC24 + DC25) :
620
20.4M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
20.4M
          if (num >= 0) {
622
14.5M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
14.5M
            if (Al > 0 && pred >= (1 << Al))
624
1.60M
              pred = (1 << Al) - 1;
625
14.5M
          } else {
626
5.96M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
5.96M
            if (Al > 0 && pred >= (1 << Al))
628
1.32M
              pred = (1 << Al) - 1;
629
5.96M
            pred = -pred;
630
5.96M
          }
631
20.4M
          workspace[1] = (JCOEF)pred;
632
20.4M
        }
633
        /* AC10 */
634
22.2M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
20.6M
          num = Q00 * (change_dc ?
636
11.8M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
11.8M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
11.8M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
11.8M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
20.6M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
20.6M
          if (num >= 0) {
642
13.7M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
13.7M
            if (Al > 0 && pred >= (1 << Al))
644
3.03M
              pred = (1 << Al) - 1;
645
13.7M
          } else {
646
6.86M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
6.86M
            if (Al > 0 && pred >= (1 << Al))
648
2.29M
              pred = (1 << Al) - 1;
649
6.86M
            pred = -pred;
650
6.86M
          }
651
20.6M
          workspace[8] = (JCOEF)pred;
652
20.6M
        }
653
        /* AC20 */
654
22.2M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
20.7M
          num = Q00 * (change_dc ?
656
11.8M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
11.8M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
20.7M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
20.7M
          if (num >= 0) {
660
12.2M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
12.2M
            if (Al > 0 && pred >= (1 << Al))
662
2.44M
              pred = (1 << Al) - 1;
663
12.2M
          } else {
664
8.45M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
8.45M
            if (Al > 0 && pred >= (1 << Al))
666
2.53M
              pred = (1 << Al) - 1;
667
8.45M
            pred = -pred;
668
8.45M
          }
669
20.7M
          workspace[16] = (JCOEF)pred;
670
20.7M
        }
671
        /* AC11 */
672
22.2M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
20.8M
          num = Q00 * (change_dc ?
674
11.8M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
11.8M
                 9 * DC19 + DC21 - DC25) :
676
20.8M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
9.02M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
20.8M
          if (num >= 0) {
679
15.1M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
15.1M
            if (Al > 0 && pred >= (1 << Al))
681
826k
              pred = (1 << Al) - 1;
682
15.1M
          } else {
683
5.72M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
5.72M
            if (Al > 0 && pred >= (1 << Al))
685
798k
              pred = (1 << Al) - 1;
686
5.72M
            pred = -pred;
687
5.72M
          }
688
20.8M
          workspace[9] = (JCOEF)pred;
689
20.8M
        }
690
        /* AC02 */
691
22.2M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
20.9M
          num = Q00 * (change_dc ?
693
11.8M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
11.8M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
20.9M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
20.9M
          if (num >= 0) {
697
12.6M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
12.6M
            if (Al > 0 && pred >= (1 << Al))
699
1.51M
              pred = (1 << Al) - 1;
700
12.6M
          } else {
701
8.32M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
8.32M
            if (Al > 0 && pred >= (1 << Al))
703
1.49M
              pred = (1 << Al) - 1;
704
8.32M
            pred = -pred;
705
8.32M
          }
706
20.9M
          workspace[2] = (JCOEF)pred;
707
20.9M
        }
708
22.2M
        if (change_dc) {
709
          /* AC03 */
710
11.8M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
11.8M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
11.8M
            if (num >= 0) {
713
8.91M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
8.91M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
8.91M
            } else {
717
2.89M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
2.89M
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
2.89M
              pred = -pred;
721
2.89M
            }
722
11.8M
            workspace[3] = (JCOEF)pred;
723
11.8M
          }
724
          /* AC12 */
725
11.8M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
11.8M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
11.8M
            if (num >= 0) {
728
6.80M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
6.80M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
6.80M
            } else {
732
5.00M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
5.00M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
5.00M
              pred = -pred;
736
5.00M
            }
737
11.8M
            workspace[10] = (JCOEF)pred;
738
11.8M
          }
739
          /* AC21 */
740
11.8M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
11.8M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
11.8M
            if (num >= 0) {
743
6.69M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
6.69M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
6.69M
            } else {
747
5.11M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
5.11M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
5.11M
              pred = -pred;
751
5.11M
            }
752
11.8M
            workspace[17] = (JCOEF)pred;
753
11.8M
          }
754
          /* AC30 */
755
11.8M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
11.8M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
11.8M
            if (num >= 0) {
758
8.33M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
8.33M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
8.33M
            } else {
762
3.47M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
3.47M
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
3.47M
              pred = -pred;
766
3.47M
            }
767
11.8M
            workspace[24] = (JCOEF)pred;
768
11.8M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
11.8M
          num = Q00 *
773
11.8M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
11.8M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
11.8M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
11.8M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
11.8M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
11.8M
          if (num >= 0) {
779
6.71M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
6.71M
          } else {
781
5.09M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
5.09M
            pred = -pred;
783
5.09M
          }
784
11.8M
          workspace[0] = (JCOEF)pred;
785
11.8M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
22.2M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
22.2M
                        output_col);
790
        /* Advance for next column */
791
22.2M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
22.2M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
22.2M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
22.2M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
22.2M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
22.2M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
22.2M
          prev_prev_block_row++, next_next_block_row++;
798
22.2M
        output_col += compptr->_DCT_scaled_size;
799
22.2M
      }
800
2.63M
      output_ptr += compptr->_DCT_scaled_size;
801
2.63M
    }
802
1.79M
  }
803
804
1.21M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
1.20M
    return JPEG_ROW_COMPLETED;
806
3.05k
  return JPEG_SCAN_COMPLETED;
807
1.21M
}
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
124k
{
819
124k
  my_coef_ptr coef;
820
821
124k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
124k
  coef = (my_coef_ptr)
825
124k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
124k
                                sizeof(my_coef_controller));
827
124k
  memset(coef, 0, sizeof(my_coef_controller));
828
124k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
124k
  coef->pub.start_input_pass = start_input_pass;
830
124k
  coef->pub.start_output_pass = start_output_pass;
831
124k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
124k
  coef->coef_bits_latch = NULL;
833
124k
#endif
834
835
  /* Create the coefficient buffer. */
836
124k
  if (need_full_buffer) {
837
95.3k
#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
95.3k
    int ci, access_rows;
842
95.3k
    jpeg_component_info *compptr;
843
844
287k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
191k
         ci++, compptr++) {
846
191k
      access_rows = compptr->v_samp_factor;
847
191k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
191k
      if (cinfo->progressive_mode)
850
113k
        access_rows *= 5;
851
191k
#endif
852
191k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
191k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
191k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
191k
                               (long)compptr->h_samp_factor),
856
191k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
191k
                               (long)compptr->v_samp_factor),
858
191k
         (JDIMENSION)access_rows);
859
191k
    }
860
95.3k
    coef->pub.consume_data = consume_data;
861
95.3k
    coef->pub._decompress_data = decompress_data;
862
95.3k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
95.3k
  } else {
867
    /* We only need a single-MCU buffer. */
868
29.0k
    JBLOCKROW buffer;
869
29.0k
    int i;
870
871
29.0k
    buffer = (JBLOCKROW)
872
29.0k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
29.0k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
319k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
290k
      coef->MCU_buffer[i] = buffer + i;
876
290k
    }
877
29.0k
    coef->pub.consume_data = dummy_consume_data;
878
29.0k
    coef->pub._decompress_data = decompress_onepass;
879
29.0k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
29.0k
  }
881
882
  /* Allocate the workspace buffer */
883
124k
  coef->workspace = (JCOEF *)
884
124k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
124k
                                sizeof(JCOEF) * DCTSIZE2);
886
124k
}
jinit_d_coef_controller
Line
Count
Source
818
100k
{
819
100k
  my_coef_ptr coef;
820
821
100k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
100k
  coef = (my_coef_ptr)
825
100k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
100k
                                sizeof(my_coef_controller));
827
100k
  memset(coef, 0, sizeof(my_coef_controller));
828
100k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
100k
  coef->pub.start_input_pass = start_input_pass;
830
100k
  coef->pub.start_output_pass = start_output_pass;
831
100k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
100k
  coef->coef_bits_latch = NULL;
833
100k
#endif
834
835
  /* Create the coefficient buffer. */
836
100k
  if (need_full_buffer) {
837
75.3k
#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
75.3k
    int ci, access_rows;
842
75.3k
    jpeg_component_info *compptr;
843
844
230k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
154k
         ci++, compptr++) {
846
154k
      access_rows = compptr->v_samp_factor;
847
154k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
154k
      if (cinfo->progressive_mode)
850
93.2k
        access_rows *= 5;
851
154k
#endif
852
154k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
154k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
154k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
154k
                               (long)compptr->h_samp_factor),
856
154k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
154k
                               (long)compptr->v_samp_factor),
858
154k
         (JDIMENSION)access_rows);
859
154k
    }
860
75.3k
    coef->pub.consume_data = consume_data;
861
75.3k
    coef->pub._decompress_data = decompress_data;
862
75.3k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
75.3k
  } else {
867
    /* We only need a single-MCU buffer. */
868
25.4k
    JBLOCKROW buffer;
869
25.4k
    int i;
870
871
25.4k
    buffer = (JBLOCKROW)
872
25.4k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
25.4k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
279k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
254k
      coef->MCU_buffer[i] = buffer + i;
876
254k
    }
877
25.4k
    coef->pub.consume_data = dummy_consume_data;
878
25.4k
    coef->pub._decompress_data = decompress_onepass;
879
25.4k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
25.4k
  }
881
882
  /* Allocate the workspace buffer */
883
100k
  coef->workspace = (JCOEF *)
884
100k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
100k
                                sizeof(JCOEF) * DCTSIZE2);
886
100k
}
j12init_d_coef_controller
Line
Count
Source
818
23.6k
{
819
23.6k
  my_coef_ptr coef;
820
821
23.6k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
23.6k
  coef = (my_coef_ptr)
825
23.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
23.6k
                                sizeof(my_coef_controller));
827
23.6k
  memset(coef, 0, sizeof(my_coef_controller));
828
23.6k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
23.6k
  coef->pub.start_input_pass = start_input_pass;
830
23.6k
  coef->pub.start_output_pass = start_output_pass;
831
23.6k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
23.6k
  coef->coef_bits_latch = NULL;
833
23.6k
#endif
834
835
  /* Create the coefficient buffer. */
836
23.6k
  if (need_full_buffer) {
837
19.9k
#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
19.9k
    int ci, access_rows;
842
19.9k
    jpeg_component_info *compptr;
843
844
56.9k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
36.9k
         ci++, compptr++) {
846
36.9k
      access_rows = compptr->v_samp_factor;
847
36.9k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
36.9k
      if (cinfo->progressive_mode)
850
20.4k
        access_rows *= 5;
851
36.9k
#endif
852
36.9k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
36.9k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
36.9k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
36.9k
                               (long)compptr->h_samp_factor),
856
36.9k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
36.9k
                               (long)compptr->v_samp_factor),
858
36.9k
         (JDIMENSION)access_rows);
859
36.9k
    }
860
19.9k
    coef->pub.consume_data = consume_data;
861
19.9k
    coef->pub._decompress_data = decompress_data;
862
19.9k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
19.9k
  } else {
867
    /* We only need a single-MCU buffer. */
868
3.65k
    JBLOCKROW buffer;
869
3.65k
    int i;
870
871
3.65k
    buffer = (JBLOCKROW)
872
3.65k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
3.65k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
40.1k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
36.5k
      coef->MCU_buffer[i] = buffer + i;
876
36.5k
    }
877
3.65k
    coef->pub.consume_data = dummy_consume_data;
878
3.65k
    coef->pub._decompress_data = decompress_onepass;
879
3.65k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
3.65k
  }
881
882
  /* Allocate the workspace buffer */
883
23.6k
  coef->workspace = (JCOEF *)
884
23.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
23.6k
                                sizeof(JCOEF) * DCTSIZE2);
886
23.6k
}