Coverage Report

Created: 2026-06-09 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo/src/jdlossls.c
Line
Count
Source
1
/*
2
 * jdlossls.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1998, Thomas G. Lane.
6
 * Lossless JPEG Modifications:
7
 * Copyright (C) 1999, Ken Murchison.
8
 * libjpeg-turbo Modifications:
9
 * Copyright (C) 2022, 2024, 2026, D. R. Commander.
10
 * For conditions of distribution and use, see the accompanying README.ijg
11
 * file.
12
 *
13
 * This file contains prediction, sample undifferencing, point transform, and
14
 * sample scaling routines for the lossless JPEG decompressor.
15
 */
16
17
#define JPEG_INTERNALS
18
#include "jinclude.h"
19
#include "jpeglib.h"
20
#include "jlossls.h"
21
22
#ifdef D_LOSSLESS_SUPPORTED
23
24
25
/**************** Sample undifferencing (reconstruction) *****************/
26
27
/*
28
 * In order to avoid a performance penalty for checking which predictor is
29
 * being used and which row is being processed for each call of the
30
 * undifferencer, and to promote optimization, we have separate undifferencing
31
 * functions for each predictor selection value.
32
 *
33
 * We are able to avoid duplicating source code by implementing the predictors
34
 * and undifferencers as macros.  Each of the undifferencing functions is
35
 * simply a wrapper around an UNDIFFERENCE macro with the appropriate PREDICTOR
36
 * macro passed as an argument.
37
 */
38
39
/* Predictor for the first column of the first row: 2^(P-Pt-1) */
40
#define INITIAL_PREDICTORx  (1 << (cinfo->data_precision - cinfo->Al - 1))
41
42
/* Predictor for the first column of the remaining rows: Rb */
43
#define INITIAL_PREDICTOR2  prev_row[0]
44
45
46
/*
47
 * 1-Dimensional undifferencer routine.
48
 *
49
 * This macro implements the 1-D horizontal predictor (1).  INITIAL_PREDICTOR
50
 * is used as the special case predictor for the first column, which must be
51
 * either INITIAL_PREDICTOR2 or INITIAL_PREDICTORx.  The remaining samples
52
 * use PREDICTOR1.
53
 *
54
 * The reconstructed sample is supposed to be calculated modulo 2^16, so we
55
 * logically AND the result with 0xFFFF.
56
 */
57
58
#define UNDIFFERENCE_1D(INITIAL_PREDICTOR) \
59
42.4k
  int Ra; \
60
42.4k
  \
61
42.4k
  Ra = (*diff_buf++ + INITIAL_PREDICTOR) & 0xFFFF; \
62
42.4k
  *undiff_buf++ = Ra; \
63
42.4k
  \
64
331k
  while (--width) { \
65
289k
    Ra = (*diff_buf++ + PREDICTOR1) & 0xFFFF; \
66
289k
    *undiff_buf++ = Ra; \
67
289k
  }
68
69
70
/*
71
 * 2-Dimensional undifferencer routine.
72
 *
73
 * This macro implements the 2-D horizontal predictors (#2-7).  PREDICTOR2 is
74
 * used as the special case predictor for the first column.  The remaining
75
 * samples use PREDICTOR, which is a function of Ra, Rb, and Rc.
76
 *
77
 * Because prev_row and output_buf may point to the same storage area (in an
78
 * interleaved image with Vi=1, for example), we must take care to buffer Rb/Rc
79
 * before writing the current reconstructed sample value into output_buf.
80
 *
81
 * The reconstructed sample is supposed to be calculated modulo 2^16, so we
82
 * logically AND the result with 0xFFFF.
83
 */
84
85
#define UNDIFFERENCE_2D(PREDICTOR) \
86
50.0k
  int Ra, Rb, Rc; \
87
50.0k
  \
88
50.0k
  Rb = *prev_row++; \
89
50.0k
  Ra = (*diff_buf++ + PREDICTOR2) & 0xFFFF; \
90
50.0k
  *undiff_buf++ = Ra; \
91
50.0k
  \
92
895k
  while (--width) { \
93
845k
    Rc = Rb; \
94
845k
    Rb = *prev_row++; \
95
845k
    Ra = (*diff_buf++ + PREDICTOR) & 0xFFFF; \
96
845k
    *undiff_buf++ = Ra; \
97
845k
  }
98
99
100
/*
101
 * Undifferencers for the second and subsequent rows in a scan or restart
102
 * interval.  The first sample in the row is undifferenced using the vertical
103
 * predictor (2).  The rest of the samples are undifferenced using the
104
 * predictor specified in the scan header.
105
 */
106
107
METHODDEF(void)
108
jpeg_undifference1(j_decompress_ptr cinfo, int comp_index,
109
                   JDIFFROW diff_buf, JDIFFROW prev_row,
110
                   JDIFFROW undiff_buf, JDIMENSION width)
111
40.0k
{
112
40.0k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
40.0k
}
jdlossls-8.c:jpeg_undifference1
Line
Count
Source
111
1.88k
{
112
1.88k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
1.88k
}
jdlossls-12.c:jpeg_undifference1
Line
Count
Source
111
2.71k
{
112
2.71k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
2.71k
}
jdlossls-16.c:jpeg_undifference1
Line
Count
Source
111
35.4k
{
112
35.4k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
35.4k
}
114
115
METHODDEF(void)
116
jpeg_undifference2(j_decompress_ptr cinfo, int comp_index,
117
                   JDIFFROW diff_buf, JDIFFROW prev_row,
118
                   JDIFFROW undiff_buf, JDIMENSION width)
119
15.4k
{
120
15.4k
  UNDIFFERENCE_2D(PREDICTOR2);
121
15.4k
  (void)(Rc);
122
15.4k
}
jdlossls-8.c:jpeg_undifference2
Line
Count
Source
119
4.45k
{
120
4.45k
  UNDIFFERENCE_2D(PREDICTOR2);
121
4.45k
  (void)(Rc);
122
4.45k
}
jdlossls-12.c:jpeg_undifference2
Line
Count
Source
119
1.43k
{
120
1.43k
  UNDIFFERENCE_2D(PREDICTOR2);
121
1.43k
  (void)(Rc);
122
1.43k
}
jdlossls-16.c:jpeg_undifference2
Line
Count
Source
119
9.55k
{
120
9.55k
  UNDIFFERENCE_2D(PREDICTOR2);
121
9.55k
  (void)(Rc);
122
9.55k
}
123
124
METHODDEF(void)
125
jpeg_undifference3(j_decompress_ptr cinfo, int comp_index,
126
                   JDIFFROW diff_buf, JDIFFROW prev_row,
127
                   JDIFFROW undiff_buf, JDIMENSION width)
128
13.5k
{
129
13.5k
  UNDIFFERENCE_2D(PREDICTOR3);
130
13.5k
}
jdlossls-8.c:jpeg_undifference3
Line
Count
Source
128
5.98k
{
129
5.98k
  UNDIFFERENCE_2D(PREDICTOR3);
130
5.98k
}
jdlossls-12.c:jpeg_undifference3
Line
Count
Source
128
2.21k
{
129
2.21k
  UNDIFFERENCE_2D(PREDICTOR3);
130
2.21k
}
jdlossls-16.c:jpeg_undifference3
Line
Count
Source
128
5.30k
{
129
5.30k
  UNDIFFERENCE_2D(PREDICTOR3);
130
5.30k
}
131
132
METHODDEF(void)
133
jpeg_undifference4(j_decompress_ptr cinfo, int comp_index,
134
                   JDIFFROW diff_buf, JDIFFROW prev_row,
135
                   JDIFFROW undiff_buf, JDIMENSION width)
136
5.92k
{
137
5.92k
  UNDIFFERENCE_2D(PREDICTOR4);
138
5.92k
}
jdlossls-8.c:jpeg_undifference4
Line
Count
Source
136
3.84k
{
137
3.84k
  UNDIFFERENCE_2D(PREDICTOR4);
138
3.84k
}
jdlossls-12.c:jpeg_undifference4
Line
Count
Source
136
1.31k
{
137
1.31k
  UNDIFFERENCE_2D(PREDICTOR4);
138
1.31k
}
jdlossls-16.c:jpeg_undifference4
Line
Count
Source
136
770
{
137
770
  UNDIFFERENCE_2D(PREDICTOR4);
138
770
}
139
140
METHODDEF(void)
141
jpeg_undifference5(j_decompress_ptr cinfo, int comp_index,
142
                   JDIFFROW diff_buf, JDIFFROW prev_row,
143
                   JDIFFROW undiff_buf, JDIMENSION width)
144
5.10k
{
145
5.10k
  UNDIFFERENCE_2D(PREDICTOR5);
146
5.10k
}
jdlossls-8.c:jpeg_undifference5
Line
Count
Source
144
1.68k
{
145
1.68k
  UNDIFFERENCE_2D(PREDICTOR5);
146
1.68k
}
jdlossls-12.c:jpeg_undifference5
Line
Count
Source
144
1.46k
{
145
1.46k
  UNDIFFERENCE_2D(PREDICTOR5);
146
1.46k
}
jdlossls-16.c:jpeg_undifference5
Line
Count
Source
144
1.96k
{
145
1.96k
  UNDIFFERENCE_2D(PREDICTOR5);
146
1.96k
}
147
148
METHODDEF(void)
149
jpeg_undifference6(j_decompress_ptr cinfo, int comp_index,
150
                   JDIFFROW diff_buf, JDIFFROW prev_row,
151
                   JDIFFROW undiff_buf, JDIMENSION width)
152
5.24k
{
153
5.24k
  UNDIFFERENCE_2D(PREDICTOR6);
154
5.24k
}
jdlossls-8.c:jpeg_undifference6
Line
Count
Source
152
993
{
153
993
  UNDIFFERENCE_2D(PREDICTOR6);
154
993
}
jdlossls-12.c:jpeg_undifference6
Line
Count
Source
152
666
{
153
666
  UNDIFFERENCE_2D(PREDICTOR6);
154
666
}
jdlossls-16.c:jpeg_undifference6
Line
Count
Source
152
3.58k
{
153
3.58k
  UNDIFFERENCE_2D(PREDICTOR6);
154
3.58k
}
155
156
METHODDEF(void)
157
jpeg_undifference7(j_decompress_ptr cinfo, int comp_index,
158
                   JDIFFROW diff_buf, JDIFFROW prev_row,
159
                   JDIFFROW undiff_buf, JDIMENSION width)
160
4.86k
{
161
4.86k
  UNDIFFERENCE_2D(PREDICTOR7);
162
4.86k
  (void)(Rc);
163
4.86k
}
jdlossls-8.c:jpeg_undifference7
Line
Count
Source
160
2.01k
{
161
2.01k
  UNDIFFERENCE_2D(PREDICTOR7);
162
2.01k
  (void)(Rc);
163
2.01k
}
jdlossls-12.c:jpeg_undifference7
Line
Count
Source
160
979
{
161
979
  UNDIFFERENCE_2D(PREDICTOR7);
162
979
  (void)(Rc);
163
979
}
jdlossls-16.c:jpeg_undifference7
Line
Count
Source
160
1.87k
{
161
1.87k
  UNDIFFERENCE_2D(PREDICTOR7);
162
1.87k
  (void)(Rc);
163
1.87k
}
164
165
166
/*
167
 * Undifferencer for the first row in a scan or restart interval.  The first
168
 * sample in the row is undifferenced using the special predictor constant
169
 * x=2^(P-Pt-1).  The rest of the samples are undifferenced using the
170
 * 1-D horizontal predictor (1).
171
 */
172
173
METHODDEF(void)
174
jpeg_undifference_first_row(j_decompress_ptr cinfo, int comp_index,
175
                            JDIFFROW diff_buf, JDIFFROW prev_row,
176
                            JDIFFROW undiff_buf, JDIMENSION width)
177
2.45k
{
178
2.45k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
2.45k
  UNDIFFERENCE_1D(INITIAL_PREDICTORx);
181
182
  /*
183
   * Now that we have undifferenced the first row, we want to use the
184
   * undifferencer that corresponds to the predictor specified in the
185
   * scan header.
186
   */
187
2.45k
  switch (cinfo->Ss) {
188
235
  case 1:
189
235
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
235
    break;
191
298
  case 2:
192
298
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
298
    break;
194
346
  case 3:
195
346
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
346
    break;
197
206
  case 4:
198
206
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
206
    break;
200
174
  case 5:
201
174
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
174
    break;
203
410
  case 6:
204
410
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
410
    break;
206
783
  case 7:
207
783
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
783
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
2.45k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
2.45k
  }
213
2.45k
}
jdlossls-8.c:jpeg_undifference_first_row
Line
Count
Source
177
1.09k
{
178
1.09k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
1.09k
  UNDIFFERENCE_1D(INITIAL_PREDICTORx);
181
182
  /*
183
   * Now that we have undifferenced the first row, we want to use the
184
   * undifferencer that corresponds to the predictor specified in the
185
   * scan header.
186
   */
187
1.09k
  switch (cinfo->Ss) {
188
129
  case 1:
189
129
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
129
    break;
191
145
  case 2:
192
145
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
145
    break;
194
178
  case 3:
195
178
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
178
    break;
197
112
  case 4:
198
112
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
112
    break;
200
91
  case 5:
201
91
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
91
    break;
203
151
  case 6:
204
151
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
151
    break;
206
292
  case 7:
207
292
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
292
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
1.09k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
1.09k
  }
213
1.09k
}
jdlossls-12.c:jpeg_undifference_first_row
Line
Count
Source
177
686
{
178
686
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
686
  UNDIFFERENCE_1D(INITIAL_PREDICTORx);
181
182
  /*
183
   * Now that we have undifferenced the first row, we want to use the
184
   * undifferencer that corresponds to the predictor specified in the
185
   * scan header.
186
   */
187
686
  switch (cinfo->Ss) {
188
57
  case 1:
189
57
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
57
    break;
191
51
  case 2:
192
51
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
51
    break;
194
80
  case 3:
195
80
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
80
    break;
197
51
  case 4:
198
51
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
51
    break;
200
46
  case 5:
201
46
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
46
    break;
203
129
  case 6:
204
129
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
129
    break;
206
272
  case 7:
207
272
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
272
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
686
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
686
  }
213
686
}
jdlossls-16.c:jpeg_undifference_first_row
Line
Count
Source
177
668
{
178
668
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
668
  UNDIFFERENCE_1D(INITIAL_PREDICTORx);
181
182
  /*
183
   * Now that we have undifferenced the first row, we want to use the
184
   * undifferencer that corresponds to the predictor specified in the
185
   * scan header.
186
   */
187
668
  switch (cinfo->Ss) {
188
49
  case 1:
189
49
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
49
    break;
191
102
  case 2:
192
102
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
102
    break;
194
88
  case 3:
195
88
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
88
    break;
197
43
  case 4:
198
43
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
43
    break;
200
37
  case 5:
201
37
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
37
    break;
203
130
  case 6:
204
130
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
130
    break;
206
219
  case 7:
207
219
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
219
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
668
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
668
  }
213
668
}
214
215
216
/*********************** Sample upscaling by 2^Pt ************************/
217
218
METHODDEF(void)
219
simple_upscale(j_decompress_ptr cinfo,
220
               JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
221
20.0k
{
222
232k
  do {
223
232k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
232k
  } while (--width);
225
20.0k
}
jdlossls-8.c:simple_upscale
Line
Count
Source
221
10.1k
{
222
155k
  do {
223
155k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
155k
  } while (--width);
225
10.1k
}
jdlossls-12.c:simple_upscale
Line
Count
Source
221
3.13k
{
222
32.5k
  do {
223
32.5k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
32.5k
  } while (--width);
225
3.13k
}
jdlossls-16.c:simple_upscale
Line
Count
Source
221
6.77k
{
222
44.8k
  do {
223
44.8k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
44.8k
  } while (--width);
225
6.77k
}
226
227
METHODDEF(void)
228
noscale(j_decompress_ptr cinfo,
229
        JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
230
72.5k
{
231
994k
  do {
232
994k
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
994k
  } while (--width);
234
72.5k
}
jdlossls-8.c:noscale
Line
Count
Source
230
11.8k
{
231
107k
  do {
232
107k
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
107k
  } while (--width);
234
11.8k
}
jdlossls-12.c:noscale
Line
Count
Source
230
8.33k
{
231
32.5k
  do {
232
32.5k
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
32.5k
  } while (--width);
234
8.33k
}
jdlossls-16.c:noscale
Line
Count
Source
230
52.3k
{
231
854k
  do {
232
854k
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
854k
  } while (--width);
234
52.3k
}
235
236
237
/*
238
 * Initialize for an input processing pass.
239
 */
240
241
METHODDEF(void)
242
start_pass_lossless(j_decompress_ptr cinfo)
243
2.29k
{
244
2.29k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
2.29k
  int ci;
246
247
  /* Check that the scan parameters Ss, Se, Ah, Al are OK for lossless JPEG.
248
   *
249
   * Ss is the predictor selection value (psv).  Legal values for sequential
250
   * lossless JPEG are: 1 <= psv <= 7.
251
   *
252
   * Se and Ah are not used and should be zero.
253
   *
254
   * Al specifies the point transform (Pt).
255
   * Legal values are: 0 <= Pt <= (data precision - 1).
256
   */
257
2.29k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
2.26k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
2.23k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
67
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
2.29k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
9.23k
  for (ci = 0; ci < cinfo->num_components; ci++)
265
6.94k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
2.29k
  if (cinfo->Al)
269
895
    losslessd->scaler_scale = simple_upscale;
270
1.39k
  else
271
1.39k
    losslessd->scaler_scale = noscale;
272
2.29k
}
jdlossls-8.c:start_pass_lossless
Line
Count
Source
243
859
{
244
859
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
859
  int ci;
246
247
  /* Check that the scan parameters Ss, Se, Ah, Al are OK for lossless JPEG.
248
   *
249
   * Ss is the predictor selection value (psv).  Legal values for sequential
250
   * lossless JPEG are: 1 <= psv <= 7.
251
   *
252
   * Se and Ah are not used and should be zero.
253
   *
254
   * Al specifies the point transform (Pt).
255
   * Legal values are: 0 <= Pt <= (data precision - 1).
256
   */
257
859
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
854
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
845
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
16
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
859
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
3.64k
  for (ci = 0; ci < cinfo->num_components; ci++)
265
2.78k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
859
  if (cinfo->Al)
269
371
    losslessd->scaler_scale = simple_upscale;
270
488
  else
271
488
    losslessd->scaler_scale = noscale;
272
859
}
jdlossls-12.c:start_pass_lossless
Line
Count
Source
243
728
{
244
728
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
728
  int ci;
246
247
  /* Check that the scan parameters Ss, Se, Ah, Al are OK for lossless JPEG.
248
   *
249
   * Ss is the predictor selection value (psv).  Legal values for sequential
250
   * lossless JPEG are: 1 <= psv <= 7.
251
   *
252
   * Se and Ah are not used and should be zero.
253
   *
254
   * Al specifies the point transform (Pt).
255
   * Legal values are: 0 <= Pt <= (data precision - 1).
256
   */
257
728
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
719
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
709
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
24
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
728
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
2.84k
  for (ci = 0; ci < cinfo->num_components; ci++)
265
2.12k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
728
  if (cinfo->Al)
269
246
    losslessd->scaler_scale = simple_upscale;
270
482
  else
271
482
    losslessd->scaler_scale = noscale;
272
728
}
jdlossls-16.c:start_pass_lossless
Line
Count
Source
243
705
{
244
705
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
705
  int ci;
246
247
  /* Check that the scan parameters Ss, Se, Ah, Al are OK for lossless JPEG.
248
   *
249
   * Ss is the predictor selection value (psv).  Legal values for sequential
250
   * lossless JPEG are: 1 <= psv <= 7.
251
   *
252
   * Se and Ah are not used and should be zero.
253
   *
254
   * Al specifies the point transform (Pt).
255
   * Legal values are: 0 <= Pt <= (data precision - 1).
256
   */
257
705
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
692
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
681
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
27
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
705
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
2.74k
  for (ci = 0; ci < cinfo->num_components; ci++)
265
2.04k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
705
  if (cinfo->Al)
269
278
    losslessd->scaler_scale = simple_upscale;
270
427
  else
271
427
    losslessd->scaler_scale = noscale;
272
705
}
273
274
275
/*
276
 * Initialize the lossless decompressor.
277
 */
278
279
GLOBAL(void)
280
_jinit_lossless_decompressor(j_decompress_ptr cinfo)
281
1.12k
{
282
1.12k
  lossless_decomp_ptr losslessd;
283
284
#if BITS_IN_JSAMPLE == 8
285
373
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
286
#else
287
756
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
756
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
289
0
#endif
290
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
291
292
  /* Create subobject in permanent pool */
293
1.12k
  losslessd = (lossless_decomp_ptr)
294
1.12k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
1.12k
                                sizeof(jpeg_lossless_decompressor));
296
1.12k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
1.12k
  losslessd->pub.start_pass = start_pass_lossless;
298
1.12k
}
jinit_lossless_decompressor
Line
Count
Source
281
373
{
282
373
  lossless_decomp_ptr losslessd;
283
284
373
#if BITS_IN_JSAMPLE == 8
285
373
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
286
#else
287
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
289
#endif
290
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
291
292
  /* Create subobject in permanent pool */
293
373
  losslessd = (lossless_decomp_ptr)
294
373
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
373
                                sizeof(jpeg_lossless_decompressor));
296
373
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
373
  losslessd->pub.start_pass = start_pass_lossless;
298
373
}
j12init_lossless_decompressor
Line
Count
Source
281
357
{
282
357
  lossless_decomp_ptr losslessd;
283
284
#if BITS_IN_JSAMPLE == 8
285
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
286
#else
287
357
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
357
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
289
0
#endif
290
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
291
292
  /* Create subobject in permanent pool */
293
357
  losslessd = (lossless_decomp_ptr)
294
357
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
357
                                sizeof(jpeg_lossless_decompressor));
296
357
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
357
  losslessd->pub.start_pass = start_pass_lossless;
298
357
}
j16init_lossless_decompressor
Line
Count
Source
281
399
{
282
399
  lossless_decomp_ptr losslessd;
283
284
#if BITS_IN_JSAMPLE == 8
285
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
286
#else
287
399
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
399
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
289
0
#endif
290
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
291
292
  /* Create subobject in permanent pool */
293
399
  losslessd = (lossless_decomp_ptr)
294
399
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
399
                                sizeof(jpeg_lossless_decompressor));
296
399
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
399
  losslessd->pub.start_pass = start_pass_lossless;
298
399
}
299
300
#endif /* D_LOSSLESS_SUPPORTED */