Coverage Report

Created: 2025-11-11 07:02

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
72.1k
{
68
72.1k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
72.1k
  if (cinfo->comps_in_scan > 1) {
75
3.35k
    diff->MCU_rows_per_iMCU_row = 1;
76
68.7k
  } else {
77
68.7k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
68.4k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
299
    else
80
299
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
68.7k
  }
82
83
72.1k
  diff->MCU_ctr = 0;
84
72.1k
  diff->MCU_vert_offset = 0;
85
72.1k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
8.25k
{
68
8.25k
  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
8.25k
  if (cinfo->comps_in_scan > 1) {
75
3.34k
    diff->MCU_rows_per_iMCU_row = 1;
76
4.91k
  } else {
77
4.91k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
4.80k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
108
    else
80
108
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
4.91k
  }
82
83
8.25k
  diff->MCU_ctr = 0;
84
8.25k
  diff->MCU_vert_offset = 0;
85
8.25k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
7.41k
{
68
7.41k
  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
7.41k
  if (cinfo->comps_in_scan > 1) {
75
9
    diff->MCU_rows_per_iMCU_row = 1;
76
7.40k
  } else {
77
7.40k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
7.32k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
74
    else
80
74
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
7.40k
  }
82
83
7.41k
  diff->MCU_ctr = 0;
84
7.41k
  diff->MCU_vert_offset = 0;
85
7.41k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
56.4k
{
68
56.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
56.4k
  if (cinfo->comps_in_scan > 1) {
75
5
    diff->MCU_rows_per_iMCU_row = 1;
76
56.4k
  } else {
77
56.4k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
56.3k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
117
    else
80
117
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
56.4k
  }
82
83
56.4k
  diff->MCU_ctr = 0;
84
56.4k
  diff->MCU_vert_offset = 0;
85
56.4k
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
1.60k
{
95
1.60k
  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.60k
  (*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.60k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
3
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.60k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.60k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.60k
  cinfo->input_iMCU_row = 0;
115
1.60k
  start_iMCU_row(cinfo);
116
1.60k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
623
{
95
623
  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
623
  (*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
623
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
623
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
623
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
623
  cinfo->input_iMCU_row = 0;
115
623
  start_iMCU_row(cinfo);
116
623
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
473
{
95
473
  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
473
  (*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
473
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
473
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
473
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
473
  cinfo->input_iMCU_row = 0;
115
473
  start_iMCU_row(cinfo);
116
473
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
513
{
95
513
  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
513
  (*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
513
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
1
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
513
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
513
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
513
  cinfo->input_iMCU_row = 0;
115
513
  start_iMCU_row(cinfo);
116
513
}
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
16
{
127
16
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
16
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
16
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
16
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
16
  return TRUE;
138
16
}
jddiffct-8.c:process_restart
Line
Count
Source
126
8
{
127
8
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
8
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
8
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
8
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
8
  return TRUE;
138
8
}
jddiffct-12.c:process_restart
Line
Count
Source
126
5
{
127
5
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
5
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
5
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
5
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
5
  return TRUE;
138
5
}
jddiffct-16.c:process_restart
Line
Count
Source
126
3
{
127
3
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
3
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
3
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
3
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
3
  return TRUE;
138
3
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
277
{
148
277
  cinfo->output_iMCU_row = 0;
149
277
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
262
{
148
262
  cinfo->output_iMCU_row = 0;
149
262
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
10
{
148
10
  cinfo->output_iMCU_row = 0;
149
10
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
5
{
148
5
  cinfo->output_iMCU_row = 0;
149
5
}
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
72.1k
{
165
72.1k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
72.1k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
72.1k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
72.1k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
72.1k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
72.1k
  int ci, compi, row, prev_row;
171
72.1k
  unsigned int yoffset;
172
72.1k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
155k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
83.4k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
83.4k
    if (cinfo->restart_interval) {
180
1.06k
      if (diff->restart_rows_to_go == 0)
181
16
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.06k
    }
184
185
83.4k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
83.4k
    MCU_count =
188
83.4k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
83.4k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
83.4k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
83.4k
    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
83.4k
    if (cinfo->restart_interval)
200
1.01k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
83.4k
    diff->MCU_ctr = 0;
204
83.4k
  }
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
151k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
79.2k
    compptr = cinfo->cur_comp_info[ci];
213
79.2k
    compi = compptr->component_index;
214
79.2k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
172k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
171k
                compptr->last_row_height : compptr->v_samp_factor);
217
93.2k
         prev_row = row, row++) {
218
93.2k
      (*losslessd->predict_undifference[compi])
219
93.2k
        (cinfo, compi, diff->diff_buf[compi][row],
220
93.2k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
93.2k
          compptr->width_in_blocks);
222
93.2k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
93.2k
                                  output_buf[compi][row],
224
93.2k
                                  compptr->width_in_blocks);
225
93.2k
    }
226
79.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
72.1k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
70.5k
    start_iMCU_row(cinfo);
236
70.5k
    return JPEG_ROW_COMPLETED;
237
70.5k
  }
238
  /* Completed the scan */
239
1.51k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.51k
  return JPEG_SCAN_COMPLETED;
241
72.1k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
8.25k
{
165
8.25k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
8.25k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
8.25k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
8.25k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
8.25k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
8.25k
  int ci, compi, row, prev_row;
171
8.25k
  unsigned int yoffset;
172
8.25k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
20.1k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
11.9k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
11.9k
    if (cinfo->restart_interval) {
180
338
      if (diff->restart_rows_to_go == 0)
181
8
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
338
    }
184
185
11.9k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
11.9k
    MCU_count =
188
11.9k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
11.9k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
11.9k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
11.9k
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
11.9k
    if (cinfo->restart_interval)
200
326
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
11.9k
    diff->MCU_ctr = 0;
204
11.9k
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
24.3k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
16.0k
    compptr = cinfo->cur_comp_info[ci];
213
16.0k
    compi = compptr->component_index;
214
16.0k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
38.7k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
38.2k
                compptr->last_row_height : compptr->v_samp_factor);
217
22.6k
         prev_row = row, row++) {
218
22.6k
      (*losslessd->predict_undifference[compi])
219
22.6k
        (cinfo, compi, diff->diff_buf[compi][row],
220
22.6k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
22.6k
          compptr->width_in_blocks);
222
22.6k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
22.6k
                                  output_buf[compi][row],
224
22.6k
                                  compptr->width_in_blocks);
225
22.6k
    }
226
16.0k
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
8.25k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
7.65k
    start_iMCU_row(cinfo);
236
7.65k
    return JPEG_ROW_COMPLETED;
237
7.65k
  }
238
  /* Completed the scan */
239
597
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
597
  return JPEG_SCAN_COMPLETED;
241
8.25k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
7.40k
{
165
7.40k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
7.40k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
7.40k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
7.40k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
7.40k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
7.40k
  int ci, compi, row, prev_row;
171
7.40k
  unsigned int yoffset;
172
7.40k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
18.9k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
11.5k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
11.5k
    if (cinfo->restart_interval) {
180
364
      if (diff->restart_rows_to_go == 0)
181
5
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
364
    }
184
185
11.5k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
11.5k
    MCU_count =
188
11.5k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
11.5k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
11.5k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
11.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
11.5k
    if (cinfo->restart_interval)
200
352
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
11.5k
    diff->MCU_ctr = 0;
204
11.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
14.4k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
7.03k
    compptr = cinfo->cur_comp_info[ci];
213
7.03k
    compi = compptr->component_index;
214
7.03k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
18.0k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
17.8k
                compptr->last_row_height : compptr->v_samp_factor);
217
11.0k
         prev_row = row, row++) {
218
11.0k
      (*losslessd->predict_undifference[compi])
219
11.0k
        (cinfo, compi, diff->diff_buf[compi][row],
220
11.0k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
11.0k
          compptr->width_in_blocks);
222
11.0k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
11.0k
                                  output_buf[compi][row],
224
11.0k
                                  compptr->width_in_blocks);
225
11.0k
    }
226
7.03k
  }
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
7.40k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
6.96k
    start_iMCU_row(cinfo);
236
6.96k
    return JPEG_ROW_COMPLETED;
237
6.96k
  }
238
  /* Completed the scan */
239
439
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
439
  return JPEG_SCAN_COMPLETED;
241
7.40k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
56.4k
{
165
56.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
56.4k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
56.4k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
56.4k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
56.4k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
56.4k
  int ci, compi, row, prev_row;
171
56.4k
  unsigned int yoffset;
172
56.4k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
116k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
60.0k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
60.0k
    if (cinfo->restart_interval) {
180
358
      if (diff->restart_rows_to_go == 0)
181
3
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
358
    }
184
185
60.0k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
60.0k
    MCU_count =
188
60.0k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
60.0k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
60.0k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
60.0k
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
60.0k
    if (cinfo->restart_interval)
200
341
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
60.0k
    diff->MCU_ctr = 0;
204
60.0k
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
112k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
56.0k
    compptr = cinfo->cur_comp_info[ci];
213
56.0k
    compi = compptr->component_index;
214
56.0k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
115k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
115k
                compptr->last_row_height : compptr->v_samp_factor);
217
59.5k
         prev_row = row, row++) {
218
59.5k
      (*losslessd->predict_undifference[compi])
219
59.5k
        (cinfo, compi, diff->diff_buf[compi][row],
220
59.5k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
59.5k
          compptr->width_in_blocks);
222
59.5k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
59.5k
                                  output_buf[compi][row],
224
59.5k
                                  compptr->width_in_blocks);
225
59.5k
    }
226
56.0k
  }
227
228
  /* Completed the iMCU row, advance counters for next one.
229
   *
230
   * NB: output_data will increment output_iMCU_row.
231
   * This counter is not needed for the single-pass case
232
   * or the input side of the multi-pass case.
233
   */
234
56.4k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
55.9k
    start_iMCU_row(cinfo);
236
55.9k
    return JPEG_ROW_COMPLETED;
237
55.9k
  }
238
  /* Completed the scan */
239
477
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
477
  return JPEG_SCAN_COMPLETED;
241
56.4k
}
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
68.7k
{
267
68.7k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
68.7k
  int ci, compi;
269
68.7k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
68.7k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
137k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
68.7k
    compptr = cinfo->cur_comp_info[ci];
275
68.7k
    compi = compptr->component_index;
276
68.7k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
68.7k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
68.7k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
68.7k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
68.7k
  }
281
282
68.7k
  return decompress_data(cinfo, buffer);
283
68.7k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
4.91k
{
267
4.91k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
4.91k
  int ci, compi;
269
4.91k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
4.91k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
9.82k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
4.91k
    compptr = cinfo->cur_comp_info[ci];
275
4.91k
    compi = compptr->component_index;
276
4.91k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
4.91k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
4.91k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
4.91k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
4.91k
  }
281
282
4.91k
  return decompress_data(cinfo, buffer);
283
4.91k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
7.40k
{
267
7.40k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
7.40k
  int ci, compi;
269
7.40k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
7.40k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
14.8k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
7.40k
    compptr = cinfo->cur_comp_info[ci];
275
7.40k
    compi = compptr->component_index;
276
7.40k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
7.40k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
7.40k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
7.40k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
7.40k
  }
281
282
7.40k
  return decompress_data(cinfo, buffer);
283
7.40k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
56.4k
{
267
56.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
56.4k
  int ci, compi;
269
56.4k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
56.4k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
112k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
56.4k
    compptr = cinfo->cur_comp_info[ci];
275
56.4k
    compi = compptr->component_index;
276
56.4k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
56.4k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
56.4k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
56.4k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
56.4k
  }
281
282
56.4k
  return decompress_data(cinfo, buffer);
283
56.4k
}
284
285
286
/*
287
 * Output some data from the full-image sample buffer in the multi-pass case.
288
 * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
289
 * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
290
 *
291
 * NB: output_buf contains a plane for each component in image.
292
 */
293
294
METHODDEF(int)
295
output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf)
296
4
{
297
4
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
4
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
4
  int ci, samp_rows, row;
300
4
  _JSAMPARRAY buffer;
301
4
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
4
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
4
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
4
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
0
  }
310
311
  /* OK, output from the virtual arrays. */
312
12
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
8
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
8
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
8
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
8
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
8
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
8
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1
      samp_rows = compptr->v_samp_factor;
322
7
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
7
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
7
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
7
    }
327
328
18
    for (row = 0; row < samp_rows; row++) {
329
10
      memcpy(output_buf[ci][row], buffer[row],
330
10
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
10
    }
332
8
  }
333
334
4
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
4
  return JPEG_SCAN_COMPLETED;
337
4
}
jddiffct-8.c:output_data
Line
Count
Source
296
4
{
297
4
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
4
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
4
  int ci, samp_rows, row;
300
4
  _JSAMPARRAY buffer;
301
4
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
4
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
4
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
4
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
0
  }
310
311
  /* OK, output from the virtual arrays. */
312
12
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
8
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
8
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
8
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
8
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
8
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
8
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1
      samp_rows = compptr->v_samp_factor;
322
7
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
7
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
7
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
7
    }
327
328
18
    for (row = 0; row < samp_rows; row++) {
329
10
      memcpy(output_buf[ci][row], buffer[row],
330
10
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
10
    }
332
8
  }
333
334
4
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
4
  return JPEG_SCAN_COMPLETED;
337
4
}
Unexecuted instantiation: jddiffct-12.c:output_data
Unexecuted instantiation: jddiffct-16.c:output_data
338
339
#endif /* D_MULTISCAN_FILES_SUPPORTED */
340
341
342
/*
343
 * Initialize difference buffer controller.
344
 */
345
346
GLOBAL(void)
347
_jinit_d_diff_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
348
1.44k
{
349
1.44k
  my_diff_ptr diff;
350
1.44k
  int ci;
351
1.44k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
561
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
881
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
881
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.44k
  diff = (my_diff_ptr)
362
1.44k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.44k
                                sizeof(my_diff_controller));
364
1.44k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.44k
  diff->pub.start_input_pass = start_input_pass;
366
1.44k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
5.97k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.53k
       ci++, compptr++) {
371
4.53k
    diff->diff_buf[ci] =
372
4.53k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.53k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.53k
                                         (long)compptr->h_samp_factor),
375
4.53k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.53k
    diff->undiff_buf[ci] =
377
4.53k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.53k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.53k
                                         (long)compptr->h_samp_factor),
380
4.53k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.53k
  }
382
383
1.44k
  if (need_full_buffer) {
384
1.10k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.10k
    int access_rows;
387
388
4.43k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.32k
         ci++, compptr++) {
390
3.32k
      access_rows = compptr->v_samp_factor;
391
3.32k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.32k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.32k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.32k
                               (long)compptr->h_samp_factor),
395
3.32k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.32k
                               (long)compptr->v_samp_factor),
397
3.32k
         (JDIMENSION)access_rows);
398
3.32k
    }
399
1.10k
    diff->pub.consume_data = consume_data;
400
1.10k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.10k
  } else {
405
333
    diff->pub.consume_data = dummy_consume_data;
406
333
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
333
  }
409
1.44k
}
jinit_d_diff_controller
Line
Count
Source
348
561
{
349
561
  my_diff_ptr diff;
350
561
  int ci;
351
561
  jpeg_component_info *compptr;
352
353
561
#if BITS_IN_JSAMPLE == 8
354
561
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
561
  diff = (my_diff_ptr)
362
561
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
561
                                sizeof(my_diff_controller));
364
561
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
561
  diff->pub.start_input_pass = start_input_pass;
366
561
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
2.40k
  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
561
  if (need_full_buffer) {
384
271
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
271
    int access_rows;
387
388
1.08k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
813
         ci++, compptr++) {
390
813
      access_rows = compptr->v_samp_factor;
391
813
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
813
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
813
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
813
                               (long)compptr->h_samp_factor),
395
813
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
813
                               (long)compptr->v_samp_factor),
397
813
         (JDIMENSION)access_rows);
398
813
    }
399
271
    diff->pub.consume_data = consume_data;
400
271
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
290
  } else {
405
290
    diff->pub.consume_data = dummy_consume_data;
406
290
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
290
  }
409
561
}
j12init_d_diff_controller
Line
Count
Source
348
446
{
349
446
  my_diff_ptr diff;
350
446
  int ci;
351
446
  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
446
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
446
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
446
  diff = (my_diff_ptr)
362
446
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
446
                                sizeof(my_diff_controller));
364
446
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
446
  diff->pub.start_input_pass = start_input_pass;
366
446
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.80k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.36k
       ci++, compptr++) {
371
1.36k
    diff->diff_buf[ci] =
372
1.36k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.36k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.36k
                                         (long)compptr->h_samp_factor),
375
1.36k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.36k
    diff->undiff_buf[ci] =
377
1.36k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.36k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.36k
                                         (long)compptr->h_samp_factor),
380
1.36k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.36k
  }
382
383
446
  if (need_full_buffer) {
384
421
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
421
    int access_rows;
387
388
1.68k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.26k
         ci++, compptr++) {
390
1.26k
      access_rows = compptr->v_samp_factor;
391
1.26k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.26k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.26k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.26k
                               (long)compptr->h_samp_factor),
395
1.26k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.26k
                               (long)compptr->v_samp_factor),
397
1.26k
         (JDIMENSION)access_rows);
398
1.26k
    }
399
421
    diff->pub.consume_data = consume_data;
400
421
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
421
  } else {
405
25
    diff->pub.consume_data = dummy_consume_data;
406
25
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
25
  }
409
446
}
j16init_d_diff_controller
Line
Count
Source
348
435
{
349
435
  my_diff_ptr diff;
350
435
  int ci;
351
435
  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
435
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
435
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
435
  diff = (my_diff_ptr)
362
435
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
435
                                sizeof(my_diff_controller));
364
435
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
435
  diff->pub.start_input_pass = start_input_pass;
366
435
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.75k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.32k
       ci++, compptr++) {
371
1.32k
    diff->diff_buf[ci] =
372
1.32k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.32k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.32k
                                         (long)compptr->h_samp_factor),
375
1.32k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.32k
    diff->undiff_buf[ci] =
377
1.32k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.32k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.32k
                                         (long)compptr->h_samp_factor),
380
1.32k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.32k
  }
382
383
435
  if (need_full_buffer) {
384
417
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
417
    int access_rows;
387
388
1.66k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.25k
         ci++, compptr++) {
390
1.25k
      access_rows = compptr->v_samp_factor;
391
1.25k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.25k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.25k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.25k
                               (long)compptr->h_samp_factor),
395
1.25k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.25k
                               (long)compptr->v_samp_factor),
397
1.25k
         (JDIMENSION)access_rows);
398
1.25k
    }
399
417
    diff->pub.consume_data = consume_data;
400
417
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
417
  } else {
405
18
    diff->pub.consume_data = dummy_consume_data;
406
18
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
18
  }
409
435
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */