Coverage Report

Created: 2026-02-26 06:40

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
853k
{
68
853k
  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
853k
  if (cinfo->comps_in_scan > 1) {
75
58.0k
    diff->MCU_rows_per_iMCU_row = 1;
76
795k
  } else {
77
795k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
777k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
17.6k
    else
80
17.6k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
795k
  }
82
83
853k
  diff->MCU_ctr = 0;
84
853k
  diff->MCU_vert_offset = 0;
85
853k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
250k
{
68
250k
  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
250k
  if (cinfo->comps_in_scan > 1) {
75
54.4k
    diff->MCU_rows_per_iMCU_row = 1;
76
195k
  } else {
77
195k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
190k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
5.23k
    else
80
5.23k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
195k
  }
82
83
250k
  diff->MCU_ctr = 0;
84
250k
  diff->MCU_vert_offset = 0;
85
250k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
271k
{
68
271k
  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
271k
  if (cinfo->comps_in_scan > 1) {
75
1.72k
    diff->MCU_rows_per_iMCU_row = 1;
76
269k
  } else {
77
269k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
262k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
6.75k
    else
80
6.75k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
269k
  }
82
83
271k
  diff->MCU_ctr = 0;
84
271k
  diff->MCU_vert_offset = 0;
85
271k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
331k
{
68
331k
  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
331k
  if (cinfo->comps_in_scan > 1) {
75
1.83k
    diff->MCU_rows_per_iMCU_row = 1;
76
330k
  } else {
77
330k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
324k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
5.63k
    else
80
5.63k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
330k
  }
82
83
331k
  diff->MCU_ctr = 0;
84
331k
  diff->MCU_vert_offset = 0;
85
331k
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
33.8k
{
95
33.8k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
33.8k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
33.8k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
84
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
33.8k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
33.8k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
33.8k
  cinfo->input_iMCU_row = 0;
115
33.8k
  start_iMCU_row(cinfo);
116
33.8k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
11.6k
{
95
11.6k
  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
11.6k
  (*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
11.6k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
27
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
11.6k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
11.6k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
11.6k
  cinfo->input_iMCU_row = 0;
115
11.6k
  start_iMCU_row(cinfo);
116
11.6k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
11.5k
{
95
11.5k
  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
11.5k
  (*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
11.5k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
21
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
11.5k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
11.5k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
11.5k
  cinfo->input_iMCU_row = 0;
115
11.5k
  start_iMCU_row(cinfo);
116
11.5k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
10.6k
{
95
10.6k
  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
10.6k
  (*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
10.6k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
36
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
10.6k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
10.6k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
10.6k
  cinfo->input_iMCU_row = 0;
115
10.6k
  start_iMCU_row(cinfo);
116
10.6k
}
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
158
{
127
158
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
158
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
158
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
158
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
158
  return TRUE;
138
158
}
jddiffct-8.c:process_restart
Line
Count
Source
126
46
{
127
46
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
46
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
46
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
46
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
46
  return TRUE;
138
46
}
jddiffct-12.c:process_restart
Line
Count
Source
126
54
{
127
54
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
54
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
54
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
54
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
54
  return TRUE;
138
54
}
jddiffct-16.c:process_restart
Line
Count
Source
126
58
{
127
58
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
58
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
58
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
58
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
58
  return TRUE;
138
58
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
4.50k
{
148
4.50k
  cinfo->output_iMCU_row = 0;
149
4.50k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
4.27k
{
148
4.27k
  cinfo->output_iMCU_row = 0;
149
4.27k
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
125
{
148
125
  cinfo->output_iMCU_row = 0;
149
125
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
106
{
148
106
  cinfo->output_iMCU_row = 0;
149
106
}
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
853k
{
165
853k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
853k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
853k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
853k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
853k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
853k
  int ci, compi, row, prev_row;
171
853k
  unsigned int yoffset;
172
853k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
2.08M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
1.23M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
1.23M
    if (cinfo->restart_interval) {
180
35.9k
      if (diff->restart_rows_to_go == 0)
181
158
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
35.9k
    }
184
185
1.23M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
1.23M
    MCU_count =
188
1.23M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
1.23M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
1.23M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
1.23M
    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
1.23M
    if (cinfo->restart_interval)
200
35.6k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
1.23M
    diff->MCU_ctr = 0;
204
1.23M
  }
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
1.80M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
955k
    compptr = cinfo->cur_comp_info[ci];
213
955k
    compi = compptr->component_index;
214
955k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
2.35M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
2.29M
                compptr->last_row_height : compptr->v_samp_factor);
217
1.40M
         prev_row = row, row++) {
218
1.40M
      (*losslessd->predict_undifference[compi])
219
1.40M
        (cinfo, compi, diff->diff_buf[compi][row],
220
1.40M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
1.40M
          compptr->width_in_blocks);
222
1.40M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
1.40M
                                  output_buf[compi][row],
224
1.40M
                                  compptr->width_in_blocks);
225
1.40M
    }
226
955k
  }
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
853k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
820k
    start_iMCU_row(cinfo);
236
820k
    return JPEG_ROW_COMPLETED;
237
820k
  }
238
  /* Completed the scan */
239
32.3k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
32.3k
  return JPEG_SCAN_COMPLETED;
241
853k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
250k
{
165
250k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
250k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
250k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
250k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
250k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
250k
  int ci, compi, row, prev_row;
171
250k
  unsigned int yoffset;
172
250k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
692k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
442k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
442k
    if (cinfo->restart_interval) {
180
2.88k
      if (diff->restart_rows_to_go == 0)
181
46
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
2.88k
    }
184
185
442k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
442k
    MCU_count =
188
442k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
442k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
442k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
442k
    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
442k
    if (cinfo->restart_interval)
200
2.76k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
442k
    diff->MCU_ctr = 0;
204
442k
  }
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
606k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
355k
    compptr = cinfo->cur_comp_info[ci];
213
355k
    compi = compptr->component_index;
214
355k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
963k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
945k
                compptr->last_row_height : compptr->v_samp_factor);
217
607k
         prev_row = row, row++) {
218
607k
      (*losslessd->predict_undifference[compi])
219
607k
        (cinfo, compi, diff->diff_buf[compi][row],
220
607k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
607k
          compptr->width_in_blocks);
222
607k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
607k
                                  output_buf[compi][row],
224
607k
                                  compptr->width_in_blocks);
225
607k
    }
226
355k
  }
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
250k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
239k
    start_iMCU_row(cinfo);
236
239k
    return JPEG_ROW_COMPLETED;
237
239k
  }
238
  /* Completed the scan */
239
11.2k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
11.2k
  return JPEG_SCAN_COMPLETED;
241
250k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
271k
{
165
271k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
271k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
271k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
271k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
271k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
271k
  int ci, compi, row, prev_row;
171
271k
  unsigned int yoffset;
172
271k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
628k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
357k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
357k
    if (cinfo->restart_interval) {
180
31.0k
      if (diff->restart_rows_to_go == 0)
181
54
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
31.0k
    }
184
185
357k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
357k
    MCU_count =
188
357k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
357k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
357k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
357k
    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
357k
    if (cinfo->restart_interval)
200
30.9k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
357k
    diff->MCU_ctr = 0;
204
357k
  }
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
540k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
269k
    compptr = cinfo->cur_comp_info[ci];
213
269k
    compi = compptr->component_index;
214
269k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
626k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
605k
                compptr->last_row_height : compptr->v_samp_factor);
217
356k
         prev_row = row, row++) {
218
356k
      (*losslessd->predict_undifference[compi])
219
356k
        (cinfo, compi, diff->diff_buf[compi][row],
220
356k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
356k
          compptr->width_in_blocks);
222
356k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
356k
                                  output_buf[compi][row],
224
356k
                                  compptr->width_in_blocks);
225
356k
    }
226
269k
  }
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
271k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
260k
    start_iMCU_row(cinfo);
236
260k
    return JPEG_ROW_COMPLETED;
237
260k
  }
238
  /* Completed the scan */
239
10.9k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
10.9k
  return JPEG_SCAN_COMPLETED;
241
271k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
331k
{
165
331k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
331k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
331k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
331k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
331k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
331k
  int ci, compi, row, prev_row;
171
331k
  unsigned int yoffset;
172
331k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
768k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
436k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
436k
    if (cinfo->restart_interval) {
180
2.01k
      if (diff->restart_rows_to_go == 0)
181
58
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
2.01k
    }
184
185
436k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
436k
    MCU_count =
188
436k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
436k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
436k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
436k
    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
436k
    if (cinfo->restart_interval)
200
1.89k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
436k
    diff->MCU_ctr = 0;
204
436k
  }
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
662k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
330k
    compptr = cinfo->cur_comp_info[ci];
213
330k
    compi = compptr->component_index;
214
330k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
766k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
746k
                compptr->last_row_height : compptr->v_samp_factor);
217
435k
         prev_row = row, row++) {
218
435k
      (*losslessd->predict_undifference[compi])
219
435k
        (cinfo, compi, diff->diff_buf[compi][row],
220
435k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
435k
          compptr->width_in_blocks);
222
435k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
435k
                                  output_buf[compi][row],
224
435k
                                  compptr->width_in_blocks);
225
435k
    }
226
330k
  }
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
331k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
321k
    start_iMCU_row(cinfo);
236
321k
    return JPEG_ROW_COMPLETED;
237
321k
  }
238
  /* Completed the scan */
239
10.1k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
10.1k
  return JPEG_SCAN_COMPLETED;
241
331k
}
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
775k
{
267
775k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
775k
  int ci, compi;
269
775k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
775k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
1.55M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
782k
    compptr = cinfo->cur_comp_info[ci];
275
782k
    compi = compptr->component_index;
276
782k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
782k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
782k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
782k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
782k
  }
281
282
775k
  return decompress_data(cinfo, buffer);
283
775k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
173k
{
267
173k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
173k
  int ci, compi;
269
173k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
173k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
348k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
175k
    compptr = cinfo->cur_comp_info[ci];
275
175k
    compi = compptr->component_index;
276
175k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
175k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
175k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
175k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
175k
  }
281
282
173k
  return decompress_data(cinfo, buffer);
283
173k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
271k
{
267
271k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
271k
  int ci, compi;
269
271k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
271k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
544k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
273k
    compptr = cinfo->cur_comp_info[ci];
275
273k
    compi = compptr->component_index;
276
273k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
273k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
273k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
273k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
273k
  }
281
282
271k
  return decompress_data(cinfo, buffer);
283
271k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
331k
{
267
331k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
331k
  int ci, compi;
269
331k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
331k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
665k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
334k
    compptr = cinfo->cur_comp_info[ci];
275
334k
    compi = compptr->component_index;
276
334k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
334k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
334k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
334k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
334k
  }
281
282
331k
  return decompress_data(cinfo, buffer);
283
331k
}
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.09k
{
297
1.09k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
1.09k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
1.09k
  int ci, samp_rows, row;
300
1.09k
  _JSAMPARRAY buffer;
301
1.09k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
1.09k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
1.09k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
1.09k
          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.61k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
2.52k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
2.52k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
2.52k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
2.52k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
2.52k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
2.52k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
2.22k
      samp_rows = compptr->v_samp_factor;
322
304
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
304
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
304
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
304
    }
327
328
6.10k
    for (row = 0; row < samp_rows; row++) {
329
3.57k
      memcpy(output_buf[ci][row], buffer[row],
330
3.57k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
3.57k
    }
332
2.52k
  }
333
334
1.09k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
912
    return JPEG_ROW_COMPLETED;
336
179
  return JPEG_SCAN_COMPLETED;
337
1.09k
}
jddiffct-8.c:output_data
Line
Count
Source
296
1.09k
{
297
1.09k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
1.09k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
1.09k
  int ci, samp_rows, row;
300
1.09k
  _JSAMPARRAY buffer;
301
1.09k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
1.09k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
1.09k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
1.09k
          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.61k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
2.52k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
2.52k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
2.52k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
2.52k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
2.52k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
2.52k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
2.22k
      samp_rows = compptr->v_samp_factor;
322
304
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
304
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
304
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
304
    }
327
328
6.10k
    for (row = 0; row < samp_rows; row++) {
329
3.57k
      memcpy(output_buf[ci][row], buffer[row],
330
3.57k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
3.57k
    }
332
2.52k
  }
333
334
1.09k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
912
    return JPEG_ROW_COMPLETED;
336
179
  return JPEG_SCAN_COMPLETED;
337
1.09k
}
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
16.5k
{
349
16.5k
  my_diff_ptr diff;
350
16.5k
  int ci;
351
16.5k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
6.63k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
9.88k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
9.88k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
16.5k
  diff = (my_diff_ptr)
362
16.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
16.5k
                                sizeof(my_diff_controller));
364
16.5k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
16.5k
  diff->pub.start_input_pass = start_input_pass;
366
16.5k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
62.4k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
45.8k
       ci++, compptr++) {
371
45.8k
    diff->diff_buf[ci] =
372
45.8k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
45.8k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
45.8k
                                         (long)compptr->h_samp_factor),
375
45.8k
                   (JDIMENSION)compptr->v_samp_factor);
376
45.8k
    diff->undiff_buf[ci] =
377
45.8k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
45.8k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
45.8k
                                         (long)compptr->h_samp_factor),
380
45.8k
                   (JDIMENSION)compptr->v_samp_factor);
381
45.8k
  }
382
383
16.5k
  if (need_full_buffer) {
384
11.2k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
11.2k
    int access_rows;
387
388
43.8k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
32.6k
         ci++, compptr++) {
390
32.6k
      access_rows = compptr->v_samp_factor;
391
32.6k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
32.6k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
32.6k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
32.6k
                               (long)compptr->h_samp_factor),
395
32.6k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
32.6k
                               (long)compptr->v_samp_factor),
397
32.6k
         (JDIMENSION)access_rows);
398
32.6k
    }
399
11.2k
    diff->pub.consume_data = consume_data;
400
11.2k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
11.2k
  } else {
405
5.24k
    diff->pub.consume_data = dummy_consume_data;
406
5.24k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
5.24k
  }
409
16.5k
}
jinit_d_diff_controller
Line
Count
Source
348
6.63k
{
349
6.63k
  my_diff_ptr diff;
350
6.63k
  int ci;
351
6.63k
  jpeg_component_info *compptr;
352
353
6.63k
#if BITS_IN_JSAMPLE == 8
354
6.63k
  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
6.63k
  diff = (my_diff_ptr)
362
6.63k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
6.63k
                                sizeof(my_diff_controller));
364
6.63k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
6.63k
  diff->pub.start_input_pass = start_input_pass;
366
6.63k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
24.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
17.6k
       ci++, compptr++) {
371
17.6k
    diff->diff_buf[ci] =
372
17.6k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
17.6k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
17.6k
                                         (long)compptr->h_samp_factor),
375
17.6k
                   (JDIMENSION)compptr->v_samp_factor);
376
17.6k
    diff->undiff_buf[ci] =
377
17.6k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
17.6k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
17.6k
                                         (long)compptr->h_samp_factor),
380
17.6k
                   (JDIMENSION)compptr->v_samp_factor);
381
17.6k
  }
382
383
6.63k
  if (need_full_buffer) {
384
2.02k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
2.02k
    int access_rows;
387
388
8.14k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
6.11k
         ci++, compptr++) {
390
6.11k
      access_rows = compptr->v_samp_factor;
391
6.11k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
6.11k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
6.11k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
6.11k
                               (long)compptr->h_samp_factor),
395
6.11k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
6.11k
                               (long)compptr->v_samp_factor),
397
6.11k
         (JDIMENSION)access_rows);
398
6.11k
    }
399
2.02k
    diff->pub.consume_data = consume_data;
400
2.02k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
4.61k
  } else {
405
4.61k
    diff->pub.consume_data = dummy_consume_data;
406
4.61k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
4.61k
  }
409
6.63k
}
j12init_d_diff_controller
Line
Count
Source
348
4.82k
{
349
4.82k
  my_diff_ptr diff;
350
4.82k
  int ci;
351
4.82k
  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
4.82k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
4.82k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
4.82k
  diff = (my_diff_ptr)
362
4.82k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
4.82k
                                sizeof(my_diff_controller));
364
4.82k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
4.82k
  diff->pub.start_input_pass = start_input_pass;
366
4.82k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
18.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
13.8k
       ci++, compptr++) {
371
13.8k
    diff->diff_buf[ci] =
372
13.8k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
13.8k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
13.8k
                                         (long)compptr->h_samp_factor),
375
13.8k
                   (JDIMENSION)compptr->v_samp_factor);
376
13.8k
    diff->undiff_buf[ci] =
377
13.8k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
13.8k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
13.8k
                                         (long)compptr->h_samp_factor),
380
13.8k
                   (JDIMENSION)compptr->v_samp_factor);
381
13.8k
  }
382
383
4.82k
  if (need_full_buffer) {
384
4.50k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
4.50k
    int access_rows;
387
388
17.4k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
12.9k
         ci++, compptr++) {
390
12.9k
      access_rows = compptr->v_samp_factor;
391
12.9k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
12.9k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
12.9k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
12.9k
                               (long)compptr->h_samp_factor),
395
12.9k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
12.9k
                               (long)compptr->v_samp_factor),
397
12.9k
         (JDIMENSION)access_rows);
398
12.9k
    }
399
4.50k
    diff->pub.consume_data = consume_data;
400
4.50k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
4.50k
  } else {
405
315
    diff->pub.consume_data = dummy_consume_data;
406
315
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
315
  }
409
4.82k
}
j16init_d_diff_controller
Line
Count
Source
348
5.06k
{
349
5.06k
  my_diff_ptr diff;
350
5.06k
  int ci;
351
5.06k
  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
5.06k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
5.06k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
5.06k
  diff = (my_diff_ptr)
362
5.06k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
5.06k
                                sizeof(my_diff_controller));
364
5.06k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
5.06k
  diff->pub.start_input_pass = start_input_pass;
366
5.06k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
19.5k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
14.4k
       ci++, compptr++) {
371
14.4k
    diff->diff_buf[ci] =
372
14.4k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
14.4k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
14.4k
                                         (long)compptr->h_samp_factor),
375
14.4k
                   (JDIMENSION)compptr->v_samp_factor);
376
14.4k
    diff->undiff_buf[ci] =
377
14.4k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
14.4k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
14.4k
                                         (long)compptr->h_samp_factor),
380
14.4k
                   (JDIMENSION)compptr->v_samp_factor);
381
14.4k
  }
382
383
5.06k
  if (need_full_buffer) {
384
4.73k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
4.73k
    int access_rows;
387
388
18.3k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
13.5k
         ci++, compptr++) {
390
13.5k
      access_rows = compptr->v_samp_factor;
391
13.5k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
13.5k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
13.5k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
13.5k
                               (long)compptr->h_samp_factor),
395
13.5k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
13.5k
                               (long)compptr->v_samp_factor),
397
13.5k
         (JDIMENSION)access_rows);
398
13.5k
    }
399
4.73k
    diff->pub.consume_data = consume_data;
400
4.73k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
4.73k
  } else {
405
323
    diff->pub.consume_data = dummy_consume_data;
406
323
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
323
  }
409
5.06k
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */