Coverage Report

Created: 2025-07-11 07:03

/src/libjpeg-turbo.main/src/jddiffct.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * jddiffct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1997, Thomas G. Lane.
6
 * Lossless JPEG Modifications:
7
 * Copyright (C) 1999, Ken Murchison.
8
 * libjpeg-turbo Modifications:
9
 * Copyright (C) 2022, 2024, D. R. Commander.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the [un]difference buffer controller for decompression.
14
 * This controller is the top level of the lossless JPEG decompressor proper.
15
 * The difference buffer lies between the entropy decoding and
16
 * prediction/undifferencing steps.  The undifference buffer lies between the
17
 * prediction/undifferencing and scaling steps.
18
 *
19
 * In buffered-image mode, this controller is the interface between
20
 * input-oriented processing and output-oriented processing.
21
 */
22
23
#define JPEG_INTERNALS
24
#include "jinclude.h"
25
#include "jpeglib.h"
26
#include "jlossls.h"            /* Private declarations for lossless codec */
27
28
29
#ifdef D_LOSSLESS_SUPPORTED
30
31
/* Private buffer controller object */
32
33
typedef struct {
34
  struct jpeg_d_coef_controller pub; /* public fields */
35
36
  /* These variables keep track of the current location of the input side. */
37
  /* cinfo->input_iMCU_row is also used for this. */
38
  JDIMENSION MCU_ctr;           /* counts MCUs processed in current row */
39
  unsigned int restart_rows_to_go;      /* MCU rows left in this restart
40
                                           interval */
41
  unsigned int MCU_vert_offset;         /* counts MCU rows within iMCU row */
42
  unsigned int MCU_rows_per_iMCU_row;   /* number of such rows needed */
43
44
  /* The output side's location is represented by cinfo->output_iMCU_row. */
45
46
  JDIFFARRAY diff_buf[MAX_COMPONENTS];  /* iMCU row of differences */
47
  JDIFFARRAY undiff_buf[MAX_COMPONENTS]; /* iMCU row of undiff'd samples */
48
49
#ifdef D_MULTISCAN_FILES_SUPPORTED
50
  /* In multi-pass modes, we need a virtual sample array for each component. */
51
  jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
52
#endif
53
} my_diff_controller;
54
55
typedef my_diff_controller *my_diff_ptr;
56
57
/* Forward declarations */
58
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
59
#ifdef D_MULTISCAN_FILES_SUPPORTED
60
METHODDEF(int) output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
61
#endif
62
63
64
LOCAL(void)
65
start_iMCU_row(j_decompress_ptr cinfo)
66
/* Reset within-iMCU-row counters for a new row (input side) */
67
70.3M
{
68
70.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
70.3M
  if (cinfo->comps_in_scan > 1) {
75
40.9M
    diff->MCU_rows_per_iMCU_row = 1;
76
40.9M
  } else {
77
29.4M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
29.4M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
5.91k
    else
80
5.91k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
29.4M
  }
82
83
70.3M
  diff->MCU_ctr = 0;
84
70.3M
  diff->MCU_vert_offset = 0;
85
70.3M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
9.76M
{
68
9.76M
  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.76M
  if (cinfo->comps_in_scan > 1) {
75
2.55M
    diff->MCU_rows_per_iMCU_row = 1;
76
7.21M
  } else {
77
7.21M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
7.21M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
2.21k
    else
80
2.21k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
7.21M
  }
82
83
9.76M
  diff->MCU_ctr = 0;
84
9.76M
  diff->MCU_vert_offset = 0;
85
9.76M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
24.1M
{
68
24.1M
  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
24.1M
  if (cinfo->comps_in_scan > 1) {
75
18.7M
    diff->MCU_rows_per_iMCU_row = 1;
76
18.7M
  } else {
77
5.31M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
5.31M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.89k
    else
80
1.89k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
5.31M
  }
82
83
24.1M
  diff->MCU_ctr = 0;
84
24.1M
  diff->MCU_vert_offset = 0;
85
24.1M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
36.5M
{
68
36.5M
  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
36.5M
  if (cinfo->comps_in_scan > 1) {
75
19.5M
    diff->MCU_rows_per_iMCU_row = 1;
76
19.5M
  } else {
77
16.9M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
16.9M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.81k
    else
80
1.81k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
16.9M
  }
82
83
36.5M
  diff->MCU_ctr = 0;
84
36.5M
  diff->MCU_vert_offset = 0;
85
36.5M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
9.77k
{
95
9.77k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
9.77k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
9.77k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
74
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
9.77k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
9.77k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
9.77k
  cinfo->input_iMCU_row = 0;
115
9.77k
  start_iMCU_row(cinfo);
116
9.77k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
3.44k
{
95
3.44k
  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.44k
  (*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.44k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
28
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
3.44k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
3.44k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
3.44k
  cinfo->input_iMCU_row = 0;
115
3.44k
  start_iMCU_row(cinfo);
116
3.44k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
3.33k
{
95
3.33k
  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.33k
  (*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.33k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
21
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
3.33k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
3.33k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
3.33k
  cinfo->input_iMCU_row = 0;
115
3.33k
  start_iMCU_row(cinfo);
116
3.33k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
2.98k
{
95
2.98k
  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
2.98k
  (*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
2.98k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
25
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
2.98k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
2.98k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
2.98k
  cinfo->input_iMCU_row = 0;
115
2.98k
  start_iMCU_row(cinfo);
116
2.98k
}
117
118
119
/*
120
 * Check for a restart marker & resynchronize decoder, undifferencer.
121
 * Returns FALSE if must suspend.
122
 */
123
124
METHODDEF(boolean)
125
process_restart(j_decompress_ptr cinfo)
126
17.3M
{
127
17.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
17.3M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
17.3M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
17.3M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
17.3M
  return TRUE;
138
17.3M
}
jddiffct-8.c:process_restart
Line
Count
Source
126
41.2k
{
127
41.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
41.2k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
41.2k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
41.2k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
41.2k
  return TRUE;
138
41.2k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
17.2M
{
127
17.2M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
17.2M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
17.2M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
17.2M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
17.2M
  return TRUE;
138
17.2M
}
jddiffct-16.c:process_restart
Line
Count
Source
126
96.2k
{
127
96.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
96.2k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
96.2k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
96.2k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
96.2k
  return TRUE;
138
96.2k
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
2.05k
{
148
2.05k
  cinfo->output_iMCU_row = 0;
149
2.05k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
664
{
148
664
  cinfo->output_iMCU_row = 0;
149
664
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
688
{
148
688
  cinfo->output_iMCU_row = 0;
149
688
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
701
{
148
701
  cinfo->output_iMCU_row = 0;
149
701
}
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
70.3M
{
165
70.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
70.3M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
70.3M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
70.3M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
70.3M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
70.3M
  int ci, compi, row, prev_row;
171
70.3M
  unsigned int yoffset;
172
70.3M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
149M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
79.5M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
79.5M
    if (cinfo->restart_interval) {
180
36.8M
      if (diff->restart_rows_to_go == 0)
181
17.3M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
36.8M
    }
184
185
79.5M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
79.5M
    MCU_count =
188
79.5M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
79.5M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
79.5M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
79.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
79.5M
    if (cinfo->restart_interval)
200
36.8M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
79.5M
    diff->MCU_ctr = 0;
204
79.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
182M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
112M
    compptr = cinfo->cur_comp_info[ci];
213
112M
    compi = compptr->component_index;
214
112M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
239M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
239M
                compptr->last_row_height : compptr->v_samp_factor);
217
127M
         prev_row = row, row++) {
218
127M
      (*losslessd->predict_undifference[compi])
219
127M
        (cinfo, compi, diff->diff_buf[compi][row],
220
127M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
127M
          compptr->width_in_blocks);
222
127M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
127M
                                  output_buf[compi][row],
224
127M
                                  compptr->width_in_blocks);
225
127M
    }
226
112M
  }
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
70.3M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
70.3M
    start_iMCU_row(cinfo);
236
70.3M
    return JPEG_ROW_COMPLETED;
237
70.3M
  }
238
  /* Completed the scan */
239
9.45k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
9.45k
  return JPEG_SCAN_COMPLETED;
241
70.3M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
9.76M
{
165
9.76M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
9.76M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
9.76M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
9.76M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
9.76M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
9.76M
  int ci, compi, row, prev_row;
171
9.76M
  unsigned int yoffset;
172
9.76M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
21.8M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
12.1M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
12.1M
    if (cinfo->restart_interval) {
180
1.48M
      if (diff->restart_rows_to_go == 0)
181
41.2k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.48M
    }
184
185
12.1M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
12.1M
    MCU_count =
188
12.1M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
12.1M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
12.1M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
12.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
12.1M
    if (cinfo->restart_interval)
200
1.48M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
12.1M
    diff->MCU_ctr = 0;
204
12.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
22.2M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
12.4M
    compptr = cinfo->cur_comp_info[ci];
213
12.4M
    compi = compptr->component_index;
214
12.4M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
28.8M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
28.8M
                compptr->last_row_height : compptr->v_samp_factor);
217
16.4M
         prev_row = row, row++) {
218
16.4M
      (*losslessd->predict_undifference[compi])
219
16.4M
        (cinfo, compi, diff->diff_buf[compi][row],
220
16.4M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
16.4M
          compptr->width_in_blocks);
222
16.4M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
16.4M
                                  output_buf[compi][row],
224
16.4M
                                  compptr->width_in_blocks);
225
16.4M
    }
226
12.4M
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
9.76M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
9.76M
    start_iMCU_row(cinfo);
236
9.76M
    return JPEG_ROW_COMPLETED;
237
9.76M
  }
238
  /* Completed the scan */
239
3.32k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
3.32k
  return JPEG_SCAN_COMPLETED;
241
9.76M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
24.1M
{
165
24.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
24.1M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
24.1M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
24.1M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
24.1M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
24.1M
  int ci, compi, row, prev_row;
171
24.1M
  unsigned int yoffset;
172
24.1M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
52.3M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
28.1M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
28.1M
    if (cinfo->restart_interval) {
180
19.0M
      if (diff->restart_rows_to_go == 0)
181
17.2M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
19.0M
    }
184
185
28.1M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
28.1M
    MCU_count =
188
28.1M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
28.1M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
28.1M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
28.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
28.1M
    if (cinfo->restart_interval)
200
19.0M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
28.1M
    diff->MCU_ctr = 0;
204
28.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
67.1M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
43.0M
    compptr = cinfo->cur_comp_info[ci];
213
43.0M
    compi = compptr->component_index;
214
43.0M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
91.2M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
91.2M
                compptr->last_row_height : compptr->v_samp_factor);
217
48.2M
         prev_row = row, row++) {
218
48.2M
      (*losslessd->predict_undifference[compi])
219
48.2M
        (cinfo, compi, diff->diff_buf[compi][row],
220
48.2M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
48.2M
          compptr->width_in_blocks);
222
48.2M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
48.2M
                                  output_buf[compi][row],
224
48.2M
                                  compptr->width_in_blocks);
225
48.2M
    }
226
43.0M
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
24.1M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
24.1M
    start_iMCU_row(cinfo);
236
24.1M
    return JPEG_ROW_COMPLETED;
237
24.1M
  }
238
  /* Completed the scan */
239
3.24k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
3.24k
  return JPEG_SCAN_COMPLETED;
241
24.1M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
36.5M
{
165
36.5M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
36.5M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
36.5M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
36.5M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
36.5M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
36.5M
  int ci, compi, row, prev_row;
171
36.5M
  unsigned int yoffset;
172
36.5M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
75.7M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
39.2M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
39.2M
    if (cinfo->restart_interval) {
180
16.3M
      if (diff->restart_rows_to_go == 0)
181
96.2k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
16.3M
    }
184
185
39.2M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
39.2M
    MCU_count =
188
39.2M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
39.2M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
39.2M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
39.2M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
39.2M
    if (cinfo->restart_interval)
200
16.3M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
39.2M
    diff->MCU_ctr = 0;
204
39.2M
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
93.0M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
56.5M
    compptr = cinfo->cur_comp_info[ci];
213
56.5M
    compi = compptr->component_index;
214
56.5M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
118M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
118M
                compptr->last_row_height : compptr->v_samp_factor);
217
62.3M
         prev_row = row, row++) {
218
62.3M
      (*losslessd->predict_undifference[compi])
219
62.3M
        (cinfo, compi, diff->diff_buf[compi][row],
220
62.3M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
62.3M
          compptr->width_in_blocks);
222
62.3M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
62.3M
                                  output_buf[compi][row],
224
62.3M
                                  compptr->width_in_blocks);
225
62.3M
    }
226
56.5M
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
36.5M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
36.5M
    start_iMCU_row(cinfo);
236
36.5M
    return JPEG_ROW_COMPLETED;
237
36.5M
  }
238
  /* Completed the scan */
239
2.88k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
2.88k
  return JPEG_SCAN_COMPLETED;
241
36.5M
}
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
70.0M
{
267
70.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
70.0M
  int ci, compi;
269
70.0M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
70.0M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
181M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
110M
    compptr = cinfo->cur_comp_info[ci];
275
110M
    compi = compptr->component_index;
276
110M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
110M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
110M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
110M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
110M
  }
281
282
70.0M
  return decompress_data(cinfo, buffer);
283
70.0M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
9.65M
{
267
9.65M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
9.65M
  int ci, compi;
269
9.65M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
9.65M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
21.7M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
12.1M
    compptr = cinfo->cur_comp_info[ci];
275
12.1M
    compi = compptr->component_index;
276
12.1M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
12.1M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
12.1M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
12.1M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
12.1M
  }
281
282
9.65M
  return decompress_data(cinfo, buffer);
283
9.65M
}
jddiffct-12.c:consume_data
Line
Count
Source
266
24.0M
{
267
24.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
24.0M
  int ci, compi;
269
24.0M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
24.0M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
66.7M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
42.7M
    compptr = cinfo->cur_comp_info[ci];
275
42.7M
    compi = compptr->component_index;
276
42.7M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
42.7M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
42.7M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
42.7M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
42.7M
  }
281
282
24.0M
  return decompress_data(cinfo, buffer);
283
24.0M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
36.3M
{
267
36.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
36.3M
  int ci, compi;
269
36.3M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
36.3M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
92.5M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
56.1M
    compptr = cinfo->cur_comp_info[ci];
275
56.1M
    compi = compptr->component_index;
276
56.1M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
56.1M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
56.1M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
56.1M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
56.1M
  }
281
282
36.3M
  return decompress_data(cinfo, buffer);
283
36.3M
}
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
174k
{
297
174k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
174k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
174k
  int ci, samp_rows, row;
300
174k
  _JSAMPARRAY buffer;
301
174k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
174k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
174k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
174k
          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
695k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
521k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
521k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
521k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
521k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
521k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
521k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
520k
      samp_rows = compptr->v_samp_factor;
322
1.17k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1.17k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1.17k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1.17k
    }
327
328
1.47M
    for (row = 0; row < samp_rows; row++) {
329
949k
      memcpy(output_buf[ci][row], buffer[row],
330
949k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
949k
    }
332
521k
  }
333
334
174k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
173k
    return JPEG_ROW_COMPLETED;
336
830
  return JPEG_SCAN_COMPLETED;
337
174k
}
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
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
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
275
  return JPEG_SCAN_COMPLETED;
337
35.8k
}
jddiffct-12.c:output_data
Line
Count
Source
296
71.5k
{
297
71.5k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
71.5k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
71.5k
  int ci, samp_rows, row;
300
71.5k
  _JSAMPARRAY buffer;
301
71.5k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
71.5k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
71.5k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
71.5k
          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
285k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
214k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
214k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
214k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
214k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
214k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
214k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
213k
      samp_rows = compptr->v_samp_factor;
322
333
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
333
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
333
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
333
    }
327
328
547k
    for (row = 0; row < samp_rows; row++) {
329
332k
      memcpy(output_buf[ci][row], buffer[row],
330
332k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
332k
    }
332
214k
  }
333
334
71.5k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
71.3k
    return JPEG_ROW_COMPLETED;
336
220
  return JPEG_SCAN_COMPLETED;
337
71.5k
}
jddiffct-16.c:output_data
Line
Count
Source
296
66.8k
{
297
66.8k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
66.8k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
66.8k
  int ci, samp_rows, row;
300
66.8k
  _JSAMPARRAY buffer;
301
66.8k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
66.8k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
66.8k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
66.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
266k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
199k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
199k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
199k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
199k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
199k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
199k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
199k
      samp_rows = compptr->v_samp_factor;
322
449
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
449
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
449
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
449
    }
327
328
696k
    for (row = 0; row < samp_rows; row++) {
329
496k
      memcpy(output_buf[ci][row], buffer[row],
330
496k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
496k
    }
332
199k
  }
333
334
66.8k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
66.4k
    return JPEG_ROW_COMPLETED;
336
335
  return JPEG_SCAN_COMPLETED;
337
66.8k
}
338
339
#endif /* D_MULTISCAN_FILES_SUPPORTED */
340
341
342
/*
343
 * Initialize difference buffer controller.
344
 */
345
346
GLOBAL(void)
347
_jinit_d_diff_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
348
2.90k
{
349
2.90k
  my_diff_ptr diff;
350
2.90k
  int ci;
351
2.90k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
966
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
1.93k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.93k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
2.90k
  diff = (my_diff_ptr)
362
2.90k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
2.90k
                                sizeof(my_diff_controller));
364
2.90k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
2.90k
  diff->pub.start_input_pass = start_input_pass;
366
2.90k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
11.4k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
8.55k
       ci++, compptr++) {
371
8.55k
    diff->diff_buf[ci] =
372
8.55k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
8.55k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
8.55k
                                         (long)compptr->h_samp_factor),
375
8.55k
                   (JDIMENSION)compptr->v_samp_factor);
376
8.55k
    diff->undiff_buf[ci] =
377
8.55k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
8.55k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
8.55k
                                         (long)compptr->h_samp_factor),
380
8.55k
                   (JDIMENSION)compptr->v_samp_factor);
381
8.55k
  }
382
383
2.90k
  if (need_full_buffer) {
384
2.51k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
2.51k
    int access_rows;
387
388
10.0k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
7.55k
         ci++, compptr++) {
390
7.55k
      access_rows = compptr->v_samp_factor;
391
7.55k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
7.55k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
7.55k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
7.55k
                               (long)compptr->h_samp_factor),
395
7.55k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
7.55k
                               (long)compptr->v_samp_factor),
397
7.55k
         (JDIMENSION)access_rows);
398
7.55k
    }
399
2.51k
    diff->pub.consume_data = consume_data;
400
2.51k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
2.51k
  } else {
405
382
    diff->pub.consume_data = dummy_consume_data;
406
382
    diff->pub._decompress_data = decompress_data;
407
382
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
382
  }
409
2.90k
}
jinit_d_diff_controller
Line
Count
Source
348
966
{
349
966
  my_diff_ptr diff;
350
966
  int ci;
351
966
  jpeg_component_info *compptr;
352
353
966
#if BITS_IN_JSAMPLE == 8
354
966
  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
966
  diff = (my_diff_ptr)
362
966
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
966
                                sizeof(my_diff_controller));
364
966
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
966
  diff->pub.start_input_pass = start_input_pass;
366
966
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
3.80k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
2.83k
       ci++, compptr++) {
371
2.83k
    diff->diff_buf[ci] =
372
2.83k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
2.83k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
2.83k
                                         (long)compptr->h_samp_factor),
375
2.83k
                   (JDIMENSION)compptr->v_samp_factor);
376
2.83k
    diff->undiff_buf[ci] =
377
2.83k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
2.83k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
2.83k
                                         (long)compptr->h_samp_factor),
380
2.83k
                   (JDIMENSION)compptr->v_samp_factor);
381
2.83k
  }
382
383
966
  if (need_full_buffer) {
384
868
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
868
    int access_rows;
387
388
3.47k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
2.60k
         ci++, compptr++) {
390
2.60k
      access_rows = compptr->v_samp_factor;
391
2.60k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
2.60k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
2.60k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
2.60k
                               (long)compptr->h_samp_factor),
395
2.60k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
2.60k
                               (long)compptr->v_samp_factor),
397
2.60k
         (JDIMENSION)access_rows);
398
2.60k
    }
399
868
    diff->pub.consume_data = consume_data;
400
868
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
868
  } else {
405
98
    diff->pub.consume_data = dummy_consume_data;
406
98
    diff->pub._decompress_data = decompress_data;
407
98
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
98
  }
409
966
}
j12init_d_diff_controller
Line
Count
Source
348
950
{
349
950
  my_diff_ptr diff;
350
950
  int ci;
351
950
  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
950
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
950
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
950
  diff = (my_diff_ptr)
362
950
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
950
                                sizeof(my_diff_controller));
364
950
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
950
  diff->pub.start_input_pass = start_input_pass;
366
950
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
3.75k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
2.80k
       ci++, compptr++) {
371
2.80k
    diff->diff_buf[ci] =
372
2.80k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
2.80k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
2.80k
                                         (long)compptr->h_samp_factor),
375
2.80k
                   (JDIMENSION)compptr->v_samp_factor);
376
2.80k
    diff->undiff_buf[ci] =
377
2.80k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
2.80k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
2.80k
                                         (long)compptr->h_samp_factor),
380
2.80k
                   (JDIMENSION)compptr->v_samp_factor);
381
2.80k
  }
382
383
950
  if (need_full_buffer) {
384
813
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
813
    int access_rows;
387
388
3.25k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
2.43k
         ci++, compptr++) {
390
2.43k
      access_rows = compptr->v_samp_factor;
391
2.43k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
2.43k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
2.43k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
2.43k
                               (long)compptr->h_samp_factor),
395
2.43k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
2.43k
                               (long)compptr->v_samp_factor),
397
2.43k
         (JDIMENSION)access_rows);
398
2.43k
    }
399
813
    diff->pub.consume_data = consume_data;
400
813
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
813
  } else {
405
137
    diff->pub.consume_data = dummy_consume_data;
406
137
    diff->pub._decompress_data = decompress_data;
407
137
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
137
  }
409
950
}
j16init_d_diff_controller
Line
Count
Source
348
985
{
349
985
  my_diff_ptr diff;
350
985
  int ci;
351
985
  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
985
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
985
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
985
  diff = (my_diff_ptr)
362
985
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
985
                                sizeof(my_diff_controller));
364
985
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
985
  diff->pub.start_input_pass = start_input_pass;
366
985
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
3.90k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
2.91k
       ci++, compptr++) {
371
2.91k
    diff->diff_buf[ci] =
372
2.91k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
2.91k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
2.91k
                                         (long)compptr->h_samp_factor),
375
2.91k
                   (JDIMENSION)compptr->v_samp_factor);
376
2.91k
    diff->undiff_buf[ci] =
377
2.91k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
2.91k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
2.91k
                                         (long)compptr->h_samp_factor),
380
2.91k
                   (JDIMENSION)compptr->v_samp_factor);
381
2.91k
  }
382
383
985
  if (need_full_buffer) {
384
838
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
838
    int access_rows;
387
388
3.35k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
2.51k
         ci++, compptr++) {
390
2.51k
      access_rows = compptr->v_samp_factor;
391
2.51k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
2.51k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
2.51k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
2.51k
                               (long)compptr->h_samp_factor),
395
2.51k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
2.51k
                               (long)compptr->v_samp_factor),
397
2.51k
         (JDIMENSION)access_rows);
398
2.51k
    }
399
838
    diff->pub.consume_data = consume_data;
400
838
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
838
  } else {
405
147
    diff->pub.consume_data = dummy_consume_data;
406
147
    diff->pub._decompress_data = decompress_data;
407
147
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
147
  }
409
985
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */