Coverage Report

Created: 2025-06-22 06:33

/src/libjpeg-turbo/src/jddiffct.c
Line
Count
Source (jump to first uncovered line)
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
3.89k
{
68
3.89k
  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.89k
  if (cinfo->comps_in_scan > 1) {
75
3.89k
    diff->MCU_rows_per_iMCU_row = 1;
76
3.89k
  } else {
77
0
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
0
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
0
    else
80
0
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
0
  }
82
83
3.89k
  diff->MCU_ctr = 0;
84
3.89k
  diff->MCU_vert_offset = 0;
85
3.89k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
3.89k
{
68
3.89k
  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.89k
  if (cinfo->comps_in_scan > 1) {
75
3.89k
    diff->MCU_rows_per_iMCU_row = 1;
76
3.89k
  } else {
77
0
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
0
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
0
    else
80
0
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
0
  }
82
83
3.89k
  diff->MCU_ctr = 0;
84
3.89k
  diff->MCU_vert_offset = 0;
85
3.89k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
5
{
68
5
  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
  if (cinfo->comps_in_scan > 1) {
75
5
    diff->MCU_rows_per_iMCU_row = 1;
76
5
  } else {
77
0
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
0
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
0
    else
80
0
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
0
  }
82
83
5
  diff->MCU_ctr = 0;
84
5
  diff->MCU_vert_offset = 0;
85
5
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
2
{
68
2
  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
2
  if (cinfo->comps_in_scan > 1) {
75
2
    diff->MCU_rows_per_iMCU_row = 1;
76
2
  } else {
77
0
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
0
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
0
    else
80
0
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
0
  }
82
83
2
  diff->MCU_ctr = 0;
84
2
  diff->MCU_vert_offset = 0;
85
2
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
326
{
95
326
  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
326
  (*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
326
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
326
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
326
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
326
  cinfo->input_iMCU_row = 0;
115
326
  start_iMCU_row(cinfo);
116
326
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
304
{
95
304
  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
304
  (*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
304
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
304
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
304
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
304
  cinfo->input_iMCU_row = 0;
115
304
  start_iMCU_row(cinfo);
116
304
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
14
{
95
14
  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
14
  (*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
14
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
14
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
14
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
14
  cinfo->input_iMCU_row = 0;
115
14
  start_iMCU_row(cinfo);
116
14
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
8
{
95
8
  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
8
  (*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
8
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
8
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
8
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
8
  cinfo->input_iMCU_row = 0;
115
8
  start_iMCU_row(cinfo);
116
8
}
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
0
{
127
0
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
0
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
0
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
0
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
0
  return TRUE;
138
0
}
Unexecuted instantiation: jddiffct-8.c:process_restart
Unexecuted instantiation: jddiffct-12.c:process_restart
Unexecuted instantiation: jddiffct-16.c:process_restart
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
289
{
148
289
  cinfo->output_iMCU_row = 0;
149
289
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
282
{
148
282
  cinfo->output_iMCU_row = 0;
149
282
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
5
{
148
5
  cinfo->output_iMCU_row = 0;
149
5
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
2
{
148
2
  cinfo->output_iMCU_row = 0;
149
2
}
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
3.89k
{
165
3.89k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
3.89k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
3.89k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
3.89k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
3.89k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
3.89k
  int ci, compi, row, prev_row;
171
3.89k
  unsigned int yoffset;
172
3.89k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
7.78k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
3.89k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
3.89k
    if (cinfo->restart_interval) {
180
0
      if (diff->restart_rows_to_go == 0)
181
0
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
0
    }
184
185
3.89k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
3.89k
    MCU_count =
188
3.89k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
3.89k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
3.89k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
3.89k
    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
3.89k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
3.89k
    diff->MCU_ctr = 0;
204
3.89k
  }
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
16.1k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
12.2k
    compptr = cinfo->cur_comp_info[ci];
213
12.2k
    compi = compptr->component_index;
214
12.2k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
27.3k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
27.2k
                compptr->last_row_height : compptr->v_samp_factor);
217
15.0k
         prev_row = row, row++) {
218
15.0k
      (*losslessd->predict_undifference[compi])
219
15.0k
        (cinfo, compi, diff->diff_buf[compi][row],
220
15.0k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
15.0k
          compptr->width_in_blocks);
222
15.0k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
15.0k
                                  output_buf[compi][row],
224
15.0k
                                  compptr->width_in_blocks);
225
15.0k
    }
226
12.2k
  }
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.89k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
3.61k
    start_iMCU_row(cinfo);
236
3.61k
    return JPEG_ROW_COMPLETED;
237
3.61k
  }
238
  /* Completed the scan */
239
282
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
282
  return JPEG_SCAN_COMPLETED;
241
3.89k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
3.89k
{
165
3.89k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
3.89k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
3.89k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
3.89k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
3.89k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
3.89k
  int ci, compi, row, prev_row;
171
3.89k
  unsigned int yoffset;
172
3.89k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
7.78k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
3.89k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
3.89k
    if (cinfo->restart_interval) {
180
0
      if (diff->restart_rows_to_go == 0)
181
0
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
0
    }
184
185
3.89k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
3.89k
    MCU_count =
188
3.89k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
3.89k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
3.89k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
3.89k
    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
3.89k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
3.89k
    diff->MCU_ctr = 0;
204
3.89k
  }
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
16.1k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
12.2k
    compptr = cinfo->cur_comp_info[ci];
213
12.2k
    compi = compptr->component_index;
214
12.2k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
27.3k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
27.2k
                compptr->last_row_height : compptr->v_samp_factor);
217
15.0k
         prev_row = row, row++) {
218
15.0k
      (*losslessd->predict_undifference[compi])
219
15.0k
        (cinfo, compi, diff->diff_buf[compi][row],
220
15.0k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
15.0k
          compptr->width_in_blocks);
222
15.0k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
15.0k
                                  output_buf[compi][row],
224
15.0k
                                  compptr->width_in_blocks);
225
15.0k
    }
226
12.2k
  }
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.89k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
3.61k
    start_iMCU_row(cinfo);
236
3.61k
    return JPEG_ROW_COMPLETED;
237
3.61k
  }
238
  /* Completed the scan */
239
282
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
282
  return JPEG_SCAN_COMPLETED;
241
3.89k
}
Unexecuted instantiation: jddiffct-12.c:decompress_data
Unexecuted instantiation: jddiffct-16.c:decompress_data
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
0
{
267
0
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
0
  int ci, compi;
269
0
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
0
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
0
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
0
    compptr = cinfo->cur_comp_info[ci];
275
0
    compi = compptr->component_index;
276
0
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
0
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
0
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
0
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
0
  }
281
282
0
  return decompress_data(cinfo, buffer);
283
0
}
Unexecuted instantiation: jddiffct-8.c:consume_data
Unexecuted instantiation: jddiffct-12.c:consume_data
Unexecuted instantiation: jddiffct-16.c:consume_data
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
0
{
297
0
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
0
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
0
  int ci, samp_rows, row;
300
0
  _JSAMPARRAY buffer;
301
0
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
0
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
0
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
0
          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
0
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
0
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
0
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
0
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
0
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
0
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
0
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
0
      samp_rows = compptr->v_samp_factor;
322
0
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
0
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
0
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
0
    }
327
328
0
    for (row = 0; row < samp_rows; row++) {
329
0
      memcpy(output_buf[ci][row], buffer[row],
330
0
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
0
    }
332
0
  }
333
334
0
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
0
  return JPEG_SCAN_COMPLETED;
337
0
}
Unexecuted instantiation: jddiffct-8.c:output_data
Unexecuted instantiation: jddiffct-12.c:output_data
Unexecuted instantiation: jddiffct-16.c:output_data
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
353
{
349
353
  my_diff_ptr diff;
350
353
  int ci;
351
353
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
327
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
26
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
26
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
353
  diff = (my_diff_ptr)
362
353
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
353
                                sizeof(my_diff_controller));
364
353
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
353
  diff->pub.start_input_pass = start_input_pass;
366
353
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.56k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.21k
       ci++, compptr++) {
371
1.21k
    diff->diff_buf[ci] =
372
1.21k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.21k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.21k
                                         (long)compptr->h_samp_factor),
375
1.21k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.21k
    diff->undiff_buf[ci] =
377
1.21k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.21k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.21k
                                         (long)compptr->h_samp_factor),
380
1.21k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.21k
  }
382
383
353
  if (need_full_buffer) {
384
0
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
0
    int access_rows;
387
388
0
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
0
         ci++, compptr++) {
390
0
      access_rows = compptr->v_samp_factor;
391
0
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
0
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
0
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
0
                               (long)compptr->h_samp_factor),
395
0
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
0
                               (long)compptr->v_samp_factor),
397
0
         (JDIMENSION)access_rows);
398
0
    }
399
0
    diff->pub.consume_data = consume_data;
400
0
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
353
  } else {
405
353
    diff->pub.consume_data = dummy_consume_data;
406
353
    diff->pub._decompress_data = decompress_data;
407
353
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
353
  }
409
353
}
jinit_d_diff_controller
Line
Count
Source
348
327
{
349
327
  my_diff_ptr diff;
350
327
  int ci;
351
327
  jpeg_component_info *compptr;
352
353
327
#if BITS_IN_JSAMPLE == 8
354
327
  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
327
  diff = (my_diff_ptr)
362
327
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
327
                                sizeof(my_diff_controller));
364
327
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
327
  diff->pub.start_input_pass = start_input_pass;
366
327
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.44k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.12k
       ci++, compptr++) {
371
1.12k
    diff->diff_buf[ci] =
372
1.12k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.12k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.12k
                                         (long)compptr->h_samp_factor),
375
1.12k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.12k
    diff->undiff_buf[ci] =
377
1.12k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.12k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.12k
                                         (long)compptr->h_samp_factor),
380
1.12k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.12k
  }
382
383
327
  if (need_full_buffer) {
384
0
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
0
    int access_rows;
387
388
0
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
0
         ci++, compptr++) {
390
0
      access_rows = compptr->v_samp_factor;
391
0
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
0
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
0
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
0
                               (long)compptr->h_samp_factor),
395
0
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
0
                               (long)compptr->v_samp_factor),
397
0
         (JDIMENSION)access_rows);
398
0
    }
399
0
    diff->pub.consume_data = consume_data;
400
0
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
327
  } else {
405
327
    diff->pub.consume_data = dummy_consume_data;
406
327
    diff->pub._decompress_data = decompress_data;
407
327
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
327
  }
409
327
}
j12init_d_diff_controller
Line
Count
Source
348
16
{
349
16
  my_diff_ptr diff;
350
16
  int ci;
351
16
  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
16
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
16
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
16
  diff = (my_diff_ptr)
362
16
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
16
                                sizeof(my_diff_controller));
364
16
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
16
  diff->pub.start_input_pass = start_input_pass;
366
16
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
73
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
57
       ci++, compptr++) {
371
57
    diff->diff_buf[ci] =
372
57
      ALLOC_DARRAY(JPOOL_IMAGE,
373
57
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
57
                                         (long)compptr->h_samp_factor),
375
57
                   (JDIMENSION)compptr->v_samp_factor);
376
57
    diff->undiff_buf[ci] =
377
57
      ALLOC_DARRAY(JPOOL_IMAGE,
378
57
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
57
                                         (long)compptr->h_samp_factor),
380
57
                   (JDIMENSION)compptr->v_samp_factor);
381
57
  }
382
383
16
  if (need_full_buffer) {
384
0
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
0
    int access_rows;
387
388
0
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
0
         ci++, compptr++) {
390
0
      access_rows = compptr->v_samp_factor;
391
0
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
0
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
0
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
0
                               (long)compptr->h_samp_factor),
395
0
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
0
                               (long)compptr->v_samp_factor),
397
0
         (JDIMENSION)access_rows);
398
0
    }
399
0
    diff->pub.consume_data = consume_data;
400
0
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
16
  } else {
405
16
    diff->pub.consume_data = dummy_consume_data;
406
16
    diff->pub._decompress_data = decompress_data;
407
16
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
16
  }
409
16
}
j16init_d_diff_controller
Line
Count
Source
348
10
{
349
10
  my_diff_ptr diff;
350
10
  int ci;
351
10
  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
10
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
10
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
10
  diff = (my_diff_ptr)
362
10
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
10
                                sizeof(my_diff_controller));
364
10
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
10
  diff->pub.start_input_pass = start_input_pass;
366
10
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
49
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
39
       ci++, compptr++) {
371
39
    diff->diff_buf[ci] =
372
39
      ALLOC_DARRAY(JPOOL_IMAGE,
373
39
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
39
                                         (long)compptr->h_samp_factor),
375
39
                   (JDIMENSION)compptr->v_samp_factor);
376
39
    diff->undiff_buf[ci] =
377
39
      ALLOC_DARRAY(JPOOL_IMAGE,
378
39
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
39
                                         (long)compptr->h_samp_factor),
380
39
                   (JDIMENSION)compptr->v_samp_factor);
381
39
  }
382
383
10
  if (need_full_buffer) {
384
0
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
0
    int access_rows;
387
388
0
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
0
         ci++, compptr++) {
390
0
      access_rows = compptr->v_samp_factor;
391
0
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
0
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
0
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
0
                               (long)compptr->h_samp_factor),
395
0
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
0
                               (long)compptr->v_samp_factor),
397
0
         (JDIMENSION)access_rows);
398
0
    }
399
0
    diff->pub.consume_data = consume_data;
400
0
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
10
  } else {
405
10
    diff->pub.consume_data = dummy_consume_data;
406
10
    diff->pub._decompress_data = decompress_data;
407
10
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
10
  }
409
10
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */