Coverage Report

Created: 2025-06-22 06:33

/src/libjpeg-turbo/src/jddiffct.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * jddiffct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1997, Thomas G. Lane.
6
 * Lossless JPEG Modifications:
7
 * Copyright (C) 1999, Ken Murchison.
8
 * libjpeg-turbo Modifications:
9
 * Copyright (C) 2022, 2024, D. R. Commander.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the [un]difference buffer controller for decompression.
14
 * This controller is the top level of the lossless JPEG decompressor proper.
15
 * The difference buffer lies between the entropy decoding and
16
 * prediction/undifferencing steps.  The undifference buffer lies between the
17
 * prediction/undifferencing and scaling steps.
18
 *
19
 * In buffered-image mode, this controller is the interface between
20
 * input-oriented processing and output-oriented processing.
21
 */
22
23
#define JPEG_INTERNALS
24
#include "jinclude.h"
25
#include "jpeglib.h"
26
#include "jlossls.h"            /* Private declarations for lossless codec */
27
28
29
#ifdef D_LOSSLESS_SUPPORTED
30
31
/* Private buffer controller object */
32
33
typedef struct {
34
  struct jpeg_d_coef_controller pub; /* public fields */
35
36
  /* These variables keep track of the current location of the input side. */
37
  /* cinfo->input_iMCU_row is also used for this. */
38
  JDIMENSION MCU_ctr;           /* counts MCUs processed in current row */
39
  unsigned int restart_rows_to_go;      /* MCU rows left in this restart
40
                                           interval */
41
  unsigned int MCU_vert_offset;         /* counts MCU rows within iMCU row */
42
  unsigned int MCU_rows_per_iMCU_row;   /* number of such rows needed */
43
44
  /* The output side's location is represented by cinfo->output_iMCU_row. */
45
46
  JDIFFARRAY diff_buf[MAX_COMPONENTS];  /* iMCU row of differences */
47
  JDIFFARRAY undiff_buf[MAX_COMPONENTS]; /* iMCU row of undiff'd samples */
48
49
#ifdef D_MULTISCAN_FILES_SUPPORTED
50
  /* In multi-pass modes, we need a virtual sample array for each component. */
51
  jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
52
#endif
53
} my_diff_controller;
54
55
typedef my_diff_controller *my_diff_ptr;
56
57
/* Forward declarations */
58
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
59
#ifdef D_MULTISCAN_FILES_SUPPORTED
60
METHODDEF(int) output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
61
#endif
62
63
64
LOCAL(void)
65
start_iMCU_row(j_decompress_ptr cinfo)
66
/* Reset within-iMCU-row counters for a new row (input side) */
67
485k
{
68
485k
  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
485k
  if (cinfo->comps_in_scan > 1) {
75
44.3k
    diff->MCU_rows_per_iMCU_row = 1;
76
441k
  } else {
77
441k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
433k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
7.85k
    else
80
7.85k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
441k
  }
82
83
485k
  diff->MCU_ctr = 0;
84
485k
  diff->MCU_vert_offset = 0;
85
485k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
192k
{
68
192k
  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
192k
  if (cinfo->comps_in_scan > 1) {
75
41.1k
    diff->MCU_rows_per_iMCU_row = 1;
76
151k
  } else {
77
151k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
149k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.90k
    else
80
1.90k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
151k
  }
82
83
192k
  diff->MCU_ctr = 0;
84
192k
  diff->MCU_vert_offset = 0;
85
192k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
123k
{
68
123k
  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
123k
  if (cinfo->comps_in_scan > 1) {
75
1.59k
    diff->MCU_rows_per_iMCU_row = 1;
76
122k
  } else {
77
122k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
118k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
3.05k
    else
80
3.05k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
122k
  }
82
83
123k
  diff->MCU_ctr = 0;
84
123k
  diff->MCU_vert_offset = 0;
85
123k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
169k
{
68
169k
  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
169k
  if (cinfo->comps_in_scan > 1) {
75
1.63k
    diff->MCU_rows_per_iMCU_row = 1;
76
168k
  } else {
77
168k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
165k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
2.89k
    else
80
2.89k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
168k
  }
82
83
169k
  diff->MCU_ctr = 0;
84
169k
  diff->MCU_vert_offset = 0;
85
169k
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
21.9k
{
95
21.9k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
21.9k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
21.9k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
82
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
21.9k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
21.9k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
21.9k
  cinfo->input_iMCU_row = 0;
115
21.9k
  start_iMCU_row(cinfo);
116
21.9k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
7.92k
{
95
7.92k
  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
7.92k
  (*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
7.92k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
24
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
7.92k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
7.92k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
7.92k
  cinfo->input_iMCU_row = 0;
115
7.92k
  start_iMCU_row(cinfo);
116
7.92k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
6.93k
{
95
6.93k
  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
6.93k
  (*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
6.93k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
27
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
6.93k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
6.93k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
6.93k
  cinfo->input_iMCU_row = 0;
115
6.93k
  start_iMCU_row(cinfo);
116
6.93k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
7.12k
{
95
7.12k
  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
7.12k
  (*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
7.12k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
31
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
7.12k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
7.12k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
7.12k
  cinfo->input_iMCU_row = 0;
115
7.12k
  start_iMCU_row(cinfo);
116
7.12k
}
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
113
{
127
113
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
113
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
113
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
113
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
113
  return TRUE;
138
113
}
jddiffct-8.c:process_restart
Line
Count
Source
126
34
{
127
34
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
34
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
34
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
34
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
34
  return TRUE;
138
34
}
jddiffct-12.c:process_restart
Line
Count
Source
126
42
{
127
42
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
42
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
42
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
42
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
42
  return TRUE;
138
42
}
jddiffct-16.c:process_restart
Line
Count
Source
126
37
{
127
37
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
37
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
37
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
37
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
37
  return TRUE;
138
37
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
4.29k
{
148
4.29k
  cinfo->output_iMCU_row = 0;
149
4.29k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
4.10k
{
148
4.10k
  cinfo->output_iMCU_row = 0;
149
4.10k
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
95
{
148
95
  cinfo->output_iMCU_row = 0;
149
95
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
96
{
148
96
  cinfo->output_iMCU_row = 0;
149
96
}
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
485k
{
165
485k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
485k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
485k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
485k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
485k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
485k
  int ci, compi, row, prev_row;
171
485k
  unsigned int yoffset;
172
485k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
1.21M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
731k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
731k
    if (cinfo->restart_interval) {
180
2.63k
      if (diff->restart_rows_to_go == 0)
181
113
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
2.63k
    }
184
185
731k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
731k
    MCU_count =
188
731k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
731k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
731k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
731k
    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
731k
    if (cinfo->restart_interval)
200
2.38k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
731k
    diff->MCU_ctr = 0;
204
731k
  }
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
1.05M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
573k
    compptr = cinfo->cur_comp_info[ci];
213
573k
    compi = compptr->component_index;
214
573k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
1.43M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
1.40M
                compptr->last_row_height : compptr->v_samp_factor);
217
862k
         prev_row = row, row++) {
218
862k
      (*losslessd->predict_undifference[compi])
219
862k
        (cinfo, compi, diff->diff_buf[compi][row],
220
862k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
862k
          compptr->width_in_blocks);
222
862k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
862k
                                  output_buf[compi][row],
224
862k
                                  compptr->width_in_blocks);
225
862k
    }
226
573k
  }
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
485k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
464k
    start_iMCU_row(cinfo);
236
464k
    return JPEG_ROW_COMPLETED;
237
464k
  }
238
  /* Completed the scan */
239
20.9k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
20.9k
  return JPEG_SCAN_COMPLETED;
241
485k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
192k
{
165
192k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
192k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
192k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
192k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
192k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
192k
  int ci, compi, row, prev_row;
171
192k
  unsigned int yoffset;
172
192k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
489k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
296k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
296k
    if (cinfo->restart_interval) {
180
1.49k
      if (diff->restart_rows_to_go == 0)
181
34
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.49k
    }
184
185
296k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
296k
    MCU_count =
188
296k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
296k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
296k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
296k
    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
296k
    if (cinfo->restart_interval)
200
1.40k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
296k
    diff->MCU_ctr = 0;
204
296k
  }
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
474k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
281k
    compptr = cinfo->cur_comp_info[ci];
213
281k
    compi = compptr->component_index;
214
281k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
710k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
700k
                compptr->last_row_height : compptr->v_samp_factor);
217
429k
         prev_row = row, row++) {
218
429k
      (*losslessd->predict_undifference[compi])
219
429k
        (cinfo, compi, diff->diff_buf[compi][row],
220
429k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
429k
          compptr->width_in_blocks);
222
429k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
429k
                                  output_buf[compi][row],
224
429k
                                  compptr->width_in_blocks);
225
429k
    }
226
281k
  }
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
192k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
185k
    start_iMCU_row(cinfo);
236
185k
    return JPEG_ROW_COMPLETED;
237
185k
  }
238
  /* Completed the scan */
239
7.56k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
7.56k
  return JPEG_SCAN_COMPLETED;
241
192k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
123k
{
165
123k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
123k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
123k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
123k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
123k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
123k
  int ci, compi, row, prev_row;
171
123k
  unsigned int yoffset;
172
123k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
298k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
175k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
175k
    if (cinfo->restart_interval) {
180
568
      if (diff->restart_rows_to_go == 0)
181
42
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
568
    }
184
185
175k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
175k
    MCU_count =
188
175k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
175k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
175k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
175k
    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
175k
    if (cinfo->restart_interval)
200
487
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
175k
    diff->MCU_ctr = 0;
204
175k
  }
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
246k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
122k
    compptr = cinfo->cur_comp_info[ci];
213
122k
    compi = compptr->component_index;
214
122k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
296k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
284k
                compptr->last_row_height : compptr->v_samp_factor);
217
174k
         prev_row = row, row++) {
218
174k
      (*losslessd->predict_undifference[compi])
219
174k
        (cinfo, compi, diff->diff_buf[compi][row],
220
174k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
174k
          compptr->width_in_blocks);
222
174k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
174k
                                  output_buf[compi][row],
224
174k
                                  compptr->width_in_blocks);
225
174k
    }
226
122k
  }
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
123k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
116k
    start_iMCU_row(cinfo);
236
116k
    return JPEG_ROW_COMPLETED;
237
116k
  }
238
  /* Completed the scan */
239
6.61k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
6.61k
  return JPEG_SCAN_COMPLETED;
241
123k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
169k
{
165
169k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
169k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
169k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
169k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
169k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
169k
  int ci, compi, row, prev_row;
171
169k
  unsigned int yoffset;
172
169k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
429k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
259k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
259k
    if (cinfo->restart_interval) {
180
570
      if (diff->restart_rows_to_go == 0)
181
37
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
570
    }
184
185
259k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
259k
    MCU_count =
188
259k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
259k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
259k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
259k
    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
259k
    if (cinfo->restart_interval)
200
496
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
259k
    diff->MCU_ctr = 0;
204
259k
  }
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
338k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
168k
    compptr = cinfo->cur_comp_info[ci];
213
168k
    compi = compptr->component_index;
214
168k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
428k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
414k
                compptr->last_row_height : compptr->v_samp_factor);
217
259k
         prev_row = row, row++) {
218
259k
      (*losslessd->predict_undifference[compi])
219
259k
        (cinfo, compi, diff->diff_buf[compi][row],
220
259k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
259k
          compptr->width_in_blocks);
222
259k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
259k
                                  output_buf[compi][row],
224
259k
                                  compptr->width_in_blocks);
225
259k
    }
226
168k
  }
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
169k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
162k
    start_iMCU_row(cinfo);
236
162k
    return JPEG_ROW_COMPLETED;
237
162k
  }
238
  /* Completed the scan */
239
6.77k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
6.77k
  return JPEG_SCAN_COMPLETED;
241
169k
}
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
416k
{
267
416k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
416k
  int ci, compi;
269
416k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
416k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
838k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
421k
    compptr = cinfo->cur_comp_info[ci];
275
421k
    compi = compptr->component_index;
276
421k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
421k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
421k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
421k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
421k
  }
281
282
416k
  return decompress_data(cinfo, buffer);
283
416k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
123k
{
267
123k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
123k
  int ci, compi;
269
123k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
123k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
248k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
124k
    compptr = cinfo->cur_comp_info[ci];
275
124k
    compi = compptr->component_index;
276
124k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
124k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
124k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
124k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
124k
  }
281
282
123k
  return decompress_data(cinfo, buffer);
283
123k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
123k
{
267
123k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
123k
  int ci, compi;
269
123k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
123k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
249k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
125k
    compptr = cinfo->cur_comp_info[ci];
275
125k
    compi = compptr->component_index;
276
125k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
125k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
125k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
125k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
125k
  }
281
282
123k
  return decompress_data(cinfo, buffer);
283
123k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
169k
{
267
169k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
169k
  int ci, compi;
269
169k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
169k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
341k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
171k
    compptr = cinfo->cur_comp_info[ci];
275
171k
    compi = compptr->component_index;
276
171k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
171k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
171k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
171k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
171k
  }
281
282
169k
  return decompress_data(cinfo, buffer);
283
169k
}
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
226
{
297
226
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
226
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
226
  int ci, samp_rows, row;
300
226
  _JSAMPARRAY buffer;
301
226
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
226
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
226
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
226
          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
712
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
486
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
486
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
486
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
486
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
486
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
486
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
277
      samp_rows = compptr->v_samp_factor;
322
209
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
209
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
209
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
209
    }
327
328
1.14k
    for (row = 0; row < samp_rows; row++) {
329
654
      memcpy(output_buf[ci][row], buffer[row],
330
654
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
654
    }
332
486
  }
333
334
226
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
111
    return JPEG_ROW_COMPLETED;
336
115
  return JPEG_SCAN_COMPLETED;
337
226
}
jddiffct-8.c:output_data
Line
Count
Source
296
226
{
297
226
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
226
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
226
  int ci, samp_rows, row;
300
226
  _JSAMPARRAY buffer;
301
226
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
226
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
226
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
226
          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
712
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
486
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
486
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
486
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
486
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
486
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
486
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
277
      samp_rows = compptr->v_samp_factor;
322
209
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
209
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
209
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
209
    }
327
328
1.14k
    for (row = 0; row < samp_rows; row++) {
329
654
      memcpy(output_buf[ci][row], buffer[row],
330
654
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
654
    }
332
486
  }
333
334
226
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
111
    return JPEG_ROW_COMPLETED;
336
115
  return JPEG_SCAN_COMPLETED;
337
226
}
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
13.3k
{
349
13.3k
  my_diff_ptr diff;
350
13.3k
  int ci;
351
13.3k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
5.84k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
7.47k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
7.47k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
13.3k
  diff = (my_diff_ptr)
362
13.3k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
13.3k
                                sizeof(my_diff_controller));
364
13.3k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
13.3k
  diff->pub.start_input_pass = start_input_pass;
366
13.3k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
48.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
35.3k
       ci++, compptr++) {
371
35.3k
    diff->diff_buf[ci] =
372
35.3k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
35.3k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
35.3k
                                         (long)compptr->h_samp_factor),
375
35.3k
                   (JDIMENSION)compptr->v_samp_factor);
376
35.3k
    diff->undiff_buf[ci] =
377
35.3k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
35.3k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
35.3k
                                         (long)compptr->h_samp_factor),
380
35.3k
                   (JDIMENSION)compptr->v_samp_factor);
381
35.3k
  }
382
383
13.3k
  if (need_full_buffer) {
384
8.35k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
8.35k
    int access_rows;
387
388
32.6k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
24.3k
         ci++, compptr++) {
390
24.3k
      access_rows = compptr->v_samp_factor;
391
24.3k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
24.3k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
24.3k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
24.3k
                               (long)compptr->h_samp_factor),
395
24.3k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
24.3k
                               (long)compptr->v_samp_factor),
397
24.3k
         (JDIMENSION)access_rows);
398
24.3k
    }
399
8.35k
    diff->pub.consume_data = consume_data;
400
8.35k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
8.35k
  } else {
405
4.96k
    diff->pub.consume_data = dummy_consume_data;
406
4.96k
    diff->pub._decompress_data = decompress_data;
407
4.96k
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
4.96k
  }
409
13.3k
}
jinit_d_diff_controller
Line
Count
Source
348
5.84k
{
349
5.84k
  my_diff_ptr diff;
350
5.84k
  int ci;
351
5.84k
  jpeg_component_info *compptr;
352
353
5.84k
#if BITS_IN_JSAMPLE == 8
354
5.84k
  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
5.84k
  diff = (my_diff_ptr)
362
5.84k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
5.84k
                                sizeof(my_diff_controller));
364
5.84k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
5.84k
  diff->pub.start_input_pass = start_input_pass;
366
5.84k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
19.9k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
14.1k
       ci++, compptr++) {
371
14.1k
    diff->diff_buf[ci] =
372
14.1k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
14.1k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
14.1k
                                         (long)compptr->h_samp_factor),
375
14.1k
                   (JDIMENSION)compptr->v_samp_factor);
376
14.1k
    diff->undiff_buf[ci] =
377
14.1k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
14.1k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
14.1k
                                         (long)compptr->h_samp_factor),
380
14.1k
                   (JDIMENSION)compptr->v_samp_factor);
381
14.1k
  }
382
383
5.84k
  if (need_full_buffer) {
384
1.42k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.42k
    int access_rows;
387
388
5.71k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
4.29k
         ci++, compptr++) {
390
4.29k
      access_rows = compptr->v_samp_factor;
391
4.29k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
4.29k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
4.29k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
4.29k
                               (long)compptr->h_samp_factor),
395
4.29k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
4.29k
                               (long)compptr->v_samp_factor),
397
4.29k
         (JDIMENSION)access_rows);
398
4.29k
    }
399
1.42k
    diff->pub.consume_data = consume_data;
400
1.42k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
4.42k
  } else {
405
4.42k
    diff->pub.consume_data = dummy_consume_data;
406
4.42k
    diff->pub._decompress_data = decompress_data;
407
4.42k
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
4.42k
  }
409
5.84k
}
j12init_d_diff_controller
Line
Count
Source
348
3.75k
{
349
3.75k
  my_diff_ptr diff;
350
3.75k
  int ci;
351
3.75k
  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
3.75k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
3.75k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
3.75k
  diff = (my_diff_ptr)
362
3.75k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
3.75k
                                sizeof(my_diff_controller));
364
3.75k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
3.75k
  diff->pub.start_input_pass = start_input_pass;
366
3.75k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
14.4k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
10.7k
       ci++, compptr++) {
371
10.7k
    diff->diff_buf[ci] =
372
10.7k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
10.7k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
10.7k
                                         (long)compptr->h_samp_factor),
375
10.7k
                   (JDIMENSION)compptr->v_samp_factor);
376
10.7k
    diff->undiff_buf[ci] =
377
10.7k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
10.7k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
10.7k
                                         (long)compptr->h_samp_factor),
380
10.7k
                   (JDIMENSION)compptr->v_samp_factor);
381
10.7k
  }
382
383
3.75k
  if (need_full_buffer) {
384
3.48k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
3.48k
    int access_rows;
387
388
13.5k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
10.0k
         ci++, compptr++) {
390
10.0k
      access_rows = compptr->v_samp_factor;
391
10.0k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
10.0k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
10.0k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
10.0k
                               (long)compptr->h_samp_factor),
395
10.0k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
10.0k
                               (long)compptr->v_samp_factor),
397
10.0k
         (JDIMENSION)access_rows);
398
10.0k
    }
399
3.48k
    diff->pub.consume_data = consume_data;
400
3.48k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
3.48k
  } else {
405
273
    diff->pub.consume_data = dummy_consume_data;
406
273
    diff->pub._decompress_data = decompress_data;
407
273
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
273
  }
409
3.75k
}
j16init_d_diff_controller
Line
Count
Source
348
3.71k
{
349
3.71k
  my_diff_ptr diff;
350
3.71k
  int ci;
351
3.71k
  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
3.71k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
3.71k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
3.71k
  diff = (my_diff_ptr)
362
3.71k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
3.71k
                                sizeof(my_diff_controller));
364
3.71k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
3.71k
  diff->pub.start_input_pass = start_input_pass;
366
3.71k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
14.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
10.5k
       ci++, compptr++) {
371
10.5k
    diff->diff_buf[ci] =
372
10.5k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
10.5k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
10.5k
                                         (long)compptr->h_samp_factor),
375
10.5k
                   (JDIMENSION)compptr->v_samp_factor);
376
10.5k
    diff->undiff_buf[ci] =
377
10.5k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
10.5k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
10.5k
                                         (long)compptr->h_samp_factor),
380
10.5k
                   (JDIMENSION)compptr->v_samp_factor);
381
10.5k
  }
382
383
3.71k
  if (need_full_buffer) {
384
3.45k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
3.45k
    int access_rows;
387
388
13.3k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
9.92k
         ci++, compptr++) {
390
9.92k
      access_rows = compptr->v_samp_factor;
391
9.92k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
9.92k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
9.92k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
9.92k
                               (long)compptr->h_samp_factor),
395
9.92k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
9.92k
                               (long)compptr->v_samp_factor),
397
9.92k
         (JDIMENSION)access_rows);
398
9.92k
    }
399
3.45k
    diff->pub.consume_data = consume_data;
400
3.45k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
3.45k
  } else {
405
269
    diff->pub.consume_data = dummy_consume_data;
406
269
    diff->pub._decompress_data = decompress_data;
407
269
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
269
  }
409
3.71k
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */