Coverage Report

Created: 2025-11-24 06:51

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
33.6k
{
68
33.6k
  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
33.6k
  if (cinfo->comps_in_scan > 1) {
75
5.45k
    diff->MCU_rows_per_iMCU_row = 1;
76
28.2k
  } else {
77
28.2k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
27.3k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
887
    else
80
887
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
28.2k
  }
82
83
33.6k
  diff->MCU_ctr = 0;
84
33.6k
  diff->MCU_vert_offset = 0;
85
33.6k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
10.0k
{
68
10.0k
  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
10.0k
  if (cinfo->comps_in_scan > 1) {
75
5.43k
    diff->MCU_rows_per_iMCU_row = 1;
76
5.43k
  } else {
77
4.62k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
4.27k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
353
    else
80
353
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
4.62k
  }
82
83
10.0k
  diff->MCU_ctr = 0;
84
10.0k
  diff->MCU_vert_offset = 0;
85
10.0k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
11.4k
{
68
11.4k
  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
11.4k
  if (cinfo->comps_in_scan > 1) {
75
12
    diff->MCU_rows_per_iMCU_row = 1;
76
11.4k
  } else {
77
11.4k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
11.1k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
272
    else
80
272
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
11.4k
  }
82
83
11.4k
  diff->MCU_ctr = 0;
84
11.4k
  diff->MCU_vert_offset = 0;
85
11.4k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
12.2k
{
68
12.2k
  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
12.2k
  if (cinfo->comps_in_scan > 1) {
75
8
    diff->MCU_rows_per_iMCU_row = 1;
76
12.2k
  } else {
77
12.2k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
11.9k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
262
    else
80
262
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
12.2k
  }
82
83
12.2k
  diff->MCU_ctr = 0;
84
12.2k
  diff->MCU_vert_offset = 0;
85
12.2k
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
2.24k
{
95
2.24k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
2.24k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
2.24k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
3
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
2.24k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
2.24k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
2.24k
  cinfo->input_iMCU_row = 0;
115
2.24k
  start_iMCU_row(cinfo);
116
2.24k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
844
{
95
844
  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
844
  (*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
844
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
844
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
844
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
844
  cinfo->input_iMCU_row = 0;
115
844
  start_iMCU_row(cinfo);
116
844
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
627
{
95
627
  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
627
  (*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
627
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
627
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
627
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
627
  cinfo->input_iMCU_row = 0;
115
627
  start_iMCU_row(cinfo);
116
627
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
773
{
95
773
  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
773
  (*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
773
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
773
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
773
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
773
  cinfo->input_iMCU_row = 0;
115
773
  start_iMCU_row(cinfo);
116
773
}
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
1
{
127
1
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
1
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
1
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
1
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
1
  return TRUE;
138
1
}
jddiffct-8.c:process_restart
Line
Count
Source
126
1
{
127
1
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
1
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
1
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
1
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
1
  return TRUE;
138
1
}
Unexecuted instantiation: jddiffct-12.c:process_restart
Unexecuted instantiation: jddiffct-16.c:process_restart
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
413
{
148
413
  cinfo->output_iMCU_row = 0;
149
413
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
392
{
148
392
  cinfo->output_iMCU_row = 0;
149
392
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
13
{
148
13
  cinfo->output_iMCU_row = 0;
149
13
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
8
{
148
8
  cinfo->output_iMCU_row = 0;
149
8
}
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
33.6k
{
165
33.6k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
33.6k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
33.6k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
33.6k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
33.6k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
33.6k
  int ci, compi, row, prev_row;
171
33.6k
  unsigned int yoffset;
172
33.6k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
78.7k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
45.0k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
45.0k
    if (cinfo->restart_interval) {
180
629
      if (diff->restart_rows_to_go == 0)
181
1
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
629
    }
184
185
45.0k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
45.0k
    MCU_count =
188
45.0k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
45.0k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
45.0k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
45.0k
    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
45.0k
    if (cinfo->restart_interval)
200
612
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
45.0k
    diff->MCU_ctr = 0;
204
45.0k
  }
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
76.3k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
42.6k
    compptr = cinfo->cur_comp_info[ci];
213
42.6k
    compi = compptr->component_index;
214
42.6k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
105k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
103k
                compptr->last_row_height : compptr->v_samp_factor);
217
63.1k
         prev_row = row, row++) {
218
63.1k
      (*losslessd->predict_undifference[compi])
219
63.1k
        (cinfo, compi, diff->diff_buf[compi][row],
220
63.1k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
63.1k
          compptr->width_in_blocks);
222
63.1k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
63.1k
                                  output_buf[compi][row],
224
63.1k
                                  compptr->width_in_blocks);
225
63.1k
    }
226
42.6k
  }
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
33.6k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
31.5k
    start_iMCU_row(cinfo);
236
31.5k
    return JPEG_ROW_COMPLETED;
237
31.5k
  }
238
  /* Completed the scan */
239
2.07k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
2.07k
  return JPEG_SCAN_COMPLETED;
241
33.6k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
10.0k
{
165
10.0k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
10.0k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
10.0k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
10.0k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
10.0k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
10.0k
  int ci, compi, row, prev_row;
171
10.0k
  unsigned int yoffset;
172
10.0k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
23.3k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
13.3k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
13.3k
    if (cinfo->restart_interval) {
180
629
      if (diff->restart_rows_to_go == 0)
181
1
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
629
    }
184
185
13.3k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
13.3k
    MCU_count =
188
13.3k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
13.3k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
13.3k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
13.3k
    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
13.3k
    if (cinfo->restart_interval)
200
612
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
13.3k
    diff->MCU_ctr = 0;
204
13.3k
  }
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
29.8k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
19.8k
    compptr = cinfo->cur_comp_info[ci];
213
19.8k
    compi = compptr->component_index;
214
19.8k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
52.0k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
51.2k
                compptr->last_row_height : compptr->v_samp_factor);
217
32.2k
         prev_row = row, row++) {
218
32.2k
      (*losslessd->predict_undifference[compi])
219
32.2k
        (cinfo, compi, diff->diff_buf[compi][row],
220
32.2k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
32.2k
          compptr->width_in_blocks);
222
32.2k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
32.2k
                                  output_buf[compi][row],
224
32.2k
                                  compptr->width_in_blocks);
225
32.2k
    }
226
19.8k
  }
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
10.0k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
9.25k
    start_iMCU_row(cinfo);
236
9.25k
    return JPEG_ROW_COMPLETED;
237
9.25k
  }
238
  /* Completed the scan */
239
797
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
797
  return JPEG_SCAN_COMPLETED;
241
10.0k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
11.4k
{
165
11.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
11.4k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
11.4k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
11.4k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
11.4k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
11.4k
  int ci, compi, row, prev_row;
171
11.4k
  unsigned int yoffset;
172
11.4k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
26.6k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
15.2k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
15.2k
    if (cinfo->restart_interval) {
180
0
      if (diff->restart_rows_to_go == 0)
181
0
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
0
    }
184
185
15.2k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
15.2k
    MCU_count =
188
15.2k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
15.2k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
15.2k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
15.2k
    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
15.2k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
15.2k
    diff->MCU_ctr = 0;
204
15.2k
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
22.5k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
11.1k
    compptr = cinfo->cur_comp_info[ci];
213
11.1k
    compi = compptr->component_index;
214
11.1k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
25.9k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
25.2k
                compptr->last_row_height : compptr->v_samp_factor);
217
14.8k
         prev_row = row, row++) {
218
14.8k
      (*losslessd->predict_undifference[compi])
219
14.8k
        (cinfo, compi, diff->diff_buf[compi][row],
220
14.8k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
14.8k
          compptr->width_in_blocks);
222
14.8k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
14.8k
                                  output_buf[compi][row],
224
14.8k
                                  compptr->width_in_blocks);
225
14.8k
    }
226
11.1k
  }
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
11.4k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
10.8k
    start_iMCU_row(cinfo);
236
10.8k
    return JPEG_ROW_COMPLETED;
237
10.8k
  }
238
  /* Completed the scan */
239
578
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
578
  return JPEG_SCAN_COMPLETED;
241
11.4k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
12.2k
{
165
12.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
12.2k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
12.2k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
12.2k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
12.2k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
12.2k
  int ci, compi, row, prev_row;
171
12.2k
  unsigned int yoffset;
172
12.2k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
28.7k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
16.5k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
16.5k
    if (cinfo->restart_interval) {
180
0
      if (diff->restart_rows_to_go == 0)
181
0
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
0
    }
184
185
16.5k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
16.5k
    MCU_count =
188
16.5k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
16.5k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
16.5k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
16.5k
    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
16.5k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
16.5k
    diff->MCU_ctr = 0;
204
16.5k
  }
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
23.9k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
11.7k
    compptr = cinfo->cur_comp_info[ci];
213
11.7k
    compi = compptr->component_index;
214
11.7k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
27.7k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
27.2k
                compptr->last_row_height : compptr->v_samp_factor);
217
16.0k
         prev_row = row, row++) {
218
16.0k
      (*losslessd->predict_undifference[compi])
219
16.0k
        (cinfo, compi, diff->diff_buf[compi][row],
220
16.0k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
16.0k
          compptr->width_in_blocks);
222
16.0k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
16.0k
                                  output_buf[compi][row],
224
16.0k
                                  compptr->width_in_blocks);
225
16.0k
    }
226
11.7k
  }
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
12.2k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
11.5k
    start_iMCU_row(cinfo);
236
11.5k
    return JPEG_ROW_COMPLETED;
237
11.5k
  }
238
  /* Completed the scan */
239
702
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
702
  return JPEG_SCAN_COMPLETED;
241
12.2k
}
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
26.1k
{
267
26.1k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
26.1k
  int ci, compi;
269
26.1k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
26.1k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
52.2k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
26.1k
    compptr = cinfo->cur_comp_info[ci];
275
26.1k
    compi = compptr->component_index;
276
26.1k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
26.1k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
26.1k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
26.1k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
26.1k
  }
281
282
26.1k
  return decompress_data(cinfo, buffer);
283
26.1k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
2.49k
{
267
2.49k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
2.49k
  int ci, compi;
269
2.49k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
2.49k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
4.98k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
2.49k
    compptr = cinfo->cur_comp_info[ci];
275
2.49k
    compi = compptr->component_index;
276
2.49k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
2.49k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
2.49k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
2.49k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
2.49k
  }
281
282
2.49k
  return decompress_data(cinfo, buffer);
283
2.49k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
11.4k
{
267
11.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
11.4k
  int ci, compi;
269
11.4k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
11.4k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
22.8k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
11.4k
    compptr = cinfo->cur_comp_info[ci];
275
11.4k
    compi = compptr->component_index;
276
11.4k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
11.4k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
11.4k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
11.4k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
11.4k
  }
281
282
11.4k
  return decompress_data(cinfo, buffer);
283
11.4k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
12.2k
{
267
12.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
12.2k
  int ci, compi;
269
12.2k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
12.2k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
24.4k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
12.2k
    compptr = cinfo->cur_comp_info[ci];
275
12.2k
    compi = compptr->component_index;
276
12.2k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
12.2k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
12.2k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
12.2k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
12.2k
  }
281
282
12.2k
  return decompress_data(cinfo, buffer);
283
12.2k
}
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
1
{
297
1
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
1
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
1
  int ci, samp_rows, row;
300
1
  _JSAMPARRAY buffer;
301
1
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
1
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
1
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
1
          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
3
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
2
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
2
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
2
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
2
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
2
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
2
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1
      samp_rows = compptr->v_samp_factor;
322
1
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1
    }
327
328
3
    for (row = 0; row < samp_rows; row++) {
329
1
      memcpy(output_buf[ci][row], buffer[row],
330
1
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1
    }
332
2
  }
333
334
1
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
1
  return JPEG_SCAN_COMPLETED;
337
1
}
jddiffct-8.c:output_data
Line
Count
Source
296
1
{
297
1
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
1
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
1
  int ci, samp_rows, row;
300
1
  _JSAMPARRAY buffer;
301
1
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
1
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
1
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
1
          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
3
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
2
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
2
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
2
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
2
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
2
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
2
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1
      samp_rows = compptr->v_samp_factor;
322
1
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1
    }
327
328
3
    for (row = 0; row < samp_rows; row++) {
329
1
      memcpy(output_buf[ci][row], buffer[row],
330
1
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1
    }
332
2
  }
333
334
1
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
1
  return JPEG_SCAN_COMPLETED;
337
1
}
Unexecuted instantiation: jddiffct-12.c:output_data
Unexecuted instantiation: jddiffct-16.c:output_data
338
339
#endif /* D_MULTISCAN_FILES_SUPPORTED */
340
341
342
/*
343
 * Initialize difference buffer controller.
344
 */
345
346
GLOBAL(void)
347
_jinit_d_diff_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
348
1.47k
{
349
1.47k
  my_diff_ptr diff;
350
1.47k
  int ci;
351
1.47k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
532
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
941
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
941
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.47k
  diff = (my_diff_ptr)
362
1.47k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.47k
                                sizeof(my_diff_controller));
364
1.47k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.47k
  diff->pub.start_input_pass = start_input_pass;
366
1.47k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
5.83k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.36k
       ci++, compptr++) {
371
4.36k
    diff->diff_buf[ci] =
372
4.36k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.36k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.36k
                                         (long)compptr->h_samp_factor),
375
4.36k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.36k
    diff->undiff_buf[ci] =
377
4.36k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.36k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.36k
                                         (long)compptr->h_samp_factor),
380
4.36k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.36k
  }
382
383
1.47k
  if (need_full_buffer) {
384
967
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
967
    int access_rows;
387
388
3.86k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
2.90k
         ci++, compptr++) {
390
2.90k
      access_rows = compptr->v_samp_factor;
391
2.90k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
2.90k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
2.90k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
2.90k
                               (long)compptr->h_samp_factor),
395
2.90k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
2.90k
                               (long)compptr->v_samp_factor),
397
2.90k
         (JDIMENSION)access_rows);
398
2.90k
    }
399
967
    diff->pub.consume_data = consume_data;
400
967
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
967
  } else {
405
506
    diff->pub.consume_data = dummy_consume_data;
406
506
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
506
  }
409
1.47k
}
jinit_d_diff_controller
Line
Count
Source
348
532
{
349
532
  my_diff_ptr diff;
350
532
  int ci;
351
532
  jpeg_component_info *compptr;
352
353
532
#if BITS_IN_JSAMPLE == 8
354
532
  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
532
  diff = (my_diff_ptr)
362
532
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
532
                                sizeof(my_diff_controller));
364
532
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
532
  diff->pub.start_input_pass = start_input_pass;
366
532
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.07k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.54k
       ci++, compptr++) {
371
1.54k
    diff->diff_buf[ci] =
372
1.54k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.54k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.54k
                                         (long)compptr->h_samp_factor),
375
1.54k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.54k
    diff->undiff_buf[ci] =
377
1.54k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.54k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.54k
                                         (long)compptr->h_samp_factor),
380
1.54k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.54k
  }
382
383
532
  if (need_full_buffer) {
384
85
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
85
    int access_rows;
387
388
340
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
255
         ci++, compptr++) {
390
255
      access_rows = compptr->v_samp_factor;
391
255
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
255
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
255
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
255
                               (long)compptr->h_samp_factor),
395
255
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
255
                               (long)compptr->v_samp_factor),
397
255
         (JDIMENSION)access_rows);
398
255
    }
399
85
    diff->pub.consume_data = consume_data;
400
85
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
447
  } else {
405
447
    diff->pub.consume_data = dummy_consume_data;
406
447
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
447
  }
409
532
}
j12init_d_diff_controller
Line
Count
Source
348
384
{
349
384
  my_diff_ptr diff;
350
384
  int ci;
351
384
  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
384
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
384
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
384
  diff = (my_diff_ptr)
362
384
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
384
                                sizeof(my_diff_controller));
364
384
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
384
  diff->pub.start_input_pass = start_input_pass;
366
384
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.53k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.14k
       ci++, compptr++) {
371
1.14k
    diff->diff_buf[ci] =
372
1.14k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.14k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.14k
                                         (long)compptr->h_samp_factor),
375
1.14k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.14k
    diff->undiff_buf[ci] =
377
1.14k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.14k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.14k
                                         (long)compptr->h_samp_factor),
380
1.14k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.14k
  }
382
383
384
  if (need_full_buffer) {
384
351
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
351
    int access_rows;
387
388
1.40k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.05k
         ci++, compptr++) {
390
1.05k
      access_rows = compptr->v_samp_factor;
391
1.05k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.05k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.05k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.05k
                               (long)compptr->h_samp_factor),
395
1.05k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.05k
                               (long)compptr->v_samp_factor),
397
1.05k
         (JDIMENSION)access_rows);
398
1.05k
    }
399
351
    diff->pub.consume_data = consume_data;
400
351
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
351
  } else {
405
33
    diff->pub.consume_data = dummy_consume_data;
406
33
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
33
  }
409
384
}
j16init_d_diff_controller
Line
Count
Source
348
557
{
349
557
  my_diff_ptr diff;
350
557
  int ci;
351
557
  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
557
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
557
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
557
  diff = (my_diff_ptr)
362
557
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
557
                                sizeof(my_diff_controller));
364
557
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
557
  diff->pub.start_input_pass = start_input_pass;
366
557
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.22k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.67k
       ci++, compptr++) {
371
1.67k
    diff->diff_buf[ci] =
372
1.67k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.67k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.67k
                                         (long)compptr->h_samp_factor),
375
1.67k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.67k
    diff->undiff_buf[ci] =
377
1.67k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.67k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.67k
                                         (long)compptr->h_samp_factor),
380
1.67k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.67k
  }
382
383
557
  if (need_full_buffer) {
384
531
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
531
    int access_rows;
387
388
2.12k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.59k
         ci++, compptr++) {
390
1.59k
      access_rows = compptr->v_samp_factor;
391
1.59k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.59k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.59k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.59k
                               (long)compptr->h_samp_factor),
395
1.59k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.59k
                               (long)compptr->v_samp_factor),
397
1.59k
         (JDIMENSION)access_rows);
398
1.59k
    }
399
531
    diff->pub.consume_data = consume_data;
400
531
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
531
  } else {
405
26
    diff->pub.consume_data = dummy_consume_data;
406
26
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
26
  }
409
557
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */