Coverage Report

Created: 2026-01-10 06:49

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.67k
    else
80
2.67k
      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.16M
{
68
1.16M
  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.16M
  if (cinfo->comps_in_scan > 1) {
75
301k
    diff->MCU_rows_per_iMCU_row = 1;
76
858k
  } else {
77
858k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
858k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
683
    else
80
683
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
858k
  }
82
83
1.16M
  diff->MCU_ctr = 0;
84
1.16M
  diff->MCU_vert_offset = 0;
85
1.16M
}
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
352k
    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
896
    else
80
896
      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.37M
{
68
9.37M
  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.37M
  if (cinfo->comps_in_scan > 1) {
75
551k
    diff->MCU_rows_per_iMCU_row = 1;
76
8.82M
  } else {
77
8.82M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
8.82M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.09k
    else
80
1.09k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
8.82M
  }
82
83
9.37M
  diff->MCU_ctr = 0;
84
9.37M
  diff->MCU_vert_offset = 0;
85
9.37M
}
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.40k
{
95
4.40k
  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.40k
  (*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.40k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
24
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
4.40k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
4.40k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
4.40k
  cinfo->input_iMCU_row = 0;
115
4.40k
  start_iMCU_row(cinfo);
116
4.40k
}
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.44k
{
95
1.44k
  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.44k
  (*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.44k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
3
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.44k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.44k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.44k
  cinfo->input_iMCU_row = 0;
115
1.44k
  start_iMCU_row(cinfo);
116
1.44k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
1.67k
{
95
1.67k
  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.67k
  (*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.67k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
11
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.67k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.67k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.67k
  cinfo->input_iMCU_row = 0;
115
1.67k
  start_iMCU_row(cinfo);
116
1.67k
}
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.05k
{
148
1.05k
  cinfo->output_iMCU_row = 0;
149
1.05k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
327
{
148
327
  cinfo->output_iMCU_row = 0;
149
327
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
371
{
148
371
  cinfo->output_iMCU_row = 0;
149
371
}
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
27.9M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
15.8M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
15.8M
    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.8M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
15.8M
    MCU_count =
188
15.8M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
15.8M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
15.8M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
15.8M
    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.8M
    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.8M
    diff->MCU_ctr = 0;
204
15.8M
  }
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.4M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
13.3M
    compptr = cinfo->cur_comp_info[ci];
213
13.3M
    compi = compptr->component_index;
214
13.3M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
32.1M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
32.1M
                compptr->last_row_height : compptr->v_samp_factor);
217
18.7M
         prev_row = row, row++) {
218
18.7M
      (*losslessd->predict_undifference[compi])
219
18.7M
        (cinfo, compi, diff->diff_buf[compi][row],
220
18.7M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
18.7M
          compptr->width_in_blocks);
222
18.7M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
18.7M
                                  output_buf[compi][row],
224
18.7M
                                  compptr->width_in_blocks);
225
18.7M
    }
226
13.3M
  }
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.27k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
4.27k
  return JPEG_SCAN_COMPLETED;
241
12.1M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
1.16M
{
165
1.16M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
1.16M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
1.16M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
1.16M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
1.16M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
1.16M
  int ci, compi, row, prev_row;
171
1.16M
  unsigned int yoffset;
172
1.16M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
3.38M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
2.22M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
2.22M
    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.22M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
2.22M
    MCU_count =
188
2.22M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
2.22M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
2.22M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
2.22M
    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.22M
    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.22M
    diff->MCU_ctr = 0;
204
2.22M
  }
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.62M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
1.46M
    compptr = cinfo->cur_comp_info[ci];
213
1.46M
    compi = compptr->component_index;
214
1.46M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
4.52M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
4.52M
                compptr->last_row_height : compptr->v_samp_factor);
217
3.05M
         prev_row = row, row++) {
218
3.05M
      (*losslessd->predict_undifference[compi])
219
3.05M
        (cinfo, compi, diff->diff_buf[compi][row],
220
3.05M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
3.05M
          compptr->width_in_blocks);
222
3.05M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
3.05M
                                  output_buf[compi][row],
224
3.05M
                                  compptr->width_in_blocks);
225
3.05M
    }
226
1.46M
  }
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.16M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
1.15M
    start_iMCU_row(cinfo);
236
1.15M
    return JPEG_ROW_COMPLETED;
237
1.15M
  }
238
  /* Completed the scan */
239
1.24k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.24k
  return JPEG_SCAN_COMPLETED;
241
1.16M
}
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.62M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
3.04M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
3.04M
    if (cinfo->restart_interval) {
180
961k
      if (diff->restart_rows_to_go == 0)
181
153k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
961k
    }
184
185
3.04M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
3.04M
    MCU_count =
188
3.04M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
3.04M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
3.04M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
3.04M
    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.04M
    if (cinfo->restart_interval)
200
961k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
3.04M
    diff->MCU_ctr = 0;
204
3.04M
  }
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.52M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
1.93M
    compptr = cinfo->cur_comp_info[ci];
213
1.93M
    compi = compptr->component_index;
214
1.93M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
5.81M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
5.80M
                compptr->last_row_height : compptr->v_samp_factor);
217
3.87M
         prev_row = row, row++) {
218
3.87M
      (*losslessd->predict_undifference[compi])
219
3.87M
        (cinfo, compi, diff->diff_buf[compi][row],
220
3.87M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
3.87M
          compptr->width_in_blocks);
222
3.87M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
3.87M
                                  output_buf[compi][row],
224
3.87M
                                  compptr->width_in_blocks);
225
3.87M
    }
226
1.93M
  }
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.37M
{
165
9.37M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
9.37M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
9.37M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
9.37M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
9.37M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
9.37M
  int ci, compi, row, prev_row;
171
9.37M
  unsigned int yoffset;
172
9.37M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
19.9M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
10.5M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
10.5M
    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.5M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
10.5M
    MCU_count =
188
10.5M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
10.5M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
10.5M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
10.5M
    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.5M
    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.5M
    diff->MCU_ctr = 0;
204
10.5M
  }
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.94M
    compptr = cinfo->cur_comp_info[ci];
213
9.94M
    compi = compptr->component_index;
214
9.94M
    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.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
9.37M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
9.37M
    start_iMCU_row(cinfo);
236
9.37M
    return JPEG_ROW_COMPLETED;
237
9.37M
  }
238
  /* Completed the scan */
239
1.62k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.62k
  return JPEG_SCAN_COMPLETED;
241
9.37M
}
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.0M
{
267
12.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
12.0M
  int ci, compi;
269
12.0M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
12.0M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
25.3M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
13.2M
    compptr = cinfo->cur_comp_info[ci];
275
13.2M
    compi = compptr->component_index;
276
13.2M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
13.2M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
13.2M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
13.2M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
13.2M
  }
281
282
12.0M
  return decompress_data(cinfo, buffer);
283
12.0M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
1.15M
{
267
1.15M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
1.15M
  int ci, compi;
269
1.15M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
1.15M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
2.60M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
1.44M
    compptr = cinfo->cur_comp_info[ci];
275
1.44M
    compi = compptr->component_index;
276
1.44M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
1.44M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
1.44M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
1.44M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
1.44M
  }
281
282
1.15M
  return decompress_data(cinfo, buffer);
283
1.15M
}
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.51M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
1.93M
    compptr = cinfo->cur_comp_info[ci];
275
1.93M
    compi = compptr->component_index;
276
1.93M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
1.93M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
1.93M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
1.93M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
1.93M
  }
281
282
1.58M
  return decompress_data(cinfo, buffer);
283
1.58M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
9.35M
{
267
9.35M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
9.35M
  int ci, compi;
269
9.35M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
9.35M
  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.88M
    compptr = cinfo->cur_comp_info[ci];
275
9.88M
    compi = compptr->component_index;
276
9.88M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
9.88M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
9.88M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
9.88M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
9.88M
  }
281
282
9.35M
  return decompress_data(cinfo, buffer);
283
9.35M
}
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
787
  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
307
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
307
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
307
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
307
    }
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
245
  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
369
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
369
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
369
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
369
    }
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
276
  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
348
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
348
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
348
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
348
    }
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
266
  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.38k
{
349
1.38k
  my_diff_ptr diff;
350
1.38k
  int ci;
351
1.38k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
423
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
960
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
960
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.38k
  diff = (my_diff_ptr)
362
1.38k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.38k
                                sizeof(my_diff_controller));
364
1.38k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.38k
  diff->pub.start_input_pass = start_input_pass;
366
1.38k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
5.53k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.14k
       ci++, compptr++) {
371
4.14k
    diff->diff_buf[ci] =
372
4.14k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.14k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.14k
                                         (long)compptr->h_samp_factor),
375
4.14k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.14k
    diff->undiff_buf[ci] =
377
4.14k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.14k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.14k
                                         (long)compptr->h_samp_factor),
380
4.14k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.14k
  }
382
383
1.38k
  if (need_full_buffer) {
384
1.18k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.18k
    int access_rows;
387
388
4.75k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.56k
         ci++, compptr++) {
390
3.56k
      access_rows = compptr->v_samp_factor;
391
3.56k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.56k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.56k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.56k
                               (long)compptr->h_samp_factor),
395
3.56k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.56k
                               (long)compptr->v_samp_factor),
397
3.56k
         (JDIMENSION)access_rows);
398
3.56k
    }
399
1.18k
    diff->pub.consume_data = consume_data;
400
1.18k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.18k
  } else {
405
194
    diff->pub.consume_data = dummy_consume_data;
406
194
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
194
  }
409
1.38k
}
jinit_d_diff_controller
Line
Count
Source
348
423
{
349
423
  my_diff_ptr diff;
350
423
  int ci;
351
423
  jpeg_component_info *compptr;
352
353
423
#if BITS_IN_JSAMPLE == 8
354
423
  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
423
  diff = (my_diff_ptr)
362
423
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
423
                                sizeof(my_diff_controller));
364
423
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
423
  diff->pub.start_input_pass = start_input_pass;
366
423
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.69k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.26k
       ci++, compptr++) {
371
1.26k
    diff->diff_buf[ci] =
372
1.26k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.26k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.26k
                                         (long)compptr->h_samp_factor),
375
1.26k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.26k
    diff->undiff_buf[ci] =
377
1.26k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.26k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.26k
                                         (long)compptr->h_samp_factor),
380
1.26k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.26k
  }
382
383
423
  if (need_full_buffer) {
384
386
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
386
    int access_rows;
387
388
1.54k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.15k
         ci++, compptr++) {
390
1.15k
      access_rows = compptr->v_samp_factor;
391
1.15k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.15k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.15k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.15k
                               (long)compptr->h_samp_factor),
395
1.15k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.15k
                               (long)compptr->v_samp_factor),
397
1.15k
         (JDIMENSION)access_rows);
398
1.15k
    }
399
386
    diff->pub.consume_data = consume_data;
400
386
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
386
  } 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
423
}
j12init_d_diff_controller
Line
Count
Source
348
468
{
349
468
  my_diff_ptr diff;
350
468
  int ci;
351
468
  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
468
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
468
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
468
  diff = (my_diff_ptr)
362
468
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
468
                                sizeof(my_diff_controller));
364
468
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
468
  diff->pub.start_input_pass = start_input_pass;
366
468
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.87k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.40k
       ci++, compptr++) {
371
1.40k
    diff->diff_buf[ci] =
372
1.40k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.40k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.40k
                                         (long)compptr->h_samp_factor),
375
1.40k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.40k
    diff->undiff_buf[ci] =
377
1.40k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.40k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.40k
                                         (long)compptr->h_samp_factor),
380
1.40k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.40k
  }
382
383
468
  if (need_full_buffer) {
384
415
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
415
    int access_rows;
387
388
1.66k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.24k
         ci++, compptr++) {
390
1.24k
      access_rows = compptr->v_samp_factor;
391
1.24k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.24k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.24k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.24k
                               (long)compptr->h_samp_factor),
395
1.24k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.24k
                               (long)compptr->v_samp_factor),
397
1.24k
         (JDIMENSION)access_rows);
398
1.24k
    }
399
415
    diff->pub.consume_data = consume_data;
400
415
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
415
  } 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
468
}
j16init_d_diff_controller
Line
Count
Source
348
492
{
349
492
  my_diff_ptr diff;
350
492
  int ci;
351
492
  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
492
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
492
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
492
  diff = (my_diff_ptr)
362
492
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
492
                                sizeof(my_diff_controller));
364
492
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
492
  diff->pub.start_input_pass = start_input_pass;
366
492
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.96k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.47k
       ci++, compptr++) {
371
1.47k
    diff->diff_buf[ci] =
372
1.47k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.47k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.47k
                                         (long)compptr->h_samp_factor),
375
1.47k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.47k
    diff->undiff_buf[ci] =
377
1.47k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.47k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.47k
                                         (long)compptr->h_samp_factor),
380
1.47k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.47k
  }
382
383
492
  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
104
    diff->pub.consume_data = dummy_consume_data;
406
104
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
104
  }
409
492
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */