Coverage Report

Created: 2026-11-12 07:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo/src/jddiffct.c
Line
Count
Source
1
/*
2
 * jddiffct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1997, Thomas G. Lane.
6
 * Lossless JPEG Modifications:
7
 * Copyright (C) 1999, Ken Murchison.
8
 * libjpeg-turbo Modifications:
9
 * Copyright (C) 2022, 2024, D. R. Commander.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the [un]difference buffer controller for decompression.
14
 * This controller is the top level of the lossless JPEG decompressor proper.
15
 * The difference buffer lies between the entropy decoding and
16
 * prediction/undifferencing steps.  The undifference buffer lies between the
17
 * prediction/undifferencing and scaling steps.
18
 *
19
 * In buffered-image mode, this controller is the interface between
20
 * input-oriented processing and output-oriented processing.
21
 */
22
23
#define JPEG_INTERNALS
24
#include "jinclude.h"
25
#include "jpeglib.h"
26
#include "jlossls.h"            /* Private declarations for lossless codec */
27
28
29
#ifdef D_LOSSLESS_SUPPORTED
30
31
/* Private buffer controller object */
32
33
typedef struct {
34
  struct jpeg_d_coef_controller pub; /* public fields */
35
36
  /* These variables keep track of the current location of the input side. */
37
  /* cinfo->input_iMCU_row is also used for this. */
38
  JDIMENSION MCU_ctr;           /* counts MCUs processed in current row */
39
  unsigned int restart_rows_to_go;      /* MCU rows left in this restart
40
                                           interval */
41
  unsigned int MCU_vert_offset;         /* counts MCU rows within iMCU row */
42
  unsigned int MCU_rows_per_iMCU_row;   /* number of such rows needed */
43
44
  /* The output side's location is represented by cinfo->output_iMCU_row. */
45
46
  JDIFFARRAY diff_buf[MAX_COMPONENTS];  /* iMCU row of differences */
47
  JDIFFARRAY undiff_buf[MAX_COMPONENTS]; /* iMCU row of undiff'd samples */
48
49
#ifdef D_MULTISCAN_FILES_SUPPORTED
50
  /* In multi-pass modes, we need a virtual sample array for each component. */
51
  jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
52
#endif
53
} my_diff_controller;
54
55
typedef my_diff_controller *my_diff_ptr;
56
57
/* Forward declarations */
58
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
59
#ifdef D_MULTISCAN_FILES_SUPPORTED
60
METHODDEF(int) output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
61
#endif
62
63
64
LOCAL(void)
65
start_iMCU_row(j_decompress_ptr cinfo)
66
/* Reset within-iMCU-row counters for a new row (input side) */
67
12.6M
{
68
12.6M
  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.6M
  if (cinfo->comps_in_scan > 1) {
75
4.68M
    diff->MCU_rows_per_iMCU_row = 1;
76
7.93M
  } else {
77
7.93M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
7.86M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
78.7k
    else
80
78.7k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
7.93M
  }
82
83
12.6M
  diff->MCU_ctr = 0;
84
12.6M
  diff->MCU_vert_offset = 0;
85
12.6M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
6.83M
{
68
6.83M
  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
6.83M
  if (cinfo->comps_in_scan > 1) {
75
1.97M
    diff->MCU_rows_per_iMCU_row = 1;
76
4.85M
  } else {
77
4.85M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
4.80M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
49.7k
    else
80
49.7k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
4.85M
  }
82
83
6.83M
  diff->MCU_ctr = 0;
84
6.83M
  diff->MCU_vert_offset = 0;
85
6.83M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
2.55M
{
68
2.55M
  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.55M
  if (cinfo->comps_in_scan > 1) {
75
1.16M
    diff->MCU_rows_per_iMCU_row = 1;
76
1.39M
  } else {
77
1.39M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
1.38M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
12.5k
    else
80
12.5k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
1.39M
  }
82
83
2.55M
  diff->MCU_ctr = 0;
84
2.55M
  diff->MCU_vert_offset = 0;
85
2.55M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
3.23M
{
68
3.23M
  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
3.23M
  if (cinfo->comps_in_scan > 1) {
75
1.55M
    diff->MCU_rows_per_iMCU_row = 1;
76
1.68M
  } else {
77
1.68M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
1.67M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
16.4k
    else
80
16.4k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
1.68M
  }
82
83
3.23M
  diff->MCU_ctr = 0;
84
3.23M
  diff->MCU_vert_offset = 0;
85
3.23M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
111k
{
95
111k
  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
111k
  (*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
111k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
445
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
111k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
111k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
111k
  cinfo->input_iMCU_row = 0;
115
111k
  start_iMCU_row(cinfo);
116
111k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
62.4k
{
95
62.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
62.4k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
62.4k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
128
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
62.4k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
62.4k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
62.4k
  cinfo->input_iMCU_row = 0;
115
62.4k
  start_iMCU_row(cinfo);
116
62.4k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
22.9k
{
95
22.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
22.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
22.9k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
125
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
22.9k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
22.9k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
22.9k
  cinfo->input_iMCU_row = 0;
115
22.9k
  start_iMCU_row(cinfo);
116
22.9k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
26.5k
{
95
26.5k
  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
26.5k
  (*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
26.5k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
192
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
26.5k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
26.5k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
26.5k
  cinfo->input_iMCU_row = 0;
115
26.5k
  start_iMCU_row(cinfo);
116
26.5k
}
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
683k
{
127
683k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
683k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
683k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
683k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
683k
  return TRUE;
138
683k
}
jddiffct-8.c:process_restart
Line
Count
Source
126
515k
{
127
515k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
515k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
515k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
515k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
515k
  return TRUE;
138
515k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
36.1k
{
127
36.1k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
36.1k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
36.1k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
36.1k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
36.1k
  return TRUE;
138
36.1k
}
jddiffct-16.c:process_restart
Line
Count
Source
126
132k
{
127
132k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
132k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
132k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
132k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
132k
  return TRUE;
138
132k
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
49.7k
{
148
49.7k
  cinfo->output_iMCU_row = 0;
149
49.7k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
40.9k
{
148
40.9k
  cinfo->output_iMCU_row = 0;
149
40.9k
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
4.12k
{
148
4.12k
  cinfo->output_iMCU_row = 0;
149
4.12k
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
4.66k
{
148
4.66k
  cinfo->output_iMCU_row = 0;
149
4.66k
}
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.6M
{
165
12.6M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
12.6M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
12.6M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
12.6M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
12.6M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
12.6M
  int ci, compi, row, prev_row;
171
12.6M
  unsigned int yoffset;
172
12.6M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
29.6M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
17.0M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
17.0M
    if (cinfo->restart_interval) {
180
3.06M
      if (diff->restart_rows_to_go == 0)
181
683k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
3.06M
    }
184
185
17.0M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
17.0M
    MCU_count =
188
17.0M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
17.0M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
17.0M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
17.0M
    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
17.0M
    if (cinfo->restart_interval)
200
3.06M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
17.0M
    diff->MCU_ctr = 0;
204
17.0M
  }
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
32.6M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
20.0M
    compptr = cinfo->cur_comp_info[ci];
213
20.0M
    compi = compptr->component_index;
214
20.0M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
53.2M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
52.8M
                compptr->last_row_height : compptr->v_samp_factor);
217
33.1M
         prev_row = row, row++) {
218
33.1M
      (*losslessd->predict_undifference[compi])
219
33.1M
        (cinfo, compi, diff->diff_buf[compi][row],
220
33.1M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
33.1M
          compptr->width_in_blocks);
222
33.1M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
33.1M
                                  output_buf[compi][row],
224
33.1M
                                  compptr->width_in_blocks);
225
33.1M
    }
226
20.0M
  }
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.6M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
12.5M
    start_iMCU_row(cinfo);
236
12.5M
    return JPEG_ROW_COMPLETED;
237
12.5M
  }
238
  /* Completed the scan */
239
107k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
107k
  return JPEG_SCAN_COMPLETED;
241
12.6M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
6.83M
{
165
6.83M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
6.83M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
6.83M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
6.83M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
6.83M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
6.83M
  int ci, compi, row, prev_row;
171
6.83M
  unsigned int yoffset;
172
6.83M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
15.9M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
9.07M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
9.07M
    if (cinfo->restart_interval) {
180
2.31M
      if (diff->restart_rows_to_go == 0)
181
515k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
2.31M
    }
184
185
9.07M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
9.07M
    MCU_count =
188
9.07M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
9.07M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
9.07M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
9.07M
    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
9.07M
    if (cinfo->restart_interval)
200
2.31M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
9.07M
    diff->MCU_ctr = 0;
204
9.07M
  }
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
16.9M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
10.0M
    compptr = cinfo->cur_comp_info[ci];
213
10.0M
    compi = compptr->component_index;
214
10.0M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
26.1M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
25.9M
                compptr->last_row_height : compptr->v_samp_factor);
217
16.0M
         prev_row = row, row++) {
218
16.0M
      (*losslessd->predict_undifference[compi])
219
16.0M
        (cinfo, compi, diff->diff_buf[compi][row],
220
16.0M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
16.0M
          compptr->width_in_blocks);
222
16.0M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
16.0M
                                  output_buf[compi][row],
224
16.0M
                                  compptr->width_in_blocks);
225
16.0M
    }
226
10.0M
  }
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
6.83M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
6.77M
    start_iMCU_row(cinfo);
236
6.77M
    return JPEG_ROW_COMPLETED;
237
6.77M
  }
238
  /* Completed the scan */
239
60.5k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
60.5k
  return JPEG_SCAN_COMPLETED;
241
6.83M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
2.55M
{
165
2.55M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
2.55M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
2.55M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
2.55M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
2.55M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
2.55M
  int ci, compi, row, prev_row;
171
2.55M
  unsigned int yoffset;
172
2.55M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
6.03M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
3.48M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
3.48M
    if (cinfo->restart_interval) {
180
301k
      if (diff->restart_rows_to_go == 0)
181
36.1k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
301k
    }
184
185
3.48M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
3.48M
    MCU_count =
188
3.48M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
3.48M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
3.48M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
3.48M
    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.48M
    if (cinfo->restart_interval)
200
301k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
3.48M
    diff->MCU_ctr = 0;
204
3.48M
  }
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
6.78M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
4.23M
    compptr = cinfo->cur_comp_info[ci];
213
4.23M
    compi = compptr->component_index;
214
4.23M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
11.7M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
11.6M
                compptr->last_row_height : compptr->v_samp_factor);
217
7.49M
         prev_row = row, row++) {
218
7.49M
      (*losslessd->predict_undifference[compi])
219
7.49M
        (cinfo, compi, diff->diff_buf[compi][row],
220
7.49M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
7.49M
          compptr->width_in_blocks);
222
7.49M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
7.49M
                                  output_buf[compi][row],
224
7.49M
                                  compptr->width_in_blocks);
225
7.49M
    }
226
4.23M
  }
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.55M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
2.53M
    start_iMCU_row(cinfo);
