Coverage Report

Created: 2026-11-12 06:16

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
49.2k
{
68
49.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
49.2k
  if (cinfo->comps_in_scan > 1) {
75
2.20k
    diff->MCU_rows_per_iMCU_row = 1;
76
47.0k
  } else {
77
47.0k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
43.5k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
3.50k
    else
80
3.50k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
47.0k
  }
82
83
49.2k
  diff->MCU_ctr = 0;
84
49.2k
  diff->MCU_vert_offset = 0;
85
49.2k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
13.8k
{
68
13.8k
  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.8k
  if (cinfo->comps_in_scan > 1) {
75
2.19k
    diff->MCU_rows_per_iMCU_row = 1;
76
11.6k
  } else {
77
11.6k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
10.6k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.08k
    else
80
1.08k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
11.6k
  }
82
83
13.8k
  diff->MCU_ctr = 0;
84
13.8k
  diff->MCU_vert_offset = 0;
85
13.8k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
8.75k
{
68
8.75k
  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
8.75k
  if (cinfo->comps_in_scan > 1) {
75
3
    diff->MCU_rows_per_iMCU_row = 1;
76
8.75k
  } else {
77
8.75k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
7.83k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
917
    else
80
917
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
8.75k
  }
82
83
8.75k
  diff->MCU_ctr = 0;
84
8.75k
  diff->MCU_vert_offset = 0;
85
8.75k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
26.6k
{
68
26.6k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
26.6k
  if (cinfo->comps_in_scan > 1) {
75
3
    diff->MCU_rows_per_iMCU_row = 1;
76
26.6k
  } else {
77
26.6k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
25.1k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.50k
    else
80
1.50k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
26.6k
  }
82
83
26.6k
  diff->MCU_ctr = 0;
84
26.6k
  diff->MCU_vert_offset = 0;
85
26.6k
}
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.58k
{
95
4.58k
  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.58k
  (*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.58k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
3
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
4.58k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
4.58k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
4.58k
  cinfo->input_iMCU_row = 0;
115
4.58k
  start_iMCU_row(cinfo);
116
4.58k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
1.49k
{
95
1.49k
  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.49k
  (*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.49k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.49k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.49k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.49k
  cinfo->input_iMCU_row = 0;
115
1.49k
  start_iMCU_row(cinfo);
116
1.49k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
1.24k
{
95
1.24k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
1.24k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
1.24k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.24k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.24k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.24k
  cinfo->input_iMCU_row = 0;
115
1.24k
  start_iMCU_row(cinfo);
116
1.24k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
1.84k
{
95
1.84k
  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.84k
  (*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.84k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.84k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.84k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.84k
  cinfo->input_iMCU_row = 0;
115
1.84k
  start_iMCU_row(cinfo);
116
1.84k
}
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
22
{
127
22
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
22
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
22
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
22
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
22
  return TRUE;
138
22
}
jddiffct-8.c:process_restart
Line
Count
Source
126
6
{
127
6
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
6
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
6
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
6
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
6
  return TRUE;
138
6
}
jddiffct-12.c:process_restart
Line
Count
Source
126
8
{
127
8
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
8
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
8
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
8
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
8
  return TRUE;
138
8
}
jddiffct-16.c:process_restart
Line
Count
Source
126
8
{
127
8
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
8
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
8
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
8
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
8
  return TRUE;
138
8
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
166
{
148
166
  cinfo->output_iMCU_row = 0;
149
166
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
155
{
148
155
  cinfo->output_iMCU_row = 0;
149
155
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
6
{
148
6
  cinfo->output_iMCU_row = 0;
149
6
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
5
{
148
5
  cinfo->output_iMCU_row = 0;
149
5
}
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
49.2k
{
165
49.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
49.2k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
49.2k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
49.2k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
49.2k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
49.2k
  int ci, compi, row, prev_row;
171
49.2k
  unsigned int yoffset;
172
49.2k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
141k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
92.6k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
92.6k
    if (cinfo->restart_interval) {
180
1.92k
      if (diff->restart_rows_to_go == 0)
181
22
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.92k
    }
184
185
92.6k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
92.6k
    MCU_count =
188
92.6k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
92.6k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
92.6k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
92.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
92.6k
    if (cinfo->restart_interval)
200
1.89k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
92.6k
    diff->MCU_ctr = 0;
204
92.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
101k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
52.7k
    compptr = cinfo->cur_comp_info[ci];
213
52.7k
    compi = compptr->component_index;
214
52.7k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
150k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
142k
                compptr->last_row_height : compptr->v_samp_factor);
217
97.7k
         prev_row = row, row++) {
218
97.7k
      (*losslessd->predict_undifference[compi])
219
97.7k
        (cinfo, compi, diff->diff_buf[compi][row],
220
97.7k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
97.7k
          compptr->width_in_blocks);
222
97.7k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
97.7k
                                  output_buf[compi][row],
224
97.7k
                                  compptr->width_in_blocks);
225
97.7k
    }
226
52.7k
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
49.2k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
44.8k
    start_iMCU_row(cinfo);
236
44.8k
    return JPEG_ROW_COMPLETED;
237
44.8k
  }
238
  /* Completed the scan */
239
4.40k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
4.40k
  return JPEG_SCAN_COMPLETED;
241
49.2k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
13.8k
{
165
13.8k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
13.8k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
13.8k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
13.8k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
13.8k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
13.8k
  int ci, compi, row, prev_row;
171
13.8k
  unsigned int yoffset;
172
13.8k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
41.3k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
27.4k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
27.4k
    if (cinfo->restart_interval) {
180
234
      if (diff->restart_rows_to_go == 0)
181
6
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
234
    }
184
185
27.4k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
27.4k
    MCU_count =
188
27.4k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
27.4k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
27.4k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
27.4k
    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
27.4k
    if (cinfo->restart_interval)
200
224
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
27.4k
    diff->MCU_ctr = 0;
204
27.4k
  }
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.8k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
17.9k
    compptr = cinfo->cur_comp_info[ci];
213
17.9k
    compi = compptr->component_index;
214
17.9k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
51.3k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
48.8k
                compptr->last_row_height : compptr->v_samp_factor);
217
33.4k
         prev_row = row, row++) {
218
33.4k
      (*losslessd->predict_undifference[compi])
219
33.4k
        (cinfo, compi, diff->diff_buf[compi][row],
220
33.4k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
33.4k
          compptr->width_in_blocks);
222
33.4k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
33.4k
                                  output_buf[compi][row],
224
33.4k
                                  compptr->width_in_blocks);
225
33.4k
    }
226
17.9k
  }
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.8k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
12.4k
    start_iMCU_row(cinfo);
236
12.4k
    return JPEG_ROW_COMPLETED;
237
12.4k
  }
238
  /* Completed the scan */
239
1.45k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.45k
  return JPEG_SCAN_COMPLETED;
241
13.8k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
8.75k
{
165
8.75k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
8.75k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
8.75k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
8.75k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
8.75k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
8.75k
  int ci, compi, row, prev_row;
171
8.75k
  unsigned int yoffset;
172
8.75k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
25.5k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
16.8k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
16.8k
    if (cinfo->restart_interval) {
180
1.44k
      if (diff->restart_rows_to_go == 0)
181
8
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.44k
    }
184
185
16.8k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
16.8k
    MCU_count =
188
16.8k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
16.8k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
16.8k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
16.8k
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
16.8k
    if (cinfo->restart_interval)
200
1.43k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
16.8k
    diff->MCU_ctr = 0;
204
16.8k
  }
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
17.2k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
8.46k
    compptr = cinfo->cur_comp_info[ci];
213
8.46k
    compi = compptr->component_index;
214
8.46k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
24.8k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
22.3k
                compptr->last_row_height : compptr->v_samp_factor);
217
16.3k
         prev_row = row, row++) {
218
16.3k
      (*losslessd->predict_undifference[compi])
219
16.3k
        (cinfo, compi, diff->diff_buf[compi][row],
220
16.3k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
16.3k
          compptr->width_in_blocks);
222
16.3k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
16.3k
                                  output_buf[compi][row],
224
16.3k
                                  compptr->width_in_blocks);
225
16.3k
    }
226
8.46k
  }
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
8.75k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
7.55k
    start_iMCU_row(cinfo);
236
7.55k
    return JPEG_ROW_COMPLETED;
237
7.55k
  }
238
  /* Completed the scan */
239
1.19k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.19k
  return JPEG_SCAN_COMPLETED;
241
8.75k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
26.6k
{
165
26.6k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
26.6k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
26.6k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
26.6k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
26.6k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
26.6k
  int ci, compi, row, prev_row;
171
26.6k
  unsigned int yoffset;
172
26.6k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
74.9k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
48.3k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
48.3k
    if (cinfo->restart_interval) {
180
248
      if (diff->restart_rows_to_go == 0)
181
8
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
248
    }
184
185
48.3k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
48.3k
    MCU_count =
188
48.3k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
48.3k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
48.3k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
48.3k
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
48.3k
    if (cinfo->restart_interval)
200
237
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
48.3k
    diff->MCU_ctr = 0;
204
48.3k
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
52.9k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
26.3k
    compptr = cinfo->cur_comp_info[ci];
213
26.3k
    compi = compptr->component_index;
214
26.3k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
74.3k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
70.9k
                compptr->last_row_height : compptr->v_samp_factor);
217
47.9k
         prev_row = row, row++) {
218
47.9k
      (*losslessd->predict_undifference[compi])
219
47.9k
        (cinfo, compi, diff->diff_buf[compi][row],
220
47.9k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
47.9k
          compptr->width_in_blocks);
222
47.9k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
47.9k
                                  output_buf[compi][row],
224
47.9k
                                  compptr->width_in_blocks);
225
47.9k
    }
226
26.3k
  }
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
26.6k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
24.8k
    start_iMCU_row(cinfo);
236
24.8k
    return JPEG_ROW_COMPLETED;
237
24.8k
  }
238
  /* Completed the scan */
239
1.75k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.75k
  return JPEG_SCAN_COMPLETED;
241
26.6k
}
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
47.0k
{
267
47.0k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
47.0k
  int ci, compi;
269
47.0k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
47.0k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
94.0k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
47.0k
    compptr = cinfo->cur_comp_info[ci];
275
47.0k
    compi = compptr->component_index;
276
47.0k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
47.0k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
47.0k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
47.0k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
47.0k
  }
281
282
47.0k
  return decompress_data(cinfo, buffer);
283
47.0k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
11.6k
{
267
11.6k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
11.6k
  int ci, compi;
269
11.6k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
11.6k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
23.3k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
11.6k
    compptr = cinfo->cur_comp_info[ci];
275
11.6k
    compi = compptr->component_index;
276
11.6k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
11.6k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
11.6k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
11.6k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
11.6k
  }
281
282
11.6k
  return decompress_data(cinfo, buffer);
283
11.6k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
8.75k
{
267
8.75k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
8.75k
  int ci, compi;
269
8.75k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
8.75k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
17.5k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
8.75k
    compptr = cinfo->cur_comp_info[ci];
275
8.75k
    compi = compptr->component_index;
276
8.75k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
8.75k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
8.75k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
8.75k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
8.75k
  }
281
282
8.75k
  return decompress_data(cinfo, buffer);
283
8.75k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
26.6k
{
267
26.6k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
26.6k
  int ci, compi;
269
26.6k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
26.6k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
53.2k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
26.6k
    compptr = cinfo->cur_comp_info[ci];
275
26.6k
    compi = compptr->component_index;
276
26.6k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
26.6k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
26.6k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
26.6k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
26.6k
  }
281
282
26.6k
  return decompress_data(cinfo, buffer);
283
26.6k
}
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
19
{
297
19
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
19
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
19
  int ci, samp_rows, row;
300
19
  _JSAMPARRAY buffer;
301
19
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
19
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
19
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
19
          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
69
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
50
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
50
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
50
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
50
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
50
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
50
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
9
      samp_rows = compptr->v_samp_factor;
322
41
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
41
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
41
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
41
    }
327
328
110
    for (row = 0; row < samp_rows; row++) {
329
60
      memcpy(output_buf[ci][row], buffer[row],
330
60
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
60
    }
332
50
  }
333
334
19
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
2
    return JPEG_ROW_COMPLETED;
336
17
  return JPEG_SCAN_COMPLETED;
337
19
}
jddiffct-8.c:output_data
Line
Count
Source
296
19
{
297
19
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
19
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
19
  int ci, samp_rows, row;
300
19
  _JSAMPARRAY buffer;
301
19
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
19
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
19
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
19
          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
69
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
50
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
50
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
50
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
50
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
50
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
50
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
9
      samp_rows = compptr->v_samp_factor;
322
41
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
41
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
41
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
41
    }
327
328
110
    for (row = 0; row < samp_rows; row++) {
329
60
      memcpy(output_buf[ci][row], buffer[row],
330
60
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
60
    }
332
50
  }
333
334
19
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
2
    return JPEG_ROW_COMPLETED;
336
17
  return JPEG_SCAN_COMPLETED;
337
19
}
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.40k
{
349
1.40k
  my_diff_ptr diff;
350
1.40k
  int ci;
351
1.40k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
523
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
877
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
877
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.40k
  diff = (my_diff_ptr)
362
1.40k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.40k
                                sizeof(my_diff_controller));
364
1.40k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.40k
  diff->pub.start_input_pass = start_input_pass;
366
1.40k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
5.66k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.26k
       ci++, compptr++) {
371
4.26k
    diff->diff_buf[ci] =
372
4.26k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.26k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.26k
                                         (long)compptr->h_samp_factor),
375
4.26k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.26k
    diff->undiff_buf[ci] =
377
4.26k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.26k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.26k
                                         (long)compptr->h_samp_factor),
380
4.26k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.26k
  }
382
383
1.40k
  if (need_full_buffer) {
384
1.20k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.20k
    int access_rows;
387
388
4.81k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.60k
         ci++, compptr++) {
390
3.60k
      access_rows = compptr->v_samp_factor;
391
3.60k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.60k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.60k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.60k
                               (long)compptr->h_samp_factor),
395
3.60k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.60k
                               (long)compptr->v_samp_factor),
397
3.60k
         (JDIMENSION)access_rows);
398
3.60k
    }
399
1.20k
    diff->pub.consume_data = consume_data;
400
1.20k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.20k
  } else {
405
198
    diff->pub.consume_data = dummy_consume_data;
406
198
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
198
  }
409
1.40k
}
jinit_d_diff_controller
Line
Count
Source
348
523
{
349
523
  my_diff_ptr diff;
350
523
  int ci;
351
523
  jpeg_component_info *compptr;
352
353
523
#if BITS_IN_JSAMPLE == 8
354
523
  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
523
  diff = (my_diff_ptr)
362
523
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
523
                                sizeof(my_diff_controller));
364
523
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
523
  diff->pub.start_input_pass = start_input_pass;
366
523
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.12k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.60k
       ci++, compptr++) {
371
1.60k
    diff->diff_buf[ci] =
372
1.60k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.60k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.60k
                                         (long)compptr->h_samp_factor),
375
1.60k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.60k
    diff->undiff_buf[ci] =
377
1.60k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.60k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.60k
                                         (long)compptr->h_samp_factor),
380
1.60k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.60k
  }
382
383
523
  if (need_full_buffer) {
384
376
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
376
    int access_rows;
387
388
1.50k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.12k
         ci++, compptr++) {
390
1.12k
      access_rows = compptr->v_samp_factor;
391
1.12k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.12k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.12k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.12k
                               (long)compptr->h_samp_factor),
395
1.12k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.12k
                               (long)compptr->v_samp_factor),
397
1.12k
         (JDIMENSION)access_rows);
398
1.12k
    }
399
376
    diff->pub.consume_data = consume_data;
400
376
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
376
  } else {
405
147
    diff->pub.consume_data = dummy_consume_data;
406
147
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
147
  }
409
523
}
j12init_d_diff_controller
Line
Count
Source
348
426
{
349
426
  my_diff_ptr diff;
350
426
  int ci;
351
426
  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
426
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
426
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
426
  diff = (my_diff_ptr)
362
426
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
426
                                sizeof(my_diff_controller));
364
426
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
426
  diff->pub.start_input_pass = start_input_pass;
366
426
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.72k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.29k
       ci++, compptr++) {
371
1.29k
    diff->diff_buf[ci] =
372
1.29k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.29k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.29k
                                         (long)compptr->h_samp_factor),
375
1.29k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.29k
    diff->undiff_buf[ci] =
377
1.29k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.29k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.29k
                                         (long)compptr->h_samp_factor),
380
1.29k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.29k
  }
382
383
426
  if (need_full_buffer) {
384
402
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
402
    int access_rows;
387
388
1.60k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.20k
         ci++, compptr++) {
390
1.20k
      access_rows = compptr->v_samp_factor;
391
1.20k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.20k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.20k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.20k
                               (long)compptr->h_samp_factor),
395
1.20k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.20k
                               (long)compptr->v_samp_factor),
397
1.20k
         (JDIMENSION)access_rows);
398
1.20k
    }
399
402
    diff->pub.consume_data = consume_data;
400
402
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
402
  } else {
405
24
    diff->pub.consume_data = dummy_consume_data;
406
24
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
24
  }
409
426
}
j16init_d_diff_controller
Line
Count
Source
348
451
{
349
451
  my_diff_ptr diff;
350
451
  int ci;
351
451
  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
451
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
451
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
451
  diff = (my_diff_ptr)
362
451
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
451
                                sizeof(my_diff_controller));
364
451
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
451
  diff->pub.start_input_pass = start_input_pass;
366
451
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.81k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.36k
       ci++, compptr++) {
371
1.36k
    diff->diff_buf[ci] =
372
1.36k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.36k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.36k
                                         (long)compptr->h_samp_factor),
375
1.36k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.36k
    diff->undiff_buf[ci] =
377
1.36k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.36k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.36k
                                         (long)compptr->h_samp_factor),
380
1.36k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.36k
  }
382
383
451
  if (need_full_buffer) {
384
424
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
424
    int access_rows;
387
388
1.69k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.27k
         ci++, compptr++) {
390
1.27k
      access_rows = compptr->v_samp_factor;
391
1.27k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.27k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.27k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.27k
                               (long)compptr->h_samp_factor),
395
1.27k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.27k
                               (long)compptr->v_samp_factor),
397
1.27k
         (JDIMENSION)access_rows);
398
1.27k
    }
399
424
    diff->pub.consume_data = consume_data;
400
424
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
424
  } else {
405
27
    diff->pub.consume_data = dummy_consume_data;
406
27
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
27
  }
409
451
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */