Coverage Report

Created: 2026-02-26 07:13

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
916k
{
68
916k
  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
916k
  if (cinfo->comps_in_scan > 1) {
75
163k
    diff->MCU_rows_per_iMCU_row = 1;
76
753k
  } else {
77
753k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
750k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
2.78k
    else
80
2.78k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
753k
  }
82
83
916k
  diff->MCU_ctr = 0;
84
916k
  diff->MCU_vert_offset = 0;
85
916k
}
jddiffct-8.c:start_iMCU_row
Line
Count
Source
67
885k
{
68
885k
  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
885k
  if (cinfo->comps_in_scan > 1) {
75
163k
    diff->MCU_rows_per_iMCU_row = 1;
76
722k
  } else {
77
722k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
719k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
2.61k
    else
80
2.61k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
722k
  }
82
83
885k
  diff->MCU_ctr = 0;
84
885k
  diff->MCU_vert_offset = 0;
85
885k
}
jddiffct-12.c:start_iMCU_row
Line
Count
Source
67
30.9k
{
68
30.9k
  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
30.9k
  if (cinfo->comps_in_scan > 1) {
75
0
    diff->MCU_rows_per_iMCU_row = 1;
76
30.9k
  } else {
77
30.9k
    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
78
30.7k
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
79
171
    else
80
171
      diff->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
81
30.9k
  }
82
83
30.9k
  diff->MCU_ctr = 0;
84
30.9k
  diff->MCU_vert_offset = 0;
85
30.9k
}
Unexecuted instantiation: jddiffct-16.c:start_iMCU_row
86
87
88
/*
89
 * Initialize for an input processing pass.
90
 */
91
92
METHODDEF(void)
93
start_input_pass(j_decompress_ptr cinfo)
94
4.72k
{
95
4.72k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
4.72k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
4.72k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
5
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
4.72k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
4.72k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
4.72k
  cinfo->input_iMCU_row = 0;
115
4.72k
  start_iMCU_row(cinfo);
116
4.72k
}
jddiffct-8.c:start_input_pass
Line
Count
Source
94
4.51k
{
95
4.51k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
96
97
  /* Because it is hitching a ride on the jpeg_inverse_dct struct,
98
   * start_pass_lossless() will be called at the start of the output pass.
99
   * This ensures that it will be called at the start of the input pass as
100
   * well.
101
   */
102
4.51k
  (*cinfo->idct->start_pass) (cinfo);
103
104
  /* Check that the restart interval is an integer multiple of the number
105
   * of MCUs in an MCU row.
106
   */
107
4.51k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
3
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
4.51k
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
4.51k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
4.51k
  cinfo->input_iMCU_row = 0;
115
4.51k
  start_iMCU_row(cinfo);
116
4.51k
}
jddiffct-12.c:start_input_pass
Line
Count
Source
94
205
{
95
205
  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
205
  (*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
205
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
108
2
    ERREXIT2(cinfo, JERR_BAD_RESTART,
109
205
             cinfo->restart_interval, cinfo->MCUs_per_row);
110
111
  /* Initialize restart counter */
112
205
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
113
114
205
  cinfo->input_iMCU_row = 0;
115
205
  start_iMCU_row(cinfo);
116
205
}
Unexecuted instantiation: jddiffct-16.c:start_input_pass
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
16.8k
{
127
16.8k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
16.8k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
16.8k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
16.8k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
16.8k
  return TRUE;
138
16.8k
}
jddiffct-8.c:process_restart
Line
Count
Source
126
16.4k
{
127
16.4k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
16.4k
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
16.4k
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
16.4k
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
16.4k
  return TRUE;
138
16.4k
}
jddiffct-12.c:process_restart
Line
Count
Source
126
325
{
127
325
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
128
129
325
  if (!(*cinfo->entropy->process_restart) (cinfo))
130
0
    return FALSE;
131
132
325
  (*cinfo->idct->start_pass) (cinfo);
133
134
  /* Reset restart counter */
135
325
  diff->restart_rows_to_go = cinfo->restart_interval / cinfo->MCUs_per_row;
136
137
325
  return TRUE;
138
325
}
Unexecuted instantiation: jddiffct-16.c:process_restart
139
140
141
/*
142
 * Initialize for an output processing pass.
143
 */
144
145
METHODDEF(void)
146
start_output_pass(j_decompress_ptr cinfo)
147
2.70k
{
148
2.70k
  cinfo->output_iMCU_row = 0;
149
2.70k
}
jddiffct-8.c:start_output_pass
Line
Count
Source
147
2.51k
{
148
2.51k
  cinfo->output_iMCU_row = 0;
149
2.51k
}
jddiffct-12.c:start_output_pass
Line
Count
Source
147
198
{
148
198
  cinfo->output_iMCU_row = 0;
149
198
}
Unexecuted instantiation: jddiffct-16.c:start_output_pass
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
916k
{
165
916k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
916k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
916k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
916k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
916k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
916k
  int ci, compi, row, prev_row;
171
916k
  unsigned int yoffset;
172
916k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
1.83M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
916k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
916k
    if (cinfo->restart_interval) {
180
102k
      if (diff->restart_rows_to_go == 0)
181
16.8k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
102k
    }
184
185
916k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
916k
    MCU_count =
188
916k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
916k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
916k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
916k
    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
916k
    if (cinfo->restart_interval)
200
102k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
916k
    diff->MCU_ctr = 0;
204
916k
  }
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.15M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
1.24M
    compptr = cinfo->cur_comp_info[ci];
213
1.24M
    compi = compptr->component_index;
214
1.24M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
2.48M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
2.47M
                compptr->last_row_height : compptr->v_samp_factor);
217
1.24M
         prev_row = row, row++) {
218
1.24M
      (*losslessd->predict_undifference[compi])
219
1.24M
        (cinfo, compi, diff->diff_buf[compi][row],
220
1.24M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
1.24M
          compptr->width_in_blocks);
222
1.24M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
1.24M
                                  output_buf[compi][row],
224
1.24M
                                  compptr->width_in_blocks);
225
1.24M
    }
226
1.24M
  }
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
916k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
912k
    start_iMCU_row(cinfo);
236
912k
    return JPEG_ROW_COMPLETED;
237
912k
  }
238
  /* Completed the scan */
239
3.46k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
3.46k
  return JPEG_SCAN_COMPLETED;
241
916k
}
jddiffct-8.c:decompress_data
Line
Count
Source
164
885k
{
165
885k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
885k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
885k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
885k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
885k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
885k
  int ci, compi, row, prev_row;
171
885k
  unsigned int yoffset;
172
885k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
1.77M
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
885k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
885k
    if (cinfo->restart_interval) {
180
101k
      if (diff->restart_rows_to_go == 0)
181
16.4k
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
101k
    }
184
185
885k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
885k
    MCU_count =
188
885k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
885k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
885k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
885k
    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
885k
    if (cinfo->restart_interval)
200
101k
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
885k
    diff->MCU_ctr = 0;
204
885k
  }
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.09M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
1.21M
    compptr = cinfo->cur_comp_info[ci];
213
1.21M
    compi = compptr->component_index;
214
1.21M
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
2.42M
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
2.41M
                compptr->last_row_height : compptr->v_samp_factor);
217
1.21M
         prev_row = row, row++) {
218
1.21M
      (*losslessd->predict_undifference[compi])
219
1.21M
        (cinfo, compi, diff->diff_buf[compi][row],
220
1.21M
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
1.21M
          compptr->width_in_blocks);
222
1.21M
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
1.21M
                                  output_buf[compi][row],
224
1.21M
                                  compptr->width_in_blocks);
225
1.21M
    }
226
1.21M
  }
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
885k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
882k
    start_iMCU_row(cinfo);
236
882k
    return JPEG_ROW_COMPLETED;
237
882k
  }
238
  /* Completed the scan */
239
3.29k
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
3.29k
  return JPEG_SCAN_COMPLETED;
241
885k
}
jddiffct-12.c:decompress_data
Line
Count
Source
164
30.8k
{
165
30.8k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
166
30.8k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
167
30.8k
  JDIMENSION MCU_col_num;       /* index of current MCU within row */
168
30.8k
  JDIMENSION MCU_count;         /* number of MCUs decoded */
169
30.8k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
170
30.8k
  int ci, compi, row, prev_row;
171
30.8k
  unsigned int yoffset;
172
30.8k
  jpeg_component_info *compptr;
173
174
  /* Loop to process as much as one whole iMCU row */
175
61.7k
  for (yoffset = diff->MCU_vert_offset; yoffset < diff->MCU_rows_per_iMCU_row;
176
30.8k
       yoffset++) {
177
178
    /* Process restart marker if needed; may have to suspend */
179
30.8k
    if (cinfo->restart_interval) {
180
943
      if (diff->restart_rows_to_go == 0)
181
325
        if (!process_restart(cinfo))
182
0
          return JPEG_SUSPENDED;
183
943
    }
184
185
30.8k
    MCU_col_num = diff->MCU_ctr;
186
    /* Try to fetch an MCU row (or remaining portion of suspended MCU row). */
187
30.8k
    MCU_count =
188
30.8k
      (*cinfo->entropy->decode_mcus) (cinfo,
189
30.8k
                                      diff->diff_buf, yoffset, MCU_col_num,
190
30.8k
                                      cinfo->MCUs_per_row - MCU_col_num);
191
30.8k
    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
30.8k
    if (cinfo->restart_interval)
200
943
      diff->restart_rows_to_go--;
201
202
    /* Completed an MCU row, but perhaps not an iMCU row */
203
30.8k
    diff->MCU_ctr = 0;
204
30.8k
  }
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
61.7k
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
212
30.8k
    compptr = cinfo->cur_comp_info[ci];
213
30.8k
    compi = compptr->component_index;
214
30.8k
    for (row = 0, prev_row = compptr->v_samp_factor - 1;
215
61.7k
         row < (cinfo->input_iMCU_row == last_iMCU_row ?
216
61.4k
                compptr->last_row_height : compptr->v_samp_factor);
217
30.8k
         prev_row = row, row++) {
218
30.8k
      (*losslessd->predict_undifference[compi])
219
30.8k
        (cinfo, compi, diff->diff_buf[compi][row],
220
30.8k
          diff->undiff_buf[compi][prev_row], diff->undiff_buf[compi][row],
221
30.8k
          compptr->width_in_blocks);
222
30.8k
      (*losslessd->scaler_scale) (cinfo, diff->undiff_buf[compi][row],
223
30.8k
                                  output_buf[compi][row],
224
30.8k
                                  compptr->width_in_blocks);
225
30.8k
    }
226
30.8k
  }
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
30.8k
  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
235
30.7k
    start_iMCU_row(cinfo);
236
30.7k
    return JPEG_ROW_COMPLETED;
237
30.7k
  }
238
  /* Completed the scan */
239
171
  (*cinfo->inputctl->finish_input_pass) (cinfo);
240
171
  return JPEG_SCAN_COMPLETED;
241
30.8k
}
Unexecuted instantiation: jddiffct-16.c:decompress_data
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
612k
{
267
612k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
612k
  int ci, compi;
269
612k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
612k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
1.52M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
914k
    compptr = cinfo->cur_comp_info[ci];
275
914k
    compi = compptr->component_index;
276
914k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
914k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
914k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
914k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
914k
  }
281
282
612k
  return decompress_data(cinfo, buffer);
283
612k
}
jddiffct-8.c:consume_data
Line
Count
Source
266
612k
{
267
612k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
268
612k
  int ci, compi;
269
612k
  _JSAMPARRAY buffer[MAX_COMPS_IN_SCAN];
270
612k
  jpeg_component_info *compptr;
271
272
  /* Align the virtual buffers for the components used in this scan. */
273
1.52M
  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
274
914k
    compptr = cinfo->cur_comp_info[ci];
275
914k
    compi = compptr->component_index;
276
914k
    buffer[compi] = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
277
914k
      ((j_common_ptr)cinfo, diff->whole_image[compi],
278
914k
       cinfo->input_iMCU_row * compptr->v_samp_factor,
279
914k
       (JDIMENSION)compptr->v_samp_factor, TRUE);
280
914k
  }
281
282
612k
  return decompress_data(cinfo, buffer);
283
612k
}
Unexecuted instantiation: jddiffct-12.c:consume_data
Unexecuted instantiation: jddiffct-16.c:consume_data
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
131k
{
297
131k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
131k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
131k
  int ci, samp_rows, row;
300
131k
  _JSAMPARRAY buffer;
301
131k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
131k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
131k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
131k
          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
526k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
394k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
394k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
394k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
394k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
394k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
394k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
394k
      samp_rows = compptr->v_samp_factor;
322
142
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
142
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
142
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
142
    }
327
328
789k
    for (row = 0; row < samp_rows; row++) {
329
394k
      memcpy(output_buf[ci][row], buffer[row],
330
394k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
394k
    }
332
394k
  }
333
334
131k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
131k
    return JPEG_ROW_COMPLETED;
336
67
  return JPEG_SCAN_COMPLETED;
337
131k
}
jddiffct-8.c:output_data
Line
Count
Source
296
131k
{
297
131k
  my_diff_ptr diff = (my_diff_ptr)cinfo->coef;
298
131k
  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
299
131k
  int ci, samp_rows, row;
300
131k
  _JSAMPARRAY buffer;
301
131k
  jpeg_component_info *compptr;
302
303
  /* Force some input to be done if we are getting ahead of the input. */
304
131k
  while (cinfo->input_scan_number < cinfo->output_scan_number ||
305
131k
         (cinfo->input_scan_number == cinfo->output_scan_number &&
306
131k
          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
526k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
313
394k
       ci++, compptr++) {
314
    /* Align the virtual buffer for this component. */
315
394k
    buffer = (_JSAMPARRAY)(*cinfo->mem->access_virt_sarray)
316
394k
      ((j_common_ptr)cinfo, diff->whole_image[ci],
317
394k
       cinfo->output_iMCU_row * compptr->v_samp_factor,
318
394k
       (JDIMENSION)compptr->v_samp_factor, FALSE);
319
320
394k
    if (cinfo->output_iMCU_row < last_iMCU_row)
321
394k
      samp_rows = compptr->v_samp_factor;
322
142
    else {
323
      /* NB: can't use last_row_height here; it is input-side-dependent! */
324
142
      samp_rows = (int)(compptr->height_in_blocks % compptr->v_samp_factor);
325
142
      if (samp_rows == 0) samp_rows = compptr->v_samp_factor;
326
142
    }
327
328
789k
    for (row = 0; row < samp_rows; row++) {
329
394k
      memcpy(output_buf[ci][row], buffer[row],
330
394k
             compptr->width_in_blocks * sizeof(_JSAMPLE));
331
394k
    }
332
394k
  }
333
334
131k
  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
335
131k
    return JPEG_ROW_COMPLETED;
336
67
  return JPEG_SCAN_COMPLETED;
337
131k
}
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
4.48k
{
349
4.48k
  my_diff_ptr diff;
350
4.48k
  int ci;
351
4.48k
  jpeg_component_info *compptr;
352
353
#if BITS_IN_JSAMPLE == 8
354
4.28k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
355
#else
356
205
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
205
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
4.48k
  diff = (my_diff_ptr)
362
4.48k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
4.48k
                                sizeof(my_diff_controller));
364
4.48k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
4.48k
  diff->pub.start_input_pass = start_input_pass;
366
4.48k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
9.23k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.74k
       ci++, compptr++) {
371
4.74k
    diff->diff_buf[ci] =
372
4.74k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.74k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.74k
                                         (long)compptr->h_samp_factor),
375
4.74k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.74k
    diff->undiff_buf[ci] =
377
4.74k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.74k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.74k
                                         (long)compptr->h_samp_factor),
380
4.74k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.74k
  }
382
383
4.48k
  if (need_full_buffer) {
384
102
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
102
    int access_rows;
387
388
408
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
306
         ci++, compptr++) {
390
306
      access_rows = compptr->v_samp_factor;
391
306
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
306
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
306
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
306
                               (long)compptr->h_samp_factor),
395
306
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
306
                               (long)compptr->v_samp_factor),
397
306
         (JDIMENSION)access_rows);
398
306
    }
399
102
    diff->pub.consume_data = consume_data;
400
102
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
4.38k
  } else {
405
4.38k
    diff->pub.consume_data = dummy_consume_data;
406
4.38k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
4.38k
  }
409
4.48k
}
jinit_d_diff_controller
Line
Count
Source
348
4.28k
{
349
4.28k
  my_diff_ptr diff;
350
4.28k
  int ci;
351
4.28k
  jpeg_component_info *compptr;
352
353
4.28k
#if BITS_IN_JSAMPLE == 8
354
4.28k
  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
4.28k
  diff = (my_diff_ptr)
362
4.28k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
4.28k
                                sizeof(my_diff_controller));
364
4.28k
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
4.28k
  diff->pub.start_input_pass = start_input_pass;
366
4.28k
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
8.82k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
4.54k
       ci++, compptr++) {
371
4.54k
    diff->diff_buf[ci] =
372
4.54k
      ALLOC_DARRAY(JPOOL_IMAGE,
373
4.54k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
4.54k
                                         (long)compptr->h_samp_factor),
375
4.54k
                   (JDIMENSION)compptr->v_samp_factor);
376
4.54k
    diff->undiff_buf[ci] =
377
4.54k
      ALLOC_DARRAY(JPOOL_IMAGE,
378
4.54k
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
4.54k
                                         (long)compptr->h_samp_factor),
380
4.54k
                   (JDIMENSION)compptr->v_samp_factor);
381
4.54k
  }
382
383
4.28k
  if (need_full_buffer) {
384
102
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
102
    int access_rows;
387
388
408
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
306
         ci++, compptr++) {
390
306
      access_rows = compptr->v_samp_factor;
391
306
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
306
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
306
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
306
                               (long)compptr->h_samp_factor),
395
306
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
306
                               (long)compptr->v_samp_factor),
397
306
         (JDIMENSION)access_rows);
398
306
    }
399
102
    diff->pub.consume_data = consume_data;
400
102
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
4.18k
  } else {
405
4.18k
    diff->pub.consume_data = dummy_consume_data;
406
4.18k
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
4.18k
  }
409
4.28k
}
j12init_d_diff_controller
Line
Count
Source
348
205
{
349
205
  my_diff_ptr diff;
350
205
  int ci;
351
205
  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
205
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
357
205
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
358
0
#endif
359
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
360
361
205
  diff = (my_diff_ptr)
362
205
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
363
205
                                sizeof(my_diff_controller));
364
205
  cinfo->coef = (struct jpeg_d_coef_controller *)diff;
365
205
  diff->pub.start_input_pass = start_input_pass;
366
205
  diff->pub.start_output_pass = start_output_pass;
367
368
  /* Create the [un]difference buffers. */
369
410
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
370
205
       ci++, compptr++) {
371
205
    diff->diff_buf[ci] =
372
205
      ALLOC_DARRAY(JPOOL_IMAGE,
373
205
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
374
205
                                         (long)compptr->h_samp_factor),
375
205
                   (JDIMENSION)compptr->v_samp_factor);
376
205
    diff->undiff_buf[ci] =
377
205
      ALLOC_DARRAY(JPOOL_IMAGE,
378
205
                   (JDIMENSION)jround_up((long)compptr->width_in_blocks,
379
205
                                         (long)compptr->h_samp_factor),
380
205
                   (JDIMENSION)compptr->v_samp_factor);
381
205
  }
382
383
205
  if (need_full_buffer) {
384
0
#ifdef D_MULTISCAN_FILES_SUPPORTED
385
    /* Allocate a full-image virtual array for each component. */
386
0
    int access_rows;
387
388
0
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
389
0
         ci++, compptr++) {
390
0
      access_rows = compptr->v_samp_factor;
391
0
      diff->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
392
0
        ((j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
393
0
         (JDIMENSION)jround_up((long)compptr->width_in_blocks,
394
0
                               (long)compptr->h_samp_factor),
395
0
         (JDIMENSION)jround_up((long)compptr->height_in_blocks,
396
0
                               (long)compptr->v_samp_factor),
397
0
         (JDIMENSION)access_rows);
398
0
    }
399
0
    diff->pub.consume_data = consume_data;
400
0
    diff->pub._decompress_data = output_data;
401
#else
402
    ERREXIT(cinfo, JERR_NOT_COMPILED);
403
#endif
404
205
  } else {
405
205
    diff->pub.consume_data = dummy_consume_data;
406
205
    diff->pub._decompress_data = decompress_data;
407
    diff->whole_image[0] = NULL; /* flag for no virtual arrays */
408
205
  }
409
205
}
Unexecuted instantiation: j16init_d_diff_controller
410
411
#endif /* D_LOSSLESS_SUPPORTED */