Coverage Report

Created: 2026-07-30 07:17

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
36.0k
{
68
36.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
36.0k
  if (cinfo->comps_in_scan > 1) {
75
5.13k
    diff->MCU_rows_per_iMCU_row = 1;
76
30.8k
  } else {
77
30.8k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
27.8k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
3.02k
    else
80
3.02k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
30.8k
  }
82
83
36.0k
  diff->MCU_ctr = 0;
84
36.0k
  diff->MCU_vert_offset = 0;
85
36.0k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
11.2k
{
68
11.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
11.2k
  if (cinfo->comps_in_scan > 1) {
75
5.11k
    diff->MCU_rows_per_iMCU_row = 1;
76
6.10k
  } else {
77
6.10k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
5.03k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.07k
    else
80
1.07k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
6.10k
  }
82
83
11.2k
  diff->MCU_ctr = 0;
84
11.2k
  diff->MCU_vert_offset = 0;
85
11.2k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
11.4k
{
68
11.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
11.4k
  if (cinfo->comps_in_scan > 1) {
75
6
    diff->MCU_rows_per_iMCU_row = 1;
76
11.4k
  } else {
77
11.4k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
10.2k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.19k
    else
80
1.19k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
11.4k
  }
82
83
11.4k
  diff->MCU_ctr = 0;
84
11.4k
  diff->MCU_vert_offset = 0;
85
11.4k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
13.3k
{
68
13.3k
  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
13.3k
  if (cinfo->comps_in_scan > 1) {
75
16
    diff->MCU_rows_per_iMCU_row = 1;
76
13.3k
  } else {
77
13.3k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
12.5k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
755
    else
80
755
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
13.3k
  }
82
83
13.3k
  diff->MCU_ctr = 0;
84
13.3k
  diff->MCU_vert_offset = 0;
85
13.3k
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
4.13k
{
95
4.13k
  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
4.13k
  (*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
4.13k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
6
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
4.13k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
4.13k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
4.13k
  cinfo->input_iMCU_row = 0;
115
4.13k
  start_iMCU_row(cinfo);
116
4.13k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
1.56k
{
95
1.56k
  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
1.56k
  (*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
1.56k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
4
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.56k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.56k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.56k
  cinfo->input_iMCU_row = 0;
115
1.56k
  start_iMCU_row(cinfo);
116
1.56k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
1.46k
{
95
1.46k
  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
1.46k
  (*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
1.46k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.46k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.46k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.46k
  cinfo->input_iMCU_row = 0;
115
1.46k
  start_iMCU_row(cinfo);
116
1.46k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
1.11k
{
95
1.11k
  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
1.11k
  (*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
1.11k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.11k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.11k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.11k
  cinfo->input_iMCU_row = 0;
115
1.11k
  start_iMCU_row(cinfo);
116
1.11k
}
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
4
{
127
4
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
4
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
4
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
4
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
4
  return TRUE;
138
4
}
jddiffct-8.c:process_restart
Line
Count
Source
126
4
{
127
4
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
4
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
4
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
4
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
4
  return TRUE;
138
4
}
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
445
{
148
445
  cinfo->output_iMCU_row = 0;
149
445
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
422
{
148
422
  cinfo->output_iMCU_row = 0;
149
422
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
7
{
148
7
  cinfo->output_iMCU_row = 0;
149
7
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
16
{
148
16
  cinfo->output_iMCU_row = 0;
149
16
}
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
35.9k
{
165
35.9k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
35.9k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
35.9k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
35.9k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
35.9k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
35.9k
  int ci, compi, row, prev_row;
171
35.9k
  unsigned int yoffset;
172
35.9k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
84.6k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
48.6k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
48.6k
    if (cinfo->restart_interval) {
180
518
      if (diff->restart_rows_to_go == 0)
181
4
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
518
    }
184
185
48.6k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
48.6k
    MCU_count =
188
48.6k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
48.6k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
48.6k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
48.6k
    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
48.6k
    if (cinfo->restart_interval)
200
502
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
48.6k
    diff->MCU_ctr = 0;
204
48.6k
  }
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
80.5k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
44.5k
    compptr = cinfo->cur_comp_info[ci];
213
44.5k
    compi = compptr->component_index;
214
44.5k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
107k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
100k
                compptr->last_row_height : compptr->v_samp_factor);
217
63.2k
         prev_row = row, row++) {
218
63.2k
      (*losslessd->predict_undifference[compi])
219
63.2k
        (cinfo, compi, diff->diff_buf[compi][row],
220
63.2k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
63.2k
          compptr->width_in_blocks);
222
63.2k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
63.2k
                                  output_buf[compi][row],
224
63.2k
                                  compptr->width_in_blocks);
225
63.2k
    }
226
44.5k
  }
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
35.9k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
32.0k
    start_iMCU_row(cinfo);
236
32.0k
    return JPEG_ROW_COMPLETED;
237
32.0k
  }
238
  /* Completed the scan */
239
3.94k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
3.94k
  return JPEG_SCAN_COMPLETED;
241
35.9k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
11.2k
{
165
11.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
11.2k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
11.2k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
11.2k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
11.2k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
11.2k
  int ci, compi, row, prev_row;
171
11.2k
  unsigned int yoffset;
172
11.2k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
26.9k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
15.7k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
15.7k
    if (cinfo->restart_interval) {
180
518
      if (diff->restart_rows_to_go == 0)
181
4
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
518
    }
184
185
15.7k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
15.7k
    MCU_count =
188
15.7k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
15.7k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
15.7k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
15.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
15.7k
    if (cinfo->restart_interval)
200
502
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
15.7k
    diff->MCU_ctr = 0;
204
15.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
31.4k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
20.2k
    compptr = cinfo->cur_comp_info[ci];
213
20.2k
    compi = compptr->component_index;
214
20.2k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
51.0k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
48.3k
                compptr->last_row_height : compptr->v_samp_factor);
217
30.8k
         prev_row = row, row++) {
218
30.8k
      (*losslessd->predict_undifference[compi])
219
30.8k
        (cinfo, compi, diff->diff_buf[compi][row],
220
30.8k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
30.8k
          compptr->width_in_blocks);
222
30.8k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
30.8k
                                  output_buf[compi][row],
224
30.8k
                                  compptr->width_in_blocks);
225
30.8k
    }
226
20.2k
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
11.2k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
9.70k
    start_iMCU_row(cinfo);
236
9.70k
    return JPEG_ROW_COMPLETED;
237
9.70k
  }
238
  /* Completed the scan */
239
1.51k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.51k
  return JPEG_SCAN_COMPLETED;
241
11.2k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
11.4k
{
165
11.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
11.4k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
11.4k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
11.4k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
11.4k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
11.4k
  int ci, compi, row, prev_row;
171
11.4k
  unsigned int yoffset;
172
11.4k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
27.1k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
15.6k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
15.6k
    if (cinfo->restart_interval) {
180
0
      if (diff->restart_rows_to_go == 0)
181
0
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
0
    }
184
185
15.6k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
15.6k
    MCU_count =
188
15.6k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
15.6k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
15.6k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
15.6k
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
15.6k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
15.6k
    diff->MCU_ctr = 0;
204
15.6k
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
22.6k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
11.2k
    compptr = cinfo->cur_comp_info[ci];
213
11.2k
    compi = compptr->component_index;
214
11.2k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
26.6k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
23.9k
                compptr->last_row_height : compptr->v_samp_factor);
217
15.4k
         prev_row = row, row++) {
218
15.4k
      (*losslessd->predict_undifference[compi])
219
15.4k
        (cinfo, compi, diff->diff_buf[compi][row],
220
15.4k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
15.4k
          compptr->width_in_blocks);
222
15.4k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
15.4k
                                  output_buf[compi][row],
224
15.4k
                                  compptr->width_in_blocks);
225
15.4k
    }
226
11.2k
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
11.4k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
10.0k
    start_iMCU_row(cinfo);
236
10.0k
    return JPEG_ROW_COMPLETED;
237
10.0k
  }
238
  /* Completed the scan */
239
1.41k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.41k
  return JPEG_SCAN_COMPLETED;
241
11.4k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
13.3k
{
165
13.3k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
13.3k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
13.3k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
13.3k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
13.3k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
13.3k
  int ci, compi, row, prev_row;
171
13.3k
  unsigned int yoffset;
172
13.3k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
30.5k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
17.2k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
17.2k
    if (cinfo->restart_interval) {
180
0
      if (diff->restart_rows_to_go == 0)
181
0
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
0
    }
184
185
17.2k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
17.2k
    MCU_count =
188
17.2k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
17.2k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
17.2k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
17.2k
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
17.2k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
17.2k
    diff->MCU_ctr = 0;
204
17.2k
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
26.3k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
13.0k
    compptr = cinfo->cur_comp_info[ci];
213
13.0k
    compi = compptr->component_index;
214
13.0k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
30.0k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
28.0k
                compptr->last_row_height : compptr->v_samp_factor);
217
16.9k
         prev_row = row, row++) {
218
16.9k
      (*losslessd->predict_undifference[compi])
219
16.9k
        (cinfo, compi, diff->diff_buf[compi][row],
220
16.9k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
16.9k
          compptr->width_in_blocks);
222
16.9k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
16.9k
                                  output_buf[compi][row],
224
16.9k
                                  compptr->width_in_blocks);
225
16.9k
    }
226
13.0k
  }
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
13.3k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
12.2k
    start_iMCU_row(cinfo);
236
12.2k
    return JPEG_ROW_COMPLETED;
237
12.2k
  }
238
  /* Completed the scan */
239
1.02k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.02k
  return JPEG_SCAN_COMPLETED;
241
13.3k
}
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
29.2k
{
267
29.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
29.2k
  int ci, compi;
269
29.2k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
29.2k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
58.4k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
29.2k
    compptr = cinfo->cur_comp_info[ci];
275
29.2k
    compi = compptr->component_index;
276
29.2k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
29.2k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
29.2k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
29.2k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
29.2k
  }
281
282
29.2k
  return decompress_data(cinfo, buffer);
283
29.2k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
4.45k
{
267
4.45k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
4.45k
  int ci, compi;
269
4.45k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
4.45k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
8.91k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
4.45k
    compptr = cinfo->cur_comp_info[ci];
275
4.45k
    compi = compptr->component_index;
276
4.45k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
4.45k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
4.45k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
4.45k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
4.45k
  }
281
282
4.45k
  return decompress_data(cinfo, buffer);
283
4.45k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
11.4k
{
267
11.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
11.4k
  int ci, compi;
269
11.4k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
11.4k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
22.9k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
11.4k
    compptr = cinfo->cur_comp_info[ci];
275
11.4k
    compi = compptr->component_index;
276
11.4k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
11.4k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
11.4k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
11.4k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
11.4k
  }
281
282
11.4k
  return decompress_data(cinfo, buffer);
283
11.4k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
13.3k
{
267
13.3k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
13.3k
  int ci, compi;
269
13.3k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
13.3k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
26.6k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
13.3k
    compptr = cinfo->cur_comp_info[ci];
275
13.3k
    compi = compptr->component_index;
276
13.3k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
13.3k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
13.3k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
13.3k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
13.3k
  }
281
282
13.3k
  return decompress_data(cinfo, buffer);
283
13.3k
}
284
285
286
/*
287
 * Output some data from the full-image sample buffer in the multi-pass case.
288
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
289
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
290
 *
291
 * NB: output_buf contains a plane for each component in image.
292
 */
293
294
METHODDEF(int)
295
output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
296
1
{
297
1
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
1
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
1
  int ci, samp_rows, row;
300
1
  _JSAMPARRAY buffer;
301
1
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
1
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
1
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
1
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
0
  }
310
311
  /* OK, output from the virtual arrays. */
312
3
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
2
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
2
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
2
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
2
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
2
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
2
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1
      samp_rows = compptr->v_samp_factor;
322
1
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1
    }
327
328
3
    for (row = 0; row < samp_rows; row++) {
329
1
      memcpy(output_buf[ci][row], buffer[row],
330
1
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1
    }
332
2
  }
333
334
1
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
1
  return JPEG_SCAN_COMPLETED;
337
1
}
jddiffct-8.c:output_data
Line
Count
Source
296
1
{
297
1
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
1
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
1
  int ci, samp_rows, row;
300
1
  _JSAMPARRAY buffer;
301
1
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
1
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
1
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
1
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
0
  }
310
311
  /* OK, output from the virtual arrays. */
312
3
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
2
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
2
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
2
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
2
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
2
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
2
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1
      samp_rows = compptr->v_samp_factor;
322
1
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1
    }
327
328
3
    for (row = 0; row < samp_rows; row++) {
329
1
      memcpy(output_buf[ci][row], buffer[row],
330
1
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1
    }
332
2
  }
333
334
1
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
1
  return JPEG_SCAN_COMPLETED;
337
1
}
Unexecuted instantiation: jddiffct-12.c:output_data
Unexecuted instantiation: jddiffct-16.c:output_data
338
339
#endif /* D_MULTISCAN_FILES_SUPPORTED */
340
341
342
/*
343
 * Initialize difference buffer controller.
344
 */
345
346
GLOBAL(void)
347
_jinit_d_diff_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
348
1.27k
{
349
1.27k
  my_diff_ptr diff;
350
1.27k
  int ci;
351
1.27k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
563
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
707
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
707
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.27k
  diff = (my_diff_ptr)
362
1.27k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.27k
                                sizeof(my_diff_controller));
364
1.27k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.27k
  diff->pub.start_input_pass = start_input_pass;
366
1.27k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
5.02k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
3.75k
       ci++, compptr++) {
371
3.75k
    diff->diff_buf[ci] =
372
3.75k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
3.75k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
3.75k
                                         (long)compptr->h_samp_factor),
375
3.75k
                   (JDIMENSION)compptr->v_samp_factor);
376
3.75k
    diff->undiff_buf[ci] =
377
3.75k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
3.75k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
3.75k
                                         (long)compptr->h_samp_factor),
380
3.75k
                   (JDIMENSION)compptr->v_samp_factor);
381
3.75k
  }
382
383
1.27k
  if (need_full_buffer) {
384
710
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
710
    int access_rows;
387
388
2.84k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
2.13k
         ci++, compptr++) {
390
2.13k
      access_rows = compptr->v_samp_factor;
391
2.13k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
2.13k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
2.13k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
2.13k
                               (long)compptr->h_samp_factor),
395
2.13k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
2.13k
                               (long)compptr->v_samp_factor),
397
2.13k
         (JDIMENSION)access_rows);
398
2.13k
    }
399
710
    diff->pub.consume_data = consume_data;
400
710
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
710
  } else {
405
560
    diff->pub.consume_data = dummy_consume_data;
406
560
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
560
  }
409
1.27k
}
jinit_d_diff_controller
Line
Count
Source
348
563
{
349
563
  my_diff_ptr diff;
350
563
  int ci;
351
563
  jpeg_component_info *compptr;
352
353
563
#if BITS_IN_JSAMPLE == 8
354
563
  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
563
  diff = (my_diff_ptr)
362
563
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
563
                                sizeof(my_diff_controller));
364
563
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
563
  diff->pub.start_input_pass = start_input_pass;
366
563
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.19k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.63k
       ci++, compptr++) {
371
1.63k
    diff->diff_buf[ci] =
372
1.63k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.63k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.63k
                                         (long)compptr->h_samp_factor),
375
1.63k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.63k
    diff->undiff_buf[ci] =
377
1.63k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.63k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.63k
                                         (long)compptr->h_samp_factor),
380
1.63k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.63k
  }
382
383
563
  if (need_full_buffer) {
384
77
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
77
    int access_rows;
387
388
308
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
231
         ci++, compptr++) {
390
231
      access_rows = compptr->v_samp_factor;
391
231
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
231
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
231
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
231
                               (long)compptr->h_samp_factor),
395
231
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
231
                               (long)compptr->v_samp_factor),
397
231
         (JDIMENSION)access_rows);
398
231
    }
399
77
    diff->pub.consume_data = consume_data;
400
77
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
486
  } else {
405
486
    diff->pub.consume_data = dummy_consume_data;
406
486
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
486
  }
409
563
}
j12init_d_diff_controller
Line
Count
Source
348
316
{
349
316
  my_diff_ptr diff;
350
316
  int ci;
351
316
  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
316
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
316
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
316
  diff = (my_diff_ptr)
362
316
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
316
                                sizeof(my_diff_controller));
364
316
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
316
  diff->pub.start_input_pass = start_input_pass;
366
316
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.26k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
945
       ci++, compptr++) {
371
945
    diff->diff_buf[ci] =
372
945
      ALLOC_DARRAY(JPOOL_IMAGE,
373
945
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
945
                                         (long)compptr->h_samp_factor),
375
945
                   (JDIMENSION)compptr->v_samp_factor);
376
945
    diff->undiff_buf[ci] =
377
945
      ALLOC_DARRAY(JPOOL_IMAGE,
378
945
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
945
                                         (long)compptr->h_samp_factor),
380
945
                   (JDIMENSION)compptr->v_samp_factor);
381
945
  }
382
383
316
  if (need_full_buffer) {
384
279
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
279
    int access_rows;
387
388
1.11k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
837
         ci++, compptr++) {
390
837
      access_rows = compptr->v_samp_factor;
391
837
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
837
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
837
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
837
                               (long)compptr->h_samp_factor),
395
837
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
837
                               (long)compptr->v_samp_factor),
397
837
         (JDIMENSION)access_rows);
398
837
    }
399
279
    diff->pub.consume_data = consume_data;
400
279
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
279
  } else {
405
37
    diff->pub.consume_data = dummy_consume_data;
406
37
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
37
  }
409
316
}
j16init_d_diff_controller
Line
Count
Source
348
391
{
349
391
  my_diff_ptr diff;
350
391
  int ci;
351
391
  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
391
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
391
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
391
  diff = (my_diff_ptr)
362
391
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
391
                                sizeof(my_diff_controller));
364
391
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
391
  diff->pub.start_input_pass = start_input_pass;
366
391
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.56k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.17k
       ci++, compptr++) {
371
1.17k
    diff->diff_buf[ci] =
372
1.17k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.17k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.17k
                                         (long)compptr->h_samp_factor),
375
1.17k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.17k
    diff->undiff_buf[ci] =
377
1.17k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.17k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.17k
                                         (long)compptr->h_samp_factor),
380
1.17k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.17k
  }
382
383
391
  if (need_full_buffer) {
384
354
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
354
    int access_rows;
387
388
1.41k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.06k
         ci++, compptr++) {
390
1.06k
      access_rows = compptr->v_samp_factor;
391
1.06k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.06k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.06k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.06k
                               (long)compptr->h_samp_factor),
395
1.06k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.06k
                               (long)compptr->v_samp_factor),
397
1.06k
         (JDIMENSION)access_rows);
398
1.06k
    }
399
354
    diff->pub.consume_data = consume_data;
400
354
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
354
  } else {
405
37
    diff->pub.consume_data = dummy_consume_data;
406
37
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
37
  }
409
391
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */