Coverage Report

Created: 2025-10-10 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/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
48.7M
{
68
48.7M
  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
48.7M
  if (cinfo->comps_in_scan > 1) {
75
29.2M
    diff->MCU_rows_per_iMCU_row = 1;
76
29.2M
  } else {
77
19.4M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
19.4M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
2.39k
    else
80
2.39k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
19.4M
  }
82
83
48.7M
  diff->MCU_ctr = 0;
84
48.7M
  diff->MCU_vert_offset = 0;
85
48.7M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
7.86M
{
68
7.86M
  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
7.86M
  if (cinfo->comps_in_scan > 1) {
75
1.26M
    diff->MCU_rows_per_iMCU_row = 1;
76
6.60M
  } else {
77
6.60M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
6.59M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
837
    else
80
837
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
6.60M
  }
82
83
7.86M
  diff->MCU_ctr = 0;
84
7.86M
  diff->MCU_vert_offset = 0;
85
7.86M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
9.80M
{
68
9.80M
  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
9.80M
  if (cinfo->comps_in_scan > 1) {
75
7.61M
    diff->MCU_rows_per_iMCU_row = 1;
76
7.61M
  } else {
77
2.19M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
2.19M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
754
    else
80
754
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
2.19M
  }
82
83
9.80M
  diff->MCU_ctr = 0;
84
9.80M
  diff->MCU_vert_offset = 0;
85
9.80M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
31.0M
{
68
31.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
31.0M
  if (cinfo->comps_in_scan > 1) {
75
20.3M
    diff->MCU_rows_per_iMCU_row = 1;
76
20.3M
  } else {
77
10.6M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
10.6M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
805
    else
80
805
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
10.6M
  }
82
83
31.0M
  diff->MCU_ctr = 0;
84
31.0M
  diff->MCU_vert_offset = 0;
85
31.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
4.38k
{
95
4.38k
  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.38k
  (*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.38k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
16
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
4.38k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
4.38k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
4.38k
  cinfo->input_iMCU_row = 0;
115
4.38k
  start_iMCU_row(cinfo);
116
4.38k
}
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
11
    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.29k
{
95
1.29k
  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.29k
  (*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.29k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.29k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.29k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.29k
  cinfo->input_iMCU_row = 0;
115
1.29k
  start_iMCU_row(cinfo);
116
1.29k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
1.60k
{
95
1.60k
  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.60k
  (*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.60k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
4
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.60k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.60k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.60k
  cinfo->input_iMCU_row = 0;
115
1.60k
  start_iMCU_row(cinfo);
116
1.60k
}
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
8.73M
{
127
8.73M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
8.73M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
8.73M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
8.73M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
8.73M
  return TRUE;
138
8.73M
}
jddiffct-8.c:process_restart
Line
Count
Source
126
40.4k
{
127
40.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
40.4k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
40.4k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
40.4k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
40.4k
  return TRUE;
138
40.4k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
5.39M
{
127
5.39M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
5.39M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
5.39M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
5.39M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
5.39M
  return TRUE;
138
5.39M
}
jddiffct-16.c:process_restart
Line
Count
Source
126
3.29M
{
127
3.29M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
3.29M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
3.29M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
3.29M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
3.29M
  return TRUE;
138
3.29M
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
825
{
148
825
  cinfo->output_iMCU_row = 0;
149
825
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
296
{
148
296
  cinfo->output_iMCU_row = 0;
149
296
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
271
{
148
271
  cinfo->output_iMCU_row = 0;
149
271
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
258
{
148
258
  cinfo->output_iMCU_row = 0;
149
258
}
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
48.7M
{
165
48.7M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
48.7M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
48.7M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
48.7M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
48.7M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
48.7M
  int ci, compi, row, prev_row;
171
48.7M
  unsigned int yoffset;
172
48.7M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
101M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
52.7M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
52.7M
    if (cinfo->restart_interval) {
180
25.4M
      if (diff->restart_rows_to_go == 0)
181
8.73M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
25.4M
    }
184
185
52.7M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
52.7M
    MCU_count =
188
52.7M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
52.7M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
52.7M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
52.7M
    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
52.7M
    if (cinfo->restart_interval)
200
25.4M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
52.7M
    diff->MCU_ctr = 0;
204
52.7M
  }
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
126M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
77.9M
    compptr = cinfo->cur_comp_info[ci];
213
77.9M
    compi = compptr->component_index;
214
77.9M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
163M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
163M
                compptr->last_row_height : compptr->v_samp_factor);
217
85.0M
         prev_row = row, row++) {
218
85.0M
      (*losslessd->predict_undifference[compi])
219
85.0M
        (cinfo, compi, diff->diff_buf[compi][row],
220
85.0M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
85.0M
          compptr->width_in_blocks);
222
85.0M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
85.0M
                                  output_buf[compi][row],
224
85.0M
                                  compptr->width_in_blocks);
225
85.0M
    }
226
77.9M
  }
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
48.7M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
48.6M
    start_iMCU_row(cinfo);
236
48.6M
    return JPEG_ROW_COMPLETED;
237
48.6M
  }
238
  /* Completed the scan */
239
4.24k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
4.24k
  return JPEG_SCAN_COMPLETED;
241
48.7M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
7.86M
{
165
7.86M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
7.86M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
7.86M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
7.86M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
7.86M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
7.86M
  int ci, compi, row, prev_row;
171
7.86M
  unsigned int yoffset;
172
7.86M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
17.2M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
9.41M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
9.41M
    if (cinfo->restart_interval) {
180
1.43M
      if (diff->restart_rows_to_go == 0)
181
40.4k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.43M
    }
184
185
9.41M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
9.41M
    MCU_count =
188
9.41M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
9.41M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
9.41M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
9.41M
    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
9.41M
    if (cinfo->restart_interval)
200
1.43M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
9.41M
    diff->MCU_ctr = 0;
204
9.41M
  }
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.0M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
9.13M
    compptr = cinfo->cur_comp_info[ci];
213
9.13M
    compi = compptr->component_index;
214
9.13M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
20.1M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
20.1M
                compptr->last_row_height : compptr->v_samp_factor);
217
11.0M
         prev_row = row, row++) {
218
11.0M
      (*losslessd->predict_undifference[compi])
219
11.0M
        (cinfo, compi, diff->diff_buf[compi][row],
220
11.0M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
11.0M
          compptr->width_in_blocks);
222
11.0M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
11.0M
                                  output_buf[compi][row],
224
11.0M
                                  compptr->width_in_blocks);
225
11.0M
    }
226
9.13M
  }
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
7.86M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
7.86M
    start_iMCU_row(cinfo);
236
7.86M
    return JPEG_ROW_COMPLETED;
237
7.86M
  }
238
  /* Completed the scan */
239
1.43k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.43k
  return JPEG_SCAN_COMPLETED;
241
7.86M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
9.80M
{
165
9.80M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
9.80M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
9.80M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
9.80M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
9.80M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
9.80M
  int ci, compi, row, prev_row;
171
9.80M
  unsigned int yoffset;
172
9.80M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
20.4M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
10.6M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
10.6M
    if (cinfo->restart_interval) {
180
7.25M
      if (diff->restart_rows_to_go == 0)
181
5.39M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
7.25M
    }
184
185
10.6M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
10.6M
    MCU_count =
188
10.6M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
10.6M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
10.6M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
10.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
10.6M
    if (cinfo->restart_interval)
200
7.25M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
10.6M
    diff->MCU_ctr = 0;
204
10.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
27.2M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
17.4M
    compptr = cinfo->cur_comp_info[ci];
213
17.4M
    compi = compptr->component_index;
214
17.4M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
37.1M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
37.1M
                compptr->last_row_height : compptr->v_samp_factor);
217
19.7M
         prev_row = row, row++) {
218
19.7M
      (*losslessd->predict_undifference[compi])
219
19.7M
        (cinfo, compi, diff->diff_buf[compi][row],
220
19.7M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
19.7M
          compptr->width_in_blocks);
222
19.7M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
19.7M
                                  output_buf[compi][row],
224
19.7M
                                  compptr->width_in_blocks);
225
19.7M
    }
226
17.4M
  }
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
9.80M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
9.80M
    start_iMCU_row(cinfo);
236
9.80M
    return JPEG_ROW_COMPLETED;
237
9.80M
  }
238
  /* Completed the scan */
239
1.25k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.25k
  return JPEG_SCAN_COMPLETED;
241
9.80M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
31.0M
{
165
31.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
31.0M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
31.0M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
31.0M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
31.0M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
31.0M
  int ci, compi, row, prev_row;
171
31.0M
  unsigned int yoffset;
172
31.0M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
63.7M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
32.6M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
32.6M
    if (cinfo->restart_interval) {
180
16.7M
      if (diff->restart_rows_to_go == 0)
181
3.29M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
16.7M
    }
184
185
32.6M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
32.6M
    MCU_count =
188
32.6M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
32.6M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
32.6M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
32.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
32.6M
    if (cinfo->restart_interval)
200
16.7M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
32.6M
    diff->MCU_ctr = 0;
204
32.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
82.4M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
51.4M
    compptr = cinfo->cur_comp_info[ci];
213
51.4M
    compi = compptr->component_index;
214
51.4M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
105M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
105M
                compptr->last_row_height : compptr->v_samp_factor);
217
54.2M
         prev_row = row, row++) {
218
54.2M
      (*losslessd->predict_undifference[compi])
219
54.2M
        (cinfo, compi, diff->diff_buf[compi][row],
220
54.2M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
54.2M
          compptr->width_in_blocks);
222
54.2M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
54.2M
                                  output_buf[compi][row],
224
54.2M
                                  compptr->width_in_blocks);
225
54.2M
    }
226
51.4M
  }
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
31.0M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
31.0M
    start_iMCU_row(cinfo);
236
31.0M
    return JPEG_ROW_COMPLETED;
237
31.0M
  }
238
  /* Completed the scan */
239
1.56k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.56k
  return JPEG_SCAN_COMPLETED;
241
31.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
}
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
48.7M
{
267
48.7M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
48.7M
  int ci, compi;
269
48.7M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
48.7M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
126M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
77.9M
    compptr = cinfo->cur_comp_info[ci];
275
77.9M
    compi = compptr->component_index;
276
77.9M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
77.9M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
77.9M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
77.9M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
77.9M
  }
281
282
48.7M
  return decompress_data(cinfo, buffer);
283
48.7M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
7.86M
{
267
7.86M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
7.86M
  int ci, compi;
269
7.86M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
7.86M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
17.0M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
9.13M
    compptr = cinfo->cur_comp_info[ci];
275
9.13M
    compi = compptr->component_index;
276
9.13M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
9.13M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
9.13M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
9.13M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
9.13M
  }
281
282
7.86M
  return decompress_data(cinfo, buffer);
283
7.86M
}
jddiffct-12.c:consume_data
Line
Count
Source
266
9.80M
{
267
9.80M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
9.80M
  int ci, compi;
269
9.80M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
9.80M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
27.2M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
17.4M
    compptr = cinfo->cur_comp_info[ci];
275
17.4M
    compi = compptr->component_index;
276
17.4M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
17.4M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
17.4M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
17.4M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
17.4M
  }
281
282
9.80M
  return decompress_data(cinfo, buffer);
283
9.80M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
31.0M
{
267
31.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
31.0M
  int ci, compi;
269
31.0M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
31.0M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
82.4M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
51.4M
    compptr = cinfo->cur_comp_info[ci];
275
51.4M
    compi = compptr->component_index;
276
51.4M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
51.4M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
51.4M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
51.4M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
51.4M
  }
281
282
31.0M
  return decompress_data(cinfo, buffer);
283
31.0M
}
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
0
{
297
0
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
0
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
0
  int ci, samp_rows, row;
300
0
  _JSAMPARRAY buffer;
301
0
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
0
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
0
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
0
          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
0
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
0
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
0
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
0
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
0
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
0
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
0
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
0
      samp_rows = compptr->v_samp_factor;
322
0
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
0
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
0
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
0
    }
327
328
0
    for (row = 0; row < samp_rows; row++) {
329
0
      memcpy(output_buf[ci][row], buffer[row],
330
0
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
0
    }
332
0
  }
333
334
0
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
0
  return JPEG_SCAN_COMPLETED;
337
0
}
Unexecuted instantiation: jddiffct-8.c:output_data
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.23k
{
349
1.23k
  my_diff_ptr diff;
350
1.23k
  int ci;
351
1.23k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
470
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
763
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
763
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.23k
  diff = (my_diff_ptr)
362
1.23k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.23k
                                sizeof(my_diff_controller));
364
1.23k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.23k
  diff->pub.start_input_pass = start_input_pass;
366
1.23k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
4.79k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
3.55k
       ci++, compptr++) {
371
3.55k
    diff->diff_buf[ci] =
372
3.55k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
3.55k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
3.55k
                                         (long)compptr->h_samp_factor),
375
3.55k
                   (JDIMENSION)compptr->v_samp_factor);
376
3.55k
    diff->undiff_buf[ci] =
377
3.55k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
3.55k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
3.55k
                                         (long)compptr->h_samp_factor),
380
3.55k
                   (JDIMENSION)compptr->v_samp_factor);
381
3.55k
  }
382
383
1.23k
  if (need_full_buffer) {
384
1.14k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.14k
    int access_rows;
387
388
4.59k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.44k
         ci++, compptr++) {
390
3.44k
      access_rows = compptr->v_samp_factor;
391
3.44k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.44k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.44k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.44k
                               (long)compptr->h_samp_factor),
395
3.44k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.44k
                               (long)compptr->v_samp_factor),
397
3.44k
         (JDIMENSION)access_rows);
398
3.44k
    }
399
1.14k
    diff->pub.consume_data = consume_data;
400
1.14k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.14k
  } else {
405
84
    diff->pub.consume_data = dummy_consume_data;
406
84
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
84
  }
409
1.23k
}
jinit_d_diff_controller
Line
Count
Source
348
470
{
349
470
  my_diff_ptr diff;
350
470
  int ci;
351
470
  jpeg_component_info *compptr;
352
353
470
#if BITS_IN_JSAMPLE == 8
354
470
  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
470
  diff = (my_diff_ptr)
362
470
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
470
                                sizeof(my_diff_controller));
364
470
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
470
  diff->pub.start_input_pass = start_input_pass;
366
470
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.82k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.35k
       ci++, compptr++) {
371
1.35k
    diff->diff_buf[ci] =
372
1.35k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.35k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.35k
                                         (long)compptr->h_samp_factor),
375
1.35k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.35k
    diff->undiff_buf[ci] =
377
1.35k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.35k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.35k
                                         (long)compptr->h_samp_factor),
380
1.35k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.35k
  }
382
383
470
  if (need_full_buffer) {
384
438
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
438
    int access_rows;
387
388
1.75k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.31k
         ci++, compptr++) {
390
1.31k
      access_rows = compptr->v_samp_factor;
391
1.31k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.31k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.31k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.31k
                               (long)compptr->h_samp_factor),
395
1.31k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.31k
                               (long)compptr->v_samp_factor),
397
1.31k
         (JDIMENSION)access_rows);
398
1.31k
    }
399
438
    diff->pub.consume_data = consume_data;
400
438
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
438
  } else {
405
32
    diff->pub.consume_data = dummy_consume_data;
406
32
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
32
  }
409
470
}
j12init_d_diff_controller
Line
Count
Source
348
396
{
349
396
  my_diff_ptr diff;
350
396
  int ci;
351
396
  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
396
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
396
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
396
  diff = (my_diff_ptr)
362
396
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
396
                                sizeof(my_diff_controller));
364
396
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
396
  diff->pub.start_input_pass = start_input_pass;
366
396
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.53k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.14k
       ci++, compptr++) {
371
1.14k
    diff->diff_buf[ci] =
372
1.14k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.14k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.14k
                                         (long)compptr->h_samp_factor),
375
1.14k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.14k
    diff->undiff_buf[ci] =
377
1.14k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.14k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.14k
                                         (long)compptr->h_samp_factor),
380
1.14k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.14k
  }
382
383
396
  if (need_full_buffer) {
384
369
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
369
    int access_rows;
387
388
1.47k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.10k
         ci++, compptr++) {
390
1.10k
      access_rows = compptr->v_samp_factor;
391
1.10k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.10k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.10k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.10k
                               (long)compptr->h_samp_factor),
395
1.10k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.10k
                               (long)compptr->v_samp_factor),
397
1.10k
         (JDIMENSION)access_rows);
398
1.10k
    }
399
369
    diff->pub.consume_data = consume_data;
400
369
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
369
  } 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
396
}
j16init_d_diff_controller
Line
Count
Source
348
367
{
349
367
  my_diff_ptr diff;
350
367
  int ci;
351
367
  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
367
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
367
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
367
  diff = (my_diff_ptr)
362
367
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
367
                                sizeof(my_diff_controller));
364
367
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
367
  diff->pub.start_input_pass = start_input_pass;
366
367
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.43k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.06k
       ci++, compptr++) {
371
1.06k
    diff->diff_buf[ci] =
372
1.06k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.06k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.06k
                                         (long)compptr->h_samp_factor),
375
1.06k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.06k
    diff->undiff_buf[ci] =
377
1.06k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.06k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.06k
                                         (long)compptr->h_samp_factor),
380
1.06k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.06k
  }
382
383
367
  if (need_full_buffer) {
384
342
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
342
    int access_rows;
387
388
1.36k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.02k
         ci++, compptr++) {
390
1.02k
      access_rows = compptr->v_samp_factor;
391
1.02k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.02k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.02k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.02k
                               (long)compptr->h_samp_factor),
395
1.02k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.02k
                               (long)compptr->v_samp_factor),
397
1.02k
         (JDIMENSION)access_rows);
398
1.02k
    }
399
342
    diff->pub.consume_data = consume_data;
400
342
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
342
  } else {
405
25
    diff->pub.consume_data = dummy_consume_data;
406
25
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
25
  }
409
367
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */