Coverage Report

Created: 2026-08-31 07:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/src/jddiffct.c
Line
Count
Source
1
/*
2
 * jddiffct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1997, Thomas G. Lane.
6
 * Lossless JPEG Modifications:
7
 * Copyright (C) 1999, Ken Murchison.
8
 * libjpeg-turbo Modifications:
9
 * Copyright (C) 2022, 2024, D. R. Commander.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the [un]difference buffer controller for decompression.
14
 * This controller is the top level of the lossless JPEG decompressor proper.
15
 * The difference buffer lies between the entropy decoding and
16
 * prediction/undifferencing steps.  The undifference buffer lies between the
17
 * prediction/undifferencing and scaling steps.
18
 *
19
 * In buffered-image mode, this controller is the interface between
20
 * input-oriented processing and output-oriented processing.
21
 */
22
23
#define JPEG_INTERNALS
24
#include "jinclude.h"
25
#include "jpeglib.h"
26
#include "jlossls.h"            /* Private declarations for lossless codec */
27
28
29
#ifdef D_LOSSLESS_SUPPORTED
30
31
/* Private buffer controller object */
32
33
typedef struct {
34
  struct jpeg_d_coef_controller pub; /* public fields */
35
36
  /* These variables keep track of the current location of the input side. */
37
  /* cinfo->input_iMCU_row is also used for this. */
38
  JDIMENSION MCU_ctr;           /* counts MCUs processed in current row */
39
  unsigned int restart_rows_to_go;      /* MCU rows left in this restart
40
                                           interval */
41
  unsigned int MCU_vert_offset;         /* counts MCU rows within iMCU row */
42
  unsigned int MCU_rows_per_iMCU_row;   /* number of such rows needed */
43
44
  /* The output side's location is represented by cinfo->output_iMCU_row. */
45
46
  JDIFFARRAY diff_buf[MAX_COMPONENTS];  /* iMCU row of differences */
47
  JDIFFARRAY undiff_buf[MAX_COMPONENTS]; /* iMCU row of undiff'd samples */
48
49
#ifdef D_MULTISCAN_FILES_SUPPORTED
50
  /* In multi-pass modes, we need a virtual sample array for each component. */
51
  jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
52
#endif
53
} my_diff_controller;
54
55
typedef my_diff_controller *my_diff_ptr;
56
57
/* Forward declarations */
58
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
59
#ifdef D_MULTISCAN_FILES_SUPPORTED
60
METHODDEF(int) output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
61
#endif
62
63
64
LOCAL(void)
65
start_iMCU_row(j_decompress_ptr cinfo)
66
/* Reset within-iMCU-row counters for a new row (input side) */
67
204M
{
68
204M
  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
204M
  if (cinfo->comps_in_scan > 1) {
75
45.9M
    diff->MCU_rows_per_iMCU_row = 1;
76
158M
  } else {
77
158M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
158M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
30.6k
    else
80
30.6k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
158M
  }
82
83
204M
  diff->MCU_ctr = 0;
84
204M
  diff->MCU_vert_offset = 0;
85
204M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
46.4M
{
68
46.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
46.4M
  if (cinfo->comps_in_scan > 1) {
75
12.1M
    diff->MCU_rows_per_iMCU_row = 1;
76
34.2M
  } else {
77
34.2M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
34.2M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
9.74k
    else
80
9.74k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
34.2M
  }
82
83
46.4M
  diff->MCU_ctr = 0;
84
46.4M
  diff->MCU_vert_offset = 0;
85
46.4M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
61.6M
{
68
61.6M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
61.6M
  if (cinfo->comps_in_scan > 1) {
75
12.3M
    diff->MCU_rows_per_iMCU_row = 1;
76
49.3M
  } else {
77
49.3M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
49.3M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
7.76k
    else
80
7.76k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
49.3M
  }
82
83
61.6M
  diff->MCU_ctr = 0;
84
61.6M
  diff->MCU_vert_offset = 0;
85
61.6M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
96.4M
{
68
96.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
96.4M
  if (cinfo->comps_in_scan > 1) {
75
21.4M
    diff->MCU_rows_per_iMCU_row = 1;
76
74.9M
  } else {
77
74.9M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
74.9M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
13.0k
    else
80
13.0k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
74.9M
  }
82
83
96.4M
  diff->MCU_ctr = 0;
84
96.4M
  diff->MCU_vert_offset = 0;
85
96.4M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
42.3k
{
95
42.3k
  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
42.3k
  (*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
42.3k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
372
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
42.3k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
42.3k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
42.3k
  cinfo->input_iMCU_row = 0;
115
42.3k
  start_iMCU_row(cinfo);
116
42.3k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
14.2k
{
95
14.2k
  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
14.2k
  (*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
14.2k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
96
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
14.2k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
14.2k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
14.2k
  cinfo->input_iMCU_row = 0;
115
14.2k
  start_iMCU_row(cinfo);
116
14.2k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
10.9k
{
95
10.9k
  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
10.9k
  (*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
10.9k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
107
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
10.9k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
10.9k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
10.9k
  cinfo->input_iMCU_row = 0;
115
10.9k
  start_iMCU_row(cinfo);
116
10.9k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
17.1k
{
95
17.1k
  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
17.1k
  (*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
17.1k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
169
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
17.1k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
17.1k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
17.1k
  cinfo->input_iMCU_row = 0;
115
17.1k
  start_iMCU_row(cinfo);
116
17.1k
}
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
76.4M
{
127
76.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
76.4M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
76.4M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
76.4M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
76.4M
  return TRUE;
138
76.4M
}
jddiffct-8.c:process_restart
Line
Count
Source
126
15.1M
{
127
15.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
15.1M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
15.1M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
15.1M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
15.1M
  return TRUE;
138
15.1M
}
jddiffct-12.c:process_restart
Line
Count
Source
126
3.60M
{
127
3.60M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
3.60M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
3.60M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
3.60M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
3.60M
  return TRUE;
138
3.60M
}
jddiffct-16.c:process_restart
Line
Count
Source
126
57.6M
{
127
57.6M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
57.6M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
57.6M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
57.6M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
57.6M
  return TRUE;
138
57.6M
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
11.3k
{
148
11.3k
  cinfo->output_iMCU_row = 0;
149
11.3k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
4.65k
{
148
4.65k
  cinfo->output_iMCU_row = 0;
149
4.65k
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
3.29k
{
148
3.29k
  cinfo->output_iMCU_row = 0;
149
3.29k
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
3.35k
{
148
3.35k
  cinfo->output_iMCU_row = 0;
149
3.35k
}
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
204M
{
165
204M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
204M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
204M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
204M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
204M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
204M
  int ci, compi, row, prev_row;
171
204M
  unsigned int yoffset;
172
204M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
514M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
309M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
309M
    if (cinfo->restart_interval) {
180
116M
      if (diff->restart_rows_to_go == 0)
181
76.4M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
116M
    }
184
185
309M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
309M
    MCU_count =
188
309M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
309M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
309M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
309M
    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
309M
    if (cinfo->restart_interval)
200
116M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
309M
    diff->MCU_ctr = 0;
204
309M
  }
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
467M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
263M
    compptr = cinfo->cur_comp_info[ci];
213
263M
    compi = compptr->component_index;
214
263M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
675M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
675M
                compptr->last_row_height : compptr->v_samp_factor);
217
412M
         prev_row = row, row++) {
218
412M
      (*losslessd->predict_undifference[compi])
219
412M
        (cinfo, compi, diff->diff_buf[compi][row],
220
412M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
412M
          compptr->width_in_blocks);
222
412M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
412M
                                  output_buf[compi][row],
224
412M
                                  compptr->width_in_blocks);
225
412M
    }
226
263M
  }
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
204M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
204M
    start_iMCU_row(cinfo);
236
204M
    return JPEG_ROW_COMPLETED;
237
204M
  }
238
  /* Completed the scan */
239
40.2k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
40.2k
  return JPEG_SCAN_COMPLETED;
241
204M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
46.4M
{
165
46.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
46.4M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
46.4M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
46.4M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
46.4M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
46.4M
  int ci, compi, row, prev_row;
171
46.4M
  unsigned int yoffset;
172
46.4M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
120M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
74.5M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
74.5M
    if (cinfo->restart_interval) {
180
25.2M
      if (diff->restart_rows_to_go == 0)
181
15.1M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
25.2M
    }
184
185
74.5M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
74.5M
    MCU_count =
188
74.5M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
74.5M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
74.5M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
74.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
74.5M
    if (cinfo->restart_interval)
200
25.2M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
74.5M
    diff->MCU_ctr = 0;
204
74.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
112M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
65.5M
    compptr = cinfo->cur_comp_info[ci];
213
65.5M
    compi = compptr->component_index;
214
65.5M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
177M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
177M
                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
65.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
46.4M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
46.4M
    start_iMCU_row(cinfo);
236
46.4M
    return JPEG_ROW_COMPLETED;
237
46.4M
  }
238
  /* Completed the scan */
239
13.5k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
13.5k
  return JPEG_SCAN_COMPLETED;
241
46.4M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
61.6M
{
165
61.6M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
61.6M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
61.6M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
61.6M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
61.6M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
61.6M
  int ci, compi, row, prev_row;
171
61.6M
  unsigned int yoffset;
172
61.6M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
164M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
103M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
103M
    if (cinfo->restart_interval) {
180
21.4M
      if (diff->restart_rows_to_go == 0)
181
3.60M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
21.4M
    }
184
185
103M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
103M
    MCU_count =
188
103M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
103M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
103M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
103M
    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
103M
    if (cinfo->restart_interval)
200
21.4M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
103M
    diff->MCU_ctr = 0;
204
103M
  }
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
137M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
75.3M
    compptr = cinfo->cur_comp_info[ci];
213
75.3M
    compi = compptr->component_index;
214
75.3M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
199M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
199M
                compptr->last_row_height : compptr->v_samp_factor);
217
124M
         prev_row = row, row++) {
218
124M
      (*losslessd->predict_undifference[compi])
219
124M
        (cinfo, compi, diff->diff_buf[compi][row],
220
124M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
124M
          compptr->width_in_blocks);
222
124M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
124M
                                  output_buf[compi][row],
224
124M
                                  compptr->width_in_blocks);
225
124M
    }
226
75.3M
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
61.6M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
61.6M
    start_iMCU_row(cinfo);
236
61.6M
    return JPEG_ROW_COMPLETED;
237
61.6M
  }
238
  /* Completed the scan */
239
10.3k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
10.3k
  return JPEG_SCAN_COMPLETED;
241
61.6M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
96.4M
{
165
96.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
96.4M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
96.4M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
96.4M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
96.4M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
96.4M
  int ci, compi, row, prev_row;
171
96.4M
  unsigned int yoffset;
172
96.4M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
228M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
132M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
132M
    if (cinfo->restart_interval) {
180
69.3M
      if (diff->restart_rows_to_go == 0)
181
57.6M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
69.3M
    }
184
185
132M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
132M
    MCU_count =
188
132M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
132M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
132M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
132M
    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
132M
    if (cinfo->restart_interval)
200
69.3M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
132M
    diff->MCU_ctr = 0;
204
132M
  }
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
218M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
122M
    compptr = cinfo->cur_comp_info[ci];
213
122M
    compi = compptr->component_index;
214
122M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
298M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
297M
                compptr->last_row_height : compptr->v_samp_factor);
217
175M
         prev_row = row, row++) {
218
175M
      (*losslessd->predict_undifference[compi])
219
175M
        (cinfo, compi, diff->diff_buf[compi][row],
220
175M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
175M
          compptr->width_in_blocks);
222
175M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
175M
                                  output_buf[compi][row],
224
175M
                                  compptr->width_in_blocks);
225
175M
    }
226
122M
  }
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
96.4M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
96.4M
    start_iMCU_row(cinfo);
236
96.4M
    return JPEG_ROW_COMPLETED;
237
96.4M
  }
238
  /* Completed the scan */
239
16.3k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
16.3k
  return JPEG_SCAN_COMPLETED;
241
96.4M
}
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
192M
{
267
192M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
192M
  int ci, compi;
269
192M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
192M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
439M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
246M
    compptr = cinfo->cur_comp_info[ci];
275
246M
    compi = compptr->component_index;
276
246M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
246M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
246M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
246M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
246M
  }
281
282
192M
  return decompress_data(cinfo, buffer);
283
192M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
42.3M
{
267
42.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
42.3M
  int ci, compi;
269
42.3M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
42.3M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
101M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
59.2M
    compptr = cinfo->cur_comp_info[ci];
275
59.2M
    compi = compptr->component_index;
276
59.2M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
59.2M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
59.2M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
59.2M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
59.2M
  }
281
282
42.3M
  return decompress_data(cinfo, buffer);
283
42.3M
}
jddiffct-12.c:consume_data
Line
Count
Source
266
58.0M
{
267
58.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
58.0M
  int ci, compi;
269
58.0M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
58.0M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
128M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
70.8M
    compptr = cinfo->cur_comp_info[ci];
275
70.8M
    compi = compptr->component_index;
276
70.8M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
70.8M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
70.8M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
70.8M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
70.8M
  }
281
282
58.0M
  return decompress_data(cinfo, buffer);
283
58.0M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
92.4M
{
267
92.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
92.4M
  int ci, compi;
269
92.4M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
92.4M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
209M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
116M
    compptr = cinfo->cur_comp_info[ci];
275
116M
    compi = compptr->component_index;
276
116M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
116M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
116M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
116M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
116M
  }
281
282
92.4M
  return decompress_data(cinfo, buffer);
283
92.4M
}
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
3.25M
{
297
3.25M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
3.25M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
3.25M
  int ci, samp_rows, row;
300
3.25M
  _JSAMPARRAY buffer;
301
3.25M
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
5.41M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
5.41M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
5.41M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
2.16M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
2.16M
  }
310
311
  /* OK, output from the virtual arrays. */
312
14.3M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
11.0M
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
11.0M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
11.0M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
11.0M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
11.0M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
11.0M
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
11.0M
      samp_rows = compptr->v_samp_factor;
322
6.61k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
6.61k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
6.61k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
6.61k
    }
327
328
31.3M
    for (row = 0; row < samp_rows; row++) {
329
20.3M
      memcpy(output_buf[ci][row], buffer[row],
330
20.3M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
20.3M
    }
332
11.0M
  }
333
334
3.25M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
3.24M
    return JPEG_ROW_COMPLETED;
336
2.90k
  return JPEG_SCAN_COMPLETED;
337
3.25M
}
jddiffct-8.c:output_data
Line
Count
Source
296
2.56M
{
297
2.56M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
2.56M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
2.56M
  int ci, samp_rows, row;
300
2.56M
  _JSAMPARRAY buffer;
301
2.56M
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
4.73M
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
4.73M
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
4.73M
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
2.16M
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
2.16M
  }
310
311
  /* OK, output from the virtual arrays. */
312
11.4M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
8.83M
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
8.83M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
8.83M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
8.83M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
8.83M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
8.83M
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
8.83M
      samp_rows = compptr->v_samp_factor;
322
4.98k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
4.98k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
4.98k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
4.98k
    }
327
328
25.9M
    for (row = 0; row < samp_rows; row++) {
329
17.0M
      memcpy(output_buf[ci][row], buffer[row],
330
17.0M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
17.0M
    }
332
8.83M
  }
333
334
2.56M
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
2.56M
    return JPEG_ROW_COMPLETED;
336
1.90k
  return JPEG_SCAN_COMPLETED;
337
2.56M
}
jddiffct-12.c:output_data
Line
Count
Source
296
242k
{
297
242k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
242k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
242k
  int ci, samp_rows, row;
300
242k
  _JSAMPARRAY buffer;
301
242k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
242k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
242k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
242k
          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
1.06M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
823k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
823k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
823k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
823k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
823k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
823k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
823k
      samp_rows = compptr->v_samp_factor;
322
724
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
724
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
724
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
724
    }
327
328
1.92M
    for (row = 0; row < samp_rows; row++) {
329
1.10M
      memcpy(output_buf[ci][row], buffer[row],
330
1.10M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1.10M
    }
332
823k
  }
333
334
242k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
242k
    return JPEG_ROW_COMPLETED;
336
400
  return JPEG_SCAN_COMPLETED;
337
242k
}
jddiffct-16.c:output_data
Line
Count
Source
296
439k
{
297
439k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
439k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
439k
  int ci, samp_rows, row;
300
439k
  _JSAMPARRAY buffer;
301
439k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
439k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
439k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
439k
          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
1.84M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
1.40M
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
1.40M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
1.40M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
1.40M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
1.40M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
1.40M
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1.40M
      samp_rows = compptr->v_samp_factor;
322
905
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
905
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
905
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
905
    }
327
328
3.56M
    for (row = 0; row < samp_rows; row++) {
329
2.16M
      memcpy(output_buf[ci][row], buffer[row],
330
2.16M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
2.16M
    }
332
1.40M
  }
333
334
439k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
438k
    return JPEG_ROW_COMPLETED;
336
600
  return JPEG_SCAN_COMPLETED;
337
439k
}
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
19.0k
{
349
19.0k
  my_diff_ptr diff;
350
19.0k
  int ci;
351
19.0k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
6.39k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
12.6k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
12.6k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
19.0k
  diff = (my_diff_ptr)
362
19.0k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
19.0k
                                sizeof(my_diff_controller));
364
19.0k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
19.0k
  diff->pub.start_input_pass = start_input_pass;
366
19.0k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
70.1k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
51.0k
       ci++, compptr++) {
371
51.0k
    diff->diff_buf[ci] =
372
51.0k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
51.0k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
51.0k
                                         (long)compptr->h_samp_factor),
375
51.0k
                   (JDIMENSION)compptr->v_samp_factor);
376
51.0k
    diff->undiff_buf[ci] =
377
51.0k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
51.0k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
51.0k
                                         (long)compptr->h_samp_factor),
380
51.0k
                   (JDIMENSION)compptr->v_samp_factor);
381
51.0k
  }
382
383
19.0k
  if (need_full_buffer) {
384
14.7k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
14.7k
    int access_rows;
387
388
58.5k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
43.7k
         ci++, compptr++) {
390
43.7k
      access_rows = compptr->v_samp_factor;
391
43.7k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
43.7k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
43.7k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
43.7k
                               (long)compptr->h_samp_factor),
395
43.7k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
43.7k
                               (long)compptr->v_samp_factor),
397
43.7k
         (JDIMENSION)access_rows);
398
43.7k
    }
399
14.7k
    diff->pub.consume_data = consume_data;
400
14.7k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
14.7k
  } else {
405
4.32k
    diff->pub.consume_data = dummy_consume_data;
406
4.32k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
4.32k
  }
409
19.0k
}
jinit_d_diff_controller
Line
Count
Source
348
6.39k
{
349
6.39k
  my_diff_ptr diff;
350
6.39k
  int ci;
351
6.39k
  jpeg_component_info *compptr;
352
353
6.39k
#if BITS_IN_JSAMPLE == 8
354
6.39k
  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
6.39k
  diff = (my_diff_ptr)
362
6.39k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
6.39k
                                sizeof(my_diff_controller));
364
6.39k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
6.39k
  diff->pub.start_input_pass = start_input_pass;
366
6.39k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
23.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
17.2k
       ci++, compptr++) {
371
17.2k
    diff->diff_buf[ci] =
372
17.2k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
17.2k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
17.2k
                                         (long)compptr->h_samp_factor),
375
17.2k
                   (JDIMENSION)compptr->v_samp_factor);
376
17.2k
    diff->undiff_buf[ci] =
377
17.2k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
17.2k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
17.2k
                                         (long)compptr->h_samp_factor),
380
17.2k
                   (JDIMENSION)compptr->v_samp_factor);
381
17.2k
  }
382
383
6.39k
  if (need_full_buffer) {
384
5.11k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
5.11k
    int access_rows;
387
388
20.3k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
15.2k
         ci++, compptr++) {
390
15.2k
      access_rows = compptr->v_samp_factor;
391
15.2k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
15.2k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
15.2k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
15.2k
                               (long)compptr->h_samp_factor),
395
15.2k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
15.2k
                               (long)compptr->v_samp_factor),
397
15.2k
         (JDIMENSION)access_rows);
398
15.2k
    }
399
5.11k
    diff->pub.consume_data = consume_data;
400
5.11k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
5.11k
  } else {
405
1.27k
    diff->pub.consume_data = dummy_consume_data;
406
1.27k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
1.27k
  }
409
6.39k
}
j12init_d_diff_controller
Line
Count
Source
348
6.17k
{
349
6.17k
  my_diff_ptr diff;
350
6.17k
  int ci;
351
6.17k
  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
6.17k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
6.17k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
6.17k
  diff = (my_diff_ptr)
362
6.17k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
6.17k
                                sizeof(my_diff_controller));
364
6.17k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
6.17k
  diff->pub.start_input_pass = start_input_pass;
366
6.17k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
22.3k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
16.2k
       ci++, compptr++) {
371
16.2k
    diff->diff_buf[ci] =
372
16.2k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
16.2k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
16.2k
                                         (long)compptr->h_samp_factor),
375
16.2k
                   (JDIMENSION)compptr->v_samp_factor);
376
16.2k
    diff->undiff_buf[ci] =
377
16.2k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
16.2k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
16.2k
                                         (long)compptr->h_samp_factor),
380
16.2k
                   (JDIMENSION)compptr->v_samp_factor);
381
16.2k
  }
382
383
6.17k
  if (need_full_buffer) {
384
4.51k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
4.51k
    int access_rows;
387
388
17.9k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
13.4k
         ci++, compptr++) {
390
13.4k
      access_rows = compptr->v_samp_factor;
391
13.4k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
13.4k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
13.4k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
13.4k
                               (long)compptr->h_samp_factor),
395
13.4k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
13.4k
                               (long)compptr->v_samp_factor),
397
13.4k
         (JDIMENSION)access_rows);
398
13.4k
    }
399
4.51k
    diff->pub.consume_data = consume_data;
400
4.51k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
4.51k
  } else {
405
1.65k
    diff->pub.consume_data = dummy_consume_data;
406
1.65k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
1.65k
  }
409
6.17k
}
j16init_d_diff_controller
Line
Count
Source
348
6.50k
{
349
6.50k
  my_diff_ptr diff;
350
6.50k
  int ci;
351
6.50k
  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
6.50k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
6.50k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
6.50k
  diff = (my_diff_ptr)
362
6.50k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
6.50k
                                sizeof(my_diff_controller));
364
6.50k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
6.50k
  diff->pub.start_input_pass = start_input_pass;
366
6.50k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
24.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
17.5k
       ci++, compptr++) {
371
17.5k
    diff->diff_buf[ci] =
372
17.5k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
17.5k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
17.5k
                                         (long)compptr->h_samp_factor),
375
17.5k
                   (JDIMENSION)compptr->v_samp_factor);
376
17.5k
    diff->undiff_buf[ci] =
377
17.5k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
17.5k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
17.5k
                                         (long)compptr->h_samp_factor),
380
17.5k
                   (JDIMENSION)compptr->v_samp_factor);
381
17.5k
  }
382
383
6.50k
  if (need_full_buffer) {
384
5.11k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
5.11k
    int access_rows;
387
388
20.2k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
15.1k
         ci++, compptr++) {
390
15.1k
      access_rows = compptr->v_samp_factor;
391
15.1k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
15.1k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
15.1k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
15.1k
                               (long)compptr->h_samp_factor),
395
15.1k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
15.1k
                               (long)compptr->v_samp_factor),
397
15.1k
         (JDIMENSION)access_rows);
398
15.1k
    }
399
5.11k
    diff->pub.consume_data = consume_data;
400
5.11k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
5.11k
  } else {
405
1.39k
    diff->pub.consume_data = dummy_consume_data;
406
1.39k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
1.39k
  }
409
6.50k
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */