Coverage Report

Created: 2025-08-28 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
58.4k
{
68
58.4k
  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
58.4k
  if (cinfo->comps_in_scan > 1) {
75
1.52k
    diff->MCU_rows_per_iMCU_row = 1;
76
56.9k
  } else {
77
56.9k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
56.1k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
786
    else
80
786
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
56.9k
  }
82
83
58.4k
  diff->MCU_ctr = 0;
84
58.4k
  diff->MCU_vert_offset = 0;
85
58.4k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
15.0k
{
68
15.0k
  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.0k
  if (cinfo->comps_in_scan > 1) {
75
1.52k
    diff->MCU_rows_per_iMCU_row = 1;
76
13.5k
  } else {
77
13.5k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
13.3k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
200
    else
80
200
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
13.5k
  }
82
83
15.0k
  diff->MCU_ctr = 0;
84
15.0k
  diff->MCU_vert_offset = 0;
85
15.0k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
34.6k
{
68
34.6k
  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
34.6k
  if (cinfo->comps_in_scan > 1) {
75
1
    diff->MCU_rows_per_iMCU_row = 1;
76
34.6k
  } else {
77
34.6k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
34.2k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
436
    else
80
436
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
34.6k
  }
82
83
34.6k
  diff->MCU_ctr = 0;
84
34.6k
  diff->MCU_vert_offset = 0;
85
34.6k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
8.74k
{
68
8.74k
  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
8.74k
  if (cinfo->comps_in_scan > 1) {
75
1
    diff->MCU_rows_per_iMCU_row = 1;
76
8.74k
  } else {
77
8.74k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
8.59k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
150
    else
80
150
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
8.74k
  }
82
83
8.74k
  diff->MCU_ctr = 0;
84
8.74k
  diff->MCU_vert_offset = 0;
85
8.74k
}
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.86k
{
95
1.86k
  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.86k
  (*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.86k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.86k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.86k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.86k
  cinfo->input_iMCU_row = 0;
115
1.86k
  start_iMCU_row(cinfo);
116
1.86k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
623
{
95
623
  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
623
  (*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
623
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
623
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
623
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
623
  cinfo->input_iMCU_row = 0;
115
623
  start_iMCU_row(cinfo);
116
623
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
792
{
95
792
  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
792
  (*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
792
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
792
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
792
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
792
  cinfo->input_iMCU_row = 0;
115
792
  start_iMCU_row(cinfo);
116
792
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
447
{
95
447
  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
447
  (*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
447
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
447
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
447
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
447
  cinfo->input_iMCU_row = 0;
115
447
  start_iMCU_row(cinfo);
116
447
}
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
129
{
148
129
  cinfo->output_iMCU_row = 0;
149
129
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
116
{
148
116
  cinfo->output_iMCU_row = 0;
149
116
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
2
{
148
2
  cinfo->output_iMCU_row = 0;
149
2
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
11
{
148
11
  cinfo->output_iMCU_row = 0;
149
11
}
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
58.4k
{
165
58.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
58.4k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
58.4k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
58.4k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
58.4k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
58.4k
  int ci, compi, row, prev_row;
171
58.4k
  unsigned int yoffset;
172
58.4k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
216k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
158k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
158k
    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
158k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
158k
    MCU_count =
188
158k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
158k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
158k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
158k
    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
158k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
158k
    diff->MCU_ctr = 0;
204
158k
  }
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
118k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
60.3k
    compptr = cinfo->cur_comp_info[ci];
213
60.3k
    compi = compptr->component_index;
214
60.3k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
221k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
219k
                compptr->last_row_height : compptr->v_samp_factor);
217
161k
         prev_row = row, row++) {
218
161k
      (*losslessd->predict_undifference[compi])
219
161k
        (cinfo, compi, diff->diff_buf[compi][row],
220
161k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
161k
          compptr->width_in_blocks);
222
161k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
161k
                                  output_buf[compi][row],
224
161k
                                  compptr->width_in_blocks);
225
161k
    }
226
60.3k
  }
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
58.4k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
56.7k
    start_iMCU_row(cinfo);
236
56.7k
    return JPEG_ROW_COMPLETED;
237
56.7k
  }
238
  /* Completed the scan */
239
1.75k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.75k
  return JPEG_SCAN_COMPLETED;
241
58.4k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
15.0k
{
165
15.0k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
15.0k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
15.0k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
15.0k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
15.0k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
15.0k
  int ci, compi, row, prev_row;
171
15.0k
  unsigned int yoffset;
172
15.0k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
53.6k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
38.5k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
38.5k
    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
38.5k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
38.5k
    MCU_count =
188
38.5k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
38.5k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
38.5k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
38.5k
    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
38.5k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
38.5k
    diff->MCU_ctr = 0;
204
38.5k
  }
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
32.5k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
17.5k
    compptr = cinfo->cur_comp_info[ci];
213
17.5k
    compi = compptr->component_index;
214
17.5k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
59.8k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
59.2k
                compptr->last_row_height : compptr->v_samp_factor);
217
42.3k
         prev_row = row, row++) {
218
42.3k
      (*losslessd->predict_undifference[compi])
219
42.3k
        (cinfo, compi, diff->diff_buf[compi][row],
220
42.3k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
42.3k
          compptr->width_in_blocks);
222
42.3k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
42.3k
                                  output_buf[compi][row],
224
42.3k
                                  compptr->width_in_blocks);
225
42.3k
    }
226
17.5k
  }
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.0k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
14.4k
    start_iMCU_row(cinfo);
236
14.4k
    return JPEG_ROW_COMPLETED;
237
14.4k
  }
238
  /* Completed the scan */
239
595
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
595
  return JPEG_SCAN_COMPLETED;
241
15.0k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
34.6k
{
165
34.6k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
34.6k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
34.6k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
34.6k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
34.6k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
34.6k
  int ci, compi, row, prev_row;
171
34.6k
  unsigned int yoffset;
172
34.6k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
133k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
98.4k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
98.4k
    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
98.4k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
98.4k
    MCU_count =
188
98.4k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
98.4k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
98.4k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
98.4k
    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
98.4k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
98.4k
    diff->MCU_ctr = 0;
204
98.4k
  }
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
68.9k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
34.3k
    compptr = cinfo->cur_comp_info[ci];
213
34.3k
    compi = compptr->component_index;
214
34.3k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
132k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
130k
                compptr->last_row_height : compptr->v_samp_factor);
217
98.0k
         prev_row = row, row++) {
218
98.0k
      (*losslessd->predict_undifference[compi])
219
98.0k
        (cinfo, compi, diff->diff_buf[compi][row],
220
98.0k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
98.0k
          compptr->width_in_blocks);
222
98.0k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
98.0k
                                  output_buf[compi][row],
224
98.0k
                                  compptr->width_in_blocks);
225
98.0k
    }
226
34.3k
  }
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
34.6k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
33.9k
    start_iMCU_row(cinfo);
236
33.9k
    return JPEG_ROW_COMPLETED;
237
33.9k
  }
238
  /* Completed the scan */
239
746
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
746
  return JPEG_SCAN_COMPLETED;
241
34.6k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
8.74k
{
165
8.74k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
8.74k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
8.74k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
8.74k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
8.74k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
8.74k
  int ci, compi, row, prev_row;
171
8.74k
  unsigned int yoffset;
172
8.74k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
30.2k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
21.4k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
21.4k
    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
21.4k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
21.4k
    MCU_count =
188
21.4k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
21.4k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
21.4k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
21.4k
    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.4k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
21.4k
    diff->MCU_ctr = 0;
204
21.4k
  }
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
17.2k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
8.47k
    compptr = cinfo->cur_comp_info[ci];
213
8.47k
    compi = compptr->component_index;
214
8.47k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
29.5k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
29.1k
                compptr->last_row_height : compptr->v_samp_factor);
217
21.0k
         prev_row = row, row++) {
218
21.0k
      (*losslessd->predict_undifference[compi])
219
21.0k
        (cinfo, compi, diff->diff_buf[compi][row],
220
21.0k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
21.0k
          compptr->width_in_blocks);
222
21.0k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
21.0k
                                  output_buf[compi][row],
224
21.0k
                                  compptr->width_in_blocks);
225
21.0k
    }
226
8.47k
  }
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
8.74k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
8.33k
    start_iMCU_row(cinfo);
236
8.33k
    return JPEG_ROW_COMPLETED;
237
8.33k
  }
238
  /* Completed the scan */
239
416
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
416
  return JPEG_SCAN_COMPLETED;
241
8.74k
}
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
56.9k
{
267
56.9k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
56.9k
  int ci, compi;
269
56.9k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
56.9k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
113k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
56.9k
    compptr = cinfo->cur_comp_info[ci];
275
56.9k
    compi = compptr->component_index;
276
56.9k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
56.9k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
56.9k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
56.9k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
56.9k
  }
281
282
56.9k
  return decompress_data(cinfo, buffer);
283
56.9k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
13.5k
{
267
13.5k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
13.5k
  int ci, compi;
269
13.5k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
13.5k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
27.1k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
13.5k
    compptr = cinfo->cur_comp_info[ci];
275
13.5k
    compi = compptr->component_index;
276
13.5k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
13.5k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
13.5k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
13.5k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
13.5k
  }
281
282
13.5k
  return decompress_data(cinfo, buffer);
283
13.5k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
34.6k
{
267
34.6k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
34.6k
  int ci, compi;
269
34.6k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
34.6k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
69.3k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
34.6k
    compptr = cinfo->cur_comp_info[ci];
275
34.6k
    compi = compptr->component_index;
276
34.6k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
34.6k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
34.6k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
34.6k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
34.6k
  }
281
282
34.6k
  return decompress_data(cinfo, buffer);
283
34.6k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
8.74k
{
267
8.74k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
8.74k
  int ci, compi;
269
8.74k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
8.74k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
17.4k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
8.74k
    compptr = cinfo->cur_comp_info[ci];
275
8.74k
    compi = compptr->component_index;
276
8.74k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
8.74k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
8.74k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
8.74k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
8.74k
  }
281
282
8.74k
  return decompress_data(cinfo, buffer);
283
8.74k
}
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
6
{
297
6
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
6
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
6
  int ci, samp_rows, row;
300
6
  _JSAMPARRAY buffer;
301
6
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
6
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
6
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
6
          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
17
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
11
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
11
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
11
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
11
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
11
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
11
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1
      samp_rows = compptr->v_samp_factor;
322
10
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
10
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
10
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
10
    }
327
328
25
    for (row = 0; row < samp_rows; row++) {
329
14
      memcpy(output_buf[ci][row], buffer[row],
330
14
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
14
    }
332
11
  }
333
334
6
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
6
  return JPEG_SCAN_COMPLETED;
337
6
}
jddiffct-8.c:output_data
Line
Count
Source
296
6
{
297
6
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
6
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
6
  int ci, samp_rows, row;
300
6
  _JSAMPARRAY buffer;
301
6
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
6
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
6
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
6
          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
17
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
11
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
11
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
11
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
11
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
11
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
11
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1
      samp_rows = compptr->v_samp_factor;
322
10
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
10
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
10
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
10
    }
327
328
25
    for (row = 0; row < samp_rows; row++) {
329
14
      memcpy(output_buf[ci][row], buffer[row],
330
14
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
14
    }
332
11
  }
333
334
6
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
6
  return JPEG_SCAN_COMPLETED;
337
6
}
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.34k
{
349
1.34k
  my_diff_ptr diff;
350
1.34k
  int ci;
351
1.34k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
520
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
826
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
826
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.34k
  diff = (my_diff_ptr)
362
1.34k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.34k
                                sizeof(my_diff_controller));
364
1.34k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.34k
  diff->pub.start_input_pass = start_input_pass;
366
1.34k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
5.40k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.05k
       ci++, compptr++) {
371
4.05k
    diff->diff_buf[ci] =
372
4.05k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.05k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.05k
                                         (long)compptr->h_samp_factor),
375
4.05k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.05k
    diff->undiff_buf[ci] =
377
4.05k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.05k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.05k
                                         (long)compptr->h_samp_factor),
380
4.05k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.05k
  }
382
383
1.34k
  if (need_full_buffer) {
384
1.20k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.20k
    int access_rows;
387
388
4.80k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.60k
         ci++, compptr++) {
390
3.60k
      access_rows = compptr->v_samp_factor;
391
3.60k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.60k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.60k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.60k
                               (long)compptr->h_samp_factor),
395
3.60k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.60k
                               (long)compptr->v_samp_factor),
397
3.60k
         (JDIMENSION)access_rows);
398
3.60k
    }
399
1.20k
    diff->pub.consume_data = consume_data;
400
1.20k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.20k
  } else {
405
144
    diff->pub.consume_data = dummy_consume_data;
406
144
    diff->pub._decompress_data = decompress_data;
407
144
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
144
  }
409
1.34k
}
jinit_d_diff_controller
Line
Count
Source
348
520
{
349
520
  my_diff_ptr diff;
350
520
  int ci;
351
520
  jpeg_component_info *compptr;
352
353
520
#if BITS_IN_JSAMPLE == 8
354
520
  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
520
  diff = (my_diff_ptr)
362
520
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
520
                                sizeof(my_diff_controller));
364
520
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
520
  diff->pub.start_input_pass = start_input_pass;
366
520
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.09k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.57k
       ci++, compptr++) {
371
1.57k
    diff->diff_buf[ci] =
372
1.57k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.57k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.57k
                                         (long)compptr->h_samp_factor),
375
1.57k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.57k
    diff->undiff_buf[ci] =
377
1.57k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.57k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.57k
                                         (long)compptr->h_samp_factor),
380
1.57k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.57k
  }
382
383
520
  if (need_full_buffer) {
384
389
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
389
    int access_rows;
387
388
1.55k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.16k
         ci++, compptr++) {
390
1.16k
      access_rows = compptr->v_samp_factor;
391
1.16k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.16k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.16k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.16k
                               (long)compptr->h_samp_factor),
395
1.16k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.16k
                               (long)compptr->v_samp_factor),
397
1.16k
         (JDIMENSION)access_rows);
398
1.16k
    }
399
389
    diff->pub.consume_data = consume_data;
400
389
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
389
  } else {
405
131
    diff->pub.consume_data = dummy_consume_data;
406
131
    diff->pub._decompress_data = decompress_data;
407
131
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
131
  }
409
520
}
j12init_d_diff_controller
Line
Count
Source
348
443
{
349
443
  my_diff_ptr diff;
350
443
  int ci;
351
443
  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
443
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
443
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
443
  diff = (my_diff_ptr)
362
443
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
443
                                sizeof(my_diff_controller));
364
443
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
443
  diff->pub.start_input_pass = start_input_pass;
366
443
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.77k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.33k
       ci++, compptr++) {
371
1.33k
    diff->diff_buf[ci] =
372
1.33k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.33k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.33k
                                         (long)compptr->h_samp_factor),
375
1.33k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.33k
    diff->undiff_buf[ci] =
377
1.33k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.33k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.33k
                                         (long)compptr->h_samp_factor),
380
1.33k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.33k
  }
382
383
443
  if (need_full_buffer) {
384
435
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
435
    int access_rows;
387
388
1.74k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.30k
         ci++, compptr++) {
390
1.30k
      access_rows = compptr->v_samp_factor;
391
1.30k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.30k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.30k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.30k
                               (long)compptr->h_samp_factor),
395
1.30k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.30k
                               (long)compptr->v_samp_factor),
397
1.30k
         (JDIMENSION)access_rows);
398
1.30k
    }
399
435
    diff->pub.consume_data = consume_data;
400
435
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
435
  } else {
405
8
    diff->pub.consume_data = dummy_consume_data;
406
8
    diff->pub._decompress_data = decompress_data;
407
8
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
8
  }
409
443
}
j16init_d_diff_controller
Line
Count
Source
348
383
{
349
383
  my_diff_ptr diff;
350
383
  int ci;
351
383
  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
383
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
383
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
383
  diff = (my_diff_ptr)
362
383
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
383
                                sizeof(my_diff_controller));
364
383
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
383
  diff->pub.start_input_pass = start_input_pass;
366
383
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.53k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.14k
       ci++, compptr++) {
371
1.14k
    diff->diff_buf[ci] =
372
1.14k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.14k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.14k
                                         (long)compptr->h_samp_factor),
375
1.14k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.14k
    diff->undiff_buf[ci] =
377
1.14k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.14k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.14k
                                         (long)compptr->h_samp_factor),
380
1.14k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.14k
  }
382
383
383
  if (need_full_buffer) {
384
378
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
378
    int access_rows;
387
388
1.51k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.13k
         ci++, compptr++) {
390
1.13k
      access_rows = compptr->v_samp_factor;
391
1.13k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.13k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.13k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.13k
                               (long)compptr->h_samp_factor),
395
1.13k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.13k
                               (long)compptr->v_samp_factor),
397
1.13k
         (JDIMENSION)access_rows);
398
1.13k
    }
399
378
    diff->pub.consume_data = consume_data;
400
378
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
378
  } else {
405
5
    diff->pub.consume_data = dummy_consume_data;
406
5
    diff->pub._decompress_data = decompress_data;
407
5
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
5
  }
409
383
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */