Coverage Report

Created: 2025-07-23 08:18

/src/libjpeg-turbo/src/jddiffct.c
Line
Count
Source (jump to first uncovered line)
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
2.66M
{
68
2.66M
  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
2.66M
  if (cinfo->comps_in_scan > 1) {
75
939k
    diff->MCU_rows_per_iMCU_row = 1;
76
1.72M
  } else {
77
1.72M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
1.71M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
13.3k
    else
80
13.3k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
1.72M
  }
82
83
2.66M
  diff->MCU_ctr = 0;
84
2.66M
  diff->MCU_vert_offset = 0;
85
2.66M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
948k
{
68
948k
  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
948k
  if (cinfo->comps_in_scan > 1) {
75
343k
    diff->MCU_rows_per_iMCU_row = 1;
76
604k
  } else {
77
604k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
599k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
4.87k
    else
80
4.87k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
604k
  }
82
83
948k
  diff->MCU_ctr = 0;
84
948k
  diff->MCU_vert_offset = 0;
85
948k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
1.09M
{
68
1.09M
  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.09M
  if (cinfo->comps_in_scan > 1) {
75
227k
    diff->MCU_rows_per_iMCU_row = 1;
76
867k
  } else {
77
867k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
862k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
4.89k
    else
80
4.89k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
867k
  }
82
83
1.09M
  diff->MCU_ctr = 0;
84
1.09M
  diff->MCU_vert_offset = 0;
85
1.09M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
624k
{
68
624k
  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
624k
  if (cinfo->comps_in_scan > 1) {
75
369k
    diff->MCU_rows_per_iMCU_row = 1;
76
369k
  } else {
77
255k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
251k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
3.56k
    else
80
3.56k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
255k
  }
82
83
624k
  diff->MCU_ctr = 0;
84
624k
  diff->MCU_vert_offset = 0;
85
624k
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
49.8k
{
95
49.8k
  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
49.8k
  (*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
49.8k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
353
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
49.8k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
49.8k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
49.8k
  cinfo->input_iMCU_row = 0;
115
49.8k
  start_iMCU_row(cinfo);
116
49.8k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
25.7k
{
95
25.7k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
25.7k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
25.7k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
99
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
25.7k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
25.7k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
25.7k
  cinfo->input_iMCU_row = 0;
115
25.7k
  start_iMCU_row(cinfo);
116
25.7k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
12.1k
{
95
12.1k
  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
12.1k
  (*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
12.1k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
178
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
12.1k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
12.1k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
12.1k
  cinfo->input_iMCU_row = 0;
115
12.1k
  start_iMCU_row(cinfo);
116
12.1k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
11.9k
{
95
11.9k
  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
11.9k
  (*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
11.9k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
76
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
11.9k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
11.9k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
11.9k
  cinfo->input_iMCU_row = 0;
115
11.9k
  start_iMCU_row(cinfo);
116
11.9k
}
117
118
119
/*
120
 * Check for a restart marker & resynchronize decoder, undifferencer.
121
 * Returns FALSE if must suspend.
122
 */
123
124
METHODDEF(boolean)
125
process_restart(j_decompress_ptr cinfo)
126
7.68k
{
127
7.68k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
7.68k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
7.68k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
7.68k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
7.68k
  return TRUE;
138
7.68k
}
jddiffct-8.c:process_restart
Line
Count
Source
126
4.83k
{
127
4.83k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
4.83k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
4.83k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
4.83k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
4.83k
  return TRUE;
138
4.83k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
2.41k
{
127
2.41k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
2.41k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
2.41k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
2.41k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
2.41k
  return TRUE;
138
2.41k
}
jddiffct-16.c:process_restart
Line
Count
Source
126
438
{
127
438
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
438
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
438
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
438
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
438
  return TRUE;
138
438
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
28.2k
{
148
28.2k
  cinfo->output_iMCU_row = 0;
149
28.2k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
17.7k
{
148
17.7k
  cinfo->output_iMCU_row = 0;
149
17.7k
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
5.10k
{
148
5.10k
  cinfo->output_iMCU_row = 0;
149
5.10k
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
5.33k
{
148
5.33k
  cinfo->output_iMCU_row = 0;
149
5.33k
}
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
2.66M
{
165
2.66M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
2.66M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
2.66M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
2.66M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
2.66M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
2.66M
  int ci, compi, row, prev_row;
171
2.66M
  unsigned int yoffset;
172
2.66M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
8.91M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
6.25M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
6.25M
    if (cinfo->restart_interval) {
180
103k
      if (diff->restart_rows_to_go == 0)
181
7.68k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
103k
    }
184
185
6.25M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
6.25M
    MCU_count =
188
6.25M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
6.25M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
6.25M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
6.25M
    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
6.25M
    if (cinfo->restart_interval)
200
101k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
6.25M
    diff->MCU_ctr = 0;
204
6.25M
  }
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
7.50M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
4.83M
    compptr = cinfo->cur_comp_info[ci];
213
4.83M
    compi = compptr->component_index;
214
4.83M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
14.8M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
14.5M
                compptr->last_row_height : compptr->v_samp_factor);
217
10.0M
         prev_row = row, row++) {
218
10.0M
      (*losslessd->predict_undifference[compi])
219
10.0M
        (cinfo, compi, diff->diff_buf[compi][row],
220
10.0M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
10.0M
          compptr->width_in_blocks);
222
10.0M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
10.0M
                                  output_buf[compi][row],
224
10.0M
                                  compptr->width_in_blocks);
225
10.0M
    }
226
4.83M
  }
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
2.66M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
2.62M
    start_iMCU_row(cinfo);
236
2.62M
    return JPEG_ROW_COMPLETED;
237
2.62M
  }
238
  /* Completed the scan */
239
43.2k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
43.2k
  return JPEG_SCAN_COMPLETED;
241
2.66M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
948k
{
165
948k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
948k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
948k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
948k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
948k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
948k
  int ci, compi, row, prev_row;
171
948k
  unsigned int yoffset;
172
948k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
3.14M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
2.19M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
2.19M
    if (cinfo->restart_interval) {
180
30.9k
      if (diff->restart_rows_to_go == 0)
181
4.83k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
30.9k
    }
184
185
2.19M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
2.19M
    MCU_count =
188
2.19M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
2.19M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
2.19M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
2.19M
    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.19M
    if (cinfo->restart_interval)
200
29.7k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
2.19M
    diff->MCU_ctr = 0;
204
2.19M
  }
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.74M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
1.79M
    compptr = cinfo->cur_comp_info[ci];
213
1.79M
    compi = compptr->component_index;
214
1.79M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
5.52M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
5.34M
                compptr->last_row_height : compptr->v_samp_factor);
217
3.72M
         prev_row = row, row++) {
218
3.72M
      (*losslessd->predict_undifference[compi])
219
3.72M
        (cinfo, compi, diff->diff_buf[compi][row],
220
3.72M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
3.72M
          compptr->width_in_blocks);
222
3.72M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
3.72M
                                  output_buf[compi][row],
224
3.72M
                                  compptr->width_in_blocks);
225
3.72M
    }
226
1.79M
  }
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
948k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
924k
    start_iMCU_row(cinfo);
236
924k
    return JPEG_ROW_COMPLETED;
237
924k
  }
238
  /* Completed the scan */
239
23.3k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
23.3k
  return JPEG_SCAN_COMPLETED;
241
948k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
1.09M
{
165
1.09M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
1.09M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
1.09M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
1.09M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
1.09M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
1.09M
  int ci, compi, row, prev_row;
171
1.09M
  unsigned int yoffset;
172
1.09M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
4.26M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
3.17M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
3.17M
    if (cinfo->restart_interval) {
180
40.9k
      if (diff->restart_rows_to_go == 0)
181
2.41k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
40.9k
    }
184
185
3.17M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
3.17M
    MCU_count =
188
3.17M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
3.17M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
3.17M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
3.17M
    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.17M
    if (cinfo->restart_interval)
200
40.4k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
3.17M
    diff->MCU_ctr = 0;
204
3.17M
  }
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.65M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
1.56M
    compptr = cinfo->cur_comp_info[ci];
213
1.56M
    compi = compptr->component_index;
214
1.56M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
5.53M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
5.49M
                compptr->last_row_height : compptr->v_samp_factor);
217
3.97M
         prev_row = row, row++) {
218
3.97M
      (*losslessd->predict_undifference[compi])
219
3.97M
        (cinfo, compi, diff->diff_buf[compi][row],
220
3.97M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
3.97M
          compptr->width_in_blocks);
222
3.97M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
3.97M
                                  output_buf[compi][row],
224
3.97M
                                  compptr->width_in_blocks);
225
3.97M
    }
226
1.56M
  }
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.09M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
1.08M
    start_iMCU_row(cinfo);
236
1.08M
    return JPEG_ROW_COMPLETED;
237
1.08M
  }
238
  /* Completed the scan */
239
10.2k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
10.2k
  return JPEG_SCAN_COMPLETED;
241
1.09M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
624k
{
165
624k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
624k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
624k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
624k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
624k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
624k
  int ci, compi, row, prev_row;
171
624k
  unsigned int yoffset;
172
624k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
1.50M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
879k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
879k
    if (cinfo->restart_interval) {
180
31.9k
      if (diff->restart_rows_to_go == 0)
181
438
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
31.9k
    }
184
185
879k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
879k
    MCU_count =
188
879k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
879k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
879k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
879k
    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
879k
    if (cinfo->restart_interval)
200
31.7k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
879k
    diff->MCU_ctr = 0;
204
879k
  }
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.10M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
1.48M
    compptr = cinfo->cur_comp_info[ci];
213
1.48M
    compi = compptr->component_index;
214
1.48M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
3.78M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
3.73M
                compptr->last_row_height : compptr->v_samp_factor);
217
2.30M
         prev_row = row, row++) {
218
2.30M
      (*losslessd->predict_undifference[compi])
219
2.30M
        (cinfo, compi, diff->diff_buf[compi][row],
220
2.30M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
2.30M
          compptr->width_in_blocks);
222
2.30M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
2.30M
                                  output_buf[compi][row],
224
2.30M
                                  compptr->width_in_blocks);
225
2.30M
    }
226
1.48M
  }
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
624k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
614k
    start_iMCU_row(cinfo);
236
614k
    return JPEG_ROW_COMPLETED;
237
614k
  }
238
  /* Completed the scan */
239
9.65k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
9.65k
  return JPEG_SCAN_COMPLETED;
241
624k
}
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
2.03M
{
267
2.03M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
2.03M
  int ci, compi;
269
2.03M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
2.03M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
5.33M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
3.30M
    compptr = cinfo->cur_comp_info[ci];
275
3.30M
    compi = compptr->component_index;
276
3.30M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
3.30M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
3.30M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
3.30M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
3.30M
  }
281
282
2.03M
  return decompress_data(cinfo, buffer);
283
2.03M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
554k
{
267
554k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
554k
  int ci, compi;
269
554k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
554k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
1.59M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
1.04M
    compptr = cinfo->cur_comp_info[ci];
275
1.04M
    compi = compptr->component_index;
276
1.04M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
1.04M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
1.04M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
1.04M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
1.04M
  }
281
282
554k
  return decompress_data(cinfo, buffer);
283
554k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
1.04M
{
267
1.04M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
1.04M
  int ci, compi;
269
1.04M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
1.04M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
2.46M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
1.42M
    compptr = cinfo->cur_comp_info[ci];
275
1.42M
    compi = compptr->component_index;
276
1.42M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
1.42M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
1.42M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
1.42M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
1.42M
  }
281
282
1.04M
  return decompress_data(cinfo, buffer);
283
1.04M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
440k
{
267
440k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
440k
  int ci, compi;
269
440k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
440k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
1.27M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
832k
    compptr = cinfo->cur_comp_info[ci];
275
832k
    compi = compptr->component_index;
276
832k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
832k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
832k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
832k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
832k
  }
281
282
440k
  return decompress_data(cinfo, buffer);
283
440k
}
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
121k
{
297
121k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
121k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
121k
  int ci, samp_rows, row;
300
121k
  _JSAMPARRAY buffer;
301
121k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
121k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
121k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
121k
          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
589k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
468k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
468k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
468k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
468k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
468k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
468k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
448k
      samp_rows = compptr->v_samp_factor;
322
19.3k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
19.3k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
19.3k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
19.3k
    }
327
328
1.22M
    for (row = 0; row < samp_rows; row++) {
329
755k
      memcpy(output_buf[ci][row], buffer[row],
330
755k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
755k
    }
332
468k
  }
333
334
121k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
113k
    return JPEG_ROW_COMPLETED;
336
7.78k
  return JPEG_SCAN_COMPLETED;
337
121k
}
jddiffct-8.c:output_data
Line
Count
Source
296
63.4k
{
297
63.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
63.4k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
63.4k
  int ci, samp_rows, row;
300
63.4k
  _JSAMPARRAY buffer;
301
63.4k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
63.4k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
63.4k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
63.4k
          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
314k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
250k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
250k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
250k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
250k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
250k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
250k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
239k
      samp_rows = compptr->v_samp_factor;
322
11.2k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
11.2k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
11.2k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
11.2k
    }
327
328
706k
    for (row = 0; row < samp_rows; row++) {
329
455k
      memcpy(output_buf[ci][row], buffer[row],
330
455k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
455k
    }
332
250k
  }
333
334
63.4k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
60.4k
    return JPEG_ROW_COMPLETED;
336
3.04k
  return JPEG_SCAN_COMPLETED;
337
63.4k
}
jddiffct-12.c:output_data
Line
Count
Source
296
23.0k
{
297
23.0k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
23.0k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
23.0k
  int ci, samp_rows, row;
300
23.0k
  _JSAMPARRAY buffer;
301
23.0k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
23.0k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
23.0k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
23.0k
          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
108k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
85.2k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
85.2k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
85.2k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
85.2k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
85.2k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
85.2k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
79.9k
      samp_rows = compptr->v_samp_factor;
322
5.33k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
5.33k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
5.33k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
5.33k
    }
327
328
207k
    for (row = 0; row < samp_rows; row++) {
329
122k
      memcpy(output_buf[ci][row], buffer[row],
330
122k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
122k
    }
332
85.2k
  }
333
334
23.0k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
20.1k
    return JPEG_ROW_COMPLETED;
336
2.88k
  return JPEG_SCAN_COMPLETED;
337
23.0k
}
jddiffct-16.c:output_data
Line
Count
Source
296
34.9k
{
297
34.9k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
34.9k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
34.9k
  int ci, samp_rows, row;
300
34.9k
  _JSAMPARRAY buffer;
301
34.9k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
34.9k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
34.9k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
34.9k
          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
167k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
132k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
132k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
132k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
132k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
132k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
132k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
129k
      samp_rows = compptr->v_samp_factor;
322
2.82k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
2.82k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
2.82k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
2.82k
    }
327
328
309k
    for (row = 0; row < samp_rows; row++) {
329
177k
      memcpy(output_buf[ci][row], buffer[row],
330
177k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
177k
    }
332
132k
  }
333
334
34.9k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
33.1k
    return JPEG_ROW_COMPLETED;
336
1.85k
  return JPEG_SCAN_COMPLETED;
337
34.9k
}
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
44.0k
{
349
44.0k
  my_diff_ptr diff;
350
44.0k
  int ci;
351
44.0k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
21.9k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
22.0k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
22.0k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
44.0k
  diff = (my_diff_ptr)
362
44.0k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
44.0k
                                sizeof(my_diff_controller));
364
44.0k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
44.0k
  diff->pub.start_input_pass = start_input_pass;
366
44.0k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
246k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
202k
       ci++, compptr++) {
371
202k
    diff->diff_buf[ci] =
372
202k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
202k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
202k
                                         (long)compptr->h_samp_factor),
375
202k
                   (JDIMENSION)compptr->v_samp_factor);
376
202k
    diff->undiff_buf[ci] =
377
202k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
202k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
202k
                                         (long)compptr->h_samp_factor),
380
202k
                   (JDIMENSION)compptr->v_samp_factor);
381
202k
  }
382
383
44.0k
  if (need_full_buffer) {
384
22.8k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
22.8k
    int access_rows;
387
388
152k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
130k
         ci++, compptr++) {
390
130k
      access_rows = compptr->v_samp_factor;
391
130k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
130k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
130k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
130k
                               (long)compptr->h_samp_factor),
395
130k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
130k
                               (long)compptr->v_samp_factor),
397
130k
         (JDIMENSION)access_rows);
398
130k
    }
399
22.8k
    diff->pub.consume_data = consume_data;
400
22.8k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
22.8k
  } else {
405
21.2k
    diff->pub.consume_data = dummy_consume_data;
406
21.2k
    diff->pub._decompress_data = decompress_data;
407
21.2k
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
21.2k
  }
409
44.0k
}
jinit_d_diff_controller
Line
Count
Source
348
21.9k
{
349
21.9k
  my_diff_ptr diff;
350
21.9k
  int ci;
351
21.9k
  jpeg_component_info *compptr;
352
353
21.9k
#if BITS_IN_JSAMPLE == 8
354
21.9k
  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
21.9k
  diff = (my_diff_ptr)
362
21.9k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
21.9k
                                sizeof(my_diff_controller));
364
21.9k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
21.9k
  diff->pub.start_input_pass = start_input_pass;
366
21.9k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
102k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
81.0k
       ci++, compptr++) {
371
81.0k
    diff->diff_buf[ci] =
372
81.0k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
81.0k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
81.0k
                                         (long)compptr->h_samp_factor),
375
81.0k
                   (JDIMENSION)compptr->v_samp_factor);
376
81.0k
    diff->undiff_buf[ci] =
377
81.0k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
81.0k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
81.0k
                                         (long)compptr->h_samp_factor),
380
81.0k
                   (JDIMENSION)compptr->v_samp_factor);
381
81.0k
  }
382
383
21.9k
  if (need_full_buffer) {
384
5.29k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
5.29k
    int access_rows;
387
388
29.4k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
24.1k
         ci++, compptr++) {
390
24.1k
      access_rows = compptr->v_samp_factor;
391
24.1k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
24.1k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
24.1k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
24.1k
                               (long)compptr->h_samp_factor),
395
24.1k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
24.1k
                               (long)compptr->v_samp_factor),
397
24.1k
         (JDIMENSION)access_rows);
398
24.1k
    }
399
5.29k
    diff->pub.consume_data = consume_data;
400
5.29k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
16.6k
  } else {
405
16.6k
    diff->pub.consume_data = dummy_consume_data;
406
16.6k
    diff->pub._decompress_data = decompress_data;
407
16.6k
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
16.6k
  }
409
21.9k
}
j12init_d_diff_controller
Line
Count
Source
348
10.7k
{
349
10.7k
  my_diff_ptr diff;
350
10.7k
  int ci;
351
10.7k
  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
10.7k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
10.7k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
10.7k
  diff = (my_diff_ptr)
362
10.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
10.7k
                                sizeof(my_diff_controller));
364
10.7k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
10.7k
  diff->pub.start_input_pass = start_input_pass;
366
10.7k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
66.3k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
55.5k
       ci++, compptr++) {
371
55.5k
    diff->diff_buf[ci] =
372
55.5k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
55.5k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
55.5k
                                         (long)compptr->h_samp_factor),
375
55.5k
                   (JDIMENSION)compptr->v_samp_factor);
376
55.5k
    diff->undiff_buf[ci] =
377
55.5k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
55.5k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
55.5k
                                         (long)compptr->h_samp_factor),
380
55.5k
                   (JDIMENSION)compptr->v_samp_factor);
381
55.5k
  }
382
383
10.7k
  if (need_full_buffer) {
384
9.50k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
9.50k
    int access_rows;
387
388
61.3k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
51.8k
         ci++, compptr++) {
390
51.8k
      access_rows = compptr->v_samp_factor;
391
51.8k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
51.8k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
51.8k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
51.8k
                               (long)compptr->h_samp_factor),
395
51.8k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
51.8k
                               (long)compptr->v_samp_factor),
397
51.8k
         (JDIMENSION)access_rows);
398
51.8k
    }
399
9.50k
    diff->pub.consume_data = consume_data;
400
9.50k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
9.50k
  } else {
405
1.27k
    diff->pub.consume_data = dummy_consume_data;
406
1.27k
    diff->pub._decompress_data = decompress_data;
407
1.27k
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
1.27k
  }
409
10.7k
}
j16init_d_diff_controller
Line
Count
Source
348
11.3k
{
349
11.3k
  my_diff_ptr diff;
350
11.3k
  int ci;
351
11.3k
  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
11.3k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
11.3k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
11.3k
  diff = (my_diff_ptr)
362
11.3k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
11.3k
                                sizeof(my_diff_controller));
364
11.3k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
11.3k
  diff->pub.start_input_pass = start_input_pass;
366
11.3k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
77.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
65.7k
       ci++, compptr++) {
371
65.7k
    diff->diff_buf[ci] =
372
65.7k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
65.7k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
65.7k
                                         (long)compptr->h_samp_factor),
375
65.7k
                   (JDIMENSION)compptr->v_samp_factor);
376
65.7k
    diff->undiff_buf[ci] =
377
65.7k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
65.7k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
65.7k
                                         (long)compptr->h_samp_factor),
380
65.7k
                   (JDIMENSION)compptr->v_samp_factor);
381
65.7k
  }
382
383
11.3k
  if (need_full_buffer) {
384
8.03k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
8.03k
    int access_rows;
387
388
62.1k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
54.1k
         ci++, compptr++) {
390
54.1k
      access_rows = compptr->v_samp_factor;
391
54.1k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
54.1k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
54.1k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
54.1k
                               (long)compptr->h_samp_factor),
395
54.1k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
54.1k
                               (long)compptr->v_samp_factor),
397
54.1k
         (JDIMENSION)access_rows);
398
54.1k
    }
399
8.03k
    diff->pub.consume_data = consume_data;
400
8.03k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
8.03k
  } else {
405
3.28k
    diff->pub.consume_data = dummy_consume_data;
406
3.28k
    diff->pub._decompress_data = decompress_data;
407
3.28k
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
3.28k
  }
409
11.3k
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */