Coverage Report

Created: 2026-03-12 08:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.3.0.x/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, 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
186M
{
68
186M
  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
186M
  if (cinfo->comps_in_scan > 1) {
75
28.9M
    diff->MCU_rows_per_iMCU_row = 1;
76
157M
  } else {
77
157M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
157M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
24.5k
    else
80
24.5k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
157M
  }
82
83
186M
  diff->MCU_ctr = 0;
84
186M
  diff->MCU_vert_offset = 0;
85
186M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
33.2k
{
95
33.2k
  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
33.2k
  (*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
33.2k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
61
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
33.2k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
33.2k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
33.2k
  cinfo->input_iMCU_row = 0;
115
33.2k
  start_iMCU_row(cinfo);
116
33.2k
}
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
13.2M
{
127
13.2M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
13.2M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
13.2M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
13.2M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
13.2M
  return TRUE;
138
13.2M
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
4.04k
{
148
4.04k
  cinfo->output_iMCU_row = 0;
149
4.04k
}
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
186M
{
165
186M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
186M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
186M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
186M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
186M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
186M
  int ci, compi, row, prev_row;
171
186M
  unsigned int yoffset;
172
186M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
382M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
196M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
196M
    if (cinfo->restart_interval) {
180
52.5M
      if (diff->restart_rows_to_go == 0)
181
13.2M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
52.5M
    }
184
185
196M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
196M
    MCU_count =
188
196M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
196M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
196M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
196M
    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
196M
    if (cinfo->restart_interval)
200
52.5M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
196M
    diff->MCU_ctr = 0;
204
196M
  }
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
428M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
241M
    compptr = cinfo->cur_comp_info[ci];
213
241M
    compi = compptr->component_index;
214
241M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
515M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
515M
                compptr->last_row_height : compptr->v_samp_factor);
217
274M
         prev_row = row, row++) {
218
274M
      (*losslessd->predict_undifference[compi])
219
274M
        (cinfo, compi, diff->diff_buf[compi][row],
220
274M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
274M
          compptr->width_in_blocks);
222
274M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
274M
                                  output_buf[compi][row],
224
274M
                                  compptr->width_in_blocks);
225
274M
    }
226
241M
  }
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
186M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
186M
    start_iMCU_row(cinfo);
236
186M
    return JPEG_ROW_COMPLETED;
237
186M
  }
238
  /* Completed the scan */
239
32.4k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
32.4k
  return JPEG_SCAN_COMPLETED;
241
186M
}
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
}
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
185M
{
267
185M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
185M
  int ci, compi;
269
185M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
185M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
423M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
238M
    compptr = cinfo->cur_comp_info[ci];
275
238M
    compi = compptr->component_index;
276
238M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
238M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
238M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
238M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
238M
  }
281
282
185M
  return decompress_data(cinfo, buffer);
283
185M
}
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
334k
{
297
334k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
334k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
334k
  int ci, samp_rows, row;
300
334k
  _JSAMPARRAY buffer;
301
334k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
334k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
334k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
334k
          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
1.33M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
1.00M
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
1.00M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
1.00M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
1.00M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
1.00M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
1.00M
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1.00M
      samp_rows = compptr->v_samp_factor;
322
1.59k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1.59k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1.59k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1.59k
    }
327
328
2.06M
    for (row = 0; row < samp_rows; row++) {
329
1.06M
      memcpy(output_buf[ci][row], buffer[row],
330
1.06M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1.06M
    }
332
1.00M
  }
333
334
334k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
333k
    return JPEG_ROW_COMPLETED;
336
1.30k
  return JPEG_SCAN_COMPLETED;
337
334k
}
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
6.35k
{
349
6.35k
  my_diff_ptr diff;
350
6.35k
  int ci;
351
6.35k
  jpeg_component_info *compptr;
352
353
6.35k
  diff = (my_diff_ptr)
354
6.35k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
355
6.35k
                                sizeof(my_diff_controller));
356
6.35k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
357
6.35k
  diff->pub.start_input_pass = start_input_pass;
358
6.35k
  diff->pub.start_output_pass = start_output_pass;
359
360
  /* Create the [un]difference buffers. */
361
24.8k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
362
18.4k
       ci++, compptr++) {
363
18.4k
    diff->diff_buf[ci] =
364
18.4k
      ALLOC_DARRAY(JPOOL_IMAGE,
365
18.4k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
366
18.4k
                                         (long)compptr->h_samp_factor),
367
18.4k
                   (JDIMENSION)compptr->v_samp_factor);
368
18.4k
    diff->undiff_buf[ci] =
369
18.4k
      ALLOC_DARRAY(JPOOL_IMAGE,
370
18.4k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
371
18.4k
                                         (long)compptr->h_samp_factor),
372
18.4k
                   (JDIMENSION)compptr->v_samp_factor);
373
18.4k
  }
374
375
6.35k
  if (need_full_buffer) {
376
5.62k
#ifdef D_MULTISCAN_FILES_SUPPORTED
377
    /* Allocate a full-image virtual array for each component. */
378
5.62k
    int access_rows;
379
380
22.5k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
381
16.8k
         ci++, compptr++) {
382
16.8k
      access_rows = compptr->v_samp_factor;
383
16.8k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
384
16.8k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
385
16.8k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
386
16.8k
                               (long)compptr->h_samp_factor),
387
16.8k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
388
16.8k
                               (long)compptr->v_samp_factor),
389
16.8k
         (JDIMENSION)access_rows);
390
16.8k
    }
391
5.62k
    diff->pub.consume_data = consume_data;
392
5.62k
    diff->pub._decompress_data = output_data;
393
#else
394
    ERREXIT(cinfo, JERR_NOT_COMPILED);
395
#endif
396
5.62k
  } else {
397
726
    diff->pub.consume_data = dummy_consume_data;
398
726
    diff->pub._decompress_data = decompress_data;
399
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
400
726
  }
401
6.35k
}
j12init_d_diff_controller
Line
Count
Source
348
2.11k
{
349
2.11k
  my_diff_ptr diff;
350
2.11k
  int ci;
351
2.11k
  jpeg_component_info *compptr;
352
353
2.11k
  diff = (my_diff_ptr)
354
2.11k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
355
2.11k
                                sizeof(my_diff_controller));
356
2.11k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
357
2.11k
  diff->pub.start_input_pass = start_input_pass;
358
2.11k
  diff->pub.start_output_pass = start_output_pass;
359
360
  /* Create the [un]difference buffers. */
361
8.33k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
362
6.21k
       ci++, compptr++) {
363
6.21k
    diff->diff_buf[ci] =
364
6.21k
      ALLOC_DARRAY(JPOOL_IMAGE,
365
6.21k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
366
6.21k
                                         (long)compptr->h_samp_factor),
367
6.21k
                   (JDIMENSION)compptr->v_samp_factor);
368
6.21k
    diff->undiff_buf[ci] =
369
6.21k
      ALLOC_DARRAY(JPOOL_IMAGE,
370
6.21k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
371
6.21k
                                         (long)compptr->h_samp_factor),
372
6.21k
                   (JDIMENSION)compptr->v_samp_factor);
373
6.21k
  }
374
375
2.11k
  if (need_full_buffer) {
376
1.90k
#ifdef D_MULTISCAN_FILES_SUPPORTED
377
    /* Allocate a full-image virtual array for each component. */
378
1.90k
    int access_rows;
379
380
7.64k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
381
5.73k
         ci++, compptr++) {
382
5.73k
      access_rows = compptr->v_samp_factor;
383
5.73k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
384
5.73k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
385
5.73k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
386
5.73k
                               (long)compptr->h_samp_factor),
387
5.73k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
388
5.73k
                               (long)compptr->v_samp_factor),
389
5.73k
         (JDIMENSION)access_rows);
390
5.73k
    }
391
1.90k
    diff->pub.consume_data = consume_data;
392
1.90k
    diff->pub._decompress_data = output_data;
393
#else
394
    ERREXIT(cinfo, JERR_NOT_COMPILED);
395
#endif
396
1.90k
  } else {
397
209
    diff->pub.consume_data = dummy_consume_data;
398
209
    diff->pub._decompress_data = decompress_data;
399
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
400
209
  }
401
2.11k
}
j16init_d_diff_controller
Line
Count
Source
348
2.26k
{
349
2.26k
  my_diff_ptr diff;
350
2.26k
  int ci;
351
2.26k
  jpeg_component_info *compptr;
352
353
2.26k
  diff = (my_diff_ptr)
354
2.26k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
355
2.26k
                                sizeof(my_diff_controller));
356
2.26k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
357
2.26k
  diff->pub.start_input_pass = start_input_pass;
358
2.26k
  diff->pub.start_output_pass = start_output_pass;
359
360
  /* Create the [un]difference buffers. */
361
8.86k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
362
6.59k
       ci++, compptr++) {
363
6.59k
    diff->diff_buf[ci] =
364
6.59k
      ALLOC_DARRAY(JPOOL_IMAGE,
365
6.59k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
366
6.59k
                                         (long)compptr->h_samp_factor),
367
6.59k
                   (JDIMENSION)compptr->v_samp_factor);
368
6.59k
    diff->undiff_buf[ci] =
369
6.59k
      ALLOC_DARRAY(JPOOL_IMAGE,
370
6.59k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
371
6.59k
                                         (long)compptr->h_samp_factor),
372
6.59k
                   (JDIMENSION)compptr->v_samp_factor);
373
6.59k
  }
374
375
2.26k
  if (need_full_buffer) {
376
1.96k
#ifdef D_MULTISCAN_FILES_SUPPORTED
377
    /* Allocate a full-image virtual array for each component. */
378
1.96k
    int access_rows;
379
380
7.87k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
381
5.91k
         ci++, compptr++) {
382
5.91k
      access_rows = compptr->v_samp_factor;
383
5.91k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
384
5.91k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
385
5.91k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
386
5.91k
                               (long)compptr->h_samp_factor),
387
5.91k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
388
5.91k
                               (long)compptr->v_samp_factor),
389
5.91k
         (JDIMENSION)access_rows);
390
5.91k
    }
391
1.96k
    diff->pub.consume_data = consume_data;
392
1.96k
    diff->pub._decompress_data = output_data;
393
#else
394
    ERREXIT(cinfo, JERR_NOT_COMPILED);
395
#endif
396
1.96k
  } else {
397
294
    diff->pub.consume_data = dummy_consume_data;
398
294
    diff->pub._decompress_data = decompress_data;
399
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
400
294
  }
401
2.26k
}
jinit_d_diff_controller
Line
Count
Source
348
1.97k
{
349
1.97k
  my_diff_ptr diff;
350
1.97k
  int ci;
351
1.97k
  jpeg_component_info *compptr;
352
353
1.97k
  diff = (my_diff_ptr)
354
1.97k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
355
1.97k
                                sizeof(my_diff_controller));
356
1.97k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
357
1.97k
  diff->pub.start_input_pass = start_input_pass;
358
1.97k
  diff->pub.start_output_pass = start_output_pass;
359
360
  /* Create the [un]difference buffers. */
361
7.65k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
362
5.68k
       ci++, compptr++) {
363
5.68k
    diff->diff_buf[ci] =
364
5.68k
      ALLOC_DARRAY(JPOOL_IMAGE,
365
5.68k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
366
5.68k
                                         (long)compptr->h_samp_factor),
367
5.68k
                   (JDIMENSION)compptr->v_samp_factor);
368
5.68k
    diff->undiff_buf[ci] =
369
5.68k
      ALLOC_DARRAY(JPOOL_IMAGE,
370
5.68k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
371
5.68k
                                         (long)compptr->h_samp_factor),
372
5.68k
                   (JDIMENSION)compptr->v_samp_factor);
373
5.68k
  }
374
375
1.97k
  if (need_full_buffer) {
376
1.74k
#ifdef D_MULTISCAN_FILES_SUPPORTED
377
    /* Allocate a full-image virtual array for each component. */
378
1.74k
    int access_rows;
379
380
6.99k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
381
5.24k
         ci++, compptr++) {
382
5.24k
      access_rows = compptr->v_samp_factor;
383
5.24k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
384
5.24k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
385
5.24k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
386
5.24k
                               (long)compptr->h_samp_factor),
387
5.24k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
388
5.24k
                               (long)compptr->v_samp_factor),
389
5.24k
         (JDIMENSION)access_rows);
390
5.24k
    }
391
1.74k
    diff->pub.consume_data = consume_data;
392
1.74k
    diff->pub._decompress_data = output_data;
393
#else
394
    ERREXIT(cinfo, JERR_NOT_COMPILED);
395
#endif
396
1.74k
  } else {
397
223
    diff->pub.consume_data = dummy_consume_data;
398
223
    diff->pub._decompress_data = decompress_data;
399
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
400
223
  }
401
1.97k
}
402
403
#endif /* D_LOSSLESS_SUPPORTED */