Coverage Report

Created: 2025-07-12 06:35

/src/libjpeg-turbo.main/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
11.0M
{
68
11.0M
  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
11.0M
  if (cinfo->comps_in_scan > 1) {
75
845k
    diff->MCU_rows_per_iMCU_row = 1;
76
10.1M
  } else {
77
10.1M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
10.1M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
3.50k
    else
80
3.50k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
10.1M
  }
82
83
11.0M
  diff->MCU_ctr = 0;
84
11.0M
  diff->MCU_vert_offset = 0;
85
11.0M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
1.03M
{
68
1.03M
  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
1.03M
  if (cinfo->comps_in_scan > 1) {
75
240k
    diff->MCU_rows_per_iMCU_row = 1;
76
796k
  } else {
77
796k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
795k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.38k
    else
80
1.38k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
796k
  }
82
83
1.03M
  diff->MCU_ctr = 0;
84
1.03M
  diff->MCU_vert_offset = 0;
85
1.03M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
3.33M
{
68
3.33M
  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.33M
  if (cinfo->comps_in_scan > 1) {
75
152k
    diff->MCU_rows_per_iMCU_row = 1;
76
3.18M
  } else {
77
3.18M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
3.18M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.12k
    else
80
1.12k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
3.18M
  }
82
83
3.33M
  diff->MCU_ctr = 0;
84
3.33M
  diff->MCU_vert_offset = 0;
85
3.33M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
6.64M
{
68
6.64M
  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.64M
  if (cinfo->comps_in_scan > 1) {
75
453k
    diff->MCU_rows_per_iMCU_row = 1;
76
6.18M
  } else {
77
6.18M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
6.18M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
993
    else
80
993
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
6.18M
  }
82
83
6.64M
  diff->MCU_ctr = 0;
84
6.64M
  diff->MCU_vert_offset = 0;
85
6.64M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
5.22k
{
95
5.22k
  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
5.22k
  (*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
5.22k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
38
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
5.22k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
5.22k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
5.22k
  cinfo->input_iMCU_row = 0;
115
5.22k
  start_iMCU_row(cinfo);
116
5.22k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
2.03k
{
95
2.03k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
2.03k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
2.03k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
13
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
2.03k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
2.03k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
2.03k
  cinfo->input_iMCU_row = 0;
115
2.03k
  start_iMCU_row(cinfo);
116
2.03k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
1.74k
{
95
1.74k
  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.74k
  (*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.74k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
12
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.74k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.74k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.74k
  cinfo->input_iMCU_row = 0;
115
1.74k
  start_iMCU_row(cinfo);
116
1.74k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
1.43k
{
95
1.43k
  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.43k
  (*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.43k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
13
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.43k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.43k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.43k
  cinfo->input_iMCU_row = 0;
115
1.43k
  start_iMCU_row(cinfo);
116
1.43k
}
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
217k
{
127
217k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
217k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
217k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
217k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
217k
  return TRUE;
138
217k
}
jddiffct-8.c:process_restart
Line
Count
Source
126
1.42k
{
127
1.42k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
1.42k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
1.42k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
1.42k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
1.42k
  return TRUE;
138
1.42k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
134k
{
127
134k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
134k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
134k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
134k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
134k
  return TRUE;
138
134k
}
jddiffct-16.c:process_restart
Line
Count
Source
126
82.4k
{
127
82.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
82.4k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
82.4k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
82.4k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
82.4k
  return TRUE;
138
82.4k
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
1.19k
{
148
1.19k
  cinfo->output_iMCU_row = 0;
149
1.19k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
352
{
148
352
  cinfo->output_iMCU_row = 0;
149
352
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
397
{
148
397
  cinfo->output_iMCU_row = 0;
149
397
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
443
{
148
443
  cinfo->output_iMCU_row = 0;
149
443
}
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
11.0M
{
165
11.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
11.0M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
11.0M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
11.0M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
11.0M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
11.0M
  int ci, compi, row, prev_row;
171
11.0M
  unsigned int yoffset;
172
11.0M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
26.4M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
15.4M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
15.4M
    if (cinfo->restart_interval) {
180
2.48M
      if (diff->restart_rows_to_go == 0)
181
217k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
2.48M
    }
184
185
15.4M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
15.4M
    MCU_count =
188
15.4M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
15.4M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
15.4M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
15.4M
    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
15.4M
    if (cinfo->restart_interval)
200
2.48M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
15.4M
    diff->MCU_ctr = 0;
204
15.4M
  }
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
23.5M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
12.5M
    compptr = cinfo->cur_comp_info[ci];
213
12.5M
    compi = compptr->component_index;
214
12.5M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
31.3M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
31.3M
                compptr->last_row_height : compptr->v_samp_factor);
217
18.7M
         prev_row = row, row++) {
218
18.7M
      (*losslessd->predict_undifference[compi])
219
18.7M
        (cinfo, compi, diff->diff_buf[compi][row],
220
18.7M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
18.7M
          compptr->width_in_blocks);
222
18.7M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
18.7M
                                  output_buf[compi][row],
224
18.7M
                                  compptr->width_in_blocks);
225
18.7M
    }
226
12.5M
  }
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
11.0M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
11.0M
    start_iMCU_row(cinfo);
236
11.0M
    return JPEG_ROW_COMPLETED;
237
11.0M
  }
238
  /* Completed the scan */
239
5.07k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
5.07k
  return JPEG_SCAN_COMPLETED;
241
11.0M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
1.03M
{
165
1.03M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
1.03M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
1.03M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
1.03M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
1.03M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
1.03M
  int ci, compi, row, prev_row;
171
1.03M
  unsigned int yoffset;
172
1.03M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
2.63M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
1.59M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
1.59M
    if (cinfo->restart_interval) {
180
241k
      if (diff->restart_rows_to_go == 0)
181
1.42k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
241k
    }
184
185
1.59M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
1.59M
    MCU_count =
188
1.59M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
1.59M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
1.59M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
1.59M
    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
1.59M
    if (cinfo->restart_interval)
200
241k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
1.59M
    diff->MCU_ctr = 0;
204
1.59M
  }
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
2.46M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
1.43M
    compptr = cinfo->cur_comp_info[ci];
213
1.43M
    compi = compptr->component_index;
214
1.43M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
3.51M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
3.50M
                compptr->last_row_height : compptr->v_samp_factor);
217
2.08M
         prev_row = row, row++) {
218
2.08M
      (*losslessd->predict_undifference[compi])
219
2.08M
        (cinfo, compi, diff->diff_buf[compi][row],
220
2.08M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
2.08M
          compptr->width_in_blocks);
222
2.08M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
2.08M
                                  output_buf[compi][row],
224
2.08M
                                  compptr->width_in_blocks);
225
2.08M
    }
226
1.43M
  }
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
1.03M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
1.03M
    start_iMCU_row(cinfo);
236
1.03M
    return JPEG_ROW_COMPLETED;
237
1.03M
  }
238
  /* Completed the scan */
239
1.98k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.98k
  return JPEG_SCAN_COMPLETED;
241
1.03M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
3.33M
{
165
3.33M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
3.33M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
3.33M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
3.33M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
3.33M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
3.33M
  int ci, compi, row, prev_row;
171
3.33M
  unsigned int yoffset;
172
3.33M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
9.79M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
6.46M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
6.46M
    if (cinfo->restart_interval) {
180
833k
      if (diff->restart_rows_to_go == 0)
181
134k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
833k
    }
184
185
6.46M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
6.46M
    MCU_count =
188
6.46M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
6.46M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
6.46M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
6.46M
    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
6.46M
    if (cinfo->restart_interval)
200
833k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
6.46M
    diff->MCU_ctr = 0;
204
6.46M
  }
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
6.95M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
3.62M
    compptr = cinfo->cur_comp_info[ci];
213
3.62M
    compi = compptr->component_index;
214
3.62M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
10.6M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
10.6M
                compptr->last_row_height : compptr->v_samp_factor);
217
7.03M
         prev_row = row, row++) {
218
7.03M
      (*losslessd->predict_undifference[compi])
219
7.03M
        (cinfo, compi, diff->diff_buf[compi][row],
220
7.03M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
7.03M
          compptr->width_in_blocks);
222
7.03M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
7.03M
                                  output_buf[compi][row],
224
7.03M
                                  compptr->width_in_blocks);
225
7.03M
    }
226
3.62M
  }
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.33M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
3.33M
    start_iMCU_row(cinfo);
236
3.33M
    return JPEG_ROW_COMPLETED;
237
3.33M
  }
238
  /* Completed the scan */
239
1.70k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.70k
  return JPEG_SCAN_COMPLETED;
241
3.33M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
6.64M
{
165
6.64M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
6.64M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
6.64M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
6.64M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
6.64M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
6.64M
  int ci, compi, row, prev_row;
171
6.64M
  unsigned int yoffset;
172
6.64M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
14.0M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
7.36M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
7.36M
    if (cinfo->restart_interval) {
180
1.40M
      if (diff->restart_rows_to_go == 0)
181
82.4k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.40M
    }
184
185
7.36M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
7.36M
    MCU_count =
188
7.36M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
7.36M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
7.36M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
7.36M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
7.36M
    if (cinfo->restart_interval)
200
1.40M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
7.36M
    diff->MCU_ctr = 0;
204
7.36M
  }
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
14.1M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
7.53M
    compptr = cinfo->cur_comp_info[ci];
213
7.53M
    compi = compptr->component_index;
214
7.53M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
17.1M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
17.1M
                compptr->last_row_height : compptr->v_samp_factor);
217
9.63M
         prev_row = row, row++) {
218
9.63M
      (*losslessd->predict_undifference[compi])
219
9.63M
        (cinfo, compi, diff->diff_buf[compi][row],
220
9.63M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
9.63M
          compptr->width_in_blocks);
222
9.63M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
9.63M
                                  output_buf[compi][row],
224
9.63M
                                  compptr->width_in_blocks);
225
9.63M
    }
226
7.53M
  }
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.64M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
6.63M
    start_iMCU_row(cinfo);
236
6.63M
    return JPEG_ROW_COMPLETED;
237
6.63M
  }
238
  /* Completed the scan */
239
1.38k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.38k
  return JPEG_SCAN_COMPLETED;
241
6.64M
}
242
243
244
/*
245
 * Dummy consume-input routine for single-pass operation.
246
 */
247
248
METHODDEF(int)
249
dummy_consume_data(j_decompress_ptr cinfo)
250
0
{
251
0
  return JPEG_SUSPENDED;        /* Always indicate nothing was done */
252
0
}
Unexecuted instantiation: jddiffct-8.c:dummy_consume_data
Unexecuted instantiation: jddiffct-12.c:dummy_consume_data
Unexecuted instantiation: jddiffct-16.c:dummy_consume_data
253
254
255
#ifdef D_MULTISCAN_FILES_SUPPORTED
256
257
/*
258
 * Consume input data and store it in the full-image sample buffer.
259
 * We read as much as one fully interleaved MCU row ("iMCU" row) per call,
260
 * ie, v_samp_factor rows for each component in the scan.
261
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
262
 */
263
264
METHODDEF(int)
265
consume_data(j_decompress_ptr cinfo)
266
10.6M
{
267
10.6M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
10.6M
  int ci, compi;
269
10.6M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
10.6M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
22.1M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
11.5M
    compptr = cinfo->cur_comp_info[ci];
275
11.5M
    compi = compptr->component_index;
276
11.5M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
11.5M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
11.5M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
11.5M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
11.5M
  }
281
282
10.6M
  return decompress_data(cinfo, buffer);
283
10.6M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
918k
{
267
918k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
918k
  int ci, compi;
269
918k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
918k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
1.99M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
1.07M
    compptr = cinfo->cur_comp_info[ci];
275
1.07M
    compi = compptr->component_index;
276
1.07M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
1.07M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
1.07M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
1.07M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
1.07M
  }
281
282
918k
  return decompress_data(cinfo, buffer);
283
918k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
3.23M
{
267
3.23M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
3.23M
  int ci, compi;
269
3.23M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
3.23M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
6.56M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
3.33M
    compptr = cinfo->cur_comp_info[ci];
275
3.33M
    compi = compptr->component_index;
276
3.33M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
3.33M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
3.33M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
3.33M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
3.33M
  }
281
282
3.23M
  return decompress_data(cinfo, buffer);
283
3.23M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
6.49M
{
267
6.49M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
6.49M
  int ci, compi;
269
6.49M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
6.49M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
13.5M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
7.10M
    compptr = cinfo->cur_comp_info[ci];
275
7.10M
    compi = compptr->component_index;
276
7.10M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
7.10M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
7.10M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
7.10M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
7.10M
  }
281
282
6.49M
  return decompress_data(cinfo, buffer);
283
6.49M
}
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
174k
{
297
174k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
174k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
174k
  int ci, samp_rows, row;
300
174k
  _JSAMPARRAY buffer;
301
174k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
174k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
174k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
174k
          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
695k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
521k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
521k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
521k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
521k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
521k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
521k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
520k
      samp_rows = compptr->v_samp_factor;
322
1.17k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1.17k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1.17k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1.17k
    }
327
328
1.47M
    for (row = 0; row < samp_rows; row++) {
329
949k
      memcpy(output_buf[ci][row], buffer[row],
330
949k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
949k
    }
332
521k
  }
333
334
174k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
173k
    return JPEG_ROW_COMPLETED;
336
830
  return JPEG_SCAN_COMPLETED;
337
174k
}
jddiffct-8.c:output_data
Line
Count
Source
296
35.8k
{
297
35.8k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
35.8k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
35.8k
  int ci, samp_rows, row;
300
35.8k
  _JSAMPARRAY buffer;
301
35.8k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
35.8k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
35.8k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
35.8k
          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
143k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
107k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
107k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
107k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
107k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
107k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
107k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
106k
      samp_rows = compptr->v_samp_factor;
322
391
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
391
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
391
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
391
    }
327
328
228k
    for (row = 0; row < samp_rows; row++) {
329
120k
      memcpy(output_buf[ci][row], buffer[row],
330
120k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
120k
    }
332
107k
  }
333
334
35.8k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
35.5k
    return JPEG_ROW_COMPLETED;
336
275
  return JPEG_SCAN_COMPLETED;
337
35.8k
}
jddiffct-12.c:output_data
Line
Count
Source
296
71.5k
{
297
71.5k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
71.5k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
71.5k
  int ci, samp_rows, row;
300
71.5k
  _JSAMPARRAY buffer;
301
71.5k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
71.5k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
71.5k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
71.5k
          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
285k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
214k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
214k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
214k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
214k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
214k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
214k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
213k
      samp_rows = compptr->v_samp_factor;
322
333
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
333
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
333
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
333
    }
327
328
547k
    for (row = 0; row < samp_rows; row++) {
329
332k
      memcpy(output_buf[ci][row], buffer[row],
330
332k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
332k
    }
332
214k
  }
333
334
71.5k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
71.3k
    return JPEG_ROW_COMPLETED;
336
220
  return JPEG_SCAN_COMPLETED;
337
71.5k
}
jddiffct-16.c:output_data
Line
Count
Source
296
66.8k
{
297
66.8k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
66.8k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
66.8k
  int ci, samp_rows, row;
300
66.8k
  _JSAMPARRAY buffer;
301
66.8k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
66.8k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
66.8k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
66.8k
          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
266k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
199k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
199k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
199k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
199k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
199k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
199k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
199k
      samp_rows = compptr->v_samp_factor;
322
449
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
449
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
449
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
449
    }
327
328
696k
    for (row = 0; row < samp_rows; row++) {
329
496k
      memcpy(output_buf[ci][row], buffer[row],
330
496k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
496k
    }
332
199k
  }
333
334
66.8k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
66.4k
    return JPEG_ROW_COMPLETED;
336
335
  return JPEG_SCAN_COMPLETED;
337
66.8k
}
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.58k
{
349
1.58k
  my_diff_ptr diff;
350
1.58k
  int ci;
351
1.58k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
471
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
1.11k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.11k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.58k
  diff = (my_diff_ptr)
362
1.58k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.58k
                                sizeof(my_diff_controller));
364
1.58k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.58k
  diff->pub.start_input_pass = start_input_pass;
366
1.58k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
6.32k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.74k
       ci++, compptr++) {
371
4.74k
    diff->diff_buf[ci] =
372
4.74k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.74k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.74k
                                         (long)compptr->h_samp_factor),
375
4.74k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.74k
    diff->undiff_buf[ci] =
377
4.74k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.74k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.74k
                                         (long)compptr->h_samp_factor),
380
4.74k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.74k
  }
382
383
1.58k
  if (need_full_buffer) {
384
1.28k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.28k
    int access_rows;
387
388
5.14k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.85k
         ci++, compptr++) {
390
3.85k
      access_rows = compptr->v_samp_factor;
391
3.85k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.85k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.85k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.85k
                               (long)compptr->h_samp_factor),
395
3.85k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.85k
                               (long)compptr->v_samp_factor),
397
3.85k
         (JDIMENSION)access_rows);
398
3.85k
    }
399
1.28k
    diff->pub.consume_data = consume_data;
400
1.28k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.28k
  } else {
405
295
    diff->pub.consume_data = dummy_consume_data;
406
295
    diff->pub._decompress_data = decompress_data;
407
295
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
295
  }
409
1.58k
}
jinit_d_diff_controller
Line
Count
Source
348
471
{
349
471
  my_diff_ptr diff;
350
471
  int ci;
351
471
  jpeg_component_info *compptr;
352
353
471
#if BITS_IN_JSAMPLE == 8
354
471
  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
471
  diff = (my_diff_ptr)
362
471
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
471
                                sizeof(my_diff_controller));
364
471
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
471
  diff->pub.start_input_pass = start_input_pass;
366
471
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.88k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.41k
       ci++, compptr++) {
371
1.41k
    diff->diff_buf[ci] =
372
1.41k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.41k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.41k
                                         (long)compptr->h_samp_factor),
375
1.41k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.41k
    diff->undiff_buf[ci] =
377
1.41k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.41k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.41k
                                         (long)compptr->h_samp_factor),
380
1.41k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.41k
  }
382
383
471
  if (need_full_buffer) {
384
406
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
406
    int access_rows;
387
388
1.62k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.21k
         ci++, compptr++) {
390
1.21k
      access_rows = compptr->v_samp_factor;
391
1.21k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.21k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.21k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.21k
                               (long)compptr->h_samp_factor),
395
1.21k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.21k
                               (long)compptr->v_samp_factor),
397
1.21k
         (JDIMENSION)access_rows);
398
1.21k
    }
399
406
    diff->pub.consume_data = consume_data;
400
406
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
406
  } else {
405
65
    diff->pub.consume_data = dummy_consume_data;
406
65
    diff->pub._decompress_data = decompress_data;
407
65
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
65
  }
409
471
}
j12init_d_diff_controller
Line
Count
Source
348
518
{
349
518
  my_diff_ptr diff;
350
518
  int ci;
351
518
  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
518
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
518
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
518
  diff = (my_diff_ptr)
362
518
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
518
                                sizeof(my_diff_controller));
364
518
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
518
  diff->pub.start_input_pass = start_input_pass;
366
518
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.07k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.55k
       ci++, compptr++) {
371
1.55k
    diff->diff_buf[ci] =
372
1.55k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.55k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.55k
                                         (long)compptr->h_samp_factor),
375
1.55k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.55k
    diff->undiff_buf[ci] =
377
1.55k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.55k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.55k
                                         (long)compptr->h_samp_factor),
380
1.55k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.55k
  }
382
383
518
  if (need_full_buffer) {
384
408
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
408
    int access_rows;
387
388
1.63k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.22k
         ci++, compptr++) {
390
1.22k
      access_rows = compptr->v_samp_factor;
391
1.22k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.22k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.22k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.22k
                               (long)compptr->h_samp_factor),
395
1.22k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.22k
                               (long)compptr->v_samp_factor),
397
1.22k
         (JDIMENSION)access_rows);
398
1.22k
    }
399
408
    diff->pub.consume_data = consume_data;
400
408
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
408
  } else {
405
110
    diff->pub.consume_data = dummy_consume_data;
406
110
    diff->pub._decompress_data = decompress_data;
407
110
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
110
  }
409
518
}
j16init_d_diff_controller
Line
Count
Source
348
592
{
349
592
  my_diff_ptr diff;
350
592
  int ci;
351
592
  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
592
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
592
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
592
  diff = (my_diff_ptr)
362
592
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
592
                                sizeof(my_diff_controller));
364
592
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
592
  diff->pub.start_input_pass = start_input_pass;
366
592
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.36k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.77k
       ci++, compptr++) {
371
1.77k
    diff->diff_buf[ci] =
372
1.77k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.77k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.77k
                                         (long)compptr->h_samp_factor),
375
1.77k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.77k
    diff->undiff_buf[ci] =
377
1.77k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.77k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.77k
                                         (long)compptr->h_samp_factor),
380
1.77k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.77k
  }
382
383
592
  if (need_full_buffer) {
384
472
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
472
    int access_rows;
387
388
1.88k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.41k
         ci++, compptr++) {
390
1.41k
      access_rows = compptr->v_samp_factor;
391
1.41k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.41k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.41k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.41k
                               (long)compptr->h_samp_factor),
395
1.41k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.41k
                               (long)compptr->v_samp_factor),
397
1.41k
         (JDIMENSION)access_rows);
398
1.41k
    }
399
472
    diff->pub.consume_data = consume_data;
400
472
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
472
  } else {
405
120
    diff->pub.consume_data = dummy_consume_data;
406
120
    diff->pub._decompress_data = decompress_data;
407
120
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
120
  }
409
592
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */