Coverage Report

Created: 2026-06-15 06:19

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
37.5k
{
68
37.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
37.5k
  if (cinfo->comps_in_scan > 1) {
75
2.44k
    diff->MCU_rows_per_iMCU_row = 1;
76
35.1k
  } else {
77
35.1k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
34.1k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
958
    else
80
958
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
35.1k
  }
82
83
37.5k
  diff->MCU_ctr = 0;
84
37.5k
  diff->MCU_vert_offset = 0;
85
37.5k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
19.7k
{
68
19.7k
  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
19.7k
  if (cinfo->comps_in_scan > 1) {
75
2.39k
    diff->MCU_rows_per_iMCU_row = 1;
76
17.3k
  } else {
77
17.3k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
17.1k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
245
    else
80
245
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
17.3k
  }
82
83
19.7k
  diff->MCU_ctr = 0;
84
19.7k
  diff->MCU_vert_offset = 0;
85
19.7k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
8.15k
{
68
8.15k
  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.15k
  if (cinfo->comps_in_scan > 1) {
75
40
    diff->MCU_rows_per_iMCU_row = 1;
76
8.11k
  } else {
77
8.11k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
7.68k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
421
    else
80
421
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
8.11k
  }
82
83
8.15k
  diff->MCU_ctr = 0;
84
8.15k
  diff->MCU_vert_offset = 0;
85
8.15k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
9.61k
{
68
9.61k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
9.61k
  if (cinfo->comps_in_scan > 1) {
75
14
    diff->MCU_rows_per_iMCU_row = 1;
76
9.60k
  } else {
77
9.60k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
9.31k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
292
    else
80
292
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
9.60k
  }
82
83
9.61k
  diff->MCU_ctr = 0;
84
9.61k
  diff->MCU_vert_offset = 0;
85
9.61k
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
2.28k
{
95
2.28k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
2.28k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
2.28k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
18
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
2.28k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
2.28k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
2.28k
  cinfo->input_iMCU_row = 0;
115
2.28k
  start_iMCU_row(cinfo);
116
2.28k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
699
{
95
699
  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
699
  (*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
699
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
5
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
699
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
699
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
699
  cinfo->input_iMCU_row = 0;
115
699
  start_iMCU_row(cinfo);
116
699
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
817
{
95
817
  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
817
  (*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
817
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
6
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
817
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
817
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
817
  cinfo->input_iMCU_row = 0;
115
817
  start_iMCU_row(cinfo);
116
817
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
764
{
95
764
  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
764
  (*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
764
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
7
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
764
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
764
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
764
  cinfo->input_iMCU_row = 0;
115
764
  start_iMCU_row(cinfo);
116
764
}
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
6
{
127
6
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
6
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
6
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
6
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
6
  return TRUE;
138
6
}
jddiffct-8.c:process_restart
Line
Count
Source
126
1
{
127
1
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
1
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
1
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
1
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
1
  return TRUE;
138
1
}
jddiffct-12.c:process_restart
Line
Count
Source
126
3
{
127
3
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
3
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
3
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
3
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
3
  return TRUE;
138
3
}
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
326
{
148
326
  cinfo->output_iMCU_row = 0;
149
326
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
267
{
148
267
  cinfo->output_iMCU_row = 0;
149
267
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
40
{
148
40
  cinfo->output_iMCU_row = 0;
149
40
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
19
{
148
19
  cinfo->output_iMCU_row = 0;
149
19
}
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
37.4k
{
165
37.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
37.4k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
37.4k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
37.4k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
37.4k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
37.4k
  int ci, compi, row, prev_row;
171
37.4k
  unsigned int yoffset;
172
37.4k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
105k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
67.7k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
67.7k
    if (cinfo->restart_interval) {
180
2.70k
      if (diff->restart_rows_to_go == 0)
181
6
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
2.70k
    }
184
185
67.7k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
67.7k
    MCU_count =
188
67.7k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
67.7k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
67.7k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
67.7k
    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
67.7k
    if (cinfo->restart_interval)
200
2.65k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
67.7k
    diff->MCU_ctr = 0;
204
67.7k
  }
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
80.3k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
42.8k
    compptr = cinfo->cur_comp_info[ci];
213
42.8k
    compi = compptr->component_index;
214
42.8k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
118k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
116k
                compptr->last_row_height : compptr->v_samp_factor);
217
75.9k
         prev_row = row, row++) {
218
75.9k
      (*losslessd->predict_undifference[compi])
219
75.9k
        (cinfo, compi, diff->diff_buf[compi][row],
220
75.9k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
75.9k
          compptr->width_in_blocks);
222
75.9k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
75.9k
                                  output_buf[compi][row],
224
75.9k
                                  compptr->width_in_blocks);
225
75.9k
    }
226
42.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
37.4k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
35.4k
    start_iMCU_row(cinfo);
236
35.4k
    return JPEG_ROW_COMPLETED;
237
35.4k
  }
238
  /* Completed the scan */
239
2.07k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
2.07k
  return JPEG_SCAN_COMPLETED;
241
37.4k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
19.7k
{
165
19.7k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
19.7k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
19.7k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
19.7k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
19.7k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
19.7k
  int ci, compi, row, prev_row;
171
19.7k
  unsigned int yoffset;
172
19.7k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
56.5k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
36.7k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
36.7k
    if (cinfo->restart_interval) {
180
494
      if (diff->restart_rows_to_go == 0)
181
1
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
494
    }
184
185
36.7k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
36.7k
    MCU_count =
188
36.7k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
36.7k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
36.7k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
36.7k
    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
36.7k
    if (cinfo->restart_interval)
200
484
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
36.7k
    diff->MCU_ctr = 0;
204
36.7k
  }
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
45.6k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
25.8k
    compptr = cinfo->cur_comp_info[ci];
213
25.8k
    compi = compptr->component_index;
214
25.8k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
71.8k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
71.0k
                compptr->last_row_height : compptr->v_samp_factor);
217
46.0k
         prev_row = row, row++) {
218
46.0k
      (*losslessd->predict_undifference[compi])
219
46.0k
        (cinfo, compi, diff->diff_buf[compi][row],
220
46.0k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
46.0k
          compptr->width_in_blocks);
222
46.0k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
46.0k
                                  output_buf[compi][row],
224
46.0k
                                  compptr->width_in_blocks);
225
46.0k
    }
226
25.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
19.7k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
19.1k
    start_iMCU_row(cinfo);
236
19.1k
    return JPEG_ROW_COMPLETED;
237
19.1k
  }
238
  /* Completed the scan */
239
649
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
649
  return JPEG_SCAN_COMPLETED;
241
19.7k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
8.11k
{
165
8.11k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
8.11k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
8.11k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
8.11k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
8.11k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
8.11k
  int ci, compi, row, prev_row;
171
8.11k
  unsigned int yoffset;
172
8.11k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
21.5k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
13.4k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
13.4k
    if (cinfo->restart_interval) {
180
1.65k
      if (diff->restart_rows_to_go == 0)
181
3
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.65k
    }
184
185
13.4k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
13.4k
    MCU_count =
188
13.4k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
13.4k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
13.4k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
13.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
13.4k
    if (cinfo->restart_interval)
200
1.62k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
13.4k
    diff->MCU_ctr = 0;
204
13.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
15.8k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
7.78k
    compptr = cinfo->cur_comp_info[ci];
213
7.78k
    compi = compptr->component_index;
214
7.78k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
20.8k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
19.8k
                compptr->last_row_height : compptr->v_samp_factor);
217
13.0k
         prev_row = row, row++) {
218
13.0k
      (*losslessd->predict_undifference[compi])
219
13.0k
        (cinfo, compi, diff->diff_buf[compi][row],
220
13.0k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
13.0k
          compptr->width_in_blocks);
222
13.0k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
13.0k
                                  output_buf[compi][row],
224
13.0k
                                  compptr->width_in_blocks);
225
13.0k
    }
226
7.78k
  }
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.11k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
7.37k
    start_iMCU_row(cinfo);
236
7.37k
    return JPEG_ROW_COMPLETED;
237
7.37k
  }
238
  /* Completed the scan */
239
733
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
733
  return JPEG_SCAN_COMPLETED;
241
8.11k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
9.60k
{
165
9.60k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
9.60k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
9.60k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
9.60k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
9.60k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
9.60k
  int ci, compi, row, prev_row;
171
9.60k
  unsigned int yoffset;
172
9.60k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
27.1k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
17.4k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
17.4k
    if (cinfo->restart_interval) {
180
562
      if (diff->restart_rows_to_go == 0)
181
2
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
562
    }
184
185
17.4k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
17.4k
    MCU_count =
188
17.4k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
17.4k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
17.4k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
17.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
17.4k
    if (cinfo->restart_interval)
200
545
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
17.4k
    diff->MCU_ctr = 0;
204
17.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
18.8k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
9.19k
    compptr = cinfo->cur_comp_info[ci];
213
9.19k
    compi = compptr->component_index;
214
9.19k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
26.1k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
25.3k
                compptr->last_row_height : compptr->v_samp_factor);
217
16.9k
         prev_row = row, row++) {
218
16.9k
      (*losslessd->predict_undifference[compi])
219
16.9k
        (cinfo, compi, diff->diff_buf[compi][row],
220
16.9k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
16.9k
          compptr->width_in_blocks);
222
16.9k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
16.9k
                                  output_buf[compi][row],
224
16.9k
                                  compptr->width_in_blocks);
225
16.9k
    }
226
9.19k
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
9.60k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
8.91k
    start_iMCU_row(cinfo);
236
8.91k
    return JPEG_ROW_COMPLETED;
237
8.91k
  }
238
  /* Completed the scan */
239
693
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
693
  return JPEG_SCAN_COMPLETED;
241
9.60k
}
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
35.1k
{
267
35.1k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
35.1k
  int ci, compi;
269
35.1k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
35.1k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
70.2k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
35.1k
    compptr = cinfo->cur_comp_info[ci];
275
35.1k
    compi = compptr->component_index;
276
35.1k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
35.1k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
35.1k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
35.1k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
35.1k
  }
281
282
35.1k
  return decompress_data(cinfo, buffer);
283
35.1k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
17.3k
{
267
17.3k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
17.3k
  int ci, compi;
269
17.3k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
17.3k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
34.7k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
17.3k
    compptr = cinfo->cur_comp_info[ci];
275
17.3k
    compi = compptr->component_index;
276
17.3k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
17.3k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
17.3k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
17.3k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
17.3k
  }
281
282
17.3k
  return decompress_data(cinfo, buffer);
283
17.3k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
8.11k
{
267
8.11k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
8.11k
  int ci, compi;
269
8.11k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
8.11k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
16.2k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
8.11k
    compptr = cinfo->cur_comp_info[ci];
275
8.11k
    compi = compptr->component_index;
276
8.11k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
8.11k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
8.11k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
8.11k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
8.11k
  }
281
282
8.11k
  return decompress_data(cinfo, buffer);
283
8.11k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
9.60k
{
267
9.60k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
9.60k
  int ci, compi;
269
9.60k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
9.60k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
19.2k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
9.60k
    compptr = cinfo->cur_comp_info[ci];
275
9.60k
    compi = compptr->component_index;
276
9.60k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
9.60k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
9.60k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
9.60k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
9.60k
  }
281
282
9.60k
  return decompress_data(cinfo, buffer);
283
9.60k
}
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
25
{
297
25
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
25
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
25
  int ci, samp_rows, row;
300
25
  _JSAMPARRAY buffer;
301
25
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
25
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
25
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
25
          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
75
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
50
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
50
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
50
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
50
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
50
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
50
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
13
      samp_rows = compptr->v_samp_factor;
322
37
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
37
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
37
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
37
    }
327
328
108
    for (row = 0; row < samp_rows; row++) {
329
58
      memcpy(output_buf[ci][row], buffer[row],
330
58
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
58
    }
332
50
  }
333
334
25
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
25
  return JPEG_SCAN_COMPLETED;
337
25
}
jddiffct-8.c:output_data
Line
Count
Source
296
25
{
297
25
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
25
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
25
  int ci, samp_rows, row;
300
25
  _JSAMPARRAY buffer;
301
25
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
25
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
25
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
25
          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
75
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
50
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
50
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
50
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
50
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
50
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
50
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
13
      samp_rows = compptr->v_samp_factor;
322
37
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
37
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
37
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
37
    }
327
328
108
    for (row = 0; row < samp_rows; row++) {
329
58
      memcpy(output_buf[ci][row], buffer[row],
330
58
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
58
    }
332
50
  }
333
334
25
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
25
  return JPEG_SCAN_COMPLETED;
337
25
}
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.66k
{
349
1.66k
  my_diff_ptr diff;
350
1.66k
  int ci;
351
1.66k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
549
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
1.11k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.11k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.66k
  diff = (my_diff_ptr)
362
1.66k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.66k
                                sizeof(my_diff_controller));
364
1.66k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.66k
  diff->pub.start_input_pass = start_input_pass;
366
1.66k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
6.95k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
5.29k
       ci++, compptr++) {
371
5.29k
    diff->diff_buf[ci] =
372
5.29k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
5.29k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
5.29k
                                         (long)compptr->h_samp_factor),
375
5.29k
                   (JDIMENSION)compptr->v_samp_factor);
376
5.29k
    diff->undiff_buf[ci] =
377
5.29k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
5.29k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
5.29k
                                         (long)compptr->h_samp_factor),
380
5.29k
                   (JDIMENSION)compptr->v_samp_factor);
381
5.29k
  }
382
383
1.66k
  if (need_full_buffer) {
384
1.26k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.26k
    int access_rows;
387
388
5.05k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.79k
         ci++, compptr++) {
390
3.79k
      access_rows = compptr->v_samp_factor;
391
3.79k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.79k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.79k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.79k
                               (long)compptr->h_samp_factor),
395
3.79k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.79k
                               (long)compptr->v_samp_factor),
397
3.79k
         (JDIMENSION)access_rows);
398
3.79k
    }
399
1.26k
    diff->pub.consume_data = consume_data;
400
1.26k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.26k
  } else {
405
398
    diff->pub.consume_data = dummy_consume_data;
406
398
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
398
  }
409
1.66k
}
jinit_d_diff_controller
Line
Count
Source
348
549
{
349
549
  my_diff_ptr diff;
350
549
  int ci;
351
549
  jpeg_component_info *compptr;
352
353
549
#if BITS_IN_JSAMPLE == 8
354
549
  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
549
  diff = (my_diff_ptr)
362
549
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
549
                                sizeof(my_diff_controller));
364
549
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
549
  diff->pub.start_input_pass = start_input_pass;
366
549
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.42k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.87k
       ci++, compptr++) {
371
1.87k
    diff->diff_buf[ci] =
372
1.87k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.87k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.87k
                                         (long)compptr->h_samp_factor),
375
1.87k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.87k
    diff->undiff_buf[ci] =
377
1.87k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.87k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.87k
                                         (long)compptr->h_samp_factor),
380
1.87k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.87k
  }
382
383
549
  if (need_full_buffer) {
384
265
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
265
    int access_rows;
387
388
1.06k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
796
         ci++, compptr++) {
390
796
      access_rows = compptr->v_samp_factor;
391
796
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
796
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
796
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
796
                               (long)compptr->h_samp_factor),
395
796
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
796
                               (long)compptr->v_samp_factor),
397
796
         (JDIMENSION)access_rows);
398
796
    }
399
265
    diff->pub.consume_data = consume_data;
400
265
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
284
  } else {
405
284
    diff->pub.consume_data = dummy_consume_data;
406
284
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
284
  }
409
549
}
j12init_d_diff_controller
Line
Count
Source
348
507
{
349
507
  my_diff_ptr diff;
350
507
  int ci;
351
507
  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
507
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
507
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
507
  diff = (my_diff_ptr)
362
507
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
507
                                sizeof(my_diff_controller));
364
507
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
507
  diff->pub.start_input_pass = start_input_pass;
366
507
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.06k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.55k
       ci++, compptr++) {
371
1.55k
    diff->diff_buf[ci] =
372
1.55k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.55k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.55k
                                         (long)compptr->h_samp_factor),
375
1.55k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.55k
    diff->undiff_buf[ci] =
377
1.55k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.55k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.55k
                                         (long)compptr->h_samp_factor),
380
1.55k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.55k
  }
382
383
507
  if (need_full_buffer) {
384
457
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
457
    int access_rows;
387
388
1.83k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.37k
         ci++, compptr++) {
390
1.37k
      access_rows = compptr->v_samp_factor;
391
1.37k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.37k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.37k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.37k
                               (long)compptr->h_samp_factor),
395
1.37k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.37k
                               (long)compptr->v_samp_factor),
397
1.37k
         (JDIMENSION)access_rows);
398
1.37k
    }
399
457
    diff->pub.consume_data = consume_data;
400
457
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
457
  } else {
405
50
    diff->pub.consume_data = dummy_consume_data;
406
50
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
50
  }
409
507
}
j16init_d_diff_controller
Line
Count
Source
348
605
{
349
605
  my_diff_ptr diff;
350
605
  int ci;
351
605
  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
605
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
605
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
605
  diff = (my_diff_ptr)
362
605
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
605
                                sizeof(my_diff_controller));
364
605
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
605
  diff->pub.start_input_pass = start_input_pass;
366
605
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.47k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.86k
       ci++, compptr++) {
371
1.86k
    diff->diff_buf[ci] =
372
1.86k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.86k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.86k
                                         (long)compptr->h_samp_factor),
375
1.86k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.86k
    diff->undiff_buf[ci] =
377
1.86k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.86k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.86k
                                         (long)compptr->h_samp_factor),
380
1.86k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.86k
  }
382
383
605
  if (need_full_buffer) {
384
541
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
541
    int access_rows;
387
388
2.16k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.62k
         ci++, compptr++) {
390
1.62k
      access_rows = compptr->v_samp_factor;
391
1.62k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.62k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.62k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.62k
                               (long)compptr->h_samp_factor),
395
1.62k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.62k
                               (long)compptr->v_samp_factor),
397
1.62k
         (JDIMENSION)access_rows);
398
1.62k
    }
399
541
    diff->pub.consume_data = consume_data;
400
541
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
541
  } else {
405
64
    diff->pub.consume_data = dummy_consume_data;
406
64
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
64
  }
409
605
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */