Coverage Report

Created: 2026-07-30 07:40

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/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
180M
{
68
180M
  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
180M
  if (cinfo->comps_in_scan > 1) {
75
37.3M
    diff->MCU_rows_per_iMCU_row = 1;
76
142M
  } else {
77
142M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
142M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
26.9k
    else
80
26.9k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
142M
  }
82
83
180M
  diff->MCU_ctr = 0;
84
180M
  diff->MCU_vert_offset = 0;
85
180M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
45.8M
{
68
45.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
45.8M
  if (cinfo->comps_in_scan > 1) {
75
9.39M
    diff->MCU_rows_per_iMCU_row = 1;
76
36.4M
  } else {
77
36.4M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
36.4M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
9.87k
    else
80
9.87k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
36.4M
  }
82
83
45.8M
  diff->MCU_ctr = 0;
84
45.8M
  diff->MCU_vert_offset = 0;
85
45.8M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
61.3M
{
68
61.3M
  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
61.3M
  if (cinfo->comps_in_scan > 1) {
75
11.6M
    diff->MCU_rows_per_iMCU_row = 1;
76
49.7M
  } else {
77
49.7M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
49.6M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
7.29k
    else
80
7.29k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
49.7M
  }
82
83
61.3M
  diff->MCU_ctr = 0;
84
61.3M
  diff->MCU_vert_offset = 0;
85
61.3M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
73.0M
{
68
73.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
73.0M
  if (cinfo->comps_in_scan > 1) {
75
16.3M
    diff->MCU_rows_per_iMCU_row = 1;
76
56.7M
  } else {
77
56.7M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
56.6M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
9.81k
    else
80
9.81k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
56.7M
  }
82
83
73.0M
  diff->MCU_ctr = 0;
84
73.0M
  diff->MCU_vert_offset = 0;
85
73.0M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
38.7k
{
95
38.7k
  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
38.7k
  (*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
38.7k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
382
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
38.7k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
38.7k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
38.7k
  cinfo->input_iMCU_row = 0;
115
38.7k
  start_iMCU_row(cinfo);
116
38.7k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
14.2k
{
95
14.2k
  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
14.2k
  (*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
14.2k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
77
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
14.2k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
14.2k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
14.2k
  cinfo->input_iMCU_row = 0;
115
14.2k
  start_iMCU_row(cinfo);
116
14.2k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
10.3k
{
95
10.3k
  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
10.3k
  (*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
10.3k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
122
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
10.3k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
10.3k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
10.3k
  cinfo->input_iMCU_row = 0;
115
10.3k
  start_iMCU_row(cinfo);
116
10.3k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
14.0k
{
95
14.0k
  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
14.0k
  (*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
14.0k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
183
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
14.0k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
14.0k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
14.0k
  cinfo->input_iMCU_row = 0;
115
14.0k
  start_iMCU_row(cinfo);
116
14.0k
}
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
61.1M
{
127
61.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
61.1M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
61.1M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
61.1M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
61.1M
  return TRUE;
138
61.1M
}
jddiffct-8.c:process_restart
Line
Count
Source
126
8.06M
{
127
8.06M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
8.06M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
8.06M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
8.06M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
8.06M
  return TRUE;
138
8.06M
}
jddiffct-12.c:process_restart
Line
Count
Source
126
4.83M
{
127
4.83M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
4.83M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
4.83M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
4.83M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
4.83M
  return TRUE;
138
4.83M
}
jddiffct-16.c:process_restart
Line
Count
Source
126
48.2M
{
127
48.2M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
48.2M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
48.2M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
48.2M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
48.2M
  return TRUE;
138
48.2M
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
11.0k
{
148
11.0k
  cinfo->output_iMCU_row = 0;
149
11.0k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
4.52k
{
148
4.52k
  cinfo->output_iMCU_row = 0;
149
4.52k
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
3.20k
{
148
3.20k
  cinfo->output_iMCU_row = 0;
149
3.20k
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
3.33k
{
148
3.33k
  cinfo->output_iMCU_row = 0;
149
3.33k
}
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
180M
{
165
180M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
180M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
180M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
180M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
180M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
180M
  int ci, compi, row, prev_row;
171
180M
  unsigned int yoffset;
172
180M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
459M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
278M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
278M
    if (cinfo->restart_interval) {
180
100M
      if (diff->restart_rows_to_go == 0)
181
61.1M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
100M
    }
184
185
278M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
278M
    MCU_count =
188
278M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
278M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
278M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
278M
    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
278M
    if (cinfo->restart_interval)
200
100M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
278M
    diff->MCU_ctr = 0;
204
278M
  }
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
404M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
224M
    compptr = cinfo->cur_comp_info[ci];
213
224M
    compi = compptr->component_index;
214
224M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
577M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
577M
                compptr->last_row_height : compptr->v_samp_factor);
217
352M
         prev_row = row, row++) {
218
352M
      (*losslessd->predict_undifference[compi])
219
352M
        (cinfo, compi, diff->diff_buf[compi][row],
220
352M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
352M
          compptr->width_in_blocks);
222
352M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
352M
                                  output_buf[compi][row],
224
352M
                                  compptr->width_in_blocks);
225
352M
    }
226
224M
  }
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
180M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
180M
    start_iMCU_row(cinfo);
236
180M
    return JPEG_ROW_COMPLETED;
237
180M
  }
238
  /* Completed the scan */
239
36.7k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
36.7k
  return JPEG_SCAN_COMPLETED;
241
180M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
45.8M
{
165
45.8M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
45.8M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
45.8M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
45.8M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
45.8M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
45.8M
  int ci, compi, row, prev_row;
171
45.8M
  unsigned int yoffset;
172
45.8M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
115M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
69.5M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
69.5M
    if (cinfo->restart_interval) {
180
18.4M
      if (diff->restart_rows_to_go == 0)
181
8.06M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
18.4M
    }
184
185
69.5M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
69.5M
    MCU_count =
188
69.5M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
69.5M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
69.5M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
69.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
69.5M
    if (cinfo->restart_interval)
200
18.4M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
69.5M
    diff->MCU_ctr = 0;
204
69.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
105M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
59.5M
    compptr = cinfo->cur_comp_info[ci];
213
59.5M
    compi = compptr->component_index;
214
59.5M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
158M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
158M
                compptr->last_row_height : compptr->v_samp_factor);
217
98.9M
         prev_row = row, row++) {
218
98.9M
      (*losslessd->predict_undifference[compi])
219
98.9M
        (cinfo, compi, diff->diff_buf[compi][row],
220
98.9M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
98.9M
          compptr->width_in_blocks);
222
98.9M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
98.9M
                                  output_buf[compi][row],
224
98.9M
                                  compptr->width_in_blocks);
225
98.9M
    }
226
59.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
45.8M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
45.8M
    start_iMCU_row(cinfo);
236
45.8M
    return JPEG_ROW_COMPLETED;
237
45.8M
  }
238
  /* Completed the scan */
239
13.6k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
13.6k
  return JPEG_SCAN_COMPLETED;
241
45.8M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
61.3M
{
165
61.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
61.3M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
61.3M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
61.3M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
61.3M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
61.3M
  int ci, compi, row, prev_row;
171
61.3M
  unsigned int yoffset;
172
61.3M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
164M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
103M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
103M
    if (cinfo->restart_interval) {
180
25.6M
      if (diff->restart_rows_to_go == 0)
181
4.83M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
25.6M
    }
184
185
103M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
103M
    MCU_count =
188
103M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
103M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
103M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
103M
    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
103M
    if (cinfo->restart_interval)
200
25.6M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
103M
    diff->MCU_ctr = 0;
204
103M
  }
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
135M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
73.9M
    compptr = cinfo->cur_comp_info[ci];
213
73.9M
    compi = compptr->component_index;
214
73.9M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
194M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
194M
                compptr->last_row_height : compptr->v_samp_factor);
217
121M
         prev_row = row, row++) {
218
121M
      (*losslessd->predict_undifference[compi])
219
121M
        (cinfo, compi, diff->diff_buf[compi][row],
220
121M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
121M
          compptr->width_in_blocks);
222
121M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
121M
                                  output_buf[compi][row],
224
121M
                                  compptr->width_in_blocks);
225
121M
    }
226
73.9M
  }
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
61.3M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
61.2M
    start_iMCU_row(cinfo);
236
61.2M
    return JPEG_ROW_COMPLETED;
237
61.2M
  }
238
  /* Completed the scan */
239
9.81k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
9.81k
  return JPEG_SCAN_COMPLETED;
241
61.3M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
73.0M
{
165
73.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
73.0M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
73.0M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
73.0M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
73.0M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
73.0M
  int ci, compi, row, prev_row;
171
73.0M
  unsigned int yoffset;
172
73.0M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
179M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
106M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
106M
    if (cinfo->restart_interval) {
180
56.7M
      if (diff->restart_rows_to_go == 0)
181
48.2M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
56.7M
    }
184
185
106M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
106M
    MCU_count =
188
106M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
106M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
106M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
106M
    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
106M
    if (cinfo->restart_interval)
200
56.7M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
106M
    diff->MCU_ctr = 0;
204
106M
  }
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
164M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
91.0M
    compptr = cinfo->cur_comp_info[ci];
213
91.0M
    compi = compptr->component_index;
214
91.0M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
223M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
223M
                compptr->last_row_height : compptr->v_samp_factor);
217
132M
         prev_row = row, row++) {
218
132M
      (*losslessd->predict_undifference[compi])
219
132M
        (cinfo, compi, diff->diff_buf[compi][row],
220
132M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
132M
          compptr->width_in_blocks);
222
132M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
132M
                                  output_buf[compi][row],
224
132M
                                  compptr->width_in_blocks);
225
132M
    }
226
91.0M
  }
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
73.0M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
73.0M
    start_iMCU_row(cinfo);
236
73.0M
    return JPEG_ROW_COMPLETED;
237
73.0M
  }
238
  /* Completed the scan */
239
13.2k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
13.2k
  return JPEG_SCAN_COMPLETED;
241
73.0M
}
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
170M
{
267
170M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
170M
  int ci, compi;
269
170M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
170M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
380M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
210M
    compptr = cinfo->cur_comp_info[ci];
275
210M
    compi = compptr->component_index;
276
210M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
210M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
210M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
210M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
210M
  }
281
282
170M
  return decompress_data(cinfo, buffer);
283
170M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
42.0M
{
267
42.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
42.0M
  int ci, compi;
269
42.0M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
42.0M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
96.3M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
54.2M
    compptr = cinfo->cur_comp_info[ci];
275
54.2M
    compi = compptr->component_index;
276
54.2M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
54.2M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
54.2M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
54.2M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
54.2M
  }
281
282
42.0M
  return decompress_data(cinfo, buffer);
283
42.0M
}
jddiffct-12.c:consume_data
Line
Count
Source
266
58.3M
{
267
58.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
58.3M
  int ci, compi;
269
58.3M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
58.3M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
128M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
70.2M
    compptr = cinfo->cur_comp_info[ci];
275
70.2M
    compi = compptr->component_index;
276
70.2M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
70.2M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
70.2M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
70.2M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
70.2M
  }
281
282
58.3M
  return decompress_data(cinfo, buffer);
283
58.3M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
69.6M
{
267
69.6M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
69.6M
  int ci, compi;
269
69.6M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
69.6M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
155M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
86.2M
    compptr = cinfo->cur_comp_info[ci];
275
86.2M
    compi = compptr->component_index;
276
86.2M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
86.2M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
86.2M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
86.2M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
86.2M
  }
281
282
69.6M
  return decompress_data(cinfo, buffer);
283
69.6M
}
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
3.54M
{
297
3.54M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
3.54M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
3.54M
  int ci, samp_rows, row;
300
3.54M
  _JSAMPARRAY buffer;
301
3.54M
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
5.87M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
5.87M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
5.87M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
2.32M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
2.32M
  }
310
311
  /* OK, output from the virtual arrays. */
312
14.8M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
11.2M
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
11.2M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
11.2M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
11.2M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
11.2M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
11.2M
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
11.2M
      samp_rows = compptr->v_samp_factor;
322
6.08k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
6.08k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
6.08k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
6.08k
    }
327
328
32.1M
    for (row = 0; row < samp_rows; row++) {
329
20.8M
      memcpy(output_buf[ci][row], buffer[row],
330
20.8M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
20.8M
    }
332
11.2M
  }
333
334
3.54M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
3.54M
    return JPEG_ROW_COMPLETED;
336
2.81k
  return JPEG_SCAN_COMPLETED;
337
3.54M
}
jddiffct-8.c:output_data
Line
Count
Source
296
2.83M
{
297
2.83M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
2.83M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
2.83M
  int ci, samp_rows, row;
300
2.83M
  _JSAMPARRAY buffer;
301
2.83M
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
5.15M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
5.15M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
5.15M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
2.32M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
2.32M
  }
310
311
  /* OK, output from the virtual arrays. */
312
11.7M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
8.89M
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
8.89M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
8.89M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
8.89M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
8.89M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
8.89M
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
8.89M
      samp_rows = compptr->v_samp_factor;
322
4.45k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
4.45k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
4.45k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
4.45k
    }
327
328
26.1M
    for (row = 0; row < samp_rows; row++) {
329
17.2M
      memcpy(output_buf[ci][row], buffer[row],
330
17.2M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
17.2M
    }
332
8.89M
  }
333
334
2.83M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
2.83M
    return JPEG_ROW_COMPLETED;
336
1.79k
  return JPEG_SCAN_COMPLETED;
337
2.83M
}
jddiffct-12.c:output_data
Line
Count
Source
296
224k
{
297
224k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
224k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
224k
  int ci, samp_rows, row;
300
224k
  _JSAMPARRAY buffer;
301
224k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
224k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
224k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
224k
          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.00M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
775k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
775k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
775k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
775k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
775k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
775k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
775k
      samp_rows = compptr->v_samp_factor;
322
674
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
674
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
674
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
674
    }
327
328
1.71M
    for (row = 0; row < samp_rows; row++) {
329
940k
      memcpy(output_buf[ci][row], buffer[row],
330
940k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
940k
    }
332
775k
  }
333
334
224k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
224k
    return JPEG_ROW_COMPLETED;
336
386
  return JPEG_SCAN_COMPLETED;
337
224k
}
jddiffct-16.c:output_data
Line
Count
Source
296
492k
{
297
492k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
492k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
492k
  int ci, samp_rows, row;
300
492k
  _JSAMPARRAY buffer;
301
492k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
492k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
492k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
492k
          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.10M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
1.60M
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
1.60M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
1.60M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
1.60M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
1.60M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
1.60M
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1.60M
      samp_rows = compptr->v_samp_factor;
322
956
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
956
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
956
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
956
    }
327
328
4.21M
    for (row = 0; row < samp_rows; row++) {
329
2.60M
      memcpy(output_buf[ci][row], buffer[row],
330
2.60M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
2.60M
    }
332
1.60M
  }
333
334
492k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
491k
    return JPEG_ROW_COMPLETED;
336
629
  return JPEG_SCAN_COMPLETED;
337
492k
}
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
18.5k
{
349
18.5k
  my_diff_ptr diff;
350
18.5k
  int ci;
351
18.5k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
6.38k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
12.1k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
12.1k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
18.5k
  diff = (my_diff_ptr)
362
18.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
18.5k
                                sizeof(my_diff_controller));
364
18.5k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
18.5k
  diff->pub.start_input_pass = start_input_pass;
366
18.5k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
69.7k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
51.1k
       ci++, compptr++) {
371
51.1k
    diff->diff_buf[ci] =
372
51.1k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
51.1k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
51.1k
                                         (long)compptr->h_samp_factor),
375
51.1k
                   (JDIMENSION)compptr->v_samp_factor);
376
51.1k
    diff->undiff_buf[ci] =
377
51.1k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
51.1k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
51.1k
                                         (long)compptr->h_samp_factor),
380
51.1k
                   (JDIMENSION)compptr->v_samp_factor);
381
51.1k
  }
382
383
18.5k
  if (need_full_buffer) {
384
14.4k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
14.4k
    int access_rows;
387
388
58.2k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
43.8k
         ci++, compptr++) {
390
43.8k
      access_rows = compptr->v_samp_factor;
391
43.8k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
43.8k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
43.8k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
43.8k
                               (long)compptr->h_samp_factor),
395
43.8k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
43.8k
                               (long)compptr->v_samp_factor),
397
43.8k
         (JDIMENSION)access_rows);
398
43.8k
    }
399
14.4k
    diff->pub.consume_data = consume_data;
400
14.4k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
14.4k
  } else {
405
4.15k
    diff->pub.consume_data = dummy_consume_data;
406
4.15k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
4.15k
  }
409
18.5k
}
jinit_d_diff_controller
Line
Count
Source
348
6.38k
{
349
6.38k
  my_diff_ptr diff;
350
6.38k
  int ci;
351
6.38k
  jpeg_component_info *compptr;
352
353
6.38k
#if BITS_IN_JSAMPLE == 8
354
6.38k
  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
6.38k
  diff = (my_diff_ptr)
362
6.38k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
6.38k
                                sizeof(my_diff_controller));
364
6.38k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
6.38k
  diff->pub.start_input_pass = start_input_pass;
366
6.38k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
24.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
17.6k
       ci++, compptr++) {
371
17.6k
    diff->diff_buf[ci] =
372
17.6k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
17.6k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
17.6k
                                         (long)compptr->h_samp_factor),
375
17.6k
                   (JDIMENSION)compptr->v_samp_factor);
376
17.6k
    diff->undiff_buf[ci] =
377
17.6k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
17.6k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
17.6k
                                         (long)compptr->h_samp_factor),
380
17.6k
                   (JDIMENSION)compptr->v_samp_factor);
381
17.6k
  }
382
383
6.38k
  if (need_full_buffer) {
384
5.15k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
5.15k
    int access_rows;
387
388
20.7k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
15.6k
         ci++, compptr++) {
390
15.6k
      access_rows = compptr->v_samp_factor;
391
15.6k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
15.6k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
15.6k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
15.6k
                               (long)compptr->h_samp_factor),
395
15.6k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
15.6k
                               (long)compptr->v_samp_factor),
397
15.6k
         (JDIMENSION)access_rows);
398
15.6k
    }
399
5.15k
    diff->pub.consume_data = consume_data;
400
5.15k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
5.15k
  } else {
405
1.22k
    diff->pub.consume_data = dummy_consume_data;
406
1.22k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
1.22k
  }
409
6.38k
}
j12init_d_diff_controller
Line
Count
Source
348
5.82k
{
349
5.82k
  my_diff_ptr diff;
350
5.82k
  int ci;
351
5.82k
  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
5.82k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
5.82k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
5.82k
  diff = (my_diff_ptr)
362
5.82k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
5.82k
                                sizeof(my_diff_controller));
364
5.82k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
5.82k
  diff->pub.start_input_pass = start_input_pass;
366
5.82k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
21.5k
  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.82k
  if (need_full_buffer) {
384
4.23k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
4.23k
    int access_rows;
387
388
17.1k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
12.9k
         ci++, compptr++) {
390
12.9k
      access_rows = compptr->v_samp_factor;
391
12.9k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
12.9k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
12.9k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
12.9k
                               (long)compptr->h_samp_factor),
395
12.9k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
12.9k
                               (long)compptr->v_samp_factor),
397
12.9k
         (JDIMENSION)access_rows);
398
12.9k
    }
399
4.23k
    diff->pub.consume_data = consume_data;
400
4.23k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
4.23k
  } else {
405
1.58k
    diff->pub.consume_data = dummy_consume_data;
406
1.58k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
1.58k
  }
409
5.82k
}
j16init_d_diff_controller
Line
Count
Source
348
6.36k
{
349
6.36k
  my_diff_ptr diff;
350
6.36k
  int ci;
351
6.36k
  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
6.36k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
6.36k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
6.36k
  diff = (my_diff_ptr)
362
6.36k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
6.36k
                                sizeof(my_diff_controller));
364
6.36k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
6.36k
  diff->pub.start_input_pass = start_input_pass;
366
6.36k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
24.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
17.7k
       ci++, compptr++) {
371
17.7k
    diff->diff_buf[ci] =
372
17.7k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
17.7k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
17.7k
                                         (long)compptr->h_samp_factor),
375
17.7k
                   (JDIMENSION)compptr->v_samp_factor);
376
17.7k
    diff->undiff_buf[ci] =
377
17.7k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
17.7k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
17.7k
                                         (long)compptr->h_samp_factor),
380
17.7k
                   (JDIMENSION)compptr->v_samp_factor);
381
17.7k
  }
382
383
6.36k
  if (need_full_buffer) {
384
5.02k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
5.02k
    int access_rows;
387
388
20.2k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
15.2k
         ci++, compptr++) {
390
15.2k
      access_rows = compptr->v_samp_factor;
391
15.2k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
15.2k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
15.2k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
15.2k
                               (long)compptr->h_samp_factor),
395
15.2k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
15.2k
                               (long)compptr->v_samp_factor),
397
15.2k
         (JDIMENSION)access_rows);
398
15.2k
    }
399
5.02k
    diff->pub.consume_data = consume_data;
400
5.02k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
5.02k
  } else {
405
1.33k
    diff->pub.consume_data = dummy_consume_data;
406
1.33k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
1.33k
  }
409
6.36k
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */