Coverage Report

Created: 2025-11-11 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.dev/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
151M
{
68
151M
  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
151M
  if (cinfo->comps_in_scan > 1) {
75
39.3M
    diff->MCU_rows_per_iMCU_row = 1;
76
112M
  } else {
77
112M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
112M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
14.9k
    else
80
14.9k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
112M
  }
82
83
151M
  diff->MCU_ctr = 0;
84
151M
  diff->MCU_vert_offset = 0;
85
151M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
21.2M
{
68
21.2M
  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
21.2M
  if (cinfo->comps_in_scan > 1) {
75
1.76M
    diff->MCU_rows_per_iMCU_row = 1;
76
19.5M
  } else {
77
19.5M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
19.5M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
5.14k
    else
80
5.14k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
19.5M
  }
82
83
21.2M
  diff->MCU_ctr = 0;
84
21.2M
  diff->MCU_vert_offset = 0;
85
21.2M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
61.3M
{
68
61.3M
  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
61.3M
  if (cinfo->comps_in_scan > 1) {
75
15.4M
    diff->MCU_rows_per_iMCU_row = 1;
76
45.9M
  } else {
77
45.9M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
45.9M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
5.44k
    else
80
5.44k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
45.9M
  }
82
83
61.3M
  diff->MCU_ctr = 0;
84
61.3M
  diff->MCU_vert_offset = 0;
85
61.3M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
68.7M
{
68
68.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
68.7M
  if (cinfo->comps_in_scan > 1) {
75
22.1M
    diff->MCU_rows_per_iMCU_row = 1;
76
46.6M
  } else {
77
46.6M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
46.6M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
4.34k
    else
80
4.34k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
46.6M
  }
82
83
68.7M
  diff->MCU_ctr = 0;
84
68.7M
  diff->MCU_vert_offset = 0;
85
68.7M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
21.8k
{
95
21.8k
  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
21.8k
  (*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
21.8k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
88
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
21.8k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
21.8k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
21.8k
  cinfo->input_iMCU_row = 0;
115
21.8k
  start_iMCU_row(cinfo);
116
21.8k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
7.39k
{
95
7.39k
  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
7.39k
  (*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
7.39k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
42
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
7.39k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
7.39k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
7.39k
  cinfo->input_iMCU_row = 0;
115
7.39k
  start_iMCU_row(cinfo);
116
7.39k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
7.87k
{
95
7.87k
  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
7.87k
  (*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
7.87k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
9
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
7.87k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
7.87k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
7.87k
  cinfo->input_iMCU_row = 0;
115
7.87k
  start_iMCU_row(cinfo);
116
7.87k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
6.53k
{
95
6.53k
  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
6.53k
  (*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
6.53k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
37
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
6.53k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
6.53k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
6.53k
  cinfo->input_iMCU_row = 0;
115
6.53k
  start_iMCU_row(cinfo);
116
6.53k
}
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
9.44M
{
127
9.44M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
9.44M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
9.44M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
9.44M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
9.44M
  return TRUE;
138
9.44M
}
jddiffct-8.c:process_restart
Line
Count
Source
126
195k
{
127
195k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
195k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
195k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
195k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
195k
  return TRUE;
138
195k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
5.71M
{
127
5.71M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
5.71M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
5.71M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
5.71M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
5.71M
  return TRUE;
138
5.71M
}
jddiffct-16.c:process_restart
Line
Count
Source
126
3.53M
{
127
3.53M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
3.53M
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
3.53M
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
3.53M
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
3.53M
  return TRUE;
138
3.53M
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
3.86k
{
148
3.86k
  cinfo->output_iMCU_row = 0;
149
3.86k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
1.23k
{
148
1.23k
  cinfo->output_iMCU_row = 0;
149
1.23k
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
1.30k
{
148
1.30k
  cinfo->output_iMCU_row = 0;
149
1.30k
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
1.32k
{
148
1.32k
  cinfo->output_iMCU_row = 0;
149
1.32k
}
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
151M
{
165
151M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
151M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
151M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
151M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
151M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
151M
  int ci, compi, row, prev_row;
171
151M
  unsigned int yoffset;
172
151M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
334M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
182M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
182M
    if (cinfo->restart_interval) {
180
67.9M
      if (diff->restart_rows_to_go == 0)
181
9.44M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
67.9M
    }
184
185
182M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
182M
    MCU_count =
188
182M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
182M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
182M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
182M
    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
182M
    if (cinfo->restart_interval)
200
67.9M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
182M
    diff->MCU_ctr = 0;
204
182M
  }
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
342M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
191M
    compptr = cinfo->cur_comp_info[ci];
213
191M
    compi = compptr->component_index;
214
191M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
426M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
426M
                compptr->last_row_height : compptr->v_samp_factor);
217
235M
         prev_row = row, row++) {
218
235M
      (*losslessd->predict_undifference[compi])
219
235M
        (cinfo, compi, diff->diff_buf[compi][row],
220
235M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
235M
          compptr->width_in_blocks);
222
235M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
235M
                                  output_buf[compi][row],
224
235M
                                  compptr->width_in_blocks);
225
235M
    }
226
191M
  }
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
151M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
151M
    start_iMCU_row(cinfo);
236
151M
    return JPEG_ROW_COMPLETED;
237
151M
  }
238
  /* Completed the scan */
239
21.2k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
21.2k
  return JPEG_SCAN_COMPLETED;
241
151M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
21.2M
{
165
21.2M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
21.2M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
21.2M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
21.2M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
21.2M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
21.2M
  int ci, compi, row, prev_row;
171
21.2M
  unsigned int yoffset;
172
21.2M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
50.8M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
29.5M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
29.5M
    if (cinfo->restart_interval) {
180
11.2M
      if (diff->restart_rows_to_go == 0)
181
195k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
11.2M
    }
184
185
29.5M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
29.5M
    MCU_count =
188
29.5M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
29.5M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
29.5M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
29.5M
    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
29.5M
    if (cinfo->restart_interval)
200
11.2M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
29.5M
    diff->MCU_ctr = 0;
204
29.5M
  }
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
44.5M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
23.3M
    compptr = cinfo->cur_comp_info[ci];
213
23.3M
    compi = compptr->component_index;
214
23.3M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
56.0M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
56.0M
                compptr->last_row_height : compptr->v_samp_factor);
217
32.7M
         prev_row = row, row++) {
218
32.7M
      (*losslessd->predict_undifference[compi])
219
32.7M
        (cinfo, compi, diff->diff_buf[compi][row],
220
32.7M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
32.7M
          compptr->width_in_blocks);
222
32.7M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
32.7M
                                  output_buf[compi][row],
224
32.7M
                                  compptr->width_in_blocks);
225
32.7M
    }
226
23.3M
  }
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
21.2M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
21.2M
    start_iMCU_row(cinfo);
236
21.2M
    return JPEG_ROW_COMPLETED;
237
21.2M
  }
238
  /* Completed the scan */
239
7.19k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
7.19k
  return JPEG_SCAN_COMPLETED;
241
21.2M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
61.3M
{
165
61.3M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
61.3M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
61.3M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
61.3M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
61.3M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
61.3M
  int ci, compi, row, prev_row;
171
61.3M
  unsigned int yoffset;
172
61.3M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
140M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
79.5M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
79.5M
    if (cinfo->restart_interval) {
180
36.5M
      if (diff->restart_rows_to_go == 0)
181
5.71M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
36.5M
    }
184
185
79.5M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
79.5M
    MCU_count =
188
79.5M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
79.5M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
79.5M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
79.5M
    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.5M
    if (cinfo->restart_interval)
200
36.5M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
79.5M
    diff->MCU_ctr = 0;
204
79.5M
  }
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
138M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
76.9M
    compptr = cinfo->cur_comp_info[ci];
213
76.9M
    compi = compptr->component_index;
214
76.9M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
181M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
181M
                compptr->last_row_height : compptr->v_samp_factor);
217
104M
         prev_row = row, row++) {
218
104M
      (*losslessd->predict_undifference[compi])
219
104M
        (cinfo, compi, diff->diff_buf[compi][row],
220
104M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
104M
          compptr->width_in_blocks);
222
104M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
104M
                                  output_buf[compi][row],
224
104M
                                  compptr->width_in_blocks);
225
104M
    }
226
76.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
61.3M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
61.3M
    start_iMCU_row(cinfo);
236
61.3M
    return JPEG_ROW_COMPLETED;
237
61.3M
  }
238
  /* Completed the scan */
239
7.72k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
7.72k
  return JPEG_SCAN_COMPLETED;
241
61.3M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
68.7M
{
165
68.7M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
68.7M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
68.7M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
68.7M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
68.7M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
68.7M
  int ci, compi, row, prev_row;
171
68.7M
  unsigned int yoffset;
172
68.7M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
142M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
73.5M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
73.5M
    if (cinfo->restart_interval) {
180
20.1M
      if (diff->restart_rows_to_go == 0)
181
3.53M
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
20.1M
    }
184
185
73.5M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
73.5M
    MCU_count =
188
73.5M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
73.5M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
73.5M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
73.5M
    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
73.5M
    if (cinfo->restart_interval)
200
20.1M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
73.5M
    diff->MCU_ctr = 0;
204
73.5M
  }
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
159M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
91.1M
    compptr = cinfo->cur_comp_info[ci];
213
91.1M
    compi = compptr->component_index;
214
91.1M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
189M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
189M
                compptr->last_row_height : compptr->v_samp_factor);
217
98.4M
         prev_row = row, row++) {
218
98.4M
      (*losslessd->predict_undifference[compi])
219
98.4M
        (cinfo, compi, diff->diff_buf[compi][row],
220
98.4M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
98.4M
          compptr->width_in_blocks);
222
98.4M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
98.4M
                                  output_buf[compi][row],
224
98.4M
                                  compptr->width_in_blocks);
225
98.4M
    }
226
91.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
68.7M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
68.7M
    start_iMCU_row(cinfo);
236
68.7M
    return JPEG_ROW_COMPLETED;
237
68.7M
  }
238
  /* Completed the scan */
239
6.34k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
6.34k
  return JPEG_SCAN_COMPLETED;
241
68.7M
}
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
150M
{
267
150M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
150M
  int ci, compi;
269
150M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
150M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
341M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
190M
    compptr = cinfo->cur_comp_info[ci];
275
190M
    compi = compptr->component_index;
276
190M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
190M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
190M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
190M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
190M
  }
281
282
150M
  return decompress_data(cinfo, buffer);
283
150M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
21.1M
{
267
21.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
21.1M
  int ci, compi;
269
21.1M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
21.1M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
44.0M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
22.9M
    compptr = cinfo->cur_comp_info[ci];
275
22.9M
    compi = compptr->component_index;
276
22.9M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
22.9M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
22.9M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
22.9M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
22.9M
  }
281
282
21.1M
  return decompress_data(cinfo, buffer);
283
21.1M
}
jddiffct-12.c:consume_data
Line
Count
Source
266
61.2M
{
267
61.2M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
61.2M
  int ci, compi;
269
61.2M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
61.2M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
137M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
76.6M
    compptr = cinfo->cur_comp_info[ci];
275
76.6M
    compi = compptr->component_index;
276
76.6M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
76.6M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
76.6M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
76.6M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
76.6M
  }
281
282
61.2M
  return decompress_data(cinfo, buffer);
283
61.2M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
68.5M
{
267
68.5M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
68.5M
  int ci, compi;
269
68.5M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
68.5M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
159M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
90.5M
    compptr = cinfo->cur_comp_info[ci];
275
90.5M
    compi = compptr->component_index;
276
90.5M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
90.5M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
90.5M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
90.5M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
90.5M
  }
281
282
68.5M
  return decompress_data(cinfo, buffer);
283
68.5M
}
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
732k
{
297
732k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
732k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
732k
  int ci, samp_rows, row;
300
732k
  _JSAMPARRAY buffer;
301
732k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
732k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
732k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
732k
          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
2.92M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
2.19M
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
2.19M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
2.19M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
2.19M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
2.19M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
2.19M
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
2.19M
      samp_rows = compptr->v_samp_factor;
322
2.21k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
2.21k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
2.21k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
2.21k
    }
327
328
5.74M
    for (row = 0; row < samp_rows; row++) {
329
3.54M
      memcpy(output_buf[ci][row], buffer[row],
330
3.54M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
3.54M
    }
332
2.19M
  }
333
334
732k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
730k
    return JPEG_ROW_COMPLETED;
336
1.60k
  return JPEG_SCAN_COMPLETED;
337
732k
}
jddiffct-8.c:output_data
Line
Count
Source
296
151k
{
297
151k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
151k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
151k
  int ci, samp_rows, row;
300
151k
  _JSAMPARRAY buffer;
301
151k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
151k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
151k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
151k
          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
603k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
452k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
452k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
452k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
452k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
452k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
452k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
451k
      samp_rows = compptr->v_samp_factor;
322
686
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
686
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
686
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
686
    }
327
328
1.20M
    for (row = 0; row < samp_rows; row++) {
329
751k
      memcpy(output_buf[ci][row], buffer[row],
330
751k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
751k
    }
332
452k
  }
333
334
151k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
150k
    return JPEG_ROW_COMPLETED;
336
492
  return JPEG_SCAN_COMPLETED;
337
151k
}
jddiffct-12.c:output_data
Line
Count
Source
296
302k
{
297
302k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
302k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
302k
  int ci, samp_rows, row;
300
302k
  _JSAMPARRAY buffer;
301
302k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
302k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
302k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
302k
          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.20M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
905k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
905k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
905k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
905k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
905k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
905k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
904k
      samp_rows = compptr->v_samp_factor;
322
691
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
691
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
691
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
691
    }
327
328
2.36M
    for (row = 0; row < samp_rows; row++) {
329
1.46M
      memcpy(output_buf[ci][row], buffer[row],
330
1.46M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1.46M
    }
332
905k
  }
333
334
302k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
301k
    return JPEG_ROW_COMPLETED;
336
493
  return JPEG_SCAN_COMPLETED;
337
302k
}
jddiffct-16.c:output_data
Line
Count
Source
296
279k
{
297
279k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
279k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
279k
  int ci, samp_rows, row;
300
279k
  _JSAMPARRAY buffer;
301
279k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
279k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
279k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
279k
          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.11M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
836k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
836k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
836k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
836k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
836k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
836k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
836k
      samp_rows = compptr->v_samp_factor;
322
840
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
840
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
840
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
840
    }
327
328
2.17M
    for (row = 0; row < samp_rows; row++) {
329
1.33M
      memcpy(output_buf[ci][row], buffer[row],
330
1.33M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1.33M
    }
332
836k
  }
333
334
279k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
278k
    return JPEG_ROW_COMPLETED;
336
621
  return JPEG_SCAN_COMPLETED;
337
279k
}
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
5.37k
{
349
5.37k
  my_diff_ptr diff;
350
5.37k
  int ci;
351
5.37k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
1.77k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
3.59k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
3.59k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
5.37k
  diff = (my_diff_ptr)
362
5.37k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
5.37k
                                sizeof(my_diff_controller));
364
5.37k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
5.37k
  diff->pub.start_input_pass = start_input_pass;
366
5.37k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
21.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
15.8k
       ci++, compptr++) {
371
15.8k
    diff->diff_buf[ci] =
372
15.8k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
15.8k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
15.8k
                                         (long)compptr->h_samp_factor),
375
15.8k
                   (JDIMENSION)compptr->v_samp_factor);
376
15.8k
    diff->undiff_buf[ci] =
377
15.8k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
15.8k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
15.8k
                                         (long)compptr->h_samp_factor),
380
15.8k
                   (JDIMENSION)compptr->v_samp_factor);
381
15.8k
  }
382
383
5.37k
  if (need_full_buffer) {
384
4.77k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
4.77k
    int access_rows;
387
388
19.1k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
14.3k
         ci++, compptr++) {
390
14.3k
      access_rows = compptr->v_samp_factor;
391
14.3k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
14.3k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
14.3k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
14.3k
                               (long)compptr->h_samp_factor),
395
14.3k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
14.3k
                               (long)compptr->v_samp_factor),
397
14.3k
         (JDIMENSION)access_rows);
398
14.3k
    }
399
4.77k
    diff->pub.consume_data = consume_data;
400
4.77k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
4.77k
  } else {
405
600
    diff->pub.consume_data = dummy_consume_data;
406
600
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
600
  }
409
5.37k
}
jinit_d_diff_controller
Line
Count
Source
348
1.77k
{
349
1.77k
  my_diff_ptr diff;
350
1.77k
  int ci;
351
1.77k
  jpeg_component_info *compptr;
352
353
1.77k
#if BITS_IN_JSAMPLE == 8
354
1.77k
  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.77k
  diff = (my_diff_ptr)
362
1.77k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.77k
                                sizeof(my_diff_controller));
364
1.77k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.77k
  diff->pub.start_input_pass = start_input_pass;
366
1.77k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
7.03k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
5.25k
       ci++, compptr++) {
371
5.25k
    diff->diff_buf[ci] =
372
5.25k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
5.25k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
5.25k
                                         (long)compptr->h_samp_factor),
375
5.25k
                   (JDIMENSION)compptr->v_samp_factor);
376
5.25k
    diff->undiff_buf[ci] =
377
5.25k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
5.25k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
5.25k
                                         (long)compptr->h_samp_factor),
380
5.25k
                   (JDIMENSION)compptr->v_samp_factor);
381
5.25k
  }
382
383
1.77k
  if (need_full_buffer) {
384
1.62k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.62k
    int access_rows;
387
388
6.51k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
4.88k
         ci++, compptr++) {
390
4.88k
      access_rows = compptr->v_samp_factor;
391
4.88k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
4.88k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
4.88k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
4.88k
                               (long)compptr->h_samp_factor),
395
4.88k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
4.88k
                               (long)compptr->v_samp_factor),
397
4.88k
         (JDIMENSION)access_rows);
398
4.88k
    }
399
1.62k
    diff->pub.consume_data = consume_data;
400
1.62k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.62k
  } else {
405
151
    diff->pub.consume_data = dummy_consume_data;
406
151
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
151
  }
409
1.77k
}
j12init_d_diff_controller
Line
Count
Source
348
1.78k
{
349
1.78k
  my_diff_ptr diff;
350
1.78k
  int ci;
351
1.78k
  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.78k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.78k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.78k
  diff = (my_diff_ptr)
362
1.78k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.78k
                                sizeof(my_diff_controller));
364
1.78k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.78k
  diff->pub.start_input_pass = start_input_pass;
366
1.78k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
7.02k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
5.24k
       ci++, compptr++) {
371
5.24k
    diff->diff_buf[ci] =
372
5.24k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
5.24k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
5.24k
                                         (long)compptr->h_samp_factor),
375
5.24k
                   (JDIMENSION)compptr->v_samp_factor);
376
5.24k
    diff->undiff_buf[ci] =
377
5.24k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
5.24k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
5.24k
                                         (long)compptr->h_samp_factor),
380
5.24k
                   (JDIMENSION)compptr->v_samp_factor);
381
5.24k
  }
382
383
1.78k
  if (need_full_buffer) {
384
1.57k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.57k
    int access_rows;
387
388
6.29k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
4.72k
         ci++, compptr++) {
390
4.72k
      access_rows = compptr->v_samp_factor;
391
4.72k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
4.72k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
4.72k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
4.72k
                               (long)compptr->h_samp_factor),
395
4.72k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
4.72k
                               (long)compptr->v_samp_factor),
397
4.72k
         (JDIMENSION)access_rows);
398
4.72k
    }
399
1.57k
    diff->pub.consume_data = consume_data;
400
1.57k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.57k
  } else {
405
208
    diff->pub.consume_data = dummy_consume_data;
406
208
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
208
  }
409
1.78k
}
j16init_d_diff_controller
Line
Count
Source
348
1.81k
{
349
1.81k
  my_diff_ptr diff;
350
1.81k
  int ci;
351
1.81k
  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.81k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.81k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.81k
  diff = (my_diff_ptr)
362
1.81k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.81k
                                sizeof(my_diff_controller));
364
1.81k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.81k
  diff->pub.start_input_pass = start_input_pass;
366
1.81k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
7.20k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
5.39k
       ci++, compptr++) {
371
5.39k
    diff->diff_buf[ci] =
372
5.39k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
5.39k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
5.39k
                                         (long)compptr->h_samp_factor),
375
5.39k
                   (JDIMENSION)compptr->v_samp_factor);
376
5.39k
    diff->undiff_buf[ci] =
377
5.39k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
5.39k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
5.39k
                                         (long)compptr->h_samp_factor),
380
5.39k
                   (JDIMENSION)compptr->v_samp_factor);
381
5.39k
  }
382
383
1.81k
  if (need_full_buffer) {
384
1.57k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.57k
    int access_rows;
387
388
6.29k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
4.72k
         ci++, compptr++) {
390
4.72k
      access_rows = compptr->v_samp_factor;
391
4.72k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
4.72k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
4.72k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
4.72k
                               (long)compptr->h_samp_factor),
395
4.72k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
4.72k
                               (long)compptr->v_samp_factor),
397
4.72k
         (JDIMENSION)access_rows);
398
4.72k
    }
399
1.57k
    diff->pub.consume_data = consume_data;
400
1.57k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.57k
  } else {
405
241
    diff->pub.consume_data = dummy_consume_data;
406
241
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
241
  }
409
1.81k
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */