Coverage Report

Created: 2023-09-28 22:18

/src/libjpeg-turbo.main/jddiffct.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * jddiffct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1997, Thomas G. Lane.
6
 * Lossless JPEG Modifications:
7
 * Copyright (C) 1999, Ken Murchison.
8
 * libjpeg-turbo Modifications:
9
 * Copyright (C) 2022, 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
12.0M
{
68
12.0M
  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
12.0M
  if (cinfo->comps_in_scan > 1) {
75
6.38M
    diff->MCU_rows_per_iMCU_row = 1;
76
6.38M
  } else {
77
5.65M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
5.63M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
18.6k
    else
80
18.6k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
5.65M
  }
82
83
12.0M
  diff->MCU_ctr = 0;
84
12.0M
  diff->MCU_vert_offset = 0;
85
12.0M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
36.2k
{
95
36.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
36.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
36.2k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
80
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
36.2k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
36.2k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
36.2k
  cinfo->input_iMCU_row = 0;
115
36.2k
  start_iMCU_row(cinfo);
116
36.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
852k
{
127
852k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
852k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
852k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
852k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
852k
  return TRUE;
138
852k
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
10.9k
{
148
10.9k
  cinfo->output_iMCU_row = 0;
149
10.9k
}
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
12.0M
{
165
12.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
12.0M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
12.0M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
12.0M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
12.0M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
12.0M
  int ci, compi, row, prev_row;
171
12.0M
  unsigned int yoffset;
172
12.0M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
36.6M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
24.6M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
24.6M
    if (cinfo->restart_interval) {
180
6.75M
      if (diff->restart_rows_to_go == 0)
181
852k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
6.75M
    }
184
185
24.6M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
24.6M
    MCU_count =
188
24.6M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
24.6M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
24.6M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
24.6M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
24.6M
    if (cinfo->restart_interval)
200
6.75M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
24.6M
    diff->MCU_ctr = 0;
204
24.6M
  }
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
36.8M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
24.7M
    compptr = cinfo->cur_comp_info[ci];
213
24.7M
    compi = compptr->component_index;
214
24.7M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
68.3M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
68.2M
                compptr->last_row_height : compptr->v_samp_factor);
217
43.6M
         prev_row = row, row++) {
218
43.6M
      (*losslessd->predict_undifference[compi])
219
43.6M
        (cinfo, compi, diff->diff_buf[compi][row],
220
43.6M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
43.6M
          compptr->width_in_blocks);
222
43.6M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
43.6M
                                  output_buf[compi][row],
224
43.6M
                                  compptr->width_in_blocks);
225
43.6M
    }
226
24.7M
  }
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
12.0M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
12.0M
    start_iMCU_row(cinfo);
236
12.0M
    return JPEG_ROW_COMPLETED;
237
12.0M
  }
238
  /* Completed the scan */
239
35.3k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
35.3k
  return JPEG_SCAN_COMPLETED;
241
12.0M
}
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
6.00M
{
267
6.00M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
6.00M
  int ci, compi;
269
6.00M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
6.00M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
12.6M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
6.65M
    compptr = cinfo->cur_comp_info[ci];
275
6.65M
    compi = compptr->component_index;
276
6.65M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
6.65M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
6.65M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
6.65M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
6.65M
  }
281
282
6.00M
  return decompress_data(cinfo, buffer);
283
6.00M
}
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
263k
{
297
263k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
263k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
263k
  int ci, samp_rows, row;
300
263k
  _JSAMPARRAY buffer;
301
263k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
263k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
263k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
263k
          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.05M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
789k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
789k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
789k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
789k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
789k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
789k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
786k
      samp_rows = compptr->v_samp_factor;
322
2.58k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
2.58k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
2.58k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
2.58k
    }
327
328
2.39M
    for (row = 0; row < samp_rows; row++) {
329
1.60M
      memcpy(output_buf[ci][row], buffer[row],
330
1.60M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1.60M
    }
332
789k
  }
333
334
263k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
262k
    return JPEG_ROW_COMPLETED;
336
1.34k
  return JPEG_SCAN_COMPLETED;
337
263k
}
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
12.8k
{
349
12.8k
  my_diff_ptr diff;
350
12.8k
  int ci;
351
12.8k
  jpeg_component_info *compptr;
352
353
12.8k
  diff = (my_diff_ptr)
354
12.8k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
355
12.8k
                                sizeof(my_diff_controller));
356
12.8k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
357
12.8k
  diff->pub.start_input_pass = start_input_pass;
358
12.8k
  diff->pub.start_output_pass = start_output_pass;
359
360
  /* Create the [un]difference buffers. */
361
51.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
362
38.4k
       ci++, compptr++) {
363
38.4k
    diff->diff_buf[ci] =
364
38.4k
      ALLOC_DARRAY(JPOOL_IMAGE,
365
38.4k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
366
38.4k
                                         (long)compptr->h_samp_factor),
367
38.4k
                   (JDIMENSION)compptr->v_samp_factor);
368
38.4k
    diff->undiff_buf[ci] =
369
38.4k
      ALLOC_DARRAY(JPOOL_IMAGE,
370
38.4k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
371
38.4k
                                         (long)compptr->h_samp_factor),
372
38.4k
                   (JDIMENSION)compptr->v_samp_factor);
373
38.4k
  }
374
375
12.8k
  if (need_full_buffer) {
376
2.62k
#ifdef D_MULTISCAN_FILES_SUPPORTED
377
    /* Allocate a full-image virtual array for each component. */
378
2.62k
    int access_rows;
379
380
10.5k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
381
7.88k
         ci++, compptr++) {
382
7.88k
      access_rows = compptr->v_samp_factor;
383
7.88k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
384
7.88k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
385
7.88k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
386
7.88k
                               (long)compptr->h_samp_factor),
387
7.88k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
388
7.88k
                               (long)compptr->v_samp_factor),
389
7.88k
         (JDIMENSION)access_rows);
390
7.88k
    }
391
2.62k
    diff->pub.consume_data = consume_data;
392
2.62k
    diff->pub._decompress_data = output_data;
393
#else
394
    ERREXIT(cinfo, JERR_NOT_COMPILED);
395
#endif
396
10.1k
  } else {
397
10.1k
    diff->pub.consume_data = dummy_consume_data;
398
10.1k
    diff->pub._decompress_data = decompress_data;
399
10.1k
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
400
10.1k
  }
401
12.8k
}
j12init_d_diff_controller
Line
Count
Source
348
4.13k
{
349
4.13k
  my_diff_ptr diff;
350
4.13k
  int ci;
351
4.13k
  jpeg_component_info *compptr;
352
353
4.13k
  diff = (my_diff_ptr)
354
4.13k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
355
4.13k
                                sizeof(my_diff_controller));
356
4.13k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
357
4.13k
  diff->pub.start_input_pass = start_input_pass;
358
4.13k
  diff->pub.start_output_pass = start_output_pass;
359
360
  /* Create the [un]difference buffers. */
361
16.5k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
362
12.3k
       ci++, compptr++) {
363
12.3k
    diff->diff_buf[ci] =
364
12.3k
      ALLOC_DARRAY(JPOOL_IMAGE,
365
12.3k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
366
12.3k
                                         (long)compptr->h_samp_factor),
367
12.3k
                   (JDIMENSION)compptr->v_samp_factor);
368
12.3k
    diff->undiff_buf[ci] =
369
12.3k
      ALLOC_DARRAY(JPOOL_IMAGE,
370
12.3k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
371
12.3k
                                         (long)compptr->h_samp_factor),
372
12.3k
                   (JDIMENSION)compptr->v_samp_factor);
373
12.3k
  }
374
375
4.13k
  if (need_full_buffer) {
376
918
#ifdef D_MULTISCAN_FILES_SUPPORTED
377
    /* Allocate a full-image virtual array for each component. */
378
918
    int access_rows;
379
380
3.67k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
381
2.75k
         ci++, compptr++) {
382
2.75k
      access_rows = compptr->v_samp_factor;
383
2.75k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
384
2.75k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
385
2.75k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
386
2.75k
                               (long)compptr->h_samp_factor),
387
2.75k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
388
2.75k
                               (long)compptr->v_samp_factor),
389
2.75k
         (JDIMENSION)access_rows);
390
2.75k
    }
391
918
    diff->pub.consume_data = consume_data;
392
918
    diff->pub._decompress_data = output_data;
393
#else
394
    ERREXIT(cinfo, JERR_NOT_COMPILED);
395
#endif
396
3.21k
  } else {
397
3.21k
    diff->pub.consume_data = dummy_consume_data;
398
3.21k
    diff->pub._decompress_data = decompress_data;
399
3.21k
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
400
3.21k
  }
401
4.13k
}
j16init_d_diff_controller
Line
Count
Source
348
4.49k
{
349
4.49k
  my_diff_ptr diff;
350
4.49k
  int ci;
351
4.49k
  jpeg_component_info *compptr;
352
353
4.49k
  diff = (my_diff_ptr)
354
4.49k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
355
4.49k
                                sizeof(my_diff_controller));
356
4.49k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
357
4.49k
  diff->pub.start_input_pass = start_input_pass;
358
4.49k
  diff->pub.start_output_pass = start_output_pass;
359
360
  /* Create the [un]difference buffers. */
361
17.9k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
362
13.4k
       ci++, compptr++) {
363
13.4k
    diff->diff_buf[ci] =
364
13.4k
      ALLOC_DARRAY(JPOOL_IMAGE,
365
13.4k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
366
13.4k
                                         (long)compptr->h_samp_factor),
367
13.4k
                   (JDIMENSION)compptr->v_samp_factor);
368
13.4k
    diff->undiff_buf[ci] =
369
13.4k
      ALLOC_DARRAY(JPOOL_IMAGE,
370
13.4k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
371
13.4k
                                         (long)compptr->h_samp_factor),
372
13.4k
                   (JDIMENSION)compptr->v_samp_factor);
373
13.4k
  }
374
375
4.49k
  if (need_full_buffer) {
376
816
#ifdef D_MULTISCAN_FILES_SUPPORTED
377
    /* Allocate a full-image virtual array for each component. */
378
816
    int access_rows;
379
380
3.26k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
381
2.44k
         ci++, compptr++) {
382
2.44k
      access_rows = compptr->v_samp_factor;
383
2.44k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
384
2.44k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
385
2.44k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
386
2.44k
                               (long)compptr->h_samp_factor),
387
2.44k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
388
2.44k
                               (long)compptr->v_samp_factor),
389
2.44k
         (JDIMENSION)access_rows);
390
2.44k
    }
391
816
    diff->pub.consume_data = consume_data;
392
816
    diff->pub._decompress_data = output_data;
393
#else
394
    ERREXIT(cinfo, JERR_NOT_COMPILED);
395
#endif
396
3.67k
  } else {
397
3.67k
    diff->pub.consume_data = dummy_consume_data;
398
3.67k
    diff->pub._decompress_data = decompress_data;
399
3.67k
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
400
3.67k
  }
401
4.49k
}
jinit_d_diff_controller
Line
Count
Source
348
4.18k
{
349
4.18k
  my_diff_ptr diff;
350
4.18k
  int ci;
351
4.18k
  jpeg_component_info *compptr;
352
353
4.18k
  diff = (my_diff_ptr)
354
4.18k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
355
4.18k
                                sizeof(my_diff_controller));
356
4.18k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
357
4.18k
  diff->pub.start_input_pass = start_input_pass;
358
4.18k
  diff->pub.start_output_pass = start_output_pass;
359
360
  /* Create the [un]difference buffers. */
361
16.7k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
362
12.5k
       ci++, compptr++) {
363
12.5k
    diff->diff_buf[ci] =
364
12.5k
      ALLOC_DARRAY(JPOOL_IMAGE,
365
12.5k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
366
12.5k
                                         (long)compptr->h_samp_factor),
367
12.5k
                   (JDIMENSION)compptr->v_samp_factor);
368
12.5k
    diff->undiff_buf[ci] =
369
12.5k
      ALLOC_DARRAY(JPOOL_IMAGE,
370
12.5k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
371
12.5k
                                         (long)compptr->h_samp_factor),
372
12.5k
                   (JDIMENSION)compptr->v_samp_factor);
373
12.5k
  }
374
375
4.18k
  if (need_full_buffer) {
376
895
#ifdef D_MULTISCAN_FILES_SUPPORTED
377
    /* Allocate a full-image virtual array for each component. */
378
895
    int access_rows;
379
380
3.58k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
381
2.68k
         ci++, compptr++) {
382
2.68k
      access_rows = compptr->v_samp_factor;
383
2.68k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
384
2.68k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
385
2.68k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
386
2.68k
                               (long)compptr->h_samp_factor),
387
2.68k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
388
2.68k
                               (long)compptr->v_samp_factor),
389
2.68k
         (JDIMENSION)access_rows);
390
2.68k
    }
391
895
    diff->pub.consume_data = consume_data;
392
895
    diff->pub._decompress_data = output_data;
393
#else
394
    ERREXIT(cinfo, JERR_NOT_COMPILED);
395
#endif
396
3.28k
  } else {
397
3.28k
    diff->pub.consume_data = dummy_consume_data;
398
3.28k
    diff->pub._decompress_data = decompress_data;
399
3.28k
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
400
3.28k
  }
401
4.18k
}
402
403
#endif /* D_LOSSLESS_SUPPORTED */