Coverage Report

Created: 2026-04-12 07:01

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
16.9k
  int Ra; \
60
16.9k
  \
61
16.9k
  Ra = (*diff_buf++ + INITIAL_PREDICTOR) & 0xFFFF; \
62
16.9k
  *undiff_buf++ = Ra; \
63
16.9k
  \
64
151k
  while (--width) { \
65
134k
    Ra = (*diff_buf++ + PREDICTOR1) & 0xFFFF; \
66
134k
    *undiff_buf++ = Ra; \
67
134k
  }
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
98.3k
  int Ra, Rb, Rc; \
87
98.3k
  \
88
98.3k
  Rb = *prev_row++; \
89
98.3k
  Ra = (*diff_buf++ + PREDICTOR2) & 0xFFFF; \
90
98.3k
  *undiff_buf++ = Ra; \
91
98.3k
  \
92
593k
  while (--width) { \
93
495k
    Rc = Rb; \
94
495k
    Rb = *prev_row++; \
95
495k
    Ra = (*diff_buf++ + PREDICTOR) & 0xFFFF; \
96
495k
    *undiff_buf++ = Ra; \
97
495k
  }
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
12.3k
{
112
12.3k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
12.3k
}
jdlossls-8.c:jpeg_undifference1
Line
Count
Source
111
3.16k
{
112
3.16k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
3.16k
}
jdlossls-12.c:jpeg_undifference1
Line
Count
Source
111
3.96k
{
112
3.96k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
3.96k
}
jdlossls-16.c:jpeg_undifference1
Line
Count
Source
111
5.22k
{
112
5.22k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
5.22k
}
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
7.64k
{
120
7.64k
  UNDIFFERENCE_2D(PREDICTOR2);
121
7.64k
  (void)(Rc);
122
7.64k
}
jdlossls-8.c:jpeg_undifference2
Line
Count
Source
119
2.74k
{
120
2.74k
  UNDIFFERENCE_2D(PREDICTOR2);
121
2.74k
  (void)(Rc);
122
2.74k
}
jdlossls-12.c:jpeg_undifference2
Line
Count
Source
119
2.26k
{
120
2.26k
  UNDIFFERENCE_2D(PREDICTOR2);
121
2.26k
  (void)(Rc);
122
2.26k
}
jdlossls-16.c:jpeg_undifference2
Line
Count
Source
119
2.63k
{
120
2.63k
  UNDIFFERENCE_2D(PREDICTOR2);
121
2.63k
  (void)(Rc);
122
2.63k
}
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
50.4k
{
129
50.4k
  UNDIFFERENCE_2D(PREDICTOR3);
130
50.4k
}
jdlossls-8.c:jpeg_undifference3
Line
Count
Source
128
34.3k
{
129
34.3k
  UNDIFFERENCE_2D(PREDICTOR3);
130
34.3k
}
jdlossls-12.c:jpeg_undifference3
Line
Count
Source
128
2.47k
{
129
2.47k
  UNDIFFERENCE_2D(PREDICTOR3);
130
2.47k
}
jdlossls-16.c:jpeg_undifference3
Line
Count
Source
128
13.5k
{
129
13.5k
  UNDIFFERENCE_2D(PREDICTOR3);
130
13.5k
}
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
6.75k
{
137
6.75k
  UNDIFFERENCE_2D(PREDICTOR4);
138
6.75k
}
jdlossls-8.c:jpeg_undifference4
Line
Count
Source
136
3.30k
{
137
3.30k
  UNDIFFERENCE_2D(PREDICTOR4);
138
3.30k
}
jdlossls-12.c:jpeg_undifference4
Line
Count
Source
136
1.27k
{
137
1.27k
  UNDIFFERENCE_2D(PREDICTOR4);
138
1.27k
}
jdlossls-16.c:jpeg_undifference4
Line
Count
Source
136
2.17k
{
137
2.17k
  UNDIFFERENCE_2D(PREDICTOR4);
138
2.17k
}
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
12.0k
{
145
12.0k
  UNDIFFERENCE_2D(PREDICTOR5);
146
12.0k
}
jdlossls-8.c:jpeg_undifference5
Line
Count
Source
144
1.60k
{
145
1.60k
  UNDIFFERENCE_2D(PREDICTOR5);
146
1.60k
}
jdlossls-12.c:jpeg_undifference5
Line
Count
Source
144
3.05k
{
145
3.05k
  UNDIFFERENCE_2D(PREDICTOR5);
146
3.05k
}
jdlossls-16.c:jpeg_undifference5
Line
Count
Source
144
7.38k
{
145
7.38k
  UNDIFFERENCE_2D(PREDICTOR5);
146
7.38k
}
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
3.92k
{
153
3.92k
  UNDIFFERENCE_2D(PREDICTOR6);
154
3.92k
}
jdlossls-8.c:jpeg_undifference6
Line
Count
Source
152
1.80k
{
153
1.80k
  UNDIFFERENCE_2D(PREDICTOR6);
154
1.80k
}
jdlossls-12.c:jpeg_undifference6
Line
Count
Source
152
1.30k
{
153
1.30k
  UNDIFFERENCE_2D(PREDICTOR6);
154
1.30k
}
jdlossls-16.c:jpeg_undifference6
Line
Count
Source
152
813
{
153
813
  UNDIFFERENCE_2D(PREDICTOR6);
154
813
}
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
17.6k
{
161
17.6k
  UNDIFFERENCE_2D(PREDICTOR7);
162
17.6k
  (void)(Rc);
163
17.6k
}
jdlossls-8.c:jpeg_undifference7
Line
Count
Source
160
12.1k
{
161
12.1k
  UNDIFFERENCE_2D(PREDICTOR7);
162
12.1k
  (void)(Rc);
163
12.1k
}
jdlossls-12.c:jpeg_undifference7
Line
Count
Source
160
3.29k
{
161
3.29k
  UNDIFFERENCE_2D(PREDICTOR7);
162
3.29k
  (void)(Rc);
163
3.29k
}
jdlossls-16.c:jpeg_undifference7
Line
Count
Source
160
2.17k
{
161
2.17k
  UNDIFFERENCE_2D(PREDICTOR7);
162
2.17k
  (void)(Rc);
163
2.17k
}
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
4.64k
{
178
4.64k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
4.64k
  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
4.64k
  switch (cinfo->Ss) {
188
2.05k
  case 1:
189
2.05k
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
2.05k
    break;
191
338
  case 2:
192
338
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
338
    break;
194
454
  case 3:
195
454
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
454
    break;
197
671
  case 4:
198
671
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
671
    break;
200
209
  case 5:
201
209
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
209
    break;
203
483
  case 6:
204
483
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
483
    break;
206
431
  case 7:
207
431
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
431
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
4.64k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
4.64k
  }
213
4.64k
}
jdlossls-8.c:jpeg_undifference_first_row
Line
Count
Source
177
1.81k
{
178
1.81k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
1.81k
  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.81k
  switch (cinfo->Ss) {
188
598
  case 1:
189
598
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
598
    break;
191
108
  case 2:
192
108
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
108
    break;
194
247
  case 3:
195
247
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
247
    break;
197
137
  case 4:
198
137
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
137
    break;
200
87
  case 5:
201
87
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
87
    break;
203
319
  case 6:
204
319
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
319
    break;
206
317
  case 7:
207
317
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
317
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
1.81k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
1.81k
  }
213
1.81k
}
jdlossls-12.c:jpeg_undifference_first_row
Line
Count
Source
177
1.33k
{
178
1.33k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
1.33k
  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.33k
  switch (cinfo->Ss) {
188
644
  case 1:
189
644
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
644
    break;
191
82
  case 2:
192
82
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
82
    break;
194
94
  case 3:
195
94
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
94
    break;
197
291
  case 4:
198
291
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
291
    break;
200
58
  case 5:
201
58
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
58
    break;
203
97
  case 6:
204
97
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
97
    break;
206
64
  case 7:
207
64
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
64
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
1.33k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
1.33k
  }
213
1.33k
}
jdlossls-16.c:jpeg_undifference_first_row
Line
Count
Source
177
1.50k
{
178
1.50k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
1.50k
  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.50k
  switch (cinfo->Ss) {
188
816
  case 1:
189
816
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
816
    break;
191
148
  case 2:
192
148
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
148
    break;
194
113
  case 3:
195
113
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
113
    break;
197
243
  case 4:
198
243
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
243
    break;
200
64
  case 5:
201
64
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
64
    break;
203
67
  case 6:
204
67
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
67
    break;
206
50
  case 7:
207
50
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
50
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
1.50k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
1.50k
  }
213
1.50k
}
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
46.5k
{
222
482k
  do {
223
482k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
482k
  } while (--width);
225
46.5k
}
jdlossls-8.c:simple_upscale
Line
Count
Source
221
22.3k
{
222
285k
  do {
223
285k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
285k
  } while (--width);
225
22.3k
}
jdlossls-12.c:simple_upscale
Line
Count
Source
221
11.0k
{
222
98.8k
  do {
223
98.8k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
98.8k
  } while (--width);
225
11.0k
}
jdlossls-16.c:simple_upscale
Line
Count
Source
221
13.1k
{
222
97.9k
  do {
223
97.9k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
97.9k
  } while (--width);
225
13.1k
}
226
227
METHODDEF(void)
228
noscale(j_decompress_ptr cinfo,
229
        JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
230
68.8k
{
231
262k
  do {
232
262k
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
262k
  } while (--width);
234
68.8k
}
jdlossls-8.c:noscale
Line
Count
Source
230
38.5k
{
231
160k
  do {
232
160k
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
160k
  } while (--width);
234
38.5k
}
jdlossls-12.c:noscale
Line
Count
Source
230
7.88k
{
231
49.9k
  do {
232
49.9k
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
49.9k
  } while (--width);
234
7.88k
}
jdlossls-16.c:noscale
Line
Count
Source
230
22.3k
{
231
51.7k
  do {
232
51.7k
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
51.7k
  } while (--width);
234
22.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
4.50k
{
244
4.50k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
4.50k
  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
4.50k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
4.44k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
4.38k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
144
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
4.50k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
16.1k
  for (ci = 0; ci < cinfo->num_components; ci++)
265
11.6k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
4.50k
  if (cinfo->Al)
269
3.08k
    losslessd->scaler_scale = simple_upscale;
270
1.41k
  else
271
1.41k
    losslessd->scaler_scale = noscale;
272
4.50k
}
jdlossls-8.c:start_pass_lossless
Line
Count
Source
243
1.92k
{
244
1.92k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
1.92k
  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
1.92k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
1.90k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
1.88k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
52
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
1.92k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
6.18k
  for (ci = 0; ci < cinfo->num_components; ci++)
265
4.26k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
1.92k
  if (cinfo->Al)
269
1.20k
    losslessd->scaler_scale = simple_upscale;
270
717
  else
271
717
    losslessd->scaler_scale = noscale;
272
1.92k
}
jdlossls-12.c:start_pass_lossless
Line
Count
Source
243
1.19k
{
244
1.19k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
1.19k
  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
1.19k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
1.16k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
1.14k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
59
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
1.19k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
4.57k
  for (ci = 0; ci < cinfo->num_components; ci++)
265
3.37k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
1.19k
  if (cinfo->Al)
269
807
    losslessd->scaler_scale = simple_upscale;
270
386
  else
271
386
    losslessd->scaler_scale = noscale;
272
1.19k
}
jdlossls-16.c:start_pass_lossless
Line
Count
Source
243
1.38k
{
244
1.38k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
1.38k
  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
1.38k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
1.37k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
1.35k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
33
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
1.38k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
5.42k
  for (ci = 0; ci < cinfo->num_components; ci++)
265
4.04k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
1.38k
  if (cinfo->Al)
269
1.07k
    losslessd->scaler_scale = simple_upscale;
270
315
  else
271
315
    losslessd->scaler_scale = noscale;
272
1.38k
}
273
274
275
/*
276
 * Initialize the lossless decompressor.
277
 */
278
279
GLOBAL(void)
280
_jinit_lossless_decompressor(j_decompress_ptr cinfo)
281
1.90k
{
282
1.90k
  lossless_decomp_ptr losslessd;
283
284
#if BITS_IN_JSAMPLE == 8
285
817
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
286
#else
287
1.09k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
1.09k
      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.90k
  losslessd = (lossless_decomp_ptr)
294
1.90k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
1.90k
                                sizeof(jpeg_lossless_decompressor));
296
1.90k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
1.90k
  losslessd->pub.start_pass = start_pass_lossless;
298
1.90k
}
jinit_lossless_decompressor
Line
Count
Source
281
817
{
282
817
  lossless_decomp_ptr losslessd;
283
284
817
#if BITS_IN_JSAMPLE == 8
285
817
  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
817
  losslessd = (lossless_decomp_ptr)
294
817
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
817
                                sizeof(jpeg_lossless_decompressor));
296
817
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
817
  losslessd->pub.start_pass = start_pass_lossless;
298
817
}
j12init_lossless_decompressor
Line
Count
Source
281
579
{
282
579
  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
579
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
579
      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
579
  losslessd = (lossless_decomp_ptr)
294
579
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
579
                                sizeof(jpeg_lossless_decompressor));
296
579
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
579
  losslessd->pub.start_pass = start_pass_lossless;
298
579
}
j16init_lossless_decompressor
Line
Count
Source
281
513
{
282
513
  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
513
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
513
      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
513
  losslessd = (lossless_decomp_ptr)
294
513
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
513
                                sizeof(jpeg_lossless_decompressor));
296
513
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
513
  losslessd->pub.start_pass = start_pass_lossless;
298
513
}
299
300
#endif /* D_LOSSLESS_SUPPORTED */