Coverage Report

Created: 2025-07-09 06:48

/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
49.7k
{
48
49.7k
  cinfo->input_iMCU_row = 0;
49
49.7k
  start_iMCU_row(cinfo);
50
49.7k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
47
48.7k
{
48
48.7k
  cinfo->input_iMCU_row = 0;
49
48.7k
  start_iMCU_row(cinfo);
50
48.7k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
47
984
{
48
984
  cinfo->input_iMCU_row = 0;
49
984
  start_iMCU_row(cinfo);
50
984
}
51
52
53
/*
54
 * Initialize for an output processing pass.
55
 */
56
57
METHODDEF(void)
58
start_output_pass(j_decompress_ptr cinfo)
59
34.4k
{
60
34.4k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
34.4k
  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
34.4k
  if (coef->pub.coef_arrays != NULL) {
65
13.4k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
2.56k
      coef->pub._decompress_data = decompress_smooth_data;
67
10.8k
    else
68
10.8k
      coef->pub._decompress_data = decompress_data;
69
13.4k
  }
70
34.4k
#endif
71
34.4k
  cinfo->output_iMCU_row = 0;
72
34.4k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
59
34.3k
{
60
34.3k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
34.3k
  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
34.3k
  if (coef->pub.coef_arrays != NULL) {
65
13.2k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
2.45k
      coef->pub._decompress_data = decompress_smooth_data;
67
10.8k
    else
68
10.8k
      coef->pub._decompress_data = decompress_data;
69
13.2k
  }
70
34.3k
#endif
71
34.3k
  cinfo->output_iMCU_row = 0;
72
34.3k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
59
151
{
60
151
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
151
  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
151
  if (coef->pub.coef_arrays != NULL) {
65
147
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
104
      coef->pub._decompress_data = decompress_smooth_data;
67
43
    else
68
43
      coef->pub._decompress_data = decompress_data;
69
147
  }
70
151
#endif
71
151
  cinfo->output_iMCU_row = 0;
72
151
}
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.72M
{
88
1.72M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
1.72M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
1.72M
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
1.72M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
1.72M
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
1.72M
  _JSAMPARRAY output_ptr;
94
1.72M
  JDIMENSION start_col, output_col;
95
1.72M
  jpeg_component_info *compptr;
96
1.72M
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
3.45M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
1.72M
       yoffset++) {
101
33.0M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
31.2M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
31.2M
      jzero_far((void *)coef->MCU_buffer[0],
105
31.2M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
31.2M
      if (!cinfo->entropy->insufficient_data)
107
7.19M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
31.2M
      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
31.2M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
31.2M
          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
31.2M
        blkn = 0;               /* index of current DCT block within MCU */
126
63.4M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
32.1M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
32.1M
          if (!compptr->component_needed) {
130
0
            blkn += compptr->MCU_blocks;
131
0
            continue;
132
0
          }
133
32.1M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
32.1M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
30.2M
                         compptr->MCU_width : compptr->last_col_width;
136
32.1M
          output_ptr = output_buf[compptr->component_index] +
137
32.1M
                       yoffset * compptr->_DCT_scaled_size;
138
32.1M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
32.1M
                      compptr->MCU_sample_width;
140
64.6M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
32.5M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
32.5M
                yoffset + yindex < compptr->last_row_height) {
143
32.5M
              output_col = start_col;
144
65.7M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
33.2M
                (*inverse_DCT) (cinfo, compptr,
146
33.2M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
33.2M
                                output_ptr, output_col);
148
33.2M
                output_col += compptr->_DCT_scaled_size;
149
33.2M
              }
150
32.5M
            }
151
32.5M
            blkn += compptr->MCU_width;
152
32.5M
            output_ptr += compptr->_DCT_scaled_size;
153
32.5M
          }
154
32.1M
        }
155
31.2M
      }
156
31.2M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
1.72M
    coef->MCU_ctr = 0;
159
1.72M
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
1.72M
  cinfo->output_iMCU_row++;
162
1.72M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
1.70M
    start_iMCU_row(cinfo);
164
1.70M
    return JPEG_ROW_COMPLETED;
165
1.70M
  }
166
  /* Completed the scan */
167
26.1k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
26.1k
  return JPEG_SCAN_COMPLETED;
169
1.72M
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
87
1.70M
{
88
1.70M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
1.70M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
1.70M
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
1.70M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
1.70M
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
1.70M
  _JSAMPARRAY output_ptr;
94
1.70M
  JDIMENSION start_col, output_col;
95
1.70M
  jpeg_component_info *compptr;
96
1.70M
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
3.40M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
1.70M
       yoffset++) {
101
32.9M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
31.2M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
31.2M
      jzero_far((void *)coef->MCU_buffer[0],
105
31.2M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
31.2M
      if (!cinfo->entropy->insufficient_data)
107
7.16M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
31.2M
      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
31.2M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
31.2M
          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
31.2M
        blkn = 0;               /* index of current DCT block within MCU */
126
63.3M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
32.0M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
32.0M
          if (!compptr->component_needed) {
130
0
            blkn += compptr->MCU_blocks;
131
0
            continue;
132
0
          }
133
32.0M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
32.0M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
30.2M
                         compptr->MCU_width : compptr->last_col_width;
136
32.0M
          output_ptr = output_buf[compptr->component_index] +
137
32.0M
                       yoffset * compptr->_DCT_scaled_size;
138
32.0M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
32.0M
                      compptr->MCU_sample_width;
140
64.5M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
32.4M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
32.4M
                yoffset + yindex < compptr->last_row_height) {
143
32.4M
              output_col = start_col;
144
65.6M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
33.1M
                (*inverse_DCT) (cinfo, compptr,
146
33.1M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
33.1M
                                output_ptr, output_col);
148
33.1M
                output_col += compptr->_DCT_scaled_size;
149
33.1M
              }
150
32.4M
            }
151
32.4M
            blkn += compptr->MCU_width;
152
32.4M
            output_ptr += compptr->_DCT_scaled_size;
153
32.4M
          }
154
32.0M
        }
155
31.2M
      }
156
31.2M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
1.70M
    coef->MCU_ctr = 0;
159
1.70M
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
1.70M
  cinfo->output_iMCU_row++;
162
1.70M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
1.67M
    start_iMCU_row(cinfo);
164
1.67M
    return JPEG_ROW_COMPLETED;
165
1.67M
  }
166
  /* Completed the scan */
167
26.1k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
26.1k
  return JPEG_SCAN_COMPLETED;
169
1.70M
}
jdcoefct-12.c:decompress_onepass
Line
Count
Source
87
24.3k
{
88
24.3k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
24.3k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
24.3k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
24.3k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
24.3k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
24.3k
  _JSAMPARRAY output_ptr;
94
24.3k
  JDIMENSION start_col, output_col;
95
24.3k
  jpeg_component_info *compptr;
96
24.3k
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
48.7k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
24.3k
       yoffset++) {
101
48.7k
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
24.3k
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
24.3k
      jzero_far((void *)coef->MCU_buffer[0],
105
24.3k
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
24.3k
      if (!cinfo->entropy->insufficient_data)
107
24.3k
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
24.3k
      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
24.3k
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
24.3k
          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
24.3k
        blkn = 0;               /* index of current DCT block within MCU */
126
97.4k
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
73.1k
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
73.1k
          if (!compptr->component_needed) {
130
0
            blkn += compptr->MCU_blocks;
131
0
            continue;
132
0
          }
133
73.1k
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
73.1k
          useful_width = (MCU_col_num < last_MCU_col) ?
135
73.1k
                         compptr->MCU_width : compptr->last_col_width;
136
73.1k
          output_ptr = output_buf[compptr->component_index] +
137
73.1k
                       yoffset * compptr->_DCT_scaled_size;
138
73.1k
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
73.1k
                      compptr->MCU_sample_width;
140
146k
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
73.1k
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
73.1k
                yoffset + yindex < compptr->last_row_height) {
143
73.1k
              output_col = start_col;
144
146k
              for (xindex = 0; xindex < useful_width; xindex++) {
145
73.1k
                (*inverse_DCT) (cinfo, compptr,
146
73.1k
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
73.1k
                                output_ptr, output_col);
148
73.1k
                output_col += compptr->_DCT_scaled_size;
149
73.1k
              }
150
73.1k
            }
151
73.1k
            blkn += compptr->MCU_width;
152
73.1k
            output_ptr += compptr->_DCT_scaled_size;
153
73.1k
          }
154
73.1k
        }
155
24.3k
      }
156
24.3k
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
24.3k
    coef->MCU_ctr = 0;
159
24.3k
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
24.3k
  cinfo->output_iMCU_row++;
162
24.3k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
24.3k
    start_iMCU_row(cinfo);
164
24.3k
    return JPEG_ROW_COMPLETED;
165
24.3k
  }
166
  /* Completed the scan */
167
0
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
0
  return JPEG_SCAN_COMPLETED;
169
24.3k
}
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
3.25M
{
195
3.25M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
3.25M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
3.25M
  int blkn, ci, xindex, yindex, yoffset;
198
3.25M
  JDIMENSION start_col;
199
3.25M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
3.25M
  JBLOCKROW buffer_ptr;
201
3.25M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
6.63M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
3.38M
    compptr = cinfo->cur_comp_info[ci];
206
3.38M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
3.38M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
3.38M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
3.38M
       (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
3.38M
  }
215
216
  /* Loop to process one whole iMCU row */
217
6.53M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
3.28M
       yoffset++) {
219
27.3M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
24.0M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
24.0M
      blkn = 0;                 /* index of current DCT block within MCU */
223
49.3M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
25.2M
        compptr = cinfo->cur_comp_info[ci];
225
25.2M
        start_col = MCU_col_num * compptr->MCU_width;
226
50.7M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
25.4M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
51.2M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
25.7M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
25.7M
          }
231
25.4M
        }
232
25.2M
      }
233
24.0M
      if (!cinfo->entropy->insufficient_data)
234
3.75M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
24.0M
      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
24.0M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
3.28M
    coef->MCU_ctr = 0;
245
3.28M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
3.25M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
3.22M
    start_iMCU_row(cinfo);
249
3.22M
    return JPEG_ROW_COMPLETED;
250
3.22M
  }
251
  /* Completed the scan */
252
28.6k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
28.6k
  return JPEG_SCAN_COMPLETED;
254
3.25M
}
jdcoefct-8.c:consume_data
Line
Count
Source
194
3.17M
{
195
3.17M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
3.17M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
3.17M
  int blkn, ci, xindex, yindex, yoffset;
198
3.17M
  JDIMENSION start_col;
199
3.17M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
3.17M
  JBLOCKROW buffer_ptr;
201
3.17M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
6.41M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
3.23M
    compptr = cinfo->cur_comp_info[ci];
206
3.23M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
3.23M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
3.23M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
3.23M
       (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
3.23M
  }
215
216
  /* Loop to process one whole iMCU row */
217
6.37M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
3.20M
       yoffset++) {
219
26.7M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
23.5M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
23.5M
      blkn = 0;                 /* index of current DCT block within MCU */
223
47.5M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
24.0M
        compptr = cinfo->cur_comp_info[ci];
225
24.0M
        start_col = MCU_col_num * compptr->MCU_width;
226
48.2M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
24.1M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
48.7M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
24.5M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
24.5M
          }
231
24.1M
        }
232
24.0M
      }
233
23.5M
      if (!cinfo->entropy->insufficient_data)
234
3.27M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
23.5M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
237
        /* Suspension forced; update state counters and exit */
238
0
        coef->MCU_vert_offset = yoffset;
239
0
        coef->MCU_ctr = MCU_col_num;
240
0
        return JPEG_SUSPENDED;
241
0
      }
242
23.5M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
3.20M
    coef->MCU_ctr = 0;
245
3.20M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
3.17M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
3.14M
    start_iMCU_row(cinfo);
249
3.14M
    return JPEG_ROW_COMPLETED;
250
3.14M
  }
251
  /* Completed the scan */
252
27.7k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
27.7k
  return JPEG_SCAN_COMPLETED;
254
3.17M
}
jdcoefct-12.c:consume_data
Line
Count
Source
194
82.0k
{
195
82.0k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
82.0k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
82.0k
  int blkn, ci, xindex, yindex, yoffset;
198
82.0k
  JDIMENSION start_col;
199
82.0k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
82.0k
  JBLOCKROW buffer_ptr;
201
82.0k
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
226k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
144k
    compptr = cinfo->cur_comp_info[ci];
206
144k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
144k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
144k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
144k
       (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
144k
  }
215
216
  /* Loop to process one whole iMCU row */
217
164k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
82.0k
       yoffset++) {
219
620k
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
538k
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
538k
      blkn = 0;                 /* index of current DCT block within MCU */
223
1.78M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
1.24M
        compptr = cinfo->cur_comp_info[ci];
225
1.24M
        start_col = MCU_col_num * compptr->MCU_width;
226
2.48M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
1.24M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
2.48M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
1.24M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
1.24M
          }
231
1.24M
        }
232
1.24M
      }
233
538k
      if (!cinfo->entropy->insufficient_data)
234
478k
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
538k
      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
538k
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
82.0k
    coef->MCU_ctr = 0;
245
82.0k
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
82.0k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
81.0k
    start_iMCU_row(cinfo);
249
81.0k
    return JPEG_ROW_COMPLETED;
250
81.0k
  }
251
  /* Completed the scan */
252
979
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
979
  return JPEG_SCAN_COMPLETED;
254
82.0k
}
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
974k
{
268
974k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
974k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
974k
  JDIMENSION block_num;
271
974k
  int ci, block_row, block_rows;
272
974k
  JBLOCKARRAY buffer;
273
974k
  JBLOCKROW buffer_ptr;
274
974k
  _JSAMPARRAY output_ptr;
275
974k
  JDIMENSION output_col;
276
974k
  jpeg_component_info *compptr;
277
974k
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
974k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
974k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
974k
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
283
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
284
0
      return JPEG_SUSPENDED;
285
0
  }
286
287
  /* OK, output from the virtual arrays. */
288
2.03M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
1.05M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
1.05M
    if (!compptr->component_needed)
292
0
      continue;
293
    /* Align the virtual buffer for this component. */
294
1.05M
    buffer = (*cinfo->mem->access_virt_barray)
295
1.05M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
1.05M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
1.05M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
1.05M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
1.03M
      block_rows = compptr->v_samp_factor;
301
23.2k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
23.2k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
23.2k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
23.2k
    }
306
1.05M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
1.05M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
2.14M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
1.08M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
1.08M
      output_col = 0;
312
1.08M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
8.75M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
7.67M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
7.67M
                        output_col);
316
7.67M
        buffer_ptr++;
317
7.67M
        output_col += compptr->_DCT_scaled_size;
318
7.67M
      }
319
1.08M
      output_ptr += compptr->_DCT_scaled_size;
320
1.08M
    }
321
1.05M
  }
322
323
974k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
963k
    return JPEG_ROW_COMPLETED;
325
10.7k
  return JPEG_SCAN_COMPLETED;
326
974k
}
jdcoefct-8.c:decompress_data
Line
Count
Source
267
974k
{
268
974k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
974k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
974k
  JDIMENSION block_num;
271
974k
  int ci, block_row, block_rows;
272
974k
  JBLOCKARRAY buffer;
273
974k
  JBLOCKROW buffer_ptr;
274
974k
  _JSAMPARRAY output_ptr;
275
974k
  JDIMENSION output_col;
276
974k
  jpeg_component_info *compptr;
277
974k
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
974k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
974k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
974k
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
283
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
284
0
      return JPEG_SUSPENDED;
285
0
  }
286
287
  /* OK, output from the virtual arrays. */
288
2.03M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
1.05M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
1.05M
    if (!compptr->component_needed)
292
0
      continue;
293
    /* Align the virtual buffer for this component. */
294
1.05M
    buffer = (*cinfo->mem->access_virt_barray)
295
1.05M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
1.05M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
1.05M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
1.05M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
1.03M
      block_rows = compptr->v_samp_factor;
301
23.1k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
23.1k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
23.1k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
23.1k
    }
306
1.05M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
1.05M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
2.14M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
1.08M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
1.08M
      output_col = 0;
312
1.08M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
8.70M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
7.62M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
7.62M
                        output_col);
316
7.62M
        buffer_ptr++;
317
7.62M
        output_col += compptr->_DCT_scaled_size;
318
7.62M
      }
319
1.08M
      output_ptr += compptr->_DCT_scaled_size;
320
1.08M
    }
321
1.05M
  }
322
323
974k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
963k
    return JPEG_ROW_COMPLETED;
325
10.7k
  return JPEG_SCAN_COMPLETED;
326
974k
}
jdcoefct-12.c:decompress_data
Line
Count
Source
267
91
{
268
91
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
91
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
91
  JDIMENSION block_num;
271
91
  int ci, block_row, block_rows;
272
91
  JBLOCKARRAY buffer;
273
91
  JBLOCKROW buffer_ptr;
274
91
  _JSAMPARRAY output_ptr;
275
91
  JDIMENSION output_col;
276
91
  jpeg_component_info *compptr;
277
91
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
91
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
91
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
91
          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
364
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
273
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
273
    if (!compptr->component_needed)
292
0
      continue;
293
    /* Align the virtual buffer for this component. */
294
273
    buffer = (*cinfo->mem->access_virt_barray)
295
273
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
273
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
273
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
273
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
222
      block_rows = compptr->v_samp_factor;
301
51
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
51
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
51
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
51
    }
306
273
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
273
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
546
    for (block_row = 0; block_row < block_rows; block_row++) {
310
273
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
273
      output_col = 0;
312
273
      for (block_num = cinfo->master->first_MCU_col[ci];
313
48.0k
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
47.8k
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
47.8k
                        output_col);
316
47.8k
        buffer_ptr++;
317
47.8k
        output_col += compptr->_DCT_scaled_size;
318
47.8k
      }
319
273
      output_ptr += compptr->_DCT_scaled_size;
320
273
    }
321
273
  }
322
323
91
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
74
    return JPEG_ROW_COMPLETED;
325
17
  return JPEG_SCAN_COMPLETED;
326
91
}
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
95.9k
#define Q01_POS  1
342
95.5k
#define Q10_POS  8
343
95.1k
#define Q20_POS  16
344
94.8k
#define Q11_POS  9
345
94.5k
#define Q02_POS  2
346
84.1k
#define Q03_POS  3
347
83.2k
#define Q12_POS  10
348
82.7k
#define Q21_POS  17
349
82.4k
#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
13.4k
{
362
13.4k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
13.4k
  boolean smoothing_useful = FALSE;
364
13.4k
  int ci, coefi;
365
13.4k
  jpeg_component_info *compptr;
366
13.4k
  JQUANT_TBL *qtable;
367
13.4k
  int *coef_bits, *prev_coef_bits;
368
13.4k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
13.4k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
4.19k
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
9.22k
  if (coef->coef_bits_latch == NULL)
375
9.22k
    coef->coef_bits_latch = (int *)
376
9.22k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
9.22k
                                  cinfo->num_components * 2 *
378
9.22k
                                  (SAVED_COEFS * sizeof(int)));
379
9.22k
  coef_bits_latch = coef->coef_bits_latch;
380
9.22k
  prev_coef_bits_latch =
381
9.22k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
13.4k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
10.5k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
10.5k
    if ((qtable = compptr->quant_table) == NULL)
387
1.04k
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
9.54k
    if (qtable->quantval[0] == 0 ||
390
9.54k
        qtable->quantval[Q01_POS] == 0 ||
391
9.54k
        qtable->quantval[Q10_POS] == 0 ||
392
9.54k
        qtable->quantval[Q20_POS] == 0 ||
393
9.54k
        qtable->quantval[Q11_POS] == 0 ||
394
9.54k
        qtable->quantval[Q02_POS] == 0 ||
395
9.54k
        qtable->quantval[Q03_POS] == 0 ||
396
9.54k
        qtable->quantval[Q12_POS] == 0 ||
397
9.54k
        qtable->quantval[Q21_POS] == 0 ||
398
9.54k
        qtable->quantval[Q30_POS] == 0)
399
4.50k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
5.03k
    coef_bits = cinfo->coef_bits[ci];
402
5.03k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
5.03k
    if (coef_bits[0] < 0)
404
798
      return FALSE;
405
4.23k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
42.3k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
38.1k
      if (cinfo->input_scan_number > 1)
409
20.1k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
17.9k
      else
411
17.9k
        prev_coef_bits_latch[coefi] = -1;
412
38.1k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
38.1k
      if (coef_bits[coefi] != 0)
414
32.3k
        smoothing_useful = TRUE;
415
38.1k
    }
416
4.23k
    coef_bits_latch += SAVED_COEFS;
417
4.23k
    prev_coef_bits_latch += SAVED_COEFS;
418
4.23k
  }
419
420
2.87k
  return smoothing_useful;
421
9.22k
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
361
13.2k
{
362
13.2k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
13.2k
  boolean smoothing_useful = FALSE;
364
13.2k
  int ci, coefi;
365
13.2k
  jpeg_component_info *compptr;
366
13.2k
  JQUANT_TBL *qtable;
367
13.2k
  int *coef_bits, *prev_coef_bits;
368
13.2k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
13.2k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
4.18k
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
9.07k
  if (coef->coef_bits_latch == NULL)
375
9.07k
    coef->coef_bits_latch = (int *)
376
9.07k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
9.07k
                                  cinfo->num_components * 2 *
378
9.07k
                                  (SAVED_COEFS * sizeof(int)));
379
9.07k
  coef_bits_latch = coef->coef_bits_latch;
380
9.07k
  prev_coef_bits_latch =
381
9.07k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
12.9k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
10.2k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
10.2k
    if ((qtable = compptr->quant_table) == NULL)
387
1.03k
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
9.18k
    if (qtable->quantval[0] == 0 ||
390
9.18k
        qtable->quantval[Q01_POS] == 0 ||
391
9.18k
        qtable->quantval[Q10_POS] == 0 ||
392
9.18k
        qtable->quantval[Q20_POS] == 0 ||
393
9.18k
        qtable->quantval[Q11_POS] == 0 ||
394
9.18k
        qtable->quantval[Q02_POS] == 0 ||
395
9.18k
        qtable->quantval[Q03_POS] == 0 ||
396
9.18k
        qtable->quantval[Q12_POS] == 0 ||
397
9.18k
        qtable->quantval[Q21_POS] == 0 ||
398
9.18k
        qtable->quantval[Q30_POS] == 0)
399
4.47k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
4.71k
    coef_bits = cinfo->coef_bits[ci];
402
4.71k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
4.71k
    if (coef_bits[0] < 0)
404
797
      return FALSE;
405
3.91k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
39.1k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
35.2k
      if (cinfo->input_scan_number > 1)
409
18.2k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
17.0k
      else
411
17.0k
        prev_coef_bits_latch[coefi] = -1;
412
35.2k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
35.2k
      if (coef_bits[coefi] != 0)
414
29.6k
        smoothing_useful = TRUE;
415
35.2k
    }
416
3.91k
    coef_bits_latch += SAVED_COEFS;
417
3.91k
    prev_coef_bits_latch += SAVED_COEFS;
418
3.91k
  }
419
420
2.77k
  return smoothing_useful;
421
9.07k
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
361
147
{
362
147
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
147
  boolean smoothing_useful = FALSE;
364
147
  int ci, coefi;
365
147
  jpeg_component_info *compptr;
366
147
  JQUANT_TBL *qtable;
367
147
  int *coef_bits, *prev_coef_bits;
368
147
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
147
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
1
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
146
  if (coef->coef_bits_latch == NULL)
375
146
    coef->coef_bits_latch = (int *)
376
146
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
146
                                  cinfo->num_components * 2 *
378
146
                                  (SAVED_COEFS * sizeof(int)));
379
146
  coef_bits_latch = coef->coef_bits_latch;
380
146
  prev_coef_bits_latch =
381
146
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
466
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
361
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
361
    if ((qtable = compptr->quant_table) == NULL)
387
3
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
358
    if (qtable->quantval[0] == 0 ||
390
358
        qtable->quantval[Q01_POS] == 0 ||
391
358
        qtable->quantval[Q10_POS] == 0 ||
392
358
        qtable->quantval[Q20_POS] == 0 ||
393
358
        qtable->quantval[Q11_POS] == 0 ||
394
358
        qtable->quantval[Q02_POS] == 0 ||
395
358
        qtable->quantval[Q03_POS] == 0 ||
396
358
        qtable->quantval[Q12_POS] == 0 ||
397
358
        qtable->quantval[Q21_POS] == 0 ||
398
358
        qtable->quantval[Q30_POS] == 0)
399
37
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
321
    coef_bits = cinfo->coef_bits[ci];
402
321
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
321
    if (coef_bits[0] < 0)
404
1
      return FALSE;
405
320
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
3.20k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
2.88k
      if (cinfo->input_scan_number > 1)
409
1.93k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
945
      else
411
945
        prev_coef_bits_latch[coefi] = -1;
412
2.88k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
2.88k
      if (coef_bits[coefi] != 0)
414
2.72k
        smoothing_useful = TRUE;
415
2.88k
    }
416
320
    coef_bits_latch += SAVED_COEFS;
417
320
    prev_coef_bits_latch += SAVED_COEFS;
418
320
  }
419
420
105
  return smoothing_useful;
421
146
}
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
81.8k
{
431
81.8k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
81.8k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
81.8k
  JDIMENSION block_num, last_block_column;
434
81.8k
  int ci, block_row, block_rows, access_rows, image_block_row,
435
81.8k
    image_block_rows;
436
81.8k
  JBLOCKARRAY buffer;
437
81.8k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
81.8k
  JBLOCKROW next_block_row, next_next_block_row;
439
81.8k
  _JSAMPARRAY output_ptr;
440
81.8k
  JDIMENSION output_col;
441
81.8k
  jpeg_component_info *compptr;
442
81.8k
  _inverse_DCT_method_ptr inverse_DCT;
443
81.8k
  boolean change_dc;
444
81.8k
  JCOEF *workspace;
445
81.8k
  int *coef_bits;
446
81.8k
  JQUANT_TBL *quanttbl;
447
81.8k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
81.8k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
81.8k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
81.8k
      DC25;
451
81.8k
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
81.8k
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
81.8k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
81.8k
         !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
168k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
86.7k
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
86.7k
    if (!compptr->component_needed)
478
0
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
86.7k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
81.0k
      block_rows = compptr->v_samp_factor;
482
81.0k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
81.0k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
2.86k
      block_rows = compptr->v_samp_factor;
485
2.86k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
2.86k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
2.86k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
2.86k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
2.86k
      access_rows = block_rows; /* this iMCU row only */
491
2.86k
    }
492
    /* Align the virtual buffer for this component. */
493
86.7k
    if (cinfo->output_iMCU_row > 1) {
494
81.0k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
81.0k
      buffer = (*cinfo->mem->access_virt_barray)
496
81.0k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
81.0k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
81.0k
         (JDIMENSION)access_rows, FALSE);
499
81.0k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
81.0k
    } else if (cinfo->output_iMCU_row > 0) {
501
2.86k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
2.86k
      buffer = (*cinfo->mem->access_virt_barray)
503
2.86k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
2.86k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
2.86k
         (JDIMENSION)access_rows, FALSE);
506
2.86k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
2.87k
    } else {
508
2.87k
      buffer = (*cinfo->mem->access_virt_barray)
509
2.87k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
2.87k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
2.87k
    }
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
86.7k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
49.7k
      coef_bits =
518
49.7k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
37.0k
    else
520
37.0k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
86.7k
    change_dc =
524
86.7k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
86.7k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
86.7k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
86.7k
    quanttbl = compptr->quant_table;
529
86.7k
    Q00 = quanttbl->quantval[0];
530
86.7k
    Q01 = quanttbl->quantval[Q01_POS];
531
86.7k
    Q10 = quanttbl->quantval[Q10_POS];
532
86.7k
    Q20 = quanttbl->quantval[Q20_POS];
533
86.7k
    Q11 = quanttbl->quantval[Q11_POS];
534
86.7k
    Q02 = quanttbl->quantval[Q02_POS];
535
86.7k
    if (change_dc) {
536
77.1k
      Q03 = quanttbl->quantval[Q03_POS];
537
77.1k
      Q12 = quanttbl->quantval[Q12_POS];
538
77.1k
      Q21 = quanttbl->quantval[Q21_POS];
539
77.1k
      Q30 = quanttbl->quantval[Q30_POS];
540
77.1k
    }
541
86.7k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
86.7k
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
86.7k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
173k
    for (block_row = 0; block_row < block_rows; block_row++) {
546
86.7k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
86.7k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
86.7k
      if (image_block_row > 0)
550
83.8k
        prev_block_row =
551
83.8k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
2.87k
      else
553
2.87k
        prev_block_row = buffer_ptr;
554
555
86.7k
      if (image_block_row > 1)
556
81.0k
        prev_prev_block_row =
557
81.0k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
5.73k
      else
559
5.73k
        prev_prev_block_row = prev_block_row;
560
561
86.7k
      if (image_block_row < image_block_rows - 1)
562
83.8k
        next_block_row =
563
83.8k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
2.86k
      else
565
2.86k
        next_block_row = buffer_ptr;
566
567
86.7k
      if (image_block_row < image_block_rows - 2)
568
81.0k
        next_next_block_row =
569
81.0k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
5.72k
      else
571
5.72k
        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
86.7k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
86.7k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
86.7k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
86.7k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
86.7k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
86.7k
      output_col = 0;
582
86.7k
      last_block_column = compptr->width_in_blocks - 1;
583
86.7k
      for (block_num = cinfo->master->first_MCU_col[ci];
584
4.90M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
4.82M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
4.82M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
4.82M
            block_num < last_block_column) {
590
82.6k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
82.6k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
82.6k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
82.6k
          DC19 = DC20 = (int)next_block_row[1][0];
594
82.6k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
82.6k
        }
596
4.82M
        if (block_num + 1 < last_block_column) {
597
4.65M
          DC05 = (int)prev_prev_block_row[2][0];
598
4.65M
          DC10 = (int)prev_block_row[2][0];
599
4.65M
          DC15 = (int)buffer_ptr[2][0];
600
4.65M
          DC20 = (int)next_block_row[2][0];
601
4.65M
          DC25 = (int)next_next_block_row[2][0];
602
4.65M
        }
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
4.82M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
4.74M
          num = Q00 * (change_dc ?
616
4.55M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
4.55M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
4.55M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
4.55M
                 DC21 - DC22 + DC24 + DC25) :
620
4.74M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
4.74M
          if (num >= 0) {
622
4.03M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
4.03M
            if (Al > 0 && pred >= (1 << Al))
624
8.75k
              pred = (1 << Al) - 1;
625
4.03M
          } else {
626
709k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
709k
            if (Al > 0 && pred >= (1 << Al))
628
8.62k
              pred = (1 << Al) - 1;
629
709k
            pred = -pred;
630
709k
          }
631
4.74M
          workspace[1] = (JCOEF)pred;
632
4.74M
        }
633
        /* AC10 */
634
4.82M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
4.78M
          num = Q00 * (change_dc ?
636
4.55M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
4.55M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
4.55M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
4.55M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
4.78M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
4.78M
          if (num >= 0) {
642
4.02M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
4.02M
            if (Al > 0 && pred >= (1 << Al))
644
78.5k
              pred = (1 << Al) - 1;
645
4.02M
          } else {
646
753k
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
753k
            if (Al > 0 && pred >= (1 << Al))
648
25.2k
              pred = (1 << Al) - 1;
649
753k
            pred = -pred;
650
753k
          }
651
4.78M
          workspace[8] = (JCOEF)pred;
652
4.78M
        }
653
        /* AC20 */
654
4.82M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
4.74M
          num = Q00 * (change_dc ?
656
4.55M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
4.55M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
4.74M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
4.74M
          if (num >= 0) {
660
4.02M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
4.02M
            if (Al > 0 && pred >= (1 << Al))
662
21.7k
              pred = (1 << Al) - 1;
663
4.02M
          } else {
664
723k
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
723k
            if (Al > 0 && pred >= (1 << Al))
666
22.3k
              pred = (1 << Al) - 1;
667
723k
            pred = -pred;
668
723k
          }
669
4.74M
          workspace[16] = (JCOEF)pred;
670
4.74M
        }
671
        /* AC11 */
672
4.82M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
4.78M
          num = Q00 * (change_dc ?
674
4.55M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
4.55M
                 9 * DC19 + DC21 - DC25) :
676
4.78M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
224k
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
4.78M
          if (num >= 0) {
679
4.21M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
4.21M
            if (Al > 0 && pred >= (1 << Al))
681
19.1k
              pred = (1 << Al) - 1;
682
4.21M
          } else {
683
562k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
562k
            if (Al > 0 && pred >= (1 << Al))
685
18.9k
              pred = (1 << Al) - 1;
686
562k
            pred = -pred;
687
562k
          }
688
4.78M
          workspace[9] = (JCOEF)pred;
689
4.78M
        }
690
        /* AC02 */
691
4.82M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
4.80M
          num = Q00 * (change_dc ?
693
4.55M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
4.55M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
4.80M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
4.80M
          if (num >= 0) {
697
4.09M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
4.09M
            if (Al > 0 && pred >= (1 << Al))
699
16.7k
              pred = (1 << Al) - 1;
700
4.09M
          } else {
701
704k
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
704k
            if (Al > 0 && pred >= (1 << Al))
703
16.3k
              pred = (1 << Al) - 1;
704
704k
            pred = -pred;
705
704k
          }
706
4.80M
          workspace[2] = (JCOEF)pred;
707
4.80M
        }
708
4.82M
        if (change_dc) {
709
          /* AC03 */
710
4.55M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
4.55M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
4.55M
            if (num >= 0) {
713
3.97M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
3.97M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
3.97M
            } else {
717
584k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
584k
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
584k
              pred = -pred;
721
584k
            }
722
4.55M
            workspace[3] = (JCOEF)pred;
723
4.55M
          }
724
          /* AC12 */
725
4.55M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
4.55M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
4.55M
            if (num >= 0) {
728
3.91M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
3.91M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
3.91M
            } else {
732
638k
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
638k
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
638k
              pred = -pred;
736
638k
            }
737
4.55M
            workspace[10] = (JCOEF)pred;
738
4.55M
          }
739
          /* AC21 */
740
4.55M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
4.55M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
4.55M
            if (num >= 0) {
743
4.02M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
4.02M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
4.02M
            } else {
747
529k
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
529k
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
529k
              pred = -pred;
751
529k
            }
752
4.55M
            workspace[17] = (JCOEF)pred;
753
4.55M
          }
754
          /* AC30 */
755
4.55M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
4.55M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
4.55M
            if (num >= 0) {
758
3.93M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
3.93M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
3.93M
            } else {
762
622k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
622k
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
622k
              pred = -pred;
766
622k
            }
767
4.55M
            workspace[24] = (JCOEF)pred;
768
4.55M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
4.55M
          num = Q00 *
773
4.55M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
4.55M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
4.55M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
4.55M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
4.55M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
4.55M
          if (num >= 0) {
779
3.87M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
3.87M
          } else {
781
686k
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
686k
            pred = -pred;
783
686k
          }
784
4.55M
          workspace[0] = (JCOEF)pred;
785
4.55M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
4.82M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
4.82M
                        output_col);
790
        /* Advance for next column */
791
4.82M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
4.82M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
4.82M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
4.82M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
4.82M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
4.82M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
4.82M
          prev_prev_block_row++, next_next_block_row++;
798
4.82M
        output_col += compptr->_DCT_scaled_size;
799
4.82M
      }
800
86.7k
      output_ptr += compptr->_DCT_scaled_size;
801
86.7k
    }
802
86.7k
  }
803
804
81.8k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
79.3k
    return JPEG_ROW_COMPLETED;
806
2.55k
  return JPEG_SCAN_COMPLETED;
807
81.8k
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
430
81.4k
{
431
81.4k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
81.4k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
81.4k
  JDIMENSION block_num, last_block_column;
434
81.4k
  int ci, block_row, block_rows, access_rows, image_block_row,
435
81.4k
    image_block_rows;
436
81.4k
  JBLOCKARRAY buffer;
437
81.4k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
81.4k
  JBLOCKROW next_block_row, next_next_block_row;
439
81.4k
  _JSAMPARRAY output_ptr;
440
81.4k
  JDIMENSION output_col;
441
81.4k
  jpeg_component_info *compptr;
442
81.4k
  _inverse_DCT_method_ptr inverse_DCT;
443
81.4k
  boolean change_dc;
444
81.4k
  JCOEF *workspace;
445
81.4k
  int *coef_bits;
446
81.4k
  JQUANT_TBL *quanttbl;
447
81.4k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
81.4k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
81.4k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
81.4k
      DC25;
451
81.4k
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
81.4k
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
81.4k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
81.4k
         !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
166k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
85.4k
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
85.4k
    if (!compptr->component_needed)
478
0
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
85.4k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
80.3k
      block_rows = compptr->v_samp_factor;
482
80.3k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
80.3k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
2.55k
      block_rows = compptr->v_samp_factor;
485
2.55k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
2.55k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
2.55k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
2.55k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
2.55k
      access_rows = block_rows; /* this iMCU row only */
491
2.55k
    }
492
    /* Align the virtual buffer for this component. */
493
85.4k
    if (cinfo->output_iMCU_row > 1) {
494
80.3k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
80.3k
      buffer = (*cinfo->mem->access_virt_barray)
496
80.3k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
80.3k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
80.3k
         (JDIMENSION)access_rows, FALSE);
499
80.3k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
80.3k
    } else if (cinfo->output_iMCU_row > 0) {
501
2.55k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
2.55k
      buffer = (*cinfo->mem->access_virt_barray)
503
2.55k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
2.55k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
2.55k
         (JDIMENSION)access_rows, FALSE);
506
2.55k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
2.55k
    } else {
508
2.55k
      buffer = (*cinfo->mem->access_virt_barray)
509
2.55k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
2.55k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
2.55k
    }
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
85.4k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
49.7k
      coef_bits =
518
49.7k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
35.7k
    else
520
35.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
85.4k
    change_dc =
524
85.4k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
85.4k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
85.4k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
85.4k
    quanttbl = compptr->quant_table;
529
85.4k
    Q00 = quanttbl->quantval[0];
530
85.4k
    Q01 = quanttbl->quantval[Q01_POS];
531
85.4k
    Q10 = quanttbl->quantval[Q10_POS];
532
85.4k
    Q20 = quanttbl->quantval[Q20_POS];
533
85.4k
    Q11 = quanttbl->quantval[Q11_POS];
534
85.4k
    Q02 = quanttbl->quantval[Q02_POS];
535
85.4k
    if (change_dc) {
536
76.0k
      Q03 = quanttbl->quantval[Q03_POS];
537
76.0k
      Q12 = quanttbl->quantval[Q12_POS];
538
76.0k
      Q21 = quanttbl->quantval[Q21_POS];
539
76.0k
      Q30 = quanttbl->quantval[Q30_POS];
540
76.0k
    }
541
85.4k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
85.4k
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
85.4k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
170k
    for (block_row = 0; block_row < block_rows; block_row++) {
546
85.4k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
85.4k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
85.4k
      if (image_block_row > 0)
550
82.9k
        prev_block_row =
551
82.9k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
2.55k
      else
553
2.55k
        prev_block_row = buffer_ptr;
554
555
85.4k
      if (image_block_row > 1)
556
80.3k
        prev_prev_block_row =
557
80.3k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
5.11k
      else
559
5.11k
        prev_prev_block_row = prev_block_row;
560
561
85.4k
      if (image_block_row < image_block_rows - 1)
562
82.9k
        next_block_row =
563
82.9k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
2.55k
      else
565
2.55k
        next_block_row = buffer_ptr;
566
567
85.4k
      if (image_block_row < image_block_rows - 2)
568
80.3k
        next_next_block_row =
569
80.3k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
5.11k
      else
571
5.11k
        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
85.4k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
85.4k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
85.4k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
85.4k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
85.4k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
85.4k
      output_col = 0;
582
85.4k
      last_block_column = compptr->width_in_blocks - 1;
583
85.4k
      for (block_num = cinfo->master->first_MCU_col[ci];
584
4.01M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
3.92M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
3.92M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
3.92M
            block_num < last_block_column) {
590
81.4k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
81.4k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
81.4k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
81.4k
          DC19 = DC20 = (int)next_block_row[1][0];
594
81.4k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
81.4k
        }
596
3.92M
        if (block_num + 1 < last_block_column) {
597
3.75M
          DC05 = (int)prev_prev_block_row[2][0];
598
3.75M
          DC10 = (int)prev_block_row[2][0];
599
3.75M
          DC15 = (int)buffer_ptr[2][0];
600
3.75M
          DC20 = (int)next_block_row[2][0];
601
3.75M
          DC25 = (int)next_next_block_row[2][0];
602
3.75M
        }
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.92M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
3.85M
          num = Q00 * (change_dc ?
616
3.69M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
3.69M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
3.69M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
3.69M
                 DC21 - DC22 + DC24 + DC25) :
620
3.85M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
3.85M
          if (num >= 0) {
622
3.51M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
3.51M
            if (Al > 0 && pred >= (1 << Al))
624
8.00k
              pred = (1 << Al) - 1;
625
3.51M
          } else {
626
340k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
340k
            if (Al > 0 && pred >= (1 << Al))
628
7.74k
              pred = (1 << Al) - 1;
629
340k
            pred = -pred;
630
340k
          }
631
3.85M
          workspace[1] = (JCOEF)pred;
632
3.85M
        }
633
        /* AC10 */
634
3.92M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
3.88M
          num = Q00 * (change_dc ?
636
3.69M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
3.69M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
3.69M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
3.69M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
3.88M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
3.88M
          if (num >= 0) {
642
3.55M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
3.55M
            if (Al > 0 && pred >= (1 << Al))
644
70.1k
              pred = (1 << Al) - 1;
645
3.55M
          } else {
646
330k
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
330k
            if (Al > 0 && pred >= (1 << Al))
648
17.6k
              pred = (1 << Al) - 1;
649
330k
            pred = -pred;
650
330k
          }
651
3.88M
          workspace[8] = (JCOEF)pred;
652
3.88M
        }
653
        /* AC20 */
654
3.92M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
3.85M
          num = Q00 * (change_dc ?
656
3.68M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
3.68M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
3.85M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
3.85M
          if (num >= 0) {
660
3.54M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
3.54M
            if (Al > 0 && pred >= (1 << Al))
662
13.4k
              pred = (1 << Al) - 1;
663
3.54M
          } else {
664
310k
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
310k
            if (Al > 0 && pred >= (1 << Al))
666
13.7k
              pred = (1 << Al) - 1;
667
310k
            pred = -pred;
668
310k
          }
669
3.85M
          workspace[16] = (JCOEF)pred;
670
3.85M
        }
671
        /* AC11 */
672
3.92M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
3.88M
          num = Q00 * (change_dc ?
674
3.68M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
3.68M
                 9 * DC19 + DC21 - DC25) :
676
3.88M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
198k
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
3.88M
          if (num >= 0) {
679
3.63M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
3.63M
            if (Al > 0 && pred >= (1 << Al))
681
17.7k
              pred = (1 << Al) - 1;
682
3.63M
          } else {
683
249k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
249k
            if (Al > 0 && pred >= (1 << Al))
685
17.4k
              pred = (1 << Al) - 1;
686
249k
            pred = -pred;
687
249k
          }
688
3.88M
          workspace[9] = (JCOEF)pred;
689
3.88M
        }
690
        /* AC02 */
691
3.92M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
3.90M
          num = Q00 * (change_dc ?
693
3.68M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
3.68M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
3.90M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
3.90M
          if (num >= 0) {
697
3.59M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
3.59M
            if (Al > 0 && pred >= (1 << Al))
699
15.2k
              pred = (1 << Al) - 1;
700
3.59M
          } else {
701
314k
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
314k
            if (Al > 0 && pred >= (1 << Al))
703
14.8k
              pred = (1 << Al) - 1;
704
314k
            pred = -pred;
705
314k
          }
706
3.90M
          workspace[2] = (JCOEF)pred;
707
3.90M
        }
708
3.92M
        if (change_dc) {
709
          /* AC03 */
710
3.69M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
3.68M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
3.68M
            if (num >= 0) {
713
3.43M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
3.43M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
3.43M
            } else {
717
259k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
259k
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
259k
              pred = -pred;
721
259k
            }
722
3.68M
            workspace[3] = (JCOEF)pred;
723
3.68M
          }
724
          /* AC12 */
725
3.69M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
3.68M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
3.68M
            if (num >= 0) {
728
3.43M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
3.43M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
3.43M
            } else {
732
254k
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
254k
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
254k
              pred = -pred;
736
254k
            }
737
3.68M
            workspace[10] = (JCOEF)pred;
738
3.68M
          }
739
          /* AC21 */
740
3.69M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
3.68M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
3.68M
            if (num >= 0) {
743
3.47M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
3.47M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
3.47M
            } else {
747
217k
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
217k
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
217k
              pred = -pred;
751
217k
            }
752
3.68M
            workspace[17] = (JCOEF)pred;
753
3.68M
          }
754
          /* AC30 */
755
3.69M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
3.68M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
3.68M
            if (num >= 0) {
758
3.44M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
3.44M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
3.44M
            } else {
762
247k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
247k
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
247k
              pred = -pred;
766
247k
            }
767
3.68M
            workspace[24] = (JCOEF)pred;
768
3.68M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
3.69M
          num = Q00 *
773
3.69M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
3.69M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
3.69M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
3.69M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
3.69M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
3.69M
          if (num >= 0) {
779
3.41M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
3.41M
          } else {
781
275k
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
275k
            pred = -pred;
783
275k
          }
784
3.69M
          workspace[0] = (JCOEF)pred;
785
3.69M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
3.92M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
3.92M
                        output_col);
790
        /* Advance for next column */
791
3.92M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
3.92M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
3.92M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
3.92M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
3.92M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
3.92M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
3.92M
          prev_prev_block_row++, next_next_block_row++;
798
3.92M
        output_col += compptr->_DCT_scaled_size;
799
3.92M
      }
800
85.4k
      output_ptr += compptr->_DCT_scaled_size;
801
85.4k
    }
802
85.4k
  }
803
804
81.4k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
78.9k
    return JPEG_ROW_COMPLETED;
806
2.45k
  return JPEG_SCAN_COMPLETED;
807
81.4k
}
jdcoefct-12.c:decompress_smooth_data
Line
Count
Source
430
428
{
431
428
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
428
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
428
  JDIMENSION block_num, last_block_column;
434
428
  int ci, block_row, block_rows, access_rows, image_block_row,
435
428
    image_block_rows;
436
428
  JBLOCKARRAY buffer;
437
428
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
428
  JBLOCKROW next_block_row, next_next_block_row;
439
428
  _JSAMPARRAY output_ptr;
440
428
  JDIMENSION output_col;
441
428
  jpeg_component_info *compptr;
442
428
  _inverse_DCT_method_ptr inverse_DCT;
443
428
  boolean change_dc;
444
428
  JCOEF *workspace;
445
428
  int *coef_bits;
446
428
  JQUANT_TBL *quanttbl;
447
428
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
428
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
428
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
428
      DC25;
451
428
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
428
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
428
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
428
         !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.71k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
1.28k
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
1.28k
    if (!compptr->component_needed)
478
0
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
1.28k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
675
      block_rows = compptr->v_samp_factor;
482
675
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
675
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
303
      block_rows = compptr->v_samp_factor;
485
303
      access_rows = block_rows * 2; /* this and next iMCU row */
486
306
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
306
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
306
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
306
      access_rows = block_rows; /* this iMCU row only */
491
306
    }
492
    /* Align the virtual buffer for this component. */
493
1.28k
    if (cinfo->output_iMCU_row > 1) {
494
663
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
663
      buffer = (*cinfo->mem->access_virt_barray)
496
663
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
663
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
663
         (JDIMENSION)access_rows, FALSE);
499
663
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
663
    } else if (cinfo->output_iMCU_row > 0) {
501
309
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
309
      buffer = (*cinfo->mem->access_virt_barray)
503
309
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
309
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
309
         (JDIMENSION)access_rows, FALSE);
506
309
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
312
    } else {
508
312
      buffer = (*cinfo->mem->access_virt_barray)
509
312
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
312
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
312
    }
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.28k
    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.28k
    else
520
1.28k
      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.28k
    change_dc =
524
1.28k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
1.28k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
1.28k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
1.28k
    quanttbl = compptr->quant_table;
529
1.28k
    Q00 = quanttbl->quantval[0];
530
1.28k
    Q01 = quanttbl->quantval[Q01_POS];
531
1.28k
    Q10 = quanttbl->quantval[Q10_POS];
532
1.28k
    Q20 = quanttbl->quantval[Q20_POS];
533
1.28k
    Q11 = quanttbl->quantval[Q11_POS];
534
1.28k
    Q02 = quanttbl->quantval[Q02_POS];
535
1.28k
    if (change_dc) {
536
1.02k
      Q03 = quanttbl->quantval[Q03_POS];
537
1.02k
      Q12 = quanttbl->quantval[Q12_POS];
538
1.02k
      Q21 = quanttbl->quantval[Q21_POS];
539
1.02k
      Q30 = quanttbl->quantval[Q30_POS];
540
1.02k
    }
541
1.28k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
1.28k
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
1.28k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
2.56k
    for (block_row = 0; block_row < block_rows; block_row++) {
546
1.28k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
1.28k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
1.28k
      if (image_block_row > 0)
550
972
        prev_block_row =
551
972
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
312
      else
553
312
        prev_block_row = buffer_ptr;
554
555
1.28k
      if (image_block_row > 1)
556
663
        prev_prev_block_row =
557
663
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
621
      else
559
621
        prev_prev_block_row = prev_block_row;
560
561
1.28k
      if (image_block_row < image_block_rows - 1)
562
978
        next_block_row =
563
978
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
306
      else
565
306
        next_block_row = buffer_ptr;
566
567
1.28k
      if (image_block_row < image_block_rows - 2)
568
675
        next_next_block_row =
569
675
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
609
      else
571
609
        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.28k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
1.28k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
1.28k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
1.28k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
1.28k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
1.28k
      output_col = 0;
582
1.28k
      last_block_column = compptr->width_in_blocks - 1;
583
1.28k
      for (block_num = cinfo->master->first_MCU_col[ci];
584
897k
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
896k
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
896k
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
896k
            block_num < last_block_column) {
590
1.21k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
1.21k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
1.21k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
1.21k
          DC19 = DC20 = (int)next_block_row[1][0];
594
1.21k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
1.21k
        }
596
896k
        if (block_num + 1 < last_block_column) {
597
894k
          DC05 = (int)prev_prev_block_row[2][0];
598
894k
          DC10 = (int)prev_block_row[2][0];
599
894k
          DC15 = (int)buffer_ptr[2][0];
600
894k
          DC20 = (int)next_block_row[2][0];
601
894k
          DC25 = (int)next_next_block_row[2][0];
602
894k
        }
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
896k
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
892k
          num = Q00 * (change_dc ?
616
867k
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
867k
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
867k
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
867k
                 DC21 - DC22 + DC24 + DC25) :
620
892k
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
892k
          if (num >= 0) {
622
523k
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
523k
            if (Al > 0 && pred >= (1 << Al))
624
744
              pred = (1 << Al) - 1;
625
523k
          } else {
626
368k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
368k
            if (Al > 0 && pred >= (1 << Al))
628
872
              pred = (1 << Al) - 1;
629
368k
            pred = -pred;
630
368k
          }
631
892k
          workspace[1] = (JCOEF)pred;
632
892k
        }
633
        /* AC10 */
634
896k
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
893k
          num = Q00 * (change_dc ?
636
867k
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
867k
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
867k
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
867k
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
893k
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
893k
          if (num >= 0) {
642
470k
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
470k
            if (Al > 0 && pred >= (1 << Al))
644
8.39k
              pred = (1 << Al) - 1;
645
470k
          } else {
646
422k
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
422k
            if (Al > 0 && pred >= (1 << Al))
648
7.65k
              pred = (1 << Al) - 1;
649
422k
            pred = -pred;
650
422k
          }
651
893k
          workspace[8] = (JCOEF)pred;
652
893k
        }
653
        /* AC20 */
654
896k
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
893k
          num = Q00 * (change_dc ?
656
867k
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
867k
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
893k
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
893k
          if (num >= 0) {
660
480k
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
480k
            if (Al > 0 && pred >= (1 << Al))
662
8.26k
              pred = (1 << Al) - 1;
663
480k
          } else {
664
412k
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
412k
            if (Al > 0 && pred >= (1 << Al))
666
8.58k
              pred = (1 << Al) - 1;
667
412k
            pred = -pred;
668
412k
          }
669
893k
          workspace[16] = (JCOEF)pred;
670
893k
        }
671
        /* AC11 */
672
896k
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
893k
          num = Q00 * (change_dc ?
674
867k
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
867k
                 9 * DC19 + DC21 - DC25) :
676
893k
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
26.0k
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
893k
          if (num >= 0) {
679
580k
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
580k
            if (Al > 0 && pred >= (1 << Al))
681
1.49k
              pred = (1 << Al) - 1;
682
580k
          } else {
683
313k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
313k
            if (Al > 0 && pred >= (1 << Al))
685
1.48k
              pred = (1 << Al) - 1;
686
313k
            pred = -pred;
687
313k
          }
688
893k
          workspace[9] = (JCOEF)pred;
689
893k
        }
690
        /* AC02 */
691
896k
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
894k
          num = Q00 * (change_dc ?
693
867k
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
867k
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
894k
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
894k
          if (num >= 0) {
697
503k
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
503k
            if (Al > 0 && pred >= (1 << Al))
699
1.50k
              pred = (1 << Al) - 1;
700
503k
          } else {
701
390k
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
390k
            if (Al > 0 && pred >= (1 << Al))
703
1.49k
              pred = (1 << Al) - 1;
704
390k
            pred = -pred;
705
390k
          }
706
894k
          workspace[2] = (JCOEF)pred;
707
894k
        }
708
896k
        if (change_dc) {
709
          /* AC03 */
710
867k
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
867k
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
867k
            if (num >= 0) {
713
543k
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
543k
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
543k
            } else {
717
324k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
324k
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
324k
              pred = -pred;
721
324k
            }
722
867k
            workspace[3] = (JCOEF)pred;
723
867k
          }
724
          /* AC12 */
725
867k
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
867k
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
867k
            if (num >= 0) {
728
484k
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
484k
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
484k
            } else {
732
383k
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
383k
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
383k
              pred = -pred;
736
383k
            }
737
867k
            workspace[10] = (JCOEF)pred;
738
867k
          }
739
          /* AC21 */
740
867k
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
867k
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
867k
            if (num >= 0) {
743
555k
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
555k
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
555k
            } else {
747
311k
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
311k
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
311k
              pred = -pred;
751
311k
            }
752
867k
            workspace[17] = (JCOEF)pred;
753
867k
          }
754
          /* AC30 */
755
867k
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
867k
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
867k
            if (num >= 0) {
758
492k
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
492k
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
492k
            } else {
762
375k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
375k
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
375k
              pred = -pred;
766
375k
            }
767
867k
            workspace[24] = (JCOEF)pred;
768
867k
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
867k
          num = Q00 *
773
867k
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
867k
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
867k
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
867k
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
867k
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
867k
          if (num >= 0) {
779
456k
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
456k
          } else {
781
411k
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
411k
            pred = -pred;
783
411k
          }
784
867k
          workspace[0] = (JCOEF)pred;
785
867k
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
896k
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
896k
                        output_col);
790
        /* Advance for next column */
791
896k
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
896k
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
896k
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
896k
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
896k
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
896k
        buffer_ptr++, prev_block_row++, next_block_row++,
797
896k
          prev_prev_block_row++, next_next_block_row++;
798
896k
        output_col += compptr->_DCT_scaled_size;
799
896k
      }
800
1.28k
      output_ptr += compptr->_DCT_scaled_size;
801
1.28k
    }
802
1.28k
  }
803
804
428
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
326
    return JPEG_ROW_COMPLETED;
806
102
  return JPEG_SCAN_COMPLETED;
807
428
}
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
43.7k
{
819
43.7k
  my_coef_ptr coef;
820
821
43.7k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
43.7k
  coef = (my_coef_ptr)
825
43.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
43.7k
                                sizeof(my_coef_controller));
827
43.7k
  memset(coef, 0, sizeof(my_coef_controller));
828
43.7k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
43.7k
  coef->pub.start_input_pass = start_input_pass;
830
43.7k
  coef->pub.start_output_pass = start_output_pass;
831
43.7k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
43.7k
  coef->coef_bits_latch = NULL;
833
43.7k
#endif
834
835
  /* Create the coefficient buffer. */
836
43.7k
  if (need_full_buffer) {
837
22.3k
#ifdef D_MULTISCAN_FILES_SUPPORTED
838
    /* Allocate a full-image virtual array for each component, */
839
    /* padded to a multiple of samp_factor DCT blocks in each direction. */
840
    /* Note we ask for a pre-zeroed array. */
841
22.3k
    int ci, access_rows;
842
22.3k
    jpeg_component_info *compptr;
843
844
60.8k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
38.5k
         ci++, compptr++) {
846
38.5k
      access_rows = compptr->v_samp_factor;
847
38.5k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
38.5k
      if (cinfo->progressive_mode)
850
23.9k
        access_rows *= 5;
851
38.5k
#endif
852
38.5k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
38.5k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
38.5k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
38.5k
                               (long)compptr->h_samp_factor),
856
38.5k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
38.5k
                               (long)compptr->v_samp_factor),
858
38.5k
         (JDIMENSION)access_rows);
859
38.5k
    }
860
22.3k
    coef->pub.consume_data = consume_data;
861
22.3k
    coef->pub._decompress_data = decompress_data;
862
22.3k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
22.3k
  } else {
867
    /* We only need a single-MCU buffer. */
868
21.3k
    JBLOCKROW buffer;
869
21.3k
    int i;
870
871
21.3k
    buffer = (JBLOCKROW)
872
21.3k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
21.3k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
235k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
213k
      coef->MCU_buffer[i] = buffer + i;
876
213k
    }
877
21.3k
    coef->pub.consume_data = dummy_consume_data;
878
21.3k
    coef->pub._decompress_data = decompress_onepass;
879
21.3k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
21.3k
  }
881
882
  /* Allocate the workspace buffer */
883
43.7k
  coef->workspace = (JCOEF *)
884
43.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
43.7k
                                sizeof(JCOEF) * DCTSIZE2);
886
43.7k
}
jinit_d_coef_controller
Line
Count
Source
818
43.5k
{
819
43.5k
  my_coef_ptr coef;
820
821
43.5k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
43.5k
  coef = (my_coef_ptr)
825
43.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
43.5k
                                sizeof(my_coef_controller));
827
43.5k
  memset(coef, 0, sizeof(my_coef_controller));
828
43.5k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
43.5k
  coef->pub.start_input_pass = start_input_pass;
830
43.5k
  coef->pub.start_output_pass = start_output_pass;
831
43.5k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
43.5k
  coef->coef_bits_latch = NULL;
833
43.5k
#endif
834
835
  /* Create the coefficient buffer. */
836
43.5k
  if (need_full_buffer) {
837
22.2k
#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.2k
    int ci, access_rows;
842
22.2k
    jpeg_component_info *compptr;
843
844
60.2k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
38.0k
         ci++, compptr++) {
846
38.0k
      access_rows = compptr->v_samp_factor;
847
38.0k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
38.0k
      if (cinfo->progressive_mode)
850
23.5k
        access_rows *= 5;
851
38.0k
#endif
852
38.0k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
38.0k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
38.0k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
38.0k
                               (long)compptr->h_samp_factor),
856
38.0k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
38.0k
                               (long)compptr->v_samp_factor),
858
38.0k
         (JDIMENSION)access_rows);
859
38.0k
    }
860
22.2k
    coef->pub.consume_data = consume_data;
861
22.2k
    coef->pub._decompress_data = decompress_data;
862
22.2k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
22.2k
  } else {
867
    /* We only need a single-MCU buffer. */
868
21.3k
    JBLOCKROW buffer;
869
21.3k
    int i;
870
871
21.3k
    buffer = (JBLOCKROW)
872
21.3k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
21.3k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
235k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
213k
      coef->MCU_buffer[i] = buffer + i;
876
213k
    }
877
21.3k
    coef->pub.consume_data = dummy_consume_data;
878
21.3k
    coef->pub._decompress_data = decompress_onepass;
879
21.3k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
21.3k
  }
881
882
  /* Allocate the workspace buffer */
883
43.5k
  coef->workspace = (JCOEF *)
884
43.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
43.5k
                                sizeof(JCOEF) * DCTSIZE2);
886
43.5k
}
j12init_d_coef_controller
Line
Count
Source
818
159
{
819
159
  my_coef_ptr coef;
820
821
159
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
159
  coef = (my_coef_ptr)
825
159
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
159
                                sizeof(my_coef_controller));
827
159
  memset(coef, 0, sizeof(my_coef_controller));
828
159
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
159
  coef->pub.start_input_pass = start_input_pass;
830
159
  coef->pub.start_output_pass = start_output_pass;
831
159
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
159
  coef->coef_bits_latch = NULL;
833
159
#endif
834
835
  /* Create the coefficient buffer. */
836
159
  if (need_full_buffer) {
837
155
#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
155
    int ci, access_rows;
842
155
    jpeg_component_info *compptr;
843
844
620
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
465
         ci++, compptr++) {
846
465
      access_rows = compptr->v_samp_factor;
847
465
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
465
      if (cinfo->progressive_mode)
850
453
        access_rows *= 5;
851
465
#endif
852
465
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
465
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
465
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
465
                               (long)compptr->h_samp_factor),
856
465
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
465
                               (long)compptr->v_samp_factor),
858
465
         (JDIMENSION)access_rows);
859
465
    }
860
155
    coef->pub.consume_data = consume_data;
861
155
    coef->pub._decompress_data = decompress_data;
862
155
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
155
  } else {
867
    /* We only need a single-MCU buffer. */
868
4
    JBLOCKROW buffer;
869
4
    int i;
870
871
4
    buffer = (JBLOCKROW)
872
4
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
4
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
44
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
40
      coef->MCU_buffer[i] = buffer + i;
876
40
    }
877
4
    coef->pub.consume_data = dummy_consume_data;
878
4
    coef->pub._decompress_data = decompress_onepass;
879
4
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
4
  }
881
882
  /* Allocate the workspace buffer */
883
159
  coef->workspace = (JCOEF *)
884
159
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
159
                                sizeof(JCOEF) * DCTSIZE2);
886
159
}