Coverage Report

Created: 2025-10-13 06:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.dev/src/jddiffct.c
Line
Count
Source
1
/*
2
 * jddiffct.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1994-1997, Thomas G. Lane.
6
 * Lossless JPEG Modifications:
7
 * Copyright (C) 1999, Ken Murchison.
8
 * libjpeg-turbo Modifications:
9
 * Copyright (C) 2022, 2024, D. R. Commander.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains the [un]difference buffer controller for decompression.
14
 * This controller is the top level of the lossless JPEG decompressor proper.
15
 * The difference buffer lies between the entropy decoding and
16
 * prediction/undifferencing steps.  The undifference buffer lies between the
17
 * prediction/undifferencing and scaling steps.
18
 *
19
 * In buffered-image mode, this controller is the interface between
20
 * input-oriented processing and output-oriented processing.
21
 */
22
23
#define JPEG_INTERNALS
24
#include "jinclude.h"
25
#include "jpeglib.h"
26
#include "jlossls.h"            /* Private declarations for lossless codec */
27
28
29
#ifdef D_LOSSLESS_SUPPORTED
30
31
/* Private buffer controller object */
32
33
typedef struct {
34
  struct jpeg_d_coef_controller pub; /* public fields */
35
36
  /* These variables keep track of the current location of the input side. */
37
  /* cinfo->input_iMCU_row is also used for this. */
38
  JDIMENSION MCU_ctr;           /* counts MCUs processed in current row */
39
  unsigned int restart_rows_to_go;      /* MCU rows left in this restart
40
                                           interval */
41
  unsigned int MCU_vert_offset;         /* counts MCU rows within iMCU row */
42
  unsigned int MCU_rows_per_iMCU_row;   /* number of such rows needed */
43
44
  /* The output side's location is represented by cinfo->output_iMCU_row. */
45
46
  JDIFFARRAY diff_buf[MAX_COMPONENTS];  /* iMCU row of differences */
47
  JDIFFARRAY undiff_buf[MAX_COMPONENTS]; /* iMCU row of undiff'd samples */
48
49
#ifdef D_MULTISCAN_FILES_SUPPORTED
50
  /* In multi-pass modes, we need a virtual sample array for each component. */
51
  jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
52
#endif
53
} my_diff_controller;
54
55
typedef my_diff_controller *my_diff_ptr;
56
57
/* Forward declarations */
58
METHODDEF(int) decompress_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
59
#ifdef D_MULTISCAN_FILES_SUPPORTED
60
METHODDEF(int) output_data(j_decompress_ptr cinfo, _JSAMPIMAGE output_buf);
61
#endif
62
63
64
LOCAL(void)
65
start_iMCU_row(j_decompress_ptr cinfo)
66
/* Reset within-iMCU-row counters for a new row (input side) */
67
51.1M
{
68
51.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
69
70
  /* In an interleaved scan, an MCU row is the same as an iMCU row.
71
   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
72
   * But at the bottom of the image, process only what's left.
73
   */
74
51.1M
  if (cinfo->comps_in_scan > 1) {
75
4.75M
    diff->MCU_rows_per_iMCU_row = 1;
76
46.4M
  } else {
77
46.4M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
46.4M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
4.68k
    else
80
4.68k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
46.4M
  }
82
83
51.1M
  diff->MCU_ctr = 0;
84
51.1M
  diff->MCU_vert_offset = 0;
85
51.1M
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
6.71M
{
68
6.71M
  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.71M
  if (cinfo->comps_in_scan > 1) {
75
194k
    diff->MCU_rows_per_iMCU_row = 1;
76
6.52M
  } else {
77
6.52M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
6.52M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
1.04k
    else
80
1.04k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
6.52M
  }
82
83
6.71M
  diff->MCU_ctr = 0;
84
6.71M
  diff->MCU_vert_offset = 0;
85
6.71M
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
32.4M
{
68
32.4M
  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
32.4M
  if (cinfo->comps_in_scan > 1) {
75
4.32M
    diff->MCU_rows_per_iMCU_row = 1;
76
28.0M
  } else {
77
28.0M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
28.0M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
2.74k
    else
80
2.74k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
28.0M
  }
82
83
32.4M
  diff->MCU_ctr = 0;
84
32.4M
  diff->MCU_vert_offset = 0;
85
32.4M
}
jddiffct-16.c:start_iMCU_row
Line
Count
Source
67
12.0M
{
68
12.0M
  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.0M
  if (cinfo->comps_in_scan > 1) {
75
234k
    diff->MCU_rows_per_iMCU_row = 1;
76
11.8M
  } else {
77
11.8M
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
11.8M
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
889
    else
80
889
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
11.8M
  }
82
83
12.0M
  diff->MCU_ctr = 0;
84
12.0M
  diff->MCU_vert_offset = 0;
85
12.0M
}
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
6.15k
{
95
6.15k
  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
6.15k
  (*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
6.15k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
16
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
6.15k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
6.15k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
6.15k
  cinfo->input_iMCU_row = 0;
115
6.15k
  start_iMCU_row(cinfo);
116
6.15k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
1.47k
{
95
1.47k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
1.47k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
1.47k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
9
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.47k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.47k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.47k
  cinfo->input_iMCU_row = 0;
115
1.47k
  start_iMCU_row(cinfo);
116
1.47k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
3.28k
{
95
3.28k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
3.28k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
3.28k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
4
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
3.28k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
3.28k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
3.28k
  cinfo->input_iMCU_row = 0;
115
3.28k
  start_iMCU_row(cinfo);
116
3.28k
}
jddiffct-16.c:start_input_pass
Line
Count
Source
94
1.38k
{
95
1.38k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
1.38k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
1.38k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
3
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
1.38k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
1.38k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
1.38k
  cinfo->input_iMCU_row = 0;
115
1.38k
  start_iMCU_row(cinfo);
116
1.38k
}
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
59.0k
{
127
59.0k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
59.0k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
59.0k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
59.0k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
59.0k
  return TRUE;
138
59.0k
}
jddiffct-8.c:process_restart
Line
Count
Source
126
4.47k
{
127
4.47k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
4.47k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
4.47k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
4.47k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
4.47k
  return TRUE;
138
4.47k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
50.7k
{
127
50.7k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
50.7k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
50.7k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
50.7k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
50.7k
  return TRUE;
138
50.7k
}
jddiffct-16.c:process_restart
Line
Count
Source
126
3.80k
{
127
3.80k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
3.80k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
3.80k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
3.80k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
3.80k
  return TRUE;
138
3.80k
}
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
768
{
148
768
  cinfo->output_iMCU_row = 0;
149
768
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
269
{
148
269
  cinfo->output_iMCU_row = 0;
149
269
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
261
{
148
261
  cinfo->output_iMCU_row = 0;
149
261
}
jddiffct-16.c:start_output_pass
Line
Count
Source
147
238
{
148
238
  cinfo->output_iMCU_row = 0;
149
238
}
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
51.1M
{
165
51.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
51.1M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
51.1M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
51.1M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
51.1M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
51.1M
  int ci, compi, row, prev_row;
171
51.1M
  unsigned int yoffset;
172
51.1M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
113M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
62.7M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
62.7M
    if (cinfo->restart_interval) {
180
18.5M
      if (diff->restart_rows_to_go == 0)
181
59.0k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
18.5M
    }
184
185
62.7M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
62.7M
    MCU_count =
188
62.7M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
62.7M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
62.7M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
62.7M
    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
62.7M
    if (cinfo->restart_interval)
200
18.5M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
62.7M
    diff->MCU_ctr = 0;
204
62.7M
  }
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
107M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
56.0M
    compptr = cinfo->cur_comp_info[ci];
213
56.0M
    compi = compptr->component_index;
214
56.0M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
128M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
128M
                compptr->last_row_height : compptr->v_samp_factor);
217
71.9M
         prev_row = row, row++) {
218
71.9M
      (*losslessd->predict_undifference[compi])
219
71.9M
        (cinfo, compi, diff->diff_buf[compi][row],
220
71.9M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
71.9M
          compptr->width_in_blocks);
222
71.9M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
71.9M
                                  output_buf[compi][row],
224
71.9M
                                  compptr->width_in_blocks);
225
71.9M
    }
226
56.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
51.1M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
51.1M
    start_iMCU_row(cinfo);
236
51.1M
    return JPEG_ROW_COMPLETED;
237
51.1M
  }
238
  /* Completed the scan */
239
6.04k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
6.04k
  return JPEG_SCAN_COMPLETED;
241
51.1M
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
6.71M
{
165
6.71M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
6.71M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
6.71M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
6.71M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
6.71M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
6.71M
  int ci, compi, row, prev_row;
171
6.71M
  unsigned int yoffset;
172
6.71M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
14.2M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
7.51M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
7.51M
    if (cinfo->restart_interval) {
180
1.06M
      if (diff->restart_rows_to_go == 0)
181
4.47k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
1.06M
    }
184
185
7.51M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
7.51M
    MCU_count =
188
7.51M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
7.51M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
7.51M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
7.51M
    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
7.51M
    if (cinfo->restart_interval)
200
1.06M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
7.51M
    diff->MCU_ctr = 0;
204
7.51M
  }
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
13.7M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
7.03M
    compptr = cinfo->cur_comp_info[ci];
213
7.03M
    compi = compptr->component_index;
214
7.03M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
15.0M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
15.0M
                compptr->last_row_height : compptr->v_samp_factor);
217
8.01M
         prev_row = row, row++) {
218
8.01M
      (*losslessd->predict_undifference[compi])
219
8.01M
        (cinfo, compi, diff->diff_buf[compi][row],
220
8.01M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
8.01M
          compptr->width_in_blocks);
222
8.01M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
8.01M
                                  output_buf[compi][row],
224
8.01M
                                  compptr->width_in_blocks);
225
8.01M
    }
226
7.03M
  }
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.71M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
6.71M
    start_iMCU_row(cinfo);
236
6.71M
    return JPEG_ROW_COMPLETED;
237
6.71M
  }
238
  /* Completed the scan */
239
1.43k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.43k
  return JPEG_SCAN_COMPLETED;
241
6.71M
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
32.4M
{
165
32.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
32.4M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
32.4M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
32.4M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
32.4M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
32.4M
  int ci, compi, row, prev_row;
171
32.4M
  unsigned int yoffset;
172
32.4M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
74.7M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
42.3M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
42.3M
    if (cinfo->restart_interval) {
180
16.8M
      if (diff->restart_rows_to_go == 0)
181
50.7k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
16.8M
    }
184
185
42.3M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
42.3M
    MCU_count =
188
42.3M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
42.3M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
42.3M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
42.3M
    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
42.3M
    if (cinfo->restart_interval)
200
16.8M
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
42.3M
    diff->MCU_ctr = 0;
204
42.3M
  }
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
69.1M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
36.7M
    compptr = cinfo->cur_comp_info[ci];
213
36.7M
    compi = compptr->component_index;
214
36.7M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
87.3M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
87.3M
                compptr->last_row_height : compptr->v_samp_factor);
217
50.6M
         prev_row = row, row++) {
218
50.6M
      (*losslessd->predict_undifference[compi])
219
50.6M
        (cinfo, compi, diff->diff_buf[compi][row],
220
50.6M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
50.6M
          compptr->width_in_blocks);
222
50.6M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
50.6M
                                  output_buf[compi][row],
224
50.6M
                                  compptr->width_in_blocks);
225
50.6M
    }
226
36.7M
  }
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
32.4M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
32.4M
    start_iMCU_row(cinfo);
236
32.4M
    return JPEG_ROW_COMPLETED;
237
32.4M
  }
238
  /* Completed the scan */
239
3.24k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
3.24k
  return JPEG_SCAN_COMPLETED;
241
32.4M
}
jddiffct-16.c:decompress_data
Line
Count
Source
164
12.0M
{
165
12.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
12.0M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
12.0M
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
12.0M
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
12.0M
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
12.0M
  int ci, compi, row, prev_row;
171
12.0M
  unsigned int yoffset;
172
12.0M
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
24.8M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
12.8M
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
12.8M
    if (cinfo->restart_interval) {
180
576k
      if (diff->restart_rows_to_go == 0)
181
3.80k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
576k
    }
184
185
12.8M
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
12.8M
    MCU_count =
188
12.8M
      (*cinfo->entropy->decode_mcus) (cinfo,
189
12.8M
                                      diff->diff_buf, yoffset, MCU_col_num,
190
12.8M
                                      cinfo->MCUs_per_row - MCU_col_num);
191
12.8M
    if (MCU_count != cinfo->MCUs_per_row - MCU_col_num) {
192
      /* Suspension forced; update state counters and exit */
193
0
      diff->MCU_vert_offset = yoffset;
194
0
      diff->MCU_ctr += MCU_count;
195
0
      return JPEG_SUSPENDED;
196
0
    }
197
198
    /* Account for restart interval (no-op if not using restarts) */
199
12.8M
    if (cinfo->restart_interval)
200
576k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
12.8M
    diff->MCU_ctr = 0;
204
12.8M
  }
205
206
  /*
207
   * Undifference and scale each scanline of the disassembled MCU row
208
   * separately.  We do not process dummy samples at the end of a scanline
209
   * or dummy rows at the end of the image.
210
   */
211
24.3M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
12.2M
    compptr = cinfo->cur_comp_info[ci];
213
12.2M
    compi = compptr->component_index;
214
12.2M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
25.5M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
25.5M
                compptr->last_row_height : compptr->v_samp_factor);
217
13.3M
         prev_row = row, row++) {
218
13.3M
      (*losslessd->predict_undifference[compi])
219
13.3M
        (cinfo, compi, diff->diff_buf[compi][row],
220
13.3M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
13.3M
          compptr->width_in_blocks);
222
13.3M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
13.3M
                                  output_buf[compi][row],
224
13.3M
                                  compptr->width_in_blocks);
225
13.3M
    }
226
12.2M
  }
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.0M
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
12.0M
    start_iMCU_row(cinfo);
236
12.0M
    return JPEG_ROW_COMPLETED;
237
12.0M
  }
238
  /* Completed the scan */
239
1.35k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
1.35k
  return JPEG_SCAN_COMPLETED;
241
12.0M
}
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
51.1M
{
267
51.1M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
51.1M
  int ci, compi;
269
51.1M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
51.1M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
107M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
56.0M
    compptr = cinfo->cur_comp_info[ci];
275
56.0M
    compi = compptr->component_index;
276
56.0M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
56.0M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
56.0M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
56.0M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
56.0M
  }
281
282
51.1M
  return decompress_data(cinfo, buffer);
283
51.1M
}
jddiffct-8.c:consume_data
Line
Count
Source
266
6.71M
{
267
6.71M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
6.71M
  int ci, compi;
269
6.71M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
6.71M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
13.7M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
7.03M
    compptr = cinfo->cur_comp_info[ci];
275
7.03M
    compi = compptr->component_index;
276
7.03M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
7.03M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
7.03M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
7.03M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
7.03M
  }
281
282
6.71M
  return decompress_data(cinfo, buffer);
283
6.71M
}
jddiffct-12.c:consume_data
Line
Count
Source
266
32.4M
{
267
32.4M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
32.4M
  int ci, compi;
269
32.4M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
32.4M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
69.1M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
36.7M
    compptr = cinfo->cur_comp_info[ci];
275
36.7M
    compi = compptr->component_index;
276
36.7M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
36.7M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
36.7M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
36.7M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
36.7M
  }
281
282
32.4M
  return decompress_data(cinfo, buffer);
283
32.4M
}
jddiffct-16.c:consume_data
Line
Count
Source
266
12.0M
{
267
12.0M
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
12.0M
  int ci, compi;
269
12.0M
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
12.0M
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
24.3M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
12.2M
    compptr = cinfo->cur_comp_info[ci];
275
12.2M
    compi = compptr->component_index;
276
12.2M
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
12.2M
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
12.2M
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
12.2M
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
12.2M
  }
281
282
12.0M
  return decompress_data(cinfo, buffer);
283
12.0M
}
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
0
{
297
0
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
0
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
0
  int ci, samp_rows, row;
300
0
  _JSAMPARRAY buffer;
301
0
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
0
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
0
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
0
          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
0
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
0
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
0
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
0
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
0
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
0
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
0
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
0
      samp_rows = compptr->v_samp_factor;
322
0
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
0
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
0
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
0
    }
327
328
0
    for (row = 0; row < samp_rows; row++) {
329
0
      memcpy(output_buf[ci][row], buffer[row],
330
0
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
0
    }
332
0
  }
333
334
0
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
0
    return JPEG_ROW_COMPLETED;
336
0
  return JPEG_SCAN_COMPLETED;
337
0
}
Unexecuted instantiation: jddiffct-8.c:output_data
Unexecuted instantiation: jddiffct-12.c:output_data
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
1.10k
{
349
1.10k
  my_diff_ptr diff;
350
1.10k
  int ci;
351
1.10k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
374
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
735
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
735
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
1.10k
  diff = (my_diff_ptr)
362
1.10k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
1.10k
                                sizeof(my_diff_controller));
364
1.10k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
1.10k
  diff->pub.start_input_pass = start_input_pass;
366
1.10k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
4.35k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
3.24k
       ci++, compptr++) {
371
3.24k
    diff->diff_buf[ci] =
372
3.24k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
3.24k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
3.24k
                                         (long)compptr->h_samp_factor),
375
3.24k
                   (JDIMENSION)compptr->v_samp_factor);
376
3.24k
    diff->undiff_buf[ci] =
377
3.24k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
3.24k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
3.24k
                                         (long)compptr->h_samp_factor),
380
3.24k
                   (JDIMENSION)compptr->v_samp_factor);
381
3.24k
  }
382
383
1.10k
  if (need_full_buffer) {
384
1.05k
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
1.05k
    int access_rows;
387
388
4.23k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
3.17k
         ci++, compptr++) {
390
3.17k
      access_rows = compptr->v_samp_factor;
391
3.17k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
3.17k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
3.17k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
3.17k
                               (long)compptr->h_samp_factor),
395
3.17k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
3.17k
                               (long)compptr->v_samp_factor),
397
3.17k
         (JDIMENSION)access_rows);
398
3.17k
    }
399
1.05k
    diff->pub.consume_data = consume_data;
400
1.05k
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
1.05k
  } else {
405
51
    diff->pub.consume_data = dummy_consume_data;
406
51
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
51
  }
409
1.10k
}
jinit_d_diff_controller
Line
Count
Source
348
374
{
349
374
  my_diff_ptr diff;
350
374
  int ci;
351
374
  jpeg_component_info *compptr;
352
353
374
#if BITS_IN_JSAMPLE == 8
354
374
  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
374
  diff = (my_diff_ptr)
362
374
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
374
                                sizeof(my_diff_controller));
364
374
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
374
  diff->pub.start_input_pass = start_input_pass;
366
374
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.47k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.10k
       ci++, compptr++) {
371
1.10k
    diff->diff_buf[ci] =
372
1.10k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.10k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.10k
                                         (long)compptr->h_samp_factor),
375
1.10k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.10k
    diff->undiff_buf[ci] =
377
1.10k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.10k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.10k
                                         (long)compptr->h_samp_factor),
380
1.10k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.10k
  }
382
383
374
  if (need_full_buffer) {
384
363
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
363
    int access_rows;
387
388
1.45k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.08k
         ci++, compptr++) {
390
1.08k
      access_rows = compptr->v_samp_factor;
391
1.08k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.08k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.08k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.08k
                               (long)compptr->h_samp_factor),
395
1.08k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.08k
                               (long)compptr->v_samp_factor),
397
1.08k
         (JDIMENSION)access_rows);
398
1.08k
    }
399
363
    diff->pub.consume_data = consume_data;
400
363
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
363
  } else {
405
11
    diff->pub.consume_data = dummy_consume_data;
406
11
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
11
  }
409
374
}
j12init_d_diff_controller
Line
Count
Source
348
388
{
349
388
  my_diff_ptr diff;
350
388
  int ci;
351
388
  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
388
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
388
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
388
  diff = (my_diff_ptr)
362
388
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
388
                                sizeof(my_diff_controller));
364
388
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
388
  diff->pub.start_input_pass = start_input_pass;
366
388
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.50k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.11k
       ci++, compptr++) {
371
1.11k
    diff->diff_buf[ci] =
372
1.11k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.11k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.11k
                                         (long)compptr->h_samp_factor),
375
1.11k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.11k
    diff->undiff_buf[ci] =
377
1.11k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.11k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.11k
                                         (long)compptr->h_samp_factor),
380
1.11k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.11k
  }
382
383
388
  if (need_full_buffer) {
384
362
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
362
    int access_rows;
387
388
1.44k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
1.08k
         ci++, compptr++) {
390
1.08k
      access_rows = compptr->v_samp_factor;
391
1.08k
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
1.08k
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
1.08k
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
1.08k
                               (long)compptr->h_samp_factor),
395
1.08k
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
1.08k
                               (long)compptr->v_samp_factor),
397
1.08k
         (JDIMENSION)access_rows);
398
1.08k
    }
399
362
    diff->pub.consume_data = consume_data;
400
362
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
362
  } else {
405
26
    diff->pub.consume_data = dummy_consume_data;
406
26
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
26
  }
409
388
}
j16init_d_diff_controller
Line
Count
Source
348
347
{
349
347
  my_diff_ptr diff;
350
347
  int ci;
351
347
  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
347
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
347
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
347
  diff = (my_diff_ptr)
362
347
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
347
                                sizeof(my_diff_controller));
364
347
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
347
  diff->pub.start_input_pass = start_input_pass;
366
347
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
1.37k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
1.02k
       ci++, compptr++) {
371
1.02k
    diff->diff_buf[ci] =
372
1.02k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
1.02k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
1.02k
                                         (long)compptr->h_samp_factor),
375
1.02k
                   (JDIMENSION)compptr->v_samp_factor);
376
1.02k
    diff->undiff_buf[ci] =
377
1.02k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
1.02k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
1.02k
                                         (long)compptr->h_samp_factor),
380
1.02k
                   (JDIMENSION)compptr->v_samp_factor);
381
1.02k
  }
382
383
347
  if (need_full_buffer) {
384
333
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
333
    int access_rows;
387
388
1.33k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
999
         ci++, compptr++) {
390
999
      access_rows = compptr->v_samp_factor;
391
999
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
999
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
999
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
999
                               (long)compptr->h_samp_factor),
395
999
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
999
                               (long)compptr->v_samp_factor),
397
999
         (JDIMENSION)access_rows);
398
999
    }
399
333
    diff->pub.consume_data = consume_data;
400
333
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
333
  } else {
405
14
    diff->pub.consume_data = dummy_consume_data;
406
14
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
14
  }
409
347
}
410
411
#endif /* D_LOSSLESS_SUPPORTED */