Coverage Report

Created: 2025-11-24 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo/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
28.5k
{
68
28.5k
  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
28.5k
  if (cinfo->comps_in_scan > 1) {
75
2.99k
    diff->MCU_rows_per_iMCU_row = 1;
76
25.5k
  } else {
77
25.5k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
25.1k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
339
    else
80
339
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
25.5k
  }
82
83
28.5k
  diff->MCU_ctr = 0;
84
28.5k
  diff->MCU_vert_offset = 0;
85
28.5k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
8.22k
{
68
8.22k
  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
8.22k
  if (cinfo->comps_in_scan > 1) {
75
2.98k
    diff->MCU_rows_per_iMCU_row = 1;
76
5.24k
  } else {
77
5.24k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
5.13k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
112
    else
80
112
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
5.24k
  }
82
83
8.22k
  diff->MCU_ctr = 0;
84
8.22k
  diff->MCU_vert_offset = 0;
85
8.22k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
8.17k
{
68
8.17k
  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
8.17k
  if (cinfo->comps_in_scan > 1) {
75
10
    diff->MCU_rows_per_iMCU_row = 1;
76
8.16k
  } else {
77
8.16k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
8.07k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
93
    else
80
93
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
8.16k
  }
82
83
8.17k
  diff->MCU_ctr = 0;
84
8.17k
  diff->MCU_vert_offset = 0;
85
8.17k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
12.1k
{
68
12.1k
  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.1k
  if (cinfo->comps_in_scan > 1) {
75
4
    diff->MCU_rows_per_iMCU_row = 1;
76
12.1k
  } else {
77
12.1k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
11.9k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
134
    else
80
134
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
12.1k
  }
82
83
12.1k
  diff->MCU_ctr = 0;
84
12.1k
  diff->MCU_vert_offset = 0;
85
12.1k
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
1.62k
{
95
1.62k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
1.62k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
1.62k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
3
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.62k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.62k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.62k
  cinfo->input_iMCU_row = 0;
115
1.62k
  start_iMCU_row(cinfo);
116
1.62k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
605
{
95
605
  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
605
  (*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
605
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
605
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
605
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
605
  cinfo->input_iMCU_row = 0;
115
605
  start_iMCU_row(cinfo);
116
605
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
491
{
95
491
  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
491
  (*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
491
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
491
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
491
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
491
  cinfo->input_iMCU_row = 0;
115
491
  start_iMCU_row(cinfo);
116
491
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
530
{
95
530
  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
530
  (*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
530
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
530
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
530
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
530
  cinfo->input_iMCU_row = 0;
115
530
  start_iMCU_row(cinfo);
116
530
}
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
11
{
127
11
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
11
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
11
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
11
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
11
  return TRUE;
138
11
}
jddiffct-8.c:process_restart
Line
Count
Source
126
4
{
127
4
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
4
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
4
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
4
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
4
  return TRUE;
138
4
}
jddiffct-12.c:process_restart
Line
Count
Source
126
5
{
127
5
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
5
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
5
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
5
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
5
  return TRUE;
138
5
}
jddiffct-16.c:process_restart
Line
Count
Source
126
2
{
127
2
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
2
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
2
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
2
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
2
  return TRUE;
138
2
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
259
{
148
259
  cinfo->output_iMCU_row = 0;
149
259
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
245
{
148
245
  cinfo->output_iMCU_row = 0;
149
245
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
10
{
148
10
  cinfo->output_iMCU_row = 0;
149
10
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
4
{
148
4
  cinfo->output_iMCU_row = 0;
149
4
}
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
28.5k
{
165
28.5k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
28.5k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
28.5k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
28.5k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
28.5k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
28.5k
  int ci, compi, row, prev_row;
171
28.5k
  unsigned int yoffset;
172
28.5k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
67.9k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
39.4k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
39.4k
    if (cinfo->restart_interval) {
180
1.00k
      if (diff->restart_rows_to_go == 0)
181
11
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.00k
    }
184
185
39.4k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
39.4k
    MCU_count =
188
39.4k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
39.4k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
39.4k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
39.4k
    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
39.4k
    if (cinfo->restart_interval)
200
961
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
39.4k
    diff->MCU_ctr = 0;
204
39.4k
  }
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
62.8k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
34.3k
    compptr = cinfo->cur_comp_info[ci];
213
34.3k
    compi = compptr->component_index;
214
34.3k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
81.5k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
80.4k
                compptr->last_row_height : compptr->v_samp_factor);
217
47.1k
         prev_row = row, row++) {
218
47.1k
      (*losslessd->predict_undifference[compi])
219
47.1k
        (cinfo, compi, diff->diff_buf[compi][row],
220
47.1k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
47.1k
          compptr->width_in_blocks);
222
47.1k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
47.1k
                                  output_buf[compi][row],
224
47.1k
                                  compptr->width_in_blocks);
225
47.1k
    }
226
34.3k
  }
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
28.5k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
26.9k
    start_iMCU_row(cinfo);
236
26.9k
    return JPEG_ROW_COMPLETED;
237
26.9k
  }
238
  /* Completed the scan */
239
1.53k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.53k
  return JPEG_SCAN_COMPLETED;
241
28.5k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
8.22k
{
165
8.22k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
8.22k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
8.22k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
8.22k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
8.22k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
8.22k
  int ci, compi, row, prev_row;
171
8.22k
  unsigned int yoffset;
172
8.22k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
19.6k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
11.4k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
11.4k
    if (cinfo->restart_interval) {
180
290
      if (diff->restart_rows_to_go == 0)
181
4
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
290
    }
184
185
11.4k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
11.4k
    MCU_count =
188
11.4k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
11.4k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
11.4k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
11.4k
    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
11.4k
    if (cinfo->restart_interval)
200
278
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
11.4k
    diff->MCU_ctr = 0;
204
11.4k
  }
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
23.0k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
14.8k
    compptr = cinfo->cur_comp_info[ci];
213
14.8k
    compi = compptr->component_index;
214
14.8k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
34.8k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
34.4k
                compptr->last_row_height : compptr->v_samp_factor);
217
20.0k
         prev_row = row, row++) {
218
20.0k
      (*losslessd->predict_undifference[compi])
219
20.0k
        (cinfo, compi, diff->diff_buf[compi][row],
220
20.0k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
20.0k
          compptr->width_in_blocks);
222
20.0k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
20.0k
                                  output_buf[compi][row],
224
20.0k
                                  compptr->width_in_blocks);
225
20.0k
    }
226
14.8k
  }
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
8.22k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
7.64k
    start_iMCU_row(cinfo);
236
7.64k
    return JPEG_ROW_COMPLETED;
237
7.64k
  }
238
  /* Completed the scan */
239
575
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
575
  return JPEG_SCAN_COMPLETED;
241
8.22k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
8.16k
{
165
8.16k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
8.16k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
8.16k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
8.16k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
8.16k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
8.16k
  int ci, compi, row, prev_row;
171
8.16k
  unsigned int yoffset;
172
8.16k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
20.7k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
12.5k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
12.5k
    if (cinfo->restart_interval) {
180
364
      if (diff->restart_rows_to_go == 0)
181
5
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
364
    }
184
185
12.5k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
12.5k
    MCU_count =
188
12.5k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
12.5k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
12.5k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
12.5k
    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
12.5k
    if (cinfo->restart_interval)
200
352
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
12.5k
    diff->MCU_ctr = 0;
204
12.5k
  }
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
15.9k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
7.79k
    compptr = cinfo->cur_comp_info[ci];
213
7.79k
    compi = compptr->component_index;
214
7.79k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
19.8k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
19.5k
                compptr->last_row_height : compptr->v_samp_factor);
217
12.0k
         prev_row = row, row++) {
218
12.0k
      (*losslessd->predict_undifference[compi])
219
12.0k
        (cinfo, compi, diff->diff_buf[compi][row],
220
12.0k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
12.0k
          compptr->width_in_blocks);
222
12.0k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
12.0k
                                  output_buf[compi][row],
224
12.0k
                                  compptr->width_in_blocks);
225
12.0k
    }
226
7.79k
  }
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
8.16k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
7.71k
    start_iMCU_row(cinfo);
236
7.71k
    return JPEG_ROW_COMPLETED;
237
7.71k
  }
238
  /* Completed the scan */
239
458
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
458
  return JPEG_SCAN_COMPLETED;
241
8.16k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
12.1k
{
165
12.1k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
12.1k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
12.1k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
12.1k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
12.1k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
12.1k
  int ci, compi, row, prev_row;
171
12.1k
  unsigned int yoffset;
172
12.1k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
27.6k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
15.5k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
15.5k
    if (cinfo->restart_interval) {
180
347
      if (diff->restart_rows_to_go == 0)
181
2
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
347
    }
184
185
15.5k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
15.5k
    MCU_count =
188
15.5k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
15.5k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
15.5k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
15.5k
    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
15.5k
    if (cinfo->restart_interval)
200
331
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
15.5k
    diff->MCU_ctr = 0;
204
15.5k
  }
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
23.8k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
11.7k
    compptr = cinfo->cur_comp_info[ci];
213
11.7k
    compi = compptr->component_index;
214
11.7k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
26.8k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
26.4k
                compptr->last_row_height : compptr->v_samp_factor);
217
15.0k
         prev_row = row, row++) {
218
15.0k
      (*losslessd->predict_undifference[compi])
219
15.0k
        (cinfo, compi, diff->diff_buf[compi][row],
220
15.0k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
15.0k
          compptr->width_in_blocks);
222
15.0k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
15.0k
                                  output_buf[compi][row],
224
15.0k
                                  compptr->width_in_blocks);
225
15.0k
    }
226
11.7k
  }
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.1k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
11.6k
    start_iMCU_row(cinfo);
236
11.6k
    return JPEG_ROW_COMPLETED;
237
11.6k
  }
238
  /* Completed the scan */
239
497
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
497
  return JPEG_SCAN_COMPLETED;
241
12.1k
}
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
25.5k
{
267
25.5k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
25.5k
  int ci, compi;
269
25.5k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
25.5k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
51.0k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
25.5k
    compptr = cinfo->cur_comp_info[ci];
275
25.5k
    compi = compptr->component_index;
276
25.5k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
25.5k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
25.5k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
25.5k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
25.5k
  }
281
282
25.5k
  return decompress_data(cinfo, buffer);
283
25.5k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
5.24k
{
267
5.24k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
5.24k
  int ci, compi;
269
5.24k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
5.24k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
10.4k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
5.24k
    compptr = cinfo->cur_comp_info[ci];
275
5.24k
    compi = compptr->component_index;
276
5.24k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
5.24k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
5.24k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
5.24k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
5.24k
  }
281
282
5.24k
  return decompress_data(cinfo, buffer);
283
5.24k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
8.16k
{
267
8.16k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
8.16k
  int ci, compi;
269
8.16k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
8.16k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
16.3k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
8.16k
    compptr = cinfo->cur_comp_info[ci];
275
8.16k
    compi = compptr->component_index;
276
8.16k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
8.16k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
8.16k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
8.16k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
8.16k
  }
281
282
8.16k
  return decompress_data(cinfo, buffer);
283
8.16k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
12.1k
{
267
12.1k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
12.1k
  int ci, compi;
269
12.1k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
12.1k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
24.2k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
12.1k
    compptr = cinfo->cur_comp_info[ci];
275
12.1k
    compi = compptr->component_index;
276
12.1k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
12.1k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
12.1k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
12.1k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
12.1k
  }
281
282
12.1k
  return decompress_data(cinfo, buffer);
283
12.1k
}
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
4
{
297
4
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
4
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
4
  int ci, samp_rows, row;
300
4
  _JSAMPARRAY buffer;
301
4
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
4
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
4
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
4
          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
12
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
8
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
8
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
8
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
8
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
8
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
8
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1
      samp_rows = compptr->v_samp_factor;
322
7
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
7
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
7
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
7
    }
327
328
18
    for (row = 0; row < samp_rows; row++) {
329
10
      memcpy(output_buf[ci][row], buffer[row],
330
10
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
10
    }
332
8
  }
333
334
4
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
4
  return JPEG_SCAN_COMPLETED;
337
4
}
jddiffct-8.c:output_data
Line
Count
Source
296
4
{
297
4
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
4
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
4
  int ci, samp_rows, row;
300
4
  _JSAMPARRAY buffer;
301
4
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
4
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
4
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
4
          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
12
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
8
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
8
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
8
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
8
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
8
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
8
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1
      samp_rows = compptr->v_samp_factor;
322
7
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
7
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
7
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
7
    }
327
328
18
    for (row = 0; row < samp_rows; row++) {
329
10
      memcpy(output_buf[ci][row], buffer[row],
330
10
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
10
    }
332
8
  }
333
334
4
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
4
  return JPEG_SCAN_COMPLETED;
337
4
}
Unexecuted instantiation: jddiffct-12.c:output_data
Unexecuted instantiation: jddiffct-16.c:output_data
338
339
#endif /* D_MULTISCAN_FILES_SUPPORTED */
340
341
342
/*
343
 * Initialize difference buffer controller.
344
 */
345
346
GLOBAL(void)
347
_jinit_d_diff_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
348
1.42k
{
349
1.42k
  my_diff_ptr diff;
350
1.42k
  int ci;
351
1.42k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
538
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
885
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
885
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.42k
  diff = (my_diff_ptr)
362
1.42k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.42k
                                sizeof(my_diff_controller));
364
1.42k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.42k
  diff->pub.start_input_pass = start_input_pass;
366
1.42k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
5.86k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.44k
       ci++, compptr++) {
371
4.44k
    diff->diff_buf[ci] =
372
4.44k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.44k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.44k
                                         (long)compptr->h_samp_factor),
375
4.44k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.44k
    diff->undiff_buf[ci] =
377
4.44k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.44k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.44k
                                         (long)compptr->h_samp_factor),
380
4.44k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.44k
  }
382
383
1.42k
  if (need_full_buffer) {
384
1.10k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.10k
    int access_rows;
387
388
4.40k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.30k
         ci++, compptr++) {
390
3.30k
      access_rows = compptr->v_samp_factor;
391
3.30k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.30k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.30k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.30k
                               (long)compptr->h_samp_factor),
395
3.30k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.30k
                               (long)compptr->v_samp_factor),
397
3.30k
         (JDIMENSION)access_rows);
398
3.30k
    }
399
1.10k
    diff->pub.consume_data = consume_data;
400
1.10k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.10k
  } else {
405
322
    diff->pub.consume_data = dummy_consume_data;
406
322
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
322
  }
409
1.42k
}
jinit_d_diff_controller
Line
Count
Source
348
538
{
349
538
  my_diff_ptr diff;
350
538
  int ci;
351
538
  jpeg_component_info *compptr;
352
353
538
#if BITS_IN_JSAMPLE == 8
354
538
  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
538
  diff = (my_diff_ptr)
362
538
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
538
                                sizeof(my_diff_controller));
364
538
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
538
  diff->pub.start_input_pass = start_input_pass;
366
538
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.29k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.75k
       ci++, compptr++) {
371
1.75k
    diff->diff_buf[ci] =
372
1.75k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.75k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.75k
                                         (long)compptr->h_samp_factor),
375
1.75k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.75k
    diff->undiff_buf[ci] =
377
1.75k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.75k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.75k
                                         (long)compptr->h_samp_factor),
380
1.75k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.75k
  }
382
383
538
  if (need_full_buffer) {
384
261
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
261
    int access_rows;
387
388
1.04k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
783
         ci++, compptr++) {
390
783
      access_rows = compptr->v_samp_factor;
391
783
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
783
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
783
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
783
                               (long)compptr->h_samp_factor),
395
783
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
783
                               (long)compptr->v_samp_factor),
397
783
         (JDIMENSION)access_rows);
398
783
    }
399
261
    diff->pub.consume_data = consume_data;
400
261
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
277
  } else {
405
277
    diff->pub.consume_data = dummy_consume_data;
406
277
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
277
  }
409
538
}
j12init_d_diff_controller
Line
Count
Source
348
441
{
349
441
  my_diff_ptr diff;
350
441
  int ci;
351
441
  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
441
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
441
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
441
  diff = (my_diff_ptr)
362
441
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
441
                                sizeof(my_diff_controller));
364
441
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
441
  diff->pub.start_input_pass = start_input_pass;
366
441
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.78k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.34k
       ci++, compptr++) {
371
1.34k
    diff->diff_buf[ci] =
372
1.34k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.34k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.34k
                                         (long)compptr->h_samp_factor),
375
1.34k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.34k
    diff->undiff_buf[ci] =
377
1.34k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.34k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.34k
                                         (long)compptr->h_samp_factor),
380
1.34k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.34k
  }
382
383
441
  if (need_full_buffer) {
384
416
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
416
    int access_rows;
387
388
1.66k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.24k
         ci++, compptr++) {
390
1.24k
      access_rows = compptr->v_samp_factor;
391
1.24k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.24k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.24k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.24k
                               (long)compptr->h_samp_factor),
395
1.24k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.24k
                               (long)compptr->v_samp_factor),
397
1.24k
         (JDIMENSION)access_rows);
398
1.24k
    }
399
416
    diff->pub.consume_data = consume_data;
400
416
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
416
  } else {
405
25
    diff->pub.consume_data = dummy_consume_data;
406
25
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
25
  }
409
441
}
j16init_d_diff_controller
Line
Count
Source
348
444
{
349
444
  my_diff_ptr diff;
350
444
  int ci;
351
444
  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
444
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
444
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
444
  diff = (my_diff_ptr)
362
444
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
444
                                sizeof(my_diff_controller));
364
444
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
444
  diff->pub.start_input_pass = start_input_pass;
366
444
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.78k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.34k
       ci++, compptr++) {
371
1.34k
    diff->diff_buf[ci] =
372
1.34k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.34k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.34k
                                         (long)compptr->h_samp_factor),
375
1.34k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.34k
    diff->undiff_buf[ci] =
377
1.34k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.34k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.34k
                                         (long)compptr->h_samp_factor),
380
1.34k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.34k
  }
382
383
444
  if (need_full_buffer) {
384
424
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
424
    int access_rows;
387
388
1.69k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.27k
         ci++, compptr++) {
390
1.27k
      access_rows = compptr->v_samp_factor;
391
1.27k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.27k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.27k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.27k
                               (long)compptr->h_samp_factor),
395
1.27k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.27k
                               (long)compptr->v_samp_factor),
397
1.27k
         (JDIMENSION)access_rows);
398
1.27k
    }
399
424
    diff->pub.consume_data = consume_data;
400
424
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
424
  } else {
405
20
    diff->pub.consume_data = dummy_consume_data;
406
20
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
20
  }
409
444
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */