Coverage Report

Created: 2025-10-10 06:56

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
4.86M
{
68
4.86M
  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
4.86M
  if (cinfo->comps_in_scan > 1) {
75
423k
    diff->MCU_rows_per_iMCU_row = 1;
76
4.44M
  } else {
77
4.44M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
4.43M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
6.57k
    else
80
6.57k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
4.44M
  }
82
83
4.86M
  diff->MCU_ctr = 0;
84
4.86M
  diff->MCU_vert_offset = 0;
85
4.86M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
166k
{
68
166k
  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
166k
  if (cinfo->comps_in_scan > 1) {
75
6.69k
    diff->MCU_rows_per_iMCU_row = 1;
76
159k
  } else {
77
159k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
154k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
5.74k
    else
80
5.74k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
159k
  }
82
83
166k
  diff->MCU_ctr = 0;
84
166k
  diff->MCU_vert_offset = 0;
85
166k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
939k
{
68
939k
  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
939k
  if (cinfo->comps_in_scan > 1) {
75
416k
    diff->MCU_rows_per_iMCU_row = 1;
76
522k
  } else {
77
522k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
521k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
729
    else
80
729
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
522k
  }
82
83
939k
  diff->MCU_ctr = 0;
84
939k
  diff->MCU_vert_offset = 0;
85
939k
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
3.75M
{
68
3.75M
  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.75M
  if (cinfo->comps_in_scan > 1) {
75
298
    diff->MCU_rows_per_iMCU_row = 1;
76
3.75M
  } else {
77
3.75M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
3.75M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
97
    else
80
97
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
3.75M
  }
82
83
3.75M
  diff->MCU_ctr = 0;
84
3.75M
  diff->MCU_vert_offset = 0;
85
3.75M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
8.58k
{
95
8.58k
  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
8.58k
  (*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
8.58k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
206
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
8.58k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
8.58k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
8.58k
  cinfo->input_iMCU_row = 0;
115
8.58k
  start_iMCU_row(cinfo);
116
8.58k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
7.58k
{
95
7.58k
  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
7.58k
  (*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
7.58k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
202
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
7.58k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
7.58k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
7.58k
  cinfo->input_iMCU_row = 0;
115
7.58k
  start_iMCU_row(cinfo);
116
7.58k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
827
{
95
827
  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
827
  (*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
827
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
4
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
827
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
827
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
827
  cinfo->input_iMCU_row = 0;
115
827
  start_iMCU_row(cinfo);
116
827
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
173
{
95
173
  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
173
  (*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
173
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
173
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
173
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
173
  cinfo->input_iMCU_row = 0;
115
173
  start_iMCU_row(cinfo);
116
173
}
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
29.6k
{
127
29.6k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
29.6k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
29.6k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
29.6k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
29.6k
  return TRUE;
138
29.6k
}
jddiffct-8.c:process_restart
Line
Count
Source
126
17
{
127
17
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
17
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
17
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
17
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
17
  return TRUE;
138
17
}
jddiffct-12.c:process_restart
Line
Count
Source
126
29.5k
{
127
29.5k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
29.5k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
29.5k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
29.5k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
29.5k
  return TRUE;
138
29.5k
}
jddiffct-16.c:process_restart
Line
Count
Source
126
66
{
127
66
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
66
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
66
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
66
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
66
  return TRUE;
138
66
}
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.49k
{
148
1.49k
  cinfo->output_iMCU_row = 0;
149
1.49k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
1.46k
{
148
1.46k
  cinfo->output_iMCU_row = 0;
149
1.46k
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
23
{
148
23
  cinfo->output_iMCU_row = 0;
149
23
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
12
{
148
12
  cinfo->output_iMCU_row = 0;
149
12
}
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
4.86M
{
165
4.86M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
4.86M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
4.86M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
4.86M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
4.86M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
4.86M
  int ci, compi, row, prev_row;
171
4.86M
  unsigned int yoffset;
172
4.86M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
10.0M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
5.15M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
5.15M
    if (cinfo->restart_interval) {
180
946k
      if (diff->restart_rows_to_go == 0)
181
29.6k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
946k
    }
184
185
5.15M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
5.15M
    MCU_count =
188
5.15M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
5.15M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
5.15M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
5.15M
    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
5.15M
    if (cinfo->restart_interval)
200
946k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
5.15M
    diff->MCU_ctr = 0;
204
5.15M
  }
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
10.1M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
5.29M
    compptr = cinfo->cur_comp_info[ci];
213
5.29M
    compi = compptr->component_index;
214
5.29M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
11.1M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
11.0M
                compptr->last_row_height : compptr->v_samp_factor);
217
5.81M
         prev_row = row, row++) {
218
5.81M
      (*losslessd->predict_undifference[compi])
219
5.81M
        (cinfo, compi, diff->diff_buf[compi][row],
220
5.81M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
5.81M
          compptr->width_in_blocks);
222
5.81M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
5.81M
                                  output_buf[compi][row],
224
5.81M
                                  compptr->width_in_blocks);
225
5.81M
    }
226
5.29M
  }
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
4.86M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
4.85M
    start_iMCU_row(cinfo);
236
4.85M
    return JPEG_ROW_COMPLETED;
237
4.85M
  }
238
  /* Completed the scan */
239
7.40k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
7.40k
  return JPEG_SCAN_COMPLETED;
241
4.86M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
166k
{
165
166k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
166k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
166k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
166k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
166k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
166k
  int ci, compi, row, prev_row;
171
166k
  unsigned int yoffset;
172
166k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
333k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
166k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
166k
    if (cinfo->restart_interval) {
180
35
      if (diff->restart_rows_to_go == 0)
181
17
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
35
    }
184
185
166k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
166k
    MCU_count =
188
166k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
166k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
166k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
166k
    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
166k
    if (cinfo->restart_interval)
200
35
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
166k
    diff->MCU_ctr = 0;
204
166k
  }
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
343k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
176k
    compptr = cinfo->cur_comp_info[ci];
213
176k
    compi = compptr->component_index;
214
176k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
352k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
337k
                compptr->last_row_height : compptr->v_samp_factor);
217
176k
         prev_row = row, row++) {
218
176k
      (*losslessd->predict_undifference[compi])
219
176k
        (cinfo, compi, diff->diff_buf[compi][row],
220
176k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
176k
          compptr->width_in_blocks);
222
176k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
176k
                                  output_buf[compi][row],
224
176k
                                  compptr->width_in_blocks);
225
176k
    }
226
176k
  }
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
166k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
160k
    start_iMCU_row(cinfo);
236
160k
    return JPEG_ROW_COMPLETED;
237
160k
  }
238
  /* Completed the scan */
239
6.42k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
6.42k
  return JPEG_SCAN_COMPLETED;
241
166k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
939k
{
165
939k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
939k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
939k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
939k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
939k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
939k
  int ci, compi, row, prev_row;
171
939k
  unsigned int yoffset;
172
939k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
2.16M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
1.22M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
1.22M
    if (cinfo->restart_interval) {
180
919k
      if (diff->restart_rows_to_go == 0)
181
29.5k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
919k
    }
184
185
1.22M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
1.22M
    MCU_count =
188
1.22M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
1.22M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
1.22M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
1.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
1.22M
    if (cinfo->restart_interval)
200
919k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
1.22M
    diff->MCU_ctr = 0;
204
1.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.29M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
1.35M
    compptr = cinfo->cur_comp_info[ci];
213
1.35M
    compi = compptr->component_index;
214
1.35M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
3.23M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
3.23M
                compptr->last_row_height : compptr->v_samp_factor);
217
1.87M
         prev_row = row, row++) {
218
1.87M
      (*losslessd->predict_undifference[compi])
219
1.87M
        (cinfo, compi, diff->diff_buf[compi][row],
220
1.87M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
1.87M
          compptr->width_in_blocks);
222
1.87M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
1.87M
                                  output_buf[compi][row],
224
1.87M
                                  compptr->width_in_blocks);
225
1.87M
    }
226
1.35M
  }
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
939k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
938k
    start_iMCU_row(cinfo);
236
938k
    return JPEG_ROW_COMPLETED;
237
938k
  }
238
  /* Completed the scan */
239
811
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
811
  return JPEG_SCAN_COMPLETED;
241
939k
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
3.75M
{
165
3.75M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
3.75M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
3.75M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
3.75M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
3.75M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
3.75M
  int ci, compi, row, prev_row;
171
3.75M
  unsigned int yoffset;
172
3.75M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
7.51M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
3.75M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
3.75M
    if (cinfo->restart_interval) {
180
26.4k
      if (diff->restart_rows_to_go == 0)
181
66
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
26.4k
    }
184
185
3.75M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
3.75M
    MCU_count =
188
3.75M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
3.75M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
3.75M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
3.75M
    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.75M
    if (cinfo->restart_interval)
200
26.4k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
3.75M
    diff->MCU_ctr = 0;
204
3.75M
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
7.51M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
3.75M
    compptr = cinfo->cur_comp_info[ci];
213
3.75M
    compi = compptr->component_index;
214
3.75M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
7.51M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
7.51M
                compptr->last_row_height : compptr->v_samp_factor);
217
3.75M
         prev_row = row, row++) {
218
3.75M
      (*losslessd->predict_undifference[compi])
219
3.75M
        (cinfo, compi, diff->diff_buf[compi][row],
220
3.75M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
3.75M
          compptr->width_in_blocks);
222
3.75M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
3.75M
                                  output_buf[compi][row],
224
3.75M
                                  compptr->width_in_blocks);
225
3.75M
    }
226
3.75M
  }
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.75M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
3.75M
    start_iMCU_row(cinfo);
236
3.75M
    return JPEG_ROW_COMPLETED;
237
3.75M
  }
238
  /* Completed the scan */
239
172
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
172
  return JPEG_SCAN_COMPLETED;
241
3.75M
}
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
4.75M
{
267
4.75M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
4.75M
  int ci, compi;
269
4.75M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
4.75M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
9.93M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
5.17M
    compptr = cinfo->cur_comp_info[ci];
275
5.17M
    compi = compptr->component_index;
276
5.17M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
5.17M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
5.17M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
5.17M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
5.17M
  }
281
282
4.75M
  return decompress_data(cinfo, buffer);
283
4.75M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
55.0k
{
267
55.0k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
55.0k
  int ci, compi;
269
55.0k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
55.0k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
118k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
63.4k
    compptr = cinfo->cur_comp_info[ci];
275
63.4k
    compi = compptr->component_index;
276
63.4k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
63.4k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
63.4k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
63.4k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
63.4k
  }
281
282
55.0k
  return decompress_data(cinfo, buffer);
283
55.0k
}
jddiffct-12.c:consume_data
Line
Count
Source
266
939k
{
267
939k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
939k
  int ci, compi;
269
939k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
939k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
2.29M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
1.35M
    compptr = cinfo->cur_comp_info[ci];
275
1.35M
    compi = compptr->component_index;
276
1.35M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
1.35M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
1.35M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
1.35M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
1.35M
  }
281
282
939k
  return decompress_data(cinfo, buffer);
283
939k
}
jddiffct-16.c:consume_data
Line
Count
Source
266
3.75M
{
267
3.75M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
3.75M
  int ci, compi;
269
3.75M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
3.75M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
7.51M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
3.75M
    compptr = cinfo->cur_comp_info[ci];
275
3.75M
    compi = compptr->component_index;
276
3.75M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
3.75M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
3.75M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
3.75M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
3.75M
  }
281
282
3.75M
  return decompress_data(cinfo, buffer);
283
3.75M
}
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
1.76k
{
297
1.76k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
1.76k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
1.76k
  int ci, samp_rows, row;
300
1.76k
  _JSAMPARRAY buffer;
301
1.76k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
1.76k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
1.76k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
1.76k
          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
5.54k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
3.78k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
3.78k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
3.78k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
3.78k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
3.78k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
3.78k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
2.26k
      samp_rows = compptr->v_samp_factor;
322
1.51k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1.51k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1.51k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1.51k
    }
327
328
6.23k
    for (row = 0; row < samp_rows; row++) {
329
2.45k
      memcpy(output_buf[ci][row], buffer[row],
330
2.45k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
2.45k
    }
332
3.78k
  }
333
334
1.76k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
394
    return JPEG_ROW_COMPLETED;
336
1.36k
  return JPEG_SCAN_COMPLETED;
337
1.76k
}
jddiffct-8.c:output_data
Line
Count
Source
296
1.66k
{
297
1.66k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
1.66k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
1.66k
  int ci, samp_rows, row;
300
1.66k
  _JSAMPARRAY buffer;
301
1.66k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
1.66k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
1.66k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
1.66k
          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
5.17k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
3.50k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
3.50k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
3.50k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
3.50k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
3.50k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
3.50k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
2.01k
      samp_rows = compptr->v_samp_factor;
322
1.49k
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
1.49k
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
1.49k
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
1.49k
    }
327
328
5.70k
    for (row = 0; row < samp_rows; row++) {
329
2.20k
      memcpy(output_buf[ci][row], buffer[row],
330
2.20k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
2.20k
    }
332
3.50k
  }
333
334
1.66k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
319
    return JPEG_ROW_COMPLETED;
336
1.34k
  return JPEG_SCAN_COMPLETED;
337
1.66k
}
jddiffct-12.c:output_data
Line
Count
Source
296
95
{
297
95
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
95
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
95
  int ci, samp_rows, row;
300
95
  _JSAMPARRAY buffer;
301
95
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
95
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
95
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
95
          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
368
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
273
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
273
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
273
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
273
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
273
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
273
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
249
      samp_rows = compptr->v_samp_factor;
322
24
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
24
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
24
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
24
    }
327
328
527
    for (row = 0; row < samp_rows; row++) {
329
254
      memcpy(output_buf[ci][row], buffer[row],
330
254
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
254
    }
332
273
  }
333
334
95
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
75
    return JPEG_ROW_COMPLETED;
336
20
  return JPEG_SCAN_COMPLETED;
337
95
}
Unexecuted instantiation: jddiffct-16.c:output_data
338
339
#endif /* D_MULTISCAN_FILES_SUPPORTED */
340
341
342
/*
343
 * Initialize difference buffer controller.
344
 */
345
346
GLOBAL(void)
347
_jinit_d_diff_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
348
5.27k
{
349
5.27k
  my_diff_ptr diff;
350
5.27k
  int ci;
351
5.27k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
5.16k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
102
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
102
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
5.27k
  diff = (my_diff_ptr)
362
5.27k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
5.27k
                                sizeof(my_diff_controller));
364
5.27k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
5.27k
  diff->pub.start_input_pass = start_input_pass;
366
5.27k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
20.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
15.3k
       ci++, compptr++) {
371
15.3k
    diff->diff_buf[ci] =
372
15.3k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
15.3k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
15.3k
                                         (long)compptr->h_samp_factor),
375
15.3k
                   (JDIMENSION)compptr->v_samp_factor);
376
15.3k
    diff->undiff_buf[ci] =
377
15.3k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
15.3k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
15.3k
                                         (long)compptr->h_samp_factor),
380
15.3k
                   (JDIMENSION)compptr->v_samp_factor);
381
15.3k
  }
382
383
5.27k
  if (need_full_buffer) {
384
4.90k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
4.90k
    int access_rows;
387
388
19.6k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
14.7k
         ci++, compptr++) {
390
14.7k
      access_rows = compptr->v_samp_factor;
391
14.7k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
14.7k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
14.7k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
14.7k
                               (long)compptr->h_samp_factor),
395
14.7k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
14.7k
                               (long)compptr->v_samp_factor),
397
14.7k
         (JDIMENSION)access_rows);
398
14.7k
    }
399
4.90k
    diff->pub.consume_data = consume_data;
400
4.90k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
4.90k
  } else {
405
368
    diff->pub.consume_data = dummy_consume_data;
406
368
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
368
  }
409
5.27k
}
jinit_d_diff_controller
Line
Count
Source
348
5.16k
{
349
5.16k
  my_diff_ptr diff;
350
5.16k
  int ci;
351
5.16k
  jpeg_component_info *compptr;
352
353
5.16k
#if BITS_IN_JSAMPLE == 8
354
5.16k
  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
5.16k
  diff = (my_diff_ptr)
362
5.16k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
5.16k
                                sizeof(my_diff_controller));
364
5.16k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
5.16k
  diff->pub.start_input_pass = start_input_pass;
366
5.16k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
20.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
15.0k
       ci++, compptr++) {
371
15.0k
    diff->diff_buf[ci] =
372
15.0k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
15.0k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
15.0k
                                         (long)compptr->h_samp_factor),
375
15.0k
                   (JDIMENSION)compptr->v_samp_factor);
376
15.0k
    diff->undiff_buf[ci] =
377
15.0k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
15.0k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
15.0k
                                         (long)compptr->h_samp_factor),
380
15.0k
                   (JDIMENSION)compptr->v_samp_factor);
381
15.0k
  }
382
383
5.16k
  if (need_full_buffer) {
384
4.80k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
4.80k
    int access_rows;
387
388
19.2k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
14.4k
         ci++, compptr++) {
390
14.4k
      access_rows = compptr->v_samp_factor;
391
14.4k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
14.4k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
14.4k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
14.4k
                               (long)compptr->h_samp_factor),
395
14.4k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
14.4k
                               (long)compptr->v_samp_factor),
397
14.4k
         (JDIMENSION)access_rows);
398
14.4k
    }
399
4.80k
    diff->pub.consume_data = consume_data;
400
4.80k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
4.80k
  } else {
405
368
    diff->pub.consume_data = dummy_consume_data;
406
368
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
368
  }
409
5.16k
}
j12init_d_diff_controller
Line
Count
Source
348
72
{
349
72
  my_diff_ptr diff;
350
72
  int ci;
351
72
  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
72
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
72
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
72
  diff = (my_diff_ptr)
362
72
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
72
                                sizeof(my_diff_controller));
364
72
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
72
  diff->pub.start_input_pass = start_input_pass;
366
72
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
288
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
216
       ci++, compptr++) {
371
216
    diff->diff_buf[ci] =
372
216
      ALLOC_DARRAY(JPOOL_IMAGE,
373
216
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
216
                                         (long)compptr->h_samp_factor),
375
216
                   (JDIMENSION)compptr->v_samp_factor);
376
216
    diff->undiff_buf[ci] =
377
216
      ALLOC_DARRAY(JPOOL_IMAGE,
378
216
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
216
                                         (long)compptr->h_samp_factor),
380
216
                   (JDIMENSION)compptr->v_samp_factor);
381
216
  }
382
383
72
  if (need_full_buffer) {
384
72
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
72
    int access_rows;
387
388
288
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
216
         ci++, compptr++) {
390
216
      access_rows = compptr->v_samp_factor;
391
216
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
216
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
216
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
216
                               (long)compptr->h_samp_factor),
395
216
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
216
                               (long)compptr->v_samp_factor),
397
216
         (JDIMENSION)access_rows);
398
216
    }
399
72
    diff->pub.consume_data = consume_data;
400
72
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
72
  } else {
405
0
    diff->pub.consume_data = dummy_consume_data;
406
0
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
0
  }
409
72
}
j16init_d_diff_controller
Line
Count
Source
348
30
{
349
30
  my_diff_ptr diff;
350
30
  int ci;
351
30
  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
30
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
30
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
30
  diff = (my_diff_ptr)
362
30
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
30
                                sizeof(my_diff_controller));
364
30
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
30
  diff->pub.start_input_pass = start_input_pass;
366
30
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
120
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
90
       ci++, compptr++) {
371
90
    diff->diff_buf[ci] =
372
90
      ALLOC_DARRAY(JPOOL_IMAGE,
373
90
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
90
                                         (long)compptr->h_samp_factor),
375
90
                   (JDIMENSION)compptr->v_samp_factor);
376
90
    diff->undiff_buf[ci] =
377
90
      ALLOC_DARRAY(JPOOL_IMAGE,
378
90
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
90
                                         (long)compptr->h_samp_factor),
380
90
                   (JDIMENSION)compptr->v_samp_factor);
381
90
  }
382
383
30
  if (need_full_buffer) {
384
30
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
30
    int access_rows;
387
388
120
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
90
         ci++, compptr++) {
390
90
      access_rows = compptr->v_samp_factor;
391
90
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
90
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
90
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
90
                               (long)compptr->h_samp_factor),
395
90
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
90
                               (long)compptr->v_samp_factor),
397
90
         (JDIMENSION)access_rows);
398
90
    }
399
30
    diff->pub.consume_data = consume_data;
400
30
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
30
  } else {
405
0
    diff->pub.consume_data = dummy_consume_data;
406
0
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
0
  }
409
30
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */