Coverage Report

Created: 2025-10-10 07:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.dev/src/jddiffct.c
Line
Count
Source
1
/*
2
 * jddiffct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1997, Thomas G. Lane.
6
 * Lossless JPEG Modifications:
7
 * Copyright (C) 1999, Ken Murchison.
8
 * libjpeg-turbo Modifications:
9
 * Copyright (C) 2022, 2024, D. R. Commander.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the [un]difference buffer controller for decompression.
14
 * This controller is the top level of the lossless JPEG decompressor proper.
15
 * The difference buffer lies between the entropy decoding and
16
 * prediction/undifferencing steps.  The undifference buffer lies between the
17
 * prediction/undifferencing and scaling steps.
18
 *
19
 * In buffered-image mode, this controller is the interface between
20
 * input-oriented processing and output-oriented processing.
21
 */
22
23
#define JPEG_INTERNALS
24
#include "jinclude.h"
25
#include "jpeglib.h"
26
#include "jlossls.h"            /* Private declarations for lossless codec */
27
28
29
#ifdef D_LOSSLESS_SUPPORTED
30
31
/* Private buffer controller object */
32
33
typedef struct {
34
  struct jpeg_d_coef_controller pub; /* public fields */
35
36
  /* These variables keep track of the current location of the input side. */
37
  /* cinfo->input_iMCU_row is also used for this. */
38
  JDIMENSION MCU_ctr;           /* counts MCUs processed in current row */
39
  unsigned int restart_rows_to_go;      /* MCU rows left in this restart
40
                                           interval */
41
  unsigned int MCU_vert_offset;         /* counts MCU rows within iMCU row */
42
  unsigned int MCU_rows_per_iMCU_row;   /* number of such rows needed */
43
44
  /* The output side's location is represented by cinfo->output_iMCU_row. */
45
46
  JDIFFARRAY diff_buf[MAX_COMPONENTS];  /* iMCU row of differences */
47
  JDIFFARRAY undiff_buf[MAX_COMPONENTS]; /* iMCU row of undiff'd samples */
48
49
#ifdef D_MULTISCAN_FILES_SUPPORTED
50
  /* In multi-pass modes, we need a virtual sample array for each component. */
51
  jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
52
#endif
53
} my_diff_controller;
54
55
typedef my_diff_controller *my_diff_ptr;
56
57
/* Forward declarations */
58
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
59
#ifdef D_MULTISCAN_FILES_SUPPORTED
60
METHODDEF(int) output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
61
#endif
62
63
64
LOCAL(void)
65
start_iMCU_row(j_decompress_ptr cinfo)
66
/* Reset within-iMCU-row counters for a new row (input side) */
67
12.4M
{
68
12.4M
  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
12.4M
  if (cinfo->comps_in_scan > 1) {
75
1.25M
    diff->MCU_rows_per_iMCU_row = 1;
76
11.1M
  } else {
77
11.1M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
11.1M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
2.46k
    else
80
2.46k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
11.1M
  }
82
83
12.4M
  diff->MCU_ctr = 0;
84
12.4M
  diff->MCU_vert_offset = 0;
85
12.4M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
1.10M
{
68
1.10M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
1.10M
  if (cinfo->comps_in_scan > 1) {
75
261k
    diff->MCU_rows_per_iMCU_row = 1;
76
843k
  } else {
77
843k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
843k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
671
    else
80
671
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
843k
  }
82
83
1.10M
  diff->MCU_ctr = 0;
84
1.10M
  diff->MCU_vert_offset = 0;
85
1.10M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
1.68M
{
68
1.68M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
1.68M
  if (cinfo->comps_in_scan > 1) {
75
475k
    diff->MCU_rows_per_iMCU_row = 1;
76
1.21M
  } else {
77
1.21M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
1.21M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
713
    else
80
713
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
1.21M
  }
82
83
1.68M
  diff->MCU_ctr = 0;
84
1.68M
  diff->MCU_vert_offset = 0;
85
1.68M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
9.61M
{
68
9.61M
  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
9.61M
  if (cinfo->comps_in_scan > 1) {
75
519k
    diff->MCU_rows_per_iMCU_row = 1;
76
9.09M
  } else {
77
9.09M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
9.09M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.07k
    else
80
1.07k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
9.09M
  }
82
83
9.61M
  diff->MCU_ctr = 0;
84
9.61M
  diff->MCU_vert_offset = 0;
85
9.61M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
3.97k
{
95
3.97k
  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.97k
  (*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.97k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
20
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
3.97k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
3.97k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
3.97k
  cinfo->input_iMCU_row = 0;
115
3.97k
  start_iMCU_row(cinfo);
116
3.97k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
1.17k
{
95
1.17k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
1.17k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
1.17k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
10
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.17k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.17k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.17k
  cinfo->input_iMCU_row = 0;
115
1.17k
  start_iMCU_row(cinfo);
116
1.17k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
1.18k
{
95
1.18k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
1.18k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
1.18k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.18k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.18k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.18k
  cinfo->input_iMCU_row = 0;
115
1.18k
  start_iMCU_row(cinfo);
116
1.18k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
1.61k
{
95
1.61k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
1.61k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
1.61k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
9
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.61k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.61k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.61k
  cinfo->input_iMCU_row = 0;
115
1.61k
  start_iMCU_row(cinfo);
116
1.61k
}
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
325k
{
127
325k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
325k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
325k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
325k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
325k
  return TRUE;
138
325k
}
jddiffct-8.c:process_restart
Line
Count
Source
126
27.4k
{
127
27.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
27.4k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
27.4k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
27.4k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
27.4k
  return TRUE;
138
27.4k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
161k
{
127
161k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
161k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
161k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
161k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
161k
  return TRUE;
138
161k
}
jddiffct-16.c:process_restart
Line
Count
Source
126
136k
{
127
136k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
136k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
136k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
136k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
136k
  return TRUE;
138
136k
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
1.00k
{
148
1.00k
  cinfo->output_iMCU_row = 0;
149
1.00k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
317
{
148
317
  cinfo->output_iMCU_row = 0;
149
317
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
356
{
148
356
  cinfo->output_iMCU_row = 0;
149
356
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
329
{
148
329
  cinfo->output_iMCU_row = 0;
149
329
}
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
12.4M
{
165
12.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
12.4M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
12.4M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
12.4M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
12.4M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
12.4M
  int ci, compi, row, prev_row;
171
12.4M
  unsigned int yoffset;
172
12.4M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
28.5M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
16.1M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
16.1M
    if (cinfo->restart_interval) {
180
2.13M
      if (diff->restart_rows_to_go == 0)
181
325k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
2.13M
    }
184
185
16.1M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
16.1M
    MCU_count =
188
16.1M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
16.1M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
16.1M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
16.1M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
16.1M
    if (cinfo->restart_interval)
200
2.13M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
16.1M
    diff->MCU_ctr = 0;
204
16.1M
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
26.1M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
13.6M
    compptr = cinfo->cur_comp_info[ci];
213
13.6M
    compi = compptr->component_index;
214
13.6M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
32.9M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
32.9M
                compptr->last_row_height : compptr->v_samp_factor);
217
19.2M
         prev_row = row, row++) {
218
19.2M
      (*losslessd->predict_undifference[compi])
219
19.2M
        (cinfo, compi, diff->diff_buf[compi][row],
220
19.2M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
19.2M
          compptr->width_in_blocks);
222
19.2M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
19.2M
                                  output_buf[compi][row],
224
19.2M
                                  compptr->width_in_blocks);
225
19.2M
    }
226
13.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
12.4M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
12.4M
    start_iMCU_row(cinfo);
236
12.4M
    return JPEG_ROW_COMPLETED;
237
12.4M
  }
238
  /* Completed the scan */
239
3.85k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
3.85k
  return JPEG_SCAN_COMPLETED;
241
12.4M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
1.10M
{
165
1.10M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
1.10M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
1.10M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
1.10M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
1.10M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
1.10M
  int ci, compi, row, prev_row;
171
1.10M
  unsigned int yoffset;
172
1.10M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
3.20M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
2.10M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
2.10M
    if (cinfo->restart_interval) {
180
131k
      if (diff->restart_rows_to_go == 0)
181
27.4k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
131k
    }
184
185
2.10M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
2.10M
    MCU_count =
188
2.10M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
2.10M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
2.10M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
2.10M
    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
2.10M
    if (cinfo->restart_interval)
200
131k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
2.10M
    diff->MCU_ctr = 0;
204
2.10M
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
2.48M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
1.37M
    compptr = cinfo->cur_comp_info[ci];
213
1.37M
    compi = compptr->component_index;
214
1.37M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
4.28M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
4.27M
                compptr->last_row_height : compptr->v_samp_factor);
217
2.90M
         prev_row = row, row++) {
218
2.90M
      (*losslessd->predict_undifference[compi])
219
2.90M
        (cinfo, compi, diff->diff_buf[compi][row],
220
2.90M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
2.90M
          compptr->width_in_blocks);
222
2.90M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
2.90M
                                  output_buf[compi][row],
224
2.90M
                                  compptr->width_in_blocks);
225
2.90M
    }
226
1.37M
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
1.10M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
1.10M
    start_iMCU_row(cinfo);
236
1.10M
    return JPEG_ROW_COMPLETED;
237
1.10M
  }
238
  /* Completed the scan */
239
1.13k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.13k
  return JPEG_SCAN_COMPLETED;
241
1.10M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
1.68M
{
165
1.68M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
1.68M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
1.68M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
1.68M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
1.68M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
1.68M
  int ci, compi, row, prev_row;
171
1.68M
  unsigned int yoffset;
172
1.68M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
4.81M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
3.12M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
3.12M
    if (cinfo->restart_interval) {
180
1.02M
      if (diff->restart_rows_to_go == 0)
181
161k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.02M
    }
184
185
3.12M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
3.12M
    MCU_count =
188
3.12M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
3.12M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
3.12M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
3.12M
    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
3.12M
    if (cinfo->restart_interval)
200
1.02M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
3.12M
    diff->MCU_ctr = 0;
204
3.12M
  }
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
3.85M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
2.16M
    compptr = cinfo->cur_comp_info[ci];
213
2.16M
    compi = compptr->component_index;
214
2.16M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
6.51M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
6.51M
                compptr->last_row_height : compptr->v_samp_factor);
217
4.35M
         prev_row = row, row++) {
218
4.35M
      (*losslessd->predict_undifference[compi])
219
4.35M
        (cinfo, compi, diff->diff_buf[compi][row],
220
4.35M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
4.35M
          compptr->width_in_blocks);
222
4.35M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
4.35M
                                  output_buf[compi][row],
224
4.35M
                                  compptr->width_in_blocks);
225
4.35M
    }
226
2.16M
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
1.68M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
1.68M
    start_iMCU_row(cinfo);
236
1.68M
    return JPEG_ROW_COMPLETED;
237
1.68M
  }
238
  /* Completed the scan */
239
1.15k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.15k
  return JPEG_SCAN_COMPLETED;
241
1.68M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
9.61M
{
165
9.61M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
9.61M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
9.61M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
9.61M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
9.61M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
9.61M
  int ci, compi, row, prev_row;
171
9.61M
  unsigned int yoffset;
172
9.61M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
20.4M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
10.8M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
10.8M
    if (cinfo->restart_interval) {
180
971k
      if (diff->restart_rows_to_go == 0)
181
136k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
971k
    }
184
185
10.8M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
10.8M
    MCU_count =
188
10.8M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
10.8M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
10.8M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
10.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
10.8M
    if (cinfo->restart_interval)
200
971k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
10.8M
    diff->MCU_ctr = 0;
204
10.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
19.7M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
10.1M
    compptr = cinfo->cur_comp_info[ci];
213
10.1M
    compi = compptr->component_index;
214
10.1M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
22.1M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
22.1M
                compptr->last_row_height : compptr->v_samp_factor);
217
11.9M
         prev_row = row, row++) {
218
11.9M
      (*losslessd->predict_undifference[compi])
219
11.9M
        (cinfo, compi, diff->diff_buf[compi][row],
220
11.9M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
11.9M
          compptr->width_in_blocks);
222
11.9M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
11.9M
                                  output_buf[compi][row],
224
11.9M
                                  compptr->width_in_blocks);
225
11.9M
    }
226
10.1M
  }
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
9.61M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
9.61M
    start_iMCU_row(cinfo);
236
9.61M
    return JPEG_ROW_COMPLETED;
237
9.61M
  }
238
  /* Completed the scan */
239
1.57k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.57k
  return JPEG_SCAN_COMPLETED;
241
9.61M
}
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
12.3M
{
267
12.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
12.3M
  int ci, compi;
269
12.3M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
12.3M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
26.0M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
13.6M
    compptr = cinfo->cur_comp_info[ci];
275
13.6M
    compi = compptr->component_index;
276
13.6M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
13.6M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
13.6M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
13.6M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
13.6M
  }
281
282
12.3M
  return decompress_data(cinfo, buffer);
283
12.3M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
1.09M
{
267
1.09M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
1.09M
  int ci, compi;
269
1.09M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
1.09M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
2.45M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
1.35M
    compptr = cinfo->cur_comp_info[ci];
275
1.35M
    compi = compptr->component_index;
276
1.35M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
1.35M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
1.35M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
1.35M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
1.35M
  }
281
282
1.09M
  return decompress_data(cinfo, buffer);
283
1.09M
}
jddiffct-12.c:consume_data
Line
Count
Source
266
1.68M
{
267
1.68M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
1.68M
  int ci, compi;
269
1.68M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
1.68M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
3.85M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
2.16M
    compptr = cinfo->cur_comp_info[ci];
275
2.16M
    compi = compptr->component_index;
276
2.16M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
2.16M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
2.16M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
2.16M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
2.16M
  }
281
282
1.68M
  return decompress_data(cinfo, buffer);
283
1.68M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
9.60M
{
267
9.60M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
9.60M
  int ci, compi;
269
9.60M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
9.60M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
19.7M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
10.1M
    compptr = cinfo->cur_comp_info[ci];
275
10.1M
    compi = compptr->component_index;
276
10.1M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
10.1M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
10.1M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
10.1M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
10.1M
  }
281
282
9.60M
  return decompress_data(cinfo, buffer);
283
9.60M
}
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
510k
{
297
510k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
510k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
510k
  int ci, samp_rows, row;
300
510k
  _JSAMPARRAY buffer;
301
510k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
510k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
510k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
510k
          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.03M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
1.52M
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
1.52M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
1.52M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
1.52M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
1.52M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
1.52M
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1.52M
      samp_rows = compptr->v_samp_factor;
322
1.06k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1.06k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1.06k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1.06k
    }
327
328
4.02M
    for (row = 0; row < samp_rows; row++) {
329
2.49M
      memcpy(output_buf[ci][row], buffer[row],
330
2.49M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
2.49M
    }
332
1.52M
  }
333
334
510k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
509k
    return JPEG_ROW_COMPLETED;
336
797
  return JPEG_SCAN_COMPLETED;
337
510k
}
jddiffct-8.c:output_data
Line
Count
Source
296
87.1k
{
297
87.1k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
87.1k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
87.1k
  int ci, samp_rows, row;
300
87.1k
  _JSAMPARRAY buffer;
301
87.1k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
87.1k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
87.1k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
87.1k
          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
348k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
261k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
261k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
261k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
261k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
261k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
261k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
260k
      samp_rows = compptr->v_samp_factor;
322
310
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
310
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
310
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
310
    }
327
328
782k
    for (row = 0; row < samp_rows; row++) {
329
521k
      memcpy(output_buf[ci][row], buffer[row],
330
521k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
521k
    }
332
261k
  }
333
334
87.1k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
86.9k
    return JPEG_ROW_COMPLETED;
336
242
  return JPEG_SCAN_COMPLETED;
337
87.1k
}
jddiffct-12.c:output_data
Line
Count
Source
296
231k
{
297
231k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
231k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
231k
  int ci, samp_rows, row;
300
231k
  _JSAMPARRAY buffer;
301
231k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
231k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
231k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
231k
          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
927k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
695k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
695k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
695k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
695k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
695k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
695k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
695k
      samp_rows = compptr->v_samp_factor;
322
391
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
391
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
391
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
391
    }
327
328
1.82M
    for (row = 0; row < samp_rows; row++) {
329
1.13M
      memcpy(output_buf[ci][row], buffer[row],
330
1.13M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1.13M
    }
332
695k
  }
333
334
231k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
231k
    return JPEG_ROW_COMPLETED;
336
287
  return JPEG_SCAN_COMPLETED;
337
231k
}
jddiffct-16.c:output_data
Line
Count
Source
296
191k
{
297
191k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
191k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
191k
  int ci, samp_rows, row;
300
191k
  _JSAMPARRAY buffer;
301
191k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
191k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
191k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
191k
          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
764k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
573k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
573k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
573k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
573k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
573k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
573k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
572k
      samp_rows = compptr->v_samp_factor;
322
365
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
365
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
365
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
365
    }
327
328
1.41M
    for (row = 0; row < samp_rows; row++) {
329
840k
      memcpy(output_buf[ci][row], buffer[row],
330
840k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
840k
    }
332
573k
  }
333
334
191k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
190k
    return JPEG_ROW_COMPLETED;
336
268
  return JPEG_SCAN_COMPLETED;
337
191k
}
338
339
#endif /* D_MULTISCAN_FILES_SUPPORTED */
340
341
342
/*
343
 * Initialize difference buffer controller.
344
 */
345
346
GLOBAL(void)
347
_jinit_d_diff_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
348
1.32k
{
349
1.32k
  my_diff_ptr diff;
350
1.32k
  int ci;
351
1.32k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
425
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
899
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
899
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.32k
  diff = (my_diff_ptr)
362
1.32k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.32k
                                sizeof(my_diff_controller));
364
1.32k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.32k
  diff->pub.start_input_pass = start_input_pass;
366
1.32k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
5.29k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
3.97k
       ci++, compptr++) {
371
3.97k
    diff->diff_buf[ci] =
372
3.97k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
3.97k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
3.97k
                                         (long)compptr->h_samp_factor),
375
3.97k
                   (JDIMENSION)compptr->v_samp_factor);
376
3.97k
    diff->undiff_buf[ci] =
377
3.97k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
3.97k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
3.97k
                                         (long)compptr->h_samp_factor),
380
3.97k
                   (JDIMENSION)compptr->v_samp_factor);
381
3.97k
  }
382
383
1.32k
  if (need_full_buffer) {
384
1.17k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.17k
    int access_rows;
387
388
4.71k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.53k
         ci++, compptr++) {
390
3.53k
      access_rows = compptr->v_samp_factor;
391
3.53k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.53k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.53k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.53k
                               (long)compptr->h_samp_factor),
395
3.53k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.53k
                               (long)compptr->v_samp_factor),
397
3.53k
         (JDIMENSION)access_rows);
398
3.53k
    }
399
1.17k
    diff->pub.consume_data = consume_data;
400
1.17k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.17k
  } else {
405
145
    diff->pub.consume_data = dummy_consume_data;
406
145
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
145
  }
409
1.32k
}
jinit_d_diff_controller
Line
Count
Source
348
425
{
349
425
  my_diff_ptr diff;
350
425
  int ci;
351
425
  jpeg_component_info *compptr;
352
353
425
#if BITS_IN_JSAMPLE == 8
354
425
  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
425
  diff = (my_diff_ptr)
362
425
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
425
                                sizeof(my_diff_controller));
364
425
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
425
  diff->pub.start_input_pass = start_input_pass;
366
425
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.70k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.27k
       ci++, compptr++) {
371
1.27k
    diff->diff_buf[ci] =
372
1.27k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.27k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.27k
                                         (long)compptr->h_samp_factor),
375
1.27k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.27k
    diff->undiff_buf[ci] =
377
1.27k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.27k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.27k
                                         (long)compptr->h_samp_factor),
380
1.27k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.27k
  }
382
383
425
  if (need_full_buffer) {
384
388
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
388
    int access_rows;
387
388
1.55k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.16k
         ci++, compptr++) {
390
1.16k
      access_rows = compptr->v_samp_factor;
391
1.16k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.16k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.16k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.16k
                               (long)compptr->h_samp_factor),
395
1.16k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.16k
                               (long)compptr->v_samp_factor),
397
1.16k
         (JDIMENSION)access_rows);
398
1.16k
    }
399
388
    diff->pub.consume_data = consume_data;
400
388
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
388
  } else {
405
37
    diff->pub.consume_data = dummy_consume_data;
406
37
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
37
  }
409
425
}
j12init_d_diff_controller
Line
Count
Source
348
446
{
349
446
  my_diff_ptr diff;
350
446
  int ci;
351
446
  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
446
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
446
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
446
  diff = (my_diff_ptr)
362
446
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
446
                                sizeof(my_diff_controller));
364
446
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
446
  diff->pub.start_input_pass = start_input_pass;
366
446
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.78k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.33k
       ci++, compptr++) {
371
1.33k
    diff->diff_buf[ci] =
372
1.33k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.33k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.33k
                                         (long)compptr->h_samp_factor),
375
1.33k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.33k
    diff->undiff_buf[ci] =
377
1.33k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.33k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.33k
                                         (long)compptr->h_samp_factor),
380
1.33k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.33k
  }
382
383
446
  if (need_full_buffer) {
384
406
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
406
    int access_rows;
387
388
1.62k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.21k
         ci++, compptr++) {
390
1.21k
      access_rows = compptr->v_samp_factor;
391
1.21k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.21k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.21k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.21k
                               (long)compptr->h_samp_factor),
395
1.21k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.21k
                               (long)compptr->v_samp_factor),
397
1.21k
         (JDIMENSION)access_rows);
398
1.21k
    }
399
406
    diff->pub.consume_data = consume_data;
400
406
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
406
  } else {
405
40
    diff->pub.consume_data = dummy_consume_data;
406
40
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
40
  }
409
446
}
j16init_d_diff_controller
Line
Count
Source
348
453
{
349
453
  my_diff_ptr diff;
350
453
  int ci;
351
453
  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
453
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
453
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
453
  diff = (my_diff_ptr)
362
453
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
453
                                sizeof(my_diff_controller));
364
453
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
453
  diff->pub.start_input_pass = start_input_pass;
366
453
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.81k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.35k
       ci++, compptr++) {
371
1.35k
    diff->diff_buf[ci] =
372
1.35k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.35k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.35k
                                         (long)compptr->h_samp_factor),
375
1.35k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.35k
    diff->undiff_buf[ci] =
377
1.35k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.35k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.35k
                                         (long)compptr->h_samp_factor),
380
1.35k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.35k
  }
382
383
453
  if (need_full_buffer) {
384
385
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
385
    int access_rows;
387
388
1.54k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.15k
         ci++, compptr++) {
390
1.15k
      access_rows = compptr->v_samp_factor;
391
1.15k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.15k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.15k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.15k
                               (long)compptr->h_samp_factor),
395
1.15k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.15k
                               (long)compptr->v_samp_factor),
397
1.15k
         (JDIMENSION)access_rows);
398
1.15k
    }
399
385
    diff->pub.consume_data = consume_data;
400
385
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
385
  } else {
405
68
    diff->pub.consume_data = dummy_consume_data;
406
68
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
68
  }
409
453
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */