Coverage Report

Created: 2026-01-10 07:03

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
51.2k
{
68
51.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
51.2k
  if (cinfo->comps_in_scan > 1) {
75
5.32k
    diff->MCU_rows_per_iMCU_row = 1;
76
45.9k
  } else {
77
45.9k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
44.6k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.23k
    else
80
1.23k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
45.9k
  }
82
83
51.2k
  diff->MCU_ctr = 0;
84
51.2k
  diff->MCU_vert_offset = 0;
85
51.2k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
10.2k
{
68
10.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
10.2k
  if (cinfo->comps_in_scan > 1) {
75
5.30k
    diff->MCU_rows_per_iMCU_row = 1;
76
5.30k
  } else {
77
4.95k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
4.47k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
480
    else
80
480
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
4.95k
  }
82
83
10.2k
  diff->MCU_ctr = 0;
84
10.2k
  diff->MCU_vert_offset = 0;
85
10.2k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
18.1k
{
68
18.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
18.1k
  if (cinfo->comps_in_scan > 1) {
75
12
    diff->MCU_rows_per_iMCU_row = 1;
76
18.1k
  } else {
77
18.1k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
17.7k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
379
    else
80
379
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
18.1k
  }
82
83
18.1k
  diff->MCU_ctr = 0;
84
18.1k
  diff->MCU_vert_offset = 0;
85
18.1k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
22.8k
{
68
22.8k
  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
22.8k
  if (cinfo->comps_in_scan > 1) {
75
9
    diff->MCU_rows_per_iMCU_row = 1;
76
22.8k
  } else {
77
22.8k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
22.4k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
371
    else
80
371
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
22.8k
  }
82
83
22.8k
  diff->MCU_ctr = 0;
84
22.8k
  diff->MCU_vert_offset = 0;
85
22.8k
}
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.70k
{
95
2.70k
  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.70k
  (*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.70k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
3
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
2.70k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
2.70k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
2.70k
  cinfo->input_iMCU_row = 0;
115
2.70k
  start_iMCU_row(cinfo);
116
2.70k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
996
{
95
996
  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
996
  (*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
996
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
996
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
996
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
996
  cinfo->input_iMCU_row = 0;
115
996
  start_iMCU_row(cinfo);
116
996
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
797
{
95
797
  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
797
  (*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
797
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
797
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
797
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
797
  cinfo->input_iMCU_row = 0;
115
797
  start_iMCU_row(cinfo);
116
797
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
914
{
95
914
  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
914
  (*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
914
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
914
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
914
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
914
  cinfo->input_iMCU_row = 0;
115
914
  start_iMCU_row(cinfo);
116
914
}
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
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-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
}
Unexecuted instantiation: jddiffct-12.c:process_restart
Unexecuted instantiation: jddiffct-16.c:process_restart
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
436
{
148
436
  cinfo->output_iMCU_row = 0;
149
436
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
414
{
148
414
  cinfo->output_iMCU_row = 0;
149
414
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
13
{
148
13
  cinfo->output_iMCU_row = 0;
149
13
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
9
{
148
9
  cinfo->output_iMCU_row = 0;
149
9
}
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
51.2k
{
165
51.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
51.2k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
51.2k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
51.2k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
51.2k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
51.2k
  int ci, compi, row, prev_row;
171
51.2k
  unsigned int yoffset;
172
51.2k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
124k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
72.9k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
72.9k
    if (cinfo->restart_interval) {
180
626
      if (diff->restart_rows_to_go == 0)
181
1
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
626
    }
184
185
72.9k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
72.9k
    MCU_count =
188
72.9k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
72.9k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
72.9k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
72.9k
    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
72.9k
    if (cinfo->restart_interval)
200
608
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
72.9k
    diff->MCU_ctr = 0;
204
72.9k
  }
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
111k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
59.8k
    compptr = cinfo->cur_comp_info[ci];
213
59.8k
    compi = compptr->component_index;
214
59.8k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
149k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
146k
                compptr->last_row_height : compptr->v_samp_factor);
217
89.6k
         prev_row = row, row++) {
218
89.6k
      (*losslessd->predict_undifference[compi])
219
89.6k
        (cinfo, compi, diff->diff_buf[compi][row],
220
89.6k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
89.6k
          compptr->width_in_blocks);
222
89.6k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
89.6k
                                  output_buf[compi][row],
224
89.6k
                                  compptr->width_in_blocks);
225
89.6k
    }
226
59.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
51.2k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
48.7k
    start_iMCU_row(cinfo);
236
48.7k
    return JPEG_ROW_COMPLETED;
237
48.7k
  }
238
  /* Completed the scan */
239
2.51k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
2.51k
  return JPEG_SCAN_COMPLETED;
241
51.2k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
10.2k
{
165
10.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
10.2k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
10.2k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
10.2k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
10.2k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
10.2k
  int ci, compi, row, prev_row;
171
10.2k
  unsigned int yoffset;
172
10.2k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
23.7k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
13.5k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
13.5k
    if (cinfo->restart_interval) {
180
626
      if (diff->restart_rows_to_go == 0)
181
1
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
626
    }
184
185
13.5k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
13.5k
    MCU_count =
188
13.5k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
13.5k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
13.5k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
13.5k
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
13.5k
    if (cinfo->restart_interval)
200
608
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
13.5k
    diff->MCU_ctr = 0;
204
13.5k
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
29.9k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
19.6k
    compptr = cinfo->cur_comp_info[ci];
213
19.6k
    compi = compptr->component_index;
214
19.6k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
50.8k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
49.6k
                compptr->last_row_height : compptr->v_samp_factor);
217
31.1k
         prev_row = row, row++) {
218
31.1k
      (*losslessd->predict_undifference[compi])
219
31.1k
        (cinfo, compi, diff->diff_buf[compi][row],
220
31.1k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
31.1k
          compptr->width_in_blocks);
222
31.1k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
31.1k
                                  output_buf[compi][row],
224
31.1k
                                  compptr->width_in_blocks);
225
31.1k
    }
226
19.6k
  }
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
10.2k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
9.31k
    start_iMCU_row(cinfo);
236
9.31k
    return JPEG_ROW_COMPLETED;
237
9.31k
  }
238
  /* Completed the scan */
239
951
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
951
  return JPEG_SCAN_COMPLETED;
241
10.2k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
18.1k
{
165
18.1k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
18.1k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
18.1k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
18.1k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
18.1k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
18.1k
  int ci, compi, row, prev_row;
171
18.1k
  unsigned int yoffset;
172
18.1k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
47.9k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
29.8k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
29.8k
    if (cinfo->restart_interval) {
180
0
      if (diff->restart_rows_to_go == 0)
181
0
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
0
    }
184
185
29.8k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
29.8k
    MCU_count =
188
29.8k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
29.8k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
29.8k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
29.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
29.8k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
29.8k
    diff->MCU_ctr = 0;
204
29.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
35.8k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
17.7k
    compptr = cinfo->cur_comp_info[ci];
213
17.7k
    compi = compptr->component_index;
214
17.7k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
47.2k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
46.2k
                compptr->last_row_height : compptr->v_samp_factor);
217
29.4k
         prev_row = row, row++) {
218
29.4k
      (*losslessd->predict_undifference[compi])
219
29.4k
        (cinfo, compi, diff->diff_buf[compi][row],
220
29.4k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
29.4k
          compptr->width_in_blocks);
222
29.4k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
29.4k
                                  output_buf[compi][row],
224
29.4k
                                  compptr->width_in_blocks);
225
29.4k
    }
226
17.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
18.1k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
17.3k
    start_iMCU_row(cinfo);
236
17.3k
    return JPEG_ROW_COMPLETED;
237
17.3k
  }
238
  /* Completed the scan */
239
730
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
730
  return JPEG_SCAN_COMPLETED;
241
18.1k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
22.8k
{
165
22.8k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
22.8k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
22.8k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
22.8k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
22.8k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
22.8k
  int ci, compi, row, prev_row;
171
22.8k
  unsigned int yoffset;
172
22.8k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
52.3k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
29.5k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
29.5k
    if (cinfo->restart_interval) {
180
0
      if (diff->restart_rows_to_go == 0)
181
0
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
0
    }
184
185
29.5k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
29.5k
    MCU_count =
188
29.5k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
29.5k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
29.5k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
29.5k
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
29.5k
    if (cinfo->restart_interval)
200
0
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
29.5k
    diff->MCU_ctr = 0;
204
29.5k
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
45.2k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
22.3k
    compptr = cinfo->cur_comp_info[ci];
213
22.3k
    compi = compptr->component_index;
214
22.3k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
51.4k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
50.5k
                compptr->last_row_height : compptr->v_samp_factor);
217
29.0k
         prev_row = row, row++) {
218
29.0k
      (*losslessd->predict_undifference[compi])
219
29.0k
        (cinfo, compi, diff->diff_buf[compi][row],
220
29.0k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
29.0k
          compptr->width_in_blocks);
222
29.0k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
29.0k
                                  output_buf[compi][row],
224
29.0k
                                  compptr->width_in_blocks);
225
29.0k
    }
226
22.3k
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
22.8k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
22.0k
    start_iMCU_row(cinfo);
236
22.0k
    return JPEG_ROW_COMPLETED;
237
22.0k
  }
238
  /* Completed the scan */
239
836
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
836
  return JPEG_SCAN_COMPLETED;
241
22.8k
}
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
43.9k
{
267
43.9k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
43.9k
  int ci, compi;
269
43.9k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
43.9k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
87.9k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
43.9k
    compptr = cinfo->cur_comp_info[ci];
275
43.9k
    compi = compptr->component_index;
276
43.9k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
43.9k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
43.9k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
43.9k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
43.9k
  }
281
282
43.9k
  return decompress_data(cinfo, buffer);
283
43.9k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
3.02k
{
267
3.02k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
3.02k
  int ci, compi;
269
3.02k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
3.02k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
6.05k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
3.02k
    compptr = cinfo->cur_comp_info[ci];
275
3.02k
    compi = compptr->component_index;
276
3.02k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
3.02k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
3.02k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
3.02k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
3.02k
  }
281
282
3.02k
  return decompress_data(cinfo, buffer);
283
3.02k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
18.1k
{
267
18.1k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
18.1k
  int ci, compi;
269
18.1k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
18.1k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
36.2k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
18.1k
    compptr = cinfo->cur_comp_info[ci];
275
18.1k
    compi = compptr->component_index;
276
18.1k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
18.1k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
18.1k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
18.1k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
18.1k
  }
281
282
18.1k
  return decompress_data(cinfo, buffer);
283
18.1k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
22.8k
{
267
22.8k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
22.8k
  int ci, compi;
269
22.8k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
22.8k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
45.7k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
22.8k
    compptr = cinfo->cur_comp_info[ci];
275
22.8k
    compi = compptr->component_index;
276
22.8k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
22.8k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
22.8k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
22.8k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
22.8k
  }
281
282
22.8k
  return decompress_data(cinfo, buffer);
283
22.8k
}
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
1
{
297
1
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
1
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
1
  int ci, samp_rows, row;
300
1
  _JSAMPARRAY buffer;
301
1
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
1
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
1
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
1
          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
3
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
2
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
2
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
2
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
2
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
2
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
2
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1
      samp_rows = compptr->v_samp_factor;
322
1
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1
    }
327
328
3
    for (row = 0; row < samp_rows; row++) {
329
1
      memcpy(output_buf[ci][row], buffer[row],
330
1
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1
    }
332
2
  }
333
334
1
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
1
  return JPEG_SCAN_COMPLETED;
337
1
}
jddiffct-8.c:output_data
Line
Count
Source
296
1
{
297
1
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
1
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
1
  int ci, samp_rows, row;
300
1
  _JSAMPARRAY buffer;
301
1
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
1
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
1
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
1
          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
3
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
2
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
2
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
2
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
2
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
2
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
2
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1
      samp_rows = compptr->v_samp_factor;
322
1
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1
    }
327
328
3
    for (row = 0; row < samp_rows; row++) {
329
1
      memcpy(output_buf[ci][row], buffer[row],
330
1
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1
    }
332
2
  }
333
334
1
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
1
  return JPEG_SCAN_COMPLETED;
337
1
}
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.60k
{
349
1.60k
  my_diff_ptr diff;
350
1.60k
  int ci;
351
1.60k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
561
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
1.04k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.04k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.60k
  diff = (my_diff_ptr)
362
1.60k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.60k
                                sizeof(my_diff_controller));
364
1.60k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.60k
  diff->pub.start_input_pass = start_input_pass;
366
1.60k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
6.34k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.74k
       ci++, compptr++) {
371
4.74k
    diff->diff_buf[ci] =
372
4.74k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.74k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.74k
                                         (long)compptr->h_samp_factor),
375
4.74k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.74k
    diff->undiff_buf[ci] =
377
4.74k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.74k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.74k
                                         (long)compptr->h_samp_factor),
380
4.74k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.74k
  }
382
383
1.60k
  if (need_full_buffer) {
384
1.08k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.08k
    int access_rows;
387
388
4.32k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.24k
         ci++, compptr++) {
390
3.24k
      access_rows = compptr->v_samp_factor;
391
3.24k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.24k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.24k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.24k
                               (long)compptr->h_samp_factor),
395
3.24k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.24k
                               (long)compptr->v_samp_factor),
397
3.24k
         (JDIMENSION)access_rows);
398
3.24k
    }
399
1.08k
    diff->pub.consume_data = consume_data;
400
1.08k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.08k
  } else {
405
519
    diff->pub.consume_data = dummy_consume_data;
406
519
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
519
  }
409
1.60k
}
jinit_d_diff_controller
Line
Count
Source
348
561
{
349
561
  my_diff_ptr diff;
350
561
  int ci;
351
561
  jpeg_component_info *compptr;
352
353
561
#if BITS_IN_JSAMPLE == 8
354
561
  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
561
  diff = (my_diff_ptr)
362
561
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
561
                                sizeof(my_diff_controller));
364
561
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
561
  diff->pub.start_input_pass = start_input_pass;
366
561
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.19k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.63k
       ci++, compptr++) {
371
1.63k
    diff->diff_buf[ci] =
372
1.63k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.63k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.63k
                                         (long)compptr->h_samp_factor),
375
1.63k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.63k
    diff->undiff_buf[ci] =
377
1.63k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.63k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.63k
                                         (long)compptr->h_samp_factor),
380
1.63k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.63k
  }
382
383
561
  if (need_full_buffer) {
384
98
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
98
    int access_rows;
387
388
392
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
294
         ci++, compptr++) {
390
294
      access_rows = compptr->v_samp_factor;
391
294
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
294
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
294
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
294
                               (long)compptr->h_samp_factor),
395
294
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
294
                               (long)compptr->v_samp_factor),
397
294
         (JDIMENSION)access_rows);
398
294
    }
399
98
    diff->pub.consume_data = consume_data;
400
98
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
463
  } else {
405
463
    diff->pub.consume_data = dummy_consume_data;
406
463
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
463
  }
409
561
}
j12init_d_diff_controller
Line
Count
Source
348
451
{
349
451
  my_diff_ptr diff;
350
451
  int ci;
351
451
  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
451
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
451
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
451
  diff = (my_diff_ptr)
362
451
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
451
                                sizeof(my_diff_controller));
364
451
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
451
  diff->pub.start_input_pass = start_input_pass;
366
451
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.80k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.35k
       ci++, compptr++) {
371
1.35k
    diff->diff_buf[ci] =
372
1.35k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.35k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.35k
                                         (long)compptr->h_samp_factor),
375
1.35k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.35k
    diff->undiff_buf[ci] =
377
1.35k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.35k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.35k
                                         (long)compptr->h_samp_factor),
380
1.35k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.35k
  }
382
383
451
  if (need_full_buffer) {
384
415
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
415
    int access_rows;
387
388
1.66k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.24k
         ci++, compptr++) {
390
1.24k
      access_rows = compptr->v_samp_factor;
391
1.24k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.24k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.24k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.24k
                               (long)compptr->h_samp_factor),
395
1.24k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.24k
                               (long)compptr->v_samp_factor),
397
1.24k
         (JDIMENSION)access_rows);
398
1.24k
    }
399
415
    diff->pub.consume_data = consume_data;
400
415
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
415
  } else {
405
36
    diff->pub.consume_data = dummy_consume_data;
406
36
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
36
  }
409
451
}
j16init_d_diff_controller
Line
Count
Source
348
589
{
349
589
  my_diff_ptr diff;
350
589
  int ci;
351
589
  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
589
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
589
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
589
  diff = (my_diff_ptr)
362
589
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
589
                                sizeof(my_diff_controller));
364
589
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
589
  diff->pub.start_input_pass = start_input_pass;
366
589
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.35k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.76k
       ci++, compptr++) {
371
1.76k
    diff->diff_buf[ci] =
372
1.76k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.76k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.76k
                                         (long)compptr->h_samp_factor),
375
1.76k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.76k
    diff->undiff_buf[ci] =
377
1.76k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.76k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.76k
                                         (long)compptr->h_samp_factor),
380
1.76k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.76k
  }
382
383
589
  if (need_full_buffer) {
384
569
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
569
    int access_rows;
387
388
2.27k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.70k
         ci++, compptr++) {
390
1.70k
      access_rows = compptr->v_samp_factor;
391
1.70k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.70k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.70k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.70k
                               (long)compptr->h_samp_factor),
395
1.70k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.70k
                               (long)compptr->v_samp_factor),
397
1.70k
         (JDIMENSION)access_rows);
398
1.70k
    }
399
569
    diff->pub.consume_data = consume_data;
400
569
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
569
  } else {
405
20
    diff->pub.consume_data = dummy_consume_data;
406
20
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
20
  }
409
589
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */