Coverage Report

Created: 2026-01-25 06:25

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
125k
{
68
125k
  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
125k
  if (cinfo->comps_in_scan > 1) {
75
3.96k
    diff->MCU_rows_per_iMCU_row = 1;
76
121k
  } else {
77
121k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
119k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.47k
    else
80
1.47k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
121k
  }
82
83
125k
  diff->MCU_ctr = 0;
84
125k
  diff->MCU_vert_offset = 0;
85
125k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
21.5k
{
68
21.5k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
21.5k
  if (cinfo->comps_in_scan > 1) {
75
2.71k
    diff->MCU_rows_per_iMCU_row = 1;
76
18.8k
  } else {
77
18.8k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
18.3k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
461
    else
80
461
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
18.8k
  }
82
83
21.5k
  diff->MCU_ctr = 0;
84
21.5k
  diff->MCU_vert_offset = 0;
85
21.5k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
75.4k
{
68
75.4k
  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
75.4k
  if (cinfo->comps_in_scan > 1) {
75
647
    diff->MCU_rows_per_iMCU_row = 1;
76
74.7k
  } else {
77
74.7k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
74.2k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
561
    else
80
561
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
74.7k
  }
82
83
75.4k
  diff->MCU_ctr = 0;
84
75.4k
  diff->MCU_vert_offset = 0;
85
75.4k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
28.2k
{
68
28.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
28.2k
  if (cinfo->comps_in_scan > 1) {
75
602
    diff->MCU_rows_per_iMCU_row = 1;
76
27.6k
  } else {
77
27.6k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
27.2k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
453
    else
80
453
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
27.6k
  }
82
83
28.2k
  diff->MCU_ctr = 0;
84
28.2k
  diff->MCU_vert_offset = 0;
85
28.2k
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
4.73k
{
95
4.73k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
4.73k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
4.73k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
32
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
4.73k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
4.73k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
4.73k
  cinfo->input_iMCU_row = 0;
115
4.73k
  start_iMCU_row(cinfo);
116
4.73k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
1.68k
{
95
1.68k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
1.68k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
1.68k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
6
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.68k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.68k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.68k
  cinfo->input_iMCU_row = 0;
115
1.68k
  start_iMCU_row(cinfo);
116
1.68k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
1.55k
{
95
1.55k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
1.55k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
1.55k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
9
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.55k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.55k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.55k
  cinfo->input_iMCU_row = 0;
115
1.55k
  start_iMCU_row(cinfo);
116
1.55k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
1.50k
{
95
1.50k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
1.50k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
1.50k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
17
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.50k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.50k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.50k
  cinfo->input_iMCU_row = 0;
115
1.50k
  start_iMCU_row(cinfo);
116
1.50k
}
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
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-8.c:process_restart
Line
Count
Source
126
19
{
127
19
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
19
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
19
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
19
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
19
  return TRUE;
138
19
}
jddiffct-12.c:process_restart
Line
Count
Source
126
15
{
127
15
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
15
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
15
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
15
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
15
  return TRUE;
138
15
}
jddiffct-16.c:process_restart
Line
Count
Source
126
20
{
127
20
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
20
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
20
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
20
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
20
  return TRUE;
138
20
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
840
{
148
840
  cinfo->output_iMCU_row = 0;
149
840
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
797
{
148
797
  cinfo->output_iMCU_row = 0;
149
797
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
23
{
148
23
  cinfo->output_iMCU_row = 0;
149
23
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
20
{
148
20
  cinfo->output_iMCU_row = 0;
149
20
}
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
125k
{
165
125k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
125k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
125k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
125k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
125k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
125k
  int ci, compi, row, prev_row;
171
125k
  unsigned int yoffset;
172
125k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
311k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
186k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
186k
    if (cinfo->restart_interval) {
180
66.6k
      if (diff->restart_rows_to_go == 0)
181
54
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
66.6k
    }
184
185
186k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
186k
    MCU_count =
188
186k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
186k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
186k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
186k
    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
186k
    if (cinfo->restart_interval)
200
66.5k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
186k
    diff->MCU_ctr = 0;
204
186k
  }
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
253k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
128k
    compptr = cinfo->cur_comp_info[ci];
213
128k
    compi = compptr->component_index;
214
128k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
322k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
314k
                compptr->last_row_height : compptr->v_samp_factor);
217
194k
         prev_row = row, row++) {
218
194k
      (*losslessd->predict_undifference[compi])
219
194k
        (cinfo, compi, diff->diff_buf[compi][row],
220
194k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
194k
          compptr->width_in_blocks);
222
194k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
194k
                                  output_buf[compi][row],
224
194k
                                  compptr->width_in_blocks);
225
194k
    }
226
128k
  }
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
125k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
120k
    start_iMCU_row(cinfo);
236
120k
    return JPEG_ROW_COMPLETED;
237
120k
  }
238
  /* Completed the scan */
239
4.55k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
4.55k
  return JPEG_SCAN_COMPLETED;
241
125k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
21.5k
{
165
21.5k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
21.5k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
21.5k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
21.5k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
21.5k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
21.5k
  int ci, compi, row, prev_row;
171
21.5k
  unsigned int yoffset;
172
21.5k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
51.7k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
30.1k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
30.1k
    if (cinfo->restart_interval) {
180
250
      if (diff->restart_rows_to_go == 0)
181
19
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
250
    }
184
185
30.1k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
30.1k
    MCU_count =
188
30.1k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
30.1k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
30.1k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
30.1k
    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
30.1k
    if (cinfo->restart_interval)
200
222
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
30.1k
    diff->MCU_ctr = 0;
204
30.1k
  }
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.9k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
24.3k
    compptr = cinfo->cur_comp_info[ci];
213
24.3k
    compi = compptr->component_index;
214
24.3k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
62.1k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
59.8k
                compptr->last_row_height : compptr->v_samp_factor);
217
37.7k
         prev_row = row, row++) {
218
37.7k
      (*losslessd->predict_undifference[compi])
219
37.7k
        (cinfo, compi, diff->diff_buf[compi][row],
220
37.7k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
37.7k
          compptr->width_in_blocks);
222
37.7k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
37.7k
                                  output_buf[compi][row],
224
37.7k
                                  compptr->width_in_blocks);
225
37.7k
    }
226
24.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
21.5k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
19.9k
    start_iMCU_row(cinfo);
236
19.9k
    return JPEG_ROW_COMPLETED;
237
19.9k
  }
238
  /* Completed the scan */
239
1.62k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.62k
  return JPEG_SCAN_COMPLETED;
241
21.5k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
75.4k
{
165
75.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
75.4k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
75.4k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
75.4k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
75.4k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
75.4k
  int ci, compi, row, prev_row;
171
75.4k
  unsigned int yoffset;
172
75.4k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
157k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
82.3k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
82.3k
    if (cinfo->restart_interval) {
180
61.9k
      if (diff->restart_rows_to_go == 0)
181
15
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
61.9k
    }
184
185
82.3k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
82.3k
    MCU_count =
188
82.3k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
82.3k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
82.3k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
82.3k
    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
82.3k
    if (cinfo->restart_interval)
200
61.8k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
82.3k
    diff->MCU_ctr = 0;
204
82.3k
  }
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
150k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
75.4k
    compptr = cinfo->cur_comp_info[ci];
213
75.4k
    compi = compptr->component_index;
214
75.4k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
158k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
155k
                compptr->last_row_height : compptr->v_samp_factor);
217
83.1k
         prev_row = row, row++) {
218
83.1k
      (*losslessd->predict_undifference[compi])
219
83.1k
        (cinfo, compi, diff->diff_buf[compi][row],
220
83.1k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
83.1k
          compptr->width_in_blocks);
222
83.1k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
83.1k
                                  output_buf[compi][row],
224
83.1k
                                  compptr->width_in_blocks);
225
83.1k
    }
226
75.4k
  }
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
75.4k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
73.9k
    start_iMCU_row(cinfo);
236
73.9k
    return JPEG_ROW_COMPLETED;
237
73.9k
  }
238
  /* Completed the scan */
239
1.49k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.49k
  return JPEG_SCAN_COMPLETED;
241
75.4k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
28.2k
{
165
28.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
28.2k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
28.2k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
28.2k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
28.2k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
28.2k
  int ci, compi, row, prev_row;
171
28.2k
  unsigned int yoffset;
172
28.2k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
101k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
73.5k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
73.5k
    if (cinfo->restart_interval) {
180
4.47k
      if (diff->restart_rows_to_go == 0)
181
20
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
4.47k
    }
184
185
73.5k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
73.5k
    MCU_count =
188
73.5k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
73.5k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
73.5k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
73.5k
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
73.5k
    if (cinfo->restart_interval)
200
4.44k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
73.5k
    diff->MCU_ctr = 0;
204
73.5k
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
56.4k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
28.2k
    compptr = cinfo->cur_comp_info[ci];
213
28.2k
    compi = compptr->component_index;
214
28.2k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
102k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
99.1k
                compptr->last_row_height : compptr->v_samp_factor);
217
74.0k
         prev_row = row, row++) {
218
74.0k
      (*losslessd->predict_undifference[compi])
219
74.0k
        (cinfo, compi, diff->diff_buf[compi][row],
220
74.0k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
74.0k
          compptr->width_in_blocks);
222
74.0k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
74.0k
                                  output_buf[compi][row],
224
74.0k
                                  compptr->width_in_blocks);
225
74.0k
    }
226
28.2k
  }
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
28.2k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
26.8k
    start_iMCU_row(cinfo);
236
26.8k
    return JPEG_ROW_COMPLETED;
237
26.8k
  }
238
  /* Completed the scan */
239
1.43k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.43k
  return JPEG_SCAN_COMPLETED;
241
28.2k
}
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
115k
{
267
115k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
115k
  int ci, compi;
269
115k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
115k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
233k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
117k
    compptr = cinfo->cur_comp_info[ci];
275
117k
    compi = compptr->component_index;
276
117k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
117k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
117k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
117k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
117k
  }
281
282
115k
  return decompress_data(cinfo, buffer);
283
115k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
12.2k
{
267
12.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
12.2k
  int ci, compi;
269
12.2k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
12.2k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
24.9k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
12.7k
    compptr = cinfo->cur_comp_info[ci];
275
12.7k
    compi = compptr->component_index;
276
12.7k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
12.7k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
12.7k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
12.7k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
12.7k
  }
281
282
12.2k
  return decompress_data(cinfo, buffer);
283
12.2k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
75.4k
{
267
75.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
75.4k
  int ci, compi;
269
75.4k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
75.4k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
151k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
76.0k
    compptr = cinfo->cur_comp_info[ci];
275
76.0k
    compi = compptr->component_index;
276
76.0k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
76.0k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
76.0k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
76.0k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
76.0k
  }
281
282
75.4k
  return decompress_data(cinfo, buffer);
283
75.4k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
28.2k
{
267
28.2k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
28.2k
  int ci, compi;
269
28.2k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
28.2k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
57.1k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
28.8k
    compptr = cinfo->cur_comp_info[ci];
275
28.8k
    compi = compptr->component_index;
276
28.8k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
28.8k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
28.8k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
28.8k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
28.8k
  }
281
282
28.2k
  return decompress_data(cinfo, buffer);
283
28.2k
}
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
617
{
297
617
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
617
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
617
  int ci, samp_rows, row;
300
617
  _JSAMPARRAY buffer;
301
617
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
617
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
617
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
617
          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
1.89k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
1.28k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
1.28k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
1.28k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
1.28k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
1.28k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
1.28k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1.20k
      samp_rows = compptr->v_samp_factor;
322
80
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
80
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
80
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
80
    }
327
328
2.96k
    for (row = 0; row < samp_rows; row++) {
329
1.68k
      memcpy(output_buf[ci][row], buffer[row],
330
1.68k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1.68k
    }
332
1.28k
  }
333
334
617
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
571
    return JPEG_ROW_COMPLETED;
336
46
  return JPEG_SCAN_COMPLETED;
337
617
}
jddiffct-8.c:output_data
Line
Count
Source
296
617
{
297
617
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
617
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
617
  int ci, samp_rows, row;
300
617
  _JSAMPARRAY buffer;
301
617
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
617
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
617
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
617
          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
1.89k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
1.28k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
1.28k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
1.28k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
1.28k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
1.28k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
1.28k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1.20k
      samp_rows = compptr->v_samp_factor;
322
80
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
80
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
80
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
80
    }
327
328
2.96k
    for (row = 0; row < samp_rows; row++) {
329
1.68k
      memcpy(output_buf[ci][row], buffer[row],
330
1.68k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1.68k
    }
332
1.28k
  }
333
334
617
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
571
    return JPEG_ROW_COMPLETED;
336
46
  return JPEG_SCAN_COMPLETED;
337
617
}
Unexecuted instantiation: jddiffct-12.c:output_data
Unexecuted instantiation: jddiffct-16.c:output_data
338
339
#endif /* D_MULTISCAN_FILES_SUPPORTED */
340
341
342
/*
343
 * Initialize difference buffer controller.
344
 */
345
346
GLOBAL(void)
347
_jinit_d_diff_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
348
2.74k
{
349
2.74k
  my_diff_ptr diff;
350
2.74k
  int ci;
351
2.74k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
1.13k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
1.61k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
1.61k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
2.74k
  diff = (my_diff_ptr)
362
2.74k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
2.74k
                                sizeof(my_diff_controller));
364
2.74k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
2.74k
  diff->pub.start_input_pass = start_input_pass;
366
2.74k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
8.76k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
6.02k
       ci++, compptr++) {
371
6.02k
    diff->diff_buf[ci] =
372
6.02k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
6.02k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
6.02k
                                         (long)compptr->h_samp_factor),
375
6.02k
                   (JDIMENSION)compptr->v_samp_factor);
376
6.02k
    diff->undiff_buf[ci] =
377
6.02k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
6.02k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
6.02k
                                         (long)compptr->h_samp_factor),
380
6.02k
                   (JDIMENSION)compptr->v_samp_factor);
381
6.02k
  }
382
383
2.74k
  if (need_full_buffer) {
384
1.85k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.85k
    int access_rows;
387
388
6.51k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
4.66k
         ci++, compptr++) {
390
4.66k
      access_rows = compptr->v_samp_factor;
391
4.66k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
4.66k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
4.66k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
4.66k
                               (long)compptr->h_samp_factor),
395
4.66k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
4.66k
                               (long)compptr->v_samp_factor),
397
4.66k
         (JDIMENSION)access_rows);
398
4.66k
    }
399
1.85k
    diff->pub.consume_data = consume_data;
400
1.85k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.85k
  } else {
405
894
    diff->pub.consume_data = dummy_consume_data;
406
894
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
894
  }
409
2.74k
}
jinit_d_diff_controller
Line
Count
Source
348
1.13k
{
349
1.13k
  my_diff_ptr diff;
350
1.13k
  int ci;
351
1.13k
  jpeg_component_info *compptr;
352
353
1.13k
#if BITS_IN_JSAMPLE == 8
354
1.13k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.13k
  diff = (my_diff_ptr)
362
1.13k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.13k
                                sizeof(my_diff_controller));
364
1.13k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.13k
  diff->pub.start_input_pass = start_input_pass;
366
1.13k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
3.28k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
2.14k
       ci++, compptr++) {
371
2.14k
    diff->diff_buf[ci] =
372
2.14k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
2.14k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
2.14k
                                         (long)compptr->h_samp_factor),
375
2.14k
                   (JDIMENSION)compptr->v_samp_factor);
376
2.14k
    diff->undiff_buf[ci] =
377
2.14k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
2.14k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
2.14k
                                         (long)compptr->h_samp_factor),
380
2.14k
                   (JDIMENSION)compptr->v_samp_factor);
381
2.14k
  }
382
383
1.13k
  if (need_full_buffer) {
384
317
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
317
    int access_rows;
387
388
1.23k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
913
         ci++, compptr++) {
390
913
      access_rows = compptr->v_samp_factor;
391
913
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
913
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
913
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
913
                               (long)compptr->h_samp_factor),
395
913
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
913
                               (long)compptr->v_samp_factor),
397
913
         (JDIMENSION)access_rows);
398
913
    }
399
317
    diff->pub.consume_data = consume_data;
400
317
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
818
  } else {
405
818
    diff->pub.consume_data = dummy_consume_data;
406
818
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
818
  }
409
1.13k
}
j12init_d_diff_controller
Line
Count
Source
348
770
{
349
770
  my_diff_ptr diff;
350
770
  int ci;
351
770
  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
770
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
770
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
770
  diff = (my_diff_ptr)
362
770
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
770
                                sizeof(my_diff_controller));
364
770
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
770
  diff->pub.start_input_pass = start_input_pass;
366
770
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.61k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.84k
       ci++, compptr++) {
371
1.84k
    diff->diff_buf[ci] =
372
1.84k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.84k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.84k
                                         (long)compptr->h_samp_factor),
375
1.84k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.84k
    diff->undiff_buf[ci] =
377
1.84k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.84k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.84k
                                         (long)compptr->h_samp_factor),
380
1.84k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.84k
  }
382
383
770
  if (need_full_buffer) {
384
734
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
734
    int access_rows;
387
388
2.50k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.77k
         ci++, compptr++) {
390
1.77k
      access_rows = compptr->v_samp_factor;
391
1.77k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.77k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.77k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.77k
                               (long)compptr->h_samp_factor),
395
1.77k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.77k
                               (long)compptr->v_samp_factor),
397
1.77k
         (JDIMENSION)access_rows);
398
1.77k
    }
399
734
    diff->pub.consume_data = consume_data;
400
734
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
734
  } else {
405
36
    diff->pub.consume_data = dummy_consume_data;
406
36
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
36
  }
409
770
}
j16init_d_diff_controller
Line
Count
Source
348
841
{
349
841
  my_diff_ptr diff;
350
841
  int ci;
351
841
  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
841
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
841
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
841
  diff = (my_diff_ptr)
362
841
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
841
                                sizeof(my_diff_controller));
364
841
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
841
  diff->pub.start_input_pass = start_input_pass;
366
841
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.87k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
2.03k
       ci++, compptr++) {
371
2.03k
    diff->diff_buf[ci] =
372
2.03k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
2.03k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
2.03k
                                         (long)compptr->h_samp_factor),
375
2.03k
                   (JDIMENSION)compptr->v_samp_factor);
376
2.03k
    diff->undiff_buf[ci] =
377
2.03k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
2.03k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
2.03k
                                         (long)compptr->h_samp_factor),
380
2.03k
                   (JDIMENSION)compptr->v_samp_factor);
381
2.03k
  }
382
383
841
  if (need_full_buffer) {
384
801
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
801
    int access_rows;
387
388
2.77k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.97k
         ci++, compptr++) {
390
1.97k
      access_rows = compptr->v_samp_factor;
391
1.97k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.97k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.97k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.97k
                               (long)compptr->h_samp_factor),
395
1.97k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.97k
                               (long)compptr->v_samp_factor),
397
1.97k
         (JDIMENSION)access_rows);
398
1.97k
    }
399
801
    diff->pub.consume_data = consume_data;
400
801
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
801
  } else {
405
40
    diff->pub.consume_data = dummy_consume_data;
406
40
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
40
  }
409
841
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */