Coverage Report

Created: 2026-11-12 06:19

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
810k
{
68
810k
  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
810k
  if (cinfo->comps_in_scan > 1) {
75
68.3k
    diff->MCU_rows_per_iMCU_row = 1;
76
742k
  } else {
77
742k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
712k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
29.8k
    else
80
29.8k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
742k
  }
82
83
810k
  diff->MCU_ctr = 0;
84
810k
  diff->MCU_vert_offset = 0;
85
810k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
224k
{
68
224k
  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
224k
  if (cinfo->comps_in_scan > 1) {
75
61.5k
    diff->MCU_rows_per_iMCU_row = 1;
76
162k
  } else {
77
162k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
153k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
9.15k
    else
80
9.15k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
162k
  }
82
83
224k
  diff->MCU_ctr = 0;
84
224k
  diff->MCU_vert_offset = 0;
85
224k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
321k
{
68
321k
  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
321k
  if (cinfo->comps_in_scan > 1) {
75
3.43k
    diff->MCU_rows_per_iMCU_row = 1;
76
317k
  } else {
77
317k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
307k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
10.2k
    else
80
10.2k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
317k
  }
82
83
321k
  diff->MCU_ctr = 0;
84
321k
  diff->MCU_vert_offset = 0;
85
321k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
265k
{
68
265k
  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
265k
  if (cinfo->comps_in_scan > 1) {
75
3.36k
    diff->MCU_rows_per_iMCU_row = 1;
76
262k
  } else {
77
262k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
251k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
10.4k
    else
80
10.4k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
262k
  }
82
83
265k
  diff->MCU_ctr = 0;
84
265k
  diff->MCU_vert_offset = 0;
85
265k
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
50.2k
{
95
50.2k
  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
50.2k
  (*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
50.2k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
103
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
50.2k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
50.2k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
50.2k
  cinfo->input_iMCU_row = 0;
115
50.2k
  start_iMCU_row(cinfo);
116
50.2k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
17.4k
{
95
17.4k
  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
17.4k
  (*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
17.4k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
39
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
17.4k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
17.4k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
17.4k
  cinfo->input_iMCU_row = 0;
115
17.4k
  start_iMCU_row(cinfo);
116
17.4k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
16.0k
{
95
16.0k
  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
16.0k
  (*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
16.0k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
23
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
16.0k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
16.0k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
16.0k
  cinfo->input_iMCU_row = 0;
115
16.0k
  start_iMCU_row(cinfo);
116
16.0k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
16.7k
{
95
16.7k
  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
16.7k
  (*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
16.7k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
41
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
16.7k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
16.7k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
16.7k
  cinfo->input_iMCU_row = 0;
115
16.7k
  start_iMCU_row(cinfo);
116
16.7k
}
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
333
{
127
333
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
333
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
333
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
333
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
333
  return TRUE;
138
333
}
jddiffct-8.c:process_restart
Line
Count
Source
126
114
{
127
114
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
114
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
114
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
114
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
114
  return TRUE;
138
114
}
jddiffct-12.c:process_restart
Line
Count
Source
126
112
{
127
112
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
112
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
112
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
112
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
112
  return TRUE;
138
112
}
jddiffct-16.c:process_restart
Line
Count
Source
126
107
{
127
107
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
107
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
107
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
107
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
107
  return TRUE;
138
107
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
5.55k
{
148
5.55k
  cinfo->output_iMCU_row = 0;
149
5.55k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
5.16k
{
148
5.16k
  cinfo->output_iMCU_row = 0;
149
5.16k
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
187
{
148
187
  cinfo->output_iMCU_row = 0;
149
187
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
205
{
148
205
  cinfo->output_iMCU_row = 0;
149
205
}
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
810k
{
165
810k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
810k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
810k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
810k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
810k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
810k
  int ci, compi, row, prev_row;
171
810k
  unsigned int yoffset;
172
810k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
2.05M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
1.24M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
1.24M
    if (cinfo->restart_interval) {
180
49.7k
      if (diff->restart_rows_to_go == 0)
181
333
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
49.7k
    }
184
185
1.24M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
1.24M
    MCU_count =
188
1.24M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
1.24M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
1.24M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
1.24M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
1.24M
    if (cinfo->restart_interval)
200
49.3k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
1.24M
    diff->MCU_ctr = 0;
204
1.24M
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
1.75M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
940k
    compptr = cinfo->cur_comp_info[ci];
213
940k
    compi = compptr->component_index;
214
940k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
2.37M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
2.27M
                compptr->last_row_height : compptr->v_samp_factor);
217
1.43M
         prev_row = row, row++) {
218
1.43M
      (*losslessd->predict_undifference[compi])
219
1.43M
        (cinfo, compi, diff->diff_buf[compi][row],
220
1.43M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
1.43M
          compptr->width_in_blocks);
222
1.43M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
1.43M
                                  output_buf[compi][row],
224
1.43M
                                  compptr->width_in_blocks);
225
1.43M
    }
226
940k
  }
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
810k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
762k
    start_iMCU_row(cinfo);
236
762k
    return JPEG_ROW_COMPLETED;
237
762k
  }
238
  /* Completed the scan */
239
48.3k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
48.3k
  return JPEG_SCAN_COMPLETED;
241
810k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
224k
{
165
224k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
224k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
224k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
224k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
224k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
224k
  int ci, compi, row, prev_row;
171
224k
  unsigned int yoffset;
172
224k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
579k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
355k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
355k
    if (cinfo->restart_interval) {
180
4.20k
      if (diff->restart_rows_to_go == 0)
181
114
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
4.20k
    }
184
185
355k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
355k
    MCU_count =
188
355k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
355k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
355k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
355k
    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
355k
    if (cinfo->restart_interval)
200
4.06k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
355k
    diff->MCU_ctr = 0;
204
355k
  }
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
575k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
351k
    compptr = cinfo->cur_comp_info[ci];
213
351k
    compi = compptr->component_index;
214
351k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
889k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
856k
                compptr->last_row_height : compptr->v_samp_factor);
217
538k
         prev_row = row, row++) {
218
538k
      (*losslessd->predict_undifference[compi])
219
538k
        (cinfo, compi, diff->diff_buf[compi][row],
220
538k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
538k
          compptr->width_in_blocks);
222
538k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
538k
                                  output_buf[compi][row],
224
538k
                                  compptr->width_in_blocks);
225
538k
    }
226
351k
  }
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
224k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
207k
    start_iMCU_row(cinfo);
236
207k
    return JPEG_ROW_COMPLETED;
237
207k
  }
238
  /* Completed the scan */
239
16.8k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
16.8k
  return JPEG_SCAN_COMPLETED;
241
224k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
321k
{
165
321k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
321k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
321k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
321k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
321k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
321k
  int ci, compi, row, prev_row;
171
321k
  unsigned int yoffset;
172
321k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
831k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
510k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
510k
    if (cinfo->restart_interval) {
180
30.6k
      if (diff->restart_rows_to_go == 0)
181
112
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
30.6k
    }
184
185
510k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
510k
    MCU_count =
188
510k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
510k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
510k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
510k
    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
510k
    if (cinfo->restart_interval)
200
30.4k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
510k
    diff->MCU_ctr = 0;
204
510k
  }
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
643k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
322k
    compptr = cinfo->cur_comp_info[ci];
213
322k
    compi = compptr->component_index;
214
322k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
836k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
801k
                compptr->last_row_height : compptr->v_samp_factor);
217
514k
         prev_row = row, row++) {
218
514k
      (*losslessd->predict_undifference[compi])
219
514k
        (cinfo, compi, diff->diff_buf[compi][row],
220
514k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
514k
          compptr->width_in_blocks);
222
514k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
514k
                                  output_buf[compi][row],
224
514k
                                  compptr->width_in_blocks);
225
514k
    }
226
322k
  }
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
321k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
305k
    start_iMCU_row(cinfo);
236
305k
    return JPEG_ROW_COMPLETED;
237
305k
  }
238
  /* Completed the scan */
239
15.4k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
15.4k
  return JPEG_SCAN_COMPLETED;
241
321k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
265k
{
165
265k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
265k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
265k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
265k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
265k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
265k
  int ci, compi, row, prev_row;
171
265k
  unsigned int yoffset;
172
265k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
645k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
379k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
379k
    if (cinfo->restart_interval) {
180
14.9k
      if (diff->restart_rows_to_go == 0)
181
107
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
14.9k
    }
184
185
379k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
379k
    MCU_count =
188
379k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
379k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
379k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
379k
    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
379k
    if (cinfo->restart_interval)
200
14.7k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
379k
    diff->MCU_ctr = 0;
204
379k
  }
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
532k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
266k
    compptr = cinfo->cur_comp_info[ci];
213
266k
    compi = compptr->component_index;
214
266k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
649k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
612k
                compptr->last_row_height : compptr->v_samp_factor);
217
382k
         prev_row = row, row++) {
218
382k
      (*losslessd->predict_undifference[compi])
219
382k
        (cinfo, compi, diff->diff_buf[compi][row],
220
382k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
382k
          compptr->width_in_blocks);
222
382k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
382k
                                  output_buf[compi][row],
224
382k
                                  compptr->width_in_blocks);
225
382k
    }
226
266k
  }
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
265k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
249k
    start_iMCU_row(cinfo);
236
249k
    return JPEG_ROW_COMPLETED;
237
249k
  }
238
  /* Completed the scan */
239
16.0k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
16.0k
  return JPEG_SCAN_COMPLETED;
241
265k
}
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
712k
{
267
712k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
712k
  int ci, compi;
269
712k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
712k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
1.46M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
753k
    compptr = cinfo->cur_comp_info[ci];
275
753k
    compi = compptr->component_index;
276
753k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
753k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
753k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
753k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
753k
  }
281
282
712k
  return decompress_data(cinfo, buffer);
283
712k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
126k
{
267
126k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
126k
  int ci, compi;
269
126k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
126k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
283k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
156k
    compptr = cinfo->cur_comp_info[ci];
275
156k
    compi = compptr->component_index;
276
156k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
156k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
156k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
156k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
156k
  }
281
282
126k
  return decompress_data(cinfo, buffer);
283
126k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
321k
{
267
321k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
321k
  int ci, compi;
269
321k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
321k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
647k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
326k
    compptr = cinfo->cur_comp_info[ci];
275
326k
    compi = compptr->component_index;
276
326k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
326k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
326k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
326k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
326k
  }
281
282
321k
  return decompress_data(cinfo, buffer);
283
321k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
265k
{
267
265k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
265k
  int ci, compi;
269
265k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
265k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
536k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
270k
    compptr = cinfo->cur_comp_info[ci];
275
270k
    compi = compptr->component_index;
276
270k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
270k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
270k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
270k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
270k
  }
281
282
265k
  return decompress_data(cinfo, buffer);
283
265k
}
284
285
286
/*
287
 * Output some data from the full-image sample buffer in the multi-pass case.
288
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
289
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
290
 *
291
 * NB: output_buf contains a plane for each component in image.
292
 */
293
294
METHODDEF(int)
295
output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
296
1.23k
{
297
1.23k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
1.23k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
1.23k
  int ci, samp_rows, row;
300
1.23k
  _JSAMPARRAY buffer;
301
1.23k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
1.23k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
1.23k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
1.23k
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
0
  }
310
311
  /* OK, output from the virtual arrays. */
312
3.98k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
2.74k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
2.74k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
2.74k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
2.74k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
2.74k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
2.74k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
2.30k
      samp_rows = compptr->v_samp_factor;
322
438
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
438
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
438
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
438
    }
327
328
6.73k
    for (row = 0; row < samp_rows; row++) {
329
3.99k
      memcpy(output_buf[ci][row], buffer[row],
330
3.99k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
3.99k
    }
332
2.74k
  }
333
334
1.23k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
998
    return JPEG_ROW_COMPLETED;
336
241
  return JPEG_SCAN_COMPLETED;
337
1.23k
}
jddiffct-8.c:output_data
Line
Count
Source
296
1.23k
{
297
1.23k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
1.23k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
1.23k
  int ci, samp_rows, row;
300
1.23k
  _JSAMPARRAY buffer;
301
1.23k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
1.23k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
1.23k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
1.23k
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
0
  }
310
311
  /* OK, output from the virtual arrays. */
312
3.98k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
2.74k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
2.74k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
2.74k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
2.74k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
2.74k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
2.74k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
2.30k
      samp_rows = compptr->v_samp_factor;
322
438
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
438
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
438
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
438
    }
327
328
6.73k
    for (row = 0; row < samp_rows; row++) {
329
3.99k
      memcpy(output_buf[ci][row], buffer[row],
330
3.99k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
3.99k
    }
332
2.74k
  }
333
334
1.23k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
998
    return JPEG_ROW_COMPLETED;
336
241
  return JPEG_SCAN_COMPLETED;
337
1.23k
}
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
19.4k
{
349
19.4k
  my_diff_ptr diff;
350
19.4k
  int ci;
351
19.4k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
8.11k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
11.2k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
11.2k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
19.4k
  diff = (my_diff_ptr)
362
19.4k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
19.4k
                                sizeof(my_diff_controller));
364
19.4k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
19.4k
  diff->pub.start_input_pass = start_input_pass;
366
19.4k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
72.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
53.2k
       ci++, compptr++) {
371
53.2k
    diff->diff_buf[ci] =
372
53.2k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
53.2k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
53.2k
                                         (long)compptr->h_samp_factor),
375
53.2k
                   (JDIMENSION)compptr->v_samp_factor);
376
53.2k
    diff->undiff_buf[ci] =
377
53.2k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
53.2k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
53.2k
                                         (long)compptr->h_samp_factor),
380
53.2k
                   (JDIMENSION)compptr->v_samp_factor);
381
53.2k
  }
382
383
19.4k
  if (need_full_buffer) {
384
13.0k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
13.0k
    int access_rows;
387
388
50.8k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
37.7k
         ci++, compptr++) {
390
37.7k
      access_rows = compptr->v_samp_factor;
391
37.7k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
37.7k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
37.7k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
37.7k
                               (long)compptr->h_samp_factor),
395
37.7k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
37.7k
                               (long)compptr->v_samp_factor),
397
37.7k
         (JDIMENSION)access_rows);
398
37.7k
    }
399
13.0k
    diff->pub.consume_data = consume_data;
400
13.0k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
13.0k
  } else {
405
6.33k
    diff->pub.consume_data = dummy_consume_data;
406
6.33k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
6.33k
  }
409
19.4k
}
jinit_d_diff_controller
Line
Count
Source
348
8.11k
{
349
8.11k
  my_diff_ptr diff;
350
8.11k
  int ci;
351
8.11k
  jpeg_component_info *compptr;
352
353
8.11k
#if BITS_IN_JSAMPLE == 8
354
8.11k
  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
8.11k
  diff = (my_diff_ptr)
362
8.11k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
8.11k
                                sizeof(my_diff_controller));
364
8.11k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
8.11k
  diff->pub.start_input_pass = start_input_pass;
366
8.11k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
29.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
20.9k
       ci++, compptr++) {
371
20.9k
    diff->diff_buf[ci] =
372
20.9k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
20.9k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
20.9k
                                         (long)compptr->h_samp_factor),
375
20.9k
                   (JDIMENSION)compptr->v_samp_factor);
376
20.9k
    diff->undiff_buf[ci] =
377
20.9k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
20.9k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
20.9k
                                         (long)compptr->h_samp_factor),
380
20.9k
                   (JDIMENSION)compptr->v_samp_factor);
381
20.9k
  }
382
383
8.11k
  if (need_full_buffer) {
384
2.59k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
2.59k
    int access_rows;
387
388
10.4k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
7.82k
         ci++, compptr++) {
390
7.82k
      access_rows = compptr->v_samp_factor;
391
7.82k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
7.82k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
7.82k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
7.82k
                               (long)compptr->h_samp_factor),
395
7.82k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
7.82k
                               (long)compptr->v_samp_factor),
397
7.82k
         (JDIMENSION)access_rows);
398
7.82k
    }
399
2.59k
    diff->pub.consume_data = consume_data;
400
2.59k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
5.51k
  } else {
405
5.51k
    diff->pub.consume_data = dummy_consume_data;
406
5.51k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
5.51k
  }
409
8.11k
}
j12init_d_diff_controller
Line
Count
Source
348
5.49k
{
349
5.49k
  my_diff_ptr diff;
350
5.49k
  int ci;
351
5.49k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
5.49k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
5.49k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
5.49k
  diff = (my_diff_ptr)
362
5.49k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
5.49k
                                sizeof(my_diff_controller));
364
5.49k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
5.49k
  diff->pub.start_input_pass = start_input_pass;
366
5.49k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
21.1k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
15.6k
       ci++, compptr++) {
371
15.6k
    diff->diff_buf[ci] =
372
15.6k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
15.6k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
15.6k
                                         (long)compptr->h_samp_factor),
375
15.6k
                   (JDIMENSION)compptr->v_samp_factor);
376
15.6k
    diff->undiff_buf[ci] =
377
15.6k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
15.6k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
15.6k
                                         (long)compptr->h_samp_factor),
380
15.6k
                   (JDIMENSION)compptr->v_samp_factor);
381
15.6k
  }
382
383
5.49k
  if (need_full_buffer) {
384
5.09k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
5.09k
    int access_rows;
387
388
19.6k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
14.5k
         ci++, compptr++) {
390
14.5k
      access_rows = compptr->v_samp_factor;
391
14.5k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
14.5k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
14.5k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
14.5k
                               (long)compptr->h_samp_factor),
395
14.5k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
14.5k
                               (long)compptr->v_samp_factor),
397
14.5k
         (JDIMENSION)access_rows);
398
14.5k
    }
399
5.09k
    diff->pub.consume_data = consume_data;
400
5.09k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
5.09k
  } else {
405
399
    diff->pub.consume_data = dummy_consume_data;
406
399
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
399
  }
409
5.49k
}
j16init_d_diff_controller
Line
Count
Source
348
5.80k
{
349
5.80k
  my_diff_ptr diff;
350
5.80k
  int ci;
351
5.80k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
5.80k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
5.80k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
5.80k
  diff = (my_diff_ptr)
362
5.80k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
5.80k
                                sizeof(my_diff_controller));
364
5.80k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
5.80k
  diff->pub.start_input_pass = start_input_pass;
366
5.80k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
22.4k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
16.6k
       ci++, compptr++) {
371
16.6k
    diff->diff_buf[ci] =
372
16.6k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
16.6k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
16.6k
                                         (long)compptr->h_samp_factor),
375
16.6k
                   (JDIMENSION)compptr->v_samp_factor);
376
16.6k
    diff->undiff_buf[ci] =
377
16.6k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
16.6k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
16.6k
                                         (long)compptr->h_samp_factor),
380
16.6k
                   (JDIMENSION)compptr->v_samp_factor);
381
16.6k
  }
382
383
5.80k
  if (need_full_buffer) {
384
5.38k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
5.38k
    int access_rows;
387
388
20.7k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
15.4k
         ci++, compptr++) {
390
15.4k
      access_rows = compptr->v_samp_factor;
391
15.4k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
15.4k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
15.4k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
15.4k
                               (long)compptr->h_samp_factor),
395
15.4k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
15.4k
                               (long)compptr->v_samp_factor),
397
15.4k
         (JDIMENSION)access_rows);
398
15.4k
    }
399
5.38k
    diff->pub.consume_data = consume_data;
400
5.38k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
5.38k
  } else {
405
422
    diff->pub.consume_data = dummy_consume_data;
406
422
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
422
  }
409
5.80k
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */