Coverage Report

Created: 2026-09-13 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo/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
9.10M
{
68
9.10M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
9.10M
  if (cinfo->comps_in_scan > 1) {
75
4.02M
    diff->MCU_rows_per_iMCU_row = 1;
76
5.07M
  } else {
77
5.07M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
5.03M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
44.1k
    else
80
44.1k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
5.07M
  }
82
83
9.10M
  diff->MCU_ctr = 0;
84
9.10M
  diff->MCU_vert_offset = 0;
85
9.10M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
3.98M
{
68
3.98M
  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
3.98M
  if (cinfo->comps_in_scan > 1) {
75
1.62M
    diff->MCU_rows_per_iMCU_row = 1;
76
2.35M
  } else {
77
2.35M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
2.33M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
20.1k
    else
80
20.1k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
2.35M
  }
82
83
3.98M
  diff->MCU_ctr = 0;
84
3.98M
  diff->MCU_vert_offset = 0;
85
3.98M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
2.16M
{
68
2.16M
  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
2.16M
  if (cinfo->comps_in_scan > 1) {
75
966k
    diff->MCU_rows_per_iMCU_row = 1;
76
1.20M
  } else {
77
1.20M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
1.19M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
10.2k
    else
80
10.2k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
1.20M
  }
82
83
2.16M
  diff->MCU_ctr = 0;
84
2.16M
  diff->MCU_vert_offset = 0;
85
2.16M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
2.95M
{
68
2.95M
  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
2.95M
  if (cinfo->comps_in_scan > 1) {
75
1.42M
    diff->MCU_rows_per_iMCU_row = 1;
76
1.52M
  } else {
77
1.52M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
1.50M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
13.7k
    else
80
13.7k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
1.52M
  }
82
83
2.95M
  diff->MCU_ctr = 0;
84
2.95M
  diff->MCU_vert_offset = 0;
85
2.95M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
74.7k
{
95
74.7k
  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
74.7k
  (*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
74.7k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
112
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
74.7k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
74.7k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
74.7k
  cinfo->input_iMCU_row = 0;
115
74.7k
  start_iMCU_row(cinfo);
116
74.7k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
31.6k
{
95
31.6k
  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
31.6k
  (*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
31.6k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
46
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
31.6k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
31.6k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
31.6k
  cinfo->input_iMCU_row = 0;
115
31.6k
  start_iMCU_row(cinfo);
116
31.6k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
19.6k
{
95
19.6k
  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
19.6k
  (*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
19.6k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
33
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
19.6k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
19.6k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
19.6k
  cinfo->input_iMCU_row = 0;
115
19.6k
  start_iMCU_row(cinfo);
116
19.6k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
23.4k
{
95
23.4k
  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
23.4k
  (*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
23.4k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
33
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
23.4k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
23.4k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
23.4k
  cinfo->input_iMCU_row = 0;
115
23.4k
  start_iMCU_row(cinfo);
116
23.4k
}
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
405k
{
127
405k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
405k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
405k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
405k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
405k
  return TRUE;
138
405k
}
jddiffct-8.c:process_restart
Line
Count
Source
126
172k
{
127
172k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
172k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
172k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
172k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
172k
  return TRUE;
138
172k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
34.3k
{
127
34.3k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
34.3k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
34.3k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
34.3k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
34.3k
  return TRUE;
138
34.3k
}
jddiffct-16.c:process_restart
Line
Count
Source
126
198k
{
127
198k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
198k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
198k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
198k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
198k
  return TRUE;
138
198k
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
24.3k
{
148
24.3k
  cinfo->output_iMCU_row = 0;
149
24.3k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
14.2k
{
148
14.2k
  cinfo->output_iMCU_row = 0;
149
14.2k
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
4.27k
{
148
4.27k
  cinfo->output_iMCU_row = 0;
149
4.27k
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
5.89k
{
148
5.89k
  cinfo->output_iMCU_row = 0;
149
5.89k
}
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
9.10M
{
165
9.10M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
9.10M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
9.10M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
9.10M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
9.10M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
9.10M
  int ci, compi, row, prev_row;
171
9.10M
  unsigned int yoffset;
172
9.10M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
22.0M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
12.9M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
12.9M
    if (cinfo->restart_interval) {
180
1.55M
      if (diff->restart_rows_to_go == 0)
181
405k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.55M
    }
184
185
12.9M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
12.9M
    MCU_count =
188
12.9M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
12.9M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
12.9M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
12.9M
    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.9M
    if (cinfo->restart_interval)
200
1.55M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
12.9M
    diff->MCU_ctr = 0;
204
12.9M
  }
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
25.1M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
16.0M
    compptr = cinfo->cur_comp_info[ci];
213
16.0M
    compi = compptr->component_index;
214
16.0M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
44.0M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
43.7M
                compptr->last_row_height : compptr->v_samp_factor);
217
28.0M
         prev_row = row, row++) {
218
28.0M
      (*losslessd->predict_undifference[compi])
219
28.0M
        (cinfo, compi, diff->diff_buf[compi][row],
220
28.0M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
28.0M
          compptr->width_in_blocks);
222
28.0M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
28.0M
                                  output_buf[compi][row],
224
28.0M
                                  compptr->width_in_blocks);
225
28.0M
    }
226
16.0M
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
9.10M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
9.02M
    start_iMCU_row(cinfo);
236
9.02M
    return JPEG_ROW_COMPLETED;
237
9.02M
  }
238
  /* Completed the scan */
239
72.9k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
72.9k
  return JPEG_SCAN_COMPLETED;
241
9.10M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
3.98M
{
165
3.98M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
3.98M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
3.98M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
3.98M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
3.98M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
3.98M
  int ci, compi, row, prev_row;
171
3.98M
  unsigned int yoffset;
172
3.98M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
9.40M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
5.42M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
5.42M
    if (cinfo->restart_interval) {
180
798k
      if (diff->restart_rows_to_go == 0)
181
172k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
798k
    }
184
185
5.42M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
5.42M
    MCU_count =
188
5.42M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
5.42M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
5.42M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
5.42M
    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
5.42M
    if (cinfo->restart_interval)
200
798k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
5.42M
    diff->MCU_ctr = 0;
204
5.42M
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
11.0M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
7.03M
    compptr = cinfo->cur_comp_info[ci];
213
7.03M
    compi = compptr->component_index;
214
7.03M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
19.0M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
18.8M
                compptr->last_row_height : compptr->v_samp_factor);
217
11.9M
         prev_row = row, row++) {
218
11.9M
      (*losslessd->predict_undifference[compi])
219
11.9M
        (cinfo, compi, diff->diff_buf[compi][row],
220
11.9M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
11.9M
          compptr->width_in_blocks);
222
11.9M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
11.9M
                                  output_buf[compi][row],
224
11.9M
                                  compptr->width_in_blocks);
225
11.9M
    }
226
7.03M
  }
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
3.98M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
3.94M
    start_iMCU_row(cinfo);
236
3.94M
    return JPEG_ROW_COMPLETED;
237
3.94M
  }
238
  /* Completed the scan */
239
30.7k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
30.7k
  return JPEG_SCAN_COMPLETED;
241
3.98M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
2.16M
{
165
2.16M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
2.16M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
2.16M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
2.16M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
2.16M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
2.16M
  int ci, compi, row, prev_row;
171
2.16M
  unsigned int yoffset;
172
2.16M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
5.28M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
3.11M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
3.11M
    if (cinfo->restart_interval) {
180
303k
      if (diff->restart_rows_to_go == 0)
181
34.3k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
303k
    }
184
185
3.11M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
3.11M
    MCU_count =
188
3.11M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
3.11M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
3.11M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
3.11M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
3.11M
    if (cinfo->restart_interval)
200
303k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
3.11M
    diff->MCU_ctr = 0;
204
3.11M
  }
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
5.85M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
3.68M
    compptr = cinfo->cur_comp_info[ci];
213
3.68M
    compi = compptr->component_index;
214
3.68M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
10.4M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
10.3M
                compptr->last_row_height : compptr->v_samp_factor);
217
6.76M
         prev_row = row, row++) {
218
6.76M
      (*losslessd->predict_undifference[compi])
219
6.76M
        (cinfo, compi, diff->diff_buf[compi][row],
220
6.76M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
6.76M
          compptr->width_in_blocks);
222
6.76M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
6.76M
                                  output_buf[compi][row],
224
6.76M
                                  compptr->width_in_blocks);
225
6.76M
    }
226
3.68M
  }
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
2.16M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
2.14M
    start_iMCU_row(cinfo);
236
2.14M
    return JPEG_ROW_COMPLETED;
237
2.14M
  }
238
  /* Completed the scan */
239
19.1k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
19.1k
  return JPEG_SCAN_COMPLETED;
241
2.16M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
2.95M
{
165
2.95M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
2.95M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
2.95M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
2.95M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
2.95M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
2.95M
  int ci, compi, row, prev_row;
171
2.95M
  unsigned int yoffset;
172
2.95M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
7.37M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
4.42M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
4.42M
    if (cinfo->restart_interval) {
180
456k
      if (diff->restart_rows_to_go == 0)
181
198k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
456k
    }
184
185
4.42M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
4.42M
    MCU_count =
188
4.42M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
4.42M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
4.42M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
4.42M
    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
4.42M
    if (cinfo->restart_interval)
200
456k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
4.42M
    diff->MCU_ctr = 0;
204
4.42M
  }
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
8.28M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
5.33M
    compptr = cinfo->cur_comp_info[ci];
213
5.33M
    compi = compptr->component_index;
214
5.33M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
14.6M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
14.5M
                compptr->last_row_height : compptr->v_samp_factor);
217
9.28M
         prev_row = row, row++) {
218
9.28M
      (*losslessd->predict_undifference[compi])
219
9.28M
        (cinfo, compi, diff->diff_buf[compi][row],
220
9.28M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
9.28M
          compptr->width_in_blocks);
222
9.28M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
9.28M
                                  output_buf[compi][row],
224
9.28M
                                  compptr->width_in_blocks);
225
9.28M
    }
226
5.33M
  }
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
2.95M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
2.92M
    start_iMCU_row(cinfo);
236
2.92M
    return JPEG_ROW_COMPLETED;
237
2.92M
  }
238
  /* Completed the scan */
239
22.9k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
22.9k
  return JPEG_SCAN_COMPLETED;
241
2.95M
}
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
7.87M
{
267
7.87M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
7.87M
  int ci, compi;
269
7.87M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
7.87M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
22.1M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
14.2M
    compptr = cinfo->cur_comp_info[ci];
275
14.2M
    compi = compptr->component_index;
276
14.2M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
14.2M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
14.2M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
14.2M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
14.2M
  }
281
282
7.87M
  return decompress_data(cinfo, buffer);
283
7.87M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
3.29M
{
267
3.29M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
3.29M
  int ci, compi;
269
3.29M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
3.29M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
9.46M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
6.16M
    compptr = cinfo->cur_comp_info[ci];
275
6.16M
    compi = compptr->component_index;
276
6.16M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
6.16M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
6.16M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
6.16M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
6.16M
  }
281
282
3.29M
  return decompress_data(cinfo, buffer);
283
3.29M
}
jddiffct-12.c:consume_data
Line
Count
Source
266
1.88M
{
267
1.88M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
1.88M
  int ci, compi;
269
1.88M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
1.88M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
5.04M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
3.15M
    compptr = cinfo->cur_comp_info[ci];
275
3.15M
    compi = compptr->component_index;
276
3.15M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
3.15M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
3.15M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
3.15M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
3.15M
  }
281
282
1.88M
  return decompress_data(cinfo, buffer);
283
1.88M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
2.69M
{
267
2.69M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
2.69M
  int ci, compi;
269
2.69M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
2.69M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
7.65M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
4.95M
    compptr = cinfo->cur_comp_info[ci];
275
4.95M
    compi = compptr->component_index;
276
4.95M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
4.95M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
4.95M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
4.95M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
4.95M
  }
281
282
2.69M
  return decompress_data(cinfo, buffer);
283
2.69M
}
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
295k
{
297
295k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
295k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
295k
  int ci, samp_rows, row;
300
295k
  _JSAMPARRAY buffer;
301
295k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
295k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
295k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
295k
          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.27M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
978k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
978k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
978k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
978k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
978k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
978k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
962k
      samp_rows = compptr->v_samp_factor;
322
16.5k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
16.5k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
16.5k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
16.5k
    }
327
328
2.54M
    for (row = 0; row < samp_rows; row++) {
329
1.56M
      memcpy(output_buf[ci][row], buffer[row],
330
1.56M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1.56M
    }
332
978k
  }
333
334
295k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
285k
    return JPEG_ROW_COMPLETED;
336
9.55k
  return JPEG_SCAN_COMPLETED;
337
295k
}
jddiffct-8.c:output_data
Line
Count
Source
296
95.9k
{
297
95.9k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
95.9k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
95.9k
  int ci, samp_rows, row;
300
95.9k
  _JSAMPARRAY buffer;
301
95.9k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
95.9k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
95.9k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
95.9k
          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
409k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
313k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
313k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
313k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
313k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
313k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
313k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
307k
      samp_rows = compptr->v_samp_factor;
322
5.25k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
5.25k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
5.25k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
5.25k
    }
327
328
824k
    for (row = 0; row < samp_rows; row++) {
329
511k
      memcpy(output_buf[ci][row], buffer[row],
330
511k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
511k
    }
332
313k
  }
333
334
95.9k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
93.0k
    return JPEG_ROW_COMPLETED;
336
2.88k
  return JPEG_SCAN_COMPLETED;
337
95.9k
}
jddiffct-12.c:output_data
Line
Count
Source
296
94.2k
{
297
94.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
94.2k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
94.2k
  int ci, samp_rows, row;
300
94.2k
  _JSAMPARRAY buffer;
301
94.2k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
94.2k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
94.2k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
94.2k
          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
403k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
309k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
309k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
309k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
309k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
309k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
309k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
305k
      samp_rows = compptr->v_samp_factor;
322
4.17k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
4.17k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
4.17k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
4.17k
    }
327
328
779k
    for (row = 0; row < samp_rows; row++) {
329
469k
      memcpy(output_buf[ci][row], buffer[row],
330
469k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
469k
    }
332
309k
  }
333
334
94.2k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
91.7k
    return JPEG_ROW_COMPLETED;
336
2.47k
  return JPEG_SCAN_COMPLETED;
337
94.2k
}
jddiffct-16.c:output_data
Line
Count
Source
296
104k
{
297
104k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
104k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
104k
  int ci, samp_rows, row;
300
104k
  _JSAMPARRAY buffer;
301
104k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
104k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
104k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
104k
          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
460k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
355k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
355k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
355k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
355k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
355k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
355k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
348k
      samp_rows = compptr->v_samp_factor;
322
7.16k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
7.16k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
7.16k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
7.16k
    }
327
328
936k
    for (row = 0; row < samp_rows; row++) {
329
581k
      memcpy(output_buf[ci][row], buffer[row],
330
581k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
581k
    }
332
355k
  }
333
334
104k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
100k
    return JPEG_ROW_COMPLETED;
336
4.19k
  return JPEG_SCAN_COMPLETED;
337
104k
}
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
30.6k
{
349
30.6k
  my_diff_ptr diff;
350
30.6k
  int ci;
351
30.6k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
16.5k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
14.0k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
14.0k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
30.6k
  diff = (my_diff_ptr)
362
30.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
30.6k
                                sizeof(my_diff_controller));
364
30.6k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
30.6k
  diff->pub.start_input_pass = start_input_pass;
366
30.6k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
122k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
91.7k
       ci++, compptr++) {
371
91.7k
    diff->diff_buf[ci] =
372
91.7k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
91.7k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
91.7k
                                         (long)compptr->h_samp_factor),
375
91.7k
                   (JDIMENSION)compptr->v_samp_factor);
376
91.7k
    diff->undiff_buf[ci] =
377
91.7k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
91.7k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
91.7k
                                         (long)compptr->h_samp_factor),
380
91.7k
                   (JDIMENSION)compptr->v_samp_factor);
381
91.7k
  }
382
383
30.6k
  if (need_full_buffer) {
384
16.7k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
16.7k
    int access_rows;
387
388
88.9k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
72.1k
         ci++, compptr++) {
390
72.1k
      access_rows = compptr->v_samp_factor;
391
72.1k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
72.1k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
72.1k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
72.1k
                               (long)compptr->h_samp_factor),
395
72.1k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
72.1k
                               (long)compptr->v_samp_factor),
397
72.1k
         (JDIMENSION)access_rows);
398
72.1k
    }
399
16.7k
    diff->pub.consume_data = consume_data;
400
16.7k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
16.7k
  } else {
405
13.9k
    diff->pub.consume_data = dummy_consume_data;
406
13.9k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
13.9k
  }
409
30.6k
}
jinit_d_diff_controller
Line
Count
Source
348
16.5k
{
349
16.5k
  my_diff_ptr diff;
350
16.5k
  int ci;
351
16.5k
  jpeg_component_info *compptr;
352
353
16.5k
#if BITS_IN_JSAMPLE == 8
354
16.5k
  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
16.5k
  diff = (my_diff_ptr)
362
16.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
16.5k
                                sizeof(my_diff_controller));
364
16.5k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
16.5k
  diff->pub.start_input_pass = start_input_pass;
366
16.5k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
52.4k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
35.9k
       ci++, compptr++) {
371
35.9k
    diff->diff_buf[ci] =
372
35.9k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
35.9k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
35.9k
                                         (long)compptr->h_samp_factor),
375
35.9k
                   (JDIMENSION)compptr->v_samp_factor);
376
35.9k
    diff->undiff_buf[ci] =
377
35.9k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
35.9k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
35.9k
                                         (long)compptr->h_samp_factor),
380
35.9k
                   (JDIMENSION)compptr->v_samp_factor);
381
35.9k
  }
382
383
16.5k
  if (need_full_buffer) {
384
5.25k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
5.25k
    int access_rows;
387
388
27.5k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
22.3k
         ci++, compptr++) {
390
22.3k
      access_rows = compptr->v_samp_factor;
391
22.3k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
22.3k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
22.3k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
22.3k
                               (long)compptr->h_samp_factor),
395
22.3k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
22.3k
                               (long)compptr->v_samp_factor),
397
22.3k
         (JDIMENSION)access_rows);
398
22.3k
    }
399
5.25k
    diff->pub.consume_data = consume_data;
400
5.25k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
11.3k
  } else {
405
11.3k
    diff->pub.consume_data = dummy_consume_data;
406
11.3k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
11.3k
  }
409
16.5k
}
j12init_d_diff_controller
Line
Count
Source
348
6.21k
{
349
6.21k
  my_diff_ptr diff;
350
6.21k
  int ci;
351
6.21k
  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.21k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
6.21k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
6.21k
  diff = (my_diff_ptr)
362
6.21k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
6.21k
                                sizeof(my_diff_controller));
364
6.21k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
6.21k
  diff->pub.start_input_pass = start_input_pass;
366
6.21k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
30.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
24.4k
       ci++, compptr++) {
371
24.4k
    diff->diff_buf[ci] =
372
24.4k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
24.4k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
24.4k
                                         (long)compptr->h_samp_factor),
375
24.4k
                   (JDIMENSION)compptr->v_samp_factor);
376
24.4k
    diff->undiff_buf[ci] =
377
24.4k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
24.4k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
24.4k
                                         (long)compptr->h_samp_factor),
380
24.4k
                   (JDIMENSION)compptr->v_samp_factor);
381
24.4k
  }
382
383
6.21k
  if (need_full_buffer) {
384
4.78k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
4.78k
    int access_rows;
387
388
25.9k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
21.1k
         ci++, compptr++) {
390
21.1k
      access_rows = compptr->v_samp_factor;
391
21.1k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
21.1k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
21.1k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
21.1k
                               (long)compptr->h_samp_factor),
395
21.1k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
21.1k
                               (long)compptr->v_samp_factor),
397
21.1k
         (JDIMENSION)access_rows);
398
21.1k
    }
399
4.78k
    diff->pub.consume_data = consume_data;
400
4.78k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
4.78k
  } else {
405
1.42k
    diff->pub.consume_data = dummy_consume_data;
406
1.42k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
1.42k
  }
409
6.21k
}
j16init_d_diff_controller
Line
Count
Source
348
7.84k
{
349
7.84k
  my_diff_ptr diff;
350
7.84k
  int ci;
351
7.84k
  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
7.84k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
7.84k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
7.84k
  diff = (my_diff_ptr)
362
7.84k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
7.84k
                                sizeof(my_diff_controller));
364
7.84k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
7.84k
  diff->pub.start_input_pass = start_input_pass;
366
7.84k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
39.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
31.3k
       ci++, compptr++) {
371
31.3k
    diff->diff_buf[ci] =
372
31.3k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
31.3k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
31.3k
                                         (long)compptr->h_samp_factor),
375
31.3k
                   (JDIMENSION)compptr->v_samp_factor);
376
31.3k
    diff->undiff_buf[ci] =
377
31.3k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
31.3k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
31.3k
                                         (long)compptr->h_samp_factor),
380
31.3k
                   (JDIMENSION)compptr->v_samp_factor);
381
31.3k
  }
382
383
7.84k
  if (need_full_buffer) {
384
6.68k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
6.68k
    int access_rows;
387
388
35.4k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
28.7k
         ci++, compptr++) {
390
28.7k
      access_rows = compptr->v_samp_factor;
391
28.7k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
28.7k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
28.7k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
28.7k
                               (long)compptr->h_samp_factor),
395
28.7k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
28.7k
                               (long)compptr->v_samp_factor),
397
28.7k
         (JDIMENSION)access_rows);
398
28.7k
    }
399
6.68k
    diff->pub.consume_data = consume_data;
400
6.68k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
6.68k
  } else {
405
1.16k
    diff->pub.consume_data = dummy_consume_data;
406
1.16k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
1.16k
  }
409
7.84k
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */