Coverage Report

Created: 2026-10-08 07:01

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
65.4M
{
68
65.4M
  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
65.4M
  if (cinfo->comps_in_scan > 1) {
75
25.4M
    diff->MCU_rows_per_iMCU_row = 1;
76
40.0M
  } else {
77
40.0M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
39.9M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
6.26k
    else
80
6.26k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
40.0M
  }
82
83
65.4M
  diff->MCU_ctr = 0;
84
65.4M
  diff->MCU_vert_offset = 0;
85
65.4M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
15.0M
{
68
15.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
15.0M
  if (cinfo->comps_in_scan > 1) {
75
3.95M
    diff->MCU_rows_per_iMCU_row = 1;
76
11.0M
  } else {
77
11.0M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
11.0M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
2.52k
    else
80
2.52k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
11.0M
  }
82
83
15.0M
  diff->MCU_ctr = 0;
84
15.0M
  diff->MCU_vert_offset = 0;
85
15.0M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
12.9M
{
68
12.9M
  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.9M
  if (cinfo->comps_in_scan > 1) {
75
6.73M
    diff->MCU_rows_per_iMCU_row = 1;
76
6.73M
  } else {
77
6.25M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
6.24M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
2.16k
    else
80
2.16k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
6.25M
  }
82
83
12.9M
  diff->MCU_ctr = 0;
84
12.9M
  diff->MCU_vert_offset = 0;
85
12.9M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
37.4M
{
68
37.4M
  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
37.4M
  if (cinfo->comps_in_scan > 1) {
75
14.7M
    diff->MCU_rows_per_iMCU_row = 1;
76
22.6M
  } else {
77
22.6M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
22.6M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.56k
    else
80
1.56k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
22.6M
  }
82
83
37.4M
  diff->MCU_ctr = 0;
84
37.4M
  diff->MCU_vert_offset = 0;
85
37.4M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
8.49k
{
95
8.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
8.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
8.49k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
136
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
8.49k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
8.49k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
8.49k
  cinfo->input_iMCU_row = 0;
115
8.49k
  start_iMCU_row(cinfo);
116
8.49k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
3.10k
{
95
3.10k
  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
3.10k
  (*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
3.10k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
36
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
3.10k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
3.10k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
3.10k
  cinfo->input_iMCU_row = 0;
115
3.10k
  start_iMCU_row(cinfo);
116
3.10k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
2.92k
{
95
2.92k
  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
2.92k
  (*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
2.92k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
48
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
2.92k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
2.92k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
2.92k
  cinfo->input_iMCU_row = 0;
115
2.92k
  start_iMCU_row(cinfo);
116
2.92k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
2.47k
{
95
2.47k
  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
2.47k
  (*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
2.47k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
52
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
2.47k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
2.47k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
2.47k
  cinfo->input_iMCU_row = 0;
115
2.47k
  start_iMCU_row(cinfo);
116
2.47k
}
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.1M
{
127
13.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
13.1M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
13.1M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
13.1M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
13.1M
  return TRUE;
138
13.1M
}
jddiffct-8.c:process_restart
Line
Count
Source
126
470k
{
127
470k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
470k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
470k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
470k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
470k
  return TRUE;
138
470k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
51.0k
{
127
51.0k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
51.0k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
51.0k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
51.0k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
51.0k
  return TRUE;
138
51.0k
}
jddiffct-16.c:process_restart
Line
Count
Source
126
12.6M
{
127
12.6M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
12.6M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
12.6M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
12.6M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
12.6M
  return TRUE;
138
12.6M
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
2.52k
{
148
2.52k
  cinfo->output_iMCU_row = 0;
149
2.52k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
896
{
148
896
  cinfo->output_iMCU_row = 0;
149
896
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
860
{
148
860
  cinfo->output_iMCU_row = 0;
149
860
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
764
{
148
764
  cinfo->output_iMCU_row = 0;
149
764
}
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
65.4M
{
165
65.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
65.4M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
65.4M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
65.4M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
65.4M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
65.4M
  int ci, compi, row, prev_row;
171
65.4M
  unsigned int yoffset;
172
65.4M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
145M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
79.7M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
79.7M
    if (cinfo->restart_interval) {
180
24.0M
      if (diff->restart_rows_to_go == 0)
181
13.1M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
24.0M
    }
184
185
79.7M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
79.7M
    MCU_count =
188
79.7M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
79.7M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
79.7M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
79.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
79.7M
    if (cinfo->restart_interval)
200
24.0M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
79.7M
    diff->MCU_ctr = 0;
204
79.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
156M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
90.8M
    compptr = cinfo->cur_comp_info[ci];
213
90.8M
    compi = compptr->component_index;
214
90.8M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
203M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
203M
                compptr->last_row_height : compptr->v_samp_factor);
217
113M
         prev_row = row, row++) {
218
113M
      (*losslessd->predict_undifference[compi])
219
113M
        (cinfo, compi, diff->diff_buf[compi][row],
220
113M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
113M
          compptr->width_in_blocks);
222
113M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
113M
                                  output_buf[compi][row],
224
113M
                                  compptr->width_in_blocks);
225
113M
    }
226
90.8M
  }
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
65.4M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
65.4M
    start_iMCU_row(cinfo);
236
65.4M
    return JPEG_ROW_COMPLETED;
237
65.4M
  }
238
  /* Completed the scan */
239
7.92k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
7.92k
  return JPEG_SCAN_COMPLETED;
241
65.4M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
15.0M
{
165
15.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
15.0M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
15.0M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
15.0M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
15.0M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
15.0M
  int ci, compi, row, prev_row;
171
15.0M
  unsigned int yoffset;
172
15.0M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
36.2M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
21.2M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
21.2M
    if (cinfo->restart_interval) {
180
5.78M
      if (diff->restart_rows_to_go == 0)
181
470k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
5.78M
    }
184
185
21.2M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
21.2M
    MCU_count =
188
21.2M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
21.2M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
21.2M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
21.2M
    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
21.2M
    if (cinfo->restart_interval)
200
5.78M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
21.2M
    diff->MCU_ctr = 0;
204
21.2M
  }
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
33.9M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
18.9M
    compptr = cinfo->cur_comp_info[ci];
213
18.9M
    compi = compptr->component_index;
214
18.9M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
44.5M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
44.5M
                compptr->last_row_height : compptr->v_samp_factor);
217
25.5M
         prev_row = row, row++) {
218
25.5M
      (*losslessd->predict_undifference[compi])
219
25.5M
        (cinfo, compi, diff->diff_buf[compi][row],
220
25.5M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
25.5M
          compptr->width_in_blocks);
222
25.5M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
25.5M
                                  output_buf[compi][row],
224
25.5M
                                  compptr->width_in_blocks);
225
25.5M
    }
226
18.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
15.0M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
15.0M
    start_iMCU_row(cinfo);
236
15.0M
    return JPEG_ROW_COMPLETED;
237
15.0M
  }
238
  /* Completed the scan */
239
2.90k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
2.90k
  return JPEG_SCAN_COMPLETED;
241
15.0M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
12.9M
{
165
12.9M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
12.9M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
12.9M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
12.9M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
12.9M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
12.9M
  int ci, compi, row, prev_row;
171
12.9M
  unsigned int yoffset;
172
12.9M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
30.2M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
17.2M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
17.2M
    if (cinfo->restart_interval) {
180
3.36M
      if (diff->restart_rows_to_go == 0)
181
51.0k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
3.36M
    }
184
185
17.2M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
17.2M
    MCU_count =
188
17.2M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
17.2M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
17.2M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
17.2M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
17.2M
    if (cinfo->restart_interval)
200
3.36M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
17.2M
    diff->MCU_ctr = 0;
204
17.2M
  }
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
32.7M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
19.7M
    compptr = cinfo->cur_comp_info[ci];
213
19.7M
    compi = compptr->component_index;
214
19.7M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
46.5M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
46.5M
                compptr->last_row_height : compptr->v_samp_factor);
217
26.8M
         prev_row = row, row++) {
218
26.8M
      (*losslessd->predict_undifference[compi])
219
26.8M
        (cinfo, compi, diff->diff_buf[compi][row],
220
26.8M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
26.8M
          compptr->width_in_blocks);
222
26.8M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
26.8M
                                  output_buf[compi][row],
224
26.8M
                                  compptr->width_in_blocks);
225
26.8M
    }
226
19.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.9M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
12.9M
    start_iMCU_row(cinfo);
236
12.9M
    return JPEG_ROW_COMPLETED;
237
12.9M
  }
238
  /* Completed the scan */
239
2.76k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
2.76k
  return JPEG_SCAN_COMPLETED;
241
12.9M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
37.4M
{
165
37.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
37.4M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
37.4M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
37.4M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
37.4M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
37.4M
  int ci, compi, row, prev_row;
171
37.4M
  unsigned int yoffset;
172
37.4M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
78.7M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
41.3M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
41.3M
    if (cinfo->restart_interval) {
180
14.8M
      if (diff->restart_rows_to_go == 0)
181
12.6M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
14.8M
    }
184
185
41.3M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
41.3M
    MCU_count =
188
41.3M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
41.3M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
41.3M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
41.3M
    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
41.3M
    if (cinfo->restart_interval)
200
14.8M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
41.3M
    diff->MCU_ctr = 0;
204
41.3M
  }
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
89.5M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
52.1M
    compptr = cinfo->cur_comp_info[ci];
213
52.1M
    compi = compptr->component_index;
214
52.1M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
112M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
112M
                compptr->last_row_height : compptr->v_samp_factor);
217
60.5M
         prev_row = row, row++) {
218
60.5M
      (*losslessd->predict_undifference[compi])
219
60.5M
        (cinfo, compi, diff->diff_buf[compi][row],
220
60.5M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
60.5M
          compptr->width_in_blocks);
222
60.5M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
60.5M
                                  output_buf[compi][row],
224
60.5M
                                  compptr->width_in_blocks);
225
60.5M
    }
226
52.1M
  }
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
37.4M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
37.4M
    start_iMCU_row(cinfo);
236
37.4M
    return JPEG_ROW_COMPLETED;
237
37.4M
  }
238
  /* Completed the scan */
239
2.26k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
2.26k
  return JPEG_SCAN_COMPLETED;
241
37.4M
}
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
65.4M
{
267
65.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
65.4M
  int ci, compi;
269
65.4M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
65.4M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
156M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
90.8M
    compptr = cinfo->cur_comp_info[ci];
275
90.8M
    compi = compptr->component_index;
276
90.8M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
90.8M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
90.8M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
90.8M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
90.8M
  }
281
282
65.4M
  return decompress_data(cinfo, buffer);
283
65.4M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
15.0M
{
267
15.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
15.0M
  int ci, compi;
269
15.0M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
15.0M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
33.9M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
18.9M
    compptr = cinfo->cur_comp_info[ci];
275
18.9M
    compi = compptr->component_index;
276
18.9M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
18.9M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
18.9M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
18.9M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
18.9M
  }
281
282
15.0M
  return decompress_data(cinfo, buffer);
283
15.0M
}
jddiffct-12.c:consume_data
Line
Count
Source
266
12.9M
{
267
12.9M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
12.9M
  int ci, compi;
269
12.9M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
12.9M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
32.7M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
19.7M
    compptr = cinfo->cur_comp_info[ci];
275
19.7M
    compi = compptr->component_index;
276
19.7M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
19.7M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
19.7M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
19.7M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
19.7M
  }
281
282
12.9M
  return decompress_data(cinfo, buffer);
283
12.9M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
37.4M
{
267
37.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
37.4M
  int ci, compi;
269
37.4M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
37.4M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
89.5M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
52.1M
    compptr = cinfo->cur_comp_info[ci];
275
52.1M
    compi = compptr->component_index;
276
52.1M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
52.1M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
52.1M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
52.1M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
52.1M
  }
281
282
37.4M
  return decompress_data(cinfo, buffer);
283
37.4M
}
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
4.31k
{
349
4.31k
  my_diff_ptr diff;
350
4.31k
  int ci;
351
4.31k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
1.53k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
2.77k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
2.77k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
4.31k
  diff = (my_diff_ptr)
362
4.31k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
4.31k
                                sizeof(my_diff_controller));
364
4.31k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
4.31k
  diff->pub.start_input_pass = start_input_pass;
366
4.31k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
16.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
11.9k
       ci++, compptr++) {
371
11.9k
    diff->diff_buf[ci] =
372
11.9k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
11.9k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
11.9k
                                         (long)compptr->h_samp_factor),
375
11.9k
                   (JDIMENSION)compptr->v_samp_factor);
376
11.9k
    diff->undiff_buf[ci] =
377
11.9k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
11.9k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
11.9k
                                         (long)compptr->h_samp_factor),
380
11.9k
                   (JDIMENSION)compptr->v_samp_factor);
381
11.9k
  }
382
383
4.31k
  if (need_full_buffer) {
384
3.76k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
3.76k
    int access_rows;
387
388
15.0k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
11.3k
         ci++, compptr++) {
390
11.3k
      access_rows = compptr->v_samp_factor;
391
11.3k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
11.3k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
11.3k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
11.3k
                               (long)compptr->h_samp_factor),
395
11.3k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
11.3k
                               (long)compptr->v_samp_factor),
397
11.3k
         (JDIMENSION)access_rows);
398
11.3k
    }
399
3.76k
    diff->pub.consume_data = consume_data;
400
3.76k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
3.76k
  } else {
405
544
    diff->pub.consume_data = dummy_consume_data;
406
544
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
544
  }
409
4.31k
}
jinit_d_diff_controller
Line
Count
Source
348
1.53k
{
349
1.53k
  my_diff_ptr diff;
350
1.53k
  int ci;
351
1.53k
  jpeg_component_info *compptr;
352
353
1.53k
#if BITS_IN_JSAMPLE == 8
354
1.53k
  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
1.53k
  diff = (my_diff_ptr)
362
1.53k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.53k
                                sizeof(my_diff_controller));
364
1.53k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.53k
  diff->pub.start_input_pass = start_input_pass;
366
1.53k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
5.78k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.24k
       ci++, compptr++) {
371
4.24k
    diff->diff_buf[ci] =
372
4.24k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.24k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.24k
                                         (long)compptr->h_samp_factor),
375
4.24k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.24k
    diff->undiff_buf[ci] =
377
4.24k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.24k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.24k
                                         (long)compptr->h_samp_factor),
380
4.24k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.24k
  }
382
383
1.53k
  if (need_full_buffer) {
384
1.34k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.34k
    int access_rows;
387
388
5.39k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
4.04k
         ci++, compptr++) {
390
4.04k
      access_rows = compptr->v_samp_factor;
391
4.04k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
4.04k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
4.04k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
4.04k
                               (long)compptr->h_samp_factor),
395
4.04k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
4.04k
                               (long)compptr->v_samp_factor),
397
4.04k
         (JDIMENSION)access_rows);
398
4.04k
    }
399
1.34k
    diff->pub.consume_data = consume_data;
400
1.34k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.34k
  } else {
405
188
    diff->pub.consume_data = dummy_consume_data;
406
188
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
188
  }
409
1.53k
}
j12init_d_diff_controller
Line
Count
Source
348
1.43k
{
349
1.43k
  my_diff_ptr diff;
350
1.43k
  int ci;
351
1.43k
  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
1.43k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.43k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.43k
  diff = (my_diff_ptr)
362
1.43k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.43k
                                sizeof(my_diff_controller));
364
1.43k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.43k
  diff->pub.start_input_pass = start_input_pass;
366
1.43k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
5.48k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.05k
       ci++, compptr++) {
371
4.05k
    diff->diff_buf[ci] =
372
4.05k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.05k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.05k
                                         (long)compptr->h_samp_factor),
375
4.05k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.05k
    diff->undiff_buf[ci] =
377
4.05k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.05k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.05k
                                         (long)compptr->h_samp_factor),
380
4.05k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.05k
  }
382
383
1.43k
  if (need_full_buffer) {
384
1.30k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.30k
    int access_rows;
387
388
5.20k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.90k
         ci++, compptr++) {
390
3.90k
      access_rows = compptr->v_samp_factor;
391
3.90k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.90k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.90k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.90k
                               (long)compptr->h_samp_factor),
395
3.90k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.90k
                               (long)compptr->v_samp_factor),
397
3.90k
         (JDIMENSION)access_rows);
398
3.90k
    }
399
1.30k
    diff->pub.consume_data = consume_data;
400
1.30k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.30k
  } else {
405
132
    diff->pub.consume_data = dummy_consume_data;
406
132
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
132
  }
409
1.43k
}
j16init_d_diff_controller
Line
Count
Source
348
1.34k
{
349
1.34k
  my_diff_ptr diff;
350
1.34k
  int ci;
351
1.34k
  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
1.34k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.34k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.34k
  diff = (my_diff_ptr)
362
1.34k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.34k
                                sizeof(my_diff_controller));
364
1.34k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.34k
  diff->pub.start_input_pass = start_input_pass;
366
1.34k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
4.99k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
3.64k
       ci++, compptr++) {
371
3.64k
    diff->diff_buf[ci] =
372
3.64k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
3.64k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
3.64k
                                         (long)compptr->h_samp_factor),
375
3.64k
                   (JDIMENSION)compptr->v_samp_factor);
376
3.64k
    diff->undiff_buf[ci] =
377
3.64k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
3.64k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
3.64k
                                         (long)compptr->h_samp_factor),
380
3.64k
                   (JDIMENSION)compptr->v_samp_factor);
381
3.64k
  }
382
383
1.34k
  if (need_full_buffer) {
384
1.12k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.12k
    int access_rows;
387
388
4.48k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.36k
         ci++, compptr++) {
390
3.36k
      access_rows = compptr->v_samp_factor;
391
3.36k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.36k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.36k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.36k
                               (long)compptr->h_samp_factor),
395
3.36k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.36k
                               (long)compptr->v_samp_factor),
397
3.36k
         (JDIMENSION)access_rows);
398
3.36k
    }
399
1.12k
    diff->pub.consume_data = consume_data;
400
1.12k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.12k
  } else {
405
224
    diff->pub.consume_data = dummy_consume_data;
406
224
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
224
  }
409
1.34k
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */