Coverage Report

Created: 2025-08-03 06:59

/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
65.1M
{
68
65.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
65.1M
  if (cinfo->comps_in_scan > 1) {
75
32.1M
    diff->MCU_rows_per_iMCU_row = 1;
76
33.0M
  } else {
77
33.0M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
33.0M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
6.00k
    else
80
6.00k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
33.0M
  }
82
83
65.1M
  diff->MCU_ctr = 0;
84
65.1M
  diff->MCU_vert_offset = 0;
85
65.1M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
9.70M
{
68
9.70M
  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.70M
  if (cinfo->comps_in_scan > 1) {
75
2.24M
    diff->MCU_rows_per_iMCU_row = 1;
76
7.46M
  } else {
77
7.46M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
7.45M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
2.19k
    else
80
2.19k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
7.46M
  }
82
83
9.70M
  diff->MCU_ctr = 0;
84
9.70M
  diff->MCU_vert_offset = 0;
85
9.70M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
17.1M
{
68
17.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
17.1M
  if (cinfo->comps_in_scan > 1) {
75
10.5M
    diff->MCU_rows_per_iMCU_row = 1;
76
10.5M
  } else {
77
6.56M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
6.56M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.97k
    else
80
1.97k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
6.56M
  }
82
83
17.1M
  diff->MCU_ctr = 0;
84
17.1M
  diff->MCU_vert_offset = 0;
85
17.1M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
38.3M
{
68
38.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
38.3M
  if (cinfo->comps_in_scan > 1) {
75
19.3M
    diff->MCU_rows_per_iMCU_row = 1;
76
19.3M
  } else {
77
18.9M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
18.9M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.83k
    else
80
1.83k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
18.9M
  }
82
83
38.3M
  diff->MCU_ctr = 0;
84
38.3M
  diff->MCU_vert_offset = 0;
85
38.3M
}
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.68k
{
95
9.68k
  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.68k
  (*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.68k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
80
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
9.68k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
9.68k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
9.68k
  cinfo->input_iMCU_row = 0;
115
9.68k
  start_iMCU_row(cinfo);
116
9.68k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
3.40k
{
95
3.40k
  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.40k
  (*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.40k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
28
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
3.40k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
3.40k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
3.40k
  cinfo->input_iMCU_row = 0;
115
3.40k
  start_iMCU_row(cinfo);
116
3.40k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
3.27k
{
95
3.27k
  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.27k
  (*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.27k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
23
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
3.27k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
3.27k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
3.27k
  cinfo->input_iMCU_row = 0;
115
3.27k
  start_iMCU_row(cinfo);
116
3.27k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
3.00k
{
95
3.00k
  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.00k
  (*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.00k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
29
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
3.00k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
3.00k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
3.00k
  cinfo->input_iMCU_row = 0;
115
3.00k
  start_iMCU_row(cinfo);
116
3.00k
}
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
8.89M
{
127
8.89M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
8.89M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
8.89M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
8.89M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
8.89M
  return TRUE;
138
8.89M
}
jddiffct-8.c:process_restart
Line
Count
Source
126
46.7k
{
127
46.7k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
46.7k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
46.7k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
46.7k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
46.7k
  return TRUE;
138
46.7k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
8.74M
{
127
8.74M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
8.74M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
8.74M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
8.74M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
8.74M
  return TRUE;
138
8.74M
}
jddiffct-16.c:process_restart
Line
Count
Source
126
107k
{
127
107k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
107k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
107k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
107k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
107k
  return TRUE;
138
107k
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
2.14k
{
148
2.14k
  cinfo->output_iMCU_row = 0;
149
2.14k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
684
{
148
684
  cinfo->output_iMCU_row = 0;
149
684
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
722
{
148
722
  cinfo->output_iMCU_row = 0;
149
722
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
735
{
148
735
  cinfo->output_iMCU_row = 0;
149
735
}
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
65.1M
{
165
65.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
65.1M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
65.1M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
65.1M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
65.1M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
65.1M
  int ci, compi, row, prev_row;
171
65.1M
  unsigned int yoffset;
172
65.1M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
140M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
75.2M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
75.2M
    if (cinfo->restart_interval) {
180
26.8M
      if (diff->restart_rows_to_go == 0)
181
8.89M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
26.8M
    }
184
185
75.2M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
75.2M
    MCU_count =
188
75.2M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
75.2M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
75.2M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
75.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
75.2M
    if (cinfo->restart_interval)
200
26.8M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
75.2M
    diff->MCU_ctr = 0;
204
75.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
162M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
97.8M
    compptr = cinfo->cur_comp_info[ci];
213
97.8M
    compi = compptr->component_index;
214
97.8M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
209M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
209M
                compptr->last_row_height : compptr->v_samp_factor);
217
112M
         prev_row = row, row++) {
218
112M
      (*losslessd->predict_undifference[compi])
219
112M
        (cinfo, compi, diff->diff_buf[compi][row],
220
112M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
112M
          compptr->width_in_blocks);
222
112M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
112M
                                  output_buf[compi][row],
224
112M
                                  compptr->width_in_blocks);
225
112M
    }
226
97.8M
  }
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
65.1M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
65.1M
    start_iMCU_row(cinfo);
236
65.1M
    return JPEG_ROW_COMPLETED;
237
65.1M
  }
238
  /* Completed the scan */
239
9.35k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
9.35k
  return JPEG_SCAN_COMPLETED;
241
65.1M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
9.70M
{
165
9.70M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
9.70M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
9.70M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
9.70M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
9.70M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
9.70M
  int ci, compi, row, prev_row;
171
9.70M
  unsigned int yoffset;
172
9.70M
  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.59M
      if (diff->restart_rows_to_go == 0)
181
46.7k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.59M
    }
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.59M
      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
21.8M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
12.1M
    compptr = cinfo->cur_comp_info[ci];
213
12.1M
    compi = compptr->component_index;
214
12.1M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
27.9M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
27.9M
                compptr->last_row_height : compptr->v_samp_factor);
217
15.8M
         prev_row = row, row++) {
218
15.8M
      (*losslessd->predict_undifference[compi])
219
15.8M
        (cinfo, compi, diff->diff_buf[compi][row],
220
15.8M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
15.8M
          compptr->width_in_blocks);
222
15.8M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
15.8M
                                  output_buf[compi][row],
224
15.8M
                                  compptr->width_in_blocks);
225
15.8M
    }
226
12.1M
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
9.70M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
9.70M
    start_iMCU_row(cinfo);
236
9.70M
    return JPEG_ROW_COMPLETED;
237
9.70M
  }
238
  /* Completed the scan */
239
3.28k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
3.28k
  return JPEG_SCAN_COMPLETED;
241
9.70M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
17.1M
{
165
17.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
17.1M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
17.1M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
17.1M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
17.1M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
17.1M
  int ci, compi, row, prev_row;
171
17.1M
  unsigned int yoffset;
172
17.1M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
39.1M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
22.0M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
22.0M
    if (cinfo->restart_interval) {
180
10.4M
      if (diff->restart_rows_to_go == 0)
181
8.74M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
10.4M
    }
184
185
22.0M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
22.0M
    MCU_count =
188
22.0M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
22.0M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
22.0M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
22.0M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
22.0M
    if (cinfo->restart_interval)
200
10.4M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
22.0M
    diff->MCU_ctr = 0;
204
22.0M
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
44.9M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
27.7M
    compptr = cinfo->cur_comp_info[ci];
213
27.7M
    compi = compptr->component_index;
214
27.7M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
61.6M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
61.6M
                compptr->last_row_height : compptr->v_samp_factor);
217
33.8M
         prev_row = row, row++) {
218
33.8M
      (*losslessd->predict_undifference[compi])
219
33.8M
        (cinfo, compi, diff->diff_buf[compi][row],
220
33.8M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
33.8M
          compptr->width_in_blocks);
222
33.8M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
33.8M
                                  output_buf[compi][row],
224
33.8M
                                  compptr->width_in_blocks);
225
33.8M
    }
226
27.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
17.1M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
17.1M
    start_iMCU_row(cinfo);
236
17.1M
    return JPEG_ROW_COMPLETED;
237
17.1M
  }
238
  /* Completed the scan */
239
3.17k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
3.17k
  return JPEG_SCAN_COMPLETED;
241
17.1M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
38.3M
{
165
38.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
38.3M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
38.3M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
38.3M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
38.3M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
38.3M
  int ci, compi, row, prev_row;
171
38.3M
  unsigned int yoffset;
172
38.3M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
79.3M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
41.0M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
41.0M
    if (cinfo->restart_interval) {
180
14.8M
      if (diff->restart_rows_to_go == 0)
181
107k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
14.8M
    }
184
185
41.0M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
41.0M
    MCU_count =
188
41.0M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
41.0M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
41.0M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
41.0M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
41.0M
    if (cinfo->restart_interval)
200
14.8M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
41.0M
    diff->MCU_ctr = 0;
204
41.0M
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
96.2M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
57.9M
    compptr = cinfo->cur_comp_info[ci];
213
57.9M
    compi = compptr->component_index;
214
57.9M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
120M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
120M
                compptr->last_row_height : compptr->v_samp_factor);
217
62.4M
         prev_row = row, row++) {
218
62.4M
      (*losslessd->predict_undifference[compi])
219
62.4M
        (cinfo, compi, diff->diff_buf[compi][row],
220
62.4M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
62.4M
          compptr->width_in_blocks);
222
62.4M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
62.4M
                                  output_buf[compi][row],
224
62.4M
                                  compptr->width_in_blocks);
225
62.4M
    }
226
57.9M
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
38.3M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
38.2M
    start_iMCU_row(cinfo);
236
38.2M
    return JPEG_ROW_COMPLETED;
237
38.2M
  }
238
  /* Completed the scan */
239
2.89k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
2.89k
  return JPEG_SCAN_COMPLETED;
241
38.3M
}
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
64.6M
{
267
64.6M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
64.6M
  int ci, compi;
269
64.6M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
64.6M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
161M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
96.4M
    compptr = cinfo->cur_comp_info[ci];
275
96.4M
    compi = compptr->component_index;
276
96.4M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
96.4M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
96.4M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
96.4M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
96.4M
  }
281
282
64.6M
  return decompress_data(cinfo, buffer);
283
64.6M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
9.58M
{
267
9.58M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
9.58M
  int ci, compi;
269
9.58M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
9.58M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
21.3M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
11.7M
    compptr = cinfo->cur_comp_info[ci];
275
11.7M
    compi = compptr->component_index;
276
11.7M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
11.7M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
11.7M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
11.7M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
11.7M
  }
281
282
9.58M
  return decompress_data(cinfo, buffer);
283
9.58M
}
jddiffct-12.c:consume_data
Line
Count
Source
266
17.0M
{
267
17.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
17.0M
  int ci, compi;
269
17.0M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
17.0M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
44.5M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
27.4M
    compptr = cinfo->cur_comp_info[ci];
275
27.4M
    compi = compptr->component_index;
276
27.4M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
27.4M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
27.4M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
27.4M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
27.4M
  }
281
282
17.0M
  return decompress_data(cinfo, buffer);
283
17.0M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
38.0M
{
267
38.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
38.0M
  int ci, compi;
269
38.0M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
38.0M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
95.3M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
57.2M
    compptr = cinfo->cur_comp_info[ci];
275
57.2M
    compi = compptr->component_index;
276
57.2M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
57.2M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
57.2M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
57.2M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
57.2M
  }
281
282
38.0M
  return decompress_data(cinfo, buffer);
283
38.0M
}
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
157k
{
297
157k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
157k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
157k
  int ci, samp_rows, row;
300
157k
  _JSAMPARRAY buffer;
301
157k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
157k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
157k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
157k
          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
630k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
472k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
472k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
472k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
472k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
472k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
472k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
471k
      samp_rows = compptr->v_samp_factor;
322
1.19k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1.19k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1.19k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1.19k
    }
327
328
1.30M
    for (row = 0; row < samp_rows; row++) {
329
835k
      memcpy(output_buf[ci][row], buffer[row],
330
835k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
835k
    }
332
472k
  }
333
334
157k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
157k
    return JPEG_ROW_COMPLETED;
336
850
  return JPEG_SCAN_COMPLETED;
337
157k
}
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
396
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
396
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
396
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
396
    }
327
328
228k
    for (row = 0; row < samp_rows; row++) {
329
121k
      memcpy(output_buf[ci][row], buffer[row],
330
121k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
121k
    }
332
107k
  }
333
334
35.8k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
35.5k
    return JPEG_ROW_COMPLETED;
336
281
  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
336
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
336
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
336
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
336
    }
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
221
  return JPEG_SCAN_COMPLETED;
337
71.5k
}
jddiffct-16.c:output_data
Line
Count
Source
296
50.5k
{
297
50.5k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
50.5k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
50.5k
  int ci, samp_rows, row;
300
50.5k
  _JSAMPARRAY buffer;
301
50.5k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
50.5k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
50.5k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
50.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
201k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
151k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
151k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
151k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
151k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
151k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
151k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
150k
      samp_rows = compptr->v_samp_factor;
322
463
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
463
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
463
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
463
    }
327
328
532k
    for (row = 0; row < samp_rows; row++) {
329
381k
      memcpy(output_buf[ci][row], buffer[row],
330
381k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
381k
    }
332
151k
  }
333
334
50.5k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
50.1k
    return JPEG_ROW_COMPLETED;
336
348
  return JPEG_SCAN_COMPLETED;
337
50.5k
}
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.99k
{
349
2.99k
  my_diff_ptr diff;
350
2.99k
  int ci;
351
2.99k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
987
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
2.00k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
2.00k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
2.99k
  diff = (my_diff_ptr)
362
2.99k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
2.99k
                                sizeof(my_diff_controller));
364
2.99k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
2.99k
  diff->pub.start_input_pass = start_input_pass;
366
2.99k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
11.8k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
8.81k
       ci++, compptr++) {
371
8.81k
    diff->diff_buf[ci] =
372
8.81k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
8.81k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
8.81k
                                         (long)compptr->h_samp_factor),
375
8.81k
                   (JDIMENSION)compptr->v_samp_factor);
376
8.81k
    diff->undiff_buf[ci] =
377
8.81k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
8.81k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
8.81k
                                         (long)compptr->h_samp_factor),
380
8.81k
                   (JDIMENSION)compptr->v_samp_factor);
381
8.81k
  }
382
383
2.99k
  if (need_full_buffer) {
384
2.59k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
2.59k
    int access_rows;
387
388
10.3k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
7.79k
         ci++, compptr++) {
390
7.79k
      access_rows = compptr->v_samp_factor;
391
7.79k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
7.79k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
7.79k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
7.79k
                               (long)compptr->h_samp_factor),
395
7.79k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
7.79k
                               (long)compptr->v_samp_factor),
397
7.79k
         (JDIMENSION)access_rows);
398
7.79k
    }
399
2.59k
    diff->pub.consume_data = consume_data;
400
2.59k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
2.59k
  } else {
405
391
    diff->pub.consume_data = dummy_consume_data;
406
391
    diff->pub._decompress_data = decompress_data;
407
391
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
391
  }
409
2.99k
}
jinit_d_diff_controller
Line
Count
Source
348
987
{
349
987
  my_diff_ptr diff;
350
987
  int ci;
351
987
  jpeg_component_info *compptr;
352
353
987
#if BITS_IN_JSAMPLE == 8
354
987
  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
987
  diff = (my_diff_ptr)
362
987
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
987
                                sizeof(my_diff_controller));
364
987
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
987
  diff->pub.start_input_pass = start_input_pass;
366
987
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
3.87k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
2.89k
       ci++, compptr++) {
371
2.89k
    diff->diff_buf[ci] =
372
2.89k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
2.89k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
2.89k
                                         (long)compptr->h_samp_factor),
375
2.89k
                   (JDIMENSION)compptr->v_samp_factor);
376
2.89k
    diff->undiff_buf[ci] =
377
2.89k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
2.89k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
2.89k
                                         (long)compptr->h_samp_factor),
380
2.89k
                   (JDIMENSION)compptr->v_samp_factor);
381
2.89k
  }
382
383
987
  if (need_full_buffer) {
384
884
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
884
    int access_rows;
387
388
3.53k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
2.65k
         ci++, compptr++) {
390
2.65k
      access_rows = compptr->v_samp_factor;
391
2.65k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
2.65k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
2.65k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
2.65k
                               (long)compptr->h_samp_factor),
395
2.65k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
2.65k
                               (long)compptr->v_samp_factor),
397
2.65k
         (JDIMENSION)access_rows);
398
2.65k
    }
399
884
    diff->pub.consume_data = consume_data;
400
884
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
884
  } else {
405
103
    diff->pub.consume_data = dummy_consume_data;
406
103
    diff->pub._decompress_data = decompress_data;
407
103
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
103
  }
409
987
}
j12init_d_diff_controller
Line
Count
Source
348
991
{
349
991
  my_diff_ptr diff;
350
991
  int ci;
351
991
  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
991
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
991
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
991
  diff = (my_diff_ptr)
362
991
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
991
                                sizeof(my_diff_controller));
364
991
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
991
  diff->pub.start_input_pass = start_input_pass;
366
991
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
3.91k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
2.92k
       ci++, compptr++) {
371
2.92k
    diff->diff_buf[ci] =
372
2.92k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
2.92k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
2.92k
                                         (long)compptr->h_samp_factor),
375
2.92k
                   (JDIMENSION)compptr->v_samp_factor);
376
2.92k
    diff->undiff_buf[ci] =
377
2.92k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
2.92k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
2.92k
                                         (long)compptr->h_samp_factor),
380
2.92k
                   (JDIMENSION)compptr->v_samp_factor);
381
2.92k
  }
382
383
991
  if (need_full_buffer) {
384
847
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
847
    int access_rows;
387
388
3.38k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
2.54k
         ci++, compptr++) {
390
2.54k
      access_rows = compptr->v_samp_factor;
391
2.54k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
2.54k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
2.54k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
2.54k
                               (long)compptr->h_samp_factor),
395
2.54k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
2.54k
                               (long)compptr->v_samp_factor),
397
2.54k
         (JDIMENSION)access_rows);
398
2.54k
    }
399
847
    diff->pub.consume_data = consume_data;
400
847
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
847
  } else {
405
144
    diff->pub.consume_data = dummy_consume_data;
406
144
    diff->pub._decompress_data = decompress_data;
407
144
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
144
  }
409
991
}
j16init_d_diff_controller
Line
Count
Source
348
1.01k
{
349
1.01k
  my_diff_ptr diff;
350
1.01k
  int ci;
351
1.01k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
1.01k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.01k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.01k
  diff = (my_diff_ptr)
362
1.01k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.01k
                                sizeof(my_diff_controller));
364
1.01k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.01k
  diff->pub.start_input_pass = start_input_pass;
366
1.01k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
4.01k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
3.00k
       ci++, compptr++) {
371
3.00k
    diff->diff_buf[ci] =
372
3.00k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
3.00k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
3.00k
                                         (long)compptr->h_samp_factor),
375
3.00k
                   (JDIMENSION)compptr->v_samp_factor);
376
3.00k
    diff->undiff_buf[ci] =
377
3.00k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
3.00k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
3.00k
                                         (long)compptr->h_samp_factor),
380
3.00k
                   (JDIMENSION)compptr->v_samp_factor);
381
3.00k
  }
382
383
1.01k
  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
144
    diff->pub.consume_data = dummy_consume_data;
406
144
    diff->pub._decompress_data = decompress_data;
407
144
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
144
  }
409
1.01k
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */