Coverage Report

Created: 2025-10-10 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/src/jddiffct.c
Line
Count
Source
1
/*
2
 * jddiffct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1997, Thomas G. Lane.
6
 * Lossless JPEG Modifications:
7
 * Copyright (C) 1999, Ken Murchison.
8
 * libjpeg-turbo Modifications:
9
 * Copyright (C) 2022, 2024, D. R. Commander.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the [un]difference buffer controller for decompression.
14
 * This controller is the top level of the lossless JPEG decompressor proper.
15
 * The difference buffer lies between the entropy decoding and
16
 * prediction/undifferencing steps.  The undifference buffer lies between the
17
 * prediction/undifferencing and scaling steps.
18
 *
19
 * In buffered-image mode, this controller is the interface between
20
 * input-oriented processing and output-oriented processing.
21
 */
22
23
#define JPEG_INTERNALS
24
#include "jinclude.h"
25
#include "jpeglib.h"
26
#include "jlossls.h"            /* Private declarations for lossless codec */
27
28
29
#ifdef D_LOSSLESS_SUPPORTED
30
31
/* Private buffer controller object */
32
33
typedef struct {
34
  struct jpeg_d_coef_controller pub; /* public fields */
35
36
  /* These variables keep track of the current location of the input side. */
37
  /* cinfo->input_iMCU_row is also used for this. */
38
  JDIMENSION MCU_ctr;           /* counts MCUs processed in current row */
39
  unsigned int restart_rows_to_go;      /* MCU rows left in this restart
40
                                           interval */
41
  unsigned int MCU_vert_offset;         /* counts MCU rows within iMCU row */
42
  unsigned int MCU_rows_per_iMCU_row;   /* number of such rows needed */
43
44
  /* The output side's location is represented by cinfo->output_iMCU_row. */
45
46
  JDIFFARRAY diff_buf[MAX_COMPONENTS];  /* iMCU row of differences */
47
  JDIFFARRAY undiff_buf[MAX_COMPONENTS]; /* iMCU row of undiff'd samples */
48
49
#ifdef D_MULTISCAN_FILES_SUPPORTED
50
  /* In multi-pass modes, we need a virtual sample array for each component. */
51
  jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
52
#endif
53
} my_diff_controller;
54
55
typedef my_diff_controller *my_diff_ptr;
56
57
/* Forward declarations */
58
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
59
#ifdef D_MULTISCAN_FILES_SUPPORTED
60
METHODDEF(int) output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
61
#endif
62
63
64
LOCAL(void)
65
start_iMCU_row(j_decompress_ptr cinfo)
66
/* Reset within-iMCU-row counters for a new row (input side) */
67
27.6M
{
68
27.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
27.6M
  if (cinfo->comps_in_scan > 1) {
75
599k
    diff->MCU_rows_per_iMCU_row = 1;
76
27.0M
  } else {
77
27.0M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
27.0M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
3.65k
    else
80
3.65k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
27.0M
  }
82
83
27.6M
  diff->MCU_ctr = 0;
84
27.6M
  diff->MCU_vert_offset = 0;
85
27.6M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
1.05M
{
68
1.05M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
1.05M
  if (cinfo->comps_in_scan > 1) {
75
220k
    diff->MCU_rows_per_iMCU_row = 1;
76
836k
  } else {
77
836k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
834k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.29k
    else
80
1.29k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
836k
  }
82
83
1.05M
  diff->MCU_ctr = 0;
84
1.05M
  diff->MCU_vert_offset = 0;
85
1.05M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
5.73M
{
68
5.73M
  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
5.73M
  if (cinfo->comps_in_scan > 1) {
75
116k
    diff->MCU_rows_per_iMCU_row = 1;
76
5.61M
  } else {
77
5.61M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
5.61M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
966
    else
80
966
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
5.61M
  }
82
83
5.73M
  diff->MCU_ctr = 0;
84
5.73M
  diff->MCU_vert_offset = 0;
85
5.73M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
20.8M
{
68
20.8M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
20.8M
  if (cinfo->comps_in_scan > 1) {
75
262k
    diff->MCU_rows_per_iMCU_row = 1;
76
20.5M
  } else {
77
20.5M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
20.5M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.39k
    else
80
1.39k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
20.5M
  }
82
83
20.8M
  diff->MCU_ctr = 0;
84
20.8M
  diff->MCU_vert_offset = 0;
85
20.8M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
5.25k
{
95
5.25k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
5.25k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
5.25k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
19
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
5.25k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
5.25k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
5.25k
  cinfo->input_iMCU_row = 0;
115
5.25k
  start_iMCU_row(cinfo);
116
5.25k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
1.89k
{
95
1.89k
  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.89k
  (*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.89k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
7
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.89k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.89k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.89k
  cinfo->input_iMCU_row = 0;
115
1.89k
  start_iMCU_row(cinfo);
116
1.89k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
1.54k
{
95
1.54k
  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.54k
  (*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.54k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.54k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.54k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.54k
  cinfo->input_iMCU_row = 0;
115
1.54k
  start_iMCU_row(cinfo);
116
1.54k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
1.82k
{
95
1.82k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
1.82k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
1.82k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
11
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.82k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.82k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.82k
  cinfo->input_iMCU_row = 0;
115
1.82k
  start_iMCU_row(cinfo);
116
1.82k
}
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
90.4k
{
127
90.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
90.4k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
90.4k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
90.4k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
90.4k
  return TRUE;
138
90.4k
}
jddiffct-8.c:process_restart
Line
Count
Source
126
1.47k
{
127
1.47k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
1.47k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
1.47k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
1.47k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
1.47k
  return TRUE;
138
1.47k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
1.47k
{
127
1.47k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
1.47k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
1.47k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
1.47k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
1.47k
  return TRUE;
138
1.47k
}
jddiffct-16.c:process_restart
Line
Count
Source
126
87.4k
{
127
87.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
87.4k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
87.4k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
87.4k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
87.4k
  return TRUE;
138
87.4k
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
1.19k
{
148
1.19k
  cinfo->output_iMCU_row = 0;
149
1.19k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
339
{
148
339
  cinfo->output_iMCU_row = 0;
149
339
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
406
{
148
406
  cinfo->output_iMCU_row = 0;
149
406
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
452
{
148
452
  cinfo->output_iMCU_row = 0;
149
452
}
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
27.6M
{
165
27.6M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
27.6M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
27.6M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
27.6M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
27.6M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
27.6M
  int ci, compi, row, prev_row;
171
27.6M
  unsigned int yoffset;
172
27.6M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
62.4M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
34.7M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
34.7M
    if (cinfo->restart_interval) {
180
2.27M
      if (diff->restart_rows_to_go == 0)
181
90.4k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
2.27M
    }
184
185
34.7M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
34.7M
    MCU_count =
188
34.7M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
34.7M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
34.7M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
34.7M
    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
34.7M
    if (cinfo->restart_interval)
200
2.27M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
34.7M
    diff->MCU_ctr = 0;
204
34.7M
  }
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
56.3M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
28.7M
    compptr = cinfo->cur_comp_info[ci];
213
28.7M
    compi = compptr->component_index;
214
28.7M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
65.3M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
65.3M
                compptr->last_row_height : compptr->v_samp_factor);
217
36.5M
         prev_row = row, row++) {
218
36.5M
      (*losslessd->predict_undifference[compi])
219
36.5M
        (cinfo, compi, diff->diff_buf[compi][row],
220
36.5M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
36.5M
          compptr->width_in_blocks);
222
36.5M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
36.5M
                                  output_buf[compi][row],
224
36.5M
                                  compptr->width_in_blocks);
225
36.5M
    }
226
28.7M
  }
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
27.6M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
27.6M
    start_iMCU_row(cinfo);
236
27.6M
    return JPEG_ROW_COMPLETED;
237
27.6M
  }
238
  /* Completed the scan */
239
5.13k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
5.13k
  return JPEG_SCAN_COMPLETED;
241
27.6M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
1.05M
{
165
1.05M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
1.05M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
1.05M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
1.05M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
1.05M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
1.05M
  int ci, compi, row, prev_row;
171
1.05M
  unsigned int yoffset;
172
1.05M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
2.80M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
1.74M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
1.74M
    if (cinfo->restart_interval) {
180
248k
      if (diff->restart_rows_to_go == 0)
181
1.47k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
248k
    }
184
185
1.74M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
1.74M
    MCU_count =
188
1.74M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
1.74M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
1.74M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
1.74M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
1.74M
    if (cinfo->restart_interval)
200
248k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
1.74M
    diff->MCU_ctr = 0;
204
1.74M
  }
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.42M
    compptr = cinfo->cur_comp_info[ci];
213
1.42M
    compi = compptr->component_index;
214
1.42M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
3.62M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
3.62M
                compptr->last_row_height : compptr->v_samp_factor);
217
2.20M
         prev_row = row, row++) {
218
2.20M
      (*losslessd->predict_undifference[compi])
219
2.20M
        (cinfo, compi, diff->diff_buf[compi][row],
220
2.20M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
2.20M
          compptr->width_in_blocks);
222
2.20M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
2.20M
                                  output_buf[compi][row],
224
2.20M
                                  compptr->width_in_blocks);
225
2.20M
    }
226
1.42M
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
1.05M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
1.05M
    start_iMCU_row(cinfo);
236
1.05M
    return JPEG_ROW_COMPLETED;
237
1.05M
  }
238
  /* Completed the scan */
239
1.85k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.85k
  return JPEG_SCAN_COMPLETED;
241
1.05M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
5.73M
{
165
5.73M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
5.73M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
5.73M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
5.73M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
5.73M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
5.73M
  int ci, compi, row, prev_row;
171
5.73M
  unsigned int yoffset;
172
5.73M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
17.1M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
11.4M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
11.4M
    if (cinfo->restart_interval) {
180
637k
      if (diff->restart_rows_to_go == 0)
181
1.47k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
637k
    }
184
185
11.4M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
11.4M
    MCU_count =
188
11.4M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
11.4M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
11.4M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
11.4M
    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
11.4M
    if (cinfo->restart_interval)
200
637k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
11.4M
    diff->MCU_ctr = 0;
204
11.4M
  }
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
11.7M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
5.96M
    compptr = cinfo->cur_comp_info[ci];
213
5.96M
    compi = compptr->component_index;
214
5.96M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
17.8M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
17.8M
                compptr->last_row_height : compptr->v_samp_factor);
217
11.8M
         prev_row = row, row++) {
218
11.8M
      (*losslessd->predict_undifference[compi])
219
11.8M
        (cinfo, compi, diff->diff_buf[compi][row],
220
11.8M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
11.8M
          compptr->width_in_blocks);
222
11.8M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
11.8M
                                  output_buf[compi][row],
224
11.8M
                                  compptr->width_in_blocks);
225
11.8M
    }
226
5.96M
  }
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
5.73M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
5.73M
    start_iMCU_row(cinfo);
236
5.73M
    return JPEG_ROW_COMPLETED;
237
5.73M
  }
238
  /* Completed the scan */
239
1.51k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.51k
  return JPEG_SCAN_COMPLETED;
241
5.73M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
20.8M
{
165
20.8M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
20.8M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
20.8M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
20.8M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
20.8M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
20.8M
  int ci, compi, row, prev_row;
171
20.8M
  unsigned int yoffset;
172
20.8M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
42.4M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
21.5M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
21.5M
    if (cinfo->restart_interval) {
180
1.39M
      if (diff->restart_rows_to_go == 0)
181
87.4k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.39M
    }
184
185
21.5M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
21.5M
    MCU_count =
188
21.5M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
21.5M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
21.5M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
21.5M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
21.5M
    if (cinfo->restart_interval)
200
1.39M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
21.5M
    diff->MCU_ctr = 0;
204
21.5M
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
42.2M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
21.3M
    compptr = cinfo->cur_comp_info[ci];
213
21.3M
    compi = compptr->component_index;
214
21.3M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
43.8M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
43.8M
                compptr->last_row_height : compptr->v_samp_factor);
217
22.5M
         prev_row = row, row++) {
218
22.5M
      (*losslessd->predict_undifference[compi])
219
22.5M
        (cinfo, compi, diff->diff_buf[compi][row],
220
22.5M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
22.5M
          compptr->width_in_blocks);
222
22.5M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
22.5M
                                  output_buf[compi][row],
224
22.5M
                                  compptr->width_in_blocks);
225
22.5M
    }
226
21.3M
  }
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
20.8M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
20.8M
    start_iMCU_row(cinfo);
236
20.8M
    return JPEG_ROW_COMPLETED;
237
20.8M
  }
238
  /* Completed the scan */
239
1.77k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.77k
  return JPEG_SCAN_COMPLETED;
241
20.8M
}
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
27.2M
{
267
27.2M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
27.2M
  int ci, compi;
269
27.2M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
27.2M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
54.9M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
27.6M
    compptr = cinfo->cur_comp_info[ci];
275
27.6M
    compi = compptr->component_index;
276
27.6M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
27.6M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
27.6M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
27.6M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
27.6M
  }
281
282
27.2M
  return decompress_data(cinfo, buffer);
283
27.2M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
941k
{
267
941k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
941k
  int ci, compi;
269
941k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
941k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
2.02M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
1.08M
    compptr = cinfo->cur_comp_info[ci];
275
1.08M
    compi = compptr->component_index;
276
1.08M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
1.08M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
1.08M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
1.08M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
1.08M
  }
281
282
941k
  return decompress_data(cinfo, buffer);
283
941k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
5.65M
{
267
5.65M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
5.65M
  int ci, compi;
269
5.65M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
5.65M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
11.3M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
5.72M
    compptr = cinfo->cur_comp_info[ci];
275
5.72M
    compi = compptr->component_index;
276
5.72M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
5.72M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
5.72M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
5.72M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
5.72M
  }
281
282
5.65M
  return decompress_data(cinfo, buffer);
283
5.65M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
20.6M
{
267
20.6M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
20.6M
  int ci, compi;
269
20.6M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
20.6M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
41.5M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
20.8M
    compptr = cinfo->cur_comp_info[ci];
275
20.8M
    compi = compptr->component_index;
276
20.8M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
20.8M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
20.8M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
20.8M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
20.8M
  }
281
282
20.6M
  return decompress_data(cinfo, buffer);
283
20.6M
}
284
285
286
/*
287
 * Output some data from the full-image sample buffer in the multi-pass case.
288
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
289
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
290
 *
291
 * NB: output_buf contains a plane for each component in image.
292
 */
293
294
METHODDEF(int)
295
output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
296
197k
{
297
197k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
197k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
197k
  int ci, samp_rows, row;
300
197k
  _JSAMPARRAY buffer;
301
197k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
197k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
197k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
197k
          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
788k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
590k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
590k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
590k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
590k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
590k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
590k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
589k
      samp_rows = compptr->v_samp_factor;
322
1.16k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1.16k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1.16k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1.16k
    }
327
328
1.55M
    for (row = 0; row < samp_rows; row++) {
329
966k
      memcpy(output_buf[ci][row], buffer[row],
330
966k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
966k
    }
332
590k
  }
333
334
197k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
196k
    return JPEG_ROW_COMPLETED;
336
815
  return JPEG_SCAN_COMPLETED;
337
197k
}
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
368
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
368
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
368
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
368
    }
327
328
228k
    for (row = 0; row < samp_rows; row++) {
329
120k
      memcpy(output_buf[ci][row], buffer[row],
330
120k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
120k
    }
332
107k
  }
333
334
35.8k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
35.5k
    return JPEG_ROW_COMPLETED;
336
252
  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
323
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
323
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
323
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
323
    }
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
215
  return JPEG_SCAN_COMPLETED;
337
70.4k
}
jddiffct-16.c:output_data
Line
Count
Source
296
91.0k
{
297
91.0k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
91.0k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
91.0k
  int ci, samp_rows, row;
300
91.0k
  _JSAMPARRAY buffer;
301
91.0k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
91.0k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
91.0k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
91.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
363k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
272k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
272k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
272k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
272k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
272k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
272k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
272k
      samp_rows = compptr->v_samp_factor;
322
478
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
478
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
478
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
478
    }
327
328
788k
    for (row = 0; row < samp_rows; row++) {
329
515k
      memcpy(output_buf[ci][row], buffer[row],
330
515k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
515k
    }
332
272k
  }
333
334
91.0k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
90.6k
    return JPEG_ROW_COMPLETED;
336
348
  return JPEG_SCAN_COMPLETED;
337
91.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
1.52k
{
349
1.52k
  my_diff_ptr diff;
350
1.52k
  int ci;
351
1.52k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
442
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
1.08k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.08k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.52k
  diff = (my_diff_ptr)
362
1.52k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.52k
                                sizeof(my_diff_controller));
364
1.52k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.52k
  diff->pub.start_input_pass = start_input_pass;
366
1.52k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
6.10k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.58k
       ci++, compptr++) {
371
4.58k
    diff->diff_buf[ci] =
372
4.58k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.58k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.58k
                                         (long)compptr->h_samp_factor),
375
4.58k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.58k
    diff->undiff_buf[ci] =
377
4.58k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.58k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.58k
                                         (long)compptr->h_samp_factor),
380
4.58k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.58k
  }
382
383
1.52k
  if (need_full_buffer) {
384
1.23k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.23k
    int access_rows;
387
388
4.92k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.69k
         ci++, compptr++) {
390
3.69k
      access_rows = compptr->v_samp_factor;
391
3.69k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.69k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.69k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.69k
                               (long)compptr->h_samp_factor),
395
3.69k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.69k
                               (long)compptr->v_samp_factor),
397
3.69k
         (JDIMENSION)access_rows);
398
3.69k
    }
399
1.23k
    diff->pub.consume_data = consume_data;
400
1.23k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.23k
  } else {
405
297
    diff->pub.consume_data = dummy_consume_data;
406
297
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
297
  }
409
1.52k
}
jinit_d_diff_controller
Line
Count
Source
348
442
{
349
442
  my_diff_ptr diff;
350
442
  int ci;
351
442
  jpeg_component_info *compptr;
352
353
442
#if BITS_IN_JSAMPLE == 8
354
442
  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
442
  diff = (my_diff_ptr)
362
442
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
442
                                sizeof(my_diff_controller));
364
442
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
442
  diff->pub.start_input_pass = start_input_pass;
366
442
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.76k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.32k
       ci++, compptr++) {
371
1.32k
    diff->diff_buf[ci] =
372
1.32k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.32k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.32k
                                         (long)compptr->h_samp_factor),
375
1.32k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.32k
    diff->undiff_buf[ci] =
377
1.32k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.32k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.32k
                                         (long)compptr->h_samp_factor),
380
1.32k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.32k
  }
382
383
442
  if (need_full_buffer) {
384
376
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
376
    int access_rows;
387
388
1.50k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.12k
         ci++, compptr++) {
390
1.12k
      access_rows = compptr->v_samp_factor;
391
1.12k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.12k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.12k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.12k
                               (long)compptr->h_samp_factor),
395
1.12k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.12k
                               (long)compptr->v_samp_factor),
397
1.12k
         (JDIMENSION)access_rows);
398
1.12k
    }
399
376
    diff->pub.consume_data = consume_data;
400
376
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
376
  } else {
405
66
    diff->pub.consume_data = dummy_consume_data;
406
66
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
66
  }
409
442
}
j12init_d_diff_controller
Line
Count
Source
348
512
{
349
512
  my_diff_ptr diff;
350
512
  int ci;
351
512
  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
512
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
512
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
512
  diff = (my_diff_ptr)
362
512
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
512
                                sizeof(my_diff_controller));
364
512
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
512
  diff->pub.start_input_pass = start_input_pass;
366
512
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.04k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.53k
       ci++, compptr++) {
371
1.53k
    diff->diff_buf[ci] =
372
1.53k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.53k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.53k
                                         (long)compptr->h_samp_factor),
375
1.53k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.53k
    diff->undiff_buf[ci] =
377
1.53k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.53k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.53k
                                         (long)compptr->h_samp_factor),
380
1.53k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.53k
  }
382
383
512
  if (need_full_buffer) {
384
398
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
398
    int access_rows;
387
388
1.59k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.19k
         ci++, compptr++) {
390
1.19k
      access_rows = compptr->v_samp_factor;
391
1.19k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.19k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.19k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.19k
                               (long)compptr->h_samp_factor),
395
1.19k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.19k
                               (long)compptr->v_samp_factor),
397
1.19k
         (JDIMENSION)access_rows);
398
1.19k
    }
399
398
    diff->pub.consume_data = consume_data;
400
398
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
398
  } else {
405
114
    diff->pub.consume_data = dummy_consume_data;
406
114
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
114
  }
409
512
}
j16init_d_diff_controller
Line
Count
Source
348
573
{
349
573
  my_diff_ptr diff;
350
573
  int ci;
351
573
  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
573
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
573
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
573
  diff = (my_diff_ptr)
362
573
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
573
                                sizeof(my_diff_controller));
364
573
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
573
  diff->pub.start_input_pass = start_input_pass;
366
573
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.29k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.71k
       ci++, compptr++) {
371
1.71k
    diff->diff_buf[ci] =
372
1.71k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.71k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.71k
                                         (long)compptr->h_samp_factor),
375
1.71k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.71k
    diff->undiff_buf[ci] =
377
1.71k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.71k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.71k
                                         (long)compptr->h_samp_factor),
380
1.71k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.71k
  }
382
383
573
  if (need_full_buffer) {
384
456
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
456
    int access_rows;
387
388
1.82k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.36k
         ci++, compptr++) {
390
1.36k
      access_rows = compptr->v_samp_factor;
391
1.36k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.36k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.36k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.36k
                               (long)compptr->h_samp_factor),
395
1.36k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.36k
                               (long)compptr->v_samp_factor),
397
1.36k
         (JDIMENSION)access_rows);
398
1.36k
    }
399
456
    diff->pub.consume_data = consume_data;
400
456
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
456
  } else {
405
117
    diff->pub.consume_data = dummy_consume_data;
406
117
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
117
  }
409
573
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */