Coverage Report

Created: 2025-08-29 06:39

/src/libjpeg-turbo.main/src/jddiffct.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * jddiffct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1997, Thomas G. Lane.
6
 * Lossless JPEG Modifications:
7
 * Copyright (C) 1999, Ken Murchison.
8
 * libjpeg-turbo Modifications:
9
 * Copyright (C) 2022, 2024, D. R. Commander.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the [un]difference buffer controller for decompression.
14
 * This controller is the top level of the lossless JPEG decompressor proper.
15
 * The difference buffer lies between the entropy decoding and
16
 * prediction/undifferencing steps.  The undifference buffer lies between the
17
 * prediction/undifferencing and scaling steps.
18
 *
19
 * In buffered-image mode, this controller is the interface between
20
 * input-oriented processing and output-oriented processing.
21
 */
22
23
#define JPEG_INTERNALS
24
#include "jinclude.h"
25
#include "jpeglib.h"
26
#include "jlossls.h"            /* Private declarations for lossless codec */
27
28
29
#ifdef D_LOSSLESS_SUPPORTED
30
31
/* Private buffer controller object */
32
33
typedef struct {
34
  struct jpeg_d_coef_controller pub; /* public fields */
35
36
  /* These variables keep track of the current location of the input side. */
37
  /* cinfo->input_iMCU_row is also used for this. */
38
  JDIMENSION MCU_ctr;           /* counts MCUs processed in current row */
39
  unsigned int restart_rows_to_go;      /* MCU rows left in this restart
40
                                           interval */
41
  unsigned int MCU_vert_offset;         /* counts MCU rows within iMCU row */
42
  unsigned int MCU_rows_per_iMCU_row;   /* number of such rows needed */
43
44
  /* The output side's location is represented by cinfo->output_iMCU_row. */
45
46
  JDIFFARRAY diff_buf[MAX_COMPONENTS];  /* iMCU row of differences */
47
  JDIFFARRAY undiff_buf[MAX_COMPONENTS]; /* iMCU row of undiff'd samples */
48
49
#ifdef D_MULTISCAN_FILES_SUPPORTED
50
  /* In multi-pass modes, we need a virtual sample array for each component. */
51
  jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
52
#endif
53
} my_diff_controller;
54
55
typedef my_diff_controller *my_diff_ptr;
56
57
/* Forward declarations */
58
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
59
#ifdef D_MULTISCAN_FILES_SUPPORTED
60
METHODDEF(int) output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
61
#endif
62
63
64
LOCAL(void)
65
start_iMCU_row(j_decompress_ptr cinfo)
66
/* Reset within-iMCU-row counters for a new row (input side) */
67
61.2M
{
68
61.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
61.2M
  if (cinfo->comps_in_scan > 1) {
75
29.8M
    diff->MCU_rows_per_iMCU_row = 1;
76
31.3M
  } else {
77
31.3M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
31.3M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
5.85k
    else
80
5.85k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
31.3M
  }
82
83
61.2M
  diff->MCU_ctr = 0;
84
61.2M
  diff->MCU_vert_offset = 0;
85
61.2M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
10.2M
{
68
10.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
10.2M
  if (cinfo->comps_in_scan > 1) {
75
2.81M
    diff->MCU_rows_per_iMCU_row = 1;
76
7.47M
  } else {
77
7.47M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
7.47M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
2.18k
    else
80
2.18k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
7.47M
  }
82
83
10.2M
  diff->MCU_ctr = 0;
84
10.2M
  diff->MCU_vert_offset = 0;
85
10.2M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
13.2M
{
68
13.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
13.2M
  if (cinfo->comps_in_scan > 1) {
75
7.06M
    diff->MCU_rows_per_iMCU_row = 1;
76
7.06M
  } else {
77
6.18M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
6.18M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.82k
    else
80
1.82k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
6.18M
  }
82
83
13.2M
  diff->MCU_ctr = 0;
84
13.2M
  diff->MCU_vert_offset = 0;
85
13.2M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
37.6M
{
68
37.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
37.6M
  if (cinfo->comps_in_scan > 1) {
75
19.9M
    diff->MCU_rows_per_iMCU_row = 1;
76
19.9M
  } else {
77
17.7M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
17.7M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.85k
    else
80
1.85k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
17.7M
  }
82
83
37.6M
  diff->MCU_ctr = 0;
84
37.6M
  diff->MCU_vert_offset = 0;
85
37.6M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
9.50k
{
95
9.50k
  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
9.50k
  (*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
9.50k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
81
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
9.50k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
9.50k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
9.50k
  cinfo->input_iMCU_row = 0;
115
9.50k
  start_iMCU_row(cinfo);
116
9.50k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
3.39k
{
95
3.39k
  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
3.39k
  (*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
3.39k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
29
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
3.39k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
3.39k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
3.39k
  cinfo->input_iMCU_row = 0;
115
3.39k
  start_iMCU_row(cinfo);
116
3.39k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
3.06k
{
95
3.06k
  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
3.06k
  (*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
3.06k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
23
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
3.06k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
3.06k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
3.06k
  cinfo->input_iMCU_row = 0;
115
3.06k
  start_iMCU_row(cinfo);
116
3.06k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
3.05k
{
95
3.05k
  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
3.05k
  (*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
3.05k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
29
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
3.05k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
3.05k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
3.05k
  cinfo->input_iMCU_row = 0;
115
3.05k
  start_iMCU_row(cinfo);
116
3.05k
}
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
9.11M
{
127
9.11M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
9.11M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
9.11M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
9.11M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
9.11M
  return TRUE;
138
9.11M
}
jddiffct-8.c:process_restart
Line
Count
Source
126
47.8k
{
127
47.8k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
47.8k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
47.8k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
47.8k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
47.8k
  return TRUE;
138
47.8k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
5.49M
{
127
5.49M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
5.49M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
5.49M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
5.49M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
5.49M
  return TRUE;
138
5.49M
}
jddiffct-16.c:process_restart
Line
Count
Source
126
3.57M
{
127
3.57M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
3.57M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
3.57M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
3.57M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
3.57M
  return TRUE;
138
3.57M
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
2.14k
{
148
2.14k
  cinfo->output_iMCU_row = 0;
149
2.14k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
676
{
148
676
  cinfo->output_iMCU_row = 0;
149
676
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
720
{
148
720
  cinfo->output_iMCU_row = 0;
149
720
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
745
{
148
745
  cinfo->output_iMCU_row = 0;
149
745
}
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
61.2M
{
165
61.2M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
61.2M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
61.2M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
61.2M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
61.2M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
61.2M
  int ci, compi, row, prev_row;
171
61.2M
  unsigned int yoffset;
172
61.2M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
132M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
71.0M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
71.0M
    if (cinfo->restart_interval) {
180
28.6M
      if (diff->restart_rows_to_go == 0)
181
9.11M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
28.6M
    }
184
185
71.0M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
71.0M
    MCU_count =
188
71.0M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
71.0M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
71.0M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
71.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
71.0M
    if (cinfo->restart_interval)
200
28.6M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
71.0M
    diff->MCU_ctr = 0;
204
71.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
152M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
91.6M
    compptr = cinfo->cur_comp_info[ci];
213
91.6M
    compi = compptr->component_index;
214
91.6M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
196M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
196M
                compptr->last_row_height : compptr->v_samp_factor);
217
105M
         prev_row = row, row++) {
218
105M
      (*losslessd->predict_undifference[compi])
219
105M
        (cinfo, compi, diff->diff_buf[compi][row],
220
105M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
105M
          compptr->width_in_blocks);
222
105M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
105M
                                  output_buf[compi][row],
224
105M
                                  compptr->width_in_blocks);
225
105M
    }
226
91.6M
  }
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.2M
  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.17k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
9.17k
  return JPEG_SCAN_COMPLETED;
241
61.2M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
10.2M
{
165
10.2M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
10.2M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
10.2M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
10.2M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
10.2M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
10.2M
  int ci, compi, row, prev_row;
171
10.2M
  unsigned int yoffset;
172
10.2M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
23.2M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
12.9M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
12.9M
    if (cinfo->restart_interval) {
180
2.34M
      if (diff->restart_rows_to_go == 0)
181
47.8k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
2.34M
    }
184
185
12.9M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
12.9M
    MCU_count =
188
12.9M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
12.9M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
12.9M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
12.9M
    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
12.9M
    if (cinfo->restart_interval)
200
2.34M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
12.9M
    diff->MCU_ctr = 0;
204
12.9M
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
23.5M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
13.2M
    compptr = cinfo->cur_comp_info[ci];
213
13.2M
    compi = compptr->component_index;
214
13.2M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
30.4M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
30.4M
                compptr->last_row_height : compptr->v_samp_factor);
217
17.1M
         prev_row = row, row++) {
218
17.1M
      (*losslessd->predict_undifference[compi])
219
17.1M
        (cinfo, compi, diff->diff_buf[compi][row],
220
17.1M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
17.1M
          compptr->width_in_blocks);
222
17.1M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
17.1M
                                  output_buf[compi][row],
224
17.1M
                                  compptr->width_in_blocks);
225
17.1M
    }
226
13.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
10.2M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
10.2M
    start_iMCU_row(cinfo);
236
10.2M
    return JPEG_ROW_COMPLETED;
237
10.2M
  }
238
  /* Completed the scan */
239
3.26k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
3.26k
  return JPEG_SCAN_COMPLETED;
241
10.2M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
13.2M
{
165
13.2M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
13.2M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
13.2M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
13.2M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
13.2M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
13.2M
  int ci, compi, row, prev_row;
171
13.2M
  unsigned int yoffset;
172
13.2M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
31.1M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
17.8M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
17.8M
    if (cinfo->restart_interval) {
180
7.15M
      if (diff->restart_rows_to_go == 0)
181
5.49M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
7.15M
    }
184
185
17.8M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
17.8M
    MCU_count =
188
17.8M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
17.8M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
17.8M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
17.8M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
17.8M
    if (cinfo->restart_interval)
200
7.15M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
17.8M
    diff->MCU_ctr = 0;
204
17.8M
  }
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
33.6M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
20.4M
    compptr = cinfo->cur_comp_info[ci];
213
20.4M
    compi = compptr->component_index;
214
20.4M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
46.5M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
46.4M
                compptr->last_row_height : compptr->v_samp_factor);
217
26.0M
         prev_row = row, row++) {
218
26.0M
      (*losslessd->predict_undifference[compi])
219
26.0M
        (cinfo, compi, diff->diff_buf[compi][row],
220
26.0M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
26.0M
          compptr->width_in_blocks);
222
26.0M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
26.0M
                                  output_buf[compi][row],
224
26.0M
                                  compptr->width_in_blocks);
225
26.0M
    }
226
20.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
13.2M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
13.2M
    start_iMCU_row(cinfo);
236
13.2M
    return JPEG_ROW_COMPLETED;
237
13.2M
  }
238
  /* Completed the scan */
239
2.96k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
2.96k
  return JPEG_SCAN_COMPLETED;
241
13.2M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
37.6M
{
165
37.6M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
37.6M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
37.6M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
37.6M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
37.6M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
37.6M
  int ci, compi, row, prev_row;
171
37.6M
  unsigned int yoffset;
172
37.6M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
77.9M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
40.2M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
40.2M
    if (cinfo->restart_interval) {
180
19.1M
      if (diff->restart_rows_to_go == 0)
181
3.57M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
19.1M
    }
184
185
40.2M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
40.2M
    MCU_count =
188
40.2M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
40.2M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
40.2M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
40.2M
    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
40.2M
    if (cinfo->restart_interval)
200
19.1M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
40.2M
    diff->MCU_ctr = 0;
204
40.2M
  }
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
95.6M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
57.9M
    compptr = cinfo->cur_comp_info[ci];
213
57.9M
    compi = compptr->component_index;
214
57.9M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
120M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
120M
                compptr->last_row_height : compptr->v_samp_factor);
217
62.1M
         prev_row = row, row++) {
218
62.1M
      (*losslessd->predict_undifference[compi])
219
62.1M
        (cinfo, compi, diff->diff_buf[compi][row],
220
62.1M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
62.1M
          compptr->width_in_blocks);
222
62.1M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
62.1M
                                  output_buf[compi][row],
224
62.1M
                                  compptr->width_in_blocks);
225
62.1M
    }
226
57.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
37.6M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
37.6M
    start_iMCU_row(cinfo);
236
37.6M
    return JPEG_ROW_COMPLETED;
237
37.6M
  }
238
  /* Completed the scan */
239
2.93k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
2.93k
  return JPEG_SCAN_COMPLETED;
241
37.6M
}
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
60.8M
{
267
60.8M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
60.8M
  int ci, compi;
269
60.8M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
60.8M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
151M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
90.5M
    compptr = cinfo->cur_comp_info[ci];
275
90.5M
    compi = compptr->component_index;
276
90.5M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
90.5M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
90.5M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
90.5M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
90.5M
  }
281
282
60.8M
  return decompress_data(cinfo, buffer);
283
60.8M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
10.1M
{
267
10.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
10.1M
  int ci, compi;
269
10.1M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
10.1M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
23.0M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
12.9M
    compptr = cinfo->cur_comp_info[ci];
275
12.9M
    compi = compptr->component_index;
276
12.9M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
12.9M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
12.9M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
12.9M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
12.9M
  }
281
282
10.1M
  return decompress_data(cinfo, buffer);
283
10.1M
}
jddiffct-12.c:consume_data
Line
Count
Source
266
13.1M
{
267
13.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
13.1M
  int ci, compi;
269
13.1M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
13.1M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
33.3M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
20.1M
    compptr = cinfo->cur_comp_info[ci];
275
20.1M
    compi = compptr->component_index;
276
20.1M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
20.1M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
20.1M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
20.1M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
20.1M
  }
281
282
13.1M
  return decompress_data(cinfo, buffer);
283
13.1M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
37.5M
{
267
37.5M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
37.5M
  int ci, compi;
269
37.5M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
37.5M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
94.9M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
57.4M
    compptr = cinfo->cur_comp_info[ci];
275
57.4M
    compi = compptr->component_index;
276
57.4M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
57.4M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
57.4M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
57.4M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
57.4M
  }
281
282
37.5M
  return decompress_data(cinfo, buffer);
283
37.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
194k
{
297
194k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
194k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
194k
  int ci, samp_rows, row;
300
194k
  _JSAMPARRAY buffer;
301
194k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
194k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
194k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
194k
          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
776k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
582k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
582k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
582k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
582k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
582k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
582k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
580k
      samp_rows = compptr->v_samp_factor;
322
1.20k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1.20k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1.20k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1.20k
    }
327
328
1.52M
    for (row = 0; row < samp_rows; row++) {
329
946k
      memcpy(output_buf[ci][row], buffer[row],
330
946k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
946k
    }
332
582k
  }
333
334
194k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
193k
    return JPEG_ROW_COMPLETED;
336
858
  return JPEG_SCAN_COMPLETED;
337
194k
}
jddiffct-8.c:output_data
Line
Count
Source
296
35.8k
{
297
35.8k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
35.8k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
35.8k
  int ci, samp_rows, row;
300
35.8k
  _JSAMPARRAY buffer;
301
35.8k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
35.8k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
35.8k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
35.8k
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
0
  }
310
311
  /* OK, output from the virtual arrays. */
312
143k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
107k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
107k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
107k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
107k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
107k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
107k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
106k
      samp_rows = compptr->v_samp_factor;
322
393
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
393
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
393
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
393
    }
327
328
228k
    for (row = 0; row < samp_rows; row++) {
329
121k
      memcpy(output_buf[ci][row], buffer[row],
330
121k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
121k
    }
332
107k
  }
333
334
35.8k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
35.5k
    return JPEG_ROW_COMPLETED;
336
277
  return JPEG_SCAN_COMPLETED;
337
35.8k
}
jddiffct-12.c:output_data
Line
Count
Source
296
70.4k
{
297
70.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
70.4k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
70.4k
  int ci, samp_rows, row;
300
70.4k
  _JSAMPARRAY buffer;
301
70.4k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
70.4k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
70.4k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
70.4k
          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
281k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
211k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
211k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
211k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
211k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
211k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
211k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
210k
      samp_rows = compptr->v_samp_factor;
322
334
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
334
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
334
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
334
    }
327
328
541k
    for (row = 0; row < samp_rows; row++) {
329
330k
      memcpy(output_buf[ci][row], buffer[row],
330
330k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
330k
    }
332
211k
  }
333
334
70.4k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
70.2k
    return JPEG_ROW_COMPLETED;
336
222
  return JPEG_SCAN_COMPLETED;
337
70.4k
}
jddiffct-16.c:output_data
Line
Count
Source
296
88.0k
{
297
88.0k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
88.0k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
88.0k
  int ci, samp_rows, row;
300
88.0k
  _JSAMPARRAY buffer;
301
88.0k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
88.0k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
88.0k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
88.0k
          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
351k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
263k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
263k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
263k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
263k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
263k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
263k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
263k
      samp_rows = compptr->v_samp_factor;
322
479
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
479
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
479
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
479
    }
327
328
758k
    for (row = 0; row < samp_rows; row++) {
329
494k
      memcpy(output_buf[ci][row], buffer[row],
330
494k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
494k
    }
332
263k
  }
333
334
88.0k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
87.7k
    return JPEG_ROW_COMPLETED;
336
359
  return JPEG_SCAN_COMPLETED;
337
88.0k
}
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
2.98k
{
349
2.98k
  my_diff_ptr diff;
350
2.98k
  int ci;
351
2.98k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
979
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
2.00k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
2.00k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
2.98k
  diff = (my_diff_ptr)
362
2.98k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
2.98k
                                sizeof(my_diff_controller));
364
2.98k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
2.98k
  diff->pub.start_input_pass = start_input_pass;
366
2.98k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
11.7k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
8.80k
       ci++, compptr++) {
371
8.80k
    diff->diff_buf[ci] =
372
8.80k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
8.80k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
8.80k
                                         (long)compptr->h_samp_factor),
375
8.80k
                   (JDIMENSION)compptr->v_samp_factor);
376
8.80k
    diff->undiff_buf[ci] =
377
8.80k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
8.80k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
8.80k
                                         (long)compptr->h_samp_factor),
380
8.80k
                   (JDIMENSION)compptr->v_samp_factor);
381
8.80k
  }
382
383
2.98k
  if (need_full_buffer) {
384
2.59k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
2.59k
    int access_rows;
387
388
10.3k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
7.77k
         ci++, compptr++) {
390
7.77k
      access_rows = compptr->v_samp_factor;
391
7.77k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
7.77k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
7.77k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
7.77k
                               (long)compptr->h_samp_factor),
395
7.77k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
7.77k
                               (long)compptr->v_samp_factor),
397
7.77k
         (JDIMENSION)access_rows);
398
7.77k
    }
399
2.59k
    diff->pub.consume_data = consume_data;
400
2.59k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
2.59k
  } else {
405
395
    diff->pub.consume_data = dummy_consume_data;
406
395
    diff->pub._decompress_data = decompress_data;
407
395
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
395
  }
409
2.98k
}
jinit_d_diff_controller
Line
Count
Source
348
979
{
349
979
  my_diff_ptr diff;
350
979
  int ci;
351
979
  jpeg_component_info *compptr;
352
353
979
#if BITS_IN_JSAMPLE == 8
354
979
  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
979
  diff = (my_diff_ptr)
362
979
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
979
                                sizeof(my_diff_controller));
364
979
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
979
  diff->pub.start_input_pass = start_input_pass;
366
979
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
3.84k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
2.86k
       ci++, compptr++) {
371
2.86k
    diff->diff_buf[ci] =
372
2.86k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
2.86k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
2.86k
                                         (long)compptr->h_samp_factor),
375
2.86k
                   (JDIMENSION)compptr->v_samp_factor);
376
2.86k
    diff->undiff_buf[ci] =
377
2.86k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
2.86k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
2.86k
                                         (long)compptr->h_samp_factor),
380
2.86k
                   (JDIMENSION)compptr->v_samp_factor);
381
2.86k
  }
382
383
979
  if (need_full_buffer) {
384
874
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
874
    int access_rows;
387
388
3.49k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
2.62k
         ci++, compptr++) {
390
2.62k
      access_rows = compptr->v_samp_factor;
391
2.62k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
2.62k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
2.62k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
2.62k
                               (long)compptr->h_samp_factor),
395
2.62k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
2.62k
                               (long)compptr->v_samp_factor),
397
2.62k
         (JDIMENSION)access_rows);
398
2.62k
    }
399
874
    diff->pub.consume_data = consume_data;
400
874
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
874
  } else {
405
105
    diff->pub.consume_data = dummy_consume_data;
406
105
    diff->pub._decompress_data = decompress_data;
407
105
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
105
  }
409
979
}
j12init_d_diff_controller
Line
Count
Source
348
986
{
349
986
  my_diff_ptr diff;
350
986
  int ci;
351
986
  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
986
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
986
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
986
  diff = (my_diff_ptr)
362
986
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
986
                                sizeof(my_diff_controller));
364
986
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
986
  diff->pub.start_input_pass = start_input_pass;
366
986
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
3.89k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
2.90k
       ci++, compptr++) {
371
2.90k
    diff->diff_buf[ci] =
372
2.90k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
2.90k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
2.90k
                                         (long)compptr->h_samp_factor),
375
2.90k
                   (JDIMENSION)compptr->v_samp_factor);
376
2.90k
    diff->undiff_buf[ci] =
377
2.90k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
2.90k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
2.90k
                                         (long)compptr->h_samp_factor),
380
2.90k
                   (JDIMENSION)compptr->v_samp_factor);
381
2.90k
  }
382
383
986
  if (need_full_buffer) {
384
842
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
842
    int access_rows;
387
388
3.36k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
2.52k
         ci++, compptr++) {
390
2.52k
      access_rows = compptr->v_samp_factor;
391
2.52k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
2.52k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
2.52k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
2.52k
                               (long)compptr->h_samp_factor),
395
2.52k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
2.52k
                               (long)compptr->v_samp_factor),
397
2.52k
         (JDIMENSION)access_rows);
398
2.52k
    }
399
842
    diff->pub.consume_data = consume_data;
400
842
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
842
  } else {
405
144
    diff->pub.consume_data = dummy_consume_data;
406
144
    diff->pub._decompress_data = decompress_data;
407
144
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
144
  }
409
986
}
j16init_d_diff_controller
Line
Count
Source
348
1.02k
{
349
1.02k
  my_diff_ptr diff;
350
1.02k
  int ci;
351
1.02k
  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.02k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.02k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.02k
  diff = (my_diff_ptr)
362
1.02k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.02k
                                sizeof(my_diff_controller));
364
1.02k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.02k
  diff->pub.start_input_pass = start_input_pass;
366
1.02k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
4.05k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
3.03k
       ci++, compptr++) {
371
3.03k
    diff->diff_buf[ci] =
372
3.03k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
3.03k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
3.03k
                                         (long)compptr->h_samp_factor),
375
3.03k
                   (JDIMENSION)compptr->v_samp_factor);
376
3.03k
    diff->undiff_buf[ci] =
377
3.03k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
3.03k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
3.03k
                                         (long)compptr->h_samp_factor),
380
3.03k
                   (JDIMENSION)compptr->v_samp_factor);
381
3.03k
  }
382
383
1.02k
  if (need_full_buffer) {
384
877
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
877
    int access_rows;
387
388
3.50k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
2.63k
         ci++, compptr++) {
390
2.63k
      access_rows = compptr->v_samp_factor;
391
2.63k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
2.63k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
2.63k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
2.63k
                               (long)compptr->h_samp_factor),
395
2.63k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
2.63k
                               (long)compptr->v_samp_factor),
397
2.63k
         (JDIMENSION)access_rows);
398
2.63k
    }
399
877
    diff->pub.consume_data = consume_data;
400
877
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
877
  } else {
405
146
    diff->pub.consume_data = dummy_consume_data;
406
146
    diff->pub._decompress_data = decompress_data;
407
146
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
146
  }
409
1.02k
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */