Coverage Report

Created: 2025-11-09 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.dev/src/jddiffct.c
Line
Count
Source
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
144M
{
68
144M
  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
144M
  if (cinfo->comps_in_scan > 1) {
75
44.9M
    diff->MCU_rows_per_iMCU_row = 1;
76
99.6M
  } else {
77
99.6M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
99.6M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
13.4k
    else
80
13.4k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
99.6M
  }
82
83
144M
  diff->MCU_ctr = 0;
84
144M
  diff->MCU_vert_offset = 0;
85
144M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
17.2M
{
68
17.2M
  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
17.2M
  if (cinfo->comps_in_scan > 1) {
75
1.76M
    diff->MCU_rows_per_iMCU_row = 1;
76
15.4M
  } else {
77
15.4M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
15.4M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
4.07k
    else
80
4.07k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
15.4M
  }
82
83
17.2M
  diff->MCU_ctr = 0;
84
17.2M
  diff->MCU_vert_offset = 0;
85
17.2M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
59.6M
{
68
59.6M
  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
59.6M
  if (cinfo->comps_in_scan > 1) {
75
21.7M
    diff->MCU_rows_per_iMCU_row = 1;
76
37.8M
  } else {
77
37.8M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
37.8M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
5.26k
    else
80
5.26k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
37.8M
  }
82
83
59.6M
  diff->MCU_ctr = 0;
84
59.6M
  diff->MCU_vert_offset = 0;
85
59.6M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
67.7M
{
68
67.7M
  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
67.7M
  if (cinfo->comps_in_scan > 1) {
75
21.4M
    diff->MCU_rows_per_iMCU_row = 1;
76
46.3M
  } else {
77
46.3M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
46.3M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
4.11k
    else
80
4.11k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
46.3M
  }
82
83
67.7M
  diff->MCU_ctr = 0;
84
67.7M
  diff->MCU_vert_offset = 0;
85
67.7M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
20.5k
{
95
20.5k
  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
20.5k
  (*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
20.5k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
85
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
20.5k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
20.5k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
20.5k
  cinfo->input_iMCU_row = 0;
115
20.5k
  start_iMCU_row(cinfo);
116
20.5k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
6.31k
{
95
6.31k
  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
6.31k
  (*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
6.31k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
42
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
6.31k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
6.31k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
6.31k
  cinfo->input_iMCU_row = 0;
115
6.31k
  start_iMCU_row(cinfo);
116
6.31k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
7.76k
{
95
7.76k
  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
7.76k
  (*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
7.76k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
8
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
7.76k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
7.76k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
7.76k
  cinfo->input_iMCU_row = 0;
115
7.76k
  start_iMCU_row(cinfo);
116
7.76k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
6.42k
{
95
6.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
6.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
6.42k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
35
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
6.42k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
6.42k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
6.42k
  cinfo->input_iMCU_row = 0;
115
6.42k
  start_iMCU_row(cinfo);
116
6.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
17.6M
{
127
17.6M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
17.6M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
17.6M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
17.6M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
17.6M
  return TRUE;
138
17.6M
}
jddiffct-8.c:process_restart
Line
Count
Source
126
188k
{
127
188k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
188k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
188k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
188k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
188k
  return TRUE;
138
188k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
14.0M
{
127
14.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
14.0M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
14.0M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
14.0M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
14.0M
  return TRUE;
138
14.0M
}
jddiffct-16.c:process_restart
Line
Count
Source
126
3.38M
{
127
3.38M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
3.38M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
3.38M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
3.38M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
3.38M
  return TRUE;
138
3.38M
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
3.85k
{
148
3.85k
  cinfo->output_iMCU_row = 0;
149
3.85k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
1.23k
{
148
1.23k
  cinfo->output_iMCU_row = 0;
149
1.23k
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
1.30k
{
148
1.30k
  cinfo->output_iMCU_row = 0;
149
1.30k
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
1.31k
{
148
1.31k
  cinfo->output_iMCU_row = 0;
149
1.31k
}
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
144M
{
165
144M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
144M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
144M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
144M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
144M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
144M
  int ci, compi, row, prev_row;
171
144M
  unsigned int yoffset;
172
144M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
316M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
171M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
171M
    if (cinfo->restart_interval) {
180
57.7M
      if (diff->restart_rows_to_go == 0)
181
17.6M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
57.7M
    }
184
185
171M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
171M
    MCU_count =
188
171M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
171M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
171M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
171M
    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
171M
    if (cinfo->restart_interval)
200
57.7M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
171M
    diff->MCU_ctr = 0;
204
171M
  }
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
334M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
190M
    compptr = cinfo->cur_comp_info[ci];
213
190M
    compi = compptr->component_index;
214
190M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
418M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
418M
                compptr->last_row_height : compptr->v_samp_factor);
217
228M
         prev_row = row, row++) {
218
228M
      (*losslessd->predict_undifference[compi])
219
228M
        (cinfo, compi, diff->diff_buf[compi][row],
220
228M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
228M
          compptr->width_in_blocks);
222
228M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
228M
                                  output_buf[compi][row],
224
228M
                                  compptr->width_in_blocks);
225
228M
    }
226
190M
  }
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
144M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
144M
    start_iMCU_row(cinfo);
236
144M
    return JPEG_ROW_COMPLETED;
237
144M
  }
238
  /* Completed the scan */
239
19.9k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
19.9k
  return JPEG_SCAN_COMPLETED;
241
144M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
17.2M
{
165
17.2M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
17.2M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
17.2M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
17.2M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
17.2M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
17.2M
  int ci, compi, row, prev_row;
171
17.2M
  unsigned int yoffset;
172
17.2M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
38.8M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
21.5M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
21.5M
    if (cinfo->restart_interval) {
180
3.34M
      if (diff->restart_rows_to_go == 0)
181
188k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
3.34M
    }
184
185
21.5M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
21.5M
    MCU_count =
188
21.5M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
21.5M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
21.5M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
21.5M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
21.5M
    if (cinfo->restart_interval)
200
3.34M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
21.5M
    diff->MCU_ctr = 0;
204
21.5M
  }
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
36.5M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
19.2M
    compptr = cinfo->cur_comp_info[ci];
213
19.2M
    compi = compptr->component_index;
214
19.2M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
44.0M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
44.0M
                compptr->last_row_height : compptr->v_samp_factor);
217
24.7M
         prev_row = row, row++) {
218
24.7M
      (*losslessd->predict_undifference[compi])
219
24.7M
        (cinfo, compi, diff->diff_buf[compi][row],
220
24.7M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
24.7M
          compptr->width_in_blocks);
222
24.7M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
24.7M
                                  output_buf[compi][row],
224
24.7M
                                  compptr->width_in_blocks);
225
24.7M
    }
226
19.2M
  }
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
17.2M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
17.2M
    start_iMCU_row(cinfo);
236
17.2M
    return JPEG_ROW_COMPLETED;
237
17.2M
  }
238
  /* Completed the scan */
239
6.11k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
6.11k
  return JPEG_SCAN_COMPLETED;
241
17.2M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
59.6M
{
165
59.6M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
59.6M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
59.6M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
59.6M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
59.6M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
59.6M
  int ci, compi, row, prev_row;
171
59.6M
  unsigned int yoffset;
172
59.6M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
137M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
78.0M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
78.0M
    if (cinfo->restart_interval) {
180
34.9M
      if (diff->restart_rows_to_go == 0)
181
14.0M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
34.9M
    }
184
185
78.0M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
78.0M
    MCU_count =
188
78.0M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
78.0M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
78.0M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
78.0M
    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
78.0M
    if (cinfo->restart_interval)
200
34.9M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
78.0M
    diff->MCU_ctr = 0;
204
78.0M
  }
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
141M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
81.4M
    compptr = cinfo->cur_comp_info[ci];
213
81.4M
    compi = compptr->component_index;
214
81.4M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
188M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
188M
                compptr->last_row_height : compptr->v_samp_factor);
217
107M
         prev_row = row, row++) {
218
107M
      (*losslessd->predict_undifference[compi])
219
107M
        (cinfo, compi, diff->diff_buf[compi][row],
220
107M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
107M
          compptr->width_in_blocks);
222
107M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
107M
                                  output_buf[compi][row],
224
107M
                                  compptr->width_in_blocks);
225
107M
    }
226
81.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
59.6M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
59.5M
    start_iMCU_row(cinfo);
236
59.5M
    return JPEG_ROW_COMPLETED;
237
59.5M
  }
238
  /* Completed the scan */
239
7.61k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
7.61k
  return JPEG_SCAN_COMPLETED;
241
59.6M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
67.7M
{
165
67.7M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
67.7M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
67.7M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
67.7M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
67.7M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
67.7M
  int ci, compi, row, prev_row;
171
67.7M
  unsigned int yoffset;
172
67.7M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
139M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
72.0M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
72.0M
    if (cinfo->restart_interval) {
180
19.4M
      if (diff->restart_rows_to_go == 0)
181
3.38M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
19.4M
    }
184
185
72.0M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
72.0M
    MCU_count =
188
72.0M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
72.0M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
72.0M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
72.0M
    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
72.0M
    if (cinfo->restart_interval)
200
19.4M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
72.0M
    diff->MCU_ctr = 0;
204
72.0M
  }
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
157M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
89.5M
    compptr = cinfo->cur_comp_info[ci];
213
89.5M
    compi = compptr->component_index;
214
89.5M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
185M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
185M
                compptr->last_row_height : compptr->v_samp_factor);
217
96.3M
         prev_row = row, row++) {
218
96.3M
      (*losslessd->predict_undifference[compi])
219
96.3M
        (cinfo, compi, diff->diff_buf[compi][row],
220
96.3M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
96.3M
          compptr->width_in_blocks);
222
96.3M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
96.3M
                                  output_buf[compi][row],
224
96.3M
                                  compptr->width_in_blocks);
225
96.3M
    }
226
89.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
67.7M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
67.7M
    start_iMCU_row(cinfo);
236
67.7M
    return JPEG_ROW_COMPLETED;
237
67.7M
  }
238
  /* Completed the scan */
239
6.24k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
6.24k
  return JPEG_SCAN_COMPLETED;
241
67.7M
}
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
144M
{
267
144M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
144M
  int ci, compi;
269
144M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
144M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
333M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
189M
    compptr = cinfo->cur_comp_info[ci];
275
189M
    compi = compptr->component_index;
276
189M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
189M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
189M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
189M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
189M
  }
281
282
144M
  return decompress_data(cinfo, buffer);
283
144M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
17.1M
{
267
17.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
17.1M
  int ci, compi;
269
17.1M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
17.1M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
36.0M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
18.9M
    compptr = cinfo->cur_comp_info[ci];
275
18.9M
    compi = compptr->component_index;
276
18.9M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
18.9M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
18.9M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
18.9M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
18.9M
  }
281
282
17.1M
  return decompress_data(cinfo, buffer);
283
17.1M
}
jddiffct-12.c:consume_data
Line
Count
Source
266
59.5M
{
267
59.5M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
59.5M
  int ci, compi;
269
59.5M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
59.5M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
140M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
81.1M
    compptr = cinfo->cur_comp_info[ci];
275
81.1M
    compi = compptr->component_index;
276
81.1M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
81.1M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
81.1M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
81.1M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
81.1M
  }
281
282
59.5M
  return decompress_data(cinfo, buffer);
283
59.5M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
67.5M
{
267
67.5M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
67.5M
  int ci, compi;
269
67.5M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
67.5M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
156M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
88.8M
    compptr = cinfo->cur_comp_info[ci];
275
88.8M
    compi = compptr->component_index;
276
88.8M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
88.8M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
88.8M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
88.8M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
88.8M
  }
281
282
67.5M
  return decompress_data(cinfo, buffer);
283
67.5M
}
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
732k
{
297
732k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
732k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
732k
  int ci, samp_rows, row;
300
732k
  _JSAMPARRAY buffer;
301
732k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
732k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
732k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
732k
          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
2.92M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
2.19M
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
2.19M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
2.19M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
2.19M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
2.19M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
2.19M
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
2.19M
      samp_rows = compptr->v_samp_factor;
322
2.21k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
2.21k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
2.21k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
2.21k
    }
327
328
5.74M
    for (row = 0; row < samp_rows; row++) {
329
3.54M
      memcpy(output_buf[ci][row], buffer[row],
330
3.54M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
3.54M
    }
332
2.19M
  }
333
334
732k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
730k
    return JPEG_ROW_COMPLETED;
336
1.60k
  return JPEG_SCAN_COMPLETED;
337
732k
}
jddiffct-8.c:output_data
Line
Count
Source
296
151k
{
297
151k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
151k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
151k
  int ci, samp_rows, row;
300
151k
  _JSAMPARRAY buffer;
301
151k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
151k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
151k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
151k
          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
603k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
452k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
452k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
452k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
452k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
452k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
452k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
451k
      samp_rows = compptr->v_samp_factor;
322
684
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
684
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
684
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
684
    }
327
328
1.20M
    for (row = 0; row < samp_rows; row++) {
329
751k
      memcpy(output_buf[ci][row], buffer[row],
330
751k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
751k
    }
332
452k
  }
333
334
151k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
150k
    return JPEG_ROW_COMPLETED;
336
492
  return JPEG_SCAN_COMPLETED;
337
151k
}
jddiffct-12.c:output_data
Line
Count
Source
296
302k
{
297
302k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
302k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
302k
  int ci, samp_rows, row;
300
302k
  _JSAMPARRAY buffer;
301
302k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
302k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
302k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
302k
          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
1.20M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
905k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
905k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
905k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
905k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
905k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
905k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
904k
      samp_rows = compptr->v_samp_factor;
322
693
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
693
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
693
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
693
    }
327
328
2.36M
    for (row = 0; row < samp_rows; row++) {
329
1.46M
      memcpy(output_buf[ci][row], buffer[row],
330
1.46M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1.46M
    }
332
905k
  }
333
334
302k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
301k
    return JPEG_ROW_COMPLETED;
336
493
  return JPEG_SCAN_COMPLETED;
337
302k
}
jddiffct-16.c:output_data
Line
Count
Source
296
279k
{
297
279k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
279k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
279k
  int ci, samp_rows, row;
300
279k
  _JSAMPARRAY buffer;
301
279k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
279k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
279k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
279k
          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
1.11M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
836k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
836k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
836k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
836k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
836k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
836k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
836k
      samp_rows = compptr->v_samp_factor;
322
837
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
837
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
837
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
837
    }
327
328
2.17M
    for (row = 0; row < samp_rows; row++) {
329
1.33M
      memcpy(output_buf[ci][row], buffer[row],
330
1.33M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1.33M
    }
332
836k
  }
333
334
279k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
278k
    return JPEG_ROW_COMPLETED;
336
619
  return JPEG_SCAN_COMPLETED;
337
279k
}
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
5.33k
{
349
5.33k
  my_diff_ptr diff;
350
5.33k
  int ci;
351
5.33k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
1.75k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
3.58k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
3.58k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
5.33k
  diff = (my_diff_ptr)
362
5.33k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
5.33k
                                sizeof(my_diff_controller));
364
5.33k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
5.33k
  diff->pub.start_input_pass = start_input_pass;
366
5.33k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
21.1k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
15.7k
       ci++, compptr++) {
371
15.7k
    diff->diff_buf[ci] =
372
15.7k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
15.7k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
15.7k
                                         (long)compptr->h_samp_factor),
375
15.7k
                   (JDIMENSION)compptr->v_samp_factor);
376
15.7k
    diff->undiff_buf[ci] =
377
15.7k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
15.7k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
15.7k
                                         (long)compptr->h_samp_factor),
380
15.7k
                   (JDIMENSION)compptr->v_samp_factor);
381
15.7k
  }
382
383
5.33k
  if (need_full_buffer) {
384
4.73k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
4.73k
    int access_rows;
387
388
18.9k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
14.2k
         ci++, compptr++) {
390
14.2k
      access_rows = compptr->v_samp_factor;
391
14.2k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
14.2k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
14.2k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
14.2k
                               (long)compptr->h_samp_factor),
395
14.2k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
14.2k
                               (long)compptr->v_samp_factor),
397
14.2k
         (JDIMENSION)access_rows);
398
14.2k
    }
399
4.73k
    diff->pub.consume_data = consume_data;
400
4.73k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
4.73k
  } else {
405
597
    diff->pub.consume_data = dummy_consume_data;
406
597
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
597
  }
409
5.33k
}
jinit_d_diff_controller
Line
Count
Source
348
1.75k
{
349
1.75k
  my_diff_ptr diff;
350
1.75k
  int ci;
351
1.75k
  jpeg_component_info *compptr;
352
353
1.75k
#if BITS_IN_JSAMPLE == 8
354
1.75k
  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
1.75k
  diff = (my_diff_ptr)
362
1.75k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.75k
                                sizeof(my_diff_controller));
364
1.75k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.75k
  diff->pub.start_input_pass = start_input_pass;
366
1.75k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
6.92k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
5.17k
       ci++, compptr++) {
371
5.17k
    diff->diff_buf[ci] =
372
5.17k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
5.17k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
5.17k
                                         (long)compptr->h_samp_factor),
375
5.17k
                   (JDIMENSION)compptr->v_samp_factor);
376
5.17k
    diff->undiff_buf[ci] =
377
5.17k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
5.17k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
5.17k
                                         (long)compptr->h_samp_factor),
380
5.17k
                   (JDIMENSION)compptr->v_samp_factor);
381
5.17k
  }
382
383
1.75k
  if (need_full_buffer) {
384
1.60k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.60k
    int access_rows;
387
388
6.40k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
4.80k
         ci++, compptr++) {
390
4.80k
      access_rows = compptr->v_samp_factor;
391
4.80k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
4.80k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
4.80k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
4.80k
                               (long)compptr->h_samp_factor),
395
4.80k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
4.80k
                               (long)compptr->v_samp_factor),
397
4.80k
         (JDIMENSION)access_rows);
398
4.80k
    }
399
1.60k
    diff->pub.consume_data = consume_data;
400
1.60k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.60k
  } else {
405
152
    diff->pub.consume_data = dummy_consume_data;
406
152
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
152
  }
409
1.75k
}
j12init_d_diff_controller
Line
Count
Source
348
1.78k
{
349
1.78k
  my_diff_ptr diff;
350
1.78k
  int ci;
351
1.78k
  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
1.78k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.78k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.78k
  diff = (my_diff_ptr)
362
1.78k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.78k
                                sizeof(my_diff_controller));
364
1.78k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.78k
  diff->pub.start_input_pass = start_input_pass;
366
1.78k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
7.02k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
5.24k
       ci++, compptr++) {
371
5.24k
    diff->diff_buf[ci] =
372
5.24k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
5.24k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
5.24k
                                         (long)compptr->h_samp_factor),
375
5.24k
                   (JDIMENSION)compptr->v_samp_factor);
376
5.24k
    diff->undiff_buf[ci] =
377
5.24k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
5.24k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
5.24k
                                         (long)compptr->h_samp_factor),
380
5.24k
                   (JDIMENSION)compptr->v_samp_factor);
381
5.24k
  }
382
383
1.78k
  if (need_full_buffer) {
384
1.57k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.57k
    int access_rows;
387
388
6.30k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
4.72k
         ci++, compptr++) {
390
4.72k
      access_rows = compptr->v_samp_factor;
391
4.72k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
4.72k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
4.72k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
4.72k
                               (long)compptr->h_samp_factor),
395
4.72k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
4.72k
                               (long)compptr->v_samp_factor),
397
4.72k
         (JDIMENSION)access_rows);
398
4.72k
    }
399
1.57k
    diff->pub.consume_data = consume_data;
400
1.57k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.57k
  } else {
405
204
    diff->pub.consume_data = dummy_consume_data;
406
204
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
204
  }
409
1.78k
}
j16init_d_diff_controller
Line
Count
Source
348
1.80k
{
349
1.80k
  my_diff_ptr diff;
350
1.80k
  int ci;
351
1.80k
  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
1.80k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.80k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.80k
  diff = (my_diff_ptr)
362
1.80k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.80k
                                sizeof(my_diff_controller));
364
1.80k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.80k
  diff->pub.start_input_pass = start_input_pass;
366
1.80k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
7.16k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
5.35k
       ci++, compptr++) {
371
5.35k
    diff->diff_buf[ci] =
372
5.35k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
5.35k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
5.35k
                                         (long)compptr->h_samp_factor),
375
5.35k
                   (JDIMENSION)compptr->v_samp_factor);
376
5.35k
    diff->undiff_buf[ci] =
377
5.35k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
5.35k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
5.35k
                                         (long)compptr->h_samp_factor),
380
5.35k
                   (JDIMENSION)compptr->v_samp_factor);
381
5.35k
  }
382
383
1.80k
  if (need_full_buffer) {
384
1.56k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.56k
    int access_rows;
387
388
6.24k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
4.68k
         ci++, compptr++) {
390
4.68k
      access_rows = compptr->v_samp_factor;
391
4.68k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
4.68k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
4.68k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
4.68k
                               (long)compptr->h_samp_factor),
395
4.68k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
4.68k
                               (long)compptr->v_samp_factor),
397
4.68k
         (JDIMENSION)access_rows);
398
4.68k
    }
399
1.56k
    diff->pub.consume_data = consume_data;
400
1.56k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.56k
  } else {
405
241
    diff->pub.consume_data = dummy_consume_data;
406
241
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
241
  }
409
1.80k
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */