Coverage Report

Created: 2025-08-26 07:09

/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
41.1k
{
68
41.1k
  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
41.1k
  if (cinfo->comps_in_scan > 1) {
75
14.2k
    diff->MCU_rows_per_iMCU_row = 1;
76
26.8k
  } else {
77
26.8k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
26.6k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
223
    else
80
223
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
26.8k
  }
82
83
41.1k
  diff->MCU_ctr = 0;
84
41.1k
  diff->MCU_vert_offset = 0;
85
41.1k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
15.2k
{
68
15.2k
  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.2k
  if (cinfo->comps_in_scan > 1) {
75
14.2k
    diff->MCU_rows_per_iMCU_row = 1;
76
14.2k
  } else {
77
1.03k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
986
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
46
    else
80
46
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
1.03k
  }
82
83
15.2k
  diff->MCU_ctr = 0;
84
15.2k
  diff->MCU_vert_offset = 0;
85
15.2k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
6.53k
{
68
6.53k
  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.53k
  if (cinfo->comps_in_scan > 1) {
75
6
    diff->MCU_rows_per_iMCU_row = 1;
76
6.52k
  } else {
77
6.52k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
6.43k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
93
    else
80
93
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
6.52k
  }
82
83
6.53k
  diff->MCU_ctr = 0;
84
6.53k
  diff->MCU_vert_offset = 0;
85
6.53k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
19.3k
{
68
19.3k
  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
19.3k
  if (cinfo->comps_in_scan > 1) {
75
3
    diff->MCU_rows_per_iMCU_row = 1;
76
19.3k
  } else {
77
19.3k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
19.2k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
84
    else
80
84
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
19.3k
  }
82
83
19.3k
  diff->MCU_ctr = 0;
84
19.3k
  diff->MCU_vert_offset = 0;
85
19.3k
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
1.23k
{
95
1.23k
  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
1.23k
  (*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
1.23k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.23k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.23k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.23k
  cinfo->input_iMCU_row = 0;
115
1.23k
  start_iMCU_row(cinfo);
116
1.23k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
492
{
95
492
  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
492
  (*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
492
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
492
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
492
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
492
  cinfo->input_iMCU_row = 0;
115
492
  start_iMCU_row(cinfo);
116
492
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
375
{
95
375
  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
375
  (*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
375
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
375
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
375
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
375
  cinfo->input_iMCU_row = 0;
115
375
  start_iMCU_row(cinfo);
116
375
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
369
{
95
369
  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
369
  (*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
369
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
369
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
369
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
369
  cinfo->input_iMCU_row = 0;
115
369
  start_iMCU_row(cinfo);
116
369
}
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
406
{
148
406
  cinfo->output_iMCU_row = 0;
149
406
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
396
{
148
396
  cinfo->output_iMCU_row = 0;
149
396
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
6
{
148
6
  cinfo->output_iMCU_row = 0;
149
6
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
4
{
148
4
  cinfo->output_iMCU_row = 0;
149
4
}
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
41.1k
{
165
41.1k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
41.1k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
41.1k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
41.1k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
41.1k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
41.1k
  int ci, compi, row, prev_row;
171
41.1k
  unsigned int yoffset;
172
41.1k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
98.4k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
57.3k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
57.3k
    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
57.3k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
57.3k
    MCU_count =
188
57.3k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
57.3k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
57.3k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
57.3k
    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
57.3k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
57.3k
    diff->MCU_ctr = 0;
204
57.3k
  }
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
122k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
81.6k
    compptr = cinfo->cur_comp_info[ci];
213
81.6k
    compi = compptr->component_index;
214
81.6k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
194k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
193k
                compptr->last_row_height : compptr->v_samp_factor);
217
113k
         prev_row = row, row++) {
218
113k
      (*losslessd->predict_undifference[compi])
219
113k
        (cinfo, compi, diff->diff_buf[compi][row],
220
113k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
113k
          compptr->width_in_blocks);
222
113k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
113k
                                  output_buf[compi][row],
224
113k
                                  compptr->width_in_blocks);
225
113k
    }
226
81.6k
  }
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
41.1k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
39.9k
    start_iMCU_row(cinfo);
236
39.9k
    return JPEG_ROW_COMPLETED;
237
39.9k
  }
238
  /* Completed the scan */
239
1.14k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.14k
  return JPEG_SCAN_COMPLETED;
241
41.1k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
15.2k
{
165
15.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
15.2k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
15.2k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
15.2k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
15.2k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
15.2k
  int ci, compi, row, prev_row;
171
15.2k
  unsigned int yoffset;
172
15.2k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
31.9k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
16.6k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
16.6k
    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
16.6k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
16.6k
    MCU_count =
188
16.6k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
16.6k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
16.6k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
16.6k
    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
16.6k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
16.6k
    diff->MCU_ctr = 0;
204
16.6k
  }
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
71.5k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
56.2k
    compptr = cinfo->cur_comp_info[ci];
213
56.2k
    compi = compptr->component_index;
214
56.2k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
129k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
129k
                compptr->last_row_height : compptr->v_samp_factor);
217
73.2k
         prev_row = row, row++) {
218
73.2k
      (*losslessd->predict_undifference[compi])
219
73.2k
        (cinfo, compi, diff->diff_buf[compi][row],
220
73.2k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
73.2k
          compptr->width_in_blocks);
222
73.2k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
73.2k
                                  output_buf[compi][row],
224
73.2k
                                  compptr->width_in_blocks);
225
73.2k
    }
226
56.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
15.2k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
14.7k
    start_iMCU_row(cinfo);
236
14.7k
    return JPEG_ROW_COMPLETED;
237
14.7k
  }
238
  /* Completed the scan */
239
465
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
465
  return JPEG_SCAN_COMPLETED;
241
15.2k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
6.52k
{
165
6.52k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
6.52k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
6.52k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
6.52k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
6.52k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
6.52k
  int ci, compi, row, prev_row;
171
6.52k
  unsigned int yoffset;
172
6.52k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
20.3k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
13.8k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
13.8k
    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
13.8k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
13.8k
    MCU_count =
188
13.8k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
13.8k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
13.8k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
13.8k
    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
13.8k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
13.8k
    diff->MCU_ctr = 0;
204
13.8k
  }
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
12.7k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
6.26k
    compptr = cinfo->cur_comp_info[ci];
213
6.26k
    compi = compptr->component_index;
214
6.26k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
19.6k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
19.4k
                compptr->last_row_height : compptr->v_samp_factor);
217
13.4k
         prev_row = row, row++) {
218
13.4k
      (*losslessd->predict_undifference[compi])
219
13.4k
        (cinfo, compi, diff->diff_buf[compi][row],
220
13.4k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
13.4k
          compptr->width_in_blocks);
222
13.4k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
13.4k
                                  output_buf[compi][row],
224
13.4k
                                  compptr->width_in_blocks);
225
13.4k
    }
226
6.26k
  }
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.52k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
6.17k
    start_iMCU_row(cinfo);
236
6.17k
    return JPEG_ROW_COMPLETED;
237
6.17k
  }
238
  /* Completed the scan */
239
351
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
351
  return JPEG_SCAN_COMPLETED;
241
6.52k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
19.3k
{
165
19.3k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
19.3k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
19.3k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
19.3k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
19.3k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
19.3k
  int ci, compi, row, prev_row;
171
19.3k
  unsigned int yoffset;
172
19.3k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
46.1k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
26.7k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
26.7k
    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
26.7k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
26.7k
    MCU_count =
188
26.7k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
26.7k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
26.7k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
26.7k
    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
26.7k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
26.7k
    diff->MCU_ctr = 0;
204
26.7k
  }
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
38.4k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
19.0k
    compptr = cinfo->cur_comp_info[ci];
213
19.0k
    compi = compptr->component_index;
214
19.0k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
45.4k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
45.2k
                compptr->last_row_height : compptr->v_samp_factor);
217
26.3k
         prev_row = row, row++) {
218
26.3k
      (*losslessd->predict_undifference[compi])
219
26.3k
        (cinfo, compi, diff->diff_buf[compi][row],
220
26.3k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
26.3k
          compptr->width_in_blocks);
222
26.3k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
26.3k
                                  output_buf[compi][row],
224
26.3k
                                  compptr->width_in_blocks);
225
26.3k
    }
226
19.0k
  }
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
19.3k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
19.0k
    start_iMCU_row(cinfo);
236
19.0k
    return JPEG_ROW_COMPLETED;
237
19.0k
  }
238
  /* Completed the scan */
239
332
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
332
  return JPEG_SCAN_COMPLETED;
241
19.3k
}
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
26.8k
{
267
26.8k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
26.8k
  int ci, compi;
269
26.8k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
26.8k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
53.7k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
26.8k
    compptr = cinfo->cur_comp_info[ci];
275
26.8k
    compi = compptr->component_index;
276
26.8k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
26.8k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
26.8k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
26.8k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
26.8k
  }
281
282
26.8k
  return decompress_data(cinfo, buffer);
283
26.8k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
1.03k
{
267
1.03k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
1.03k
  int ci, compi;
269
1.03k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
1.03k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
2.06k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
1.03k
    compptr = cinfo->cur_comp_info[ci];
275
1.03k
    compi = compptr->component_index;
276
1.03k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
1.03k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
1.03k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
1.03k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
1.03k
  }
281
282
1.03k
  return decompress_data(cinfo, buffer);
283
1.03k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
6.52k
{
267
6.52k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
6.52k
  int ci, compi;
269
6.52k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
6.52k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
13.0k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
6.52k
    compptr = cinfo->cur_comp_info[ci];
275
6.52k
    compi = compptr->component_index;
276
6.52k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
6.52k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
6.52k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
6.52k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
6.52k
  }
281
282
6.52k
  return decompress_data(cinfo, buffer);
283
6.52k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
19.3k
{
267
19.3k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
19.3k
  int ci, compi;
269
19.3k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
19.3k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
38.6k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
19.3k
    compptr = cinfo->cur_comp_info[ci];
275
19.3k
    compi = compptr->component_index;
276
19.3k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
19.3k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
19.3k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
19.3k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
19.3k
  }
281
282
19.3k
  return decompress_data(cinfo, buffer);
283
19.3k
}
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
7
{
297
7
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
7
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
7
  int ci, samp_rows, row;
300
7
  _JSAMPARRAY buffer;
301
7
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
7
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
7
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
7
          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
21
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
14
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
14
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
14
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
14
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
14
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
14
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1
      samp_rows = compptr->v_samp_factor;
322
13
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
13
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
13
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
13
    }
327
328
36
    for (row = 0; row < samp_rows; row++) {
329
22
      memcpy(output_buf[ci][row], buffer[row],
330
22
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
22
    }
332
14
  }
333
334
7
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
7
  return JPEG_SCAN_COMPLETED;
337
7
}
jddiffct-8.c:output_data
Line
Count
Source
296
7
{
297
7
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
7
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
7
  int ci, samp_rows, row;
300
7
  _JSAMPARRAY buffer;
301
7
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
7
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
7
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
7
          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
21
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
14
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
14
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
14
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
14
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
14
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
14
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1
      samp_rows = compptr->v_samp_factor;
322
13
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
13
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
13
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
13
    }
327
328
36
    for (row = 0; row < samp_rows; row++) {
329
22
      memcpy(output_buf[ci][row], buffer[row],
330
22
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
22
    }
332
14
  }
333
334
7
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
7
  return JPEG_SCAN_COMPLETED;
337
7
}
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
1.21k
{
349
1.21k
  my_diff_ptr diff;
350
1.21k
  int ci;
351
1.21k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
491
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
724
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
724
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.21k
  diff = (my_diff_ptr)
362
1.21k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.21k
                                sizeof(my_diff_controller));
364
1.21k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.21k
  diff->pub.start_input_pass = start_input_pass;
366
1.21k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
5.29k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.08k
       ci++, compptr++) {
371
4.08k
    diff->diff_buf[ci] =
372
4.08k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.08k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.08k
                                         (long)compptr->h_samp_factor),
375
4.08k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.08k
    diff->undiff_buf[ci] =
377
4.08k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.08k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.08k
                                         (long)compptr->h_samp_factor),
380
4.08k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.08k
  }
382
383
1.21k
  if (need_full_buffer) {
384
724
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
724
    int access_rows;
387
388
2.89k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
2.17k
         ci++, compptr++) {
390
2.17k
      access_rows = compptr->v_samp_factor;
391
2.17k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
2.17k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
2.17k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
2.17k
                               (long)compptr->h_samp_factor),
395
2.17k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
2.17k
                               (long)compptr->v_samp_factor),
397
2.17k
         (JDIMENSION)access_rows);
398
2.17k
    }
399
724
    diff->pub.consume_data = consume_data;
400
724
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
724
  } else {
405
491
    diff->pub.consume_data = dummy_consume_data;
406
491
    diff->pub._decompress_data = decompress_data;
407
491
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
491
  }
409
1.21k
}
jinit_d_diff_controller
Line
Count
Source
348
491
{
349
491
  my_diff_ptr diff;
350
491
  int ci;
351
491
  jpeg_component_info *compptr;
352
353
491
#if BITS_IN_JSAMPLE == 8
354
491
  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
491
  diff = (my_diff_ptr)
362
491
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
491
                                sizeof(my_diff_controller));
364
491
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
491
  diff->pub.start_input_pass = start_input_pass;
366
491
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.35k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.86k
       ci++, compptr++) {
371
1.86k
    diff->diff_buf[ci] =
372
1.86k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.86k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.86k
                                         (long)compptr->h_samp_factor),
375
1.86k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.86k
    diff->undiff_buf[ci] =
377
1.86k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.86k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.86k
                                         (long)compptr->h_samp_factor),
380
1.86k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.86k
  }
382
383
491
  if (need_full_buffer) {
384
57
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
57
    int access_rows;
387
388
229
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
172
         ci++, compptr++) {
390
172
      access_rows = compptr->v_samp_factor;
391
172
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
172
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
172
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
172
                               (long)compptr->h_samp_factor),
395
172
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
172
                               (long)compptr->v_samp_factor),
397
172
         (JDIMENSION)access_rows);
398
172
    }
399
57
    diff->pub.consume_data = consume_data;
400
57
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
434
  } else {
405
434
    diff->pub.consume_data = dummy_consume_data;
406
434
    diff->pub._decompress_data = decompress_data;
407
434
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
434
  }
409
491
}
j12init_d_diff_controller
Line
Count
Source
348
367
{
349
367
  my_diff_ptr diff;
350
367
  int ci;
351
367
  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
367
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
367
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
367
  diff = (my_diff_ptr)
362
367
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
367
                                sizeof(my_diff_controller));
364
367
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
367
  diff->pub.start_input_pass = start_input_pass;
366
367
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.48k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.11k
       ci++, compptr++) {
371
1.11k
    diff->diff_buf[ci] =
372
1.11k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.11k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.11k
                                         (long)compptr->h_samp_factor),
375
1.11k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.11k
    diff->undiff_buf[ci] =
377
1.11k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.11k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.11k
                                         (long)compptr->h_samp_factor),
380
1.11k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.11k
  }
382
383
367
  if (need_full_buffer) {
384
339
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
339
    int access_rows;
387
388
1.35k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.01k
         ci++, compptr++) {
390
1.01k
      access_rows = compptr->v_samp_factor;
391
1.01k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.01k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.01k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.01k
                               (long)compptr->h_samp_factor),
395
1.01k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.01k
                               (long)compptr->v_samp_factor),
397
1.01k
         (JDIMENSION)access_rows);
398
1.01k
    }
399
339
    diff->pub.consume_data = consume_data;
400
339
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
339
  } else {
405
28
    diff->pub.consume_data = dummy_consume_data;
406
28
    diff->pub._decompress_data = decompress_data;
407
28
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
28
  }
409
367
}
j16init_d_diff_controller
Line
Count
Source
348
357
{
349
357
  my_diff_ptr diff;
350
357
  int ci;
351
357
  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
357
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
357
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
357
  diff = (my_diff_ptr)
362
357
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
357
                                sizeof(my_diff_controller));
364
357
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
357
  diff->pub.start_input_pass = start_input_pass;
366
357
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.45k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.09k
       ci++, compptr++) {
371
1.09k
    diff->diff_buf[ci] =
372
1.09k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.09k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.09k
                                         (long)compptr->h_samp_factor),
375
1.09k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.09k
    diff->undiff_buf[ci] =
377
1.09k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.09k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.09k
                                         (long)compptr->h_samp_factor),
380
1.09k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.09k
  }
382
383
357
  if (need_full_buffer) {
384
328
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
328
    int access_rows;
387
388
1.31k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
984
         ci++, compptr++) {
390
984
      access_rows = compptr->v_samp_factor;
391
984
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
984
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
984
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
984
                               (long)compptr->h_samp_factor),
395
984
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
984
                               (long)compptr->v_samp_factor),
397
984
         (JDIMENSION)access_rows);
398
984
    }
399
328
    diff->pub.consume_data = consume_data;
400
328
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
328
  } else {
405
29
    diff->pub.consume_data = dummy_consume_data;
406
29
    diff->pub._decompress_data = decompress_data;
407
29
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
29
  }
409
357
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */