Coverage Report

Created: 2025-07-14 06:09

/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.8M
{
68
11.8M
  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.8M
  if (cinfo->comps_in_scan > 1) {
75
849k
    diff->MCU_rows_per_iMCU_row = 1;
76
11.0M
  } else {
77
11.0M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
11.0M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
3.56k
    else
80
3.56k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
11.0M
  }
82
83
11.8M
  diff->MCU_ctr = 0;
84
11.8M
  diff->MCU_vert_offset = 0;
85
11.8M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
1.05M
{
68
1.05M
  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.05M
  if (cinfo->comps_in_scan > 1) {
75
244k
    diff->MCU_rows_per_iMCU_row = 1;
76
807k
  } else {
77
807k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
806k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.37k
    else
80
1.37k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
807k
  }
82
83
1.05M
  diff->MCU_ctr = 0;
84
1.05M
  diff->MCU_vert_offset = 0;
85
1.05M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
4.15M
{
68
4.15M
  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
4.15M
  if (cinfo->comps_in_scan > 1) {
75
152k
    diff->MCU_rows_per_iMCU_row = 1;
76
4.00M
  } else {
77
4.00M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
4.00M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.20k
    else
80
1.20k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
4.00M
  }
82
83
4.15M
  diff->MCU_ctr = 0;
84
4.15M
  diff->MCU_vert_offset = 0;
85
4.15M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
6.68M
{
68
6.68M
  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.68M
  if (cinfo->comps_in_scan > 1) {
75
453k
    diff->MCU_rows_per_iMCU_row = 1;
76
6.23M
  } else {
77
6.23M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
6.23M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
985
    else
80
985
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
6.23M
  }
82
83
6.68M
  diff->MCU_ctr = 0;
84
6.68M
  diff->MCU_vert_offset = 0;
85
6.68M
}
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.29k
{
95
5.29k
  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.29k
  (*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.29k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
38
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
5.29k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
5.29k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
5.29k
  cinfo->input_iMCU_row = 0;
115
5.29k
  start_iMCU_row(cinfo);
116
5.29k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
2.04k
{
95
2.04k
  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.04k
  (*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.04k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
13
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
2.04k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
2.04k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
2.04k
  cinfo->input_iMCU_row = 0;
115
2.04k
  start_iMCU_row(cinfo);
116
2.04k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
1.82k
{
95
1.82k
  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.82k
  (*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.82k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
12
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.82k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.82k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.82k
  cinfo->input_iMCU_row = 0;
115
1.82k
  start_iMCU_row(cinfo);
116
1.82k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
1.42k
{
95
1.42k
  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.42k
  (*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.42k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
13
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.42k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.42k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.42k
  cinfo->input_iMCU_row = 0;
115
1.42k
  start_iMCU_row(cinfo);
116
1.42k
}
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
89.3k
{
127
89.3k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
89.3k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
89.3k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
89.3k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
89.3k
  return TRUE;
138
89.3k
}
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
4.47k
{
127
4.47k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
4.47k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
4.47k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
4.47k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
4.47k
  return TRUE;
138
4.47k
}
jddiffct-16.c:process_restart
Line
Count
Source
126
83.4k
{
127
83.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
83.4k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
83.4k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
83.4k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
83.4k
  return TRUE;
138
83.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.22k
{
148
1.22k
  cinfo->output_iMCU_row = 0;
149
1.22k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
366
{
148
366
  cinfo->output_iMCU_row = 0;
149
366
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
407
{
148
407
  cinfo->output_iMCU_row = 0;
149
407
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
451
{
148
451
  cinfo->output_iMCU_row = 0;
149
451
}
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.8M
{
165
11.8M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
11.8M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
11.8M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
11.8M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
11.8M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
11.8M
  int ci, compi, row, prev_row;
171
11.8M
  unsigned int yoffset;
172
11.8M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
29.0M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
17.1M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
17.1M
    if (cinfo->restart_interval) {
180
2.34M
      if (diff->restart_rows_to_go == 0)
181
89.3k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
2.34M
    }
184
185
17.1M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
17.1M
    MCU_count =
188
17.1M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
17.1M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
17.1M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
17.1M
    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
17.1M
    if (cinfo->restart_interval)
200
2.34M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
17.1M
    diff->MCU_ctr = 0;
204
17.1M
  }
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
25.3M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
13.4M
    compptr = cinfo->cur_comp_info[ci];
213
13.4M
    compi = compptr->component_index;
214
13.4M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
34.0M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
33.9M
                compptr->last_row_height : compptr->v_samp_factor);
217
20.5M
         prev_row = row, row++) {
218
20.5M
      (*losslessd->predict_undifference[compi])
219
20.5M
        (cinfo, compi, diff->diff_buf[compi][row],
220
20.5M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
20.5M
          compptr->width_in_blocks);
222
20.5M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
20.5M
                                  output_buf[compi][row],
224
20.5M
                                  compptr->width_in_blocks);
225
20.5M
    }
226
13.4M
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
11.8M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
11.8M
    start_iMCU_row(cinfo);
236
11.8M
    return JPEG_ROW_COMPLETED;
237
11.8M
  }
238
  /* Completed the scan */
239
5.15k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
5.15k
  return JPEG_SCAN_COMPLETED;
241
11.8M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
1.05M
{
165
1.05M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
1.05M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
1.05M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
1.05M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
1.05M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
1.05M
  int ci, compi, row, prev_row;
171
1.05M
  unsigned int yoffset;
172
1.05M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
2.66M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
1.61M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
1.61M
    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.61M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
1.61M
    MCU_count =
188
1.61M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
1.61M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
1.61M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
1.61M
    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.61M
    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.61M
    diff->MCU_ctr = 0;
204
1.61M
  }
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.50M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
1.45M
    compptr = cinfo->cur_comp_info[ci];
213
1.45M
    compi = compptr->component_index;
214
1.45M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
3.58M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
3.57M
                compptr->last_row_height : compptr->v_samp_factor);
217
2.12M
         prev_row = row, row++) {
218
2.12M
      (*losslessd->predict_undifference[compi])
219
2.12M
        (cinfo, compi, diff->diff_buf[compi][row],
220
2.12M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
2.12M
          compptr->width_in_blocks);
222
2.12M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
2.12M
                                  output_buf[compi][row],
224
2.12M
                                  compptr->width_in_blocks);
225
2.12M
    }
226
1.45M
  }
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.05M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
1.04M
    start_iMCU_row(cinfo);
236
1.04M
    return JPEG_ROW_COMPLETED;
237
1.04M
  }
238
  /* Completed the scan */
239
1.98k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.98k
  return JPEG_SCAN_COMPLETED;
241
1.05M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
4.15M
{
165
4.15M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
4.15M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
4.15M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
4.15M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
4.15M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
4.15M
  int ci, compi, row, prev_row;
171
4.15M
  unsigned int yoffset;
172
4.15M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
12.2M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
8.07M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
8.07M
    if (cinfo->restart_interval) {
180
676k
      if (diff->restart_rows_to_go == 0)
181
4.47k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
676k
    }
184
185
8.07M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
8.07M
    MCU_count =
188
8.07M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
8.07M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
8.07M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
8.07M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
8.07M
    if (cinfo->restart_interval)
200
676k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
8.07M
    diff->MCU_ctr = 0;
204
8.07M
  }
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
8.59M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
4.44M
    compptr = cinfo->cur_comp_info[ci];
213
4.44M
    compi = compptr->component_index;
214
4.44M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
13.0M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
13.0M
                compptr->last_row_height : compptr->v_samp_factor);
217
8.64M
         prev_row = row, row++) {
218
8.64M
      (*losslessd->predict_undifference[compi])
219
8.64M
        (cinfo, compi, diff->diff_buf[compi][row],
220
8.64M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
8.64M
          compptr->width_in_blocks);
222
8.64M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
8.64M
                                  output_buf[compi][row],
224
8.64M
                                  compptr->width_in_blocks);
225
8.64M
    }
226
4.44M
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
4.15M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
4.15M
    start_iMCU_row(cinfo);
236
4.15M
    return JPEG_ROW_COMPLETED;
237
4.15M
  }
238
  /* Completed the scan */
239
1.78k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.78k
  return JPEG_SCAN_COMPLETED;
241
4.15M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
6.68M
{
165
6.68M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
6.68M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
6.68M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
6.68M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
6.68M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
6.68M
  int ci, compi, row, prev_row;
171
6.68M
  unsigned int yoffset;
172
6.68M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
14.1M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
7.48M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
7.48M
    if (cinfo->restart_interval) {
180
1.42M
      if (diff->restart_rows_to_go == 0)
181
83.4k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.42M
    }
184
185
7.48M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
7.48M
    MCU_count =
188
7.48M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
7.48M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
7.48M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
7.48M
    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.48M
    if (cinfo->restart_interval)
200
1.42M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
7.48M
    diff->MCU_ctr = 0;
204
7.48M
  }
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.2M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
7.58M
    compptr = cinfo->cur_comp_info[ci];
213
7.58M
    compi = compptr->component_index;
214
7.58M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
17.3M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
17.3M
                compptr->last_row_height : compptr->v_samp_factor);
217
9.75M
         prev_row = row, row++) {
218
9.75M
      (*losslessd->predict_undifference[compi])
219
9.75M
        (cinfo, compi, diff->diff_buf[compi][row],
220
9.75M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
9.75M
          compptr->width_in_blocks);
222
9.75M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
9.75M
                                  output_buf[compi][row],
224
9.75M
                                  compptr->width_in_blocks);
225
9.75M
    }
226
7.58M
  }
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.68M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
6.68M
    start_iMCU_row(cinfo);
236
6.68M
    return JPEG_ROW_COMPLETED;
237
6.68M
  }
238
  /* Completed the scan */
239
1.37k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.37k
  return JPEG_SCAN_COMPLETED;
241
6.68M
}
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
11.5M
{
267
11.5M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
11.5M
  int ci, compi;
269
11.5M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
11.5M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
23.9M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
12.4M
    compptr = cinfo->cur_comp_info[ci];
275
12.4M
    compi = compptr->component_index;
276
12.4M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
12.4M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
12.4M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
12.4M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
12.4M
  }
281
282
11.5M
  return decompress_data(cinfo, buffer);
283
11.5M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
933k
{
267
933k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
933k
  int ci, compi;
269
933k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
933k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
2.03M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
1.10M
    compptr = cinfo->cur_comp_info[ci];
275
1.10M
    compi = compptr->component_index;
276
1.10M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
1.10M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
1.10M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
1.10M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
1.10M
  }
281
282
933k
  return decompress_data(cinfo, buffer);
283
933k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
4.05M
{
267
4.05M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
4.05M
  int ci, compi;
269
4.05M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
4.05M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
8.20M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
4.15M
    compptr = cinfo->cur_comp_info[ci];
275
4.15M
    compi = compptr->component_index;
276
4.15M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
4.15M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
4.15M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
4.15M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
4.15M
  }
281
282
4.05M
  return decompress_data(cinfo, buffer);
283
4.05M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
6.54M
{
267
6.54M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
6.54M
  int ci, compi;
269
6.54M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
6.54M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
13.6M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
7.14M
    compptr = cinfo->cur_comp_info[ci];
275
7.14M
    compi = compptr->component_index;
276
7.14M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
7.14M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
7.14M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
7.14M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
7.14M
  }
281
282
6.54M
  return decompress_data(cinfo, buffer);
283
6.54M
}
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
177k
{
297
177k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
177k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
177k
  int ci, samp_rows, row;
300
177k
  _JSAMPARRAY buffer;
301
177k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
177k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
177k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
177k
          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
710k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
532k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
532k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
532k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
532k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
532k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
532k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
531k
      samp_rows = compptr->v_samp_factor;
322
1.19k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1.19k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1.19k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1.19k
    }
327
328
1.50M
    for (row = 0; row < samp_rows; row++) {
329
972k
      memcpy(output_buf[ci][row], buffer[row],
330
972k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
972k
    }
332
532k
  }
333
334
177k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
177k
    return JPEG_ROW_COMPLETED;
336
848
  return JPEG_SCAN_COMPLETED;
337
177k
}
jddiffct-8.c:output_data
Line
Count
Source
296
39.6k
{
297
39.6k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
39.6k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
39.6k
  int ci, samp_rows, row;
300
39.6k
  _JSAMPARRAY buffer;
301
39.6k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
39.6k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
39.6k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
39.6k
          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
158k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
118k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
118k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
118k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
118k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
118k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
118k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
118k
      samp_rows = compptr->v_samp_factor;
322
402
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
402
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
402
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
402
    }
327
328
262k
    for (row = 0; row < samp_rows; row++) {
329
143k
      memcpy(output_buf[ci][row], buffer[row],
330
143k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
143k
    }
332
118k
  }
333
334
39.6k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
39.3k
    return JPEG_ROW_COMPLETED;
336
282
  return JPEG_SCAN_COMPLETED;
337
39.6k
}
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
335
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
335
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
335
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
335
    }
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
223
  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
200k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
200k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
200k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
200k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
200k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
200k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
199k
      samp_rows = compptr->v_samp_factor;
322
458
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
458
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
458
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
458
    }
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
200k
  }
333
334
66.8k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
66.4k
    return JPEG_ROW_COMPLETED;
336
343
  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.61k
{
349
1.61k
  my_diff_ptr diff;
350
1.61k
  int ci;
351
1.61k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
487
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
1.12k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.12k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.61k
  diff = (my_diff_ptr)
362
1.61k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.61k
                                sizeof(my_diff_controller));
364
1.61k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.61k
  diff->pub.start_input_pass = start_input_pass;
366
1.61k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
6.45k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.84k
       ci++, compptr++) {
371
4.84k
    diff->diff_buf[ci] =
372
4.84k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.84k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.84k
                                         (long)compptr->h_samp_factor),
375
4.84k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.84k
    diff->undiff_buf[ci] =
377
4.84k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.84k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.84k
                                         (long)compptr->h_samp_factor),
380
4.84k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.84k
  }
382
383
1.61k
  if (need_full_buffer) {
384
1.31k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.31k
    int access_rows;
387
388
5.24k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.93k
         ci++, compptr++) {
390
3.93k
      access_rows = compptr->v_samp_factor;
391
3.93k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.93k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.93k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.93k
                               (long)compptr->h_samp_factor),
395
3.93k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.93k
                               (long)compptr->v_samp_factor),
397
3.93k
         (JDIMENSION)access_rows);
398
3.93k
    }
399
1.31k
    diff->pub.consume_data = consume_data;
400
1.31k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.31k
  } else {
405
304
    diff->pub.consume_data = dummy_consume_data;
406
304
    diff->pub._decompress_data = decompress_data;
407
304
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
304
  }
409
1.61k
}
jinit_d_diff_controller
Line
Count
Source
348
487
{
349
487
  my_diff_ptr diff;
350
487
  int ci;
351
487
  jpeg_component_info *compptr;
352
353
487
#if BITS_IN_JSAMPLE == 8
354
487
  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
487
  diff = (my_diff_ptr)
362
487
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
487
                                sizeof(my_diff_controller));
364
487
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
487
  diff->pub.start_input_pass = start_input_pass;
366
487
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.94k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.46k
       ci++, compptr++) {
371
1.46k
    diff->diff_buf[ci] =
372
1.46k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.46k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.46k
                                         (long)compptr->h_samp_factor),
375
1.46k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.46k
    diff->undiff_buf[ci] =
377
1.46k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.46k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.46k
                                         (long)compptr->h_samp_factor),
380
1.46k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.46k
  }
382
383
487
  if (need_full_buffer) {
384
416
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
416
    int access_rows;
387
388
1.66k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.24k
         ci++, compptr++) {
390
1.24k
      access_rows = compptr->v_samp_factor;
391
1.24k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.24k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.24k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.24k
                               (long)compptr->h_samp_factor),
395
1.24k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.24k
                               (long)compptr->v_samp_factor),
397
1.24k
         (JDIMENSION)access_rows);
398
1.24k
    }
399
416
    diff->pub.consume_data = consume_data;
400
416
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
416
  } else {
405
71
    diff->pub.consume_data = dummy_consume_data;
406
71
    diff->pub._decompress_data = decompress_data;
407
71
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
71
  }
409
487
}
j12init_d_diff_controller
Line
Count
Source
348
531
{
349
531
  my_diff_ptr diff;
350
531
  int ci;
351
531
  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
531
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
531
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
531
  diff = (my_diff_ptr)
362
531
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
531
                                sizeof(my_diff_controller));
364
531
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
531
  diff->pub.start_input_pass = start_input_pass;
366
531
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.12k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.59k
       ci++, compptr++) {
371
1.59k
    diff->diff_buf[ci] =
372
1.59k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.59k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.59k
                                         (long)compptr->h_samp_factor),
375
1.59k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.59k
    diff->undiff_buf[ci] =
377
1.59k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.59k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.59k
                                         (long)compptr->h_samp_factor),
380
1.59k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.59k
  }
382
383
531
  if (need_full_buffer) {
384
418
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
418
    int access_rows;
387
388
1.67k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.25k
         ci++, compptr++) {
390
1.25k
      access_rows = compptr->v_samp_factor;
391
1.25k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.25k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.25k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.25k
                               (long)compptr->h_samp_factor),
395
1.25k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.25k
                               (long)compptr->v_samp_factor),
397
1.25k
         (JDIMENSION)access_rows);
398
1.25k
    }
399
418
    diff->pub.consume_data = consume_data;
400
418
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
418
  } else {
405
113
    diff->pub.consume_data = dummy_consume_data;
406
113
    diff->pub._decompress_data = decompress_data;
407
113
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
113
  }
409
531
}
j16init_d_diff_controller
Line
Count
Source
348
596
{
349
596
  my_diff_ptr diff;
350
596
  int ci;
351
596
  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
596
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
596
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
596
  diff = (my_diff_ptr)
362
596
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
596
                                sizeof(my_diff_controller));
364
596
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
596
  diff->pub.start_input_pass = start_input_pass;
366
596
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.38k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.78k
       ci++, compptr++) {
371
1.78k
    diff->diff_buf[ci] =
372
1.78k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.78k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.78k
                                         (long)compptr->h_samp_factor),
375
1.78k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.78k
    diff->undiff_buf[ci] =
377
1.78k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.78k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.78k
                                         (long)compptr->h_samp_factor),
380
1.78k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.78k
  }
382
383
596
  if (need_full_buffer) {
384
476
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
476
    int access_rows;
387
388
1.90k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.42k
         ci++, compptr++) {
390
1.42k
      access_rows = compptr->v_samp_factor;
391
1.42k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.42k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.42k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.42k
                               (long)compptr->h_samp_factor),
395
1.42k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.42k
                               (long)compptr->v_samp_factor),
397
1.42k
         (JDIMENSION)access_rows);
398
1.42k
    }
399
476
    diff->pub.consume_data = consume_data;
400
476
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
476
  } 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
596
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */