Coverage Report

Created: 2026-08-13 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/src/jddiffct.c
Line
Count
Source
1
/*
2
 * jddiffct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1997, Thomas G. Lane.
6
 * Lossless JPEG Modifications:
7
 * Copyright (C) 1999, Ken Murchison.
8
 * libjpeg-turbo Modifications:
9
 * Copyright (C) 2022, 2024, D. R. Commander.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the [un]difference buffer controller for decompression.
14
 * This controller is the top level of the lossless JPEG decompressor proper.
15
 * The difference buffer lies between the entropy decoding and
16
 * prediction/undifferencing steps.  The undifference buffer lies between the
17
 * prediction/undifferencing and scaling steps.
18
 *
19
 * In buffered-image mode, this controller is the interface between
20
 * input-oriented processing and output-oriented processing.
21
 */
22
23
#define JPEG_INTERNALS
24
#include "jinclude.h"
25
#include "jpeglib.h"
26
#include "jlossls.h"            /* Private declarations for lossless codec */
27
28
29
#ifdef D_LOSSLESS_SUPPORTED
30
31
/* Private buffer controller object */
32
33
typedef struct {
34
  struct jpeg_d_coef_controller pub; /* public fields */
35
36
  /* These variables keep track of the current location of the input side. */
37
  /* cinfo->input_iMCU_row is also used for this. */
38
  JDIMENSION MCU_ctr;           /* counts MCUs processed in current row */
39
  unsigned int restart_rows_to_go;      /* MCU rows left in this restart
40
                                           interval */
41
  unsigned int MCU_vert_offset;         /* counts MCU rows within iMCU row */
42
  unsigned int MCU_rows_per_iMCU_row;   /* number of such rows needed */
43
44
  /* The output side's location is represented by cinfo->output_iMCU_row. */
45
46
  JDIFFARRAY diff_buf[MAX_COMPONENTS];  /* iMCU row of differences */
47
  JDIFFARRAY undiff_buf[MAX_COMPONENTS]; /* iMCU row of undiff'd samples */
48
49
#ifdef D_MULTISCAN_FILES_SUPPORTED
50
  /* In multi-pass modes, we need a virtual sample array for each component. */
51
  jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
52
#endif
53
} my_diff_controller;
54
55
typedef my_diff_controller *my_diff_ptr;
56
57
/* Forward declarations */
58
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
59
#ifdef D_MULTISCAN_FILES_SUPPORTED
60
METHODDEF(int) output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
61
#endif
62
63
64
LOCAL(void)
65
start_iMCU_row(j_decompress_ptr cinfo)
66
/* Reset within-iMCU-row counters for a new row (input side) */
67
15.4M
{
68
15.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
15.4M
  if (cinfo->comps_in_scan > 1) {
75
4.96M
    diff->MCU_rows_per_iMCU_row = 1;
76
10.4M
  } else {
77
10.4M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
10.4M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
4.42k
    else
80
4.42k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
10.4M
  }
82
83
15.4M
  diff->MCU_ctr = 0;
84
15.4M
  diff->MCU_vert_offset = 0;
85
15.4M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
6.23M
{
68
6.23M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
6.23M
  if (cinfo->comps_in_scan > 1) {
75
3.63M
    diff->MCU_rows_per_iMCU_row = 1;
76
3.63M
  } else {
77
2.60M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
2.60M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.70k
    else
80
1.70k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
2.60M
  }
82
83
6.23M
  diff->MCU_ctr = 0;
84
6.23M
  diff->MCU_vert_offset = 0;
85
6.23M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
3.59M
{
68
3.59M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
3.59M
  if (cinfo->comps_in_scan > 1) {
75
401k
    diff->MCU_rows_per_iMCU_row = 1;
76
3.19M
  } else {
77
3.19M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
3.19M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.19k
    else
80
1.19k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
3.19M
  }
82
83
3.59M
  diff->MCU_ctr = 0;
84
3.59M
  diff->MCU_vert_offset = 0;
85
3.59M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
5.57M
{
68
5.57M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
5.57M
  if (cinfo->comps_in_scan > 1) {
75
927k
    diff->MCU_rows_per_iMCU_row = 1;
76
4.64M
  } else {
77
4.64M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
4.64M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.53k
    else
80
1.53k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
4.64M
  }
82
83
5.57M
  diff->MCU_ctr = 0;
84
5.57M
  diff->MCU_vert_offset = 0;
85
5.57M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
7.33k
{
95
7.33k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
7.33k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
7.33k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
70
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
7.33k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
7.33k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
7.33k
  cinfo->input_iMCU_row = 0;
115
7.33k
  start_iMCU_row(cinfo);
116
7.33k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
2.64k
{
95
2.64k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
2.64k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
2.64k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
22
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
2.64k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
2.64k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
2.64k
  cinfo->input_iMCU_row = 0;
115
2.64k
  start_iMCU_row(cinfo);
116
2.64k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
2.28k
{
95
2.28k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
2.28k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
2.28k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
22
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
2.28k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
2.28k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
2.28k
  cinfo->input_iMCU_row = 0;
115
2.28k
  start_iMCU_row(cinfo);
116
2.28k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
2.41k
{
95
2.41k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
2.41k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
2.41k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
26
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
2.41k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
2.41k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
2.41k
  cinfo->input_iMCU_row = 0;
115
2.41k
  start_iMCU_row(cinfo);
116
2.41k
}
117
118
119
/*
120
 * Check for a restart marker & resynchronize decoder, undifferencer.
121
 * Returns FALSE if must suspend.
122
 */
123
124
METHODDEF(boolean)
125
process_restart(j_decompress_ptr cinfo)
126
214k
{
127
214k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
214k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
214k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
214k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
214k
  return TRUE;
138
214k
}
jddiffct-8.c:process_restart
Line
Count
Source
126
6.00k
{
127
6.00k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
6.00k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
6.00k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
6.00k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
6.00k
  return TRUE;
138
6.00k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
26.1k
{
127
26.1k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
26.1k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
26.1k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
26.1k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
26.1k
  return TRUE;
138
26.1k
}
jddiffct-16.c:process_restart
Line
Count
Source
126
182k
{
127
182k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
182k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
182k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
182k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
182k
  return TRUE;
138
182k
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
2.17k
{
148
2.17k
  cinfo->output_iMCU_row = 0;
149
2.17k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
644
{
148
644
  cinfo->output_iMCU_row = 0;
149
644
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
709
{
148
709
  cinfo->output_iMCU_row = 0;
149
709
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
817
{
148
817
  cinfo->output_iMCU_row = 0;
149
817
}
150
151
152
/*
153
 * Decompress and return some data in the supplied buffer.
154
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
155
 * Input and output must run in lockstep since we have only a one-MCU buffer.
156
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
157
 *
158
 * NB: output_buf contains a plane for each component in image,
159
 * which we index according to the component's SOF position.
160
 */
161
162
METHODDEF(int)
163
decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
164
15.4M
{
165
15.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
15.4M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
15.4M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
15.4M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
15.4M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
15.4M
  int ci, compi, row, prev_row;
171
15.4M
  unsigned int yoffset;
172
15.4M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
37.3M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
21.9M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
21.9M
    if (cinfo->restart_interval) {
180
4.75M
      if (diff->restart_rows_to_go == 0)
181
214k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
4.75M
    }
184
185
21.9M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
21.9M
    MCU_count =
188
21.9M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
21.9M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
21.9M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
21.9M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
21.9M
    if (cinfo->restart_interval)
200
4.75M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
21.9M
    diff->MCU_ctr = 0;
204
21.9M
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
39.8M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
24.4M
    compptr = cinfo->cur_comp_info[ci];
213
24.4M
    compi = compptr->component_index;
214
24.4M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
61.3M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
61.3M
                compptr->last_row_height : compptr->v_samp_factor);
217
36.9M
         prev_row = row, row++) {
218
36.9M
      (*losslessd->predict_undifference[compi])
219
36.9M
        (cinfo, compi, diff->diff_buf[compi][row],
220
36.9M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
36.9M
          compptr->width_in_blocks);
222
36.9M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
36.9M
                                  output_buf[compi][row],
224
36.9M
                                  compptr->width_in_blocks);
225
36.9M
    }
226
24.4M
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
15.4M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
15.3M
    start_iMCU_row(cinfo);
236
15.3M
    return JPEG_ROW_COMPLETED;
237
15.3M
  }
238
  /* Completed the scan */
239
6.96k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
6.96k
  return JPEG_SCAN_COMPLETED;
241
15.4M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
6.23M
{
165
6.23M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
6.23M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
6.23M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
6.23M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
6.23M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
6.23M
  int ci, compi, row, prev_row;
171
6.23M
  unsigned int yoffset;
172
6.23M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
14.1M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
7.94M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
7.94M
    if (cinfo->restart_interval) {
180
860k
      if (diff->restart_rows_to_go == 0)
181
6.00k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
860k
    }
184
185
7.94M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
7.94M
    MCU_count =
188
7.94M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
7.94M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
7.94M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
7.94M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
7.94M
    if (cinfo->restart_interval)
200
860k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
7.94M
    diff->MCU_ctr = 0;
204
7.94M
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
18.9M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
12.6M
    compptr = cinfo->cur_comp_info[ci];
213
12.6M
    compi = compptr->component_index;
214
12.6M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
31.2M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
31.2M
                compptr->last_row_height : compptr->v_samp_factor);
217
18.5M
         prev_row = row, row++) {
218
18.5M
      (*losslessd->predict_undifference[compi])
219
18.5M
        (cinfo, compi, diff->diff_buf[compi][row],
220
18.5M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
18.5M
          compptr->width_in_blocks);
222
18.5M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
18.5M
                                  output_buf[compi][row],
224
18.5M
                                  compptr->width_in_blocks);
225
18.5M
    }
226
12.6M
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
6.23M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
6.23M
    start_iMCU_row(cinfo);
236
6.23M
    return JPEG_ROW_COMPLETED;
237
6.23M
  }
238
  /* Completed the scan */
239
2.52k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
2.52k
  return JPEG_SCAN_COMPLETED;
241
6.23M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
3.59M
{
165
3.59M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
3.59M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
3.59M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
3.59M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
3.59M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
3.59M
  int ci, compi, row, prev_row;
171
3.59M
  unsigned int yoffset;
172
3.59M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
9.14M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
5.55M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
5.55M
    if (cinfo->restart_interval) {
180
1.28M
      if (diff->restart_rows_to_go == 0)
181
26.1k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.28M
    }
184
185
5.55M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
5.55M
    MCU_count =
188
5.55M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
5.55M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
5.55M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
5.55M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
5.55M
    if (cinfo->restart_interval)
200
1.28M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
5.55M
    diff->MCU_ctr = 0;
204
5.55M
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
7.95M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
4.36M
    compptr = cinfo->cur_comp_info[ci];
213
4.36M
    compi = compptr->component_index;
214
4.36M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
11.3M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
11.3M
                compptr->last_row_height : compptr->v_samp_factor);
217
7.02M
         prev_row = row, row++) {
218
7.02M
      (*losslessd->predict_undifference[compi])
219
7.02M
        (cinfo, compi, diff->diff_buf[compi][row],
220
7.02M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
7.02M
          compptr->width_in_blocks);
222
7.02M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
7.02M
                                  output_buf[compi][row],
224
7.02M
                                  compptr->width_in_blocks);
225
7.02M
    }
226
4.36M
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
3.59M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
3.59M
    start_iMCU_row(cinfo);
236
3.59M
    return JPEG_ROW_COMPLETED;
237
3.59M
  }
238
  /* Completed the scan */
239
2.16k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
2.16k
  return JPEG_SCAN_COMPLETED;
241
3.59M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
5.57M
{
165
5.57M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
5.57M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
5.57M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
5.57M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
5.57M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
5.57M
  int ci, compi, row, prev_row;
171
5.57M
  unsigned int yoffset;
172
5.57M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
14.0M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
8.43M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
8.43M
    if (cinfo->restart_interval) {
180
2.60M
      if (diff->restart_rows_to_go == 0)
181
182k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
2.60M
    }
184
185
8.43M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
8.43M
    MCU_count =
188
8.43M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
8.43M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
8.43M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
8.43M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
8.43M
    if (cinfo->restart_interval)
200
2.60M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
8.43M
    diff->MCU_ctr = 0;
204
8.43M
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
13.0M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
7.44M
    compptr = cinfo->cur_comp_info[ci];
213
7.44M
    compi = compptr->component_index;
214
7.44M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
18.7M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
18.7M
                compptr->last_row_height : compptr->v_samp_factor);
217
11.3M
         prev_row = row, row++) {
218
11.3M
      (*losslessd->predict_undifference[compi])
219
11.3M
        (cinfo, compi, diff->diff_buf[compi][row],
220
11.3M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
11.3M
          compptr->width_in_blocks);
222
11.3M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
11.3M
                                  output_buf[compi][row],
224
11.3M
                                  compptr->width_in_blocks);
225
11.3M
    }
226
7.44M
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
5.57M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
5.57M
    start_iMCU_row(cinfo);
236
5.57M
    return JPEG_ROW_COMPLETED;
237
5.57M
  }
238
  /* Completed the scan */
239
2.28k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
2.28k
  return JPEG_SCAN_COMPLETED;
241
5.57M
}
242
243
244
/*
245
 * Dummy consume-input routine for single-pass operation.
246
 */
247
248
METHODDEF(int)
249
dummy_consume_data(j_decompress_ptr cinfo)
250
0
{
251
0
  return JPEG_SUSPENDED;        /* Always indicate nothing was done */
252
0
}
Unexecuted instantiation: jddiffct-8.c:dummy_consume_data
Unexecuted instantiation: jddiffct-12.c:dummy_consume_data
Unexecuted instantiation: jddiffct-16.c:dummy_consume_data
253
254
255
#ifdef D_MULTISCAN_FILES_SUPPORTED
256
257
/*
258
 * Consume input data and store it in the full-image sample buffer.
259
 * We read as much as one fully interleaved MCU row ("iMCU" row) per call,
260
 * ie, v_samp_factor rows for each component in the scan.
261
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
262
 */
263
264
METHODDEF(int)
265
consume_data(j_decompress_ptr cinfo)
266
10.9M
{
267
10.9M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
10.9M
  int ci, compi;
269
10.9M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
10.9M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
29.1M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
18.1M
    compptr = cinfo->cur_comp_info[ci];
275
18.1M
    compi = compptr->component_index;
276
18.1M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
18.1M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
18.1M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
18.1M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
18.1M
  }
281
282
10.9M
  return decompress_data(cinfo, buffer);
283
10.9M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
4.91M
{
267
4.91M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
4.91M
  int ci, compi;
269
4.91M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
4.91M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
15.8M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
10.9M
    compptr = cinfo->cur_comp_info[ci];
275
10.9M
    compi = compptr->component_index;
276
10.9M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
10.9M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
10.9M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
10.9M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
10.9M
  }
281
282
4.91M
  return decompress_data(cinfo, buffer);
283
4.91M
}
jddiffct-12.c:consume_data
Line
Count
Source
266
2.09M
{
267
2.09M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
2.09M
  int ci, compi;
269
2.09M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
2.09M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
4.56M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
2.46M
    compptr = cinfo->cur_comp_info[ci];
275
2.46M
    compi = compptr->component_index;
276
2.46M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
2.46M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
2.46M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
2.46M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
2.46M
  }
281
282
2.09M
  return decompress_data(cinfo, buffer);
283
2.09M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
3.96M
{
267
3.96M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
3.96M
  int ci, compi;
269
3.96M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
3.96M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
8.72M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
4.75M
    compptr = cinfo->cur_comp_info[ci];
275
4.75M
    compi = compptr->component_index;
276
4.75M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
4.75M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
4.75M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
4.75M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
4.75M
  }
281
282
3.96M
  return decompress_data(cinfo, buffer);
283
3.96M
}
284
285
286
/*
287
 * Output some data from the full-image sample buffer in the multi-pass case.
288
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
289
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
290
 *
291
 * NB: output_buf contains a plane for each component in image.
292
 */
293
294
METHODDEF(int)
295
output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
296
607k
{
297
607k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
607k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
607k
  int ci, samp_rows, row;
300
607k
  _JSAMPARRAY buffer;
301
607k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
607k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
607k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
607k
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
0
  }
310
311
  /* OK, output from the virtual arrays. */
312
2.43M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
1.83M
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
1.83M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
1.83M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
1.83M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
1.83M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
1.83M
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1.83M
      samp_rows = compptr->v_samp_factor;
322
1.27k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1.27k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1.27k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1.27k
    }
327
328
4.59M
    for (row = 0; row < samp_rows; row++) {
329
2.76M
      memcpy(output_buf[ci][row], buffer[row],
330
2.76M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
2.76M
    }
332
1.83M
  }
333
334
607k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
606k
    return JPEG_ROW_COMPLETED;
336
828
  return JPEG_SCAN_COMPLETED;
337
607k
}
jddiffct-8.c:output_data
Line
Count
Source
296
235k
{
297
235k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
235k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
235k
  int ci, samp_rows, row;
300
235k
  _JSAMPARRAY buffer;
301
235k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
235k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
235k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
235k
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
0
  }
310
311
  /* OK, output from the virtual arrays. */
312
942k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
706k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
706k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
706k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
706k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
706k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
706k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
706k
      samp_rows = compptr->v_samp_factor;
322
401
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
401
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
401
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
401
    }
327
328
1.71M
    for (row = 0; row < samp_rows; row++) {
329
1.00M
      memcpy(output_buf[ci][row], buffer[row],
330
1.00M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1.00M
    }
332
706k
  }
333
334
235k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
235k
    return JPEG_ROW_COMPLETED;
336
241
  return JPEG_SCAN_COMPLETED;
337
235k
}
jddiffct-12.c:output_data
Line
Count
Source
296
110k
{
297
110k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
110k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
110k
  int ci, samp_rows, row;
300
110k
  _JSAMPARRAY buffer;
301
110k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
110k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
110k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
110k
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
0
  }
310
311
  /* OK, output from the virtual arrays. */
312
453k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
342k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
342k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
342k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
342k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
342k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
342k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
342k
      samp_rows = compptr->v_samp_factor;
322
380
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
380
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
380
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
380
    }
327
328
709k
    for (row = 0; row < samp_rows; row++) {
329
367k
      memcpy(output_buf[ci][row], buffer[row],
330
367k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
367k
    }
332
342k
  }
333
334
110k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
110k
    return JPEG_ROW_COMPLETED;
336
216
  return JPEG_SCAN_COMPLETED;
337
110k
}
jddiffct-16.c:output_data
Line
Count
Source
296
260k
{
297
260k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
260k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
260k
  int ci, samp_rows, row;
300
260k
  _JSAMPARRAY buffer;
301
260k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
260k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
260k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
260k
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
0
  }
310
311
  /* OK, output from the virtual arrays. */
312
1.04M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
782k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
782k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
782k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
782k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
782k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
782k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
781k
      samp_rows = compptr->v_samp_factor;
322
495
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
495
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
495
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
495
    }
327
328
2.16M
    for (row = 0; row < samp_rows; row++) {
329
1.38M
      memcpy(output_buf[ci][row], buffer[row],
330
1.38M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1.38M
    }
332
782k
  }
333
334
260k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
260k
    return JPEG_ROW_COMPLETED;
336
371
  return JPEG_SCAN_COMPLETED;
337
260k
}
338
339
#endif /* D_MULTISCAN_FILES_SUPPORTED */
340
341
342
/*
343
 * Initialize difference buffer controller.
344
 */
345
346
GLOBAL(void)
347
_jinit_d_diff_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
348
3.34k
{
349
3.34k
  my_diff_ptr diff;
350
3.34k
  int ci;
351
3.34k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
1.08k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
2.25k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
2.25k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
3.34k
  diff = (my_diff_ptr)
362
3.34k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
3.34k
                                sizeof(my_diff_controller));
364
3.34k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
3.34k
  diff->pub.start_input_pass = start_input_pass;
366
3.34k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
11.8k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
8.47k
       ci++, compptr++) {
371
8.47k
    diff->diff_buf[ci] =
372
8.47k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
8.47k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
8.47k
                                         (long)compptr->h_samp_factor),
375
8.47k
                   (JDIMENSION)compptr->v_samp_factor);
376
8.47k
    diff->undiff_buf[ci] =
377
8.47k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
8.47k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
8.47k
                                         (long)compptr->h_samp_factor),
380
8.47k
                   (JDIMENSION)compptr->v_samp_factor);
381
8.47k
  }
382
383
3.34k
  if (need_full_buffer) {
384
1.90k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.90k
    int access_rows;
387
388
7.73k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
5.82k
         ci++, compptr++) {
390
5.82k
      access_rows = compptr->v_samp_factor;
391
5.82k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
5.82k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
5.82k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
5.82k
                               (long)compptr->h_samp_factor),
395
5.82k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
5.82k
                               (long)compptr->v_samp_factor),
397
5.82k
         (JDIMENSION)access_rows);
398
5.82k
    }
399
1.90k
    diff->pub.consume_data = consume_data;
400
1.90k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.90k
  } else {
405
1.43k
    diff->pub.consume_data = dummy_consume_data;
406
1.43k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
1.43k
  }
409
3.34k
}
jinit_d_diff_controller
Line
Count
Source
348
1.08k
{
349
1.08k
  my_diff_ptr diff;
350
1.08k
  int ci;
351
1.08k
  jpeg_component_info *compptr;
352
353
1.08k
#if BITS_IN_JSAMPLE == 8
354
1.08k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.08k
  diff = (my_diff_ptr)
362
1.08k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.08k
                                sizeof(my_diff_controller));
364
1.08k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.08k
  diff->pub.start_input_pass = start_input_pass;
366
1.08k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
3.76k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
2.67k
       ci++, compptr++) {
371
2.67k
    diff->diff_buf[ci] =
372
2.67k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
2.67k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
2.67k
                                         (long)compptr->h_samp_factor),
375
2.67k
                   (JDIMENSION)compptr->v_samp_factor);
376
2.67k
    diff->undiff_buf[ci] =
377
2.67k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
2.67k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
2.67k
                                         (long)compptr->h_samp_factor),
380
2.67k
                   (JDIMENSION)compptr->v_samp_factor);
381
2.67k
  }
382
383
1.08k
  if (need_full_buffer) {
384
644
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
644
    int access_rows;
387
388
2.61k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.97k
         ci++, compptr++) {
390
1.97k
      access_rows = compptr->v_samp_factor;
391
1.97k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.97k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.97k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.97k
                               (long)compptr->h_samp_factor),
395
1.97k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.97k
                               (long)compptr->v_samp_factor),
397
1.97k
         (JDIMENSION)access_rows);
398
1.97k
    }
399
644
    diff->pub.consume_data = consume_data;
400
644
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
644
  } else {
405
442
    diff->pub.consume_data = dummy_consume_data;
406
442
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
442
  }
409
1.08k
}
j12init_d_diff_controller
Line
Count
Source
348
1.02k
{
349
1.02k
  my_diff_ptr diff;
350
1.02k
  int ci;
351
1.02k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
1.02k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.02k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.02k
  diff = (my_diff_ptr)
362
1.02k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.02k
                                sizeof(my_diff_controller));
364
1.02k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.02k
  diff->pub.start_input_pass = start_input_pass;
366
1.02k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
3.58k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
2.56k
       ci++, compptr++) {
371
2.56k
    diff->diff_buf[ci] =
372
2.56k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
2.56k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
2.56k
                                         (long)compptr->h_samp_factor),
375
2.56k
                   (JDIMENSION)compptr->v_samp_factor);
376
2.56k
    diff->undiff_buf[ci] =
377
2.56k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
2.56k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
2.56k
                                         (long)compptr->h_samp_factor),
380
2.56k
                   (JDIMENSION)compptr->v_samp_factor);
381
2.56k
  }
382
383
1.02k
  if (need_full_buffer) {
384
522
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
522
    int access_rows;
387
388
2.13k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.61k
         ci++, compptr++) {
390
1.61k
      access_rows = compptr->v_samp_factor;
391
1.61k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.61k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.61k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.61k
                               (long)compptr->h_samp_factor),
395
1.61k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.61k
                               (long)compptr->v_samp_factor),
397
1.61k
         (JDIMENSION)access_rows);
398
1.61k
    }
399
522
    diff->pub.consume_data = consume_data;
400
522
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
522
  } else {
405
500
    diff->pub.consume_data = dummy_consume_data;
406
500
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
500
  }
409
1.02k
}
j16init_d_diff_controller
Line
Count
Source
348
1.23k
{
349
1.23k
  my_diff_ptr diff;
350
1.23k
  int ci;
351
1.23k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
1.23k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.23k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.23k
  diff = (my_diff_ptr)
362
1.23k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.23k
                                sizeof(my_diff_controller));
364
1.23k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.23k
  diff->pub.start_input_pass = start_input_pass;
366
1.23k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
4.46k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
3.23k
       ci++, compptr++) {
371
3.23k
    diff->diff_buf[ci] =
372
3.23k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
3.23k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
3.23k
                                         (long)compptr->h_samp_factor),
375
3.23k
                   (JDIMENSION)compptr->v_samp_factor);
376
3.23k
    diff->undiff_buf[ci] =
377
3.23k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
3.23k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
3.23k
                                         (long)compptr->h_samp_factor),
380
3.23k
                   (JDIMENSION)compptr->v_samp_factor);
381
3.23k
  }
382
383
1.23k
  if (need_full_buffer) {
384
738
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
738
    int access_rows;
387
388
2.98k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
2.24k
         ci++, compptr++) {
390
2.24k
      access_rows = compptr->v_samp_factor;
391
2.24k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
2.24k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
2.24k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
2.24k
                               (long)compptr->h_samp_factor),
395
2.24k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
2.24k
                               (long)compptr->v_samp_factor),
397
2.24k
         (JDIMENSION)access_rows);
398
2.24k
    }
399
738
    diff->pub.consume_data = consume_data;
400
738
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
738
  } else {
405
496
    diff->pub.consume_data = dummy_consume_data;
406
496
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
496
  }
409
1.23k
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */