Coverage Report

Created: 2026-07-16 07:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.3.1.x/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
430k
{
48
430k
  cinfo->input_iMCU_row = 0;
49
430k
  start_iMCU_row(cinfo);
50
430k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
47
380k
{
48
380k
  cinfo->input_iMCU_row = 0;
49
380k
  start_iMCU_row(cinfo);
50
380k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
47
49.9k
{
48
49.9k
  cinfo->input_iMCU_row = 0;
49
49.9k
  start_iMCU_row(cinfo);
50
49.9k
}
51
52
53
/*
54
 * Initialize for an output processing pass.
55
 */
56
57
METHODDEF(void)
58
start_output_pass(j_decompress_ptr cinfo)
59
100k
{
60
100k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
100k
  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
100k
  if (coef->pub.coef_arrays != NULL) {
65
79.1k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
29.7k
      coef->pub._decompress_data = decompress_smooth_data;
67
49.3k
    else
68
49.3k
      coef->pub._decompress_data = decompress_data;
69
79.1k
  }
70
100k
#endif
71
100k
  cinfo->output_iMCU_row = 0;
72
100k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
59
87.0k
{
60
87.0k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
87.0k
  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
87.0k
  if (coef->pub.coef_arrays != NULL) {
65
69.5k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
25.7k
      coef->pub._decompress_data = decompress_smooth_data;
67
43.7k
    else
68
43.7k
      coef->pub._decompress_data = decompress_data;
69
69.5k
  }
70
87.0k
#endif
71
87.0k
  cinfo->output_iMCU_row = 0;
72
87.0k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
59
13.7k
{
60
13.7k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
13.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
13.7k
  if (coef->pub.coef_arrays != NULL) {
65
9.64k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
4.03k
      coef->pub._decompress_data = decompress_smooth_data;
67
5.60k
    else
68
5.60k
      coef->pub._decompress_data = decompress_data;
69
9.64k
  }
70
13.7k
#endif
71
13.7k
  cinfo->output_iMCU_row = 0;
72
13.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
9.42M
{
88
9.42M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
9.42M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
9.42M
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
9.42M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
9.42M
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
9.42M
  _JSAMPARRAY output_ptr;
94
9.42M
  JDIMENSION start_col, output_col;
95
9.42M
  jpeg_component_info *compptr;
96
9.42M
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
20.9M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
11.5M
       yoffset++) {
101
87.4M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
75.8M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
75.8M
      jzero_far((void *)coef->MCU_buffer[0],
105
75.8M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
75.8M
      if (!cinfo->entropy->insufficient_data)
107
27.7M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
75.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
75.8M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
75.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
73.2M
        blkn = 0;               /* index of current DCT block within MCU */
126
169M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
96.6M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
96.6M
          if (!compptr->component_needed) {
130
182k
            blkn += compptr->MCU_blocks;
131
182k
            continue;
132
182k
          }
133
96.4M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
96.4M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
73.0M
                         compptr->MCU_width : compptr->last_col_width;
136
96.4M
          output_ptr = output_buf[compptr->component_index] +
137
96.4M
                       yoffset * compptr->_DCT_scaled_size;
138
96.4M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
96.4M
                      compptr->MCU_sample_width;
140
201M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
105M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
102M
                yoffset + yindex < compptr->last_row_height) {
143
102M
              output_col = start_col;
144
213M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
111M
                (*inverse_DCT) (cinfo, compptr,
146
111M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
111M
                                output_ptr, output_col);
148
111M
                output_col += compptr->_DCT_scaled_size;
149
111M
              }
150
102M
            }
151
105M
            blkn += compptr->MCU_width;
152
105M
            output_ptr += compptr->_DCT_scaled_size;
153
105M
          }
154
96.4M
        }
155
73.2M
      }
156
75.8M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
11.5M
    coef->MCU_ctr = 0;
159
11.5M
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
9.42M
  cinfo->output_iMCU_row++;
162
9.42M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
9.40M
    start_iMCU_row(cinfo);
164
9.40M
    return JPEG_ROW_COMPLETED;
165
9.40M
  }
166
  /* Completed the scan */
167
18.5k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
18.5k
  return JPEG_SCAN_COMPLETED;
169
9.42M
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
87
8.72M
{
88
8.72M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
8.72M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
8.72M
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
8.72M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
8.72M
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
8.72M
  _JSAMPARRAY output_ptr;
94
8.72M
  JDIMENSION start_col, output_col;
95
8.72M
  jpeg_component_info *compptr;
96
8.72M
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
19.2M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
10.5M
       yoffset++) {
101
70.6M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
60.1M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
60.1M
      jzero_far((void *)coef->MCU_buffer[0],
105
60.1M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
60.1M
      if (!cinfo->entropy->insufficient_data)
107
20.1M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
60.1M
      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
60.1M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
60.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
58.7M
        blkn = 0;               /* index of current DCT block within MCU */
126
139M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
80.8M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
80.8M
          if (!compptr->component_needed) {
130
119k
            blkn += compptr->MCU_blocks;
131
119k
            continue;
132
119k
          }
133
80.7M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
80.7M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
58.6M
                         compptr->MCU_width : compptr->last_col_width;
136
80.7M
          output_ptr = output_buf[compptr->component_index] +
137
80.7M
                       yoffset * compptr->_DCT_scaled_size;
138
80.7M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
80.7M
                      compptr->MCU_sample_width;
140
169M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
88.7M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
86.6M
                yoffset + yindex < compptr->last_row_height) {
143
86.6M
              output_col = start_col;
144
180M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
94.1M
                (*inverse_DCT) (cinfo, compptr,
146
94.1M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
94.1M
                                output_ptr, output_col);
148
94.1M
                output_col += compptr->_DCT_scaled_size;
149
94.1M
              }
150
86.6M
            }
151
88.7M
            blkn += compptr->MCU_width;
152
88.7M
            output_ptr += compptr->_DCT_scaled_size;
153
88.7M
          }
154
80.7M
        }
155
58.7M
      }
156
60.1M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
10.5M
    coef->MCU_ctr = 0;
159
10.5M
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
8.72M
  cinfo->output_iMCU_row++;
162
8.72M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
8.70M
    start_iMCU_row(cinfo);
164
8.70M
    return JPEG_ROW_COMPLETED;
165
8.70M
  }
166
  /* Completed the scan */
167
15.4k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
15.4k
  return JPEG_SCAN_COMPLETED;
169
8.72M
}
jdcoefct-12.c:decompress_onepass
Line
Count
Source
87
699k
{
88
699k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
699k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
699k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
699k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
699k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
699k
  _JSAMPARRAY output_ptr;
94
699k
  JDIMENSION start_col, output_col;
95
699k
  jpeg_component_info *compptr;
96
699k
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
1.75M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
1.05M
       yoffset++) {
101
16.7M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
15.6M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
15.6M
      jzero_far((void *)coef->MCU_buffer[0],
105
15.6M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
15.6M
      if (!cinfo->entropy->insufficient_data)
107
7.63M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
15.6M
      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
15.6M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
15.6M
          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
14.5M
        blkn = 0;               /* index of current DCT block within MCU */
126
30.2M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
15.7M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
15.7M
          if (!compptr->component_needed) {
130
62.1k
            blkn += compptr->MCU_blocks;
131
62.1k
            continue;
132
62.1k
          }
133
15.7M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
15.7M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
14.4M
                         compptr->MCU_width : compptr->last_col_width;
136
15.7M
          output_ptr = output_buf[compptr->component_index] +
137
15.7M
                       yoffset * compptr->_DCT_scaled_size;
138
15.7M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
15.7M
                      compptr->MCU_sample_width;
140
32.1M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
16.4M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
16.1M
                yoffset + yindex < compptr->last_row_height) {
143
16.1M
              output_col = start_col;
144
33.0M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
16.9M
                (*inverse_DCT) (cinfo, compptr,
146
16.9M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
16.9M
                                output_ptr, output_col);
148
16.9M
                output_col += compptr->_DCT_scaled_size;
149
16.9M
              }
150
16.1M
            }
151
16.4M
            blkn += compptr->MCU_width;
152
16.4M
            output_ptr += compptr->_DCT_scaled_size;
153
16.4M
          }
154
15.7M
        }
155
14.5M
      }
156
15.6M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
1.05M
    coef->MCU_ctr = 0;
159
1.05M
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
699k
  cinfo->output_iMCU_row++;
162
699k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
696k
    start_iMCU_row(cinfo);
164
696k
    return JPEG_ROW_COMPLETED;
165
696k
  }
166
  /* Completed the scan */
167
3.13k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
3.13k
  return JPEG_SCAN_COMPLETED;
169
699k
}
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
100M
{
195
100M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
100M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
100M
  int blkn, ci, xindex, yindex, yoffset;
198
100M
  JDIMENSION start_col;
199
100M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
100M
  JBLOCKROW buffer_ptr;
201
100M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
222M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
122M
    compptr = cinfo->cur_comp_info[ci];
206
122M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
122M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
122M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
122M
       (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
122M
  }
215
216
  /* Loop to process one whole iMCU row */
217
309M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
209M
       yoffset++) {
219
1.16G
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
960M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
960M
      blkn = 0;                 /* index of current DCT block within MCU */
223
2.02G
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
1.06G
        compptr = cinfo->cur_comp_info[ci];
225
1.06G
        start_col = MCU_col_num * compptr->MCU_width;
226
2.19G
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
1.13G
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
2.39G
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
1.26G
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
1.26G
          }
231
1.13G
        }
232
1.06G
      }
233
960M
      if (!cinfo->entropy->insufficient_data)
234
665M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
960M
      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
960M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
209M
    coef->MCU_ctr = 0;
245
209M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
100M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
100M
    start_iMCU_row(cinfo);
249
100M
    return JPEG_ROW_COMPLETED;
250
100M
  }
251
  /* Completed the scan */
252
404k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
404k
  return JPEG_SCAN_COMPLETED;
254
100M
}
jdcoefct-8.c:consume_data
Line
Count
Source
194
90.2M
{
195
90.2M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
90.2M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
90.2M
  int blkn, ci, xindex, yindex, yoffset;
198
90.2M
  JDIMENSION start_col;
199
90.2M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
90.2M
  JBLOCKROW buffer_ptr;
201
90.2M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
197M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
107M
    compptr = cinfo->cur_comp_info[ci];
206
107M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
107M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
107M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
107M
       (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
107M
  }
215
216
  /* Loop to process one whole iMCU row */
217
286M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
196M
       yoffset++) {
219
1.00G
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
812M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
812M
      blkn = 0;                 /* index of current DCT block within MCU */
223
1.71G
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
904M
        compptr = cinfo->cur_comp_info[ci];
225
904M
        start_col = MCU_col_num * compptr->MCU_width;
226
1.86G
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
965M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
2.05G
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
1.09G
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
1.09G
          }
231
965M
        }
232
904M
      }
233
812M
      if (!cinfo->entropy->insufficient_data)
234
542M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
812M
      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
812M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
196M
    coef->MCU_ctr = 0;
245
196M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
90.2M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
89.9M
    start_iMCU_row(cinfo);
249
89.9M
    return JPEG_ROW_COMPLETED;
250
89.9M
  }
251
  /* Completed the scan */
252
358k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
358k
  return JPEG_SCAN_COMPLETED;
254
90.2M
}
jdcoefct-12.c:consume_data
Line
Count
Source
194
10.2M
{
195
10.2M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
10.2M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
10.2M
  int blkn, ci, xindex, yindex, yoffset;
198
10.2M
  JDIMENSION start_col;
199
10.2M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
10.2M
  JBLOCKROW buffer_ptr;
201
10.2M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
25.4M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
15.1M
    compptr = cinfo->cur_comp_info[ci];
206
15.1M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
15.1M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
15.1M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
15.1M
       (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
15.1M
  }
215
216
  /* Loop to process one whole iMCU row */
217
23.0M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
12.7M
       yoffset++) {
219
160M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
147M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
147M
      blkn = 0;                 /* index of current DCT block within MCU */
223
305M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
157M
        compptr = cinfo->cur_comp_info[ci];
225
157M
        start_col = MCU_col_num * compptr->MCU_width;
226
325M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
167M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
342M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
175M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
175M
          }
231
167M
        }
232
157M
      }
233
147M
      if (!cinfo->entropy->insufficient_data)
234
123M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
147M
      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
147M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
12.7M
    coef->MCU_ctr = 0;
245
12.7M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
10.2M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
10.2M
    start_iMCU_row(cinfo);
249
10.2M
    return JPEG_ROW_COMPLETED;
250
10.2M
  }
251
  /* Completed the scan */
252
45.6k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
45.6k
  return JPEG_SCAN_COMPLETED;
254
10.2M
}
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
9.39M
{
268
9.39M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
9.39M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
9.39M
  JDIMENSION block_num;
271
9.39M
  int ci, block_row, block_rows;
272
9.39M
  JBLOCKARRAY buffer;
273
9.39M
  JBLOCKROW buffer_ptr;
274
9.39M
  _JSAMPARRAY output_ptr;
275
9.39M
  JDIMENSION output_col;
276
9.39M
  jpeg_component_info *compptr;
277
9.39M
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
14.4M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
14.4M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
14.4M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
283
5.08M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
284
0
      return JPEG_SUSPENDED;
285
5.08M
  }
286
287
  /* OK, output from the virtual arrays. */
288
32.2M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
22.8M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
22.8M
    if (!compptr->component_needed)
292
1.03M
      continue;
293
    /* Align the virtual buffer for this component. */
294
21.8M
    buffer = (*cinfo->mem->access_virt_barray)
295
21.8M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
21.8M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
21.8M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
21.8M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
21.7M
      block_rows = compptr->v_samp_factor;
301
115k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
115k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
115k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
115k
    }
306
21.8M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
21.8M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
54.6M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
32.7M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
32.7M
      output_col = 0;
312
32.7M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
226M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
194M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
194M
                        output_col);
316
194M
        buffer_ptr++;
317
194M
        output_col += compptr->_DCT_scaled_size;
318
194M
      }
319
32.7M
      output_ptr += compptr->_DCT_scaled_size;
320
32.7M
    }
321
21.8M
  }
322
323
9.39M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
9.34M
    return JPEG_ROW_COMPLETED;
325
46.5k
  return JPEG_SCAN_COMPLETED;
326
9.39M
}
jdcoefct-8.c:decompress_data
Line
Count
Source
267
8.23M
{
268
8.23M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
8.23M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
8.23M
  JDIMENSION block_num;
271
8.23M
  int ci, block_row, block_rows;
272
8.23M
  JBLOCKARRAY buffer;
273
8.23M
  JBLOCKROW buffer_ptr;
274
8.23M
  _JSAMPARRAY output_ptr;
275
8.23M
  JDIMENSION output_col;
276
8.23M
  jpeg_component_info *compptr;
277
8.23M
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
13.3M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
13.3M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
13.3M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
283
5.08M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
284
0
      return JPEG_SUSPENDED;
285
5.08M
  }
286
287
  /* OK, output from the virtual arrays. */
288
27.9M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
19.7M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
19.7M
    if (!compptr->component_needed)
292
468k
      continue;
293
    /* Align the virtual buffer for this component. */
294
19.2M
    buffer = (*cinfo->mem->access_virt_barray)
295
19.2M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
19.2M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
19.2M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
19.2M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
19.1M
      block_rows = compptr->v_samp_factor;
301
107k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
107k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
107k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
107k
    }
306
19.2M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
19.2M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
48.3M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
29.0M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
29.0M
      output_col = 0;
312
29.0M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
198M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
169M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
169M
                        output_col);
316
169M
        buffer_ptr++;
317
169M
        output_col += compptr->_DCT_scaled_size;
318
169M
      }
319
29.0M
      output_ptr += compptr->_DCT_scaled_size;
320
29.0M
    }
321
19.2M
  }
322
323
8.23M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
8.19M
    return JPEG_ROW_COMPLETED;
325
42.4k
  return JPEG_SCAN_COMPLETED;
326
8.23M
}
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
4.26M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
3.10M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
3.10M
    if (!compptr->component_needed)
292
561k
      continue;
293
    /* Align the virtual buffer for this component. */
294
2.53M
    buffer = (*cinfo->mem->access_virt_barray)
295
2.53M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
2.53M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
2.53M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
2.53M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
2.53M
      block_rows = compptr->v_samp_factor;
301
7.86k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
7.86k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
7.86k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
7.86k
    }
306
2.53M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
2.53M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
6.25M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
3.72M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
3.72M
      output_col = 0;
312
3.72M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
27.9M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
24.2M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
24.2M
                        output_col);
316
24.2M
        buffer_ptr++;
317
24.2M
        output_col += compptr->_DCT_scaled_size;
318
24.2M
      }
319
3.72M
      output_ptr += compptr->_DCT_scaled_size;
320
3.72M
    }
321
2.53M
  }
322
323
1.16M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
1.15M
    return JPEG_ROW_COMPLETED;
325
4.04k
  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
10.1M
#define Q01_POS  1
342
10.1M
#define Q10_POS  8
343
10.1M
#define Q20_POS  16
344
10.1M
#define Q11_POS  9
345
10.1M
#define Q02_POS  2
346
7.00M
#define Q03_POS  3
347
7.00M
#define Q12_POS  10
348
6.99M
#define Q21_POS  17
349
6.99M
#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
79.1k
{
362
79.1k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
79.1k
  boolean smoothing_useful = FALSE;
364
79.1k
  int ci, coefi;
365
79.1k
  jpeg_component_info *compptr;
366
79.1k
  JQUANT_TBL *qtable;
367
79.1k
  int *coef_bits, *prev_coef_bits;
368
79.1k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
79.1k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
25.0k
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
54.1k
  if (coef->coef_bits_latch == NULL)
375
30.6k
    coef->coef_bits_latch = (int *)
376
30.6k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
30.6k
                                  cinfo->num_components * 2 *
378
30.6k
                                  (SAVED_COEFS * sizeof(int)));
379
54.1k
  coef_bits_latch = coef->coef_bits_latch;
380
54.1k
  prev_coef_bits_latch =
381
54.1k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
114k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
84.4k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
84.4k
    if ((qtable = compptr->quant_table) == NULL)
387
6.11k
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
78.3k
    if (qtable->quantval[0] == 0 ||
390
76.8k
        qtable->quantval[Q01_POS] == 0 ||
391
75.5k
        qtable->quantval[Q10_POS] == 0 ||
392
74.3k
        qtable->quantval[Q20_POS] == 0 ||
393
72.8k
        qtable->quantval[Q11_POS] == 0 ||
394
70.7k
        qtable->quantval[Q02_POS] == 0 ||
395
68.8k
        qtable->quantval[Q03_POS] == 0 ||
396
67.4k
        qtable->quantval[Q12_POS] == 0 ||
397
65.5k
        qtable->quantval[Q21_POS] == 0 ||
398
64.2k
        qtable->quantval[Q30_POS] == 0)
399
15.1k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
63.2k
    coef_bits = cinfo->coef_bits[ci];
402
63.2k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
63.2k
    if (coef_bits[0] < 0)
404
2.93k
      return FALSE;
405
60.2k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
602k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
542k
      if (cinfo->input_scan_number > 1)
409
464k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
78.0k
      else
411
78.0k
        prev_coef_bits_latch[coefi] = -1;
412
542k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
542k
      if (coef_bits[coefi] != 0)
414
520k
        smoothing_useful = TRUE;
415
542k
    }
416
60.2k
    coef_bits_latch += SAVED_COEFS;
417
60.2k
    prev_coef_bits_latch += SAVED_COEFS;
418
60.2k
  }
419
420
29.9k
  return smoothing_useful;
421
54.1k
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
361
69.5k
{
362
69.5k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
69.5k
  boolean smoothing_useful = FALSE;
364
69.5k
  int ci, coefi;
365
69.5k
  jpeg_component_info *compptr;
366
69.5k
  JQUANT_TBL *qtable;
367
69.5k
  int *coef_bits, *prev_coef_bits;
368
69.5k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
69.5k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
23.1k
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
46.3k
  if (coef->coef_bits_latch == NULL)
375
22.8k
    coef->coef_bits_latch = (int *)
376
22.8k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
22.8k
                                  cinfo->num_components * 2 *
378
22.8k
                                  (SAVED_COEFS * sizeof(int)));
379
46.3k
  coef_bits_latch = coef->coef_bits_latch;
380
46.3k
  prev_coef_bits_latch =
381
46.3k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
101k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
75.5k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
75.5k
    if ((qtable = compptr->quant_table) == NULL)
387
5.17k
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
70.3k
    if (qtable->quantval[0] == 0 ||
390
69.1k
        qtable->quantval[Q01_POS] == 0 ||
391
68.2k
        qtable->quantval[Q10_POS] == 0 ||
392
67.2k
        qtable->quantval[Q20_POS] == 0 ||
393
66.0k
        qtable->quantval[Q11_POS] == 0 ||
394
64.0k
        qtable->quantval[Q02_POS] == 0 ||
395
62.3k
        qtable->quantval[Q03_POS] == 0 ||
396
61.1k
        qtable->quantval[Q12_POS] == 0 ||
397
59.3k
        qtable->quantval[Q21_POS] == 0 ||
398
58.2k
        qtable->quantval[Q30_POS] == 0)
399
12.9k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
57.3k
    coef_bits = cinfo->coef_bits[ci];
402
57.3k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
57.3k
    if (coef_bits[0] < 0)
404
2.32k
      return FALSE;
405
55.0k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
550k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
495k
      if (cinfo->input_scan_number > 1)
409
438k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
56.8k
      else
411
56.8k
        prev_coef_bits_latch[coefi] = -1;
412
495k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
495k
      if (coef_bits[coefi] != 0)
414
476k
        smoothing_useful = TRUE;
415
495k
    }
416
55.0k
    coef_bits_latch += SAVED_COEFS;
417
55.0k
    prev_coef_bits_latch += SAVED_COEFS;
418
55.0k
  }
419
420
25.8k
  return smoothing_useful;
421
46.3k
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
361
9.64k
{
362
9.64k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
9.64k
  boolean smoothing_useful = FALSE;
364
9.64k
  int ci, coefi;
365
9.64k
  jpeg_component_info *compptr;
366
9.64k
  JQUANT_TBL *qtable;
367
9.64k
  int *coef_bits, *prev_coef_bits;
368
9.64k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
9.64k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
1.85k
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
7.79k
  if (coef->coef_bits_latch == NULL)
375
7.79k
    coef->coef_bits_latch = (int *)
376
7.79k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
7.79k
                                  cinfo->num_components * 2 *
378
7.79k
                                  (SAVED_COEFS * sizeof(int)));
379
7.79k
  coef_bits_latch = coef->coef_bits_latch;
380
7.79k
  prev_coef_bits_latch =
381
7.79k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
13.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
8.96k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
8.96k
    if ((qtable = compptr->quant_table) == NULL)
387
939
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
8.02k
    if (qtable->quantval[0] == 0 ||
390
7.70k
        qtable->quantval[Q01_POS] == 0 ||
391
7.34k
        qtable->quantval[Q10_POS] == 0 ||
392
7.06k
        qtable->quantval[Q20_POS] == 0 ||
393
6.85k
        qtable->quantval[Q11_POS] == 0 ||
394
6.69k
        qtable->quantval[Q02_POS] == 0 ||
395
6.51k
        qtable->quantval[Q03_POS] == 0 ||
396
6.33k
        qtable->quantval[Q12_POS] == 0 ||
397
6.16k
        qtable->quantval[Q21_POS] == 0 ||
398
5.96k
        qtable->quantval[Q30_POS] == 0)
399
2.18k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
5.83k
    coef_bits = cinfo->coef_bits[ci];
402
5.83k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
5.83k
    if (coef_bits[0] < 0)
404
610
      return FALSE;
405
5.22k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
52.2k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
47.0k
      if (cinfo->input_scan_number > 1)
409
25.8k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
21.2k
      else
411
21.2k
        prev_coef_bits_latch[coefi] = -1;
412
47.0k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
47.0k
      if (coef_bits[coefi] != 0)
414
44.6k
        smoothing_useful = TRUE;
415
47.0k
    }
416
5.22k
    coef_bits_latch += SAVED_COEFS;
417
5.22k
    prev_coef_bits_latch += SAVED_COEFS;
418
5.22k
  }
419
420
4.05k
  return smoothing_useful;
421
7.79k
}
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
5.91M
{
431
5.91M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
5.91M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
5.91M
  JDIMENSION block_num, last_block_column;
434
5.91M
  int ci, block_row, block_rows, access_rows, image_block_row,
435
5.91M
    image_block_rows;
436
5.91M
  JBLOCKARRAY buffer;
437
5.91M
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
5.91M
  JBLOCKROW next_block_row, next_next_block_row;
439
5.91M
  _JSAMPARRAY output_ptr;
440
5.91M
  JDIMENSION output_col;
441
5.91M
  jpeg_component_info *compptr;
442
5.91M
  _inverse_DCT_method_ptr inverse_DCT;
443
5.91M
  boolean change_dc;
444
5.91M
  JCOEF *workspace;
445
5.91M
  int *coef_bits;
446
5.91M
  JQUANT_TBL *quanttbl;
447
5.91M
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
5.91M
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
5.91M
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
5.91M
      DC25;
451
5.91M
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
5.91M
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
8.74M
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
8.73M
         !cinfo->inputctl->eoi_reached) {
459
5.85M
    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
5.85M
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
466
5.85M
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
467
3.01M
        break;
468
5.85M
    }
469
2.83M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
470
11.3k
      return JPEG_SUSPENDED;
471
2.83M
  }
472
473
  /* OK, output from the virtual arrays. */
474
16.1M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
10.2M
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
10.2M
    if (!compptr->component_needed)
478
167k
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
10.0M
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
10.0M
      block_rows = compptr->v_samp_factor;
482
10.0M
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
10.0M
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
32.8k
      block_rows = compptr->v_samp_factor;
485
32.8k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
50.3k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
50.3k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
50.3k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
50.3k
      access_rows = block_rows; /* this iMCU row only */
491
50.3k
    }
492
    /* Align the virtual buffer for this component. */
493
10.0M
    if (cinfo->output_iMCU_row > 1) {
494
10.0M
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
10.0M
      buffer = (*cinfo->mem->access_virt_barray)
496
10.0M
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
10.0M
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
10.0M
         (JDIMENSION)access_rows, FALSE);
499
10.0M
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
10.0M
    } else if (cinfo->output_iMCU_row > 0) {
501
35.0k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
35.0k
      buffer = (*cinfo->mem->access_virt_barray)
503
35.0k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
35.0k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
35.0k
         (JDIMENSION)access_rows, FALSE);
506
35.0k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
47.3k
    } else {
508
47.3k
      buffer = (*cinfo->mem->access_virt_barray)
509
47.3k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
47.3k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
47.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
10.0M
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
5.54M
      coef_bits =
518
5.54M
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
4.54M
    else
520
4.54M
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
10.0M
    change_dc =
524
10.0M
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
7.62M
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
7.10M
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
10.0M
    quanttbl = compptr->quant_table;
529
10.0M
    Q00 = quanttbl->quantval[0];
530
10.0M
    Q01 = quanttbl->quantval[Q01_POS];
531
10.0M
    Q10 = quanttbl->quantval[Q10_POS];
532
10.0M
    Q20 = quanttbl->quantval[Q20_POS];
533
10.0M
    Q11 = quanttbl->quantval[Q11_POS];
534
10.0M
    Q02 = quanttbl->quantval[Q02_POS];
535
10.0M
    if (change_dc) {
536
6.93M
      Q03 = quanttbl->quantval[Q03_POS];
537
6.93M
      Q12 = quanttbl->quantval[Q12_POS];
538
6.93M
      Q21 = quanttbl->quantval[Q21_POS];
539
6.93M
      Q30 = quanttbl->quantval[Q30_POS];
540
6.93M
    }
541
10.0M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
10.0M
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
10.0M
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
25.1M
    for (block_row = 0; block_row < block_rows; block_row++) {
546
15.0M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
15.0M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
15.0M
      if (image_block_row > 0)
550
15.0M
        prev_block_row =
551
15.0M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
47.3k
      else
553
47.3k
        prev_block_row = buffer_ptr;
554
555
15.0M
      if (image_block_row > 1)
556
14.9M
        prev_prev_block_row =
557
14.9M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
90.3k
      else
559
90.3k
        prev_prev_block_row = prev_block_row;
560
561
15.0M
      if (image_block_row < image_block_rows - 1)
562
15.0M
        next_block_row =
563
15.0M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
50.3k
      else
565
50.3k
        next_block_row = buffer_ptr;
566
567
15.0M
      if (image_block_row < image_block_rows - 2)
568
15.0M
        next_next_block_row =
569
15.0M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
80.3k
      else
571
80.3k
        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
15.0M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
15.0M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
15.0M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
15.0M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
15.0M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
15.0M
      output_col = 0;
582
15.0M
      last_block_column = compptr->width_in_blocks - 1;
583
15.0M
      for (block_num = cinfo->master->first_MCU_col[ci];
584
115M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
99.9M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
99.9M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
15.0M
            block_num < last_block_column) {
590
8.01M
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
8.01M
          DC09 = DC10 = (int)prev_block_row[1][0];
592
8.01M
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
8.01M
          DC19 = DC20 = (int)next_block_row[1][0];
594
8.01M
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
8.01M
        }
596
99.9M
        if (block_num + 1 < last_block_column) {
597
76.9M
          DC05 = (int)prev_prev_block_row[2][0];
598
76.9M
          DC10 = (int)prev_block_row[2][0];
599
76.9M
          DC15 = (int)buffer_ptr[2][0];
600
76.9M
          DC20 = (int)next_block_row[2][0];
601
76.9M
          DC25 = (int)next_next_block_row[2][0];
602
76.9M
        }
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
99.9M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
90.9M
          num = Q00 * (change_dc ?
616
54.4M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
54.4M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
54.4M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
54.4M
                 DC21 - DC22 + DC24 + DC25) :
620
90.9M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
90.9M
          if (num >= 0) {
622
67.7M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
67.7M
            if (Al > 0 && pred >= (1 << Al))
624
6.10M
              pred = (1 << Al) - 1;
625
67.7M
          } else {
626
23.2M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
23.2M
            if (Al > 0 && pred >= (1 << Al))
628
4.96M
              pred = (1 << Al) - 1;
629
23.2M
            pred = -pred;
630
23.2M
          }
631
90.9M
          workspace[1] = (JCOEF)pred;
632
90.9M
        }
633
        /* AC10 */
634
99.9M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
91.7M
          num = Q00 * (change_dc ?
636
54.4M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
54.4M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
54.4M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
54.4M
                 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
64.3M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
64.3M
            if (Al > 0 && pred >= (1 << Al))
644
10.0M
              pred = (1 << Al) - 1;
645
64.3M
          } else {
646
27.3M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
27.3M
            if (Al > 0 && pred >= (1 << Al))
648
8.69M
              pred = (1 << Al) - 1;
649
27.3M
            pred = -pred;
650
27.3M
          }
651
91.7M
          workspace[8] = (JCOEF)pred;
652
91.7M
        }
653
        /* AC20 */
654
99.9M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
91.3M
          num = Q00 * (change_dc ?
656
54.4M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
54.4M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
91.3M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
91.3M
          if (num >= 0) {
660
59.1M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
59.1M
            if (Al > 0 && pred >= (1 << Al))
662
8.77M
              pred = (1 << Al) - 1;
663
59.1M
          } else {
664
32.2M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
32.2M
            if (Al > 0 && pred >= (1 << Al))
666
8.76M
              pred = (1 << Al) - 1;
667
32.2M
            pred = -pred;
668
32.2M
          }
669
91.3M
          workspace[16] = (JCOEF)pred;
670
91.3M
        }
671
        /* AC11 */
672
99.9M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
91.9M
          num = Q00 * (change_dc ?
674
54.4M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
54.4M
                 9 * DC19 + DC21 - DC25) :
676
91.9M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
37.5M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
91.9M
          if (num >= 0) {
679
70.6M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
70.6M
            if (Al > 0 && pred >= (1 << Al))
681
4.24M
              pred = (1 << Al) - 1;
682
70.6M
          } else {
683
21.2M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
21.2M
            if (Al > 0 && pred >= (1 << Al))
685
4.18M
              pred = (1 << Al) - 1;
686
21.2M
            pred = -pred;
687
21.2M
          }
688
91.9M
          workspace[9] = (JCOEF)pred;
689
91.9M
        }
690
        /* AC02 */
691
99.9M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
91.6M
          num = Q00 * (change_dc ?
693
54.4M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
54.4M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
91.6M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
91.6M
          if (num >= 0) {
697
59.5M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
59.5M
            if (Al > 0 && pred >= (1 << Al))
699
5.31M
              pred = (1 << Al) - 1;
700
59.5M
          } else {
701
32.0M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
32.0M
            if (Al > 0 && pred >= (1 << Al))
703
5.34M
              pred = (1 << Al) - 1;
704
32.0M
            pred = -pred;
705
32.0M
          }
706
91.6M
          workspace[2] = (JCOEF)pred;
707
91.6M
        }
708
99.9M
        if (change_dc) {
709
          /* AC03 */
710
54.4M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
54.4M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
54.4M
            if (num >= 0) {
713
43.5M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
43.5M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
43.5M
            } else {
717
10.8M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
10.8M
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
10.8M
              pred = -pred;
721
10.8M
            }
722
54.4M
            workspace[3] = (JCOEF)pred;
723
54.4M
          }
724
          /* AC12 */
725
54.4M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
54.4M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
54.4M
            if (num >= 0) {
728
35.7M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
35.7M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
35.7M
            } else {
732
18.6M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
18.6M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
18.6M
              pred = -pred;
736
18.6M
            }
737
54.4M
            workspace[10] = (JCOEF)pred;
738
54.4M
          }
739
          /* AC21 */
740
54.4M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
54.4M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
54.4M
            if (num >= 0) {
743
34.8M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
34.8M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
34.8M
            } else {
747
19.5M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
19.5M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
19.5M
              pred = -pred;
751
19.5M
            }
752
54.4M
            workspace[17] = (JCOEF)pred;
753
54.4M
          }
754
          /* AC30 */
755
54.4M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
54.4M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
54.4M
            if (num >= 0) {
758
41.5M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
41.5M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
41.5M
            } else {
762
12.8M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
12.8M
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
12.8M
              pred = -pred;
766
12.8M
            }
767
54.4M
            workspace[24] = (JCOEF)pred;
768
54.4M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
54.4M
          num = Q00 *
773
54.4M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
54.4M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
54.4M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
54.4M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
54.4M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
54.4M
          if (num >= 0) {
779
35.5M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
35.5M
          } else {
781
18.8M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
18.8M
            pred = -pred;
783
18.8M
          }
784
54.4M
          workspace[0] = (JCOEF)pred;
785
54.4M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
99.9M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
99.9M
                        output_col);
790
        /* Advance for next column */
791
99.9M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
99.9M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
99.9M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
99.9M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
99.9M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
99.9M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
99.9M
          prev_prev_block_row++, next_next_block_row++;
798
99.9M
        output_col += compptr->_DCT_scaled_size;
799
99.9M
      }
800
15.0M
      output_ptr += compptr->_DCT_scaled_size;
801
15.0M
    }
802
10.0M
  }
803
804
5.90M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
5.88M
    return JPEG_ROW_COMPLETED;
806
25.3k
  return JPEG_SCAN_COMPLETED;
807
5.90M
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
430
5.20M
{
431
5.20M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
5.20M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
5.20M
  JDIMENSION block_num, last_block_column;
434
5.20M
  int ci, block_row, block_rows, access_rows, image_block_row,
435
5.20M
    image_block_rows;
436
5.20M
  JBLOCKARRAY buffer;
437
5.20M
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
5.20M
  JBLOCKROW next_block_row, next_next_block_row;
439
5.20M
  _JSAMPARRAY output_ptr;
440
5.20M
  JDIMENSION output_col;
441
5.20M
  jpeg_component_info *compptr;
442
5.20M
  _inverse_DCT_method_ptr inverse_DCT;
443
5.20M
  boolean change_dc;
444
5.20M
  JCOEF *workspace;
445
5.20M
  int *coef_bits;
446
5.20M
  JQUANT_TBL *quanttbl;
447
5.20M
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
5.20M
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
5.20M
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
5.20M
      DC25;
451
5.20M
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
5.20M
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
8.02M
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
8.01M
         !cinfo->inputctl->eoi_reached) {
459
5.85M
    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
5.85M
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
466
5.85M
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
467
3.01M
        break;
468
5.85M
    }
469
2.83M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
470
11.3k
      return JPEG_SUSPENDED;
471
2.83M
  }
472
473
  /* OK, output from the virtual arrays. */
474
14.4M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
9.27M
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
9.27M
    if (!compptr->component_needed)
478
77.8k
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
9.19M
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
9.11M
      block_rows = compptr->v_samp_factor;
482
9.11M
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
9.11M
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
29.9k
      block_rows = compptr->v_samp_factor;
485
29.9k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
47.2k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
47.2k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
47.2k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
47.2k
      access_rows = block_rows; /* this iMCU row only */
491
47.2k
    }
492
    /* Align the virtual buffer for this component. */
493
9.19M
    if (cinfo->output_iMCU_row > 1) {
494
9.11M
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
9.11M
      buffer = (*cinfo->mem->access_virt_barray)
496
9.11M
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
9.11M
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
9.11M
         (JDIMENSION)access_rows, FALSE);
499
9.11M
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
9.11M
    } else if (cinfo->output_iMCU_row > 0) {
501
31.7k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
31.7k
      buffer = (*cinfo->mem->access_virt_barray)
503
31.7k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
31.7k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
31.7k
         (JDIMENSION)access_rows, FALSE);
506
31.7k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
44.0k
    } else {
508
44.0k
      buffer = (*cinfo->mem->access_virt_barray)
509
44.0k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
44.0k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
44.0k
    }
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
9.19M
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
5.10M
      coef_bits =
518
5.10M
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
4.09M
    else
520
4.09M
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
9.19M
    change_dc =
524
9.19M
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
6.95M
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
6.45M
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
9.19M
    quanttbl = compptr->quant_table;
529
9.19M
    Q00 = quanttbl->quantval[0];
530
9.19M
    Q01 = quanttbl->quantval[Q01_POS];
531
9.19M
    Q10 = quanttbl->quantval[Q10_POS];
532
9.19M
    Q20 = quanttbl->quantval[Q20_POS];
533
9.19M
    Q11 = quanttbl->quantval[Q11_POS];
534
9.19M
    Q02 = quanttbl->quantval[Q02_POS];
535
9.19M
    if (change_dc) {
536
6.31M
      Q03 = quanttbl->quantval[Q03_POS];
537
6.31M
      Q12 = quanttbl->quantval[Q12_POS];
538
6.31M
      Q21 = quanttbl->quantval[Q21_POS];
539
6.31M
      Q30 = quanttbl->quantval[Q30_POS];
540
6.31M
    }
541
9.19M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
9.19M
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
9.19M
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
22.7M
    for (block_row = 0; block_row < block_rows; block_row++) {
546
13.5M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
13.5M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
13.5M
      if (image_block_row > 0)
550
13.5M
        prev_block_row =
551
13.5M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
44.0k
      else
553
44.0k
        prev_block_row = buffer_ptr;
554
555
13.5M
      if (image_block_row > 1)
556
13.5M
        prev_prev_block_row =
557
13.5M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
83.7k
      else
559
83.7k
        prev_prev_block_row = prev_block_row;
560
561
13.5M
      if (image_block_row < image_block_rows - 1)
562
13.5M
        next_block_row =
563
13.5M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
47.2k
      else
565
47.2k
        next_block_row = buffer_ptr;
566
567
13.5M
      if (image_block_row < image_block_rows - 2)
568
13.5M
        next_next_block_row =
569
13.5M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
75.2k
      else
571
75.2k
        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
13.5M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
13.5M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
13.5M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
13.5M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
13.5M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
13.5M
      output_col = 0;
582
13.5M
      last_block_column = compptr->width_in_blocks - 1;
583
13.5M
      for (block_num = cinfo->master->first_MCU_col[ci];
584
97.2M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
83.6M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
83.6M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
13.5M
            block_num < last_block_column) {
590
7.03M
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
7.03M
          DC09 = DC10 = (int)prev_block_row[1][0];
592
7.03M
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
7.03M
          DC19 = DC20 = (int)next_block_row[1][0];
594
7.03M
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
7.03M
        }
596
83.6M
        if (block_num + 1 < last_block_column) {
597
63.0M
          DC05 = (int)prev_prev_block_row[2][0];
598
63.0M
          DC10 = (int)prev_block_row[2][0];
599
63.0M
          DC15 = (int)buffer_ptr[2][0];
600
63.0M
          DC20 = (int)next_block_row[2][0];
601
63.0M
          DC25 = (int)next_next_block_row[2][0];
602
63.0M
        }
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
83.6M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
75.5M
          num = Q00 * (change_dc ?
616
44.8M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
44.8M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
44.8M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
44.8M
                 DC21 - DC22 + DC24 + DC25) :
620
75.5M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
75.5M
          if (num >= 0) {
622
57.1M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
57.1M
            if (Al > 0 && pred >= (1 << Al))
624
4.97M
              pred = (1 << Al) - 1;
625
57.1M
          } else {
626
18.4M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
18.4M
            if (Al > 0 && pred >= (1 << Al))
628
3.84M
              pred = (1 << Al) - 1;
629
18.4M
            pred = -pred;
630
18.4M
          }
631
75.5M
          workspace[1] = (JCOEF)pred;
632
75.5M
        }
633
        /* AC10 */
634
83.6M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
76.2M
          num = Q00 * (change_dc ?
636
44.8M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
44.8M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
44.8M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
44.8M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
76.2M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
76.2M
          if (num >= 0) {
642
54.1M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
54.1M
            if (Al > 0 && pred >= (1 << Al))
644
8.31M
              pred = (1 << Al) - 1;
645
54.1M
          } else {
646
22.0M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
22.0M
            if (Al > 0 && pred >= (1 << Al))
648
7.23M
              pred = (1 << Al) - 1;
649
22.0M
            pred = -pred;
650
22.0M
          }
651
76.2M
          workspace[8] = (JCOEF)pred;
652
76.2M
        }
653
        /* AC20 */
654
83.6M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
76.0M
          num = Q00 * (change_dc ?
656
44.8M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
44.8M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
76.0M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
76.0M
          if (num >= 0) {
660
50.0M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
50.0M
            if (Al > 0 && pred >= (1 << Al))
662
7.01M
              pred = (1 << Al) - 1;
663
50.0M
          } else {
664
25.9M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
25.9M
            if (Al > 0 && pred >= (1 << Al))
666
6.99M
              pred = (1 << Al) - 1;
667
25.9M
            pred = -pred;
668
25.9M
          }
669
76.0M
          workspace[16] = (JCOEF)pred;
670
76.0M
        }
671
        /* AC11 */
672
83.6M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
76.4M
          num = Q00 * (change_dc ?
674
44.8M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
44.8M
                 9 * DC19 + DC21 - DC25) :
676
76.4M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
31.6M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
76.4M
          if (num >= 0) {
679
59.2M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
59.2M
            if (Al > 0 && pred >= (1 << Al))
681
3.48M
              pred = (1 << Al) - 1;
682
59.2M
          } else {
683
17.2M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
17.2M
            if (Al > 0 && pred >= (1 << Al))
685
3.45M
              pred = (1 << Al) - 1;
686
17.2M
            pred = -pred;
687
17.2M
          }
688
76.4M
          workspace[9] = (JCOEF)pred;
689
76.4M
        }
690
        /* AC02 */
691
83.6M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
76.1M
          num = Q00 * (change_dc ?
693
44.8M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
44.8M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
76.1M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
76.1M
          if (num >= 0) {
697
50.3M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
50.3M
            if (Al > 0 && pred >= (1 << Al))
699
4.18M
              pred = (1 << Al) - 1;
700
50.3M
          } else {
701
25.8M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
25.8M
            if (Al > 0 && pred >= (1 << Al))
703
4.21M
              pred = (1 << Al) - 1;
704
25.8M
            pred = -pred;
705
25.8M
          }
706
76.1M
          workspace[2] = (JCOEF)pred;
707
76.1M
        }
708
83.6M
        if (change_dc) {
709
          /* AC03 */
710
44.8M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
44.8M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
44.8M
            if (num >= 0) {
713
36.6M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
36.6M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
36.6M
            } else {
717
8.18M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
8.18M
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
8.18M
              pred = -pred;
721
8.18M
            }
722
44.8M
            workspace[3] = (JCOEF)pred;
723
44.8M
          }
724
          /* AC12 */
725
44.8M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
44.8M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
44.8M
            if (num >= 0) {
728
30.3M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
30.3M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
30.3M
            } else {
732
14.4M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
14.4M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
14.4M
              pred = -pred;
736
14.4M
            }
737
44.8M
            workspace[10] = (JCOEF)pred;
738
44.8M
          }
739
          /* AC21 */
740
44.8M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
44.8M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
44.8M
            if (num >= 0) {
743
29.4M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
29.4M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
29.4M
            } else {
747
15.3M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
15.3M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
15.3M
              pred = -pred;
751
15.3M
            }
752
44.8M
            workspace[17] = (JCOEF)pred;
753
44.8M
          }
754
          /* AC30 */
755
44.8M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
44.8M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
44.8M
            if (num >= 0) {
758
34.8M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
34.8M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
34.8M
            } else {
762
9.94M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
9.94M
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
9.94M
              pred = -pred;
766
9.94M
            }
767
44.8M
            workspace[24] = (JCOEF)pred;
768
44.8M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
44.8M
          num = Q00 *
773
44.8M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
44.8M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
44.8M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
44.8M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
44.8M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
44.8M
          if (num >= 0) {
779
30.0M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
30.0M
          } else {
781
14.7M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
14.7M
            pred = -pred;
783
14.7M
          }
784
44.8M
          workspace[0] = (JCOEF)pred;
785
44.8M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
83.6M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
83.6M
                        output_col);
790
        /* Advance for next column */
791
83.6M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
83.6M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
83.6M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
83.6M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
83.6M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
83.6M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
83.6M
          prev_prev_block_row++, next_next_block_row++;
798
83.6M
        output_col += compptr->_DCT_scaled_size;
799
83.6M
      }
800
13.5M
      output_ptr += compptr->_DCT_scaled_size;
801
13.5M
    }
802
9.19M
  }
803
804
5.18M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
5.16M
    return JPEG_ROW_COMPLETED;
806
22.6k
  return JPEG_SCAN_COMPLETED;
807
5.18M
}
jdcoefct-12.c:decompress_smooth_data
Line
Count
Source
430
716k
{
431
716k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
716k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
716k
  JDIMENSION block_num, last_block_column;
434
716k
  int ci, block_row, block_rows, access_rows, image_block_row,
435
716k
    image_block_rows;
436
716k
  JBLOCKARRAY buffer;
437
716k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
716k
  JBLOCKROW next_block_row, next_next_block_row;
439
716k
  _JSAMPARRAY output_ptr;
440
716k
  JDIMENSION output_col;
441
716k
  jpeg_component_info *compptr;
442
716k
  _inverse_DCT_method_ptr inverse_DCT;
443
716k
  boolean change_dc;
444
716k
  JCOEF *workspace;
445
716k
  int *coef_bits;
446
716k
  JQUANT_TBL *quanttbl;
447
716k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
716k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
716k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
716k
      DC25;
451
716k
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
716k
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
716k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
716k
         !cinfo->inputctl->eoi_reached) {
459
0
    if (cinfo->input_scan_number == cinfo->output_scan_number) {
460
      /* If input is working on current scan, we ordinarily want it to
461
       * have completed the current row.  But if input scan is DC,
462
       * we want it to keep two rows ahead so that next two block rows' DC
463
       * values are up to date.
464
       */
465
0
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
466
0
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
467
0
        break;
468
0
    }
469
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
470
0
      return JPEG_SUSPENDED;
471
0
  }
472
473
  /* OK, output from the virtual arrays. */
474
1.70M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
984k
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
984k
    if (!compptr->component_needed)
478
89.9k
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
894k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
888k
      block_rows = compptr->v_samp_factor;
482
888k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
888k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
2.83k
      block_rows = compptr->v_samp_factor;
485
2.83k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
3.07k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
3.07k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
3.07k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
3.07k
      access_rows = block_rows; /* this iMCU row only */
491
3.07k
    }
492
    /* Align the virtual buffer for this component. */
493
894k
    if (cinfo->output_iMCU_row > 1) {
494
887k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
887k
      buffer = (*cinfo->mem->access_virt_barray)
496
887k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
887k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
887k
         (JDIMENSION)access_rows, FALSE);
499
887k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
887k
    } else if (cinfo->output_iMCU_row > 0) {
501
3.33k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
3.33k
      buffer = (*cinfo->mem->access_virt_barray)
503
3.33k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
3.33k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
3.33k
         (JDIMENSION)access_rows, FALSE);
506
3.33k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
3.33k
    } else {
508
3.31k
      buffer = (*cinfo->mem->access_virt_barray)
509
3.31k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
3.31k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
3.31k
    }
512
    /* Fetch component-dependent info.
513
     * If the current scan is incomplete, then we use the component-dependent
514
     * info from the previous scan.
515
     */
516
894k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
443k
      coef_bits =
518
443k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
451k
    else
520
451k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
894k
    change_dc =
524
894k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
669k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
646k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
894k
    quanttbl = compptr->quant_table;
529
894k
    Q00 = quanttbl->quantval[0];
530
894k
    Q01 = quanttbl->quantval[Q01_POS];
531
894k
    Q10 = quanttbl->quantval[Q10_POS];
532
894k
    Q20 = quanttbl->quantval[Q20_POS];
533
894k
    Q11 = quanttbl->quantval[Q11_POS];
534
894k
    Q02 = quanttbl->quantval[Q02_POS];
535
894k
    if (change_dc) {
536
622k
      Q03 = quanttbl->quantval[Q03_POS];
537
622k
      Q12 = quanttbl->quantval[Q12_POS];
538
622k
      Q21 = quanttbl->quantval[Q21_POS];
539
622k
      Q30 = quanttbl->quantval[Q30_POS];
540
622k
    }
541
894k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
894k
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
894k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
2.37M
    for (block_row = 0; block_row < block_rows; block_row++) {
546
1.48M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
1.48M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
1.48M
      if (image_block_row > 0)
550
1.47M
        prev_block_row =
551
1.47M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
3.31k
      else
553
3.31k
        prev_block_row = buffer_ptr;
554
555
1.48M
      if (image_block_row > 1)
556
1.47M
        prev_prev_block_row =
557
1.47M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
6.50k
      else
559
6.50k
        prev_prev_block_row = prev_block_row;
560
561
1.48M
      if (image_block_row < image_block_rows - 1)
562
1.47M
        next_block_row =
563
1.47M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
3.07k
      else
565
3.07k
        next_block_row = buffer_ptr;
566
567
1.48M
      if (image_block_row < image_block_rows - 2)
568
1.47M
        next_next_block_row =
569
1.47M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
5.08k
      else
571
5.08k
        next_next_block_row = next_block_row;
572
573
      /* We fetch the surrounding DC values using a sliding-register approach.
574
       * Initialize all 25 here so as to do the right thing on narrow pics.
575
       */
576
1.48M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
1.48M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
1.48M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
1.48M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
1.48M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
1.48M
      output_col = 0;
582
1.48M
      last_block_column = compptr->width_in_blocks - 1;
583
1.48M
      for (block_num = cinfo->master->first_MCU_col[ci];
584
17.7M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
16.2M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
16.2M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
1.48M
            block_num < last_block_column) {
590
982k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
982k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
982k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
982k
          DC19 = DC20 = (int)next_block_row[1][0];
594
982k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
982k
        }
596
16.2M
        if (block_num + 1 < last_block_column) {
597
13.8M
          DC05 = (int)prev_prev_block_row[2][0];
598
13.8M
          DC10 = (int)prev_block_row[2][0];
599
13.8M
          DC15 = (int)buffer_ptr[2][0];
600
13.8M
          DC20 = (int)next_block_row[2][0];
601
13.8M
          DC25 = (int)next_next_block_row[2][0];
602
13.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
16.2M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
15.4M
          num = Q00 * (change_dc ?
616
9.60M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
9.60M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
9.60M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
9.60M
                 DC21 - DC22 + DC24 + DC25) :
620
15.4M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
15.4M
          if (num >= 0) {
622
10.5M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
10.5M
            if (Al > 0 && pred >= (1 << Al))
624
1.12M
              pred = (1 << Al) - 1;
625
10.5M
          } else {
626
4.83M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
4.83M
            if (Al > 0 && pred >= (1 << Al))
628
1.11M
              pred = (1 << Al) - 1;
629
4.83M
            pred = -pred;
630
4.83M
          }
631
15.4M
          workspace[1] = (JCOEF)pred;
632
15.4M
        }
633
        /* AC10 */
634
16.2M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
15.4M
          num = Q00 * (change_dc ?
636
9.60M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
9.60M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
9.60M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
9.60M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
15.4M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
15.4M
          if (num >= 0) {
642
10.1M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
10.1M
            if (Al > 0 && pred >= (1 << Al))
644
1.74M
              pred = (1 << Al) - 1;
645
10.1M
          } else {
646
5.33M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
5.33M
            if (Al > 0 && pred >= (1 << Al))
648
1.45M
              pred = (1 << Al) - 1;
649
5.33M
            pred = -pred;
650
5.33M
          }
651
15.4M
          workspace[8] = (JCOEF)pred;
652
15.4M
        }
653
        /* AC20 */
654
16.2M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
15.3M
          num = Q00 * (change_dc ?
656
9.60M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
9.60M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
15.3M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
15.3M
          if (num >= 0) {
660
9.06M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
9.06M
            if (Al > 0 && pred >= (1 << Al))
662
1.75M
              pred = (1 << Al) - 1;
663
9.06M
          } else {
664
6.33M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
6.33M
            if (Al > 0 && pred >= (1 << Al))
666
1.76M
              pred = (1 << Al) - 1;
667
6.33M
            pred = -pred;
668
6.33M
          }
669
15.3M
          workspace[16] = (JCOEF)pred;
670
15.3M
        }
671
        /* AC11 */
672
16.2M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
15.4M
          num = Q00 * (change_dc ?
674
9.60M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
9.60M
                 9 * DC19 + DC21 - DC25) :
676
15.4M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
5.87M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
15.4M
          if (num >= 0) {
679
11.4M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
11.4M
            if (Al > 0 && pred >= (1 << Al))
681
761k
              pred = (1 << Al) - 1;
682
11.4M
          } else {
683
4.05M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
4.05M
            if (Al > 0 && pred >= (1 << Al))
685
731k
              pred = (1 << Al) - 1;
686
4.05M
            pred = -pred;
687
4.05M
          }
688
15.4M
          workspace[9] = (JCOEF)pred;
689
15.4M
        }
690
        /* AC02 */
691
16.2M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
15.4M
          num = Q00 * (change_dc ?
693
9.60M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
9.60M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
15.4M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
15.4M
          if (num >= 0) {
697
9.19M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
9.19M
            if (Al > 0 && pred >= (1 << Al))
699
1.12M
              pred = (1 << Al) - 1;
700
9.19M
          } else {
701
6.26M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
6.26M
            if (Al > 0 && pred >= (1 << Al))
703
1.12M
              pred = (1 << Al) - 1;
704
6.26M
            pred = -pred;
705
6.26M
          }
706
15.4M
          workspace[2] = (JCOEF)pred;
707
15.4M
        }
708
16.2M
        if (change_dc) {
709
          /* AC03 */
710
9.60M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
9.60M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
9.60M
            if (num >= 0) {
713
6.93M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
6.93M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
6.93M
            } else {
717
2.66M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
2.66M
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
2.66M
              pred = -pred;
721
2.66M
            }
722
9.60M
            workspace[3] = (JCOEF)pred;
723
9.60M
          }
724
          /* AC12 */
725
9.60M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
9.60M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
9.60M
            if (num >= 0) {
728
5.45M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
5.45M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
5.45M
            } else {
732
4.14M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
4.14M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
4.14M
              pred = -pred;
736
4.14M
            }
737
9.60M
            workspace[10] = (JCOEF)pred;
738
9.60M
          }
739
          /* AC21 */
740
9.60M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
9.60M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
9.60M
            if (num >= 0) {
743
5.32M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
5.32M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
5.32M
            } else {
747
4.27M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
4.27M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
4.27M
              pred = -pred;
751
4.27M
            }
752
9.60M
            workspace[17] = (JCOEF)pred;
753
9.60M
          }
754
          /* AC30 */
755
9.60M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
9.60M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
9.60M
            if (num >= 0) {
758
6.67M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
6.67M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
6.67M
            } else {
762
2.92M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
2.92M
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
2.92M
              pred = -pred;
766
2.92M
            }
767
9.60M
            workspace[24] = (JCOEF)pred;
768
9.60M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
9.60M
          num = Q00 *
773
9.60M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
9.60M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
9.60M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
9.60M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
9.60M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
9.60M
          if (num >= 0) {
779
5.49M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
5.49M
          } else {
781
4.10M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
4.10M
            pred = -pred;
783
4.10M
          }
784
9.60M
          workspace[0] = (JCOEF)pred;
785
9.60M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
16.2M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
16.2M
                        output_col);
790
        /* Advance for next column */
791
16.2M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
16.2M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
16.2M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
16.2M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
16.2M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
16.2M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
16.2M
          prev_prev_block_row++, next_next_block_row++;
798
16.2M
        output_col += compptr->_DCT_scaled_size;
799
16.2M
      }
800
1.48M
      output_ptr += compptr->_DCT_scaled_size;
801
1.48M
    }
802
894k
  }
803
804
716k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
714k
    return JPEG_ROW_COMPLETED;
806
2.61k
  return JPEG_SCAN_COMPLETED;
807
716k
}
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
149k
{
819
149k
  my_coef_ptr coef;
820
821
149k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
24
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
149k
  coef = (my_coef_ptr)
825
149k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
149k
                                sizeof(my_coef_controller));
827
149k
  memset(coef, 0, sizeof(my_coef_controller));
828
149k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
149k
  coef->pub.start_input_pass = start_input_pass;
830
149k
  coef->pub.start_output_pass = start_output_pass;
831
149k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
149k
  coef->coef_bits_latch = NULL;
833
149k
#endif
834
835
  /* Create the coefficient buffer. */
836
149k
  if (need_full_buffer) {
837
118k
#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
118k
    int ci, access_rows;
842
118k
    jpeg_component_info *compptr;
843
844
351k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
233k
         ci++, compptr++) {
846
233k
      access_rows = compptr->v_samp_factor;
847
233k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
233k
      if (cinfo->progressive_mode)
850
128k
        access_rows *= 5;
851
233k
#endif
852
233k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
233k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
233k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
233k
                               (long)compptr->h_samp_factor),
856
233k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
233k
                               (long)compptr->v_samp_factor),
858
233k
         (JDIMENSION)access_rows);
859
233k
    }
860
118k
    coef->pub.consume_data = consume_data;
861
118k
    coef->pub._decompress_data = decompress_data;
862
118k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
118k
  } else {
867
    /* We only need a single-MCU buffer. */
868
31.1k
    JBLOCKROW buffer;
869
31.1k
    int i;
870
871
31.1k
    buffer = (JBLOCKROW)
872
31.1k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
31.1k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
341k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
310k
      coef->MCU_buffer[i] = buffer + i;
876
310k
    }
877
31.1k
    coef->pub.consume_data = dummy_consume_data;
878
31.1k
    coef->pub._decompress_data = decompress_onepass;
879
31.1k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
31.1k
  }
881
882
  /* Allocate the workspace buffer */
883
149k
  coef->workspace = (JCOEF *)
884
149k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
149k
                                sizeof(JCOEF) * DCTSIZE2);
886
149k
}
jinit_d_coef_controller
Line
Count
Source
818
119k
{
819
119k
  my_coef_ptr coef;
820
821
119k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
24
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
119k
  coef = (my_coef_ptr)
825
119k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
119k
                                sizeof(my_coef_controller));
827
119k
  memset(coef, 0, sizeof(my_coef_controller));
828
119k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
119k
  coef->pub.start_input_pass = start_input_pass;
830
119k
  coef->pub.start_output_pass = start_output_pass;
831
119k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
119k
  coef->coef_bits_latch = NULL;
833
119k
#endif
834
835
  /* Create the coefficient buffer. */
836
119k
  if (need_full_buffer) {
837
93.8k
#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
93.8k
    int ci, access_rows;
842
93.8k
    jpeg_component_info *compptr;
843
844
279k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
185k
         ci++, compptr++) {
846
185k
      access_rows = compptr->v_samp_factor;
847
185k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
185k
      if (cinfo->progressive_mode)
850
102k
        access_rows *= 5;
851
185k
#endif
852
185k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
185k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
185k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
185k
                               (long)compptr->h_samp_factor),
856
185k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
185k
                               (long)compptr->v_samp_factor),
858
185k
         (JDIMENSION)access_rows);
859
185k
    }
860
93.8k
    coef->pub.consume_data = consume_data;
861
93.8k
    coef->pub._decompress_data = decompress_data;
862
93.8k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
93.8k
  } else {
867
    /* We only need a single-MCU buffer. */
868
25.5k
    JBLOCKROW buffer;
869
25.5k
    int i;
870
871
25.5k
    buffer = (JBLOCKROW)
872
25.5k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
25.5k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
280k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
254k
      coef->MCU_buffer[i] = buffer + i;
876
254k
    }
877
25.5k
    coef->pub.consume_data = dummy_consume_data;
878
25.5k
    coef->pub._decompress_data = decompress_onepass;
879
25.5k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
25.5k
  }
881
882
  /* Allocate the workspace buffer */
883
119k
  coef->workspace = (JCOEF *)
884
119k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
119k
                                sizeof(JCOEF) * DCTSIZE2);
886
119k
}
j12init_d_coef_controller
Line
Count
Source
818
30.1k
{
819
30.1k
  my_coef_ptr coef;
820
821
30.1k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
30.1k
  coef = (my_coef_ptr)
825
30.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
30.1k
                                sizeof(my_coef_controller));
827
30.1k
  memset(coef, 0, sizeof(my_coef_controller));
828
30.1k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
30.1k
  coef->pub.start_input_pass = start_input_pass;
830
30.1k
  coef->pub.start_output_pass = start_output_pass;
831
30.1k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
30.1k
  coef->coef_bits_latch = NULL;
833
30.1k
#endif
834
835
  /* Create the coefficient buffer. */
836
30.1k
  if (need_full_buffer) {
837
24.5k
#ifdef D_MULTISCAN_FILES_SUPPORTED
838
    /* Allocate a full-image virtual array for each component, */
839
    /* padded to a multiple of samp_factor DCT blocks in each direction. */
840
    /* Note we ask for a pre-zeroed array. */
841
24.5k
    int ci, access_rows;
842
24.5k
    jpeg_component_info *compptr;
843
844
72.7k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
48.2k
         ci++, compptr++) {
846
48.2k
      access_rows = compptr->v_samp_factor;
847
48.2k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
48.2k
      if (cinfo->progressive_mode)
850
25.8k
        access_rows *= 5;
851
48.2k
#endif
852
48.2k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
48.2k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
48.2k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
48.2k
                               (long)compptr->h_samp_factor),
856
48.2k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
48.2k
                               (long)compptr->v_samp_factor),
858
48.2k
         (JDIMENSION)access_rows);
859
48.2k
    }
860
24.5k
    coef->pub.consume_data = consume_data;
861
24.5k
    coef->pub._decompress_data = decompress_data;
862
24.5k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
24.5k
  } else {
867
    /* We only need a single-MCU buffer. */
868
5.59k
    JBLOCKROW buffer;
869
5.59k
    int i;
870
871
5.59k
    buffer = (JBLOCKROW)
872
5.59k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
5.59k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
61.5k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
55.9k
      coef->MCU_buffer[i] = buffer + i;
876
55.9k
    }
877
5.59k
    coef->pub.consume_data = dummy_consume_data;
878
5.59k
    coef->pub._decompress_data = decompress_onepass;
879
5.59k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
5.59k
  }
881
882
  /* Allocate the workspace buffer */
883
30.1k
  coef->workspace = (JCOEF *)
884
30.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
30.1k
                                sizeof(JCOEF) * DCTSIZE2);
886
30.1k
}