236
2.53M
    return JPEG_ROW_COMPLETED;
237
2.53M
  }
238
  /* Completed the scan */
239
21.7k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
21.7k
  return JPEG_SCAN_COMPLETED;
241
2.55M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
3.23M
{
165
3.23M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
3.23M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
3.23M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
3.23M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
3.23M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
3.23M
  int ci, compi, row, prev_row;
171
3.23M
  unsigned int yoffset;
172
3.23M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
7.72M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
4.48M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
4.48M
    if (cinfo->restart_interval) {
180
448k
      if (diff->restart_rows_to_go == 0)
181
132k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
448k
    }
184
185
4.48M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
4.48M
    MCU_count =
188
4.48M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
4.48M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
4.48M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
4.48M
    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
4.48M
    if (cinfo->restart_interval)
200
448k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
4.48M
    diff->MCU_ctr = 0;
204
4.48M
  }
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
8.94M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
5.70M
    compptr = cinfo->cur_comp_info[ci];
213
5.70M
    compi = compptr->component_index;
214
5.70M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
15.3M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
15.1M
                compptr->last_row_height : compptr->v_samp_factor);
217
9.59M
         prev_row = row, row++) {
218
9.59M
      (*losslessd->predict_undifference[compi])
219
9.59M
        (cinfo, compi, diff->diff_buf[compi][row],
220
9.59M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
9.59M
          compptr->width_in_blocks);
222
9.59M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
9.59M
                                  output_buf[compi][row],
224
9.59M
                                  compptr->width_in_blocks);
225
9.59M
    }
226
5.70M
  }
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
3.23M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
3.21M
    start_iMCU_row(cinfo);
236
3.21M
    return JPEG_ROW_COMPLETED;
237
3.21M
  }
238
  /* Completed the scan */
239
25.4k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
25.4k
  return JPEG_SCAN_COMPLETED;
241
3.23M
}
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
10.4M
{
267
10.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
10.4M
  int ci, compi;
269
10.4M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
10.4M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
27.8M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
17.3M
    compptr = cinfo->cur_comp_info[ci];
275
17.3M
    compi = compptr->component_index;
276
17.3M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
17.3M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
17.3M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
17.3M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
17.3M
  }
281
282
10.4M
  return decompress_data(cinfo, buffer);
283
10.4M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
5.19M
{
267
5.19M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
5.19M
  int ci, compi;
269
5.19M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
5.19M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
13.4M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
8.29M
    compptr = cinfo->cur_comp_info[ci];
275
8.29M
    compi = compptr->component_index;
276
8.29M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
8.29M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
8.29M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
8.29M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
8.29M
  }
281
282
5.19M
  return decompress_data(cinfo, buffer);
283
5.19M
}
jddiffct-12.c:consume_data
Line
Count
Source
266
2.21M
{
267
2.21M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
2.21M
  int ci, compi;
269
2.21M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
2.21M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
5.95M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
3.74M
    compptr = cinfo->cur_comp_info[ci];
275
3.74M
    compi = compptr->component_index;
276
3.74M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
3.74M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
3.74M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
3.74M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
3.74M
  }
281
282
2.21M
  return decompress_data(cinfo, buffer);
283
2.21M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
3.01M
{
267
3.01M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
3.01M
  int ci, compi;
269
3.01M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
3.01M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
8.37M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
5.35M
    compptr = cinfo->cur_comp_info[ci];
275
5.35M
    compi = compptr->component_index;
276
5.35M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
5.35M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
5.35M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
5.35M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
5.35M
  }
281
282
3.01M
  return decompress_data(cinfo, buffer);
283
3.01M
}
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
374k
{
297
374k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
374k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
374k
  int ci, samp_rows, row;
300
374k
  _JSAMPARRAY buffer;
301
374k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
374k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
374k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
374k
          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.58M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
1.20M
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
1.20M
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
1.20M
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
1.20M
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
1.20M
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
1.20M
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
1.19M
      samp_rows = compptr->v_samp_factor;
322
16.9k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
16.9k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
16.9k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
16.9k
    }
327
328
3.11M
    for (row = 0; row < samp_rows; row++) {
329
1.90M
      memcpy(output_buf[ci][row], buffer[row],
330
1.90M
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
1.90M
    }
332
1.20M
  }
333
334
374k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
365k
    return JPEG_ROW_COMPLETED;
336
8.60k
  return JPEG_SCAN_COMPLETED;
337
374k
}
jddiffct-8.c:output_data
Line
Count
Source
296
133k
{
297
133k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
133k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
133k
  int ci, samp_rows, row;
300
133k
  _JSAMPARRAY buffer;
301
133k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
133k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
133k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
133k
          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
560k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
427k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
427k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
427k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
427k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
427k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
427k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
420k
      samp_rows = compptr->v_samp_factor;
322
6.25k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
6.25k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
6.25k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
6.25k
    }
327
328
1.11M
    for (row = 0; row < samp_rows; row++) {
329
688k
      memcpy(output_buf[ci][row], buffer[row],
330
688k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
688k
    }
332
427k
  }
333
334
133k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
130k
    return JPEG_ROW_COMPLETED;
336
3.13k
  return JPEG_SCAN_COMPLETED;
337
133k
}
jddiffct-12.c:output_data
Line
Count
Source
296
133k
{
297
133k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
133k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
133k
  int ci, samp_rows, row;
300
133k
  _JSAMPARRAY buffer;
301
133k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
133k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
133k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
133k
          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
558k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
424k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
424k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
424k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
424k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
424k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
424k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
419k
      samp_rows = compptr->v_samp_factor;
322
4.95k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
4.95k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
4.95k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
4.95k
    }
327
328
1.04M
    for (row = 0; row < samp_rows; row++) {
329
623k
      memcpy(output_buf[ci][row], buffer[row],
330
623k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
623k
    }
332
424k
  }
333
334
133k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
131k
    return JPEG_ROW_COMPLETED;
336
2.47k
  return JPEG_SCAN_COMPLETED;
337
133k
}
jddiffct-16.c:output_data
Line
Count
Source
296
106k
{
297
106k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
106k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
106k
  int ci, samp_rows, row;
300
106k
  _JSAMPARRAY buffer;
301
106k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
106k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
106k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
106k
          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
464k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
357k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
357k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
357k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
357k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
357k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
357k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
351k
      samp_rows = compptr->v_samp_factor;
322
5.71k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
5.71k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
5.71k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
5.71k
    }
327
328
950k
    for (row = 0; row < samp_rows; row++) {
329
592k
      memcpy(output_buf[ci][row], buffer[row],
330
592k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
592k
    }
332
357k
  }
333
334
106k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
103k
    return JPEG_ROW_COMPLETED;
336
2.99k
  return JPEG_SCAN_COMPLETED;
337
106k
}
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
60.8k
{
349
60.8k
  my_diff_ptr diff;
350
60.8k
  int ci;
351
60.8k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
45.3k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
15.5k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
15.5k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
60.8k
  diff = (my_diff_ptr)
362
60.8k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
60.8k
                                sizeof(my_diff_controller));
364
60.8k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
60.8k
  diff->pub.start_input_pass = start_input_pass;
366
60.8k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
187k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
126k
       ci++, compptr++) {
371
126k
    diff->diff_buf[ci] =
372
126k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
126k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
126k
                                         (long)compptr->h_samp_factor),
375
126k
                   (JDIMENSION)compptr->v_samp_factor);
376
126k
    diff->undiff_buf[ci] =
377
126k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
126k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
126k
                                         (long)compptr->h_samp_factor),
380
126k
                   (JDIMENSION)compptr->v_samp_factor);
381
126k
  }
382
383
60.8k
  if (need_full_buffer) {
384
19.8k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
19.8k
    int access_rows;
387
388
100k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
80.8k
         ci++, compptr++) {
390
80.8k
      access_rows = compptr->v_samp_factor;
391
80.8k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
80.8k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
80.8k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
80.8k
                               (long)compptr->h_samp_factor),
395
80.8k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
80.8k
                               (long)compptr->v_samp_factor),
397
80.8k
         (JDIMENSION)access_rows);
398
80.8k
    }
399
19.8k
    diff->pub.consume_data = consume_data;
400
19.8k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
41.0k
  } else {
405
41.0k
    diff->pub.consume_data = dummy_consume_data;
406
41.0k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
41.0k
  }
409
60.8k
}
jinit_d_diff_controller
Line
Count
Source
348
45.3k
{
349
45.3k
  my_diff_ptr diff;
350
45.3k
  int ci;
351
45.3k
  jpeg_component_info *compptr;
352
353
45.3k
#if BITS_IN_JSAMPLE == 8
354
45.3k
  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
45.3k
  diff = (my_diff_ptr)
362
45.3k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
45.3k
                                sizeof(my_diff_controller));
364
45.3k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
45.3k
  diff->pub.start_input_pass = start_input_pass;
366
45.3k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
112k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
67.6k
       ci++, compptr++) {
371
67.6k
    diff->diff_buf[ci] =
372
67.6k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
67.6k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
67.6k
                                         (long)compptr->h_samp_factor),
375
67.6k
                   (JDIMENSION)compptr->v_samp_factor);
376
67.6k
    diff->undiff_buf[ci] =
377
67.6k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
67.6k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
67.6k
                                         (long)compptr->h_samp_factor),
380
67.6k
                   (JDIMENSION)compptr->v_samp_factor);
381
67.6k
  }
382
383
45.3k
  if (need_full_buffer) {
384
6.78k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
6.78k
    int access_rows;
387
388
33.6k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
26.8k
         ci++, compptr++) {
390
26.8k
      access_rows = compptr->v_samp_factor;
391
26.8k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
26.8k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
26.8k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
26.8k
                               (long)compptr->h_samp_factor),
395
26.8k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
26.8k
                               (long)compptr->v_samp_factor),
397
26.8k
         (JDIMENSION)access_rows);
398
26.8k
    }
399
6.78k
    diff->pub.consume_data = consume_data;
400
6.78k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
38.5k
  } else {
405
38.5k
    diff->pub.consume_data = dummy_consume_data;
406
38.5k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
38.5k
  }
409
45.3k
}
j12init_d_diff_controller
Line
Count
Source
348
7.39k
{
349
7.39k
  my_diff_ptr diff;
350
7.39k
  int ci;
351
7.39k
  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
7.39k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
7.39k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
7.39k
  diff = (my_diff_ptr)
362
7.39k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
7.39k
                                sizeof(my_diff_controller));
364
7.39k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
7.39k
  diff->pub.start_input_pass = start_input_pass;
366
7.39k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
35.3k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
27.9k
       ci++, compptr++) {
371
27.9k
    diff->diff_buf[ci] =
372
27.9k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
27.9k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
27.9k
                                         (long)compptr->h_samp_factor),
375
27.9k
                   (JDIMENSION)compptr->v_samp_factor);
376
27.9k
    diff->undiff_buf[ci] =
377
27.9k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
27.9k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
27.9k
                                         (long)compptr->h_samp_factor),
380
27.9k
                   (JDIMENSION)compptr->v_samp_factor);
381
27.9k
  }
382
383
7.39k
  if (need_full_buffer) {
384
6.03k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
6.03k
    int access_rows;
387
388
31.3k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
25.3k
         ci++, compptr++) {
390
25.3k
      access_rows = compptr->v_samp_factor;
391
25.3k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
25.3k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
25.3k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
25.3k
                               (long)compptr->h_samp_factor),
395
25.3k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
25.3k
                               (long)compptr->v_samp_factor),
397
25.3k
         (JDIMENSION)access_rows);
398
25.3k
    }
399
6.03k
    diff->pub.consume_data = consume_data;
400
6.03k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
6.03k
  } else {
405
1.35k
    diff->pub.consume_data = dummy_consume_data;
406
1.35k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
1.35k
  }
409
7.39k
}
j16init_d_diff_controller
Line
Count
Source
348
8.13k
{
349
8.13k
  my_diff_ptr diff;
350
8.13k
  int ci;
351
8.13k
  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
8.13k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
8.13k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
8.13k
  diff = (my_diff_ptr)
362
8.13k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
8.13k
                                sizeof(my_diff_controller));
364
8.13k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
8.13k
  diff->pub.start_input_pass = start_input_pass;
366
8.13k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
39.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
31.1k
       ci++, compptr++) {
371
31.1k
    diff->diff_buf[ci] =
372
31.1k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
31.1k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
31.1k
                                         (long)compptr->h_samp_factor),
375
31.1k
                   (JDIMENSION)compptr->v_samp_factor);
376
31.1k
    diff->undiff_buf[ci] =
377
31.1k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
31.1k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
31.1k
                                         (long)compptr->h_samp_factor),
380
31.1k
                   (JDIMENSION)compptr->v_samp_factor);
381
31.1k
  }
382
383
8.13k
  if (need_full_buffer) {
384
7.00k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
7.00k
    int access_rows;
387
388
35.6k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
28.6k
         ci++, compptr++) {
390
28.6k
      access_rows = compptr->v_samp_factor;
391
28.6k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
28.6k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
28.6k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
28.6k
                               (long)compptr->h_samp_factor),
395
28.6k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
28.6k
                               (long)compptr->v_samp_factor),
397
28.6k
         (JDIMENSION)access_rows);
398
28.6k
    }
399
7.00k
    diff->pub.consume_data = consume_data;
400
7.00k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
7.00k
  } else {
405
1.12k
    diff->pub.consume_data = dummy_consume_data;
406
1.12k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
1.12k
  }
409
8.13k
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */