Coverage Report

Created: 2025-07-11 06:58

/src/libjpeg-turbo/src/jddiffct.c
Line
Count
Source (jump to first uncovered line)
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
141k
{
68
141k
  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
141k
  if (cinfo->comps_in_scan > 1) {
75
14.1k
    diff->MCU_rows_per_iMCU_row = 1;
76
127k
  } else {
77
127k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
125k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.40k
    else
80
1.40k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
127k
  }
82
83
141k
  diff->MCU_ctr = 0;
84
141k
  diff->MCU_vert_offset = 0;
85
141k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
34.1k
{
68
34.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
34.1k
  if (cinfo->comps_in_scan > 1) {
75
2.20k
    diff->MCU_rows_per_iMCU_row = 1;
76
31.9k
  } else {
77
31.9k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
31.5k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
333
    else
80
333
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
31.9k
  }
82
83
34.1k
  diff->MCU_ctr = 0;
84
34.1k
  diff->MCU_vert_offset = 0;
85
34.1k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
32.2k
{
68
32.2k
  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
32.2k
  if (cinfo->comps_in_scan > 1) {
75
752
    diff->MCU_rows_per_iMCU_row = 1;
76
31.5k
  } else {
77
31.5k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
30.8k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
654
    else
80
654
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
31.5k
  }
82
83
32.2k
  diff->MCU_ctr = 0;
84
32.2k
  diff->MCU_vert_offset = 0;
85
32.2k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
74.9k
{
68
74.9k
  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
74.9k
  if (cinfo->comps_in_scan > 1) {
75
11.1k
    diff->MCU_rows_per_iMCU_row = 1;
76
63.8k
  } else {
77
63.8k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
63.4k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
417
    else
80
417
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
63.8k
  }
82
83
74.9k
  diff->MCU_ctr = 0;
84
74.9k
  diff->MCU_vert_offset = 0;
85
74.9k
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
4.99k
{
95
4.99k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
4.99k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
4.99k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
41
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
4.99k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
4.99k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
4.99k
  cinfo->input_iMCU_row = 0;
115
4.99k
  start_iMCU_row(cinfo);
116
4.99k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
1.71k
{
95
1.71k
  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.71k
  (*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.71k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
10
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.71k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.71k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.71k
  cinfo->input_iMCU_row = 0;
115
1.71k
  start_iMCU_row(cinfo);
116
1.71k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
1.76k
{
95
1.76k
  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.76k
  (*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.76k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
15
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.76k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.76k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.76k
  cinfo->input_iMCU_row = 0;
115
1.76k
  start_iMCU_row(cinfo);
116
1.76k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
1.51k
{
95
1.51k
  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.51k
  (*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.51k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
16
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.51k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.51k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.51k
  cinfo->input_iMCU_row = 0;
115
1.51k
  start_iMCU_row(cinfo);
116
1.51k
}
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
48
{
127
48
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
48
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
48
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
48
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
48
  return TRUE;
138
48
}
jddiffct-8.c:process_restart
Line
Count
Source
126
10
{
127
10
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
10
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
10
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
10
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
10
  return TRUE;
138
10
}
jddiffct-12.c:process_restart
Line
Count
Source
126
20
{
127
20
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
20
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
20
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
20
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
20
  return TRUE;
138
20
}
jddiffct-16.c:process_restart
Line
Count
Source
126
18
{
127
18
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
18
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
18
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
18
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
18
  return TRUE;
138
18
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
864
{
148
864
  cinfo->output_iMCU_row = 0;
149
864
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
820
{
148
820
  cinfo->output_iMCU_row = 0;
149
820
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
22
{
148
22
  cinfo->output_iMCU_row = 0;
149
22
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
22
{
148
22
  cinfo->output_iMCU_row = 0;
149
22
}
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
141k
{
165
141k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
141k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
141k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
141k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
141k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
141k
  int ci, compi, row, prev_row;
171
141k
  unsigned int yoffset;
172
141k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
348k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
206k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
206k
    if (cinfo->restart_interval) {
180
1.91k
      if (diff->restart_rows_to_go == 0)
181
48
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.91k
    }
184
185
206k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
206k
    MCU_count =
188
206k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
206k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
206k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
206k
    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
206k
    if (cinfo->restart_interval)
200
1.82k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
206k
    diff->MCU_ctr = 0;
204
206k
  }
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
295k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
154k
    compptr = cinfo->cur_comp_info[ci];
213
154k
    compi = compptr->component_index;
214
154k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
378k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
366k
                compptr->last_row_height : compptr->v_samp_factor);
217
223k
         prev_row = row, row++) {
218
223k
      (*losslessd->predict_undifference[compi])
219
223k
        (cinfo, compi, diff->diff_buf[compi][row],
220
223k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
223k
          compptr->width_in_blocks);
222
223k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
223k
                                  output_buf[compi][row],
224
223k
                                  compptr->width_in_blocks);
225
223k
    }
226
154k
  }
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
141k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
136k
    start_iMCU_row(cinfo);
236
136k
    return JPEG_ROW_COMPLETED;
237
136k
  }
238
  /* Completed the scan */
239
4.78k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
4.78k
  return JPEG_SCAN_COMPLETED;
241
141k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
34.1k
{
165
34.1k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
34.1k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
34.1k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
34.1k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
34.1k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
34.1k
  int ci, compi, row, prev_row;
171
34.1k
  unsigned int yoffset;
172
34.1k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
115k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
81.6k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
81.6k
    if (cinfo->restart_interval) {
180
312
      if (diff->restart_rows_to_go == 0)
181
10
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
312
    }
184
185
81.6k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
81.6k
    MCU_count =
188
81.6k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
81.6k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
81.6k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
81.6k
    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
81.6k
    if (cinfo->restart_interval)
200
286
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
81.6k
    diff->MCU_ctr = 0;
204
81.6k
  }
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
70.0k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
35.9k
    compptr = cinfo->cur_comp_info[ci];
213
35.9k
    compi = compptr->component_index;
214
35.9k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
122k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
119k
                compptr->last_row_height : compptr->v_samp_factor);
217
86.5k
         prev_row = row, row++) {
218
86.5k
      (*losslessd->predict_undifference[compi])
219
86.5k
        (cinfo, compi, diff->diff_buf[compi][row],
220
86.5k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
86.5k
          compptr->width_in_blocks);
222
86.5k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
86.5k
                                  output_buf[compi][row],
224
86.5k
                                  compptr->width_in_blocks);
225
86.5k
    }
226
35.9k
  }
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
34.1k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
32.4k
    start_iMCU_row(cinfo);
236
32.4k
    return JPEG_ROW_COMPLETED;
237
32.4k
  }
238
  /* Completed the scan */
239
1.65k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.65k
  return JPEG_SCAN_COMPLETED;
241
34.1k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
32.2k
{
165
32.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
32.2k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
32.2k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
32.2k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
32.2k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
32.2k
  int ci, compi, row, prev_row;
171
32.2k
  unsigned int yoffset;
172
32.2k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
67.5k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
35.2k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
35.2k
    if (cinfo->restart_interval) {
180
291
      if (diff->restart_rows_to_go == 0)
181
20
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
291
    }
184
185
35.2k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
35.2k
    MCU_count =
188
35.2k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
35.2k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
35.2k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
35.2k
    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
35.2k
    if (cinfo->restart_interval)
200
259
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
35.2k
    diff->MCU_ctr = 0;
204
35.2k
  }
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
65.0k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
32.7k
    compptr = cinfo->cur_comp_info[ci];
213
32.7k
    compi = compptr->component_index;
214
32.7k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
68.8k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
64.3k
                compptr->last_row_height : compptr->v_samp_factor);
217
36.0k
         prev_row = row, row++) {
218
36.0k
      (*losslessd->predict_undifference[compi])
219
36.0k
        (cinfo, compi, diff->diff_buf[compi][row],
220
36.0k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
36.0k
          compptr->width_in_blocks);
222
36.0k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
36.0k
                                  output_buf[compi][row],
224
36.0k
                                  compptr->width_in_blocks);
225
36.0k
    }
226
32.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
32.2k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
30.5k
    start_iMCU_row(cinfo);
236
30.5k
    return JPEG_ROW_COMPLETED;
237
30.5k
  }
238
  /* Completed the scan */
239
1.68k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.68k
  return JPEG_SCAN_COMPLETED;
241
32.2k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
74.9k
{
165
74.9k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
74.9k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
74.9k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
74.9k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
74.9k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
74.9k
  int ci, compi, row, prev_row;
171
74.9k
  unsigned int yoffset;
172
74.9k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
164k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
89.8k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
89.8k
    if (cinfo->restart_interval) {
180
1.31k
      if (diff->restart_rows_to_go == 0)
181
18
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.31k
    }
184
185
89.8k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
89.8k
    MCU_count =
188
89.8k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
89.8k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
89.8k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
89.8k
    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
89.8k
    if (cinfo->restart_interval)
200
1.28k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
89.8k
    diff->MCU_ctr = 0;
204
89.8k
  }
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
160k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
85.8k
    compptr = cinfo->cur_comp_info[ci];
213
85.8k
    compi = compptr->component_index;
214
85.8k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
187k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
183k
                compptr->last_row_height : compptr->v_samp_factor);
217
101k
         prev_row = row, row++) {
218
101k
      (*losslessd->predict_undifference[compi])
219
101k
        (cinfo, compi, diff->diff_buf[compi][row],
220
101k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
101k
          compptr->width_in_blocks);
222
101k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
101k
                                  output_buf[compi][row],
224
101k
                                  compptr->width_in_blocks);
225
101k
    }
226
85.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
74.9k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
73.5k
    start_iMCU_row(cinfo);
236
73.5k
    return JPEG_ROW_COMPLETED;
237
73.5k
  }
238
  /* Completed the scan */
239
1.44k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.44k
  return JPEG_SCAN_COMPLETED;
241
74.9k
}
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
133k
{
267
133k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
133k
  int ci, compi;
269
133k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
133k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
279k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
146k
    compptr = cinfo->cur_comp_info[ci];
275
146k
    compi = compptr->component_index;
276
146k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
146k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
146k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
146k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
146k
  }
281
282
133k
  return decompress_data(cinfo, buffer);
283
133k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
25.9k
{
267
25.9k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
25.9k
  int ci, compi;
269
25.9k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
25.9k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
52.7k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
26.7k
    compptr = cinfo->cur_comp_info[ci];
275
26.7k
    compi = compptr->component_index;
276
26.7k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
26.7k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
26.7k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
26.7k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
26.7k
  }
281
282
25.9k
  return decompress_data(cinfo, buffer);
283
25.9k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
32.2k
{
267
32.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
32.2k
  int ci, compi;
269
32.2k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
32.2k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
65.6k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
33.3k
    compptr = cinfo->cur_comp_info[ci];
275
33.3k
    compi = compptr->component_index;
276
33.3k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
33.3k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
33.3k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
33.3k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
33.3k
  }
281
282
32.2k
  return decompress_data(cinfo, buffer);
283
32.2k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
74.9k
{
267
74.9k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
74.9k
  int ci, compi;
269
74.9k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
74.9k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
161k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
86.4k
    compptr = cinfo->cur_comp_info[ci];
275
86.4k
    compi = compptr->component_index;
276
86.4k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
86.4k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
86.4k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
86.4k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
86.4k
  }
281
282
74.9k
  return decompress_data(cinfo, buffer);
283
74.9k
}
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
65
{
297
65
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
65
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
65
  int ci, samp_rows, row;
300
65
  _JSAMPARRAY buffer;
301
65
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
65
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
65
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
65
          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
205
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
140
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
140
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
140
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
140
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
140
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
140
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
78
      samp_rows = compptr->v_samp_factor;
322
62
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
62
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
62
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
62
    }
327
328
417
    for (row = 0; row < samp_rows; row++) {
329
277
      memcpy(output_buf[ci][row], buffer[row],
330
277
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
277
    }
332
140
  }
333
334
65
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
36
    return JPEG_ROW_COMPLETED;
336
29
  return JPEG_SCAN_COMPLETED;
337
65
}
jddiffct-8.c:output_data
Line
Count
Source
296
65
{
297
65
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
65
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
65
  int ci, samp_rows, row;
300
65
  _JSAMPARRAY buffer;
301
65
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
65
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
65
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
65
          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
205
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
140
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
140
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
140
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
140
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
140
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
140
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
78
      samp_rows = compptr->v_samp_factor;
322
62
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
62
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
62
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
62
    }
327
328
417
    for (row = 0; row < samp_rows; row++) {
329
277
      memcpy(output_buf[ci][row], buffer[row],
330
277
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
277
    }
332
140
  }
333
334
65
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
36
    return JPEG_ROW_COMPLETED;
336
29
  return JPEG_SCAN_COMPLETED;
337
65
}
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
2.71k
{
349
2.71k
  my_diff_ptr diff;
350
2.71k
  int ci;
351
2.71k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
1.15k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
1.56k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.56k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
2.71k
  diff = (my_diff_ptr)
362
2.71k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
2.71k
                                sizeof(my_diff_controller));
364
2.71k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
2.71k
  diff->pub.start_input_pass = start_input_pass;
366
2.71k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
9.49k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
6.77k
       ci++, compptr++) {
371
6.77k
    diff->diff_buf[ci] =
372
6.77k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
6.77k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
6.77k
                                         (long)compptr->h_samp_factor),
375
6.77k
                   (JDIMENSION)compptr->v_samp_factor);
376
6.77k
    diff->undiff_buf[ci] =
377
6.77k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
6.77k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
6.77k
                                         (long)compptr->h_samp_factor),
380
6.77k
                   (JDIMENSION)compptr->v_samp_factor);
381
6.77k
  }
382
383
2.71k
  if (need_full_buffer) {
384
1.73k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.73k
    int access_rows;
387
388
7.23k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
5.50k
         ci++, compptr++) {
390
5.50k
      access_rows = compptr->v_samp_factor;
391
5.50k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
5.50k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
5.50k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
5.50k
                               (long)compptr->h_samp_factor),
395
5.50k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
5.50k
                               (long)compptr->v_samp_factor),
397
5.50k
         (JDIMENSION)access_rows);
398
5.50k
    }
399
1.73k
    diff->pub.consume_data = consume_data;
400
1.73k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.73k
  } else {
405
983
    diff->pub.consume_data = dummy_consume_data;
406
983
    diff->pub._decompress_data = decompress_data;
407
983
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
983
  }
409
2.71k
}
jinit_d_diff_controller
Line
Count
Source
348
1.15k
{
349
1.15k
  my_diff_ptr diff;
350
1.15k
  int ci;
351
1.15k
  jpeg_component_info *compptr;
352
353
1.15k
#if BITS_IN_JSAMPLE == 8
354
1.15k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.15k
  diff = (my_diff_ptr)
362
1.15k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.15k
                                sizeof(my_diff_controller));
364
1.15k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.15k
  diff->pub.start_input_pass = start_input_pass;
366
1.15k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
3.24k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
2.08k
       ci++, compptr++) {
371
2.08k
    diff->diff_buf[ci] =
372
2.08k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
2.08k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
2.08k
                                         (long)compptr->h_samp_factor),
375
2.08k
                   (JDIMENSION)compptr->v_samp_factor);
376
2.08k
    diff->undiff_buf[ci] =
377
2.08k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
2.08k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
2.08k
                                         (long)compptr->h_samp_factor),
380
2.08k
                   (JDIMENSION)compptr->v_samp_factor);
381
2.08k
  }
382
383
1.15k
  if (need_full_buffer) {
384
288
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
288
    int access_rows;
387
388
1.23k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
946
         ci++, compptr++) {
390
946
      access_rows = compptr->v_samp_factor;
391
946
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
946
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
946
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
946
                               (long)compptr->h_samp_factor),
395
946
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
946
                               (long)compptr->v_samp_factor),
397
946
         (JDIMENSION)access_rows);
398
946
    }
399
288
    diff->pub.consume_data = consume_data;
400
288
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
867
  } else {
405
867
    diff->pub.consume_data = dummy_consume_data;
406
867
    diff->pub._decompress_data = decompress_data;
407
867
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
867
  }
409
1.15k
}
j12init_d_diff_controller
Line
Count
Source
348
783
{
349
783
  my_diff_ptr diff;
350
783
  int ci;
351
783
  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
783
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
783
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
783
  diff = (my_diff_ptr)
362
783
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
783
                                sizeof(my_diff_controller));
364
783
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
783
  diff->pub.start_input_pass = start_input_pass;
366
783
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
3.14k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
2.36k
       ci++, compptr++) {
371
2.36k
    diff->diff_buf[ci] =
372
2.36k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
2.36k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
2.36k
                                         (long)compptr->h_samp_factor),
375
2.36k
                   (JDIMENSION)compptr->v_samp_factor);
376
2.36k
    diff->undiff_buf[ci] =
377
2.36k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
2.36k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
2.36k
                                         (long)compptr->h_samp_factor),
380
2.36k
                   (JDIMENSION)compptr->v_samp_factor);
381
2.36k
  }
382
383
783
  if (need_full_buffer) {
384
724
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
724
    int access_rows;
387
388
3.01k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
2.29k
         ci++, compptr++) {
390
2.29k
      access_rows = compptr->v_samp_factor;
391
2.29k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
2.29k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
2.29k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
2.29k
                               (long)compptr->h_samp_factor),
395
2.29k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
2.29k
                               (long)compptr->v_samp_factor),
397
2.29k
         (JDIMENSION)access_rows);
398
2.29k
    }
399
724
    diff->pub.consume_data = consume_data;
400
724
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
724
  } else {
405
59
    diff->pub.consume_data = dummy_consume_data;
406
59
    diff->pub._decompress_data = decompress_data;
407
59
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
59
  }
409
783
}
j16init_d_diff_controller
Line
Count
Source
348
780
{
349
780
  my_diff_ptr diff;
350
780
  int ci;
351
780
  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
780
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
780
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
780
  diff = (my_diff_ptr)
362
780
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
780
                                sizeof(my_diff_controller));
364
780
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
780
  diff->pub.start_input_pass = start_input_pass;
366
780
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
3.10k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
2.32k
       ci++, compptr++) {
371
2.32k
    diff->diff_buf[ci] =
372
2.32k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
2.32k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
2.32k
                                         (long)compptr->h_samp_factor),
375
2.32k
                   (JDIMENSION)compptr->v_samp_factor);
376
2.32k
    diff->undiff_buf[ci] =
377
2.32k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
2.32k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
2.32k
                                         (long)compptr->h_samp_factor),
380
2.32k
                   (JDIMENSION)compptr->v_samp_factor);
381
2.32k
  }
382
383
780
  if (need_full_buffer) {
384
723
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
723
    int access_rows;
387
388
2.98k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
2.26k
         ci++, compptr++) {
390
2.26k
      access_rows = compptr->v_samp_factor;
391
2.26k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
2.26k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
2.26k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
2.26k
                               (long)compptr->h_samp_factor),
395
2.26k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
2.26k
                               (long)compptr->v_samp_factor),
397
2.26k
         (JDIMENSION)access_rows);
398
2.26k
    }
399
723
    diff->pub.consume_data = consume_data;
400
723
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
723
  } else {
405
57
    diff->pub.consume_data = dummy_consume_data;
406
57
    diff->pub._decompress_data = decompress_data;
407
57
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
57
  }
409
780
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */