Coverage Report

Created: 2026-04-15 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo/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-2026, 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
#ifdef WITH_PROFILE
27
#include "tjutil.h"
28
#endif
29
30
31
/* Forward declarations */
32
METHODDEF(int) decompress_onepass(j_decompress_ptr cinfo,
33
                                  _JSAMPIMAGE output_buf);
34
#ifdef D_MULTISCAN_FILES_SUPPORTED
35
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
36
#endif
37
#ifdef BLOCK_SMOOTHING_SUPPORTED
38
LOCAL(boolean) smoothing_ok(j_decompress_ptr cinfo);
39
METHODDEF(int) decompress_smooth_data(j_decompress_ptr cinfo,
40
                                      _JSAMPIMAGE output_buf);
41
#endif
42
43
44
/*
45
 * Initialize for an input processing pass.
46
 */
47
48
METHODDEF(void)
49
start_input_pass(j_decompress_ptr cinfo)
50
101k
{
51
101k
  cinfo->input_iMCU_row = 0;
52
101k
  start_iMCU_row(cinfo);
53
101k
}
jdcoefct-8.c:start_input_pass
Line
Count
Source
50
100k
{
51
100k
  cinfo->input_iMCU_row = 0;
52
100k
  start_iMCU_row(cinfo);
53
100k
}
jdcoefct-12.c:start_input_pass
Line
Count
Source
50
1.05k
{
51
1.05k
  cinfo->input_iMCU_row = 0;
52
1.05k
  start_iMCU_row(cinfo);
53
1.05k
}
54
55
56
/*
57
 * Initialize for an output processing pass.
58
 */
59
60
METHODDEF(void)
61
start_output_pass(j_decompress_ptr cinfo)
62
83.0k
{
63
83.0k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
83.0k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
65
66
  /* If multipass, check to see whether to use block smoothing on this pass */
67
83.0k
  if (coef->pub.coef_arrays != NULL) {
68
24.6k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
4.06k
      coef->pub._decompress_data = decompress_smooth_data;
70
20.5k
    else
71
20.5k
      coef->pub._decompress_data = decompress_data;
72
24.6k
  }
73
83.0k
#endif
74
83.0k
  cinfo->output_iMCU_row = 0;
75
83.0k
}
jdcoefct-8.c:start_output_pass
Line
Count
Source
62
82.4k
{
63
82.4k
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
82.4k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
65
66
  /* If multipass, check to see whether to use block smoothing on this pass */
67
82.4k
  if (coef->pub.coef_arrays != NULL) {
68
24.1k
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
3.72k
      coef->pub._decompress_data = decompress_smooth_data;
70
20.4k
    else
71
20.4k
      coef->pub._decompress_data = decompress_data;
72
24.1k
  }
73
82.4k
#endif
74
82.4k
  cinfo->output_iMCU_row = 0;
75
82.4k
}
jdcoefct-12.c:start_output_pass
Line
Count
Source
62
534
{
63
534
#ifdef BLOCK_SMOOTHING_SUPPORTED
64
534
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
65
66
  /* If multipass, check to see whether to use block smoothing on this pass */
67
534
  if (coef->pub.coef_arrays != NULL) {
68
454
    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
69
343
      coef->pub._decompress_data = decompress_smooth_data;
70
111
    else
71
111
      coef->pub._decompress_data = decompress_data;
72
454
  }
73
534
#endif
74
534
  cinfo->output_iMCU_row = 0;
75
534
}
76
77
78
/*
79
 * Decompress and return some data in the single-pass case.
80
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
81
 * Input and output must run in lockstep since we have only a one-MCU buffer.
82
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
83
 *
84
 * NB: output_buf contains a plane for each component in image,
85
 * which we index according to the component's SOF position.
86
 */
87
88
METHODDEF(int)
89
decompress_onepass(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
90
655k
{
91
655k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
655k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
655k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
655k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
655k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
655k
  _JSAMPARRAY output_ptr;
97
655k
  JDIMENSION start_col, output_col;
98
655k
  jpeg_component_info *compptr;
99
655k
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
1.31M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
655k
       yoffset++) {
104
55.5M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
54.8M
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
54.8M
      jzero_far((void *)coef->MCU_buffer[0],
108
54.8M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
54.8M
      if (!cinfo->entropy->insufficient_data)
110
19.0M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
54.8M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
115
        /* Suspension forced; update state counters and exit */
116
0
        coef->MCU_vert_offset = yoffset;
117
0
        coef->MCU_ctr = MCU_col_num;
118
#ifdef WITH_PROFILE
119
        cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
120
        cinfo->master->entropy_mcoeffs +=
121
          (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
122
#endif
123
0
        return JPEG_SUSPENDED;
124
0
      }
125
#ifdef WITH_PROFILE
126
      cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
127
      cinfo->master->entropy_mcoeffs +=
128
        (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
129
#endif
130
131
      /* Only perform the IDCT on blocks that are contained within the desired
132
       * cropping region.
133
       */
134
54.8M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
54.8M
          MCU_col_num <= cinfo->master->last_iMCU_col) {
136
        /* Determine where data should go in output_buf and do the IDCT thing.
137
         * We skip dummy blocks at the right and bottom edges (but blkn gets
138
         * incremented past them!).  Note the inner loop relies on having
139
         * allocated the MCU_buffer[] blocks sequentially.
140
         */
141
54.8M
        blkn = 0;               /* index of current DCT block within MCU */
142
110M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
55.2M
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
55.2M
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
55.2M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
55.2M
          useful_width = (MCU_col_num < last_MCU_col) ?
151
54.6M
                         compptr->MCU_width : compptr->last_col_width;
152
55.2M
          output_ptr = output_buf[compptr->component_index] +
153
55.2M
                       yoffset * compptr->_DCT_scaled_size;
154
55.2M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
55.2M
                      compptr->MCU_sample_width;
156
110M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
55.3M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
55.3M
                yoffset + yindex < compptr->last_row_height) {
159
55.3M
              output_col = start_col;
160
111M
              for (xindex = 0; xindex < useful_width; xindex++) {
161
#ifdef WITH_PROFILE
162
                cinfo->master->start = getTime();
163
#endif
164
55.6M
                (*inverse_DCT) (cinfo, compptr,
165
55.6M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
55.6M
                                output_ptr, output_col);
167
#ifdef WITH_PROFILE
168
                cinfo->master->idct_elapsed +=
169
                  getTime() - cinfo->master->start;
170
                cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
171
#endif
172
55.6M
                output_col += compptr->_DCT_scaled_size;
173
55.6M
              }
174
55.3M
            }
175
55.3M
            blkn += compptr->MCU_width;
176
55.3M
            output_ptr += compptr->_DCT_scaled_size;
177
55.3M
          }
178
55.2M
        }
179
54.8M
      }
180
54.8M
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
655k
    coef->MCU_ctr = 0;
183
655k
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
655k
  cinfo->output_iMCU_row++;
186
655k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
594k
    start_iMCU_row(cinfo);
188
594k
    return JPEG_ROW_COMPLETED;
189
594k
  }
190
  /* Completed the scan */
191
61.3k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
61.3k
  return JPEG_SCAN_COMPLETED;
193
655k
}
jdcoefct-8.c:decompress_onepass
Line
Count
Source
90
640k
{
91
640k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
640k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
640k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
640k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
640k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
640k
  _JSAMPARRAY output_ptr;
97
640k
  JDIMENSION start_col, output_col;
98
640k
  jpeg_component_info *compptr;
99
640k
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
1.28M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
640k
       yoffset++) {
104
55.4M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
54.7M
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
54.7M
      jzero_far((void *)coef->MCU_buffer[0],
108
54.7M
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
54.7M
      if (!cinfo->entropy->insufficient_data)
110
19.0M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
54.7M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
115
        /* Suspension forced; update state counters and exit */
116
0
        coef->MCU_vert_offset = yoffset;
117
0
        coef->MCU_ctr = MCU_col_num;
118
#ifdef WITH_PROFILE
119
        cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
120
        cinfo->master->entropy_mcoeffs +=
121
          (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
122
#endif
123
0
        return JPEG_SUSPENDED;
124
0
      }
125
#ifdef WITH_PROFILE
126
      cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
127
      cinfo->master->entropy_mcoeffs +=
128
        (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
129
#endif
130
131
      /* Only perform the IDCT on blocks that are contained within the desired
132
       * cropping region.
133
       */
134
54.7M
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
54.7M
          MCU_col_num <= cinfo->master->last_iMCU_col) {
136
        /* Determine where data should go in output_buf and do the IDCT thing.
137
         * We skip dummy blocks at the right and bottom edges (but blkn gets
138
         * incremented past them!).  Note the inner loop relies on having
139
         * allocated the MCU_buffer[] blocks sequentially.
140
         */
141
54.7M
        blkn = 0;               /* index of current DCT block within MCU */
142
109M
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
55.2M
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
55.2M
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
55.2M
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
55.2M
          useful_width = (MCU_col_num < last_MCU_col) ?
151
54.5M
                         compptr->MCU_width : compptr->last_col_width;
152
55.2M
          output_ptr = output_buf[compptr->component_index] +
153
55.2M
                       yoffset * compptr->_DCT_scaled_size;
154
55.2M
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
55.2M
                      compptr->MCU_sample_width;
156
110M
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
55.3M
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
55.3M
                yoffset + yindex < compptr->last_row_height) {
159
55.3M
              output_col = start_col;
160
110M
              for (xindex = 0; xindex < useful_width; xindex++) {
161
#ifdef WITH_PROFILE
162
                cinfo->master->start = getTime();
163
#endif
164
55.5M
                (*inverse_DCT) (cinfo, compptr,
165
55.5M
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
55.5M
                                output_ptr, output_col);
167
#ifdef WITH_PROFILE
168
                cinfo->master->idct_elapsed +=
169
                  getTime() - cinfo->master->start;
170
                cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
171
#endif
172
55.5M
                output_col += compptr->_DCT_scaled_size;
173
55.5M
              }
174
55.3M
            }
175
55.3M
            blkn += compptr->MCU_width;
176
55.3M
            output_ptr += compptr->_DCT_scaled_size;
177
55.3M
          }
178
55.2M
        }
179
54.7M
      }
180
54.7M
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
640k
    coef->MCU_ctr = 0;
183
640k
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
640k
  cinfo->output_iMCU_row++;
186
640k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
579k
    start_iMCU_row(cinfo);
188
579k
    return JPEG_ROW_COMPLETED;
189
579k
  }
190
  /* Completed the scan */
191
61.3k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
61.3k
  return JPEG_SCAN_COMPLETED;
193
640k
}
jdcoefct-12.c:decompress_onepass
Line
Count
Source
90
15.0k
{
91
15.0k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
92
15.0k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
93
15.0k
  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
94
15.0k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
95
15.0k
  int blkn, ci, xindex, yindex, yoffset, useful_width;
96
15.0k
  _JSAMPARRAY output_ptr;
97
15.0k
  JDIMENSION start_col, output_col;
98
15.0k
  jpeg_component_info *compptr;
99
15.0k
  _inverse_DCT_method_ptr inverse_DCT;
100
101
  /* Loop to process as much as one whole iMCU row */
102
30.1k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
103
15.0k
       yoffset++) {
104
87.6k
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
105
72.5k
         MCU_col_num++) {
106
      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */
107
72.5k
      jzero_far((void *)coef->MCU_buffer[0],
108
72.5k
                (size_t)(cinfo->blocks_in_MCU * sizeof(JBLOCK)));
109
72.5k
      if (!cinfo->entropy->insufficient_data)
110
49.4k
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
111
#ifdef WITH_PROFILE
112
      cinfo->master->start = getTime();
113
#endif
114
72.5k
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
115
        /* Suspension forced; update state counters and exit */
116
0
        coef->MCU_vert_offset = yoffset;
117
0
        coef->MCU_ctr = MCU_col_num;
118
#ifdef WITH_PROFILE
119
        cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
120
        cinfo->master->entropy_mcoeffs +=
121
          (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
122
#endif
123
0
        return JPEG_SUSPENDED;
124
0
      }
125
#ifdef WITH_PROFILE
126
      cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
127
      cinfo->master->entropy_mcoeffs +=
128
        (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
129
#endif
130
131
      /* Only perform the IDCT on blocks that are contained within the desired
132
       * cropping region.
133
       */
134
72.5k
      if (MCU_col_num >= cinfo->master->first_iMCU_col &&
135
72.5k
          MCU_col_num <= cinfo->master->last_iMCU_col) {
136
        /* Determine where data should go in output_buf and do the IDCT thing.
137
         * We skip dummy blocks at the right and bottom edges (but blkn gets
138
         * incremented past them!).  Note the inner loop relies on having
139
         * allocated the MCU_buffer[] blocks sequentially.
140
         */
141
72.5k
        blkn = 0;               /* index of current DCT block within MCU */
142
145k
        for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
143
72.5k
          compptr = cinfo->cur_comp_info[ci];
144
          /* Don't bother to IDCT an uninteresting component. */
145
72.5k
          if (!compptr->component_needed) {
146
0
            blkn += compptr->MCU_blocks;
147
0
            continue;
148
0
          }
149
72.5k
          inverse_DCT = cinfo->idct->_inverse_DCT[compptr->component_index];
150
72.5k
          useful_width = (MCU_col_num < last_MCU_col) ?
151
57.4k
                         compptr->MCU_width : compptr->last_col_width;
152
72.5k
          output_ptr = output_buf[compptr->component_index] +
153
72.5k
                       yoffset * compptr->_DCT_scaled_size;
154
72.5k
          start_col = (MCU_col_num - cinfo->master->first_iMCU_col) *
155
72.5k
                      compptr->MCU_sample_width;
156
145k
          for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
157
72.5k
            if (cinfo->input_iMCU_row < last_iMCU_row ||
158
72.5k
                yoffset + yindex < compptr->last_row_height) {
159
72.5k
              output_col = start_col;
160
145k
              for (xindex = 0; xindex < useful_width; xindex++) {
161
#ifdef WITH_PROFILE
162
                cinfo->master->start = getTime();
163
#endif
164
72.5k
                (*inverse_DCT) (cinfo, compptr,
165
72.5k
                                (JCOEFPTR)coef->MCU_buffer[blkn + xindex],
166
72.5k
                                output_ptr, output_col);
167
#ifdef WITH_PROFILE
168
                cinfo->master->idct_elapsed +=
169
                  getTime() - cinfo->master->start;
170
                cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
171
#endif
172
72.5k
                output_col += compptr->_DCT_scaled_size;
173
72.5k
              }
174
72.5k
            }
175
72.5k
            blkn += compptr->MCU_width;
176
72.5k
            output_ptr += compptr->_DCT_scaled_size;
177
72.5k
          }
178
72.5k
        }
179
72.5k
      }
180
72.5k
    }
181
    /* Completed an MCU row, but perhaps not an iMCU row */
182
15.0k
    coef->MCU_ctr = 0;
183
15.0k
  }
184
  /* Completed the iMCU row, advance counters for next one */
185
15.0k
  cinfo->output_iMCU_row++;
186
15.0k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
187
15.0k
    start_iMCU_row(cinfo);
188
15.0k
    return JPEG_ROW_COMPLETED;
189
15.0k
  }
190
  /* Completed the scan */
191
61
  (*cinfo->inputctl->finish_input_pass) (cinfo);
192
61
  return JPEG_SCAN_COMPLETED;
193
15.0k
}
194
195
196
/*
197
 * Dummy consume-input routine for single-pass operation.
198
 */
199
200
METHODDEF(int)
201
dummy_consume_data(j_decompress_ptr cinfo)
202
0
{
203
0
  return JPEG_SUSPENDED;        /* Always indicate nothing was done */
204
0
}
Unexecuted instantiation: jdcoefct-8.c:dummy_consume_data
Unexecuted instantiation: jdcoefct-12.c:dummy_consume_data
205
206
207
#ifdef D_MULTISCAN_FILES_SUPPORTED
208
209
/*
210
 * Consume input data and store it in the full-image coefficient buffer.
211
 * We read as much as one fully interleaved MCU row ("iMCU" row) per call,
212
 * ie, v_samp_factor block rows for each component in the scan.
213
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
214
 */
215
216
METHODDEF(int)
217
consume_data(j_decompress_ptr cinfo)
218
1.34M
{
219
1.34M
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
1.34M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
1.34M
  int blkn, ci, xindex, yindex, yoffset;
222
1.34M
  JDIMENSION start_col;
223
1.34M
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
1.34M
  JBLOCKROW buffer_ptr;
225
1.34M
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
2.74M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
1.40M
    compptr = cinfo->cur_comp_info[ci];
230
1.40M
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
1.40M
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
1.40M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
1.40M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
234
    /* Note: entropy decoder expects buffer to be zeroed,
235
     * but this is handled automatically by the memory manager
236
     * because we requested a pre-zeroed array.
237
     */
238
1.40M
  }
239
240
  /* Loop to process one whole iMCU row */
241
2.72M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
1.38M
       yoffset++) {
243
46.2M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
44.8M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
44.8M
      blkn = 0;                 /* index of current DCT block within MCU */
247
90.2M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
45.4M
        compptr = cinfo->cur_comp_info[ci];
249
45.4M
        start_col = MCU_col_num * compptr->MCU_width;
250
90.8M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
45.4M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
90.8M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
45.4M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
45.4M
          }
255
45.4M
        }
256
45.4M
      }
257
44.8M
      if (!cinfo->entropy->insufficient_data)
258
40.6M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
259
      /* Try to fetch the MCU. */
260
#ifdef WITH_PROFILE
261
      cinfo->master->start = getTime();
262
#endif
263
44.8M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
264
        /* Suspension forced; update state counters and exit */
265
0
        coef->MCU_vert_offset = yoffset;
266
0
        coef->MCU_ctr = MCU_col_num;
267
#ifdef WITH_PROFILE
268
        cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
269
        cinfo->master->entropy_mcoeffs +=
270
          (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
271
#endif
272
0
        return JPEG_SUSPENDED;
273
0
      }
274
#ifdef WITH_PROFILE
275
      cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
276
      cinfo->master->entropy_mcoeffs +=
277
        (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
278
#endif
279
44.8M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
1.38M
    coef->MCU_ctr = 0;
282
1.38M
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
1.34M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
1.30M
    start_iMCU_row(cinfo);
286
1.30M
    return JPEG_ROW_COMPLETED;
287
1.30M
  }
288
  /* Completed the scan */
289
42.8k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
42.8k
  return JPEG_SCAN_COMPLETED;
291
1.34M
}
jdcoefct-8.c:consume_data
Line
Count
Source
218
418k
{
219
418k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
418k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
418k
  int blkn, ci, xindex, yindex, yoffset;
222
418k
  JDIMENSION start_col;
223
418k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
418k
  JBLOCKROW buffer_ptr;
225
418k
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
893k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
474k
    compptr = cinfo->cur_comp_info[ci];
230
474k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
474k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
474k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
474k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
234
    /* Note: entropy decoder expects buffer to be zeroed,
235
     * but this is handled automatically by the memory manager
236
     * because we requested a pre-zeroed array.
237
     */
238
474k
  }
239
240
  /* Loop to process one whole iMCU row */
241
873k
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
455k
       yoffset++) {
243
36.7M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
36.2M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
36.2M
      blkn = 0;                 /* index of current DCT block within MCU */
247
73.1M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
36.8M
        compptr = cinfo->cur_comp_info[ci];
249
36.8M
        start_col = MCU_col_num * compptr->MCU_width;
250
73.7M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
36.8M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
73.7M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
36.9M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
36.9M
          }
255
36.8M
        }
256
36.8M
      }
257
36.2M
      if (!cinfo->entropy->insufficient_data)
258
34.2M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
259
      /* Try to fetch the MCU. */
260
#ifdef WITH_PROFILE
261
      cinfo->master->start = getTime();
262
#endif
263
36.2M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
264
        /* Suspension forced; update state counters and exit */
265
0
        coef->MCU_vert_offset = yoffset;
266
0
        coef->MCU_ctr = MCU_col_num;
267
#ifdef WITH_PROFILE
268
        cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
269
        cinfo->master->entropy_mcoeffs +=
270
          (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
271
#endif
272
0
        return JPEG_SUSPENDED;
273
0
      }
274
#ifdef WITH_PROFILE
275
      cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
276
      cinfo->master->entropy_mcoeffs +=
277
        (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
278
#endif
279
36.2M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
455k
    coef->MCU_ctr = 0;
282
455k
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
418k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
376k
    start_iMCU_row(cinfo);
286
376k
    return JPEG_ROW_COMPLETED;
287
376k
  }
288
  /* Completed the scan */
289
41.8k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
41.8k
  return JPEG_SCAN_COMPLETED;
291
418k
}
jdcoefct-12.c:consume_data
Line
Count
Source
218
925k
{
219
925k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
220
925k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
221
925k
  int blkn, ci, xindex, yindex, yoffset;
222
925k
  JDIMENSION start_col;
223
925k
  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
224
925k
  JBLOCKROW buffer_ptr;
225
925k
  jpeg_component_info *compptr;
226
227
  /* Align the virtual buffers for the components used in this scan. */
228
1.85M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
229
925k
    compptr = cinfo->cur_comp_info[ci];
230
925k
    buffer[ci] = (*cinfo->mem->access_virt_barray)
231
925k
      ((j_common_ptr)cinfo, coef->whole_image[compptr->component_index],
232
925k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
233
925k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
234
    /* Note: entropy decoder expects buffer to be zeroed,
235
     * but this is handled automatically by the memory manager
236
     * because we requested a pre-zeroed array.
237
     */
238
925k
  }
239
240
  /* Loop to process one whole iMCU row */
241
1.85M
  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
242
925k
       yoffset++) {
243
9.48M
    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
244
8.56M
         MCU_col_num++) {
245
      /* Construct list of pointers to DCT blocks belonging to this MCU */
246
8.56M
      blkn = 0;                 /* index of current DCT block within MCU */
247
17.1M
      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
248
8.56M
        compptr = cinfo->cur_comp_info[ci];
249
8.56M
        start_col = MCU_col_num * compptr->MCU_width;
250
17.1M
        for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
251
8.56M
          buffer_ptr = buffer[ci][yindex + yoffset] + start_col;
252
17.1M
          for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
253
8.56M
            coef->MCU_buffer[blkn++] = buffer_ptr++;
254
8.56M
          }
255
8.56M
        }
256
8.56M
      }
257
8.56M
      if (!cinfo->entropy->insufficient_data)
258
6.41M
        cinfo->master->last_good_iMCU_row = cinfo->input_iMCU_row;
259
      /* Try to fetch the MCU. */
260
#ifdef WITH_PROFILE
261
      cinfo->master->start = getTime();
262
#endif
263
8.56M
      if (!(*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
264
        /* Suspension forced; update state counters and exit */
265
0
        coef->MCU_vert_offset = yoffset;
266
0
        coef->MCU_ctr = MCU_col_num;
267
#ifdef WITH_PROFILE
268
        cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
269
        cinfo->master->entropy_mcoeffs +=
270
          (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
271
#endif
272
0
        return JPEG_SUSPENDED;
273
0
      }
274
#ifdef WITH_PROFILE
275
      cinfo->master->entropy_elapsed += getTime() - cinfo->master->start;
276
      cinfo->master->entropy_mcoeffs +=
277
        (double)cinfo->blocks_in_MCU * DCTSIZE2 / 1000000.;
278
#endif
279
8.56M
    }
280
    /* Completed an MCU row, but perhaps not an iMCU row */
281
925k
    coef->MCU_ctr = 0;
282
925k
  }
283
  /* Completed the iMCU row, advance counters for next one */
284
925k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
285
924k
    start_iMCU_row(cinfo);
286
924k
    return JPEG_ROW_COMPLETED;
287
924k
  }
288
  /* Completed the scan */
289
971
  (*cinfo->inputctl->finish_input_pass) (cinfo);
290
971
  return JPEG_SCAN_COMPLETED;
291
925k
}
292
293
294
/*
295
 * Decompress and return some data in the multi-pass case.
296
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
297
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
298
 *
299
 * NB: output_buf contains a plane for each component in image.
300
 */
301
302
METHODDEF(int)
303
decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
304
181k
{
305
181k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
181k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
181k
  JDIMENSION block_num;
308
181k
  int ci, block_row, block_rows;
309
181k
  JBLOCKARRAY buffer;
310
181k
  JBLOCKROW buffer_ptr;
311
181k
  _JSAMPARRAY output_ptr;
312
181k
  JDIMENSION output_col;
313
181k
  jpeg_component_info *compptr;
314
181k
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
181k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
181k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
181k
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
320
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
321
0
      return JPEG_SUSPENDED;
322
0
  }
323
324
  /* OK, output from the virtual arrays. */
325
492k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
311k
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
311k
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
311k
    buffer = (*cinfo->mem->access_virt_barray)
332
311k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
311k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
311k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
311k
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
265k
      block_rows = compptr->v_samp_factor;
338
45.8k
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
45.8k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
45.8k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
45.8k
    }
343
311k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
311k
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
655k
    for (block_row = 0; block_row < block_rows; block_row++) {
347
344k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
344k
      output_col = 0;
349
344k
      for (block_num = cinfo->master->first_MCU_col[ci];
350
7.73M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
7.39M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
7.39M
                        output_col);
356
#ifdef WITH_PROFILE
357
        cinfo->master->idct_elapsed += getTime() - cinfo->master->start;
358
        cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
359
#endif
360
7.39M
        buffer_ptr++;
361
7.39M
        output_col += compptr->_DCT_scaled_size;
362
7.39M
      }
363
344k
      output_ptr += compptr->_DCT_scaled_size;
364
344k
    }
365
311k
  }
366
367
181k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
161k
    return JPEG_ROW_COMPLETED;
369
20.4k
  return JPEG_SCAN_COMPLETED;
370
181k
}
jdcoefct-8.c:decompress_data
Line
Count
Source
304
161k
{
305
161k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
161k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
161k
  JDIMENSION block_num;
308
161k
  int ci, block_row, block_rows;
309
161k
  JBLOCKARRAY buffer;
310
161k
  JBLOCKROW buffer_ptr;
311
161k
  _JSAMPARRAY output_ptr;
312
161k
  JDIMENSION output_col;
313
161k
  jpeg_component_info *compptr;
314
161k
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
161k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
161k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
161k
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
320
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
321
0
      return JPEG_SUSPENDED;
322
0
  }
323
324
  /* OK, output from the virtual arrays. */
325
451k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
290k
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
290k
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
290k
    buffer = (*cinfo->mem->access_virt_barray)
332
290k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
290k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
290k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
290k
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
244k
      block_rows = compptr->v_samp_factor;
338
45.8k
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
45.8k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
45.8k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
45.8k
    }
343
290k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
290k
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
614k
    for (block_row = 0; block_row < block_rows; block_row++) {
347
323k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
323k
      output_col = 0;
349
323k
      for (block_num = cinfo->master->first_MCU_col[ci];
350
7.56M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
7.24M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
7.24M
                        output_col);
356
#ifdef WITH_PROFILE
357
        cinfo->master->idct_elapsed += getTime() - cinfo->master->start;
358
        cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
359
#endif
360
7.24M
        buffer_ptr++;
361
7.24M
        output_col += compptr->_DCT_scaled_size;
362
7.24M
      }
363
323k
      output_ptr += compptr->_DCT_scaled_size;
364
323k
    }
365
290k
  }
366
367
161k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
140k
    return JPEG_ROW_COMPLETED;
369
20.4k
  return JPEG_SCAN_COMPLETED;
370
161k
}
jdcoefct-12.c:decompress_data
Line
Count
Source
304
20.6k
{
305
20.6k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
306
20.6k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
307
20.6k
  JDIMENSION block_num;
308
20.6k
  int ci, block_row, block_rows;
309
20.6k
  JBLOCKARRAY buffer;
310
20.6k
  JBLOCKROW buffer_ptr;
311
20.6k
  _JSAMPARRAY output_ptr;
312
20.6k
  JDIMENSION output_col;
313
20.6k
  jpeg_component_info *compptr;
314
20.6k
  _inverse_DCT_method_ptr inverse_DCT;
315
316
  /* Force some input to be done if we are getting ahead of the input. */
317
20.6k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
318
20.6k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
319
20.6k
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
320
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
321
0
      return JPEG_SUSPENDED;
322
0
  }
323
324
  /* OK, output from the virtual arrays. */
325
41.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
326
20.6k
       ci++, compptr++) {
327
    /* Don't bother to IDCT an uninteresting component. */
328
20.6k
    if (!compptr->component_needed)
329
0
      continue;
330
    /* Align the virtual buffer for this component. */
331
20.6k
    buffer = (*cinfo->mem->access_virt_barray)
332
20.6k
      ((j_common_ptr)cinfo, coef->whole_image[ci],
333
20.6k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
334
20.6k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
335
    /* Count non-dummy DCT block rows in this iMCU row. */
336
20.6k
    if (cinfo->output_iMCU_row < last_iMCU_row)
337
20.5k
      block_rows = compptr->v_samp_factor;
338
63
    else {
339
      /* NB: can't use last_row_height here; it is input-side-dependent! */
340
63
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
341
63
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
342
63
    }
343
20.6k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
344
20.6k
    output_ptr = output_buf[ci];
345
    /* Loop over all DCT blocks to be processed. */
346
41.2k
    for (block_row = 0; block_row < block_rows; block_row++) {
347
20.6k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
348
20.6k
      output_col = 0;
349
20.6k
      for (block_num = cinfo->master->first_MCU_col[ci];
350
164k
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
351
#ifdef WITH_PROFILE
352
        cinfo->master->start = getTime();
353
#endif
354
144k
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)buffer_ptr, output_ptr,
355
144k
                        output_col);
356
#ifdef WITH_PROFILE
357
        cinfo->master->idct_elapsed += getTime() - cinfo->master->start;
358
        cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
359
#endif
360
144k
        buffer_ptr++;
361
144k
        output_col += compptr->_DCT_scaled_size;
362
144k
      }
363
20.6k
      output_ptr += compptr->_DCT_scaled_size;
364
20.6k
    }
365
20.6k
  }
366
367
20.6k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
368
20.5k
    return JPEG_ROW_COMPLETED;
369
63
  return JPEG_SCAN_COMPLETED;
370
20.6k
}
371
372
#endif /* D_MULTISCAN_FILES_SUPPORTED */
373
374
375
#ifdef BLOCK_SMOOTHING_SUPPORTED
376
377
/*
378
 * This code applies interblock smoothing; the first 9 AC coefficients are
379
 * estimated from the DC values of a DCT block and its 24 neighboring blocks.
380
 * We apply smoothing only for progressive JPEG decoding, and only if
381
 * the coefficients it can estimate are not yet known to full precision.
382
 */
383
384
/* Natural-order array positions of the first 9 zigzag-order coefficients */
385
362k
#define Q01_POS  1
386
361k
#define Q10_POS  8
387
359k
#define Q20_POS  16
388
358k
#define Q11_POS  9
389
357k
#define Q02_POS  2
390
218k
#define Q03_POS  3
391
216k
#define Q12_POS  10
392
214k
#define Q21_POS  17
393
213k
#define Q30_POS  24
394
395
/*
396
 * Determine whether block smoothing is applicable and safe.
397
 * We also latch the current states of the coef_bits[] entries for the
398
 * AC coefficients; otherwise, if the input side of the decompressor
399
 * advances into a new scan, we might think the coefficients are known
400
 * more accurately than they really are.
401
 */
402
403
LOCAL(boolean)
404
smoothing_ok(j_decompress_ptr cinfo)
405
24.6k
{
406
24.6k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
24.6k
  boolean smoothing_useful = FALSE;
408
24.6k
  int ci, coefi;
409
24.6k
  jpeg_component_info *compptr;
410
24.6k
  JQUANT_TBL *qtable;
411
24.6k
  int *coef_bits, *prev_coef_bits;
412
24.6k
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
24.6k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
3.33k
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
21.2k
  if (coef->coef_bits_latch == NULL)
419
21.2k
    coef->coef_bits_latch = (int *)
420
21.2k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
21.2k
                                  cinfo->num_components * 2 *
422
21.2k
                                  (SAVED_COEFS * sizeof(int)));
423
21.2k
  coef_bits_latch = coef->coef_bits_latch;
424
21.2k
  prev_coef_bits_latch =
425
21.2k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
30.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
25.8k
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
25.8k
    if ((qtable = compptr->quant_table) == NULL)
431
1.08k
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
24.7k
    if (qtable->quantval[0] == 0 ||
434
21.8k
        qtable->quantval[Q01_POS] == 0 ||
435
21.3k
        qtable->quantval[Q10_POS] == 0 ||
436
19.3k
        qtable->quantval[Q20_POS] == 0 ||
437
17.9k
        qtable->quantval[Q11_POS] == 0 ||
438
16.6k
        qtable->quantval[Q02_POS] == 0 ||
439
15.9k
        qtable->quantval[Q03_POS] == 0 ||
440
14.3k
        qtable->quantval[Q12_POS] == 0 ||
441
12.2k
        qtable->quantval[Q21_POS] == 0 ||
442
11.5k
        qtable->quantval[Q30_POS] == 0)
443
14.2k
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
10.4k
    coef_bits = cinfo->coef_bits[ci];
446
10.4k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
10.4k
    if (coef_bits[0] < 0)
448
1.50k
      return FALSE;
449
8.92k
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
89.2k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
80.3k
      if (cinfo->input_scan_number > 1)
453
28.1k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
52.1k
      else
455
52.1k
        prev_coef_bits_latch[coefi] = -1;
456
80.3k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
80.3k
      if (coef_bits[coefi] != 0)
458
72.9k
        smoothing_useful = TRUE;
459
80.3k
    }
460
8.92k
    coef_bits_latch += SAVED_COEFS;
461
8.92k
    prev_coef_bits_latch += SAVED_COEFS;
462
8.92k
  }
463
464
4.41k
  return smoothing_useful;
465
21.2k
}
jdcoefct-8.c:smoothing_ok
Line
Count
Source
405
24.1k
{
406
24.1k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
24.1k
  boolean smoothing_useful = FALSE;
408
24.1k
  int ci, coefi;
409
24.1k
  jpeg_component_info *compptr;
410
24.1k
  JQUANT_TBL *qtable;
411
24.1k
  int *coef_bits, *prev_coef_bits;
412
24.1k
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
24.1k
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
3.33k
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
20.8k
  if (coef->coef_bits_latch == NULL)
419
20.8k
    coef->coef_bits_latch = (int *)
420
20.8k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
20.8k
                                  cinfo->num_components * 2 *
422
20.8k
                                  (SAVED_COEFS * sizeof(int)));
423
20.8k
  coef_bits_latch = coef->coef_bits_latch;
424
20.8k
  prev_coef_bits_latch =
425
20.8k
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
29.4k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
25.3k
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
25.3k
    if ((qtable = compptr->quant_table) == NULL)
431
1.08k
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
24.2k
    if (qtable->quantval[0] == 0 ||
434
21.4k
        qtable->quantval[Q01_POS] == 0 ||
435
20.8k
        qtable->quantval[Q10_POS] == 0 ||
436
18.9k
        qtable->quantval[Q20_POS] == 0 ||
437
17.5k
        qtable->quantval[Q11_POS] == 0 ||
438
16.2k
        qtable->quantval[Q02_POS] == 0 ||
439
15.5k
        qtable->quantval[Q03_POS] == 0 ||
440
13.9k
        qtable->quantval[Q12_POS] == 0 ||
441
11.9k
        qtable->quantval[Q21_POS] == 0 ||
442
11.1k
        qtable->quantval[Q30_POS] == 0)
443
14.2k
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
10.0k
    coef_bits = cinfo->coef_bits[ci];
446
10.0k
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
10.0k
    if (coef_bits[0] < 0)
448
1.48k
      return FALSE;
449
8.58k
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
85.8k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
77.2k
      if (cinfo->input_scan_number > 1)
453
26.1k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
51.0k
      else
455
51.0k
        prev_coef_bits_latch[coefi] = -1;
456
77.2k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
77.2k
      if (coef_bits[coefi] != 0)
458
70.0k
        smoothing_useful = TRUE;
459
77.2k
    }
460
8.58k
    coef_bits_latch += SAVED_COEFS;
461
8.58k
    prev_coef_bits_latch += SAVED_COEFS;
462
8.58k
  }
463
464
4.06k
  return smoothing_useful;
465
20.8k
}
jdcoefct-12.c:smoothing_ok
Line
Count
Source
405
454
{
406
454
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
407
454
  boolean smoothing_useful = FALSE;
408
454
  int ci, coefi;
409
454
  jpeg_component_info *compptr;
410
454
  JQUANT_TBL *qtable;
411
454
  int *coef_bits, *prev_coef_bits;
412
454
  int *coef_bits_latch, *prev_coef_bits_latch;
413
414
454
  if (!cinfo->progressive_mode || cinfo->coef_bits == NULL)
415
0
    return FALSE;
416
417
  /* Allocate latch area if not already done */
418
454
  if (coef->coef_bits_latch == NULL)
419
454
    coef->coef_bits_latch = (int *)
420
454
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
421
454
                                  cinfo->num_components * 2 *
422
454
                                  (SAVED_COEFS * sizeof(int)));
423
454
  coef_bits_latch = coef->coef_bits_latch;
424
454
  prev_coef_bits_latch =
425
454
    &coef->coef_bits_latch[cinfo->num_components * SAVED_COEFS];
426
427
799
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
428
454
       ci++, compptr++) {
429
    /* All components' quantization values must already be latched. */
430
454
    if ((qtable = compptr->quant_table) == NULL)
431
0
      return FALSE;
432
    /* Verify DC & first 9 AC quantizers are nonzero to avoid zero-divide. */
433
454
    if (qtable->quantval[0] == 0 ||
434
446
        qtable->quantval[Q01_POS] == 0 ||
435
434
        qtable->quantval[Q10_POS] == 0 ||
436
415
        qtable->quantval[Q20_POS] == 0 ||
437
406
        qtable->quantval[Q11_POS] == 0 ||
438
400
        qtable->quantval[Q02_POS] == 0 ||
439
393
        qtable->quantval[Q03_POS] == 0 ||
440
387
        qtable->quantval[Q12_POS] == 0 ||
441
381
        qtable->quantval[Q21_POS] == 0 ||
442
373
        qtable->quantval[Q30_POS] == 0)
443
93
      return FALSE;
444
    /* DC values must be at least partly known for all components. */
445
361
    coef_bits = cinfo->coef_bits[ci];
446
361
    prev_coef_bits = cinfo->coef_bits[ci + cinfo->num_components];
447
361
    if (coef_bits[0] < 0)
448
16
      return FALSE;
449
345
    coef_bits_latch[0] = coef_bits[0];
450
    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
451
3.45k
    for (coefi = 1; coefi < SAVED_COEFS; coefi++) {
452
3.10k
      if (cinfo->input_scan_number > 1)
453
2.01k
        prev_coef_bits_latch[coefi] = prev_coef_bits[coefi];
454
1.08k
      else
455
1.08k
        prev_coef_bits_latch[coefi] = -1;
456
3.10k
      coef_bits_latch[coefi] = coef_bits[coefi];
457
3.10k
      if (coef_bits[coefi] != 0)
458
2.88k
        smoothing_useful = TRUE;
459
3.10k
    }
460
345
    coef_bits_latch += SAVED_COEFS;
461
345
    prev_coef_bits_latch += SAVED_COEFS;
462
345
  }
463
464
345
  return smoothing_useful;
465
454
}
466
467
468
/*
469
 * Variant of decompress_data for use when doing block smoothing.
470
 */
471
472
METHODDEF(int)
473
decompress_smooth_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
474
330k
{
475
330k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
330k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
330k
  JDIMENSION block_num, last_block_column;
478
330k
  int ci, block_row, block_rows, access_rows, image_block_row,
479
330k
    image_block_rows;
480
330k
  JBLOCKARRAY buffer;
481
330k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
330k
  JBLOCKROW next_block_row, next_next_block_row;
483
330k
  _JSAMPARRAY output_ptr;
484
330k
  JDIMENSION output_col;
485
330k
  jpeg_component_info *compptr;
486
330k
  _inverse_DCT_method_ptr inverse_DCT;
487
330k
  boolean change_dc;
488
330k
  JCOEF *workspace;
489
330k
  int *coef_bits;
490
330k
  JQUANT_TBL *quanttbl;
491
330k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
330k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
330k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
330k
      DC25;
495
330k
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
330k
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
330k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
330k
         !cinfo->inputctl->eoi_reached) {
503
0
    if (cinfo->input_scan_number == cinfo->output_scan_number) {
504
      /* If input is working on current scan, we ordinarily want it to
505
       * have completed the current row.  But if input scan is DC,
506
       * we want it to keep two rows ahead so that next two block rows' DC
507
       * values are up to date.
508
       */
509
0
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
510
0
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
511
0
        break;
512
0
    }
513
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
514
0
      return JPEG_SUSPENDED;
515
0
  }
516
517
  /* OK, output from the virtual arrays. */
518
670k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
340k
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
340k
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
340k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
330k
      block_rows = compptr->v_samp_factor;
526
330k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
330k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
2.80k
      block_rows = compptr->v_samp_factor;
529
2.80k
      access_rows = block_rows * 2; /* this and next iMCU row */
530
7.49k
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
7.49k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
7.49k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
7.49k
      access_rows = block_rows; /* this iMCU row only */
535
7.49k
    }
536
    /* Align the virtual buffer for this component. */
537
340k
    if (cinfo->output_iMCU_row > 1) {
538
329k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
329k
      buffer = (*cinfo->mem->access_virt_barray)
540
329k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
329k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
329k
         (JDIMENSION)access_rows, FALSE);
543
329k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
329k
    } else if (cinfo->output_iMCU_row > 0) {
545
3.06k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
3.06k
      buffer = (*cinfo->mem->access_virt_barray)
547
3.06k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
3.06k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
3.06k
         (JDIMENSION)access_rows, FALSE);
550
3.06k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
7.77k
    } else {
552
7.77k
      buffer = (*cinfo->mem->access_virt_barray)
553
7.77k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
7.77k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
7.77k
    }
556
    /* Fetch component-dependent info.
557
     * If the current scan is incomplete, then we use the component-dependent
558
     * info from the previous scan.
559
     */
560
340k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
561
3.18k
      coef_bits =
562
3.18k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
563
337k
    else
564
337k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
565
566
    /* We only do DC interpolation if no AC coefficient data is available. */
567
340k
    change_dc =
568
340k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
220k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
207k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
340k
    quanttbl = compptr->quant_table;
573
340k
    Q00 = quanttbl->quantval[0];
574
340k
    Q01 = quanttbl->quantval[Q01_POS];
575
340k
    Q10 = quanttbl->quantval[Q10_POS];
576
340k
    Q20 = quanttbl->quantval[Q20_POS];
577
340k
    Q11 = quanttbl->quantval[Q11_POS];
578
340k
    Q02 = quanttbl->quantval[Q02_POS];
579
340k
    if (change_dc) {
580
202k
      Q03 = quanttbl->quantval[Q03_POS];
581
202k
      Q12 = quanttbl->quantval[Q12_POS];
582
202k
      Q21 = quanttbl->quantval[Q21_POS];
583
202k
      Q30 = quanttbl->quantval[Q30_POS];
584
202k
    }
585
340k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
340k
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
340k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
681k
    for (block_row = 0; block_row < block_rows; block_row++) {
590
340k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
340k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
340k
      if (image_block_row > 0)
594
333k
        prev_block_row =
595
333k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
7.77k
      else
597
7.77k
        prev_block_row = buffer_ptr;
598
599
340k
      if (image_block_row > 1)
600
329k
        prev_prev_block_row =
601
329k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
10.9k
      else
603
10.9k
        prev_prev_block_row = prev_block_row;
604
605
340k
      if (image_block_row < image_block_rows - 1)
606
333k
        next_block_row =
607
333k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
7.49k
      else
609
7.49k
        next_block_row = buffer_ptr;
610
611
340k
      if (image_block_row < image_block_rows - 2)
612
330k
        next_next_block_row =
613
330k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
10.3k
      else
615
10.3k
        next_next_block_row = next_block_row;
616
617
      /* We fetch the surrounding DC values using a sliding-register approach.
618
       * Initialize all 25 here so as to do the right thing on narrow pics.
619
       */
620
340k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
340k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
340k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
340k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
340k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
340k
      output_col = 0;
626
340k
      last_block_column = compptr->width_in_blocks - 1;
627
340k
      for (block_num = cinfo->master->first_MCU_col[ci];
628
10.8M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
10.5M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
10.5M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
340k
            block_num < last_block_column) {
634
332k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
332k
          DC09 = DC10 = (int)prev_block_row[1][0];
636
332k
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
332k
          DC19 = DC20 = (int)next_block_row[1][0];
638
332k
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
332k
        }
640
10.5M
        if (block_num + 1 < last_block_column) {
641
9.84M
          DC05 = (int)prev_prev_block_row[2][0];
642
9.84M
          DC10 = (int)prev_block_row[2][0];
643
9.84M
          DC15 = (int)buffer_ptr[2][0];
644
9.84M
          DC20 = (int)next_block_row[2][0];
645
9.84M
          DC25 = (int)next_next_block_row[2][0];
646
9.84M
        }
647
        /* If DC interpolation is enabled, compute coefficient estimates using
648
         * a Gaussian-like kernel, keeping the averages of the DC values.
649
         *
650
         * If DC interpolation is disabled, compute coefficient estimates using
651
         * an algorithm similar to the one described in Section K.8 of the JPEG
652
         * standard, except applied to a 5x5 window rather than a 3x3 window.
653
         *
654
         * An estimate is applied only if the coefficient is still zero and is
655
         * not known to be fully accurate.
656
         */
657
        /* AC01 */
658
10.5M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
9.47M
          num = Q00 * (change_dc ?
660
7.31M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
7.31M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
7.31M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
7.31M
                 DC21 - DC22 + DC24 + DC25) :
664
9.47M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
9.47M
          if (num >= 0) {
666
6.27M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
6.27M
            if (Al > 0 && pred >= (1 << Al))
668
467k
              pred = (1 << Al) - 1;
669
6.27M
          } else {
670
3.20M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
3.20M
            if (Al > 0 && pred >= (1 << Al))
672
868k
              pred = (1 << Al) - 1;
673
3.20M
            pred = -pred;
674
3.20M
          }
675
9.47M
          workspace[1] = (JCOEF)pred;
676
9.47M
        }
677
        /* AC10 */
678
10.5M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
9.78M
          num = Q00 * (change_dc ?
680
7.31M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
7.31M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
7.31M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
7.31M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
9.78M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
9.78M
          if (num >= 0) {
686
6.52M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
6.52M
            if (Al > 0 && pred >= (1 << Al))
688
811k
              pred = (1 << Al) - 1;
689
6.52M
          } else {
690
3.26M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
3.26M
            if (Al > 0 && pred >= (1 << Al))
692
875k
              pred = (1 << Al) - 1;
693
3.26M
            pred = -pred;
694
3.26M
          }
695
9.78M
          workspace[8] = (JCOEF)pred;
696
9.78M
        }
697
        /* AC20 */
698
10.5M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
9.93M
          num = Q00 * (change_dc ?
700
7.31M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
7.31M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
9.93M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
9.93M
          if (num >= 0) {
704
6.49M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
6.49M
            if (Al > 0 && pred >= (1 << Al))
706
769k
              pred = (1 << Al) - 1;
707
6.49M
          } else {
708
3.43M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
3.43M
            if (Al > 0 && pred >= (1 << Al))
710
763k
              pred = (1 << Al) - 1;
711
3.43M
            pred = -pred;
712
3.43M
          }
713
9.93M
          workspace[16] = (JCOEF)pred;
714
9.93M
        }
715
        /* AC11 */
716
10.5M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
10.0M
          num = Q00 * (change_dc ?
718
7.31M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
7.31M
                 9 * DC19 + DC21 - DC25) :
720
10.0M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
2.73M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
10.0M
          if (num >= 0) {
723
7.80M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
7.80M
            if (Al > 0 && pred >= (1 << Al))
725
397k
              pred = (1 << Al) - 1;
726
7.80M
          } else {
727
2.24M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
2.24M
            if (Al > 0 && pred >= (1 << Al))
729
377k
              pred = (1 << Al) - 1;
730
2.24M
            pred = -pred;
731
2.24M
          }
732
10.0M
          workspace[9] = (JCOEF)pred;
733
10.0M
        }
734
        /* AC02 */
735
10.5M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
10.2M
          num = Q00 * (change_dc ?
737
7.31M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
7.31M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
10.2M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
10.2M
          if (num >= 0) {
741
6.96M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
6.96M
            if (Al > 0 && pred >= (1 << Al))
743
636k
              pred = (1 << Al) - 1;
744
6.96M
          } else {
745
3.23M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
3.23M
            if (Al > 0 && pred >= (1 << Al))
747
665k
              pred = (1 << Al) - 1;
748
3.23M
            pred = -pred;
749
3.23M
          }
750
10.2M
          workspace[2] = (JCOEF)pred;
751
10.2M
        }
752
10.5M
        if (change_dc) {
753
          /* AC03 */
754
7.31M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
7.31M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
7.31M
            if (num >= 0) {
757
5.52M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
5.52M
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
5.52M
            } else {
761
1.79M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
1.79M
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
1.79M
              pred = -pred;
765
1.79M
            }
766
7.31M
            workspace[3] = (JCOEF)pred;
767
7.31M
          }
768
          /* AC12 */
769
7.31M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
7.31M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
7.31M
            if (num >= 0) {
772
4.63M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
4.63M
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
4.63M
            } else {
776
2.67M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
2.67M
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
2.67M
              pred = -pred;
780
2.67M
            }
781
7.31M
            workspace[10] = (JCOEF)pred;
782
7.31M
          }
783
          /* AC21 */
784
7.31M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
7.31M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
7.31M
            if (num >= 0) {
787
4.84M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
4.84M
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
4.84M
            } else {
791
2.46M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
2.46M
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
2.46M
              pred = -pred;
795
2.46M
            }
796
7.31M
            workspace[17] = (JCOEF)pred;
797
7.31M
          }
798
          /* AC30 */
799
7.31M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
7.31M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
7.31M
            if (num >= 0) {
802
5.41M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
5.41M
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
5.41M
            } else {
806
1.90M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
1.90M
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
1.90M
              pred = -pred;
810
1.90M
            }
811
7.31M
            workspace[24] = (JCOEF)pred;
812
7.31M
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
7.31M
          num = Q00 *
817
7.31M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
7.31M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
7.31M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
7.31M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
7.31M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
7.31M
          if (num >= 0) {
823
4.63M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
4.63M
          } else {
825
2.67M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
2.67M
            pred = -pred;
827
2.67M
          }
828
7.31M
          workspace[0] = (JCOEF)pred;
829
7.31M
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
10.5M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
10.5M
                        output_col);
837
#ifdef WITH_PROFILE
838
        cinfo->master->idct_elapsed += getTime() - cinfo->master->start;
839
        cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
840
#endif
841
        /* Advance for next column */
842
10.5M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
10.5M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
10.5M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
10.5M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
10.5M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
10.5M
        buffer_ptr++, prev_block_row++, next_block_row++,
848
10.5M
          prev_prev_block_row++, next_next_block_row++;
849
10.5M
        output_col += compptr->_DCT_scaled_size;
850
10.5M
      }
851
340k
      output_ptr += compptr->_DCT_scaled_size;
852
340k
    }
853
340k
  }
854
855
330k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
326k
    return JPEG_ROW_COMPLETED;
857
3.78k
  return JPEG_SCAN_COMPLETED;
858
330k
}
jdcoefct-8.c:decompress_smooth_data
Line
Count
Source
474
56.9k
{
475
56.9k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
56.9k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
56.9k
  JDIMENSION block_num, last_block_column;
478
56.9k
  int ci, block_row, block_rows, access_rows, image_block_row,
479
56.9k
    image_block_rows;
480
56.9k
  JBLOCKARRAY buffer;
481
56.9k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
56.9k
  JBLOCKROW next_block_row, next_next_block_row;
483
56.9k
  _JSAMPARRAY output_ptr;
484
56.9k
  JDIMENSION output_col;
485
56.9k
  jpeg_component_info *compptr;
486
56.9k
  _inverse_DCT_method_ptr inverse_DCT;
487
56.9k
  boolean change_dc;
488
56.9k
  JCOEF *workspace;
489
56.9k
  int *coef_bits;
490
56.9k
  JQUANT_TBL *quanttbl;
491
56.9k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
56.9k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
56.9k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
56.9k
      DC25;
495
56.9k
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
56.9k
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
56.9k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
56.9k
         !cinfo->inputctl->eoi_reached) {
503
0
    if (cinfo->input_scan_number == cinfo->output_scan_number) {
504
      /* If input is working on current scan, we ordinarily want it to
505
       * have completed the current row.  But if input scan is DC,
506
       * we want it to keep two rows ahead so that next two block rows' DC
507
       * values are up to date.
508
       */
509
0
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
510
0
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
511
0
        break;
512
0
    }
513
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
514
0
      return JPEG_SUSPENDED;
515
0
  }
516
517
  /* OK, output from the virtual arrays. */
518
124k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
67.1k
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
67.1k
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
67.1k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
57.0k
      block_rows = compptr->v_samp_factor;
526
57.0k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
57.0k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
2.75k
      block_rows = compptr->v_samp_factor;
529
2.75k
      access_rows = block_rows * 2; /* this and next iMCU row */
530
7.43k
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
7.43k
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
7.43k
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
7.43k
      access_rows = block_rows; /* this iMCU row only */
535
7.43k
    }
536
    /* Align the virtual buffer for this component. */
537
67.1k
    if (cinfo->output_iMCU_row > 1) {
538
57.0k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
57.0k
      buffer = (*cinfo->mem->access_virt_barray)
540
57.0k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
57.0k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
57.0k
         (JDIMENSION)access_rows, FALSE);
543
57.0k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
57.0k
    } else if (cinfo->output_iMCU_row > 0) {
545
2.75k
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
2.75k
      buffer = (*cinfo->mem->access_virt_barray)
547
2.75k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
2.75k
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
2.75k
         (JDIMENSION)access_rows, FALSE);
550
2.75k
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
7.43k
    } else {
552
7.43k
      buffer = (*cinfo->mem->access_virt_barray)
553
7.43k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
7.43k
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
7.43k
    }
556
    /* Fetch component-dependent info.
557
     * If the current scan is incomplete, then we use the component-dependent
558
     * info from the previous scan.
559
     */
560
67.1k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
561
728
      coef_bits =
562
728
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
563
66.4k
    else
564
66.4k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
565
566
    /* We only do DC interpolation if no AC coefficient data is available. */
567
67.1k
    change_dc =
568
67.1k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
63.5k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
59.5k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
67.1k
    quanttbl = compptr->quant_table;
573
67.1k
    Q00 = quanttbl->quantval[0];
574
67.1k
    Q01 = quanttbl->quantval[Q01_POS];
575
67.1k
    Q10 = quanttbl->quantval[Q10_POS];
576
67.1k
    Q20 = quanttbl->quantval[Q20_POS];
577
67.1k
    Q11 = quanttbl->quantval[Q11_POS];
578
67.1k
    Q02 = quanttbl->quantval[Q02_POS];
579
67.1k
    if (change_dc) {
580
58.9k
      Q03 = quanttbl->quantval[Q03_POS];
581
58.9k
      Q12 = quanttbl->quantval[Q12_POS];
582
58.9k
      Q21 = quanttbl->quantval[Q21_POS];
583
58.9k
      Q30 = quanttbl->quantval[Q30_POS];
584
58.9k
    }
585
67.1k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
67.1k
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
67.1k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
134k
    for (block_row = 0; block_row < block_rows; block_row++) {
590
67.5k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
67.5k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
67.5k
      if (image_block_row > 0)
594
60.0k
        prev_block_row =
595
60.0k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
7.43k
      else
597
7.43k
        prev_block_row = buffer_ptr;
598
599
67.5k
      if (image_block_row > 1)
600
57.2k
        prev_prev_block_row =
601
57.2k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
10.2k
      else
603
10.2k
        prev_prev_block_row = prev_block_row;
604
605
67.5k
      if (image_block_row < image_block_rows - 1)
606
60.0k
        next_block_row =
607
60.0k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
7.43k
      else
609
7.43k
        next_block_row = buffer_ptr;
610
611
67.5k
      if (image_block_row < image_block_rows - 2)
612
57.2k
        next_next_block_row =
613
57.2k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
10.2k
      else
615
10.2k
        next_next_block_row = next_block_row;
616
617
      /* We fetch the surrounding DC values using a sliding-register approach.
618
       * Initialize all 25 here so as to do the right thing on narrow pics.
619
       */
620
67.5k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
67.5k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
67.5k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
67.5k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
67.5k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
67.5k
      output_col = 0;
626
67.5k
      last_block_column = compptr->width_in_blocks - 1;
627
67.5k
      for (block_num = cinfo->master->first_MCU_col[ci];
628
6.58M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
6.52M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
6.52M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
67.5k
            block_num < last_block_column) {
634
59.8k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
59.8k
          DC09 = DC10 = (int)prev_block_row[1][0];
636
59.8k
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
59.8k
          DC19 = DC20 = (int)next_block_row[1][0];
638
59.8k
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
59.8k
        }
640
6.52M
        if (block_num + 1 < last_block_column) {
641
6.39M
          DC05 = (int)prev_prev_block_row[2][0];
642
6.39M
          DC10 = (int)prev_block_row[2][0];
643
6.39M
          DC15 = (int)buffer_ptr[2][0];
644
6.39M
          DC20 = (int)next_block_row[2][0];
645
6.39M
          DC25 = (int)next_next_block_row[2][0];
646
6.39M
        }
647
        /* If DC interpolation is enabled, compute coefficient estimates using
648
         * a Gaussian-like kernel, keeping the averages of the DC values.
649
         *
650
         * If DC interpolation is disabled, compute coefficient estimates using
651
         * an algorithm similar to the one described in Section K.8 of the JPEG
652
         * standard, except applied to a 5x5 window rather than a 3x3 window.
653
         *
654
         * An estimate is applied only if the coefficient is still zero and is
655
         * not known to be fully accurate.
656
         */
657
        /* AC01 */
658
6.52M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
5.66M
          num = Q00 * (change_dc ?
660
4.22M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
4.22M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
4.22M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
4.22M
                 DC21 - DC22 + DC24 + DC25) :
664
5.66M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
5.66M
          if (num >= 0) {
666
3.14M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
3.14M
            if (Al > 0 && pred >= (1 << Al))
668
213k
              pred = (1 << Al) - 1;
669
3.14M
          } else {
670
2.51M
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
2.51M
            if (Al > 0 && pred >= (1 << Al))
672
687k
              pred = (1 << Al) - 1;
673
2.51M
            pred = -pred;
674
2.51M
          }
675
5.66M
          workspace[1] = (JCOEF)pred;
676
5.66M
        }
677
        /* AC10 */
678
6.52M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
5.93M
          num = Q00 * (change_dc ?
680
4.22M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
4.22M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
4.22M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
4.22M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
5.93M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
5.93M
          if (num >= 0) {
686
3.38M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
3.38M
            if (Al > 0 && pred >= (1 << Al))
688
582k
              pred = (1 << Al) - 1;
689
3.38M
          } else {
690
2.54M
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
2.54M
            if (Al > 0 && pred >= (1 << Al))
692
729k
              pred = (1 << Al) - 1;
693
2.54M
            pred = -pred;
694
2.54M
          }
695
5.93M
          workspace[8] = (JCOEF)pred;
696
5.93M
        }
697
        /* AC20 */
698
6.52M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
6.08M
          num = Q00 * (change_dc ?
700
4.22M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
4.22M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
6.08M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
6.08M
          if (num >= 0) {
704
3.43M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
3.43M
            if (Al > 0 && pred >= (1 << Al))
706
711k
              pred = (1 << Al) - 1;
707
3.43M
          } else {
708
2.65M
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
2.65M
            if (Al > 0 && pred >= (1 << Al))
710
706k
              pred = (1 << Al) - 1;
711
2.65M
            pred = -pred;
712
2.65M
          }
713
6.08M
          workspace[16] = (JCOEF)pred;
714
6.08M
        }
715
        /* AC11 */
716
6.52M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
6.09M
          num = Q00 * (change_dc ?
718
4.22M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
4.22M
                 9 * DC19 + DC21 - DC25) :
720
6.09M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
1.87M
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
6.09M
          if (num >= 0) {
723
4.53M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
4.53M
            if (Al > 0 && pred >= (1 << Al))
725
327k
              pred = (1 << Al) - 1;
726
4.53M
          } else {
727
1.56M
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
1.56M
            if (Al > 0 && pred >= (1 << Al))
729
305k
              pred = (1 << Al) - 1;
730
1.56M
            pred = -pred;
731
1.56M
          }
732
6.09M
          workspace[9] = (JCOEF)pred;
733
6.09M
        }
734
        /* AC02 */
735
6.52M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
6.28M
          num = Q00 * (change_dc ?
737
4.22M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
4.22M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
6.28M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
6.28M
          if (num >= 0) {
741
3.83M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
3.83M
            if (Al > 0 && pred >= (1 << Al))
743
471k
              pred = (1 << Al) - 1;
744
3.83M
          } else {
745
2.44M
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
2.44M
            if (Al > 0 && pred >= (1 << Al))
747
490k
              pred = (1 << Al) - 1;
748
2.44M
            pred = -pred;
749
2.44M
          }
750
6.28M
          workspace[2] = (JCOEF)pred;
751
6.28M
        }
752
6.52M
        if (change_dc) {
753
          /* AC03 */
754
4.22M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
4.22M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
4.22M
            if (num >= 0) {
757
2.79M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
2.79M
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
2.79M
            } else {
761
1.42M
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
1.42M
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
1.42M
              pred = -pred;
765
1.42M
            }
766
4.22M
            workspace[3] = (JCOEF)pred;
767
4.22M
          }
768
          /* AC12 */
769
4.22M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
4.22M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
4.22M
            if (num >= 0) {
772
2.03M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
2.03M
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
2.18M
            } else {
776
2.18M
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
2.18M
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
2.18M
              pred = -pred;
780
2.18M
            }
781
4.22M
            workspace[10] = (JCOEF)pred;
782
4.22M
          }
783
          /* AC21 */
784
4.22M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
4.22M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
4.22M
            if (num >= 0) {
787
2.17M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
2.17M
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
2.17M
            } else {
791
2.05M
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
2.05M
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
2.05M
              pred = -pred;
795
2.05M
            }
796
4.22M
            workspace[17] = (JCOEF)pred;
797
4.22M
          }
798
          /* AC30 */
799
4.22M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
4.22M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
4.22M
            if (num >= 0) {
802
2.70M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
2.70M
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
2.70M
            } else {
806
1.52M
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
1.52M
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
1.52M
              pred = -pred;
810
1.52M
            }
811
4.22M
            workspace[24] = (JCOEF)pred;
812
4.22M
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
4.22M
          num = Q00 *
817
4.22M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
4.22M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
4.22M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
4.22M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
4.22M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
4.22M
          if (num >= 0) {
823
2.09M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
2.12M
          } else {
825
2.12M
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
2.12M
            pred = -pred;
827
2.12M
          }
828
4.22M
          workspace[0] = (JCOEF)pred;
829
4.22M
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
6.52M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
6.52M
                        output_col);
837
#ifdef WITH_PROFILE
838
        cinfo->master->idct_elapsed += getTime() - cinfo->master->start;
839
        cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
840
#endif
841
        /* Advance for next column */
842
6.52M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
6.52M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
6.52M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
6.52M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
6.52M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
6.52M
        buffer_ptr++, prev_block_row++, next_block_row++,
848
6.52M
          prev_prev_block_row++, next_next_block_row++;
849
6.52M
        output_col += compptr->_DCT_scaled_size;
850
6.52M
      }
851
67.5k
      output_ptr += compptr->_DCT_scaled_size;
852
67.5k
    }
853
67.1k
  }
854
855
56.9k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
53.2k
    return JPEG_ROW_COMPLETED;
857
3.71k
  return JPEG_SCAN_COMPLETED;
858
56.9k
}
jdcoefct-12.c:decompress_smooth_data
Line
Count
Source
474
273k
{
475
273k
  my_coef_ptr coef = (my_coef_ptr)cinfo->coef;
476
273k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
477
273k
  JDIMENSION block_num, last_block_column;
478
273k
  int ci, block_row, block_rows, access_rows, image_block_row,
479
273k
    image_block_rows;
480
273k
  JBLOCKARRAY buffer;
481
273k
  JBLOCKROW buffer_ptr, prev_prev_block_row, prev_block_row;
482
273k
  JBLOCKROW next_block_row, next_next_block_row;
483
273k
  _JSAMPARRAY output_ptr;
484
273k
  JDIMENSION output_col;
485
273k
  jpeg_component_info *compptr;
486
273k
  _inverse_DCT_method_ptr inverse_DCT;
487
273k
  boolean change_dc;
488
273k
  JCOEF *workspace;
489
273k
  int *coef_bits;
490
273k
  JQUANT_TBL *quanttbl;
491
273k
  JLONG Q00, Q01, Q02, Q03 = 0, Q10, Q11, Q12 = 0, Q20, Q21 = 0, Q30 = 0, num;
492
273k
  int DC01, DC02, DC03, DC04, DC05, DC06, DC07, DC08, DC09, DC10, DC11, DC12,
493
273k
      DC13, DC14, DC15, DC16, DC17, DC18, DC19, DC20, DC21, DC22, DC23, DC24,
494
273k
      DC25;
495
273k
  int Al, pred;
496
497
  /* Keep a local variable to avoid looking it up more than once */
498
273k
  workspace = coef->workspace;
499
500
  /* Force some input to be done if we are getting ahead of the input. */
501
273k
  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
502
273k
         !cinfo->inputctl->eoi_reached) {
503
0
    if (cinfo->input_scan_number == cinfo->output_scan_number) {
504
      /* If input is working on current scan, we ordinarily want it to
505
       * have completed the current row.  But if input scan is DC,
506
       * we want it to keep two rows ahead so that next two block rows' DC
507
       * values are up to date.
508
       */
509
0
      JDIMENSION delta = (cinfo->Ss == 0) ? 2 : 0;
510
0
      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row + delta)
511
0
        break;
512
0
    }
513
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
514
0
      return JPEG_SUSPENDED;
515
0
  }
516
517
  /* OK, output from the virtual arrays. */
518
546k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
519
273k
       ci++, compptr++) {
520
    /* Don't bother to IDCT an uninteresting component. */
521
273k
    if (!compptr->component_needed)
522
0
      continue;
523
    /* Count non-dummy DCT block rows in this iMCU row. */
524
273k
    if (cinfo->output_iMCU_row + 1 < last_iMCU_row) {
525
273k
      block_rows = compptr->v_samp_factor;
526
273k
      access_rows = block_rows * 3; /* this and next two iMCU rows */
527
273k
    } else if (cinfo->output_iMCU_row < last_iMCU_row) {
528
54
      block_rows = compptr->v_samp_factor;
529
54
      access_rows = block_rows * 2; /* this and next iMCU row */
530
67
    } else {
531
      /* NB: can't use last_row_height here; it is input-side-dependent! */
532
67
      block_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
533
67
      if (block_rows == 0) block_rows = compptr->v_samp_factor;
534
67
      access_rows = block_rows; /* this iMCU row only */
535
67
    }
536
    /* Align the virtual buffer for this component. */
537
273k
    if (cinfo->output_iMCU_row > 1) {
538
272k
      access_rows += 2 * compptr->v_samp_factor; /* prior two iMCU rows too */
539
272k
      buffer = (*cinfo->mem->access_virt_barray)
540
272k
        ((j_common_ptr)cinfo, coef->whole_image[ci],
541
272k
         (cinfo->output_iMCU_row - 2) * compptr->v_samp_factor,
542
272k
         (JDIMENSION)access_rows, FALSE);
543
272k
      buffer += 2 * compptr->v_samp_factor; /* point to current iMCU row */
544
272k
    } else if (cinfo->output_iMCU_row > 0) {
545
319
      access_rows += compptr->v_samp_factor; /* prior iMCU row too */
546
319
      buffer = (*cinfo->mem->access_virt_barray)
547
319
        ((j_common_ptr)cinfo, coef->whole_image[ci],
548
319
         (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
549
319
         (JDIMENSION)access_rows, FALSE);
550
319
      buffer += compptr->v_samp_factor; /* point to current iMCU row */
551
343
    } else {
552
343
      buffer = (*cinfo->mem->access_virt_barray)
553
343
        ((j_common_ptr)cinfo, coef->whole_image[ci],
554
343
         (JDIMENSION)0, (JDIMENSION)access_rows, FALSE);
555
343
    }
556
    /* Fetch component-dependent info.
557
     * If the current scan is incomplete, then we use the component-dependent
558
     * info from the previous scan.
559
     */
560
273k
    if (cinfo->output_iMCU_row > cinfo->master->last_good_iMCU_row)
561
2.45k
      coef_bits =
562
2.45k
        coef->coef_bits_latch + ((ci + cinfo->num_components) * SAVED_COEFS);
563
270k
    else
564
270k
      coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
565
566
    /* We only do DC interpolation if no AC coefficient data is available. */
567
273k
    change_dc =
568
273k
      coef_bits[1] == -1 && coef_bits[2] == -1 && coef_bits[3] == -1 &&
569
156k
      coef_bits[4] == -1 && coef_bits[5] == -1 && coef_bits[6] == -1 &&
570
148k
      coef_bits[7] == -1 && coef_bits[8] == -1 && coef_bits[9] == -1;
571
572
273k
    quanttbl = compptr->quant_table;
573
273k
    Q00 = quanttbl->quantval[0];
574
273k
    Q01 = quanttbl->quantval[Q01_POS];
575
273k
    Q10 = quanttbl->quantval[Q10_POS];
576
273k
    Q20 = quanttbl->quantval[Q20_POS];
577
273k
    Q11 = quanttbl->quantval[Q11_POS];
578
273k
    Q02 = quanttbl->quantval[Q02_POS];
579
273k
    if (change_dc) {
580
143k
      Q03 = quanttbl->quantval[Q03_POS];
581
143k
      Q12 = quanttbl->quantval[Q12_POS];
582
143k
      Q21 = quanttbl->quantval[Q21_POS];
583
143k
      Q30 = quanttbl->quantval[Q30_POS];
584
143k
    }
585
273k
    inverse_DCT = cinfo->idct->_inverse_DCT[ci];
586
273k
    output_ptr = output_buf[ci];
587
    /* Loop over all DCT blocks to be processed. */
588
273k
    image_block_rows = block_rows * cinfo->total_iMCU_rows;
589
546k
    for (block_row = 0; block_row < block_rows; block_row++) {
590
273k
      image_block_row = cinfo->output_iMCU_row * block_rows + block_row;
591
273k
      buffer_ptr = buffer[block_row] + cinfo->master->first_MCU_col[ci];
592
593
273k
      if (image_block_row > 0)
594
272k
        prev_block_row =
595
272k
          buffer[block_row - 1] + cinfo->master->first_MCU_col[ci];
596
343
      else
597
343
        prev_block_row = buffer_ptr;
598
599
273k
      if (image_block_row > 1)
600
272k
        prev_prev_block_row =
601
272k
          buffer[block_row - 2] + cinfo->master->first_MCU_col[ci];
602
662
      else
603
662
        prev_prev_block_row = prev_block_row;
604
605
273k
      if (image_block_row < image_block_rows - 1)
606
273k
        next_block_row =
607
273k
          buffer[block_row + 1] + cinfo->master->first_MCU_col[ci];
608
67
      else
609
67
        next_block_row = buffer_ptr;
610
611
273k
      if (image_block_row < image_block_rows - 2)
612
273k
        next_next_block_row =
613
273k
          buffer[block_row + 2] + cinfo->master->first_MCU_col[ci];
614
121
      else
615
121
        next_next_block_row = next_block_row;
616
617
      /* We fetch the surrounding DC values using a sliding-register approach.
618
       * Initialize all 25 here so as to do the right thing on narrow pics.
619
       */
620
273k
      DC01 = DC02 = DC03 = DC04 = DC05 = (int)prev_prev_block_row[0][0];
621
273k
      DC06 = DC07 = DC08 = DC09 = DC10 = (int)prev_block_row[0][0];
622
273k
      DC11 = DC12 = DC13 = DC14 = DC15 = (int)buffer_ptr[0][0];
623
273k
      DC16 = DC17 = DC18 = DC19 = DC20 = (int)next_block_row[0][0];
624
273k
      DC21 = DC22 = DC23 = DC24 = DC25 = (int)next_next_block_row[0][0];
625
273k
      output_col = 0;
626
273k
      last_block_column = compptr->width_in_blocks - 1;
627
273k
      for (block_num = cinfo->master->first_MCU_col[ci];
628
4.27M
           block_num <= cinfo->master->last_MCU_col[ci]; block_num++) {
629
        /* Fetch current DCT block into workspace so we can modify it. */
630
4.00M
        jcopy_block_row(buffer_ptr, (JBLOCKROW)workspace, (JDIMENSION)1);
631
        /* Update DC values */
632
4.00M
        if (block_num == cinfo->master->first_MCU_col[ci] &&
633
273k
            block_num < last_block_column) {
634
273k
          DC04 = DC05 = (int)prev_prev_block_row[1][0];
635
273k
          DC09 = DC10 = (int)prev_block_row[1][0];
636
273k
          DC14 = DC15 = (int)buffer_ptr[1][0];
637
273k
          DC19 = DC20 = (int)next_block_row[1][0];
638
273k
          DC24 = DC25 = (int)next_next_block_row[1][0];
639
273k
        }
640
4.00M
        if (block_num + 1 < last_block_column) {
641
3.45M
          DC05 = (int)prev_prev_block_row[2][0];
642
3.45M
          DC10 = (int)prev_block_row[2][0];
643
3.45M
          DC15 = (int)buffer_ptr[2][0];
644
3.45M
          DC20 = (int)next_block_row[2][0];
645
3.45M
          DC25 = (int)next_next_block_row[2][0];
646
3.45M
        }
647
        /* If DC interpolation is enabled, compute coefficient estimates using
648
         * a Gaussian-like kernel, keeping the averages of the DC values.
649
         *
650
         * If DC interpolation is disabled, compute coefficient estimates using
651
         * an algorithm similar to the one described in Section K.8 of the JPEG
652
         * standard, except applied to a 5x5 window rather than a 3x3 window.
653
         *
654
         * An estimate is applied only if the coefficient is still zero and is
655
         * not known to be fully accurate.
656
         */
657
        /* AC01 */
658
4.00M
        if ((Al = coef_bits[1]) != 0 && workspace[1] == 0) {
659
3.80M
          num = Q00 * (change_dc ?
660
3.09M
                (-DC01 - DC02 + DC04 + DC05 - 3 * DC06 + 13 * DC07 -
661
3.09M
                 13 * DC09 + 3 * DC10 - 3 * DC11 + 38 * DC12 - 38 * DC14 +
662
3.09M
                 3 * DC15 - 3 * DC16 + 13 * DC17 - 13 * DC19 + 3 * DC20 -
663
3.09M
                 DC21 - DC22 + DC24 + DC25) :
664
3.80M
                (-7 * DC11 + 50 * DC12 - 50 * DC14 + 7 * DC15));
665
3.80M
          if (num >= 0) {
666
3.12M
            pred = (int)(((Q01 << 7) + num) / (Q01 << 8));
667
3.12M
            if (Al > 0 && pred >= (1 << Al))
668
254k
              pred = (1 << Al) - 1;
669
3.12M
          } else {
670
681k
            pred = (int)(((Q01 << 7) - num) / (Q01 << 8));
671
681k
            if (Al > 0 && pred >= (1 << Al))
672
181k
              pred = (1 << Al) - 1;
673
681k
            pred = -pred;
674
681k
          }
675
3.80M
          workspace[1] = (JCOEF)pred;
676
3.80M
        }
677
        /* AC10 */
678
4.00M
        if ((Al = coef_bits[2]) != 0 && workspace[8] == 0) {
679
3.85M
          num = Q00 * (change_dc ?
680
3.09M
                (-DC01 - 3 * DC02 - 3 * DC03 - 3 * DC04 - DC05 - DC06 +
681
3.09M
                 13 * DC07 + 38 * DC08 + 13 * DC09 - DC10 + DC16 -
682
3.09M
                 13 * DC17 - 38 * DC18 - 13 * DC19 + DC20 + DC21 +
683
3.09M
                 3 * DC22 + 3 * DC23 + 3 * DC24 + DC25) :
684
3.85M
                (-7 * DC03 + 50 * DC08 - 50 * DC18 + 7 * DC23));
685
3.85M
          if (num >= 0) {
686
3.13M
            pred = (int)(((Q10 << 7) + num) / (Q10 << 8));
687
3.13M
            if (Al > 0 && pred >= (1 << Al))
688
229k
              pred = (1 << Al) - 1;
689
3.13M
          } else {
690
717k
            pred = (int)(((Q10 << 7) - num) / (Q10 << 8));
691
717k
            if (Al > 0 && pred >= (1 << Al))
692
145k
              pred = (1 << Al) - 1;
693
717k
            pred = -pred;
694
717k
          }
695
3.85M
          workspace[8] = (JCOEF)pred;
696
3.85M
        }
697
        /* AC20 */
698
4.00M
        if ((Al = coef_bits[3]) != 0 && workspace[16] == 0) {
699
3.84M
          num = Q00 * (change_dc ?
700
3.09M
                (DC03 + 2 * DC07 + 7 * DC08 + 2 * DC09 - 5 * DC12 - 14 * DC13 -
701
3.09M
                 5 * DC14 + 2 * DC17 + 7 * DC18 + 2 * DC19 + DC23) :
702
3.84M
                (-DC03 + 13 * DC08 - 24 * DC13 + 13 * DC18 - DC23));
703
3.84M
          if (num >= 0) {
704
3.05M
            pred = (int)(((Q20 << 7) + num) / (Q20 << 8));
705
3.05M
            if (Al > 0 && pred >= (1 << Al))
706
57.9k
              pred = (1 << Al) - 1;
707
3.05M
          } else {
708
786k
            pred = (int)(((Q20 << 7) - num) / (Q20 << 8));
709
786k
            if (Al > 0 && pred >= (1 << Al))
710
57.1k
              pred = (1 << Al) - 1;
711
786k
            pred = -pred;
712
786k
          }
713
3.84M
          workspace[16] = (JCOEF)pred;
714
3.84M
        }
715
        /* AC11 */
716
4.00M
        if ((Al = coef_bits[4]) != 0 && workspace[9] == 0) {
717
3.94M
          num = Q00 * (change_dc ?
718
3.09M
                (-DC01 + DC05 + 9 * DC07 - 9 * DC09 - 9 * DC17 +
719
3.09M
                 9 * DC19 + DC21 - DC25) :
720
3.94M
                (DC10 + DC16 - 10 * DC17 + 10 * DC19 - DC02 - DC20 + DC22 -
721
855k
                 DC24 + DC04 - DC06 + 10 * DC07 - 10 * DC09));
722
3.94M
          if (num >= 0) {
723
3.26M
            pred = (int)(((Q11 << 7) + num) / (Q11 << 8));
724
3.26M
            if (Al > 0 && pred >= (1 << Al))
725
69.7k
              pred = (1 << Al) - 1;
726
3.26M
          } else {
727
679k
            pred = (int)(((Q11 << 7) - num) / (Q11 << 8));
728
679k
            if (Al > 0 && pred >= (1 << Al))
729
71.4k
              pred = (1 << Al) - 1;
730
679k
            pred = -pred;
731
679k
          }
732
3.94M
          workspace[9] = (JCOEF)pred;
733
3.94M
        }
734
        /* AC02 */
735
4.00M
        if ((Al = coef_bits[5]) != 0 && workspace[2] == 0) {
736
3.91M
          num = Q00 * (change_dc ?
737
3.09M
                (2 * DC07 - 5 * DC08 + 2 * DC09 + DC11 + 7 * DC12 - 14 * DC13 +
738
3.09M
                 7 * DC14 + DC15 + 2 * DC17 - 5 * DC18 + 2 * DC19) :
739
3.91M
                (-DC11 + 13 * DC12 - 24 * DC13 + 13 * DC14 - DC15));
740
3.91M
          if (num >= 0) {
741
3.12M
            pred = (int)(((Q02 << 7) + num) / (Q02 << 8));
742
3.12M
            if (Al > 0 && pred >= (1 << Al))
743
165k
              pred = (1 << Al) - 1;
744
3.12M
          } else {
745
796k
            pred = (int)(((Q02 << 7) - num) / (Q02 << 8));
746
796k
            if (Al > 0 && pred >= (1 << Al))
747
174k
              pred = (1 << Al) - 1;
748
796k
            pred = -pred;
749
796k
          }
750
3.91M
          workspace[2] = (JCOEF)pred;
751
3.91M
        }
752
4.00M
        if (change_dc) {
753
          /* AC03 */
754
3.09M
          if ((Al = coef_bits[6]) != 0 && workspace[3] == 0) {
755
3.09M
            num = Q00 * (DC07 - DC09 + 2 * DC12 - 2 * DC14 + DC17 - DC19);
756
3.09M
            if (num >= 0) {
757
2.73M
              pred = (int)(((Q03 << 7) + num) / (Q03 << 8));
758
2.73M
              if (Al > 0 && pred >= (1 << Al))
759
0
                pred = (1 << Al) - 1;
760
2.73M
            } else {
761
363k
              pred = (int)(((Q03 << 7) - num) / (Q03 << 8));
762
363k
              if (Al > 0 && pred >= (1 << Al))
763
0
                pred = (1 << Al) - 1;
764
363k
              pred = -pred;
765
363k
            }
766
3.09M
            workspace[3] = (JCOEF)pred;
767
3.09M
          }
768
          /* AC12 */
769
3.09M
          if ((Al = coef_bits[7]) != 0 && workspace[10] == 0) {
770
3.09M
            num = Q00 * (DC07 - 3 * DC08 + DC09 - DC17 + 3 * DC18 - DC19);
771
3.09M
            if (num >= 0) {
772
2.59M
              pred = (int)(((Q12 << 7) + num) / (Q12 << 8));
773
2.59M
              if (Al > 0 && pred >= (1 << Al))
774
0
                pred = (1 << Al) - 1;
775
2.59M
            } else {
776
495k
              pred = (int)(((Q12 << 7) - num) / (Q12 << 8));
777
495k
              if (Al > 0 && pred >= (1 << Al))
778
0
                pred = (1 << Al) - 1;
779
495k
              pred = -pred;
780
495k
            }
781
3.09M
            workspace[10] = (JCOEF)pred;
782
3.09M
          }
783
          /* AC21 */
784
3.09M
          if ((Al = coef_bits[8]) != 0 && workspace[17] == 0) {
785
3.09M
            num = Q00 * (DC07 - DC09 - 3 * DC12 + 3 * DC14 + DC17 - DC19);
786
3.09M
            if (num >= 0) {
787
2.67M
              pred = (int)(((Q21 << 7) + num) / (Q21 << 8));
788
2.67M
              if (Al > 0 && pred >= (1 << Al))
789
0
                pred = (1 << Al) - 1;
790
2.67M
            } else {
791
415k
              pred = (int)(((Q21 << 7) - num) / (Q21 << 8));
792
415k
              if (Al > 0 && pred >= (1 << Al))
793
0
                pred = (1 << Al) - 1;
794
415k
              pred = -pred;
795
415k
            }
796
3.09M
            workspace[17] = (JCOEF)pred;
797
3.09M
          }
798
          /* AC30 */
799
3.09M
          if ((Al = coef_bits[9]) != 0 && workspace[24] == 0) {
800
3.09M
            num = Q00 * (DC07 + 2 * DC08 + DC09 - DC17 - 2 * DC18 - DC19);
801
3.09M
            if (num >= 0) {
802
2.71M
              pred = (int)(((Q30 << 7) + num) / (Q30 << 8));
803
2.71M
              if (Al > 0 && pred >= (1 << Al))
804
0
                pred = (1 << Al) - 1;
805
2.71M
            } else {
806
382k
              pred = (int)(((Q30 << 7) - num) / (Q30 << 8));
807
382k
              if (Al > 0 && pred >= (1 << Al))
808
0
                pred = (1 << Al) - 1;
809
382k
              pred = -pred;
810
382k
            }
811
3.09M
            workspace[24] = (JCOEF)pred;
812
3.09M
          }
813
          /* coef_bits[0] is non-negative.  Otherwise this function would not
814
           * be called.
815
           */
816
3.09M
          num = Q00 *
817
3.09M
                (-2 * DC01 - 6 * DC02 - 8 * DC03 - 6 * DC04 - 2 * DC05 -
818
3.09M
                 6 * DC06 + 6 * DC07 + 42 * DC08 + 6 * DC09 - 6 * DC10 -
819
3.09M
                 8 * DC11 + 42 * DC12 + 152 * DC13 + 42 * DC14 - 8 * DC15 -
820
3.09M
                 6 * DC16 + 6 * DC17 + 42 * DC18 + 6 * DC19 - 6 * DC20 -
821
3.09M
                 2 * DC21 - 6 * DC22 - 8 * DC23 - 6 * DC24 - 2 * DC25);
822
3.09M
          if (num >= 0) {
823
2.53M
            pred = (int)(((Q00 << 7) + num) / (Q00 << 8));
824
2.53M
          } else {
825
555k
            pred = (int)(((Q00 << 7) - num) / (Q00 << 8));
826
555k
            pred = -pred;
827
555k
          }
828
3.09M
          workspace[0] = (JCOEF)pred;
829
3.09M
        }  /* change_dc */
830
831
        /* OK, do the IDCT */
832
#ifdef WITH_PROFILE
833
        cinfo->master->start = getTime();
834
#endif
835
4.00M
        (*inverse_DCT) (cinfo, compptr, (JCOEFPTR)workspace, output_ptr,
836
4.00M
                        output_col);
837
#ifdef WITH_PROFILE
838
        cinfo->master->idct_elapsed += getTime() - cinfo->master->start;
839
        cinfo->master->idct_mcoeffs += (double)DCTSIZE2 / 1000000.;
840
#endif
841
        /* Advance for next column */
842
4.00M
        DC01 = DC02;  DC02 = DC03;  DC03 = DC04;  DC04 = DC05;
843
4.00M
        DC06 = DC07;  DC07 = DC08;  DC08 = DC09;  DC09 = DC10;
844
4.00M
        DC11 = DC12;  DC12 = DC13;  DC13 = DC14;  DC14 = DC15;
845
4.00M
        DC16 = DC17;  DC17 = DC18;  DC18 = DC19;  DC19 = DC20;
846
4.00M
        DC21 = DC22;  DC22 = DC23;  DC23 = DC24;  DC24 = DC25;
847
4.00M
        buffer_ptr++, prev_block_row++, next_block_row++,
848
4.00M
          prev_prev_block_row++, next_next_block_row++;
849
4.00M
        output_col += compptr->_DCT_scaled_size;
850
4.00M
      }
851
273k
      output_ptr += compptr->_DCT_scaled_size;
852
273k
    }
853
273k
  }
854
855
273k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
856
273k
    return JPEG_ROW_COMPLETED;
857
67
  return JPEG_SCAN_COMPLETED;
858
273k
}
859
860
#endif /* BLOCK_SMOOTHING_SUPPORTED */
861
862
863
/*
864
 * Initialize coefficient buffer controller.
865
 */
866
867
GLOBAL(void)
868
_jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
869
92.6k
{
870
92.6k
  my_coef_ptr coef;
871
872
92.6k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
92.6k
  coef = (my_coef_ptr)
876
92.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
92.6k
                                sizeof(my_coef_controller));
878
92.6k
  memset(coef, 0, sizeof(my_coef_controller));
879
92.6k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
92.6k
  coef->pub.start_input_pass = start_input_pass;
881
92.6k
  coef->pub.start_output_pass = start_output_pass;
882
92.6k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
92.6k
  coef->coef_bits_latch = NULL;
884
92.6k
#endif
885
886
  /* Create the coefficient buffer. */
887
92.6k
  if (need_full_buffer) {
888
33.3k
#ifdef D_MULTISCAN_FILES_SUPPORTED
889
    /* Allocate a full-image virtual array for each component, */
890
    /* padded to a multiple of samp_factor DCT blocks in each direction. */
891
    /* Note we ask for a pre-zeroed array. */
892
33.3k
    int ci, access_rows;
893
33.3k
    jpeg_component_info *compptr;
894
895
102k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
69.2k
         ci++, compptr++) {
897
69.2k
      access_rows = compptr->v_samp_factor;
898
69.2k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
69.2k
      if (cinfo->progressive_mode)
901
58.1k
        access_rows *= 5;
902
69.2k
#endif
903
69.2k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
69.2k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
69.2k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
69.2k
                               (long)compptr->h_samp_factor),
907
69.2k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
69.2k
                               (long)compptr->v_samp_factor),
909
69.2k
         (JDIMENSION)access_rows);
910
69.2k
    }
911
33.3k
    coef->pub.consume_data = consume_data;
912
33.3k
    coef->pub._decompress_data = decompress_data;
913
33.3k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
59.2k
  } else {
918
    /* We only need a single-MCU buffer. */
919
59.2k
    JBLOCKROW buffer;
920
59.2k
    int i;
921
922
59.2k
    buffer = (JBLOCKROW)
923
59.2k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
59.2k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
651k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
592k
      coef->MCU_buffer[i] = buffer + i;
927
592k
    }
928
59.2k
    coef->pub.consume_data = dummy_consume_data;
929
59.2k
    coef->pub._decompress_data = decompress_onepass;
930
59.2k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
59.2k
  }
932
933
  /* Allocate the workspace buffer */
934
92.6k
  coef->workspace = (JCOEF *)
935
92.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
92.6k
                                sizeof(JCOEF) * DCTSIZE2);
937
92.6k
}
jinit_d_coef_controller
Line
Count
Source
869
92.0k
{
870
92.0k
  my_coef_ptr coef;
871
872
92.0k
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
92.0k
  coef = (my_coef_ptr)
876
92.0k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
92.0k
                                sizeof(my_coef_controller));
878
92.0k
  memset(coef, 0, sizeof(my_coef_controller));
879
92.0k
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
92.0k
  coef->pub.start_input_pass = start_input_pass;
881
92.0k
  coef->pub.start_output_pass = start_output_pass;
882
92.0k
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
92.0k
  coef->coef_bits_latch = NULL;
884
92.0k
#endif
885
886
  /* Create the coefficient buffer. */
887
92.0k
  if (need_full_buffer) {
888
32.8k
#ifdef D_MULTISCAN_FILES_SUPPORTED
889
    /* Allocate a full-image virtual array for each component, */
890
    /* padded to a multiple of samp_factor DCT blocks in each direction. */
891
    /* Note we ask for a pre-zeroed array. */
892
32.8k
    int ci, access_rows;
893
32.8k
    jpeg_component_info *compptr;
894
895
101k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
68.7k
         ci++, compptr++) {
897
68.7k
      access_rows = compptr->v_samp_factor;
898
68.7k
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
68.7k
      if (cinfo->progressive_mode)
901
57.6k
        access_rows *= 5;
902
68.7k
#endif
903
68.7k
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
68.7k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
68.7k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
68.7k
                               (long)compptr->h_samp_factor),
907
68.7k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
68.7k
                               (long)compptr->v_samp_factor),
909
68.7k
         (JDIMENSION)access_rows);
910
68.7k
    }
911
32.8k
    coef->pub.consume_data = consume_data;
912
32.8k
    coef->pub._decompress_data = decompress_data;
913
32.8k
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
59.1k
  } else {
918
    /* We only need a single-MCU buffer. */
919
59.1k
    JBLOCKROW buffer;
920
59.1k
    int i;
921
922
59.1k
    buffer = (JBLOCKROW)
923
59.1k
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
59.1k
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
650k
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
591k
      coef->MCU_buffer[i] = buffer + i;
927
591k
    }
928
59.1k
    coef->pub.consume_data = dummy_consume_data;
929
59.1k
    coef->pub._decompress_data = decompress_onepass;
930
59.1k
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
59.1k
  }
932
933
  /* Allocate the workspace buffer */
934
92.0k
  coef->workspace = (JCOEF *)
935
92.0k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
92.0k
                                sizeof(JCOEF) * DCTSIZE2);
937
92.0k
}
j12init_d_coef_controller
Line
Count
Source
869
557
{
870
557
  my_coef_ptr coef;
871
872
557
  if (cinfo->data_precision != BITS_IN_JSAMPLE)
873
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
874
875
557
  coef = (my_coef_ptr)
876
557
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
877
557
                                sizeof(my_coef_controller));
878
557
  memset(coef, 0, sizeof(my_coef_controller));
879
557
  cinfo->coef = (struct jpeg_d_coef_controller *)coef;
880
557
  coef->pub.start_input_pass = start_input_pass;
881
557
  coef->pub.start_output_pass = start_output_pass;
882
557
#ifdef BLOCK_SMOOTHING_SUPPORTED
883
557
  coef->coef_bits_latch = NULL;
884
557
#endif
885
886
  /* Create the coefficient buffer. */
887
557
  if (need_full_buffer) {
888
477
#ifdef D_MULTISCAN_FILES_SUPPORTED
889
    /* Allocate a full-image virtual array for each component, */
890
    /* padded to a multiple of samp_factor DCT blocks in each direction. */
891
    /* Note we ask for a pre-zeroed array. */
892
477
    int ci, access_rows;
893
477
    jpeg_component_info *compptr;
894
895
954
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
896
477
         ci++, compptr++) {
897
477
      access_rows = compptr->v_samp_factor;
898
477
#ifdef BLOCK_SMOOTHING_SUPPORTED
899
      /* If block smoothing could be used, need a bigger window */
900
477
      if (cinfo->progressive_mode)
901
477
        access_rows *= 5;
902
477
#endif
903
477
      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
904
477
        ((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
905
477
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
906
477
                               (long)compptr->h_samp_factor),
907
477
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
908
477
                               (long)compptr->v_samp_factor),
909
477
         (JDIMENSION)access_rows);
910
477
    }
911
477
    coef->pub.consume_data = consume_data;
912
477
    coef->pub._decompress_data = decompress_data;
913
477
    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
914
#else
915
    ERREXIT(cinfo, JERR_NOT_COMPILED);
916
#endif
917
477
  } else {
918
    /* We only need a single-MCU buffer. */
919
80
    JBLOCKROW buffer;
920
80
    int i;
921
922
80
    buffer = (JBLOCKROW)
923
80
      (*cinfo->mem->alloc_large) ((j_common_ptr)cinfo, JPOOL_IMAGE,
924
80
                                  D_MAX_BLOCKS_IN_MCU * sizeof(JBLOCK));
925
880
    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
926
800
      coef->MCU_buffer[i] = buffer + i;
927
800
    }
928
80
    coef->pub.consume_data = dummy_consume_data;
929
80
    coef->pub._decompress_data = decompress_onepass;
930
80
    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
931
80
  }
932
933
  /* Allocate the workspace buffer */
934
557
  coef->workspace = (JCOEF *)
935
557
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
936
557
                                sizeof(JCOEF) * DCTSIZE2);
937
557
}