Coverage Report

Created: 2026-01-17 06:32

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
41.5k
{
68
41.5k
  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
41.5k
  if (cinfo->comps_in_scan > 1) {
75
4.42k
    diff->MCU_rows_per_iMCU_row = 1;
76
37.0k
  } else {
77
37.0k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
35.9k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.11k
    else
80
1.11k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
37.0k
  }
82
83
41.5k
  diff->MCU_ctr = 0;
84
41.5k
  diff->MCU_vert_offset = 0;
85
41.5k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
6.56k
{
68
6.56k
  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
6.56k
  if (cinfo->comps_in_scan > 1) {
75
4.41k
    diff->MCU_rows_per_iMCU_row = 1;
76
4.41k
  } else {
77
2.14k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
1.74k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
404
    else
80
404
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
2.14k
  }
82
83
6.56k
  diff->MCU_ctr = 0;
84
6.56k
  diff->MCU_vert_offset = 0;
85
6.56k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
16.9k
{
68
16.9k
  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
16.9k
  if (cinfo->comps_in_scan > 1) {
75
3
    diff->MCU_rows_per_iMCU_row = 1;
76
16.9k
  } else {
77
16.9k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
16.5k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
369
    else
80
369
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
16.9k
  }
82
83
16.9k
  diff->MCU_ctr = 0;
84
16.9k
  diff->MCU_vert_offset = 0;
85
16.9k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
18.0k
{
68
18.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
18.0k
  if (cinfo->comps_in_scan > 1) {
75
4
    diff->MCU_rows_per_iMCU_row = 1;
76
18.0k
  } else {
77
18.0k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
17.6k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
341
    else
80
341
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
18.0k
  }
82
83
18.0k
  diff->MCU_ctr = 0;
84
18.0k
  diff->MCU_vert_offset = 0;
85
18.0k
}
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.25k
{
95
2.25k
  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.25k
  (*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.25k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
2.25k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
2.25k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
2.25k
  cinfo->input_iMCU_row = 0;
115
2.25k
  start_iMCU_row(cinfo);
116
2.25k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
852
{
95
852
  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
852
  (*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
852
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
852
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
852
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
852
  cinfo->input_iMCU_row = 0;
115
852
  start_iMCU_row(cinfo);
116
852
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
689
{
95
689
  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
689
  (*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
689
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
689
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
689
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
689
  cinfo->input_iMCU_row = 0;
115
689
  start_iMCU_row(cinfo);
116
689
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
710
{
95
710
  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
710
  (*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
710
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
710
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
710
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
710
  cinfo->input_iMCU_row = 0;
115
710
  start_iMCU_row(cinfo);
116
710
}
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
0
{
127
0
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
0
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
0
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
0
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
0
  return TRUE;
138
0
}
Unexecuted instantiation: jddiffct-8.c:process_restart
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
355
{
148
355
  cinfo->output_iMCU_row = 0;
149
355
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
343
{
148
343
  cinfo->output_iMCU_row = 0;
149
343
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
6
{
148
6
  cinfo->output_iMCU_row = 0;
149
6
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
6
{
148
6
  cinfo->output_iMCU_row = 0;
149
6
}
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
41.4k
{
165
41.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
41.4k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
41.4k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
41.4k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
41.4k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
41.4k
  int ci, compi, row, prev_row;
171
41.4k
  unsigned int yoffset;
172
41.4k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
97.6k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
56.1k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
56.1k
    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
56.1k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
56.1k
    MCU_count =
188
56.1k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
56.1k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
56.1k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
56.1k
    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
56.1k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
56.1k
    diff->MCU_ctr = 0;
204
56.1k
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
93.9k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
52.4k
    compptr = cinfo->cur_comp_info[ci];
213
52.4k
    compi = compptr->component_index;
214
52.4k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
124k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
121k
                compptr->last_row_height : compptr->v_samp_factor);
217
72.2k
         prev_row = row, row++) {
218
72.2k
      (*losslessd->predict_undifference[compi])
219
72.2k
        (cinfo, compi, diff->diff_buf[compi][row],
220
72.2k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
72.2k
          compptr->width_in_blocks);
222
72.2k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
72.2k
                                  output_buf[compi][row],
224
72.2k
                                  compptr->width_in_blocks);
225
72.2k
    }
226
52.4k
  }
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
41.4k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
39.3k
    start_iMCU_row(cinfo);
236
39.3k
    return JPEG_ROW_COMPLETED;
237
39.3k
  }
238
  /* Completed the scan */
239
2.15k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
2.15k
  return JPEG_SCAN_COMPLETED;
241
41.4k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
6.56k
{
165
6.56k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
6.56k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
6.56k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
6.56k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
6.56k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
6.56k
  int ci, compi, row, prev_row;
171
6.56k
  unsigned int yoffset;
172
6.56k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
14.4k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
7.92k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
7.92k
    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
7.92k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
7.92k
    MCU_count =
188
7.92k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
7.92k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
7.92k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
7.92k
    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
7.92k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
7.92k
    diff->MCU_ctr = 0;
204
7.92k
  }
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
24.6k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
18.1k
    compptr = cinfo->cur_comp_info[ci];
213
18.1k
    compi = compptr->component_index;
214
18.1k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
43.0k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
41.8k
                compptr->last_row_height : compptr->v_samp_factor);
217
24.9k
         prev_row = row, row++) {
218
24.9k
      (*losslessd->predict_undifference[compi])
219
24.9k
        (cinfo, compi, diff->diff_buf[compi][row],
220
24.9k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
24.9k
          compptr->width_in_blocks);
222
24.9k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
24.9k
                                  output_buf[compi][row],
224
24.9k
                                  compptr->width_in_blocks);
225
24.9k
    }
226
18.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
6.56k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
5.74k
    start_iMCU_row(cinfo);
236
5.74k
    return JPEG_ROW_COMPLETED;
237
5.74k
  }
238
  /* Completed the scan */
239
822
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
822
  return JPEG_SCAN_COMPLETED;
241
6.56k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
16.9k
{
165
16.9k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
16.9k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
16.9k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
16.9k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
16.9k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
16.9k
  int ci, compi, row, prev_row;
171
16.9k
  unsigned int yoffset;
172
16.9k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
41.6k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
24.7k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
24.7k
    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
24.7k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
24.7k
    MCU_count =
188
24.7k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
24.7k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
24.7k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
24.7k
    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
24.7k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
24.7k
    diff->MCU_ctr = 0;
204
24.7k
  }
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
33.5k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
16.6k
    compptr = cinfo->cur_comp_info[ci];
213
16.6k
    compi = compptr->component_index;
214
16.6k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
40.8k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
39.8k
                compptr->last_row_height : compptr->v_samp_factor);
217
24.2k
         prev_row = row, row++) {
218
24.2k
      (*losslessd->predict_undifference[compi])
219
24.2k
        (cinfo, compi, diff->diff_buf[compi][row],
220
24.2k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
24.2k
          compptr->width_in_blocks);
222
24.2k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
24.2k
                                  output_buf[compi][row],
224
24.2k
                                  compptr->width_in_blocks);
225
24.2k
    }
226
16.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
16.9k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
16.2k
    start_iMCU_row(cinfo);
236
16.2k
    return JPEG_ROW_COMPLETED;
237
16.2k
  }
238
  /* Completed the scan */
239
665
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
665
  return JPEG_SCAN_COMPLETED;
241
16.9k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
18.0k
{
165
18.0k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
18.0k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
18.0k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
18.0k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
18.0k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
18.0k
  int ci, compi, row, prev_row;
171
18.0k
  unsigned int yoffset;
172
18.0k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
41.5k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
23.5k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
23.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
23.5k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
23.5k
    MCU_count =
188
23.5k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
23.5k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
23.5k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
23.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
23.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
23.5k
    diff->MCU_ctr = 0;
204
23.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
35.6k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
17.6k
    compptr = cinfo->cur_comp_info[ci];
213
17.6k
    compi = compptr->component_index;
214
17.6k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
40.7k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
39.8k
                compptr->last_row_height : compptr->v_samp_factor);
217
23.0k
         prev_row = row, row++) {
218
23.0k
      (*losslessd->predict_undifference[compi])
219
23.0k
        (cinfo, compi, diff->diff_buf[compi][row],
220
23.0k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
23.0k
          compptr->width_in_blocks);
222
23.0k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
23.0k
                                  output_buf[compi][row],
224
23.0k
                                  compptr->width_in_blocks);
225
23.0k
    }
226
17.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
18.0k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
17.3k
    start_iMCU_row(cinfo);
236
17.3k
    return JPEG_ROW_COMPLETED;
237
17.3k
  }
238
  /* Completed the scan */
239
665
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
665
  return JPEG_SCAN_COMPLETED;
241
18.0k
}
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
37.0k
{
267
37.0k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
37.0k
  int ci, compi;
269
37.0k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
37.0k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
74.1k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
37.0k
    compptr = cinfo->cur_comp_info[ci];
275
37.0k
    compi = compptr->component_index;
276
37.0k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
37.0k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
37.0k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
37.0k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
37.0k
  }
281
282
37.0k
  return decompress_data(cinfo, buffer);
283
37.0k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
2.14k
{
267
2.14k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
2.14k
  int ci, compi;
269
2.14k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
2.14k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
4.29k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
2.14k
    compptr = cinfo->cur_comp_info[ci];
275
2.14k
    compi = compptr->component_index;
276
2.14k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
2.14k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
2.14k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
2.14k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
2.14k
  }
281
282
2.14k
  return decompress_data(cinfo, buffer);
283
2.14k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
16.9k
{
267
16.9k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
16.9k
  int ci, compi;
269
16.9k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
16.9k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
33.8k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
16.9k
    compptr = cinfo->cur_comp_info[ci];
275
16.9k
    compi = compptr->component_index;
276
16.9k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
16.9k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
16.9k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
16.9k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
16.9k
  }
281
282
16.9k
  return decompress_data(cinfo, buffer);
283
16.9k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
18.0k
{
267
18.0k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
18.0k
  int ci, compi;
269
18.0k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
18.0k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
36.0k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
18.0k
    compptr = cinfo->cur_comp_info[ci];
275
18.0k
    compi = compptr->component_index;
276
18.0k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
18.0k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
18.0k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
18.0k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
18.0k
  }
281
282
18.0k
  return decompress_data(cinfo, buffer);
283
18.0k
}
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
9
{
297
9
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
9
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
9
  int ci, samp_rows, row;
300
9
  _JSAMPARRAY buffer;
301
9
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
9
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
9
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
9
          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
27
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
18
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
18
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
18
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
18
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
18
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
18
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
4
      samp_rows = compptr->v_samp_factor;
322
14
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
14
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
14
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
14
    }
327
328
46
    for (row = 0; row < samp_rows; row++) {
329
28
      memcpy(output_buf[ci][row], buffer[row],
330
28
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
28
    }
332
18
  }
333
334
9
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
9
  return JPEG_SCAN_COMPLETED;
337
9
}
jddiffct-8.c:output_data
Line
Count
Source
296
9
{
297
9
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
9
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
9
  int ci, samp_rows, row;
300
9
  _JSAMPARRAY buffer;
301
9
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
9
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
9
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
9
          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
27
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
18
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
18
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
18
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
18
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
18
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
18
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
4
      samp_rows = compptr->v_samp_factor;
322
14
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
14
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
14
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
14
    }
327
328
46
    for (row = 0; row < samp_rows; row++) {
329
28
      memcpy(output_buf[ci][row], buffer[row],
330
28
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
28
    }
332
18
  }
333
334
9
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
9
  return JPEG_SCAN_COMPLETED;
337
9
}
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.39k
{
349
1.39k
  my_diff_ptr diff;
350
1.39k
  int ci;
351
1.39k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
521
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
874
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
874
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.39k
  diff = (my_diff_ptr)
362
1.39k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.39k
                                sizeof(my_diff_controller));
364
1.39k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.39k
  diff->pub.start_input_pass = start_input_pass;
366
1.39k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
5.95k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.55k
       ci++, compptr++) {
371
4.55k
    diff->diff_buf[ci] =
372
4.55k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.55k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.55k
                                         (long)compptr->h_samp_factor),
375
4.55k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.55k
    diff->undiff_buf[ci] =
377
4.55k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.55k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.55k
                                         (long)compptr->h_samp_factor),
380
4.55k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.55k
  }
382
383
1.39k
  if (need_full_buffer) {
384
951
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
951
    int access_rows;
387
388
3.80k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
2.85k
         ci++, compptr++) {
390
2.85k
      access_rows = compptr->v_samp_factor;
391
2.85k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
2.85k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
2.85k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
2.85k
                               (long)compptr->h_samp_factor),
395
2.85k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
2.85k
                               (long)compptr->v_samp_factor),
397
2.85k
         (JDIMENSION)access_rows);
398
2.85k
    }
399
951
    diff->pub.consume_data = consume_data;
400
951
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
951
  } else {
405
444
    diff->pub.consume_data = dummy_consume_data;
406
444
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
444
  }
409
1.39k
}
jinit_d_diff_controller
Line
Count
Source
348
521
{
349
521
  my_diff_ptr diff;
350
521
  int ci;
351
521
  jpeg_component_info *compptr;
352
353
521
#if BITS_IN_JSAMPLE == 8
354
521
  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
521
  diff = (my_diff_ptr)
362
521
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
521
                                sizeof(my_diff_controller));
364
521
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
521
  diff->pub.start_input_pass = start_input_pass;
366
521
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.41k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.89k
       ci++, compptr++) {
371
1.89k
    diff->diff_buf[ci] =
372
1.89k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.89k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.89k
                                         (long)compptr->h_samp_factor),
375
1.89k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.89k
    diff->undiff_buf[ci] =
377
1.89k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.89k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.89k
                                         (long)compptr->h_samp_factor),
380
1.89k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.89k
  }
382
383
521
  if (need_full_buffer) {
384
133
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
133
    int access_rows;
387
388
533
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
400
         ci++, compptr++) {
390
400
      access_rows = compptr->v_samp_factor;
391
400
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
400
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
400
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
400
                               (long)compptr->h_samp_factor),
395
400
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
400
                               (long)compptr->v_samp_factor),
397
400
         (JDIMENSION)access_rows);
398
400
    }
399
133
    diff->pub.consume_data = consume_data;
400
133
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
388
  } else {
405
388
    diff->pub.consume_data = dummy_consume_data;
406
388
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
388
  }
409
521
}
j12init_d_diff_controller
Line
Count
Source
348
406
{
349
406
  my_diff_ptr diff;
350
406
  int ci;
351
406
  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
406
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
406
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
406
  diff = (my_diff_ptr)
362
406
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
406
                                sizeof(my_diff_controller));
364
406
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
406
  diff->pub.start_input_pass = start_input_pass;
366
406
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.63k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.23k
       ci++, compptr++) {
371
1.23k
    diff->diff_buf[ci] =
372
1.23k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.23k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.23k
                                         (long)compptr->h_samp_factor),
375
1.23k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.23k
    diff->undiff_buf[ci] =
377
1.23k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.23k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.23k
                                         (long)compptr->h_samp_factor),
380
1.23k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.23k
  }
382
383
406
  if (need_full_buffer) {
384
383
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
383
    int access_rows;
387
388
1.53k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.15k
         ci++, compptr++) {
390
1.15k
      access_rows = compptr->v_samp_factor;
391
1.15k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.15k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.15k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.15k
                               (long)compptr->h_samp_factor),
395
1.15k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.15k
                               (long)compptr->v_samp_factor),
397
1.15k
         (JDIMENSION)access_rows);
398
1.15k
    }
399
383
    diff->pub.consume_data = consume_data;
400
383
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
383
  } else {
405
23
    diff->pub.consume_data = dummy_consume_data;
406
23
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
23
  }
409
406
}
j16init_d_diff_controller
Line
Count
Source
348
468
{
349
468
  my_diff_ptr diff;
350
468
  int ci;
351
468
  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
468
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
468
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
468
  diff = (my_diff_ptr)
362
468
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
468
                                sizeof(my_diff_controller));
364
468
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
468
  diff->pub.start_input_pass = start_input_pass;
366
468
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.89k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.42k
       ci++, compptr++) {
371
1.42k
    diff->diff_buf[ci] =
372
1.42k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.42k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.42k
                                         (long)compptr->h_samp_factor),
375
1.42k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.42k
    diff->undiff_buf[ci] =
377
1.42k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.42k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.42k
                                         (long)compptr->h_samp_factor),
380
1.42k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.42k
  }
382
383
468
  if (need_full_buffer) {
384
435
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
435
    int access_rows;
387
388
1.74k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.30k
         ci++, compptr++) {
390
1.30k
      access_rows = compptr->v_samp_factor;
391
1.30k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.30k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.30k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.30k
                               (long)compptr->h_samp_factor),
395
1.30k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.30k
                               (long)compptr->v_samp_factor),
397
1.30k
         (JDIMENSION)access_rows);
398
1.30k
    }
399
435
    diff->pub.consume_data = consume_data;
400
435
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
435
  } 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
468
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */