Coverage Report

Created: 2026-04-12 06:59

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
52.6k
{
68
52.6k
  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
52.6k
  if (cinfo->comps_in_scan > 1) {
75
3.74k
    diff->MCU_rows_per_iMCU_row = 1;
76
48.9k
  } else {
77
48.9k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
47.4k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.41k
    else
80
1.41k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
48.9k
  }
82
83
52.6k
  diff->MCU_ctr = 0;
84
52.6k
  diff->MCU_vert_offset = 0;
85
52.6k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
19.6k
{
68
19.6k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
19.6k
  if (cinfo->comps_in_scan > 1) {
75
2.93k
    diff->MCU_rows_per_iMCU_row = 1;
76
16.7k
  } else {
77
16.7k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
16.3k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
418
    else
80
418
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
16.7k
  }
82
83
19.6k
  diff->MCU_ctr = 0;
84
19.6k
  diff->MCU_vert_offset = 0;
85
19.6k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
17.0k
{
68
17.0k
  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
17.0k
  if (cinfo->comps_in_scan > 1) {
75
474
    diff->MCU_rows_per_iMCU_row = 1;
76
16.5k
  } else {
77
16.5k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
16.1k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
416
    else
80
416
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
16.5k
  }
82
83
17.0k
  diff->MCU_ctr = 0;
84
17.0k
  diff->MCU_vert_offset = 0;
85
17.0k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
15.9k
{
68
15.9k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
15.9k
  if (cinfo->comps_in_scan > 1) {
75
341
    diff->MCU_rows_per_iMCU_row = 1;
76
15.6k
  } else {
77
15.6k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
15.0k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
585
    else
80
585
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
15.6k
  }
82
83
15.9k
  diff->MCU_ctr = 0;
84
15.9k
  diff->MCU_vert_offset = 0;
85
15.9k
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
2.51k
{
95
2.51k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
2.51k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
2.51k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
3
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
2.51k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
2.51k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
2.51k
  cinfo->input_iMCU_row = 0;
115
2.51k
  start_iMCU_row(cinfo);
116
2.51k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
839
{
95
839
  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
839
  (*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
839
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
839
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
839
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
839
  cinfo->input_iMCU_row = 0;
115
839
  start_iMCU_row(cinfo);
116
839
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
759
{
95
759
  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
759
  (*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
759
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
759
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
759
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
759
  cinfo->input_iMCU_row = 0;
115
759
  start_iMCU_row(cinfo);
116
759
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
916
{
95
916
  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
916
  (*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
916
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
916
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
916
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
916
  cinfo->input_iMCU_row = 0;
115
916
  start_iMCU_row(cinfo);
116
916
}
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
7
{
127
7
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
7
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
7
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
7
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
7
  return TRUE;
138
7
}
jddiffct-8.c:process_restart
Line
Count
Source
126
3
{
127
3
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
3
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
3
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
3
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
3
  return TRUE;
138
3
}
jddiffct-12.c:process_restart
Line
Count
Source
126
2
{
127
2
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
2
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
2
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
2
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
2
  return TRUE;
138
2
}
jddiffct-16.c:process_restart
Line
Count
Source
126
2
{
127
2
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
2
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
2
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
2
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
2
  return TRUE;
138
2
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
179
{
148
179
  cinfo->output_iMCU_row = 0;
149
179
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
169
{
148
169
  cinfo->output_iMCU_row = 0;
149
169
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
6
{
148
6
  cinfo->output_iMCU_row = 0;
149
6
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
4
{
148
4
  cinfo->output_iMCU_row = 0;
149
4
}
150
151
152
/*
153
 * Decompress and return some data in the supplied buffer.
154
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
155
 * Input and output must run in lockstep since we have only a one-MCU buffer.
156
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
157
 *
158
 * NB: output_buf contains a plane for each component in image,
159
 * which we index according to the component's SOF position.
160
 */
161
162
METHODDEF(int)
163
decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
164
52.6k
{
165
52.6k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
52.6k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
52.6k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
52.6k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
52.6k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
52.6k
  int ci, compi, row, prev_row;
171
52.6k
  unsigned int yoffset;
172
52.6k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
116k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
63.8k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
63.8k
    if (cinfo->restart_interval) {
180
649
      if (diff->restart_rows_to_go == 0)
181
7
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
649
    }
184
185
63.8k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
63.8k
    MCU_count =
188
63.8k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
63.8k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
63.8k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
63.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
63.8k
    if (cinfo->restart_interval)
200
625
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
63.8k
    diff->MCU_ctr = 0;
204
63.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
112k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
59.9k
    compptr = cinfo->cur_comp_info[ci];
213
59.9k
    compi = compptr->component_index;
214
59.9k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
132k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
129k
                compptr->last_row_height : compptr->v_samp_factor);
217
72.9k
         prev_row = row, row++) {
218
72.9k
      (*losslessd->predict_undifference[compi])
219
72.9k
        (cinfo, compi, diff->diff_buf[compi][row],
220
72.9k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
72.9k
          compptr->width_in_blocks);
222
72.9k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
72.9k
                                  output_buf[compi][row],
224
72.9k
                                  compptr->width_in_blocks);
225
72.9k
    }
226
59.9k
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
52.6k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
50.2k
    start_iMCU_row(cinfo);
236
50.2k
    return JPEG_ROW_COMPLETED;
237
50.2k
  }
238
  /* Completed the scan */
239
2.41k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
2.41k
  return JPEG_SCAN_COMPLETED;
241
52.6k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
19.6k
{
165
19.6k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
19.6k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
19.6k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
19.6k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
19.6k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
19.6k
  int ci, compi, row, prev_row;
171
19.6k
  unsigned int yoffset;
172
19.6k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
42.5k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
22.9k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
22.9k
    if (cinfo->restart_interval) {
180
312
      if (diff->restart_rows_to_go == 0)
181
3
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
312
    }
184
185
22.9k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
22.9k
    MCU_count =
188
22.9k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
22.9k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
22.9k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
22.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
22.9k
    if (cinfo->restart_interval)
200
304
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
22.9k
    diff->MCU_ctr = 0;
204
22.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
45.7k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
26.0k
    compptr = cinfo->cur_comp_info[ci];
213
26.0k
    compi = compptr->component_index;
214
26.0k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
56.5k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
55.3k
                compptr->last_row_height : compptr->v_samp_factor);
217
30.4k
         prev_row = row, row++) {
218
30.4k
      (*losslessd->predict_undifference[compi])
219
30.4k
        (cinfo, compi, diff->diff_buf[compi][row],
220
30.4k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
30.4k
          compptr->width_in_blocks);
222
30.4k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
30.4k
                                  output_buf[compi][row],
224
30.4k
                                  compptr->width_in_blocks);
225
30.4k
    }
226
26.0k
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
19.6k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
18.8k
    start_iMCU_row(cinfo);
236
18.8k
    return JPEG_ROW_COMPLETED;
237
18.8k
  }
238
  /* Completed the scan */
239
803
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
803
  return JPEG_SCAN_COMPLETED;
241
19.6k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
17.0k
{
165
17.0k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
17.0k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
17.0k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
17.0k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
17.0k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
17.0k
  int ci, compi, row, prev_row;
171
17.0k
  unsigned int yoffset;
172
17.0k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
38.0k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
21.0k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
21.0k
    if (cinfo->restart_interval) {
180
90
      if (diff->restart_rows_to_go == 0)
181
2
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
90
    }
184
185
21.0k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
21.0k
    MCU_count =
188
21.0k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
21.0k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
21.0k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
21.0k
    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
21.0k
    if (cinfo->restart_interval)
200
82
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
21.0k
    diff->MCU_ctr = 0;
204
21.0k
  }
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
34.6k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
17.6k
    compptr = cinfo->cur_comp_info[ci];
213
17.6k
    compi = compptr->component_index;
214
17.6k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
39.6k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
38.5k
                compptr->last_row_height : compptr->v_samp_factor);
217
22.0k
         prev_row = row, row++) {
218
22.0k
      (*losslessd->predict_undifference[compi])
219
22.0k
        (cinfo, compi, diff->diff_buf[compi][row],
220
22.0k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
22.0k
          compptr->width_in_blocks);
222
22.0k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
22.0k
                                  output_buf[compi][row],
224
22.0k
                                  compptr->width_in_blocks);
225
22.0k
    }
226
17.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
17.0k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
16.2k
    start_iMCU_row(cinfo);
236
16.2k
    return JPEG_ROW_COMPLETED;
237
16.2k
  }
238
  /* Completed the scan */
239
720
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
720
  return JPEG_SCAN_COMPLETED;
241
17.0k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
15.9k
{
165
15.9k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
15.9k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
15.9k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
15.9k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
15.9k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
15.9k
  int ci, compi, row, prev_row;
171
15.9k
  unsigned int yoffset;
172
15.9k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
35.8k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
19.8k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
19.8k
    if (cinfo->restart_interval) {
180
247
      if (diff->restart_rows_to_go == 0)
181
2
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
247
    }
184
185
19.8k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
19.8k
    MCU_count =
188
19.8k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
19.8k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
19.8k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
19.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
19.8k
    if (cinfo->restart_interval)
200
239
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
19.8k
    diff->MCU_ctr = 0;
204
19.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
32.2k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
16.3k
    compptr = cinfo->cur_comp_info[ci];
213
16.3k
    compi = compptr->component_index;
214
16.3k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
36.8k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
35.1k
                compptr->last_row_height : compptr->v_samp_factor);
217
20.4k
         prev_row = row, row++) {
218
20.4k
      (*losslessd->predict_undifference[compi])
219
20.4k
        (cinfo, compi, diff->diff_buf[compi][row],
220
20.4k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
20.4k
          compptr->width_in_blocks);
222
20.4k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
20.4k
                                  output_buf[compi][row],
224
20.4k
                                  compptr->width_in_blocks);
225
20.4k
    }
226
16.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
15.9k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
15.0k
    start_iMCU_row(cinfo);
236
15.0k
    return JPEG_ROW_COMPLETED;
237
15.0k
  }
238
  /* Completed the scan */
239
887
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
887
  return JPEG_SCAN_COMPLETED;
241
15.9k
}
242
243
244
/*
245
 * Dummy consume-input routine for single-pass operation.
246
 */
