Coverage Report

Created: 2026-08-31 07:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.3.1.x/src/jdcoefct.c
Line
Count
Source
1
/*
2
 * jdcoefct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1997, Thomas G. Lane.
6
 * libjpeg-turbo Modifications:
7
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
8
 * Copyright (C) 2010, 2015-2016, 2019-2020, 2022-2024, D. R. Commander.
9
 * Copyright (C) 2015, 2020, Google, Inc.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the coefficient buffer controller for decompression.
14
 * This controller is the top level of the lossy JPEG decompressor proper.
15
 * The coefficient buffer lies between entropy decoding and inverse-DCT steps.
16
 *
17
 * In buffered-image mode, this controller is the interface between
18
 * input-oriented processing and output-oriented processing.
19
 * Also, the input side (only) is used when reading a file for transcoding.
20
 */
21
22
#include "jinclude.h"
23
#include "jdcoefct.h"
24
#include "jpegapicomp.h"
25
#include "jsamplecomp.h"
26
27
28
/* Forward declarations */
29
METHODDEF(int) decompress_onepass(j_decompress_ptr cinfo,
30
                                  _JSAMPIMAGE output_buf);
31
#ifdef D_MULTISCAN_FILES_SUPPORTED
32
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
33
#endif
34
#ifdef BLOCK_SMOOTHING_SUPPORTED
35
LOCAL(boolean) smoothing_ok(j_decompress_ptr cinfo);
36
METHODDEF(int) decompress_smooth_data(j_decompress_ptr cinfo,
37
                                      _JSAMPIMAGE output_buf);
38
#endif
39
40
41
/*
42
 * Initialize for an input processing pass.
43
 */
44
45
METHODDEF(void)
46
start_input_pass(j_decompress_ptr cinfo)
47
519k
{
48
519k
  cinfo->input_iMCU_row = 0;
49
519k
  start_iMCU_row(cinfo);
50
519k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
47
442k
{
48
442k
  cinfo->input_iMCU_row = 0;
49
442k
  start_iMCU_row(cinfo);
50
442k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
47
76.7k
{
48
76.7k
  cinfo->input_iMCU_row = 0;
49
76.7k
  start_iMCU_row(cinfo);
50
76.7k
}
51
52
53
/*
54
 * Initialize for an output processing pass.
55
 */
56
57
METHODDEF(void)
58
start_output_pass(j_decompress_ptr cinfo)
59
98.3k
{
60
98.3k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
98.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
98.3k
  if (coef->pub.coef_arrays != NULL) {
65
76.4k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
30.3k
      coef->pub._decompress_data = decompress_smooth_data;
67
46.0k
    else
68
46.0k
      coef->pub._decompress_data = decompress_data;
69
76.4k
  }
70
98.3k
#endif
71
98.3k
  cinfo->output_iMCU_row = 0;
72
98.3k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
59
84.8k
{
60
84.8k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
84.8k
  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
84.8k
  if (coef->pub.coef_arrays != NULL) {
65
66.9k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
26.3k
      coef->pub._decompress_data = decompress_smooth_data;
67
40.6k
    else
68
40.6k
      coef->pub._decompress_data = decompress_data;
69
66.9k
  }
70
84.8k
#endif
71
84.8k
  cinfo->output_iMCU_row = 0;
72
84.8k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
59
13.5k
{
60
13.5k
#ifdef BLOCK_SMOOTHING_SUPPORTED
61
13.5k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
62
63
  /* If multipass, check to see whether to use block smoothing on this pass */
64
13.5k
  if (coef->pub.coef_arrays != NULL) {
65
9.45k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
66
4.02k
      coef->pub._decompress_data = decompress_smooth_data;
67
5.42k
    else
68
5.42k
      coef->pub._decompress_data = decompress_data;
69
9.45k
  }
70
13.5k
#endif
71
13.5k
  cinfo->output_iMCU_row = 0;
72
13.5k
}
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
8.18M
{
88
8.18M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
8.18M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
8.18M
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
8.18M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
8.18M
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
8.18M
  _JSAMPARRAY output_ptr;
94
8.18M
  JDIMENSION start_col, output_col;
95
8.18M
  jpeg_component_info *compptr;
96
8.18M
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
18.4M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
10.2M
       yoffset++) {
101
86.2M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
76.0M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
76.0M
      jzero_far((void *)coef->MCU_buffer[0],
105
76.0M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
76.0M
      if (!cinfo->entropy->insufficient_data)
107
28.5M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
76.0M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
109
        /* Suspension forced; update state counters and exit */
110
0
        coef->MCU_vert_offset = yoffset;
111
0
        coef->MCU_ctr = MCU_col_num;
112
0
        return JPEG_SUSPENDED;
113
0
      }
114
115
      /* Only perform the IDCT on blocks that are contained within the desired
116
       * cropping region.
117
       */
118
76.0M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
75.8M
          MCU_col_num <= cinfo->master->last_iMCU_col) {
120
        /* Determine where data should go in output_buf and do the IDCT thing.
121
         * We skip dummy blocks at the right and bottom edges (but blkn gets
122
         * incremented past them!).  Note the inner loop relies on having
123
         * allocated the MCU_buffer[] blocks sequentially.
124
         */
125
73.2M
        blkn = 0;               /* index of current DCT block within MCU */
126
165M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
92.1M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
92.1M
          if (!compptr->component_needed) {
130
114k
            blkn += compptr->MCU_blocks;
131
114k
            continue;
132
114k
          }
133
92.0M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
92.0M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
72.7M
                         compptr->MCU_width : compptr->last_col_width;
136
92.0M
          output_ptr = output_buf[compptr->component_index] +
137
92.0M
                       yoffset * compptr->_DCT_scaled_size;
138
92.0M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
92.0M
                      compptr->MCU_sample_width;
140
191M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
99.1M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
97.3M
                yoffset + yindex < compptr->last_row_height) {
143
97.3M
              output_col = start_col;
144
201M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
104M
                (*inverse_DCT) (cinfo, compptr,
146
104M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
104M
                                output_ptr, output_col);
148
104M
                output_col += compptr->_DCT_scaled_size;
149
104M
              }
150
97.3M
            }
151
99.1M
            blkn += compptr->MCU_width;
152
99.1M
            output_ptr += compptr->_DCT_scaled_size;
153
99.1M
          }
154
92.0M
        }
155
73.2M
      }
156
76.0M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
10.2M
    coef->MCU_ctr = 0;
159
10.2M
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
8.18M
  cinfo->output_iMCU_row++;
162
8.18M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
8.16M
    start_iMCU_row(cinfo);
164
8.16M
    return JPEG_ROW_COMPLETED;
165
8.16M
  }
166
  /* Completed the scan */
167
18.8k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
18.8k
  return JPEG_SCAN_COMPLETED;
169
8.18M
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
87
7.51M
{
88
7.51M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
7.51M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
7.51M
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
7.51M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
7.51M
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
7.51M
  _JSAMPARRAY output_ptr;
94
7.51M
  JDIMENSION start_col, output_col;
95
7.51M
  jpeg_component_info *compptr;
96
7.51M
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
16.6M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
9.17M
       yoffset++) {
101
69.4M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
60.3M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
60.3M
      jzero_far((void *)coef->MCU_buffer[0],
105
60.3M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
60.3M
      if (!cinfo->entropy->insufficient_data)
107
21.2M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
60.3M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
109
        /* Suspension forced; update state counters and exit */
110
0
        coef->MCU_vert_offset = yoffset;
111
0
        coef->MCU_ctr = MCU_col_num;
112
0
        return JPEG_SUSPENDED;
113
0
      }
114
115
      /* Only perform the IDCT on blocks that are contained within the desired
116
       * cropping region.
117
       */
118
60.3M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
60.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
58.7M
        blkn = 0;               /* index of current DCT block within MCU */
126
135M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
76.4M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
76.4M
          if (!compptr->component_needed) {
130
86.5k
            blkn += compptr->MCU_blocks;
131
86.5k
            continue;
132
86.5k
          }
133
76.3M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
76.3M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
58.4M
                         compptr->MCU_width : compptr->last_col_width;
136
76.3M
          output_ptr = output_buf[compptr->component_index] +
137
76.3M
                       yoffset * compptr->_DCT_scaled_size;
138
76.3M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
76.3M
                      compptr->MCU_sample_width;
140
159M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
82.8M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
81.1M
                yoffset + yindex < compptr->last_row_height) {
143
81.1M
              output_col = start_col;
144
168M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
87.6M
                (*inverse_DCT) (cinfo, compptr,
146
87.6M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
87.6M
                                output_ptr, output_col);
148
87.6M
                output_col += compptr->_DCT_scaled_size;
149
87.6M
              }
150
81.1M
            }
151
82.8M
            blkn += compptr->MCU_width;
152
82.8M
            output_ptr += compptr->_DCT_scaled_size;
153
82.8M
          }
154
76.3M
        }
155
58.7M
      }
156
60.3M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
9.17M
    coef->MCU_ctr = 0;
159
9.17M
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
7.51M
  cinfo->output_iMCU_row++;
162
7.51M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
7.49M
    start_iMCU_row(cinfo);
164
7.49M
    return JPEG_ROW_COMPLETED;
165
7.49M
  }
166
  /* Completed the scan */
167
15.7k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
15.7k
  return JPEG_SCAN_COMPLETED;
169
7.51M
}
jdcoefct-12.c:decompress_onepass
Line
Count
Source
87
668k
{
88
668k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
89
668k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
90
668k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
91
668k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
92
668k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
93
668k
  _JSAMPARRAY output_ptr;
94
668k
  JDIMENSION start_col, output_col;
95
668k
  jpeg_component_info *compptr;
96
668k
  _inverse_DCT_method_ptr inverse_DCT;
97
98
  /* Loop to process as much as one whole iMCU row */
99
1.72M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
100
1.05M
       yoffset++) {
101
16.7M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
102
15.6M
         MCU_col_num++) {
103
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
104
15.6M
      jzero_far((void *)coef->MCU_buffer[0],
105
15.6M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
106
15.6M
      if (!cinfo->entropy->insufficient_data)
107
7.23M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
108
15.6M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
109
        /* Suspension forced; update state counters and exit */
110
0
        coef->MCU_vert_offset = yoffset;
111
0
        coef->MCU_ctr = MCU_col_num;
112
0
        return JPEG_SUSPENDED;
113
0
      }
114
115
      /* Only perform the IDCT on blocks that are contained within the desired
116
       * cropping region.
117
       */
118
15.6M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
119
15.6M
          MCU_col_num <= cinfo->master->last_iMCU_col) {
120
        /* Determine where data should go in output_buf and do the IDCT thing.
121
         * We skip dummy blocks at the right and bottom edges (but blkn gets
122
         * incremented past them!).  Note the inner loop relies on having
123
         * allocated the MCU_buffer[] blocks sequentially.
124
         */
125
14.5M
        blkn = 0;               /* index of current DCT block within MCU */
126
30.2M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
127
15.6M
          compptr = cinfo->cur_comp_info[ci];
128
          /* Don't bother to IDCT an uninteresting component. */
129
15.6M
          if (!compptr->component_needed) {
130
28.0k
            blkn += compptr->MCU_blocks;
131
28.0k
            continue;
132
28.0k
          }
133
15.6M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
134
15.6M
          useful_width = (MCU_col_num < last_MCU_col) ?
135
14.3M
                         compptr->MCU_width : compptr->last_col_width;
136
15.6M
          output_ptr = output_buf[compptr->component_index] +
137
15.6M
                       yoffset * compptr->_DCT_scaled_size;
138
15.6M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
139
15.6M
                      compptr->MCU_sample_width;
140
31.9M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
141
16.3M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
142
16.1M
                yoffset + yindex < compptr->last_row_height) {
143
16.1M
              output_col = start_col;
144
33.0M
              for (xindex = 0; xindex < useful_width; xindex++) {
145
16.8M
                (*inverse_DCT) (cinfo, compptr,
146
16.8M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
147
16.8M
                                output_ptr, output_col);
148
16.8M
                output_col += compptr->_DCT_scaled_size;
149
16.8M
              }
150
16.1M
            }
151
16.3M
            blkn += compptr->MCU_width;
152
16.3M
            output_ptr += compptr->_DCT_scaled_size;
153
16.3M
          }
154
15.6M
        }
155
14.5M
      }
156
15.6M
    }
157
    /* Completed an MCU row, but perhaps not an iMCU row */
158
1.05M
    coef->MCU_ctr = 0;
159
1.05M
  }
160
  /* Completed the iMCU row, advance counters for next one */
161
668k
  cinfo->output_iMCU_row++;
162
668k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
163
665k
    start_iMCU_row(cinfo);
164
665k
    return JPEG_ROW_COMPLETED;
165
665k
  }
166
  /* Completed the scan */
167
3.14k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
168
3.14k
  return JPEG_SCAN_COMPLETED;
169
668k
}
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
138M
{
195
138M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
138M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
138M
  int blkn, ci, xindex, yindex, yoffset;
198
138M
  JDIMENSION start_col;
199
138M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
138M
  JBLOCKROW buffer_ptr;
201
138M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
301M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
162M
    compptr = cinfo->cur_comp_info[ci];
206
162M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
162M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
162M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
162M
       (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
162M
  }
215
216
  /* Loop to process one whole iMCU row */
217
420M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
281M
       yoffset++) {
219
1.62G
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
1.34G
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
1.34G
      blkn = 0;                 /* index of current DCT block within MCU */
223
2.80G
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
1.46G
        compptr = cinfo->cur_comp_info[ci];
225
1.46G
        start_col = MCU_col_num * compptr->MCU_width;
226
3.00G
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
1.54G
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
3.25G
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
1.71G
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
1.71G
          }
231
1.54G
        }
232
1.46G
      }
233
1.34G
      if (!cinfo->entropy->insufficient_data)
234
923M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
1.34G
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
237
        /* Suspension forced; update state counters and exit */
238
0
        coef->MCU_vert_offset = yoffset;
239
0
        coef->MCU_ctr = MCU_col_num;
240
0
        return JPEG_SUSPENDED;
241
0
      }
242
1.34G
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
281M
    coef->MCU_ctr = 0;
245
281M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
138M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
138M
    start_iMCU_row(cinfo);
249
138M
    return JPEG_ROW_COMPLETED;
250
138M
  }
251
  /* Completed the scan */
252
493k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
493k
  return JPEG_SCAN_COMPLETED;
254
138M
}
jdcoefct-8.c:consume_data
Line
Count
Source
194
123M
{
195
123M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
123M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
123M
  int blkn, ci, xindex, yindex, yoffset;
198
123M
  JDIMENSION start_col;
199
123M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
123M
  JBLOCKROW buffer_ptr;
201
123M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
264M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
141M
    compptr = cinfo->cur_comp_info[ci];
206
141M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
141M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
141M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
141M
       (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
141M
  }
215
216
  /* Loop to process one whole iMCU row */
217
384M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
260M
       yoffset++) {
219
1.41G
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
1.15G
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
1.15G
      blkn = 0;                 /* index of current DCT block within MCU */
223
2.41G
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
1.26G
        compptr = cinfo->cur_comp_info[ci];
225
1.26G
        start_col = MCU_col_num * compptr->MCU_width;
226
2.59G
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
1.33G
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
2.81G
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
1.48G
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
1.48G
          }
231
1.33G
        }
232
1.26G
      }
233
1.15G
      if (!cinfo->entropy->insufficient_data)
234
798M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
1.15G
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
237
        /* Suspension forced; update state counters and exit */
238
0
        coef->MCU_vert_offset = yoffset;
239
0
        coef->MCU_ctr = MCU_col_num;
240
0
        return JPEG_SUSPENDED;
241
0
      }
242
1.15G
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
260M
    coef->MCU_ctr = 0;
245
260M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
123M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
123M
    start_iMCU_row(cinfo);
249
123M
    return JPEG_ROW_COMPLETED;
250
123M
  }
251
  /* Completed the scan */
252
421k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
421k
  return JPEG_SCAN_COMPLETED;
254
123M
}
jdcoefct-12.c:consume_data
Line
Count
Source
194
14.8M
{
195
14.8M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
196
14.8M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
197
14.8M
  int blkn, ci, xindex, yindex, yoffset;
198
14.8M
  JDIMENSION start_col;
199
14.8M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
200
14.8M
  JBLOCKROW buffer_ptr;
201
14.8M
  jpeg_component_info *compptr;
202
203
  /* Align the virtual buffers for the components used in this scan. */
204
36.6M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
205
21.7M
    compptr = cinfo->cur_comp_info[ci];
206
21.7M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
207
21.7M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
208
21.7M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
209
21.7M
       (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
21.7M
  }
215
216
  /* Loop to process one whole iMCU row */
217
35.5M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
218
20.6M
       yoffset++) {
219
208M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
220
188M
         MCU_col_num++) {
221
      /* Construct list of pointers to DCT blocks belonging to this MCU */
222
188M
      blkn = 0;                 /* index of current DCT block within MCU */
223
389M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
224
201M
        compptr = cinfo->cur_comp_info[ci];
225
201M
        start_col = MCU_col_num * compptr->MCU_width;
226
416M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
227
214M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
228
440M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
229
226M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
230
226M
          }
231
214M
        }
232
201M
      }
233
188M
      if (!cinfo->entropy->insufficient_data)
234
125M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
235
      /* Try to fetch the MCU. */
236
188M
      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
188M
    }
243
    /* Completed an MCU row, but perhaps not an iMCU row */
244
20.6M
    coef->MCU_ctr = 0;
245
20.6M
  }
246
  /* Completed the iMCU row, advance counters for next one */
247
14.8M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
248
14.8M
    start_iMCU_row(cinfo);
249
14.8M
    return JPEG_ROW_COMPLETED;
250
14.8M
  }
251
  /* Completed the scan */
252
72.3k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
253
72.3k
  return JPEG_SCAN_COMPLETED;
254
14.8M
}
255
256
257
/*
258
 * Decompress and return some data in the multi-pass case.
259
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
260
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
261
 *
262
 * NB: output_buf contains a plane for each component in image.
263
 */
264
265
METHODDEF(int)
266
decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
267
10.2M
{
268
10.2M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
10.2M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
10.2M
  JDIMENSION block_num;
271
10.2M
  int ci, block_row, block_rows;
272
10.2M
  JBLOCKARRAY buffer;
273
10.2M
  JBLOCKROW buffer_ptr;
274
10.2M
  _JSAMPARRAY output_ptr;
275
10.2M
  JDIMENSION output_col;
276
10.2M
  jpeg_component_info *compptr;
277
10.2M
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
15.8M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
15.8M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
15.8M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
283
5.51M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
284
0
      return JPEG_SUSPENDED;
285
5.51M
  }
286
287
  /* OK, output from the virtual arrays. */
288
35.1M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
24.8M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
24.8M
    if (!compptr->component_needed)
292
1.04M
      continue;
293
    /* Align the virtual buffer for this component. */
294
23.8M
    buffer = (*cinfo->mem->access_virt_barray)
295
23.8M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
23.8M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
23.8M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
23.8M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
23.7M
      block_rows = compptr->v_samp_factor;
301
106k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
106k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
106k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
106k
    }
306
23.8M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
23.8M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
58.9M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
35.0M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
35.0M
      output_col = 0;
312
35.0M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
232M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
197M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
197M
                        output_col);
316
197M
        buffer_ptr++;
317
197M
        output_col += compptr->_DCT_scaled_size;
318
197M
      }
319
35.0M
      output_ptr += compptr->_DCT_scaled_size;
320
35.0M
    }
321
23.8M
  }
322
323
10.2M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
10.2M
    return JPEG_ROW_COMPLETED;
325
43.3k
  return JPEG_SCAN_COMPLETED;
326
10.2M
}
jdcoefct-8.c:decompress_data
Line
Count
Source
267
9.20M
{
268
9.20M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
9.20M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
9.20M
  JDIMENSION block_num;
271
9.20M
  int ci, block_row, block_rows;
272
9.20M
  JBLOCKARRAY buffer;
273
9.20M
  JBLOCKROW buffer_ptr;
274
9.20M
  _JSAMPARRAY output_ptr;
275
9.20M
  JDIMENSION output_col;
276
9.20M
  jpeg_component_info *compptr;
277
9.20M
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
14.7M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
14.7M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
14.7M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
283
5.51M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
284
0
      return JPEG_SUSPENDED;
285
5.51M
  }
286
287
  /* OK, output from the virtual arrays. */
288
31.3M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
22.1M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
22.1M
    if (!compptr->component_needed)
292
558k
      continue;
293
    /* Align the virtual buffer for this component. */
294
21.5M
    buffer = (*cinfo->mem->access_virt_barray)
295
21.5M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
21.5M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
21.5M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
21.5M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
21.4M
      block_rows = compptr->v_samp_factor;
301
99.4k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
99.4k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
99.4k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
99.4k
    }
306
21.5M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
21.5M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
53.1M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
31.6M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
31.6M
      output_col = 0;
312
31.6M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
205M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
174M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
174M
                        output_col);
316
174M
        buffer_ptr++;
317
174M
        output_col += compptr->_DCT_scaled_size;
318
174M
      }
319
31.6M
      output_ptr += compptr->_DCT_scaled_size;
320
31.6M
    }
321
21.5M
  }
322
323
9.20M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
9.16M
    return JPEG_ROW_COMPLETED;
325
39.5k
  return JPEG_SCAN_COMPLETED;
326
9.20M
}
jdcoefct-12.c:decompress_data
Line
Count
Source
267
1.08M
{
268
1.08M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
269
1.08M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
270
1.08M
  JDIMENSION block_num;
271
1.08M
  int ci, block_row, block_rows;
272
1.08M
  JBLOCKARRAY buffer;
273
1.08M
  JBLOCKROW buffer_ptr;
274
1.08M
  _JSAMPARRAY output_ptr;
275
1.08M
  JDIMENSION output_col;
276
1.08M
  jpeg_component_info *compptr;
277
1.08M
  _inverse_DCT_method_ptr inverse_DCT;
278
279
  /* Force some input to be done if we are getting ahead of the input. */
280
1.08M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
281
1.08M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
282
1.08M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
283
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
284
0
      return JPEG_SUSPENDED;
285
0
  }
286
287
  /* OK, output from the virtual arrays. */
288
3.83M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
289
2.75M
       ci++, compptr++) {
290
    /* Don't bother to IDCT an uninteresting component. */
291
2.75M
    if (!compptr->component_needed)
292
484k
      continue;
293
    /* Align the virtual buffer for this component. */
294
2.27M
    buffer = (*cinfo->mem->access_virt_barray)
295
2.27M
      ((j_common_ptr)cinfo, coef->whole_image[ci],
296
2.27M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
297
2.27M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
298
    /* Count non-dummy DCT block rows in this iMCU row. */
299
2.27M
    if (cinfo->output_iMCU_row < last_iMCU_row)
300
2.26M
      block_rows = compptr->v_samp_factor;
301
7.24k
    else {
302
      /* NB: can't use last_row_height here; it is input-side-dependent! */
303
7.24k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
304
7.24k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
305
7.24k
    }
306
2.27M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
307
2.27M
    output_ptr = output_buf[ci];
308
    /* Loop over all DCT blocks to be processed. */
309
5.73M
    for (block_row = 0; block_row < block_rows; block_row++) {
310
3.45M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
311
3.45M
      output_col = 0;
312
3.45M
      for (block_num = cinfo->master->first_MCU_col[ci];
313
26.8M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
314
23.3M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
315
23.3M
                        output_col);
316
23.3M
        buffer_ptr++;
317
23.3M
        output_col += compptr->_DCT_scaled_size;
318
23.3M
      }
319
3.45M
      output_ptr += compptr->_DCT_scaled_size;
320
3.45M
    }
321
2.27M
  }
322
323
1.08M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
324
1.07M
    return JPEG_ROW_COMPLETED;
325
3.83k
  return JPEG_SCAN_COMPLETED;
326
1.08M
}
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
9.89M
#define Q01_POS  1
342
9.89M
#define Q10_POS  8
343
9.89M
#define Q20_POS  16
344
9.88M
#define Q11_POS  9
345
9.88M
#define Q02_POS  2
346
7.07M
#define Q03_POS  3
347
7.07M
#define Q12_POS  10
348
7.07M
#define Q21_POS  17
349
7.07M
#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
76.4k
{
362
76.4k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
76.4k
  boolean smoothing_useful = FALSE;
364
76.4k
  int ci, coefi;
365
76.4k
  jpeg_component_info *compptr;
366
76.4k
  JQUANT_TBL *qtable;
367
76.4k
  int *coef_bits, *prev_coef_bits;
368
76.4k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
76.4k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
22.7k
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
53.7k
  if (coef->coef_bits_latch == NULL)
375
30.0k
    coef->coef_bits_latch = (int *)
376
30.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
30.0k
                                  cinfo->num_components * 2 *
378
30.0k
                                  (SAVED_COEFS * sizeof(int)));
379
53.7k
  coef_bits_latch = coef->coef_bits_latch;
380
53.7k
  prev_coef_bits_latch =
381
53.7k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
114k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
83.8k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
83.8k
    if ((qtable = compptr->quant_table) == NULL)
387
5.82k
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
77.9k
    if (qtable->quantval[0] == 0 ||
390
76.4k
        qtable->quantval[Q01_POS] == 0 ||
391
75.0k
        qtable->quantval[Q10_POS] == 0 ||
392
73.3k
        qtable->quantval[Q20_POS] == 0 ||
393
72.0k
        qtable->quantval[Q11_POS] == 0 ||
394
70.6k
        qtable->quantval[Q02_POS] == 0 ||
395
69.5k
        qtable->quantval[Q03_POS] == 0 ||
396
68.2k
        qtable->quantval[Q12_POS] == 0 ||
397
66.1k
        qtable->quantval[Q21_POS] == 0 ||
398
65.0k
        qtable->quantval[Q30_POS] == 0)
399
13.9k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
64.0k
    coef_bits = cinfo->coef_bits[ci];
402
64.0k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
64.0k
    if (coef_bits[0] < 0)
404
3.25k
      return FALSE;
405
60.7k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
607k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
547k
      if (cinfo->input_scan_number > 1)
409
472k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
74.6k
      else
411
74.6k
        prev_coef_bits_latch[coefi] = -1;
412
547k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
547k
      if (coef_bits[coefi] != 0)
414
519k
        smoothing_useful = TRUE;
415
547k
    }
416
60.7k
    coef_bits_latch += SAVED_COEFS;
417
60.7k
    prev_coef_bits_latch += SAVED_COEFS;
418
60.7k
  }
419
420
30.6k
  return smoothing_useful;
421
53.7k
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
361
66.9k
{
362
66.9k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
66.9k
  boolean smoothing_useful = FALSE;
364
66.9k
  int ci, coefi;
365
66.9k
  jpeg_component_info *compptr;
366
66.9k
  JQUANT_TBL *qtable;
367
66.9k
  int *coef_bits, *prev_coef_bits;
368
66.9k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
66.9k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
20.9k
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
46.0k
  if (coef->coef_bits_latch == NULL)
375
22.3k
    coef->coef_bits_latch = (int *)
376
22.3k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
22.3k
                                  cinfo->num_components * 2 *
378
22.3k
                                  (SAVED_COEFS * sizeof(int)));
379
46.0k
  coef_bits_latch = coef->coef_bits_latch;
380
46.0k
  prev_coef_bits_latch =
381
46.0k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
101k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
75.2k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
75.2k
    if ((qtable = compptr->quant_table) == NULL)
387
5.18k
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
70.0k
    if (qtable->quantval[0] == 0 ||
390
68.8k
        qtable->quantval[Q01_POS] == 0 ||
391
67.7k
        qtable->quantval[Q10_POS] == 0 ||
392
66.3k
        qtable->quantval[Q20_POS] == 0 ||
393
65.3k
        qtable->quantval[Q11_POS] == 0 ||
394
64.1k
        qtable->quantval[Q02_POS] == 0 ||
395
63.1k
        qtable->quantval[Q03_POS] == 0 ||
396
62.0k
        qtable->quantval[Q12_POS] == 0 ||
397
60.1k
        qtable->quantval[Q21_POS] == 0 ||
398
59.2k
        qtable->quantval[Q30_POS] == 0)
399
11.6k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
58.3k
    coef_bits = cinfo->coef_bits[ci];
402
58.3k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
58.3k
    if (coef_bits[0] < 0)
404
2.57k
      return FALSE;
405
55.8k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
558k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
502k
      if (cinfo->input_scan_number > 1)
409
448k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
54.1k
      else
411
54.1k
        prev_coef_bits_latch[coefi] = -1;
412
502k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
502k
      if (coef_bits[coefi] != 0)
414
477k
        smoothing_useful = TRUE;
415
502k
    }
416
55.8k
    coef_bits_latch += SAVED_COEFS;
417
55.8k
    prev_coef_bits_latch += SAVED_COEFS;
418
55.8k
  }
419
420
26.6k
  return smoothing_useful;
421
46.0k
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
361
9.45k
{
362
9.45k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
363
9.45k
  boolean smoothing_useful = FALSE;
364
9.45k
  int ci, coefi;
365
9.45k
  jpeg_component_info *compptr;
366
9.45k
  JQUANT_TBL *qtable;
367
9.45k
  int *coef_bits, *prev_coef_bits;
368
9.45k
  int *coef_bits_latch, *prev_coef_bits_latch;
369
370
9.45k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
371
1.81k
    return FALSE;
372
373
  /* Allocate latch area if not already done */
374
7.63k
  if (coef->coef_bits_latch == NULL)
375
7.63k
    coef->coef_bits_latch = (int *)
376
7.63k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
377
7.63k
                                  cinfo->num_components * 2 *
378
7.63k
                                  (SAVED_COEFS * sizeof(int)));
379
7.63k
  coef_bits_latch = coef->coef_bits_latch;
380
7.63k
  prev_coef_bits_latch =
381
7.63k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
382
383
12.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
384
8.56k
       ci++, compptr++) {
385
    /* All components' quantization values must already be latched. */
386
8.56k
    if ((qtable = compptr->quant_table) == NULL)
387
642
      return FALSE;
388
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
389
7.92k
    if (qtable->quantval[0] == 0 ||
390
7.60k
        qtable->quantval[Q01_POS] == 0 ||
391
7.29k
        qtable->quantval[Q10_POS] == 0 ||
392
6.97k
        qtable->quantval[Q20_POS] == 0 ||
393
6.72k
        qtable->quantval[Q11_POS] == 0 ||
394
6.51k
        qtable->quantval[Q02_POS] == 0 ||
395
6.37k
        qtable->quantval[Q03_POS] == 0 ||
396
6.19k
        qtable->quantval[Q12_POS] == 0 ||
397
6.01k
        qtable->quantval[Q21_POS] == 0 ||
398
5.77k
        qtable->quantval[Q30_POS] == 0)
399
2.26k
      return FALSE;
400
    /* DC values must be at least partly known for all components. */
401
5.65k
    coef_bits = cinfo->coef_bits[ci];
402
5.65k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
403
5.65k
    if (coef_bits[0] < 0)
404
685
      return FALSE;
405
4.97k
    coef_bits_latch[0] = coef_bits[0];
406
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
407
49.7k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
408
44.7k
      if (cinfo->input_scan_number > 1)
409
24.2k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
410
20.5k
      else
411
20.5k
        prev_coef_bits_latch[coefi] = -1;
412
44.7k
      coef_bits_latch[coefi] = coef_bits[coefi];
413
44.7k
      if (coef_bits[coefi] != 0)
414
42.5k
        smoothing_useful = TRUE;
415
44.7k
    }
416
4.97k
    coef_bits_latch += SAVED_COEFS;
417
4.97k
    prev_coef_bits_latch += SAVED_COEFS;
418
4.97k
  }
419
420
4.04k
  return smoothing_useful;
421
7.63k
}
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
6.14M
{
431
6.14M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
6.14M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
6.14M
  JDIMENSION block_num, last_block_column;
434
6.14M
  int ci, block_row, block_rows, access_rows, image_block_row,
435
6.14M
    image_block_rows;
436
6.14M
  JBLOCKARRAY buffer;
437
6.14M
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
6.14M
  JBLOCKROW next_block_row, next_next_block_row;
439
6.14M
  _JSAMPARRAY output_ptr;
440
6.14M
  JDIMENSION output_col;
441
6.14M
  jpeg_component_info *compptr;
442
6.14M
  _inverse_DCT_method_ptr inverse_DCT;
443
6.14M
  boolean change_dc;
444
6.14M
  JCOEF *workspace;
445
6.14M
  int *coef_bits;
446
6.14M
  JQUANT_TBL *quanttbl;
447
6.14M
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
6.14M
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
6.14M
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
6.14M
      DC25;
451
6.14M
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
6.14M
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
8.97M
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
8.95M
         !cinfo->inputctl->eoi_reached) {
459
5.85M
    if (cinfo->input_scan_number == cinfo->output_scan_number) {
460
      /* If input is working on current scan, we ordinarily want it to
461
       * have completed the current row.  But if input scan is DC,
462
       * we want it to keep two rows ahead so that next two block rows' DC
463
       * values are up to date.
464
       */
465
5.85M
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
466
5.85M
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
467
3.01M
        break;
468
5.85M
    }
469
2.84M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
470
9.92k
      return JPEG_SUSPENDED;
471
2.84M
  }
472
473
  /* OK, output from the virtual arrays. */
474
16.1M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
9.96M
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
9.96M
    if (!compptr->component_needed)
478
152k
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
9.81M
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
9.73M
      block_rows = compptr->v_samp_factor;
482
9.73M
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
9.73M
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
34.4k
      block_rows = compptr->v_samp_factor;
485
34.4k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
50.3k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
50.3k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
50.3k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
50.3k
      access_rows = block_rows; /* this iMCU row only */
491
50.3k
    }
492
    /* Align the virtual buffer for this component. */
493
9.81M
    if (cinfo->output_iMCU_row > 1) {
494
9.73M
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
9.73M
      buffer = (*cinfo->mem->access_virt_barray)
496
9.73M
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
9.73M
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
9.73M
         (JDIMENSION)access_rows, FALSE);
499
9.73M
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
9.73M
    } else if (cinfo->output_iMCU_row > 0) {
501
37.2k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
37.2k
      buffer = (*cinfo->mem->access_virt_barray)
503
37.2k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
37.2k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
37.2k
         (JDIMENSION)access_rows, FALSE);
506
37.2k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
47.9k
    } else {
508
47.9k
      buffer = (*cinfo->mem->access_virt_barray)
509
47.9k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
47.9k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
47.9k
    }
512
    /* Fetch component-dependent info.
513
     * If the current scan is incomplete, then we use the component-dependent
514
     * info from the previous scan.
515
     */
516
9.81M
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
4.93M
      coef_bits =
518
4.93M
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
4.87M
    else
520
4.87M
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
9.81M
    change_dc =
524
9.81M
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
7.89M
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
7.29M
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
9.81M
    quanttbl = compptr->quant_table;
529
9.81M
    Q00 = quanttbl->quantval[0];
530
9.81M
    Q01 = quanttbl->quantval[Q01_POS];
531
9.81M
    Q10 = quanttbl->quantval[Q10_POS];
532
9.81M
    Q20 = quanttbl->quantval[Q20_POS];
533
9.81M
    Q11 = quanttbl->quantval[Q11_POS];
534
9.81M
    Q02 = quanttbl->quantval[Q02_POS];
535
9.81M
    if (change_dc) {
536
7.00M
      Q03 = quanttbl->quantval[Q03_POS];
537
7.00M
      Q12 = quanttbl->quantval[Q12_POS];
538
7.00M
      Q21 = quanttbl->quantval[Q21_POS];
539
7.00M
      Q30 = quanttbl->quantval[Q30_POS];
540
7.00M
    }
541
9.81M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
9.81M
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
9.81M
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
25.2M
    for (block_row = 0; block_row < block_rows; block_row++) {
546
15.4M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
15.4M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
15.4M
      if (image_block_row > 0)
550
15.4M
        prev_block_row =
551
15.4M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
47.9k
      else
553
47.9k
        prev_block_row = buffer_ptr;
554
555
15.4M
      if (image_block_row > 1)
556
15.3M
        prev_prev_block_row =
557
15.3M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
91.7k
      else
559
91.7k
        prev_prev_block_row = prev_block_row;
560
561
15.4M
      if (image_block_row < image_block_rows - 1)
562
15.4M
        next_block_row =
563
15.4M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
50.3k
      else
565
50.3k
        next_block_row = buffer_ptr;
566
567
15.4M
      if (image_block_row < image_block_rows - 2)
568
15.3M
        next_next_block_row =
569
15.3M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
81.4k
      else
571
81.4k
        next_next_block_row = next_block_row;
572
573
      /* We fetch the surrounding DC values using a sliding-register approach.
574
       * Initialize all 25 here so as to do the right thing on narrow pics.
575
       */
576
15.4M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
15.4M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
15.4M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
15.4M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
15.4M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
15.4M
      output_col = 0;
582
15.4M
      last_block_column = compptr->width_in_blocks - 1;
583
15.4M
      for (block_num = cinfo->master->first_MCU_col[ci];
584
114M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
98.8M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
98.8M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
15.4M
            block_num < last_block_column) {
590
6.88M
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
6.88M
          DC09 = DC10 = (int)prev_block_row[1][0];
592
6.88M
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
6.88M
          DC19 = DC20 = (int)next_block_row[1][0];
594
6.88M
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
6.88M
        }
596
98.8M
        if (block_num + 1 < last_block_column) {
597
76.5M
          DC05 = (int)prev_prev_block_row[2][0];
598
76.5M
          DC10 = (int)prev_block_row[2][0];
599
76.5M
          DC15 = (int)buffer_ptr[2][0];
600
76.5M
          DC20 = (int)next_block_row[2][0];
601
76.5M
          DC25 = (int)next_next_block_row[2][0];
602
76.5M
        }
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
98.8M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
90.6M
          num = Q00 * (change_dc ?
616
54.9M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
54.9M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
54.9M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
54.9M
                 DC21 - DC22 + DC24 + DC25) :
620
90.6M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
90.6M
          if (num >= 0) {
622
67.3M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
67.3M
            if (Al > 0 && pred >= (1 << Al))
624
6.18M
              pred = (1 << Al) - 1;
625
67.3M
          } else {
626
23.2M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
23.2M
            if (Al > 0 && pred >= (1 << Al))
628
4.54M
              pred = (1 << Al) - 1;
629
23.2M
            pred = -pred;
630
23.2M
          }
631
90.6M
          workspace[1] = (JCOEF)pred;
632
90.6M
        }
633
        /* AC10 */
634
98.8M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
91.3M
          num = Q00 * (change_dc ?
636
54.9M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
54.9M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
54.9M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
54.9M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
91.3M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
91.3M
          if (num >= 0) {
642
63.7M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
63.7M
            if (Al > 0 && pred >= (1 << Al))
644
10.4M
              pred = (1 << Al) - 1;
645
63.7M
          } else {
646
27.6M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
27.6M
            if (Al > 0 && pred >= (1 << Al))
648
8.34M
              pred = (1 << Al) - 1;
649
27.6M
            pred = -pred;
650
27.6M
          }
651
91.3M
          workspace[8] = (JCOEF)pred;
652
91.3M
        }
653
        /* AC20 */
654
98.8M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
91.1M
          num = Q00 * (change_dc ?
656
54.9M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
54.9M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
91.1M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
91.1M
          if (num >= 0) {
660
57.9M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
57.9M
            if (Al > 0 && pred >= (1 << Al))
662
8.79M
              pred = (1 << Al) - 1;
663
57.9M
          } else {
664
33.1M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
33.1M
            if (Al > 0 && pred >= (1 << Al))
666
8.84M
              pred = (1 << Al) - 1;
667
33.1M
            pred = -pred;
668
33.1M
          }
669
91.1M
          workspace[16] = (JCOEF)pred;
670
91.1M
        }
671
        /* AC11 */
672
98.8M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
91.7M
          num = Q00 * (change_dc ?
674
54.9M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
54.9M
                 9 * DC19 + DC21 - DC25) :
676
91.7M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
36.7M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
91.7M
          if (num >= 0) {
679
70.2M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
70.2M
            if (Al > 0 && pred >= (1 << Al))
681
4.24M
              pred = (1 << Al) - 1;
682
70.2M
          } else {
683
21.4M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
21.4M
            if (Al > 0 && pred >= (1 << Al))
685
4.24M
              pred = (1 << Al) - 1;
686
21.4M
            pred = -pred;
687
21.4M
          }
688
91.7M
          workspace[9] = (JCOEF)pred;
689
91.7M
        }
690
        /* AC02 */
691
98.8M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
91.5M
          num = Q00 * (change_dc ?
693
54.9M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
54.9M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
91.5M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
91.5M
          if (num >= 0) {
697
58.1M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
58.1M
            if (Al > 0 && pred >= (1 << Al))
699
5.49M
              pred = (1 << Al) - 1;
700
58.1M
          } else {
701
33.4M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
33.4M
            if (Al > 0 && pred >= (1 << Al))
703
5.54M
              pred = (1 << Al) - 1;
704
33.4M
            pred = -pred;
705
33.4M
          }
706
91.5M
          workspace[2] = (JCOEF)pred;
707
91.5M
        }
708
98.8M
        if (change_dc) {
709
          /* AC03 */
710
54.9M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
54.9M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
54.9M
            if (num >= 0) {
713
43.4M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
43.4M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
43.4M
            } else {
717
11.4M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
11.4M
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
11.4M
              pred = -pred;
721
11.4M
            }
722
54.9M
            workspace[3] = (JCOEF)pred;
723
54.9M
          }
724
          /* AC12 */
725
54.9M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
54.9M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
54.9M
            if (num >= 0) {
728
34.8M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
34.8M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
34.8M
            } else {
732
20.0M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
20.0M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
20.0M
              pred = -pred;
736
20.0M
            }
737
54.9M
            workspace[10] = (JCOEF)pred;
738
54.9M
          }
739
          /* AC21 */
740
54.9M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
54.9M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
54.9M
            if (num >= 0) {
743
34.1M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
34.1M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
34.1M
            } else {
747
20.8M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
20.8M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
20.8M
              pred = -pred;
751
20.8M
            }
752
54.9M
            workspace[17] = (JCOEF)pred;
753
54.9M
          }
754
          /* AC30 */
755
54.9M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
54.9M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
54.9M
            if (num >= 0) {
758
41.4M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
41.4M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
41.4M
            } else {
762
13.4M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
13.4M
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
13.4M
              pred = -pred;
766
13.4M
            }
767
54.9M
            workspace[24] = (JCOEF)pred;
768
54.9M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
54.9M
          num = Q00 *
773
54.9M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
54.9M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
54.9M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
54.9M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
54.9M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
54.9M
          if (num >= 0) {
779
35.1M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
35.1M
          } else {
781
19.7M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
19.7M
            pred = -pred;
783
19.7M
          }
784
54.9M
          workspace[0] = (JCOEF)pred;
785
54.9M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
98.8M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
98.8M
                        output_col);
790
        /* Advance for next column */
791
98.8M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
98.8M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
98.8M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
98.8M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
98.8M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
98.8M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
98.8M
          prev_prev_block_row++, next_next_block_row++;
798
98.8M
        output_col += compptr->_DCT_scaled_size;
799
98.8M
      }
800
15.4M
      output_ptr += compptr->_DCT_scaled_size;
801
15.4M
    }
802
9.81M
  }
803
804
6.13M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
6.10M
    return JPEG_ROW_COMPLETED;
806
25.9k
  return JPEG_SCAN_COMPLETED;
807
6.13M
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
430
5.40M
{
431
5.40M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
5.40M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
5.40M
  JDIMENSION block_num, last_block_column;
434
5.40M
  int ci, block_row, block_rows, access_rows, image_block_row,
435
5.40M
    image_block_rows;
436
5.40M
  JBLOCKARRAY buffer;
437
5.40M
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
5.40M
  JBLOCKROW next_block_row, next_next_block_row;
439
5.40M
  _JSAMPARRAY output_ptr;
440
5.40M
  JDIMENSION output_col;
441
5.40M
  jpeg_component_info *compptr;
442
5.40M
  _inverse_DCT_method_ptr inverse_DCT;
443
5.40M
  boolean change_dc;
444
5.40M
  JCOEF *workspace;
445
5.40M
  int *coef_bits;
446
5.40M
  JQUANT_TBL *quanttbl;
447
5.40M
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
5.40M
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
5.40M
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
5.40M
      DC25;
451
5.40M
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
5.40M
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
8.23M
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
8.21M
         !cinfo->inputctl->eoi_reached) {
459
5.85M
    if (cinfo->input_scan_number == cinfo->output_scan_number) {
460
      /* If input is working on current scan, we ordinarily want it to
461
       * have completed the current row.  But if input scan is DC,
462
       * we want it to keep two rows ahead so that next two block rows' DC
463
       * values are up to date.
464
       */
465
5.85M
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
466
5.85M
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
467
3.01M
        break;
468
5.85M
    }
469
2.84M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
470
9.92k
      return JPEG_SUSPENDED;
471
2.84M
  }
472
473
  /* OK, output from the virtual arrays. */
474
14.3M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
8.95M
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
8.95M
    if (!compptr->component_needed)
478
61.3k
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
8.89M
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
8.81M
      block_rows = compptr->v_samp_factor;
482
8.81M
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
8.81M
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
31.6k
      block_rows = compptr->v_samp_factor;
485
31.6k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
47.3k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
47.3k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
47.3k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
47.3k
      access_rows = block_rows; /* this iMCU row only */
491
47.3k
    }
492
    /* Align the virtual buffer for this component. */
493
8.89M
    if (cinfo->output_iMCU_row > 1) {
494
8.81M
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
8.81M
      buffer = (*cinfo->mem->access_virt_barray)
496
8.81M
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
8.81M
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
8.81M
         (JDIMENSION)access_rows, FALSE);
499
8.81M
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
8.81M
    } else if (cinfo->output_iMCU_row > 0) {
501
34.0k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
34.0k
      buffer = (*cinfo->mem->access_virt_barray)
503
34.0k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
34.0k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
34.0k
         (JDIMENSION)access_rows, FALSE);
506
34.0k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
44.7k
    } else {
508
44.7k
      buffer = (*cinfo->mem->access_virt_barray)
509
44.7k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
44.7k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
44.7k
    }
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
8.89M
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
4.52M
      coef_bits =
518
4.52M
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
4.36M
    else
520
4.36M
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
8.89M
    change_dc =
524
8.89M
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
7.16M
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
6.58M
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
8.89M
    quanttbl = compptr->quant_table;
529
8.89M
    Q00 = quanttbl->quantval[0];
530
8.89M
    Q01 = quanttbl->quantval[Q01_POS];
531
8.89M
    Q10 = quanttbl->quantval[Q10_POS];
532
8.89M
    Q20 = quanttbl->quantval[Q20_POS];
533
8.89M
    Q11 = quanttbl->quantval[Q11_POS];
534
8.89M
    Q02 = quanttbl->quantval[Q02_POS];
535
8.89M
    if (change_dc) {
536
6.32M
      Q03 = quanttbl->quantval[Q03_POS];
537
6.32M
      Q12 = quanttbl->quantval[Q12_POS];
538
6.32M
      Q21 = quanttbl->quantval[Q21_POS];
539
6.32M
      Q30 = quanttbl->quantval[Q30_POS];
540
6.32M
    }
541
8.89M
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
8.89M
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
8.89M
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
22.8M
    for (block_row = 0; block_row < block_rows; block_row++) {
546
13.9M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
13.9M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
13.9M
      if (image_block_row > 0)
550
13.9M
        prev_block_row =
551
13.9M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
44.7k
      else
553
44.7k
        prev_block_row = buffer_ptr;
554
555
13.9M
      if (image_block_row > 1)
556
13.9M
        prev_prev_block_row =
557
13.9M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
85.3k
      else
559
85.3k
        prev_prev_block_row = prev_block_row;
560
561
13.9M
      if (image_block_row < image_block_rows - 1)
562
13.9M
        next_block_row =
563
13.9M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
47.3k
      else
565
47.3k
        next_block_row = buffer_ptr;
566
567
13.9M
      if (image_block_row < image_block_rows - 2)
568
13.9M
        next_next_block_row =
569
13.9M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
76.3k
      else
571
76.3k
        next_next_block_row = next_block_row;
572
573
      /* We fetch the surrounding DC values using a sliding-register approach.
574
       * Initialize all 25 here so as to do the right thing on narrow pics.
575
       */
576
13.9M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
13.9M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
13.9M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
13.9M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
13.9M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
13.9M
      output_col = 0;
582
13.9M
      last_block_column = compptr->width_in_blocks - 1;
583
13.9M
      for (block_num = cinfo->master->first_MCU_col[ci];
584
94.3M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
80.3M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
80.3M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
13.9M
            block_num < last_block_column) {
590
6.05M
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
6.05M
          DC09 = DC10 = (int)prev_block_row[1][0];
592
6.05M
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
6.05M
          DC19 = DC20 = (int)next_block_row[1][0];
594
6.05M
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
6.05M
        }
596
80.3M
        if (block_num + 1 < last_block_column) {
597
60.2M
          DC05 = (int)prev_prev_block_row[2][0];
598
60.2M
          DC10 = (int)prev_block_row[2][0];
599
60.2M
          DC15 = (int)buffer_ptr[2][0];
600
60.2M
          DC20 = (int)next_block_row[2][0];
601
60.2M
          DC25 = (int)next_next_block_row[2][0];
602
60.2M
        }
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
80.3M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
72.8M
          num = Q00 * (change_dc ?
616
43.3M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
43.3M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
43.3M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
43.3M
                 DC21 - DC22 + DC24 + DC25) :
620
72.8M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
72.8M
          if (num >= 0) {
622
55.4M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
55.4M
            if (Al > 0 && pred >= (1 << Al))
624
5.09M
              pred = (1 << Al) - 1;
625
55.4M
          } else {
626
17.4M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
17.4M
            if (Al > 0 && pred >= (1 << Al))
628
3.57M
              pred = (1 << Al) - 1;
629
17.4M
            pred = -pred;
630
17.4M
          }
631
72.8M
          workspace[1] = (JCOEF)pred;
632
72.8M
        }
633
        /* AC10 */
634
80.3M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
73.5M
          num = Q00 * (change_dc ?
636
43.3M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
43.3M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
43.3M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
43.3M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
73.5M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
73.5M
          if (num >= 0) {
642
52.3M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
52.3M
            if (Al > 0 && pred >= (1 << Al))
644
8.47M
              pred = (1 << Al) - 1;
645
52.3M
          } else {
646
21.1M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
21.1M
            if (Al > 0 && pred >= (1 << Al))
648
7.00M
              pred = (1 << Al) - 1;
649
21.1M
            pred = -pred;
650
21.1M
          }
651
73.5M
          workspace[8] = (JCOEF)pred;
652
73.5M
        }
653
        /* AC20 */
654
80.3M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
73.4M
          num = Q00 * (change_dc ?
656
43.3M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
43.3M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
73.4M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
73.4M
          if (num >= 0) {
660
47.6M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
47.6M
            if (Al > 0 && pred >= (1 << Al))
662
7.09M
              pred = (1 << Al) - 1;
663
47.6M
          } else {
664
25.7M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
25.7M
            if (Al > 0 && pred >= (1 << Al))
666
7.13M
              pred = (1 << Al) - 1;
667
25.7M
            pred = -pred;
668
25.7M
          }
669
73.4M
          workspace[16] = (JCOEF)pred;
670
73.4M
        }
671
        /* AC11 */
672
80.3M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
73.9M
          num = Q00 * (change_dc ?
674
43.3M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
43.3M
                 9 * DC19 + DC21 - DC25) :
676
73.9M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
30.6M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
73.9M
          if (num >= 0) {
679
57.3M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
57.3M
            if (Al > 0 && pred >= (1 << Al))
681
3.52M
              pred = (1 << Al) - 1;
682
57.3M
          } else {
683
16.5M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
16.5M
            if (Al > 0 && pred >= (1 << Al))
685
3.52M
              pred = (1 << Al) - 1;
686
16.5M
            pred = -pred;
687
16.5M
          }
688
73.9M
          workspace[9] = (JCOEF)pred;
689
73.9M
        }
690
        /* AC02 */
691
80.3M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
73.7M
          num = Q00 * (change_dc ?
693
43.3M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
43.3M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
73.7M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
73.7M
          if (num >= 0) {
697
47.6M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
47.6M
            if (Al > 0 && pred >= (1 << Al))
699
4.40M
              pred = (1 << Al) - 1;
700
47.6M
          } else {
701
26.1M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
26.1M
            if (Al > 0 && pred >= (1 << Al))
703
4.43M
              pred = (1 << Al) - 1;
704
26.1M
            pred = -pred;
705
26.1M
          }
706
73.7M
          workspace[2] = (JCOEF)pred;
707
73.7M
        }
708
80.3M
        if (change_dc) {
709
          /* AC03 */
710
43.3M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
43.3M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
43.3M
            if (num >= 0) {
713
35.4M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
35.4M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
35.4M
            } else {
717
7.84M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
7.84M
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
7.84M
              pred = -pred;
721
7.84M
            }
722
43.3M
            workspace[3] = (JCOEF)pred;
723
43.3M
          }
724
          /* AC12 */
725
43.3M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
43.3M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
43.3M
            if (num >= 0) {
728
28.2M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
28.2M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
28.2M
            } else {
732
15.1M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
15.1M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
15.1M
              pred = -pred;
736
15.1M
            }
737
43.3M
            workspace[10] = (JCOEF)pred;
738
43.3M
          }
739
          /* AC21 */
740
43.3M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
43.3M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
43.3M
            if (num >= 0) {
743
27.6M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
27.6M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
27.6M
            } else {
747
15.6M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
15.6M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
15.6M
              pred = -pred;
751
15.6M
            }
752
43.3M
            workspace[17] = (JCOEF)pred;
753
43.3M
          }
754
          /* AC30 */
755
43.3M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
43.3M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
43.3M
            if (num >= 0) {
758
33.7M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
33.7M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
33.7M
            } else {
762
9.51M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
9.51M
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
9.51M
              pred = -pred;
766
9.51M
            }
767
43.3M
            workspace[24] = (JCOEF)pred;
768
43.3M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
43.3M
          num = Q00 *
773
43.3M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
43.3M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
43.3M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
43.3M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
43.3M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
43.3M
          if (num >= 0) {
779
28.3M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
28.3M
          } else {
781
14.9M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
14.9M
            pred = -pred;
783
14.9M
          }
784
43.3M
          workspace[0] = (JCOEF)pred;
785
43.3M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
80.3M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
80.3M
                        output_col);
790
        /* Advance for next column */
791
80.3M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
80.3M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
80.3M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
80.3M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
80.3M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
80.3M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
80.3M
          prev_prev_block_row++, next_next_block_row++;
798
80.3M
        output_col += compptr->_DCT_scaled_size;
799
80.3M
      }
800
13.9M
      output_ptr += compptr->_DCT_scaled_size;
801
13.9M
    }
802
8.89M
  }
803
804
5.39M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
5.36M
    return JPEG_ROW_COMPLETED;
806
23.2k
  return JPEG_SCAN_COMPLETED;
807
5.39M
}
jdcoefct-12.c:decompress_smooth_data
Line
Count
Source
430
743k
{
431
743k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
432
743k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
433
743k
  JDIMENSION block_num, last_block_column;
434
743k
  int ci, block_row, block_rows, access_rows, image_block_row,
435
743k
    image_block_rows;
436
743k
  JBLOCKARRAY buffer;
437
743k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
438
743k
  JBLOCKROW next_block_row, next_next_block_row;
439
743k
  _JSAMPARRAY output_ptr;
440
743k
  JDIMENSION output_col;
441
743k
  jpeg_component_info *compptr;
442
743k
  _inverse_DCT_method_ptr inverse_DCT;
443
743k
  boolean change_dc;
444
743k
  JCOEF *workspace;
445
743k
  int *coef_bits;
446
743k
  JQUANT_TBL *quanttbl;
447
743k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
448
743k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
449
743k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
450
743k
      DC25;
451
743k
  int Al, pred;
452
453
  /* Keep a local variable to avoid looking it up more than once */
454
743k
  workspace = coef->workspace;
455
456
  /* Force some input to be done if we are getting ahead of the input. */
457
743k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
458
743k
         !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.75M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
475
1.00M
       ci++, compptr++) {
476
    /* Don't bother to IDCT an uninteresting component. */
477
1.00M
    if (!compptr->component_needed)
478
91.3k
      continue;
479
    /* Count non-dummy DCT block rows in this iMCU row. */
480
918k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
481
912k
      block_rows = compptr->v_samp_factor;
482
912k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
483
912k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
484
2.77k
      block_rows = compptr->v_samp_factor;
485
2.77k
      access_rows = block_rows * 2; /* this and next iMCU row */
486
3.02k
    } else {
487
      /* NB: can't use last_row_height here; it is input-side-dependent! */
488
3.02k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
489
3.02k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
490
3.02k
      access_rows = block_rows; /* this iMCU row only */
491
3.02k
    }
492
    /* Align the virtual buffer for this component. */
493
918k
    if (cinfo->output_iMCU_row > 1) {
494
911k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
495
911k
      buffer = (*cinfo->mem->access_virt_barray)
496
911k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
497
911k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
498
911k
         (JDIMENSION)access_rows, FALSE);
499
911k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
500
911k
    } else if (cinfo->output_iMCU_row > 0) {
501
3.22k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
502
3.22k
      buffer = (*cinfo->mem->access_virt_barray)
503
3.22k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
504
3.22k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
505
3.22k
         (JDIMENSION)access_rows, FALSE);
506
3.22k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
507
3.23k
    } else {
508
3.23k
      buffer = (*cinfo->mem->access_virt_barray)
509
3.23k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
510
3.23k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
511
3.23k
    }
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
918k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
517
409k
      coef_bits =
518
409k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
519
508k
    else
520
508k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
521
522
    /* We only do DC interpolation if no AC coefficient data is available. */
523
918k
    change_dc =
524
918k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
525
724k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
526
707k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
527
528
918k
    quanttbl = compptr->quant_table;
529
918k
    Q00 = quanttbl->quantval[0];
530
918k
    Q01 = quanttbl->quantval[Q01_POS];
531
918k
    Q10 = quanttbl->quantval[Q10_POS];
532
918k
    Q20 = quanttbl->quantval[Q20_POS];
533
918k
    Q11 = quanttbl->quantval[Q11_POS];
534
918k
    Q02 = quanttbl->quantval[Q02_POS];
535
918k
    if (change_dc) {
536
683k
      Q03 = quanttbl->quantval[Q03_POS];
537
683k
      Q12 = quanttbl->quantval[Q12_POS];
538
683k
      Q21 = quanttbl->quantval[Q21_POS];
539
683k
      Q30 = quanttbl->quantval[Q30_POS];
540
683k
    }
541
918k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
542
918k
    output_ptr = output_buf[ci];
543
    /* Loop over all DCT blocks to be processed. */
544
918k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
545
2.38M
    for (block_row = 0; block_row < block_rows; block_row++) {
546
1.46M
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
547
1.46M
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
548
549
1.46M
      if (image_block_row > 0)
550
1.46M
        prev_block_row =
551
1.46M
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
552
3.23k
      else
553
3.23k
        prev_block_row = buffer_ptr;
554
555
1.46M
      if (image_block_row > 1)
556
1.46M
        prev_prev_block_row =
557
1.46M
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
558
6.38k
      else
559
6.38k
        prev_prev_block_row = prev_block_row;
560
561
1.46M
      if (image_block_row < image_block_rows - 1)
562
1.46M
        next_block_row =
563
1.46M
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
564
3.02k
      else
565
3.02k
        next_block_row = buffer_ptr;
566
567
1.46M
      if (image_block_row < image_block_rows - 2)
568
1.46M
        next_next_block_row =
569
1.46M
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
570
5.17k
      else
571
5.17k
        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.46M
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
577
1.46M
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
578
1.46M
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
579
1.46M
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
580
1.46M
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
581
1.46M
      output_col = 0;
582
1.46M
      last_block_column = compptr->width_in_blocks - 1;
583
1.46M
      for (block_num = cinfo->master->first_MCU_col[ci];
584
19.9M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
585
        /* Fetch current DCT block into workspace so we can modify it. */
586
18.5M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
587
        /* Update DC values */
588
18.5M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
589
1.46M
            block_num < last_block_column) {
590
834k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
591
834k
          DC09 = DC10 = (int)prev_block_row[1][0];
592
834k
          DC14 = DC15 = (int)buffer_ptr[1][0];
593
834k
          DC19 = DC20 = (int)next_block_row[1][0];
594
834k
          DC24 = DC25 = (int)next_next_block_row[1][0];
595
834k
        }
596
18.5M
        if (block_num + 1 < last_block_column) {
597
16.2M
          DC05 = (int)prev_prev_block_row[2][0];
598
16.2M
          DC10 = (int)prev_block_row[2][0];
599
16.2M
          DC15 = (int)buffer_ptr[2][0];
600
16.2M
          DC20 = (int)next_block_row[2][0];
601
16.2M
          DC25 = (int)next_next_block_row[2][0];
602
16.2M
        }
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
18.5M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
615
17.7M
          num = Q00 * (change_dc ?
616
11.6M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
617
11.6M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
618
11.6M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
619
11.6M
                 DC21 - DC22 + DC24 + DC25) :
620
17.7M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
621
17.7M
          if (num >= 0) {
622
11.9M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
623
11.9M
            if (Al > 0 && pred >= (1 << Al))
624
1.08M
              pred = (1 << Al) - 1;
625
11.9M
          } else {
626
5.80M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
627
5.80M
            if (Al > 0 && pred >= (1 << Al))
628
976k
              pred = (1 << Al) - 1;
629
5.80M
            pred = -pred;
630
5.80M
          }
631
17.7M
          workspace[1] = (JCOEF)pred;
632
17.7M
        }
633
        /* AC10 */
634
18.5M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
635
17.7M
          num = Q00 * (change_dc ?
636
11.6M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
637
11.6M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
638
11.6M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
639
11.6M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
640
17.7M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
641
17.7M
          if (num >= 0) {
642
11.3M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
643
11.3M
            if (Al > 0 && pred >= (1 << Al))
644
1.94M
              pred = (1 << Al) - 1;
645
11.3M
          } else {
646
6.45M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
647
6.45M
            if (Al > 0 && pred >= (1 << Al))
648
1.34M
              pred = (1 << Al) - 1;
649
6.45M
            pred = -pred;
650
6.45M
          }
651
17.7M
          workspace[8] = (JCOEF)pred;
652
17.7M
        }
653
        /* AC20 */
654
18.5M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
655
17.7M
          num = Q00 * (change_dc ?
656
11.6M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
657
11.6M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
658
17.7M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
659
17.7M
          if (num >= 0) {
660
10.3M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
661
10.3M
            if (Al > 0 && pred >= (1 << Al))
662
1.70M
              pred = (1 << Al) - 1;
663
10.3M
          } else {
664
7.39M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
665
7.39M
            if (Al > 0 && pred >= (1 << Al))
666
1.71M
              pred = (1 << Al) - 1;
667
7.39M
            pred = -pred;
668
7.39M
          }
669
17.7M
          workspace[16] = (JCOEF)pred;
670
17.7M
        }
671
        /* AC11 */
672
18.5M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
673
17.7M
          num = Q00 * (change_dc ?
674
11.6M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
675
11.6M
                 9 * DC19 + DC21 - DC25) :
676
17.7M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
677
6.12M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
678
17.7M
          if (num >= 0) {
679
12.9M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
680
12.9M
            if (Al > 0 && pred >= (1 << Al))
681
724k
              pred = (1 << Al) - 1;
682
12.9M
          } else {
683
4.84M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
684
4.84M
            if (Al > 0 && pred >= (1 << Al))
685
714k
              pred = (1 << Al) - 1;
686
4.84M
            pred = -pred;
687
4.84M
          }
688
17.7M
          workspace[9] = (JCOEF)pred;
689
17.7M
        }
690
        /* AC02 */
691
18.5M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
692
17.7M
          num = Q00 * (change_dc ?
693
11.6M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
694
11.6M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
695
17.7M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
696
17.7M
          if (num >= 0) {
697
10.4M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
698
10.4M
            if (Al > 0 && pred >= (1 << Al))
699
1.09M
              pred = (1 << Al) - 1;
700
10.4M
          } else {
701
7.31M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
702
7.31M
            if (Al > 0 && pred >= (1 << Al))
703
1.11M
              pred = (1 << Al) - 1;
704
7.31M
            pred = -pred;
705
7.31M
          }
706
17.7M
          workspace[2] = (JCOEF)pred;
707
17.7M
        }
708
18.5M
        if (change_dc) {
709
          /* AC03 */
710
11.6M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
711
11.6M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
712
11.6M
            if (num >= 0) {
713
8.00M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
714
8.00M
              if (Al > 0 && pred >= (1 << Al))
715
0
                pred = (1 << Al) - 1;
716
8.00M
            } else {
717
3.62M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
718
3.62M
              if (Al > 0 && pred >= (1 << Al))
719
0
                pred = (1 << Al) - 1;
720
3.62M
              pred = -pred;
721
3.62M
            }
722
11.6M
            workspace[3] = (JCOEF)pred;
723
11.6M
          }
724
          /* AC12 */
725
11.6M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
726
11.6M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
727
11.6M
            if (num >= 0) {
728
6.64M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
729
6.64M
              if (Al > 0 && pred >= (1 << Al))
730
0
                pred = (1 << Al) - 1;
731
6.64M
            } else {
732
4.98M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
733
4.98M
              if (Al > 0 && pred >= (1 << Al))
734
0
                pred = (1 << Al) - 1;
735
4.98M
              pred = -pred;
736
4.98M
            }
737
11.6M
            workspace[10] = (JCOEF)pred;
738
11.6M
          }
739
          /* AC21 */
740
11.6M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
741
11.6M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
742
11.6M
            if (num >= 0) {
743
6.47M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
744
6.47M
              if (Al > 0 && pred >= (1 << Al))
745
0
                pred = (1 << Al) - 1;
746
6.47M
            } else {
747
5.15M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
748
5.15M
              if (Al > 0 && pred >= (1 << Al))
749
0
                pred = (1 << Al) - 1;
750
5.15M
              pred = -pred;
751
5.15M
            }
752
11.6M
            workspace[17] = (JCOEF)pred;
753
11.6M
          }
754
          /* AC30 */
755
11.6M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
756
11.6M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
757
11.6M
            if (num >= 0) {
758
7.66M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
759
7.66M
              if (Al > 0 && pred >= (1 << Al))
760
0
                pred = (1 << Al) - 1;
761
7.66M
            } else {
762
3.96M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
763
3.96M
              if (Al > 0 && pred >= (1 << Al))
764
0
                pred = (1 << Al) - 1;
765
3.96M
              pred = -pred;
766
3.96M
            }
767
11.6M
            workspace[24] = (JCOEF)pred;
768
11.6M
          }
769
          /* coef_bits[0] is non-negative.  Otherwise this function would not
770
           * be called.
771
           */
772
11.6M
          num = Q00 *
773
11.6M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
774
11.6M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
775
11.6M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
776
11.6M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
777
11.6M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
778
11.6M
          if (num >= 0) {
779
6.80M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
780
6.80M
          } else {
781
4.82M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
782
4.82M
            pred = -pred;
783
4.82M
          }
784
11.6M
          workspace[0] = (JCOEF)pred;
785
11.6M
        }  /* change_dc */
786
787
        /* OK, do the IDCT */
788
18.5M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
789
18.5M
                        output_col);
790
        /* Advance for next column */
791
18.5M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
792
18.5M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
793
18.5M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
794
18.5M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
795
18.5M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
796
18.5M
        buffer_ptr++, prev_block_row++, next_block_row++,
797
18.5M
          prev_prev_block_row++, next_next_block_row++;
798
18.5M
        output_col += compptr->_DCT_scaled_size;
799
18.5M
      }
800
1.46M
      output_ptr += compptr->_DCT_scaled_size;
801
1.46M
    }
802
918k
  }
803
804
743k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
805
740k
    return JPEG_ROW_COMPLETED;
806
2.66k
  return JPEG_SCAN_COMPLETED;
807
743k
}
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
165k
{
819
165k
  my_coef_ptr coef;
820
821
165k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
24
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
165k
  coef = (my_coef_ptr)
825
165k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
165k
                                sizeof(my_coef_controller));
827
165k
  memset(coef, 0, sizeof(my_coef_controller));
828
165k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
165k
  coef->pub.start_input_pass = start_input_pass;
830
165k
  coef->pub.start_output_pass = start_output_pass;
831
165k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
165k
  coef->coef_bits_latch = NULL;
833
165k
#endif
834
835
  /* Create the coefficient buffer. */
836
165k
  if (need_full_buffer) {
837
133k
#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
133k
    int ci, access_rows;
842
133k
    jpeg_component_info *compptr;
843
844
386k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
253k
         ci++, compptr++) {
846
253k
      access_rows = compptr->v_samp_factor;
847
253k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
253k
      if (cinfo->progressive_mode)
850
134k
        access_rows *= 5;
851
253k
#endif
852
253k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
253k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
253k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
253k
                               (long)compptr->h_samp_factor),
856
253k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
253k
                               (long)compptr->v_samp_factor),
858
253k
         (JDIMENSION)access_rows);
859
253k
    }
860
133k
    coef->pub.consume_data = consume_data;
861
133k
    coef->pub._decompress_data = decompress_data;
862
133k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
133k
  } else {
867
    /* We only need a single-MCU buffer. */
868
31.5k
    JBLOCKROW buffer;
869
31.5k
    int i;
870
871
31.5k
    buffer = (JBLOCKROW)
872
31.5k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
31.5k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
346k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
314k
      coef->MCU_buffer[i] = buffer + i;
876
314k
    }
877
31.5k
    coef->pub.consume_data = dummy_consume_data;
878
31.5k
    coef->pub._decompress_data = decompress_onepass;
879
31.5k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
31.5k
  }
881
882
  /* Allocate the workspace buffer */
883
165k
  coef->workspace = (JCOEF *)
884
165k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
165k
                                sizeof(JCOEF) * DCTSIZE2);
886
165k
}
jinit_d_coef_controller
Line
Count
Source
818
129k
{
819
129k
  my_coef_ptr coef;
820
821
129k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
24
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
129k
  coef = (my_coef_ptr)
825
129k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
129k
                                sizeof(my_coef_controller));
827
129k
  memset(coef, 0, sizeof(my_coef_controller));
828
129k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
129k
  coef->pub.start_input_pass = start_input_pass;
830
129k
  coef->pub.start_output_pass = start_output_pass;
831
129k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
129k
  coef->coef_bits_latch = NULL;
833
129k
#endif
834
835
  /* Create the coefficient buffer. */
836
129k
  if (need_full_buffer) {
837
103k
#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
103k
    int ci, access_rows;
842
103k
    jpeg_component_info *compptr;
843
844
302k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
198k
         ci++, compptr++) {
846
198k
      access_rows = compptr->v_samp_factor;
847
198k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
198k
      if (cinfo->progressive_mode)
850
107k
        access_rows *= 5;
851
198k
#endif
852
198k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
198k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
198k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
198k
                               (long)compptr->h_samp_factor),
856
198k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
198k
                               (long)compptr->v_samp_factor),
858
198k
         (JDIMENSION)access_rows);
859
198k
    }
860
103k
    coef->pub.consume_data = consume_data;
861
103k
    coef->pub._decompress_data = decompress_data;
862
103k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
103k
  } else {
867
    /* We only need a single-MCU buffer. */
868
25.8k
    JBLOCKROW buffer;
869
25.8k
    int i;
870
871
25.8k
    buffer = (JBLOCKROW)
872
25.8k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
25.8k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
284k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
258k
      coef->MCU_buffer[i] = buffer + i;
876
258k
    }
877
25.8k
    coef->pub.consume_data = dummy_consume_data;
878
25.8k
    coef->pub._decompress_data = decompress_onepass;
879
25.8k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
25.8k
  }
881
882
  /* Allocate the workspace buffer */
883
129k
  coef->workspace = (JCOEF *)
884
129k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
129k
                                sizeof(JCOEF) * DCTSIZE2);
886
129k
}
j12init_d_coef_controller
Line
Count
Source
818
35.2k
{
819
35.2k
  my_coef_ptr coef;
820
821
35.2k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
822
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
823
824
35.2k
  coef = (my_coef_ptr)
825
35.2k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
826
35.2k
                                sizeof(my_coef_controller));
827
35.2k
  memset(coef, 0, sizeof(my_coef_controller));
828
35.2k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
829
35.2k
  coef->pub.start_input_pass = start_input_pass;
830
35.2k
  coef->pub.start_output_pass = start_output_pass;
831
35.2k
#ifdef BLOCK_SMOOTHING_SUPPORTED
832
35.2k
  coef->coef_bits_latch = NULL;
833
35.2k
#endif
834
835
  /* Create the coefficient buffer. */
836
35.2k
  if (need_full_buffer) {
837
29.5k
#ifdef D_MULTISCAN_FILES_SUPPORTED
838
    /* Allocate a full-image virtual array for each component, */
839
    /* padded to a multiple of samp_factor DCT blocks in each direction. */
840
    /* Note we ask for a pre-zeroed array. */
841
29.5k
    int ci, access_rows;
842
29.5k
    jpeg_component_info *compptr;
843
844
83.8k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
845
54.2k
         ci++, compptr++) {
846
54.2k
      access_rows = compptr->v_samp_factor;
847
54.2k
#ifdef BLOCK_SMOOTHING_SUPPORTED
848
      /* If block smoothing could be used, need a bigger window */
849
54.2k
      if (cinfo->progressive_mode)
850
27.4k
        access_rows *= 5;
851
54.2k
#endif
852
54.2k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
853
54.2k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
854
54.2k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
855
54.2k
                               (long)compptr->h_samp_factor),
856
54.2k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
857
54.2k
                               (long)compptr->v_samp_factor),
858
54.2k
         (JDIMENSION)access_rows);
859
54.2k
    }
860
29.5k
    coef->pub.consume_data = consume_data;
861
29.5k
    coef->pub._decompress_data = decompress_data;
862
29.5k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
863
#else
864
    ERREXIT(cinfo, JERR_NOT_COMPILED);
865
#endif
866
29.5k
  } else {
867
    /* We only need a single-MCU buffer. */
868
5.62k
    JBLOCKROW buffer;
869
5.62k
    int i;
870
871
5.62k
    buffer = (JBLOCKROW)
872
5.62k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
873
5.62k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
874
61.8k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
875
56.2k
      coef->MCU_buffer[i] = buffer + i;
876
56.2k
    }
877
5.62k
    coef->pub.consume_data = dummy_consume_data;
878
5.62k
    coef->pub._decompress_data = decompress_onepass;
879
5.62k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
880
5.62k
  }
881
882
  /* Allocate the workspace buffer */
883
35.2k
  coef->workspace = (JCOEF *)
884
35.2k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
885
35.2k
                                sizeof(JCOEF) * DCTSIZE2);
886
35.2k
}