Coverage Report

Created: 2025-08-29 07:07

/src/libjpeg-turbo/src/jdcoefct.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * jdcoefct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1997, Thomas G. Lane.
6
 * libjpeg-turbo Modifications:
7
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
8
 * Copyright (C) 2010, 2015-2016, 2019-2020, 2022-2024, D. R. Commander.
9
 * Copyright (C) 2015, 2020, Google, Inc.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the coefficient buffer controller for decompression.
14
 * This controller is the top level of the lossy JPEG decompressor proper.
15
 * The coefficient buffer lies between entropy decoding and inverse-DCT steps.
16
 *
17
 * In buffered-image mode, this controller is the interface between
18
 * input-oriented processing and output-oriented processing.
19
 * Also, the input side (only) is used when reading a file for transcoding.
20
 */
21
22
#include "jinclude.h"
23
#include "jdcoefct.h"
24
#include "jpegapicomp.h"
25
#include "jsamplecomp.h"
26
27
28
/* Forward declarations */
29
METHODDEF(int) decompress_onepass(j_decompress_ptr cinfo,
30
                                  _JSAMPIMAGE output_buf);
31
#ifdef D_MULTISCAN_FILES_SUPPORTED
32
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
33
#endif
34
#ifdef BLOCK_SMOOTHING_SUPPORTED
35
LOCAL(boolean) smoothing_ok(j_decompress_ptr cinfo);
36
METHODDEF(int) decompress_smooth_data(j_decompress_ptr cinfo,
37
                                      _JSAMPIMAGE output_buf);
38
#endif
39
40
41
/*
42
 * Initialize for an input processing pass.
43
 */
44
45
METHODDEF(void)
46
start_input_pass(j_decompress_ptr cinfo)
47
62.8k
{
48
62.8k
  cinfo->input_iMCU_row = 0;
49
62.8k
  start_iMCU_row(cinfo);
50
62.8k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
47
61.3k
{
48
61.3k
  cinfo->input_iMCU_row = 0;
49
61.3k
  start_iMCU_row(cinfo);
50
61.3k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
47
1.59k
{
48
1.59k
  cinfo->input_iMCU_row = 0;
49
1.59k
  start_iMCU_row(cinfo);
50
1.59k
}
51
52
53
/*
54
 * Initialize for an output processing pass.
55
 */
56
57
METHODDEF(void)
58
start_output_pass(j_decompress_ptr cinfo)
59
47.7k
{
60
47.7k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
47.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
47.7k
  if (coef->pub.coef_arrays != NULL) {
65
15.9k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
3.33k
      coef->pub._decompress_data = decompress_smooth_data;
67
12.6k
    else
68
12.6k
      coef->pub._decompress_data = decompress_data;
69
15.9k
  }
70
47.7k
#endif
71
47.7k
  cinfo->output_iMCU_row = 0;
72
47.7k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
59
47.6k
{
60
47.6k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
47.6k
  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
47.6k
  if (coef->pub.coef_arrays != NULL) {
65
15.7k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
3.23k
      coef->pub._decompress_data = decompress_smooth_data;
67
12.5k
    else
68
12.5k
      coef->pub._decompress_data = decompress_data;
69
15.7k
  }
70
47.6k
#endif
71
47.6k
  cinfo->output_iMCU_row = 0;
72
47.6k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
59
162
{
60
162
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
162
  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
162
  if (coef->pub.coef_arrays != NULL) {
65
160
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
100
      coef->pub._decompress_data = decompress_smooth_data;
67
60
    else
68
60
      coef->pub._decompress_data = decompress_data;
69
160
  }
70
162
#endif
71
162
  cinfo->output_iMCU_row = 0;
72
162
}
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
1.15M
{
88
1.15M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
1.15M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
1.15M
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
1.15M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
1.15M
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
1.15M
  _JSAMPARRAY output_ptr;
94
1.15M
  JDIMENSION start_col, output_col;
95
1.15M
  jpeg_component_info *compptr;
96
1.15M
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
2.31M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
1.15M
       yoffset++) {
101
12.6M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
11.4M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
11.4M
      jzero_far((void *)coef->MCU_buffer[0],
105
11.4M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
11.4M
      if (!cinfo->entropy->insufficient_data)
107
5.27M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
11.4M
      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
11.4M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
11.4M
          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
11.4M
        blkn = 0;               /* index of current DCT block within MCU */
126
23.7M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
12.2M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
12.2M
          if (!compptr->component_needed) {
130
0
            blkn += compptr->MCU_blocks;
131
0
            continue;
132
0
          }
133
12.2M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
12.2M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
11.0M
                         compptr->MCU_width : compptr->last_col_width;
136
12.2M
          output_ptr = output_buf[compptr->component_index] +
137
12.2M
                       yoffset * compptr->_DCT_scaled_size;
138
12.2M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
12.2M
                      compptr->MCU_sample_width;
140
24.9M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
12.6M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
12.6M
                yoffset + yindex < compptr->last_row_height) {
143
12.6M
              output_col = start_col;
144
26.0M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
13.3M
                (*inverse_DCT) (cinfo, compptr,
146
13.3M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
13.3M
                                output_ptr, output_col);
148
13.3M
                output_col += compptr->_DCT_scaled_size;
149
13.3M
              }
150
12.6M
            }
151
12.6M
            blkn += compptr->MCU_width;
152
12.6M
            output_ptr += compptr->_DCT_scaled_size;
153
12.6M
          }
154
12.2M
        }
155
11.4M
      }
156
11.4M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
1.15M
    coef->MCU_ctr = 0;
159
1.15M
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
1.15M
  cinfo->output_iMCU_row++;
162
1.15M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
1.12M
    start_iMCU_row(cinfo);
164
1.12M
    return JPEG_ROW_COMPLETED;
165
1.12M
  }
166
  /* Completed the scan */
167
36.5k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
36.5k
  return JPEG_SCAN_COMPLETED;
169
1.15M
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
87
1.15M
{
88
1.15M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
1.15M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
1.15M
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
1.15M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
1.15M
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
1.15M
  _JSAMPARRAY output_ptr;
94
1.15M
  JDIMENSION start_col, output_col;
95
1.15M
  jpeg_component_info *compptr;
96
1.15M
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
2.30M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
1.15M
       yoffset++) {
101
12.6M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
11.4M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
11.4M
      jzero_far((void *)coef->MCU_buffer[0],
105
11.4M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
11.4M
      if (!cinfo->entropy->insufficient_data)
107
5.27M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
11.4M
      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
11.4M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
11.4M
          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
11.4M
        blkn = 0;               /* index of current DCT block within MCU */
126
23.6M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
12.2M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
12.2M
          if (!compptr->component_needed) {
130
0
            blkn += compptr->MCU_blocks;
131
0
            continue;
132
0
          }
133
12.2M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
12.2M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
11.0M
                         compptr->MCU_width : compptr->last_col_width;
136
12.2M
          output_ptr = output_buf[compptr->component_index] +
137
12.2M
                       yoffset * compptr->_DCT_scaled_size;
138
12.2M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
12.2M
                      compptr->MCU_sample_width;
140
24.9M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
12.6M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
12.6M
                yoffset + yindex < compptr->last_row_height) {
143
12.6M
              output_col = start_col;
144
26.0M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
13.3M
                (*inverse_DCT) (cinfo, compptr,
146
13.3M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
13.3M
                                output_ptr, output_col);
148
13.3M
                output_col += compptr->_DCT_scaled_size;
149
13.3M
              }
150
12.6M
            }
151
12.6M
            blkn += compptr->MCU_width;
152
12.6M
            output_ptr += compptr->_DCT_scaled_size;
153
12.6M
          }
154
12.2M
        }
155
11.4M
      }
156
11.4M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
1.15M
    coef->MCU_ctr = 0;
159
1.15M
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
1.15M
  cinfo->output_iMCU_row++;
162
1.15M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
1.11M
    start_iMCU_row(cinfo);
164
1.11M
    return JPEG_ROW_COMPLETED;
165
1.11M
  }
166
  /* Completed the scan */
167
36.5k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
36.5k
  return JPEG_SCAN_COMPLETED;
169
1.15M
}
jdcoefct-12.c:decompress_onepass
Line
Count
Source
87
4.92k
{
88
4.92k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
4.92k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
4.92k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
4.92k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
4.92k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
4.92k
  _JSAMPARRAY output_ptr;
94
4.92k
  JDIMENSION start_col, output_col;
95
4.92k
  jpeg_component_info *compptr;
96
4.92k
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
9.85k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
4.92k
       yoffset++) {
101
9.85k
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
4.92k
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
4.92k
      jzero_far((void *)coef->MCU_buffer[0],
105
4.92k
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
4.92k
      if (!cinfo->entropy->insufficient_data)
107
8
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
4.92k
      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
4.92k
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
4.92k
          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
4.92k
        blkn = 0;               /* index of current DCT block within MCU */
126
19.7k
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
14.7k
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
14.7k
          if (!compptr->component_needed) {
130
0
            blkn += compptr->MCU_blocks;
131
0
            continue;
132
0
          }
133
14.7k
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
14.7k
          useful_width = (MCU_col_num < last_MCU_col) ?
135
14.7k
                         compptr->MCU_width : compptr->last_col_width;
136
14.7k
          output_ptr = output_buf[compptr->component_index] +
137
14.7k
                       yoffset * compptr->_DCT_scaled_size;
138
14.7k
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
14.7k
                      compptr->MCU_sample_width;
140
29.5k
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
14.7k
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
14.7k
                yoffset + yindex < compptr->last_row_height) {
143
14.7k
              output_col = start_col;
144
29.5k
              for (xindex = 0; xindex < useful_width; xindex++) {
145
14.7k
                (*inverse_DCT) (cinfo, compptr,
146
14.7k
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
14.7k
                                output_ptr, output_col);
148
14.7k
                output_col += compptr->_DCT_scaled_size;
149
14.7k
              }
150
14.7k
            }
151
14.7k
            blkn += compptr->MCU_width;
152
14.7k
            output_ptr += compptr->_DCT_scaled_size;
153
14.7k
          }
154
14.7k
        }
155
4.92k
      }
156
4.92k
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
4.92k
    coef->MCU_ctr = 0;
159
4.92k
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
4.92k
  cinfo->output_iMCU_row++;
162
4.92k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
4.92k
    start_iMCU_row(cinfo);
164
4.92k
    return JPEG_ROW_COMPLETED;
165
4.92k
  }
166
  /* Completed the scan */
167
2
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
2
  return JPEG_SCAN_COMPLETED;
169
4.92k
}
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
778k
{
195
778k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
778k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
778k
  int blkn, ci, xindex, yindex, yoffset;
198
778k
  JDIMENSION start_col;
199
778k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
778k
  JBLOCKROW buffer_ptr;
201
778k
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
1.74M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
970k
    compptr = cinfo->cur_comp_info[ci];
206
970k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
970k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
970k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
970k
       (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
970k
  }
215
216
  /* Loop to process one whole iMCU row */
217
1.61M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
836k
       yoffset++) {
219
13.1M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
12.2M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
12.2M
      blkn = 0;                 /* index of current DCT block within MCU */
223
26.3M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
14.0M
        compptr = cinfo->cur_comp_info[ci];
225
14.0M
        start_col = MCU_col_num * compptr->MCU_width;
226
28.1M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
14.0M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
28.2M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
14.1M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
14.1M
          }
231
14.0M
        }
232
14.0M
      }
233
12.2M
      if (!cinfo->entropy->insufficient_data)
234
5.80M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
12.2M
      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
12.2M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
836k
    coef->MCU_ctr = 0;
245
836k
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
778k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
747k
    start_iMCU_row(cinfo);
249
747k
    return JPEG_ROW_COMPLETED;
250
747k
  }
251
  /* Completed the scan */
252
31.0k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
31.0k
  return JPEG_SCAN_COMPLETED;
254
778k
}
jdcoefct-8.c:consume_data
Line
Count
Source
194
549k
{
195
549k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
549k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
549k
  int blkn, ci, xindex, yindex, yoffset;
198
549k
  JDIMENSION start_col;
199
549k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
549k
  JBLOCKROW buffer_ptr;
201
549k
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
1.11M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
566k
    compptr = cinfo->cur_comp_info[ci];
206
566k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
566k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
566k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
566k
       (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
566k
  }
215
216
  /* Loop to process one whole iMCU row */
217
1.15M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
607k
       yoffset++) {
219
10.5M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
9.98M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
9.98M
      blkn = 0;                 /* index of current DCT block within MCU */
223
20.1M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
10.2M
        compptr = cinfo->cur_comp_info[ci];
225
10.2M
        start_col = MCU_col_num * compptr->MCU_width;
226
20.4M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
10.2M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
20.4M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
10.2M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
10.2M
          }
231
10.2M
        }
232
10.2M
      }
233
9.98M
      if (!cinfo->entropy->insufficient_data)
234
3.67M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
9.98M
      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
9.98M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
607k
    coef->MCU_ctr = 0;
245
607k
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
549k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
520k
    start_iMCU_row(cinfo);
249
520k
    return JPEG_ROW_COMPLETED;
250
520k
  }
251
  /* Completed the scan */
252
29.4k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
29.4k
  return JPEG_SCAN_COMPLETED;
254
549k
}
jdcoefct-12.c:consume_data
Line
Count
Source
194
228k
{
195
228k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
228k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
228k
  int blkn, ci, xindex, yindex, yoffset;
198
228k
  JDIMENSION start_col;
199
228k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
228k
  JBLOCKROW buffer_ptr;
201
228k
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
633k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
404k
    compptr = cinfo->cur_comp_info[ci];
206
404k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
404k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
404k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
404k
       (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
404k
  }
215
216
  /* Loop to process one whole iMCU row */
217
457k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
228k
       yoffset++) {
219
2.53M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
2.30M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
2.30M
      blkn = 0;                 /* index of current DCT block within MCU */
223
6.17M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
3.87M
        compptr = cinfo->cur_comp_info[ci];
225
3.87M
        start_col = MCU_col_num * compptr->MCU_width;
226
7.74M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
3.87M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
7.74M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
3.87M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
3.87M
          }
231
3.87M
        }
232
3.87M
      }
233
2.30M
      if (!cinfo->entropy->insufficient_data)
234
2.12M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
2.30M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
237
        /* Suspension forced; update state counters and exit */
238
0
        coef->MCU_vert_offset = yoffset;
239
0
        coef->MCU_ctr = MCU_col_num;
240
0
        return JPEG_SUSPENDED;
241
0
      }
242
2.30M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
228k
    coef->MCU_ctr = 0;
245
228k
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
228k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
227k
    start_iMCU_row(cinfo);
249
227k
    return JPEG_ROW_COMPLETED;
250
227k
  }
251
  /* Completed the scan */
252
1.58k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
1.58k
  return JPEG_SCAN_COMPLETED;
254
228k
}
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
184k
{
268
184k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
184k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
184k
  JDIMENSION block_num;
271
184k
  int ci, block_row, block_rows;
272
184k
  JBLOCKARRAY buffer;
273
184k
  JBLOCKROW buffer_ptr;
274
184k
  _JSAMPARRAY output_ptr;
275
184k
  JDIMENSION output_col;
276
184k
  jpeg_component_info *compptr;
277
184k
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
184k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
184k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
184k
          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
464k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
279k
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
279k
    if (!compptr->component_needed)
292
0
      continue;
293
    /* Align the virtual buffer for this component. */
294
279k
    buffer = (*cinfo->mem->access_virt_barray)
295
279k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
279k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
279k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
279k
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
250k
      block_rows = compptr->v_samp_factor;
301
28.8k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
28.8k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
28.8k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
28.8k
    }
306
279k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
279k
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
594k
    for (block_row = 0; block_row < block_rows; block_row++) {
310
315k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
315k
      output_col = 0;
312
315k
      for (block_num = cinfo->master->first_MCU_col[ci];
313
3.12M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
2.81M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
2.81M
                        output_col);
316
2.81M
        buffer_ptr++;
317
2.81M
        output_col += compptr->_DCT_scaled_size;
318
2.81M
      }
319
315k
      output_ptr += compptr->_DCT_scaled_size;
320
315k
    }
321
279k
  }
322
323
184k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
172k
    return JPEG_ROW_COMPLETED;
325
12.5k
  return JPEG_SCAN_COMPLETED;
326
184k
}
jdcoefct-8.c:decompress_data
Line
Count
Source
267
184k
{
268
184k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
184k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
184k
  JDIMENSION block_num;
271
184k
  int ci, block_row, block_rows;
272
184k
  JBLOCKARRAY buffer;
273
184k
  JBLOCKROW buffer_ptr;
274
184k
  _JSAMPARRAY output_ptr;
275
184k
  JDIMENSION output_col;
276
184k
  jpeg_component_info *compptr;
277
184k
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
184k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
184k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
184k
          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
463k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
278k
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
278k
    if (!compptr->component_needed)
292
0
      continue;
293
    /* Align the virtual buffer for this component. */
294
278k
    buffer = (*cinfo->mem->access_virt_barray)
295
278k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
278k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
278k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
278k
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
250k
      block_rows = compptr->v_samp_factor;
301
28.8k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
28.8k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
28.8k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
28.8k
    }
306
278k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
278k
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
594k
    for (block_row = 0; block_row < block_rows; block_row++) {
310
315k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
315k
      output_col = 0;
312
315k
      for (block_num = cinfo->master->first_MCU_col[ci];
313
3.03M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
2.71M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
2.71M
                        output_col);
316
2.71M
        buffer_ptr++;
317
2.71M
        output_col += compptr->_DCT_scaled_size;
318
2.71M
      }
319
315k
      output_ptr += compptr->_DCT_scaled_size;
320
315k
    }
321
278k
  }
322
323
184k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
172k
    return JPEG_ROW_COMPLETED;
325
12.5k
  return JPEG_SCAN_COMPLETED;
326
184k
}
jdcoefct-12.c:decompress_data
Line
Count
Source
267
137
{
268
137
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
137
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
137
  JDIMENSION block_num;
271
137
  int ci, block_row, block_rows;
272
137
  JBLOCKARRAY buffer;
273
137
  JBLOCKROW buffer_ptr;
274
137
  _JSAMPARRAY output_ptr;
275
137
  JDIMENSION output_col;
276
137
  jpeg_component_info *compptr;
277
137
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
137
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
137
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
137
          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
548
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
411
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
411
    if (!compptr->component_needed)
292
0
      continue;
293
    /* Align the virtual buffer for this component. */
294
411
    buffer = (*cinfo->mem->access_virt_barray)
295
411
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
411
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
411
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
411
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
369
      block_rows = compptr->v_samp_factor;
301
42
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
42
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
42
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
42
    }
306
411
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
411
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
822
    for (block_row = 0; block_row < block_rows; block_row++) {
310
411
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
411
      output_col = 0;
312
411
      for (block_num = cinfo->master->first_MCU_col[ci];
313
95.2k
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
94.8k
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
94.8k
                        output_col);
316
94.8k
        buffer_ptr++;
317
94.8k
        output_col += compptr->_DCT_scaled_size;
318
94.8k
      }
319
411
      output_ptr += compptr->_DCT_scaled_size;
320
411
    }
321
411
  }
322
323
137
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
123
    return JPEG_ROW_COMPLETED;
325
14
  return JPEG_SCAN_COMPLETED;
326
137
}
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
126k
#define Q01_POS  1
342
125k
#define Q10_POS  8
343
125k
#define Q20_POS  16
344
124k
#define Q11_POS  9
345
124k
#define Q02_POS  2
346
103k
#define Q03_POS  3
347
102k
#define Q12_POS  10
348
102k
#define Q21_POS  17
349
102k
#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
15.9k
{
362
15.9k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
15.9k
  boolean smoothing_useful = FALSE;
364
15.9k
  int ci, coefi;
365
15.9k
  jpeg_component_info *compptr;
366
15.9k
  JQUANT_TBL *qtable;
367
15.9k
  int *coef_bits, *prev_coef_bits;
368
15.9k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
15.9k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
4.60k
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
11.3k
  if (coef->coef_bits_latch == NULL)
375
11.3k
    coef->coef_bits_latch = (int *)
376
11.3k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
11.3k
                                  cinfo->num_components * 2 *
378
11.3k
                                  (SAVED_COEFS * sizeof(int)));
379
11.3k
  coef_bits_latch = coef->coef_bits_latch;
380
11.3k
  prev_coef_bits_latch =
381
11.3k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
16.9k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
13.5k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
13.5k
    if ((qtable = compptr->quant_table) == NULL)
387
1.89k
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
11.6k
    if (qtable->quantval[0] == 0 ||
390
11.6k
        qtable->quantval[Q01_POS] == 0 ||
391
11.6k
        qtable->quantval[Q10_POS] == 0 ||
392
11.6k
        qtable->quantval[Q20_POS] == 0 ||
393
11.6k
        qtable->quantval[Q11_POS] == 0 ||
394
11.6k
        qtable->quantval[Q02_POS] == 0 ||
395
11.6k
        qtable->quantval[Q03_POS] == 0 ||
396
11.6k
        qtable->quantval[Q12_POS] == 0 ||
397
11.6k
        qtable->quantval[Q21_POS] == 0 ||
398
11.6k
        qtable->quantval[Q30_POS] == 0)
399
5.42k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
6.20k
    coef_bits = cinfo->coef_bits[ci];
402
6.20k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
6.20k
    if (coef_bits[0] < 0)
404
644
      return FALSE;
405
5.56k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
55.6k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
50.0k
      if (cinfo->input_scan_number > 1)
409
33.5k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
16.5k
      else
411
16.5k
        prev_coef_bits_latch[coefi] = -1;
412
50.0k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
50.0k
      if (coef_bits[coefi] != 0)
414
38.7k
        smoothing_useful = TRUE;
415
50.0k
    }
416
5.56k
    coef_bits_latch += SAVED_COEFS;
417
5.56k
    prev_coef_bits_latch += SAVED_COEFS;
418
5.56k
  }
419
420
3.38k
  return smoothing_useful;
421
11.3k
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
361
15.7k
{
362
15.7k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
15.7k
  boolean smoothing_useful = FALSE;
364
15.7k
  int ci, coefi;
365
15.7k
  jpeg_component_info *compptr;
366
15.7k
  JQUANT_TBL *qtable;
367
15.7k
  int *coef_bits, *prev_coef_bits;
368
15.7k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
15.7k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
4.60k
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
11.1k
  if (coef->coef_bits_latch == NULL)
375
11.1k
    coef->coef_bits_latch = (int *)
376
11.1k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
11.1k
                                  cinfo->num_components * 2 *
378
11.1k
                                  (SAVED_COEFS * sizeof(int)));
379
11.1k
  coef_bits_latch = coef->coef_bits_latch;
380
11.1k
  prev_coef_bits_latch =
381
11.1k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
16.4k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
13.1k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
13.1k
    if ((qtable = compptr->quant_table) == NULL)
387
1.88k
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
11.2k
    if (qtable->quantval[0] == 0 ||
390
11.2k
        qtable->quantval[Q01_POS] == 0 ||
391
11.2k
        qtable->quantval[Q10_POS] == 0 ||
392
11.2k
        qtable->quantval[Q20_POS] == 0 ||
393
11.2k
        qtable->quantval[Q11_POS] == 0 ||
394
11.2k
        qtable->quantval[Q02_POS] == 0 ||
395
11.2k
        qtable->quantval[Q03_POS] == 0 ||
396
11.2k
        qtable->quantval[Q12_POS] == 0 ||
397
11.2k
        qtable->quantval[Q21_POS] == 0 ||
398
11.2k
        qtable->quantval[Q30_POS] == 0)
399
5.37k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
5.88k
    coef_bits = cinfo->coef_bits[ci];
402
5.88k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
5.88k
    if (coef_bits[0] < 0)
404
637
      return FALSE;
405
5.24k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
52.4k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
47.1k
      if (cinfo->input_scan_number > 1)
409
31.5k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
15.6k
      else
411
15.6k
        prev_coef_bits_latch[coefi] = -1;
412
47.1k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
47.1k
      if (coef_bits[coefi] != 0)
414
35.9k
        smoothing_useful = TRUE;
415
47.1k
    }
416
5.24k
    coef_bits_latch += SAVED_COEFS;
417
5.24k
    prev_coef_bits_latch += SAVED_COEFS;
418
5.24k
  }
419
420
3.28k
  return smoothing_useful;
421
11.1k
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
361
160
{
362
160
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
160
  boolean smoothing_useful = FALSE;
364
160
  int ci, coefi;
365
160
  jpeg_component_info *compptr;
366
160
  JQUANT_TBL *qtable;
367
160
  int *coef_bits, *prev_coef_bits;
368
160
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
160
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
1
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
159
  if (coef->coef_bits_latch == NULL)
375
159
    coef->coef_bits_latch = (int *)
376
159
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
159
                                  cinfo->num_components * 2 *
378
159
                                  (SAVED_COEFS * sizeof(int)));
379
159
  coef_bits_latch = coef->coef_bits_latch;
380
159
  prev_coef_bits_latch =
381
159
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
476
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
376
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
376
    if ((qtable = compptr->quant_table) == NULL)
387
9
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
367
    if (qtable->quantval[0] == 0 ||
390
367
        qtable->quantval[Q01_POS] == 0 ||
391
367
        qtable->quantval[Q10_POS] == 0 ||
392
367
        qtable->quantval[Q20_POS] == 0 ||
393
367
        qtable->quantval[Q11_POS] == 0 ||
394
367
        qtable->quantval[Q02_POS] == 0 ||
395
367
        qtable->quantval[Q03_POS] == 0 ||
396
367
        qtable->quantval[Q12_POS] == 0 ||
397
367
        qtable->quantval[Q21_POS] == 0 ||
398
367
        qtable->quantval[Q30_POS] == 0)
399
43
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
324
    coef_bits = cinfo->coef_bits[ci];
402
324
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
324
    if (coef_bits[0] < 0)
404
7
      return FALSE;
405
317
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
3.17k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
2.85k
      if (cinfo->input_scan_number > 1)
409
1.94k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
909
      else
411
909
        prev_coef_bits_latch[coefi] = -1;
412
2.85k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
2.85k
      if (coef_bits[coefi] != 0)
414
2.80k
        smoothing_useful = TRUE;
415
2.85k
    }
416
317
    coef_bits_latch += SAVED_COEFS;
417
317
    prev_coef_bits_latch += SAVED_COEFS;
418
317
  }
419
420
100
  return smoothing_useful;
421
159
}
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
111k
{
431
111k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
111k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
111k
  JDIMENSION block_num, last_block_column;
434
111k
  int ci, block_row, block_rows, access_rows, image_block_row,
435
111k
    image_block_rows;
436
111k
  JBLOCKARRAY buffer;
437
111k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
111k
  JBLOCKROW next_block_row, next_next_block_row;
439
111k
  _JSAMPARRAY output_ptr;
440
111k
  JDIMENSION output_col;
441
111k
  jpeg_component_info *compptr;
442
111k
  _inverse_DCT_method_ptr inverse_DCT;
443
111k
  boolean change_dc;
444
111k
  JCOEF *workspace;
445
111k
  int *coef_bits;
446
111k
  JQUANT_TBL *quanttbl;
447
111k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
111k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
111k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
111k
      DC25;
451
111k
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
111k
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
111k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
111k
         !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
226k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
114k
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
114k
    if (!compptr->component_needed)
478
0
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
114k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
107k
      block_rows = compptr->v_samp_factor;
482
107k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
107k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
3.58k
      block_rows = compptr->v_samp_factor;
485
3.58k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
3.59k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
3.59k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
3.59k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
3.59k
      access_rows = block_rows; /* this iMCU row only */
491
3.59k
    }
492
    /* Align the virtual buffer for this component. */
493
114k
    if (cinfo->output_iMCU_row > 1) {
494
107k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
107k
      buffer = (*cinfo->mem->access_virt_barray)
496
107k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
107k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
107k
         (JDIMENSION)access_rows, FALSE);
499
107k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
107k
    } else if (cinfo->output_iMCU_row > 0) {
501
3.58k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
3.58k
      buffer = (*cinfo->mem->access_virt_barray)
503
3.58k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
3.58k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
3.58k
         (JDIMENSION)access_rows, FALSE);
506
3.58k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
3.59k
    } else {
508
3.59k
      buffer = (*cinfo->mem->access_virt_barray)
509
3.59k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
3.59k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
3.59k
    }
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
114k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
57.9k
      coef_bits =
518
57.9k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
56.7k
    else
520
56.7k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
114k
    change_dc =
524
114k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
114k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
114k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
114k
    quanttbl = compptr->quant_table;
529
114k
    Q00 = quanttbl->quantval[0];
530
114k
    Q01 = quanttbl->quantval[Q01_POS];
531
114k
    Q10 = quanttbl->quantval[Q10_POS];
532
114k
    Q20 = quanttbl->quantval[Q20_POS];
533
114k
    Q11 = quanttbl->quantval[Q11_POS];
534
114k
    Q02 = quanttbl->quantval[Q02_POS];
535
114k
    if (change_dc) {
536
94.9k
      Q03 = quanttbl->quantval[Q03_POS];
537
94.9k
      Q12 = quanttbl->quantval[Q12_POS];
538
94.9k
      Q21 = quanttbl->quantval[Q21_POS];
539
94.9k
      Q30 = quanttbl->quantval[Q30_POS];
540
94.9k
    }
541
114k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
114k
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
114k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
229k
    for (block_row = 0; block_row < block_rows; block_row++) {
546
114k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
114k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
114k
      if (image_block_row > 0)
550
111k
        prev_block_row =
551
111k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
3.59k
      else
553
3.59k
        prev_block_row = buffer_ptr;
554
555
114k
      if (image_block_row > 1)
556
107k
        prev_prev_block_row =
557
107k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
7.18k
      else
559
7.18k
        prev_prev_block_row = prev_block_row;
560
561
114k
      if (image_block_row < image_block_rows - 1)
562
111k
        next_block_row =
563
111k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
3.59k
      else
565
3.59k
        next_block_row = buffer_ptr;
566
567
114k
      if (image_block_row < image_block_rows - 2)
568
107k
        next_next_block_row =
569
107k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
7.18k
      else
571
7.18k
        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
114k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
114k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
114k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
114k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
114k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
114k
      output_col = 0;
582
114k
      last_block_column = compptr->width_in_blocks - 1;
583
114k
      for (block_num = cinfo->master->first_MCU_col[ci];
584
5.30M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
5.18M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
5.18M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
5.18M
            block_num < last_block_column) {
590
114k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
114k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
114k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
114k
          DC19 = DC20 = (int)next_block_row[1][0];
594
114k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
114k
        }
596
5.18M
        if (block_num + 1 < last_block_column) {
597
4.95M
          DC05 = (int)prev_prev_block_row[2][0];
598
4.95M
          DC10 = (int)prev_block_row[2][0];
599
4.95M
          DC15 = (int)buffer_ptr[2][0];
600
4.95M
          DC20 = (int)next_block_row[2][0];
601
4.95M
          DC25 = (int)next_next_block_row[2][0];
602
4.95M
        }
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
5.18M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
4.99M
          num = Q00 * (change_dc ?
616
4.57M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
4.57M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
4.57M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
4.57M
                 DC21 - DC22 + DC24 + DC25) :
620
4.99M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
4.99M
          if (num >= 0) {
622
3.84M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
3.84M
            if (Al > 0 && pred >= (1 << Al))
624
19.3k
              pred = (1 << Al) - 1;
625
3.84M
          } else {
626
1.15M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
1.15M
            if (Al > 0 && pred >= (1 << Al))
628
18.0k
              pred = (1 << Al) - 1;
629
1.15M
            pred = -pred;
630
1.15M
          }
631
4.99M
          workspace[1] = (JCOEF)pred;
632
4.99M
        }
633
        /* AC10 */
634
5.18M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
5.03M
          num = Q00 * (change_dc ?
636
4.57M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
4.57M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
4.57M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
4.57M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
5.03M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
5.03M
          if (num >= 0) {
642
3.69M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
3.69M
            if (Al > 0 && pred >= (1 << Al))
644
87.2k
              pred = (1 << Al) - 1;
645
3.69M
          } else {
646
1.33M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
1.33M
            if (Al > 0 && pred >= (1 << Al))
648
83.6k
              pred = (1 << Al) - 1;
649
1.33M
            pred = -pred;
650
1.33M
          }
651
5.03M
          workspace[8] = (JCOEF)pred;
652
5.03M
        }
653
        /* AC20 */
654
5.18M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
5.05M
          num = Q00 * (change_dc ?
656
4.57M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
4.57M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
5.05M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
5.05M
          if (num >= 0) {
660
3.75M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
3.75M
            if (Al > 0 && pred >= (1 << Al))
662
47.2k
              pred = (1 << Al) - 1;
663
3.75M
          } else {
664
1.30M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
1.30M
            if (Al > 0 && pred >= (1 << Al))
666
44.0k
              pred = (1 << Al) - 1;
667
1.30M
            pred = -pred;
668
1.30M
          }
669
5.05M
          workspace[16] = (JCOEF)pred;
670
5.05M
        }
671
        /* AC11 */
672
5.18M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
5.03M
          num = Q00 * (change_dc ?
674
4.57M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
4.57M
                 9 * DC19 + DC21 - DC25) :
676
5.03M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
455k
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
5.03M
          if (num >= 0) {
679
4.08M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
4.08M
            if (Al > 0 && pred >= (1 << Al))
681
43.1k
              pred = (1 << Al) - 1;
682
4.08M
          } else {
683
949k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
949k
            if (Al > 0 && pred >= (1 << Al))
685
41.8k
              pred = (1 << Al) - 1;
686
949k
            pred = -pred;
687
949k
          }
688
5.03M
          workspace[9] = (JCOEF)pred;
689
5.03M
        }
690
        /* AC02 */
691
5.18M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
5.07M
          num = Q00 * (change_dc ?
693
4.57M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
4.57M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
5.07M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
5.07M
          if (num >= 0) {
697
3.82M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
3.82M
            if (Al > 0 && pred >= (1 << Al))
699
31.2k
              pred = (1 << Al) - 1;
700
3.82M
          } else {
701
1.24M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
1.24M
            if (Al > 0 && pred >= (1 << Al))
703
29.3k
              pred = (1 << Al) - 1;
704
1.24M
            pred = -pred;
705
1.24M
          }
706
5.07M
          workspace[2] = (JCOEF)pred;
707
5.07M
        }
708
5.18M
        if (change_dc) {
709
          /* AC03 */
710
4.57M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
4.57M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
4.57M
            if (num >= 0) {
713
3.65M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
3.65M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
3.65M
            } else {
717
925k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
925k
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
925k
              pred = -pred;
721
925k
            }
722
4.57M
            workspace[3] = (JCOEF)pred;
723
4.57M
          }
724
          /* AC12 */
725
4.57M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
4.57M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
4.57M
            if (num >= 0) {
728
3.54M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
3.54M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
3.54M
            } else {
732
1.03M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
1.03M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
1.03M
              pred = -pred;
736
1.03M
            }
737
4.57M
            workspace[10] = (JCOEF)pred;
738
4.57M
          }
739
          /* AC21 */
740
4.57M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
4.57M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
4.57M
            if (num >= 0) {
743
3.62M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
3.62M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
3.62M
            } else {
747
950k
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
950k
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
950k
              pred = -pred;
751
950k
            }
752
4.57M
            workspace[17] = (JCOEF)pred;
753
4.57M
          }
754
          /* AC30 */
755
4.57M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
4.57M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
4.57M
            if (num >= 0) {
758
3.52M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
3.52M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
3.52M
            } else {
762
1.04M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
1.04M
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
1.04M
              pred = -pred;
766
1.04M
            }
767
4.57M
            workspace[24] = (JCOEF)pred;
768
4.57M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
4.57M
          num = Q00 *
773
4.57M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
4.57M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
4.57M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
4.57M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
4.57M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
4.57M
          if (num >= 0) {
779
3.43M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
3.43M
          } else {
781
1.13M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
1.13M
            pred = -pred;
783
1.13M
          }
784
4.57M
          workspace[0] = (JCOEF)pred;
785
4.57M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
5.18M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
5.18M
                        output_col);
790
        /* Advance for next column */
791
5.18M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
5.18M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
5.18M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
5.18M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
5.18M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
5.18M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
5.18M
          prev_prev_block_row++, next_next_block_row++;
798
5.18M
        output_col += compptr->_DCT_scaled_size;
799
5.18M
      }
800
114k
      output_ptr += compptr->_DCT_scaled_size;
801
114k
    }
802
114k
  }
803
804
111k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
108k
    return JPEG_ROW_COMPLETED;
806
3.32k
  return JPEG_SCAN_COMPLETED;
807
111k
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
430
111k
{
431
111k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
111k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
111k
  JDIMENSION block_num, last_block_column;
434
111k
  int ci, block_row, block_rows, access_rows, image_block_row,
435
111k
    image_block_rows;
436
111k
  JBLOCKARRAY buffer;
437
111k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
111k
  JBLOCKROW next_block_row, next_next_block_row;
439
111k
  _JSAMPARRAY output_ptr;
440
111k
  JDIMENSION output_col;
441
111k
  jpeg_component_info *compptr;
442
111k
  _inverse_DCT_method_ptr inverse_DCT;
443
111k
  boolean change_dc;
444
111k
  JCOEF *workspace;
445
111k
  int *coef_bits;
446
111k
  JQUANT_TBL *quanttbl;
447
111k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
111k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
111k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
111k
      DC25;
451
111k
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
111k
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
111k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
111k
         !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
224k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
113k
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
113k
    if (!compptr->component_needed)
478
0
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
113k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
106k
      block_rows = compptr->v_samp_factor;
482
106k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
106k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
3.29k
      block_rows = compptr->v_samp_factor;
485
3.29k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
3.29k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
3.29k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
3.29k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
3.29k
      access_rows = block_rows; /* this iMCU row only */
491
3.29k
    }
492
    /* Align the virtual buffer for this component. */
493
113k
    if (cinfo->output_iMCU_row > 1) {
494
106k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
106k
      buffer = (*cinfo->mem->access_virt_barray)
496
106k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
106k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
106k
         (JDIMENSION)access_rows, FALSE);
499
106k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
106k
    } else if (cinfo->output_iMCU_row > 0) {
501
3.29k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
3.29k
      buffer = (*cinfo->mem->access_virt_barray)
503
3.29k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
3.29k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
3.29k
         (JDIMENSION)access_rows, FALSE);
506
3.29k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
3.29k
    } else {
508
3.29k
      buffer = (*cinfo->mem->access_virt_barray)
509
3.29k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
3.29k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
3.29k
    }
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
113k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
57.9k
      coef_bits =
518
57.9k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
55.5k
    else
520
55.5k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
113k
    change_dc =
524
113k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
113k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
113k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
113k
    quanttbl = compptr->quant_table;
529
113k
    Q00 = quanttbl->quantval[0];
530
113k
    Q01 = quanttbl->quantval[Q01_POS];
531
113k
    Q10 = quanttbl->quantval[Q10_POS];
532
113k
    Q20 = quanttbl->quantval[Q20_POS];
533
113k
    Q11 = quanttbl->quantval[Q11_POS];
534
113k
    Q02 = quanttbl->quantval[Q02_POS];
535
113k
    if (change_dc) {
536
94.0k
      Q03 = quanttbl->quantval[Q03_POS];
537
94.0k
      Q12 = quanttbl->quantval[Q12_POS];
538
94.0k
      Q21 = quanttbl->quantval[Q21_POS];
539
94.0k
      Q30 = quanttbl->quantval[Q30_POS];
540
94.0k
    }
541
113k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
113k
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
113k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
227k
    for (block_row = 0; block_row < block_rows; block_row++) {
546
113k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
113k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
113k
      if (image_block_row > 0)
550
110k
        prev_block_row =
551
110k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
3.29k
      else
553
3.29k
        prev_block_row = buffer_ptr;
554
555
113k
      if (image_block_row > 1)
556
106k
        prev_prev_block_row =
557
106k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
6.59k
      else
559
6.59k
        prev_prev_block_row = prev_block_row;
560
561
113k
      if (image_block_row < image_block_rows - 1)
562
110k
        next_block_row =
563
110k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
3.29k
      else
565
3.29k
        next_block_row = buffer_ptr;
566
567
113k
      if (image_block_row < image_block_rows - 2)
568
106k
        next_next_block_row =
569
106k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
6.59k
      else
571
6.59k
        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
113k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
113k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
113k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
113k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
113k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
113k
      output_col = 0;
582
113k
      last_block_column = compptr->width_in_blocks - 1;
583
113k
      for (block_num = cinfo->master->first_MCU_col[ci];
584
3.55M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
3.43M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
3.43M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
3.43M
            block_num < last_block_column) {
590
113k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
113k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
113k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
113k
          DC19 = DC20 = (int)next_block_row[1][0];
594
113k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
113k
        }
596
3.43M
        if (block_num + 1 < last_block_column) {
597
3.21M
          DC05 = (int)prev_prev_block_row[2][0];
598
3.21M
          DC10 = (int)prev_block_row[2][0];
599
3.21M
          DC15 = (int)buffer_ptr[2][0];
600
3.21M
          DC20 = (int)next_block_row[2][0];
601
3.21M
          DC25 = (int)next_next_block_row[2][0];
602
3.21M
        }
603
        /* If DC interpolation is enabled, compute coefficient estimates using
604
         * a Gaussian-like kernel, keeping the averages of the DC values.
605
         *
606
         * If DC interpolation is disabled, compute coefficient estimates using
607
         * an algorithm similar to the one described in Section K.8 of the JPEG
608
         * standard, except applied to a 5x5 window rather than a 3x3 window.
609
         *
610
         * An estimate is applied only if the coefficient is still zero and is
611
         * not known to be fully accurate.
612
         */
613
        /* AC01 */
614
3.43M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
3.37M
          num = Q00 * (change_dc ?
616
3.07M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
3.07M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
3.07M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
3.07M
                 DC21 - DC22 + DC24 + DC25) :
620
3.37M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
3.37M
          if (num >= 0) {
622
2.90M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
2.90M
            if (Al > 0 && pred >= (1 << Al))
624
14.5k
              pred = (1 << Al) - 1;
625
2.90M
          } else {
626
472k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
472k
            if (Al > 0 && pred >= (1 << Al))
628
14.7k
              pred = (1 << Al) - 1;
629
472k
            pred = -pred;
630
472k
          }
631
3.37M
          workspace[1] = (JCOEF)pred;
632
3.37M
        }
633
        /* AC10 */
634
3.43M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
3.40M
          num = Q00 * (change_dc ?
636
3.07M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
3.07M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
3.07M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
3.07M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
3.40M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
3.40M
          if (num >= 0) {
642
2.88M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
2.88M
            if (Al > 0 && pred >= (1 << Al))
644
66.8k
              pred = (1 << Al) - 1;
645
2.88M
          } else {
646
525k
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
525k
            if (Al > 0 && pred >= (1 << Al))
648
61.4k
              pred = (1 << Al) - 1;
649
525k
            pred = -pred;
650
525k
          }
651
3.40M
          workspace[8] = (JCOEF)pred;
652
3.40M
        }
653
        /* AC20 */
654
3.43M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
3.37M
          num = Q00 * (change_dc ?
656
3.07M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
3.07M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
3.37M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
3.37M
          if (num >= 0) {
660
2.85M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
2.85M
            if (Al > 0 && pred >= (1 << Al))
662
22.0k
              pred = (1 << Al) - 1;
663
2.85M
          } else {
664
519k
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
519k
            if (Al > 0 && pred >= (1 << Al))
666
22.4k
              pred = (1 << Al) - 1;
667
519k
            pred = -pred;
668
519k
          }
669
3.37M
          workspace[16] = (JCOEF)pred;
670
3.37M
        }
671
        /* AC11 */
672
3.43M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
3.34M
          num = Q00 * (change_dc ?
674
3.07M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
3.07M
                 9 * DC19 + DC21 - DC25) :
676
3.34M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
270k
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
3.34M
          if (num >= 0) {
679
2.94M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
2.94M
            if (Al > 0 && pred >= (1 << Al))
681
33.2k
              pred = (1 << Al) - 1;
682
2.94M
          } else {
683
400k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
400k
            if (Al > 0 && pred >= (1 << Al))
685
32.5k
              pred = (1 << Al) - 1;
686
400k
            pred = -pred;
687
400k
          }
688
3.34M
          workspace[9] = (JCOEF)pred;
689
3.34M
        }
690
        /* AC02 */
691
3.43M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
3.36M
          num = Q00 * (change_dc ?
693
3.07M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
3.07M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
3.36M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
3.36M
          if (num >= 0) {
697
2.85M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
2.85M
            if (Al > 0 && pred >= (1 << Al))
699
27.6k
              pred = (1 << Al) - 1;
700
2.85M
          } else {
701
517k
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
517k
            if (Al > 0 && pred >= (1 << Al))
703
25.7k
              pred = (1 << Al) - 1;
704
517k
            pred = -pred;
705
517k
          }
706
3.36M
          workspace[2] = (JCOEF)pred;
707
3.36M
        }
708
3.43M
        if (change_dc) {
709
          /* AC03 */
710
3.07M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
3.07M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
3.07M
            if (num >= 0) {
713
2.74M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
2.74M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
2.74M
            } else {
717
333k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
333k
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
333k
              pred = -pred;
721
333k
            }
722
3.07M
            workspace[3] = (JCOEF)pred;
723
3.07M
          }
724
          /* AC12 */
725
3.07M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
3.07M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
3.07M
            if (num >= 0) {
728
2.68M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
2.68M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
2.68M
            } else {
732
391k
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
391k
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
391k
              pred = -pred;
736
391k
            }
737
3.07M
            workspace[10] = (JCOEF)pred;
738
3.07M
          }
739
          /* AC21 */
740
3.07M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
3.07M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
3.07M
            if (num >= 0) {
743
2.69M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
2.69M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
2.69M
            } else {
747
386k
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
386k
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
386k
              pred = -pred;
751
386k
            }
752
3.07M
            workspace[17] = (JCOEF)pred;
753
3.07M
          }
754
          /* AC30 */
755
3.07M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
3.07M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
3.07M
            if (num >= 0) {
758
2.73M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
2.73M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
2.73M
            } else {
762
345k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
345k
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
345k
              pred = -pred;
766
345k
            }
767
3.07M
            workspace[24] = (JCOEF)pred;
768
3.07M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
3.07M
          num = Q00 *
773
3.07M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
3.07M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
3.07M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
3.07M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
3.07M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
3.07M
          if (num >= 0) {
779
2.66M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
2.66M
          } else {
781
415k
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
415k
            pred = -pred;
783
415k
          }
784
3.07M
          workspace[0] = (JCOEF)pred;
785
3.07M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
3.43M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
3.43M
                        output_col);
790
        /* Advance for next column */
791
3.43M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
3.43M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
3.43M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
3.43M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
3.43M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
3.43M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
3.43M
          prev_prev_block_row++, next_next_block_row++;
798
3.43M
        output_col += compptr->_DCT_scaled_size;
799
3.43M
      }
800
113k
      output_ptr += compptr->_DCT_scaled_size;
801
113k
    }
802
113k
  }
803
804
111k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
107k
    return JPEG_ROW_COMPLETED;
806
3.22k
  return JPEG_SCAN_COMPLETED;
807
111k
}
jdcoefct-12.c:decompress_smooth_data
Line
Count
Source
430
391
{
431
391
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
391
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
391
  JDIMENSION block_num, last_block_column;
434
391
  int ci, block_row, block_rows, access_rows, image_block_row,
435
391
    image_block_rows;
436
391
  JBLOCKARRAY buffer;
437
391
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
391
  JBLOCKROW next_block_row, next_next_block_row;
439
391
  _JSAMPARRAY output_ptr;
440
391
  JDIMENSION output_col;
441
391
  jpeg_component_info *compptr;
442
391
  _inverse_DCT_method_ptr inverse_DCT;
443
391
  boolean change_dc;
444
391
  JCOEF *workspace;
445
391
  int *coef_bits;
446
391
  JQUANT_TBL *quanttbl;
447
391
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
391
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
391
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
391
      DC25;
451
391
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
391
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
391
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
391
         !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.56k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
1.17k
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
1.17k
    if (!compptr->component_needed)
478
0
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
1.17k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
582
      block_rows = compptr->v_samp_factor;
482
582
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
591
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
291
      block_rows = compptr->v_samp_factor;
485
291
      access_rows = block_rows * 2; /* this and next iMCU row */
486
300
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
300
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
300
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
300
      access_rows = block_rows; /* this iMCU row only */
491
300
    }
492
    /* Align the virtual buffer for this component. */
493
1.17k
    if (cinfo->output_iMCU_row > 1) {
494
582
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
582
      buffer = (*cinfo->mem->access_virt_barray)
496
582
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
582
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
582
         (JDIMENSION)access_rows, FALSE);
499
582
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
591
    } else if (cinfo->output_iMCU_row > 0) {
501
291
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
291
      buffer = (*cinfo->mem->access_virt_barray)
503
291
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
291
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
291
         (JDIMENSION)access_rows, FALSE);
506
291
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
300
    } else {
508
300
      buffer = (*cinfo->mem->access_virt_barray)
509
300
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
300
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
300
    }
512
    /* Fetch component-dependent info.
513
     * If the current scan is incomplete, then we use the component-dependent
514
     * info from the previous scan.
515
     */
516
1.17k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
0
      coef_bits =
518
0
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
1.17k
    else
520
1.17k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
1.17k
    change_dc =
524
1.17k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
1.17k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
1.17k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
1.17k
    quanttbl = compptr->quant_table;
529
1.17k
    Q00 = quanttbl->quantval[0];
530
1.17k
    Q01 = quanttbl->quantval[Q01_POS];
531
1.17k
    Q10 = quanttbl->quantval[Q10_POS];
532
1.17k
    Q20 = quanttbl->quantval[Q20_POS];
533
1.17k
    Q11 = quanttbl->quantval[Q11_POS];
534
1.17k
    Q02 = quanttbl->quantval[Q02_POS];
535
1.17k
    if (change_dc) {
536
898
      Q03 = quanttbl->quantval[Q03_POS];
537
898
      Q12 = quanttbl->quantval[Q12_POS];
538
898
      Q21 = quanttbl->quantval[Q21_POS];
539
898
      Q30 = quanttbl->quantval[Q30_POS];
540
898
    }
541
1.17k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
1.17k
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
1.17k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
2.34k
    for (block_row = 0; block_row < block_rows; block_row++) {
546
1.17k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
1.17k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
1.17k
      if (image_block_row > 0)
550
873
        prev_block_row =
551
873
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
300
      else
553
300
        prev_block_row = buffer_ptr;
554
555
1.17k
      if (image_block_row > 1)
556
582
        prev_prev_block_row =
557
582
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
591
      else
559
591
        prev_prev_block_row = prev_block_row;
560
561
1.17k
      if (image_block_row < image_block_rows - 1)
562
873
        next_block_row =
563
873
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
300
      else
565
300
        next_block_row = buffer_ptr;
566
567
1.17k
      if (image_block_row < image_block_rows - 2)
568
582
        next_next_block_row =
569
582
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
591
      else
571
591
        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.17k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
1.17k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
1.17k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
1.17k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
1.17k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
1.17k
      output_col = 0;
582
1.17k
      last_block_column = compptr->width_in_blocks - 1;
583
1.17k
      for (block_num = cinfo->master->first_MCU_col[ci];
584
1.75M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
1.75M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
1.75M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
1.75M
            block_num < last_block_column) {
590
1.16k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
1.16k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
1.16k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
1.16k
          DC19 = DC20 = (int)next_block_row[1][0];
594
1.16k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
1.16k
        }
596
1.75M
        if (block_num + 1 < last_block_column) {
597
1.74M
          DC05 = (int)prev_prev_block_row[2][0];
598
1.74M
          DC10 = (int)prev_block_row[2][0];
599
1.74M
          DC15 = (int)buffer_ptr[2][0];
600
1.74M
          DC20 = (int)next_block_row[2][0];
601
1.74M
          DC25 = (int)next_next_block_row[2][0];
602
1.74M
        }
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
1.75M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
1.61M
          num = Q00 * (change_dc ?
616
1.50M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
1.50M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
1.50M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
1.50M
                 DC21 - DC22 + DC24 + DC25) :
620
1.61M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
1.61M
          if (num >= 0) {
622
940k
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
940k
            if (Al > 0 && pred >= (1 << Al))
624
4.84k
              pred = (1 << Al) - 1;
625
940k
          } else {
626
679k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
679k
            if (Al > 0 && pred >= (1 << Al))
628
3.25k
              pred = (1 << Al) - 1;
629
679k
            pred = -pred;
630
679k
          }
631
1.61M
          workspace[1] = (JCOEF)pred;
632
1.61M
        }
633
        /* AC10 */
634
1.75M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
1.62M
          num = Q00 * (change_dc ?
636
1.50M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
1.50M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
1.50M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
1.50M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
1.62M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
1.62M
          if (num >= 0) {
642
811k
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
811k
            if (Al > 0 && pred >= (1 << Al))
644
20.4k
              pred = (1 << Al) - 1;
645
813k
          } else {
646
813k
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
813k
            if (Al > 0 && pred >= (1 << Al))
648
22.1k
              pred = (1 << Al) - 1;
649
813k
            pred = -pred;
650
813k
          }
651
1.62M
          workspace[8] = (JCOEF)pred;
652
1.62M
        }
653
        /* AC20 */
654
1.75M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
1.67M
          num = Q00 * (change_dc ?
656
1.50M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
1.50M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
1.67M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
1.67M
          if (num >= 0) {
660
897k
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
897k
            if (Al > 0 && pred >= (1 << Al))
662
25.1k
              pred = (1 << Al) - 1;
663
897k
          } else {
664
782k
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
782k
            if (Al > 0 && pred >= (1 << Al))
666
21.5k
              pred = (1 << Al) - 1;
667
782k
            pred = -pred;
668
782k
          }
669
1.67M
          workspace[16] = (JCOEF)pred;
670
1.67M
        }
671
        /* AC11 */
672
1.75M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
1.68M
          num = Q00 * (change_dc ?
674
1.50M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
1.50M
                 9 * DC19 + DC21 - DC25) :
676
1.68M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
184k
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
1.68M
          if (num >= 0) {
679
1.13M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
1.13M
            if (Al > 0 && pred >= (1 << Al))
681
9.86k
              pred = (1 << Al) - 1;
682
1.13M
          } else {
683
549k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
549k
            if (Al > 0 && pred >= (1 << Al))
685
9.29k
              pred = (1 << Al) - 1;
686
549k
            pred = -pred;
687
549k
          }
688
1.68M
          workspace[9] = (JCOEF)pred;
689
1.68M
        }
690
        /* AC02 */
691
1.75M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
1.70M
          num = Q00 * (change_dc ?
693
1.50M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
1.50M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
1.70M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
1.70M
          if (num >= 0) {
697
976k
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
976k
            if (Al > 0 && pred >= (1 << Al))
699
3.57k
              pred = (1 << Al) - 1;
700
976k
          } else {
701
729k
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
729k
            if (Al > 0 && pred >= (1 << Al))
703
3.54k
              pred = (1 << Al) - 1;
704
729k
            pred = -pred;
705
729k
          }
706
1.70M
          workspace[2] = (JCOEF)pred;
707
1.70M
        }
708
1.75M
        if (change_dc) {
709
          /* AC03 */
710
1.50M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
1.50M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
1.50M
            if (num >= 0) {
713
907k
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
907k
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
907k
            } else {
717
592k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
592k
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
592k
              pred = -pred;
721
592k
            }
722
1.50M
            workspace[3] = (JCOEF)pred;
723
1.50M
          }
724
          /* AC12 */
725
1.50M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
1.50M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
1.50M
            if (num >= 0) {
728
860k
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
860k
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
860k
            } else {
732
639k
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
639k
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
639k
              pred = -pred;
736
639k
            }
737
1.50M
            workspace[10] = (JCOEF)pred;
738
1.50M
          }
739
          /* AC21 */
740
1.50M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
1.50M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
1.50M
            if (num >= 0) {
743
936k
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
936k
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
936k
            } else {
747
564k
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
564k
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
564k
              pred = -pred;
751
564k
            }
752
1.50M
            workspace[17] = (JCOEF)pred;
753
1.50M
          }
754
          /* AC30 */
755
1.50M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
1.50M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
1.50M
            if (num >= 0) {
758
798k
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
798k
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
798k
            } else {
762
701k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
701k
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
701k
              pred = -pred;
766
701k
            }
767
1.50M
            workspace[24] = (JCOEF)pred;
768
1.50M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
1.50M
          num = Q00 *
773
1.50M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
1.50M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
1.50M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
1.50M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
1.50M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
1.50M
          if (num >= 0) {
779
776k
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
776k
          } else {
781
724k
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
724k
            pred = -pred;
783
724k
          }
784
1.50M
          workspace[0] = (JCOEF)pred;
785
1.50M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
1.75M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
1.75M
                        output_col);
790
        /* Advance for next column */
791
1.75M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
1.75M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
1.75M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
1.75M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
1.75M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
1.75M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
1.75M
          prev_prev_block_row++, next_next_block_row++;
798
1.75M
        output_col += compptr->_DCT_scaled_size;
799
1.75M
      }
800
1.17k
      output_ptr += compptr->_DCT_scaled_size;
801
1.17k
    }
802
1.17k
  }
803
804
391
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
291
    return JPEG_ROW_COMPLETED;
806
100
  return JPEG_SCAN_COMPLETED;
807
391
}
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
54.0k
{
819
54.0k
  my_coef_ptr coef;
820
821
54.0k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
54.0k
  coef = (my_coef_ptr)
825
54.0k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
54.0k
                                sizeof(my_coef_controller));
827
54.0k
  memset(coef, 0, sizeof(my_coef_controller));
828
54.0k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
54.0k
  coef->pub.start_input_pass = start_input_pass;
830
54.0k
  coef->pub.start_output_pass = start_output_pass;
831
54.0k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
54.0k
  coef->coef_bits_latch = NULL;
833
54.0k
#endif
834
835
  /* Create the coefficient buffer. */
836
54.0k
  if (need_full_buffer) {
837
22.0k
#ifdef D_MULTISCAN_FILES_SUPPORTED
838
    /* Allocate a full-image virtual array for each component, */
839
    /* padded to a multiple of samp_factor DCT blocks in each direction. */
840
    /* Note we ask for a pre-zeroed array. */
841
22.0k
    int ci, access_rows;
842
22.0k
    jpeg_component_info *compptr;
843
844
64.6k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
42.5k
         ci++, compptr++) {
846
42.5k
      access_rows = compptr->v_samp_factor;
847
42.5k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
42.5k
      if (cinfo->progressive_mode)
850
28.0k
        access_rows *= 5;
851
42.5k
#endif
852
42.5k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
42.5k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
42.5k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
42.5k
                               (long)compptr->h_samp_factor),
856
42.5k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
42.5k
                               (long)compptr->v_samp_factor),
858
42.5k
         (JDIMENSION)access_rows);
859
42.5k
    }
860
22.0k
    coef->pub.consume_data = consume_data;
861
22.0k
    coef->pub._decompress_data = decompress_data;
862
22.0k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
32.0k
  } else {
867
    /* We only need a single-MCU buffer. */
868
32.0k
    JBLOCKROW buffer;
869
32.0k
    int i;
870
871
32.0k
    buffer = (JBLOCKROW)
872
32.0k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
32.0k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
352k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
320k
      coef->MCU_buffer[i] = buffer + i;
876
320k
    }
877
32.0k
    coef->pub.consume_data = dummy_consume_data;
878
32.0k
    coef->pub._decompress_data = decompress_onepass;
879
32.0k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
32.0k
  }
881
882
  /* Allocate the workspace buffer */
883
54.0k
  coef->workspace = (JCOEF *)
884
54.0k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
54.0k
                                sizeof(JCOEF) * DCTSIZE2);
886
54.0k
}
jinit_d_coef_controller
Line
Count
Source
818
53.9k
{
819
53.9k
  my_coef_ptr coef;
820
821
53.9k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
53.9k
  coef = (my_coef_ptr)
825
53.9k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
53.9k
                                sizeof(my_coef_controller));
827
53.9k
  memset(coef, 0, sizeof(my_coef_controller));
828
53.9k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
53.9k
  coef->pub.start_input_pass = start_input_pass;
830
53.9k
  coef->pub.start_output_pass = start_output_pass;
831
53.9k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
53.9k
  coef->coef_bits_latch = NULL;
833
53.9k
#endif
834
835
  /* Create the coefficient buffer. */
836
53.9k
  if (need_full_buffer) {
837
21.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
21.8k
    int ci, access_rows;
842
21.8k
    jpeg_component_info *compptr;
843
844
63.9k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
42.0k
         ci++, compptr++) {
846
42.0k
      access_rows = compptr->v_samp_factor;
847
42.0k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
42.0k
      if (cinfo->progressive_mode)
850
27.5k
        access_rows *= 5;
851
42.0k
#endif
852
42.0k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
42.0k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
42.0k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
42.0k
                               (long)compptr->h_samp_factor),
856
42.0k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
42.0k
                               (long)compptr->v_samp_factor),
858
42.0k
         (JDIMENSION)access_rows);
859
42.0k
    }
860
21.8k
    coef->pub.consume_data = consume_data;
861
21.8k
    coef->pub._decompress_data = decompress_data;
862
21.8k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
32.0k
  } else {
867
    /* We only need a single-MCU buffer. */
868
32.0k
    JBLOCKROW buffer;
869
32.0k
    int i;
870
871
32.0k
    buffer = (JBLOCKROW)
872
32.0k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
32.0k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
352k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
320k
      coef->MCU_buffer[i] = buffer + i;
876
320k
    }
877
32.0k
    coef->pub.consume_data = dummy_consume_data;
878
32.0k
    coef->pub._decompress_data = decompress_onepass;
879
32.0k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
32.0k
  }
881
882
  /* Allocate the workspace buffer */
883
53.9k
  coef->workspace = (JCOEF *)
884
53.9k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
53.9k
                                sizeof(JCOEF) * DCTSIZE2);
886
53.9k
}
j12init_d_coef_controller
Line
Count
Source
818
171
{
819
171
  my_coef_ptr coef;
820
821
171
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
171
  coef = (my_coef_ptr)
825
171
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
171
                                sizeof(my_coef_controller));
827
171
  memset(coef, 0, sizeof(my_coef_controller));
828
171
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
171
  coef->pub.start_input_pass = start_input_pass;
830
171
  coef->pub.start_output_pass = start_output_pass;
831
171
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
171
  coef->coef_bits_latch = NULL;
833
171
#endif
834
835
  /* Create the coefficient buffer. */
836
171
  if (need_full_buffer) {
837
169
#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
169
    int ci, access_rows;
842
169
    jpeg_component_info *compptr;
843
844
676
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
507
         ci++, compptr++) {
846
507
      access_rows = compptr->v_samp_factor;
847
507
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
507
      if (cinfo->progressive_mode)
850
504
        access_rows *= 5;
851
507
#endif
852
507
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
507
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
507
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
507
                               (long)compptr->h_samp_factor),
856
507
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
507
                               (long)compptr->v_samp_factor),
858
507
         (JDIMENSION)access_rows);
859
507
    }
860
169
    coef->pub.consume_data = consume_data;
861
169
    coef->pub._decompress_data = decompress_data;
862
169
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
169
  } else {
867
    /* We only need a single-MCU buffer. */
868
2
    JBLOCKROW buffer;
869
2
    int i;
870
871
2
    buffer = (JBLOCKROW)
872
2
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
2
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
22
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
20
      coef->MCU_buffer[i] = buffer + i;
876
20
    }
877
2
    coef->pub.consume_data = dummy_consume_data;
878
2
    coef->pub._decompress_data = decompress_onepass;
879
2
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
2
  }
881
882
  /* Allocate the workspace buffer */
883
171
  coef->workspace = (JCOEF *)
884
171
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
171
                                sizeof(JCOEF) * DCTSIZE2);
886
171
}