247
248
METHODDEF(int)
249
dummy_consume_data(j_decompress_ptr cinfo)
250
0
{
251
0
  return JPEG_SUSPENDED;        /* Always indicate nothing was done */
252
0
}
Unexecuted instantiation: jddiffct-8.c:dummy_consume_data
Unexecuted instantiation: jddiffct-12.c:dummy_consume_data
Unexecuted instantiation: jddiffct-16.c:dummy_consume_data
253
254
255
#ifdef D_MULTISCAN_FILES_SUPPORTED
256
257
/*
258
 * Consume input data and store it in the full-image sample buffer.
259
 * We read as much as one fully interleaved MCU row ("iMCU" row) per call,
260
 * ie, v_samp_factor rows for each component in the scan.
261
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
262
 */
263
264
METHODDEF(int)
265
consume_data(j_decompress_ptr cinfo)
266
50.1k
{
267
50.1k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
50.1k
  int ci, compi;
269
50.1k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
50.1k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
102k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
52.7k
    compptr = cinfo->cur_comp_info[ci];
275
52.7k
    compi = compptr->component_index;
276
52.7k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
52.7k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
52.7k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
52.7k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
52.7k
  }
281
282
50.1k
  return decompress_data(cinfo, buffer);
283
50.1k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
17.2k
{
267
17.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
17.2k
  int ci, compi;
269
17.2k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
17.2k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
35.3k
  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
17.2k
  return decompress_data(cinfo, buffer);
283
17.2k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
17.0k
{
267
17.0k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
17.0k
  int ci, compi;
269
17.0k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
17.0k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
34.9k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
17.9k
    compptr = cinfo->cur_comp_info[ci];
275
17.9k
    compi = compptr->component_index;
276
17.9k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
17.9k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
17.9k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
17.9k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
17.9k
  }
281
282
17.0k
  return decompress_data(cinfo, buffer);
283
17.0k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
15.9k
{
267
15.9k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
15.9k
  int ci, compi;
269
15.9k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
15.9k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
32.6k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
16.6k
    compptr = cinfo->cur_comp_info[ci];
275
16.6k
    compi = compptr->component_index;
276
16.6k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
16.6k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
16.6k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
16.6k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
16.6k
  }
281
282
15.9k
  return decompress_data(cinfo, buffer);
283
15.9k
}
284
285
286
/*
287
 * Output some data from the full-image sample buffer in the multi-pass case.
288
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
289
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
290
 *
291
 * NB: output_buf contains a plane for each component in image.
292
 */
293
294
METHODDEF(int)
295
output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
296
4
{
297
4
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
4
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
4
  int ci, samp_rows, row;
300
4
  _JSAMPARRAY buffer;
301
4
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
4
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
4
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
4
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
0
  }
310
311
  /* OK, output from the virtual arrays. */
312
12
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
8
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
8
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
8
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
8
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
8
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
8
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1
      samp_rows = compptr->v_samp_factor;
322
7
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
7
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
7
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
7
    }
327
328
18
    for (row = 0; row < samp_rows; row++) {
329
10
      memcpy(output_buf[ci][row], buffer[row],
330
10
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
10
    }
332
8
  }
333
334
4
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
4
  return JPEG_SCAN_COMPLETED;
337
4
}
jddiffct-8.c:output_data
Line
Count
Source
296
4
{
297
4
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
4
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
4
  int ci, samp_rows, row;
300
4
  _JSAMPARRAY buffer;
301
4
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
4
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
4
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
4
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
0
  }
310
311
  /* OK, output from the virtual arrays. */
312
12
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
8
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
8
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
8
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
8
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
8
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
8
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1
      samp_rows = compptr->v_samp_factor;
322
7
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
7
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
7
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
7
    }
327
328
18
    for (row = 0; row < samp_rows; row++) {
329
10
      memcpy(output_buf[ci][row], buffer[row],
330
10
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
10
    }
332
8
  }
333
334
4
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
4
  return JPEG_SCAN_COMPLETED;
337
4
}
Unexecuted instantiation: jddiffct-12.c:output_data
Unexecuted instantiation: jddiffct-16.c:output_data
338
339
#endif /* D_MULTISCAN_FILES_SUPPORTED */
340
341
342
/*
343
 * Initialize difference buffer controller.
344
 */
345
346
GLOBAL(void)
347
_jinit_d_diff_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
348
1.27k
{
349
1.27k
  my_diff_ptr diff;
350
1.27k
  int ci;
351
1.27k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
477
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
802
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
802
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.27k
  diff = (my_diff_ptr)
362
1.27k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.27k
                                sizeof(my_diff_controller));
364
1.27k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.27k
  diff->pub.start_input_pass = start_input_pass;
366
1.27k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
5.25k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
3.97k
       ci++, compptr++) {
371
3.97k
    diff->diff_buf[ci] =
372
3.97k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
3.97k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
3.97k
                                         (long)compptr->h_samp_factor),
375
3.97k
                   (JDIMENSION)compptr->v_samp_factor);
376
3.97k
    diff->undiff_buf[ci] =
377
3.97k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
3.97k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
3.97k
                                         (long)compptr->h_samp_factor),
380
3.97k
                   (JDIMENSION)compptr->v_samp_factor);
381
3.97k
  }
382
383
1.27k
  if (need_full_buffer) {
384
1.04k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.04k
    int access_rows;
387
388
4.20k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.16k
         ci++, compptr++) {
390
3.16k
      access_rows = compptr->v_samp_factor;
391
3.16k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.16k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.16k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.16k
                               (long)compptr->h_samp_factor),
395
3.16k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.16k
                               (long)compptr->v_samp_factor),
397
3.16k
         (JDIMENSION)access_rows);
398
3.16k
    }
399
1.04k
    diff->pub.consume_data = consume_data;
400
1.04k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.04k
  } else {
405
233
    diff->pub.consume_data = dummy_consume_data;
406
233
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
233
  }
409
1.27k
}
jinit_d_diff_controller
Line
Count
Source
348
477
{
349
477
  my_diff_ptr diff;
350
477
  int ci;
351
477
  jpeg_component_info *compptr;
352
353
477
#if BITS_IN_JSAMPLE == 8
354
477
  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
477
  diff = (my_diff_ptr)
362
477
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
477
                                sizeof(my_diff_controller));
364
477
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
477
  diff->pub.start_input_pass = start_input_pass;
366
477
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.01k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.53k
       ci++, compptr++) {
371
1.53k
    diff->diff_buf[ci] =
372
1.53k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.53k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.53k
                                         (long)compptr->h_samp_factor),
375
1.53k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.53k
    diff->undiff_buf[ci] =
377
1.53k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.53k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.53k
                                         (long)compptr->h_samp_factor),
380
1.53k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.53k
  }
382
383
477
  if (need_full_buffer) {
384
277
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
277
    int access_rows;
387
388
1.11k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
839
         ci++, compptr++) {
390
839
      access_rows = compptr->v_samp_factor;
391
839
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
839
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
839
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
839
                               (long)compptr->h_samp_factor),
395
839
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
839
                               (long)compptr->v_samp_factor),
397
839
         (JDIMENSION)access_rows);
398
839
    }
399
277
    diff->pub.consume_data = consume_data;
400
277
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
277
  } else {
405
200
    diff->pub.consume_data = dummy_consume_data;
406
200
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
200
  }
409
477
}
j12init_d_diff_controller
Line
Count
Source
348
394
{
349
394
  my_diff_ptr diff;
350
394
  int ci;
351
394
  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
394
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
394
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
394
  diff = (my_diff_ptr)
362
394
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
394
                                sizeof(my_diff_controller));
364
394
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
394
  diff->pub.start_input_pass = start_input_pass;
366
394
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.59k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.20k
       ci++, compptr++) {
371
1.20k
    diff->diff_buf[ci] =
372
1.20k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.20k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.20k
                                         (long)compptr->h_samp_factor),
375
1.20k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.20k
    diff->undiff_buf[ci] =
377
1.20k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.20k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.20k
                                         (long)compptr->h_samp_factor),
380
1.20k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.20k
  }
382
383
394
  if (need_full_buffer) {
384
378
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
378
    int access_rows;
387
388
1.52k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.14k
         ci++, compptr++) {
390
1.14k
      access_rows = compptr->v_samp_factor;
391
1.14k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.14k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.14k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.14k
                               (long)compptr->h_samp_factor),
395
1.14k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.14k
                               (long)compptr->v_samp_factor),
397
1.14k
         (JDIMENSION)access_rows);
398
1.14k
    }
399
378
    diff->pub.consume_data = consume_data;
400
378
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
378
  } else {
405
16
    diff->pub.consume_data = dummy_consume_data;
406
16
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
16
  }
409
394
}
j16init_d_diff_controller
Line
Count
Source
348
408
{
349
408
  my_diff_ptr diff;
350
408
  int ci;
351
408
  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
408
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
408
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
408
  diff = (my_diff_ptr)
362
408
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
408
                                sizeof(my_diff_controller));
364
408
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
408
  diff->pub.start_input_pass = start_input_pass;
366
408
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.64k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.23k
       ci++, compptr++) {
371
1.23k
    diff->diff_buf[ci] =
372
1.23k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.23k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.23k
                                         (long)compptr->h_samp_factor),
375
1.23k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.23k
    diff->undiff_buf[ci] =
377
1.23k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.23k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.23k
                                         (long)compptr->h_samp_factor),
380
1.23k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.23k
  }
382
383
408
  if (need_full_buffer) {
384
391
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
391
    int access_rows;
387
388
1.57k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.17k
         ci++, compptr++) {
390
1.17k
      access_rows = compptr->v_samp_factor;
391
1.17k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.17k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.17k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.17k
                               (long)compptr->h_samp_factor),
395
1.17k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.17k
                               (long)compptr->v_samp_factor),
397
1.17k
         (JDIMENSION)access_rows);
398
1.17k
    }
399
391
    diff->pub.consume_data = consume_data;
400
391
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
391
  } else {
405
17
    diff->pub.consume_data = dummy_consume_data;
406
17
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
17
  }
409
408
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */