Coverage Report

Created: 2026-01-09 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.dev/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
12.1M
{
68
12.1M
  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
12.1M
  if (cinfo->comps_in_scan > 1) {
75
1.20M
    diff->MCU_rows_per_iMCU_row = 1;
76
10.9M
  } else {
77
10.9M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
10.9M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
2.68k
    else
80
2.68k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
10.9M
  }
82
83
12.1M
  diff->MCU_ctr = 0;
84
12.1M
  diff->MCU_vert_offset = 0;
85
12.1M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
1.19M
{
68
1.19M
  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
1.19M
  if (cinfo->comps_in_scan > 1) {
75
301k
    diff->MCU_rows_per_iMCU_row = 1;
76
891k
  } else {
77
891k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
890k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
685
    else
80
685
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
891k
  }
82
83
1.19M
  diff->MCU_ctr = 0;
84
1.19M
  diff->MCU_vert_offset = 0;
85
1.19M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
1.58M
{
68
1.58M
  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
1.58M
  if (cinfo->comps_in_scan > 1) {
75
354k
    diff->MCU_rows_per_iMCU_row = 1;
76
1.23M
  } else {
77
1.23M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
1.23M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
899
    else
80
899
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
1.23M
  }
82
83
1.58M
  diff->MCU_ctr = 0;
84
1.58M
  diff->MCU_vert_offset = 0;
85
1.58M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
9.38M
{
68
9.38M
  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
9.38M
  if (cinfo->comps_in_scan > 1) {
75
551k
    diff->MCU_rows_per_iMCU_row = 1;
76
8.83M
  } else {
77
8.83M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
8.83M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.10k
    else
80
1.10k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
8.83M
  }
82
83
9.38M
  diff->MCU_ctr = 0;
84
9.38M
  diff->MCU_vert_offset = 0;
85
9.38M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
4.41k
{
95
4.41k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
4.41k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
4.41k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
24
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
4.41k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
4.41k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
4.41k
  cinfo->input_iMCU_row = 0;
115
4.41k
  start_iMCU_row(cinfo);
116
4.41k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
1.28k
{
95
1.28k
  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.28k
  (*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.28k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
10
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.28k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.28k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.28k
  cinfo->input_iMCU_row = 0;
115
1.28k
  start_iMCU_row(cinfo);
116
1.28k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
1.45k
{
95
1.45k
  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.45k
  (*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.45k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
3
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.45k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.45k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.45k
  cinfo->input_iMCU_row = 0;
115
1.45k
  start_iMCU_row(cinfo);
116
1.45k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
1.68k
{
95
1.68k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
1.68k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
1.68k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
11
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.68k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.68k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.68k
  cinfo->input_iMCU_row = 0;
115
1.68k
  start_iMCU_row(cinfo);
116
1.68k
}
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
317k
{
127
317k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
317k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
317k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
317k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
317k
  return TRUE;
138
317k
}
jddiffct-8.c:process_restart
Line
Count
Source
126
28.4k
{
127
28.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
28.4k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
28.4k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
28.4k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
28.4k
  return TRUE;
138
28.4k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
153k
{
127
153k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
153k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
153k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
153k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
153k
  return TRUE;
138
153k
}
jddiffct-16.c:process_restart
Line
Count
Source
126
135k
{
127
135k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
135k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
135k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
135k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
135k
  return TRUE;
138
135k
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
1.06k
{
148
1.06k
  cinfo->output_iMCU_row = 0;
149
1.06k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
329
{
148
329
  cinfo->output_iMCU_row = 0;
149
329
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
375
{
148
375
  cinfo->output_iMCU_row = 0;
149
375
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
361
{
148
361
  cinfo->output_iMCU_row = 0;
149
361
}
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
12.1M
{
165
12.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
12.1M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
12.1M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
12.1M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
12.1M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
12.1M
  int ci, compi, row, prev_row;
171
12.1M
  unsigned int yoffset;
172
12.1M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
28.1M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
15.9M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
15.9M
    if (cinfo->restart_interval) {
180
2.06M
      if (diff->restart_rows_to_go == 0)
181
317k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
2.06M
    }
184
185
15.9M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
15.9M
    MCU_count =
188
15.9M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
15.9M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
15.9M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
15.9M
    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
15.9M
    if (cinfo->restart_interval)
200
2.06M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
15.9M
    diff->MCU_ctr = 0;
204
15.9M
  }
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
25.5M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
13.4M
    compptr = cinfo->cur_comp_info[ci];
213
13.4M
    compi = compptr->component_index;
214
13.4M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
32.3M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
32.2M
                compptr->last_row_height : compptr->v_samp_factor);
217
18.9M
         prev_row = row, row++) {
218
18.9M
      (*losslessd->predict_undifference[compi])
219
18.9M
        (cinfo, compi, diff->diff_buf[compi][row],
220
18.9M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
18.9M
          compptr->width_in_blocks);
222
18.9M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
18.9M
                                  output_buf[compi][row],
224
18.9M
                                  compptr->width_in_blocks);
225
18.9M
    }
226
13.4M
  }
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
12.1M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
12.1M
    start_iMCU_row(cinfo);
236
12.1M
    return JPEG_ROW_COMPLETED;
237
12.1M
  }
238
  /* Completed the scan */
239
4.29k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
4.29k
  return JPEG_SCAN_COMPLETED;
241
12.1M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
1.19M
{
165
1.19M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
1.19M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
1.19M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
1.19M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
1.19M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
1.19M
  int ci, compi, row, prev_row;
171
1.19M
  unsigned int yoffset;
172
1.19M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
3.48M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
2.29M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
2.29M
    if (cinfo->restart_interval) {
180
179k
      if (diff->restart_rows_to_go == 0)
181
28.4k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
179k
    }
184
185
2.29M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
2.29M
    MCU_count =
188
2.29M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
2.29M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
2.29M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
2.29M
    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
2.29M
    if (cinfo->restart_interval)
200
179k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
2.29M
    diff->MCU_ctr = 0;
204
2.29M
  }
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
2.69M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
1.50M
    compptr = cinfo->cur_comp_info[ci];
213
1.50M
    compi = compptr->component_index;
214
1.50M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
4.62M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
4.61M
                compptr->last_row_height : compptr->v_samp_factor);
217
3.12M
         prev_row = row, row++) {
218
3.12M
      (*losslessd->predict_undifference[compi])
219
3.12M
        (cinfo, compi, diff->diff_buf[compi][row],
220
3.12M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
3.12M
          compptr->width_in_blocks);
222
3.12M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
3.12M
                                  output_buf[compi][row],
224
3.12M
                                  compptr->width_in_blocks);
225
3.12M
    }
226
1.50M
  }
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
1.19M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
1.19M
    start_iMCU_row(cinfo);
236
1.19M
    return JPEG_ROW_COMPLETED;
237
1.19M
  }
238
  /* Completed the scan */
239
1.24k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.24k
  return JPEG_SCAN_COMPLETED;
241
1.19M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
1.58M
{
165
1.58M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
1.58M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
1.58M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
1.58M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
1.58M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
1.58M
  int ci, compi, row, prev_row;
171
1.58M
  unsigned int yoffset;
172
1.58M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
4.64M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
3.05M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
3.05M
    if (cinfo->restart_interval) {
180
963k
      if (diff->restart_rows_to_go == 0)
181
153k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
963k
    }
184
185
3.05M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
3.05M
    MCU_count =
188
3.05M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
3.05M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
3.05M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
3.05M
    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
3.05M
    if (cinfo->restart_interval)
200
963k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
3.05M
    diff->MCU_ctr = 0;
204
3.05M
  }
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
3.53M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
1.94M
    compptr = cinfo->cur_comp_info[ci];
213
1.94M
    compi = compptr->component_index;
214
1.94M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
5.83M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
5.82M
                compptr->last_row_height : compptr->v_samp_factor);
217
3.88M
         prev_row = row, row++) {
218
3.88M
      (*losslessd->predict_undifference[compi])
219
3.88M
        (cinfo, compi, diff->diff_buf[compi][row],
220
3.88M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
3.88M
          compptr->width_in_blocks);
222
3.88M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
3.88M
                                  output_buf[compi][row],
224
3.88M
                                  compptr->width_in_blocks);
225
3.88M
    }
226
1.94M
  }
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
1.58M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
1.58M
    start_iMCU_row(cinfo);
236
1.58M
    return JPEG_ROW_COMPLETED;
237
1.58M
  }
238
  /* Completed the scan */
239
1.41k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.41k
  return JPEG_SCAN_COMPLETED;
241
1.58M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
9.38M
{
165
9.38M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
9.38M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
9.38M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
9.38M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
9.38M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
9.38M
  int ci, compi, row, prev_row;
171
9.38M
  unsigned int yoffset;
172
9.38M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
20.0M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
10.6M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
10.6M
    if (cinfo->restart_interval) {
180
920k
      if (diff->restart_rows_to_go == 0)
181
135k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
920k
    }
184
185
10.6M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
10.6M
    MCU_count =
188
10.6M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
10.6M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
10.6M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
10.6M
    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
10.6M
    if (cinfo->restart_interval)
200
920k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
10.6M
    diff->MCU_ctr = 0;
204
10.6M
  }
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
19.3M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
9.95M
    compptr = cinfo->cur_comp_info[ci];
213
9.95M
    compi = compptr->component_index;
214
9.95M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
21.8M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
21.8M
                compptr->last_row_height : compptr->v_samp_factor);
217
11.8M
         prev_row = row, row++) {
218
11.8M
      (*losslessd->predict_undifference[compi])
219
11.8M
        (cinfo, compi, diff->diff_buf[compi][row],
220
11.8M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
11.8M
          compptr->width_in_blocks);
222
11.8M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
11.8M
                                  output_buf[compi][row],
224
11.8M
                                  compptr->width_in_blocks);
225
11.8M
    }
226
9.95M
  }
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
9.38M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
9.38M
    start_iMCU_row(cinfo);
236
9.38M
    return JPEG_ROW_COMPLETED;
237
9.38M
  }
238
  /* Completed the scan */
239
1.62k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.62k
  return JPEG_SCAN_COMPLETED;
241
9.38M
}
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
12.1M
{
267
12.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
12.1M
  int ci, compi;
269
12.1M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
12.1M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
25.4M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
13.3M
    compptr = cinfo->cur_comp_info[ci];
275
13.3M
    compi = compptr->component_index;
276
13.3M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
13.3M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
13.3M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
13.3M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
13.3M
  }
281
282
12.1M
  return decompress_data(cinfo, buffer);
283
12.1M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
1.18M
{
267
1.18M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
1.18M
  int ci, compi;
269
1.18M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
1.18M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
2.66M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
1.48M
    compptr = cinfo->cur_comp_info[ci];
275
1.48M
    compi = compptr->component_index;
276
1.48M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
1.48M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
1.48M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
1.48M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
1.48M
  }
281
282
1.18M
  return decompress_data(cinfo, buffer);
283
1.18M
}
jddiffct-12.c:consume_data
Line
Count
Source
266
1.58M
{
267
1.58M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
1.58M
  int ci, compi;
269
1.58M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
1.58M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
3.52M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
1.94M
    compptr = cinfo->cur_comp_info[ci];
275
1.94M
    compi = compptr->component_index;
276
1.94M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
1.94M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
1.94M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
1.94M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
1.94M
  }
281
282
1.58M
  return decompress_data(cinfo, buffer);
283
1.58M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
9.36M
{
267
9.36M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
9.36M
  int ci, compi;
269
9.36M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
9.36M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
19.2M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
9.89M
    compptr = cinfo->cur_comp_info[ci];
275
9.89M
    compi = compptr->component_index;
276
9.89M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
9.89M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
9.89M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
9.89M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
9.89M
  }
281
282
9.36M
  return decompress_data(cinfo, buffer);
283
9.36M
}
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
497k
{
297
497k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
497k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
497k
  int ci, samp_rows, row;
300
497k
  _JSAMPARRAY buffer;
301
497k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
497k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
497k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
497k
          cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
307
0
    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
308
0
      return JPEG_SUSPENDED;
309
0
  }
310
311
  /* OK, output from the virtual arrays. */
312
1.98M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
1.49M
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
1.49M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
1.49M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
1.49M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
1.49M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
1.49M
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1.48M
      samp_rows = compptr->v_samp_factor;
322
1.02k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1.02k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1.02k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1.02k
    }
327
328
3.82M
    for (row = 0; row < samp_rows; row++) {
329
2.33M
      memcpy(output_buf[ci][row], buffer[row],
330
2.33M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
2.33M
    }
332
1.49M
  }
333
334
497k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
496k
    return JPEG_ROW_COMPLETED;
336
792
  return JPEG_SCAN_COMPLETED;
337
497k
}
jddiffct-8.c:output_data
Line
Count
Source
296
109k
{
297
109k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
109k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
109k
  int ci, samp_rows, row;
300
109k
  _JSAMPARRAY buffer;
301
109k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
109k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
109k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
109k
          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
437k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
328k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
328k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
328k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
328k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
328k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
328k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
327k
      samp_rows = compptr->v_samp_factor;
322
309
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
309
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
309
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
309
    }
327
328
897k
    for (row = 0; row < samp_rows; row++) {
329
569k
      memcpy(output_buf[ci][row], buffer[row],
330
569k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
569k
    }
332
328k
  }
333
334
109k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
109k
    return JPEG_ROW_COMPLETED;
336
247
  return JPEG_SCAN_COMPLETED;
337
109k
}
jddiffct-12.c:output_data
Line
Count
Source
296
199k
{
297
199k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
199k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
199k
  int ci, samp_rows, row;
300
199k
  _JSAMPARRAY buffer;
301
199k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
199k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
199k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
199k
          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
795k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
596k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
596k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
596k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
596k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
596k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
596k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
596k
      samp_rows = compptr->v_samp_factor;
322
375
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
375
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
375
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
375
    }
327
328
1.53M
    for (row = 0; row < samp_rows; row++) {
329
935k
      memcpy(output_buf[ci][row], buffer[row],
330
935k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
935k
    }
332
596k
  }
333
334
199k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
198k
    return JPEG_ROW_COMPLETED;
336
280
  return JPEG_SCAN_COMPLETED;
337
199k
}
jddiffct-16.c:output_data
Line
Count
Source
296
188k
{
297
188k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
188k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
188k
  int ci, samp_rows, row;
300
188k
  _JSAMPARRAY buffer;
301
188k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
188k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
188k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
188k
          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
754k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
565k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
565k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
565k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
565k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
565k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
565k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
565k
      samp_rows = compptr->v_samp_factor;
322
345
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
345
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
345
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
345
    }
327
328
1.39M
    for (row = 0; row < samp_rows; row++) {
329
827k
      memcpy(output_buf[ci][row], buffer[row],
330
827k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
827k
    }
332
565k
  }
333
334
188k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
188k
    return JPEG_ROW_COMPLETED;
336
265
  return JPEG_SCAN_COMPLETED;
337
188k
}
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.39k
{
349
1.39k
  my_diff_ptr diff;
350
1.39k
  int ci;
351
1.39k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
425
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
967
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
967
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.39k
  diff = (my_diff_ptr)
362
1.39k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.39k
                                sizeof(my_diff_controller));
364
1.39k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.39k
  diff->pub.start_input_pass = start_input_pass;
366
1.39k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
5.56k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.17k
       ci++, compptr++) {
371
4.17k
    diff->diff_buf[ci] =
372
4.17k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.17k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.17k
                                         (long)compptr->h_samp_factor),
375
4.17k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.17k
    diff->undiff_buf[ci] =
377
4.17k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.17k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.17k
                                         (long)compptr->h_samp_factor),
380
4.17k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.17k
  }
382
383
1.39k
  if (need_full_buffer) {
384
1.19k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.19k
    int access_rows;
387
388
4.78k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.59k
         ci++, compptr++) {
390
3.59k
      access_rows = compptr->v_samp_factor;
391
3.59k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.59k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.59k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.59k
                               (long)compptr->h_samp_factor),
395
3.59k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.59k
                               (long)compptr->v_samp_factor),
397
3.59k
         (JDIMENSION)access_rows);
398
3.59k
    }
399
1.19k
    diff->pub.consume_data = consume_data;
400
1.19k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.19k
  } else {
405
195
    diff->pub.consume_data = dummy_consume_data;
406
195
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
195
  }
409
1.39k
}
jinit_d_diff_controller
Line
Count
Source
348
425
{
349
425
  my_diff_ptr diff;
350
425
  int ci;
351
425
  jpeg_component_info *compptr;
352
353
425
#if BITS_IN_JSAMPLE == 8
354
425
  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
425
  diff = (my_diff_ptr)
362
425
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
425
                                sizeof(my_diff_controller));
364
425
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
425
  diff->pub.start_input_pass = start_input_pass;
366
425
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.70k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.27k
       ci++, compptr++) {
371
1.27k
    diff->diff_buf[ci] =
372
1.27k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.27k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.27k
                                         (long)compptr->h_samp_factor),
375
1.27k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.27k
    diff->undiff_buf[ci] =
377
1.27k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.27k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.27k
                                         (long)compptr->h_samp_factor),
380
1.27k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.27k
  }
382
383
425
  if (need_full_buffer) {
384
388
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
388
    int access_rows;
387
388
1.55k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.16k
         ci++, compptr++) {
390
1.16k
      access_rows = compptr->v_samp_factor;
391
1.16k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.16k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.16k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.16k
                               (long)compptr->h_samp_factor),
395
1.16k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.16k
                               (long)compptr->v_samp_factor),
397
1.16k
         (JDIMENSION)access_rows);
398
1.16k
    }
399
388
    diff->pub.consume_data = consume_data;
400
388
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
388
  } else {
405
37
    diff->pub.consume_data = dummy_consume_data;
406
37
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
37
  }
409
425
}
j12init_d_diff_controller
Line
Count
Source
348
473
{
349
473
  my_diff_ptr diff;
350
473
  int ci;
351
473
  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
473
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
473
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
473
  diff = (my_diff_ptr)
362
473
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
473
                                sizeof(my_diff_controller));
364
473
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
473
  diff->pub.start_input_pass = start_input_pass;
366
473
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.89k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.41k
       ci++, compptr++) {
371
1.41k
    diff->diff_buf[ci] =
372
1.41k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.41k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.41k
                                         (long)compptr->h_samp_factor),
375
1.41k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.41k
    diff->undiff_buf[ci] =
377
1.41k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.41k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.41k
                                         (long)compptr->h_samp_factor),
380
1.41k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.41k
  }
382
383
473
  if (need_full_buffer) {
384
420
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
420
    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
420
    diff->pub.consume_data = consume_data;
400
420
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
420
  } else {
405
53
    diff->pub.consume_data = dummy_consume_data;
406
53
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
53
  }
409
473
}
j16init_d_diff_controller
Line
Count
Source
348
494
{
349
494
  my_diff_ptr diff;
350
494
  int ci;
351
494
  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
494
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
494
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
494
  diff = (my_diff_ptr)
362
494
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
494
                                sizeof(my_diff_controller));
364
494
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
494
  diff->pub.start_input_pass = start_input_pass;
366
494
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.97k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.48k
       ci++, compptr++) {
371
1.48k
    diff->diff_buf[ci] =
372
1.48k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.48k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.48k
                                         (long)compptr->h_samp_factor),
375
1.48k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.48k
    diff->undiff_buf[ci] =
377
1.48k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.48k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.48k
                                         (long)compptr->h_samp_factor),
380
1.48k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.48k
  }
382
383
494
  if (need_full_buffer) {
384
389
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
389
    int access_rows;
387
388
1.55k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.16k
         ci++, compptr++) {
390
1.16k
      access_rows = compptr->v_samp_factor;
391
1.16k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.16k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.16k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.16k
                               (long)compptr->h_samp_factor),
395
1.16k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.16k
                               (long)compptr->v_samp_factor),
397
1.16k
         (JDIMENSION)access_rows);
398
1.16k
    }
399
389
    diff->pub.consume_data = consume_data;
400
389
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
389
  } else {
405
105
    diff->pub.consume_data = dummy_consume_data;
406
105
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
105
  }
409
494
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */