Coverage Report

Created: 2026-04-12 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
8.94k
  int Ra; \
60
8.94k
  \
61
8.94k
  Ra = (*diff_buf++ + INITIAL_PREDICTOR) & 0xFFFF; \
62
8.94k
  *undiff_buf++ = Ra; \
63
8.94k
  \
64
64.6k
  while (--width) { \
65
55.7k
    Ra = (*diff_buf++ + PREDICTOR1) & 0xFFFF; \
66
55.7k
    *undiff_buf++ = Ra; \
67
55.7k
  }
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
93.0k
  int Ra, Rb, Rc; \
87
93.0k
  \
88
93.0k
  Rb = *prev_row++; \
89
93.0k
  Ra = (*diff_buf++ + PREDICTOR2) & 0xFFFF; \
90
93.0k
  *undiff_buf++ = Ra; \
91
93.0k
  \
92
848k
  while (--width) { \
93
755k
    Rc = Rb; \
94
755k
    Rb = *prev_row++; \
95
755k
    Ra = (*diff_buf++ + PREDICTOR) & 0xFFFF; \
96
755k
    *undiff_buf++ = Ra; \
97
755k
  }
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
5.29k
{
112
5.29k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
5.29k
}
jdlossls-8.c:jpeg_undifference1
Line
Count
Source
111
2.04k
{
112
2.04k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
2.04k
}
jdlossls-12.c:jpeg_undifference1
Line
Count
Source
111
1.75k
{
112
1.75k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
1.75k
}
jdlossls-16.c:jpeg_undifference1
Line
Count
Source
111
1.50k
{
112
1.50k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
1.50k
}
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
48.9k
{
120
48.9k
  UNDIFFERENCE_2D(PREDICTOR2);
121
48.9k
  (void)(Rc);
122
48.9k
}
jdlossls-8.c:jpeg_undifference2
Line
Count
Source
119
2.75k
{
120
2.75k
  UNDIFFERENCE_2D(PREDICTOR2);
121
2.75k
  (void)(Rc);
122
2.75k
}
jdlossls-12.c:jpeg_undifference2
Line
Count
Source
119
1.69k
{
120
1.69k
  UNDIFFERENCE_2D(PREDICTOR2);
121
1.69k
  (void)(Rc);
122
1.69k
}
jdlossls-16.c:jpeg_undifference2
Line
Count
Source
119
44.5k
{
120
44.5k
  UNDIFFERENCE_2D(PREDICTOR2);
121
44.5k
  (void)(Rc);
122
44.5k
}
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
7.91k
{
129
7.91k
  UNDIFFERENCE_2D(PREDICTOR3);
130
7.91k
}
jdlossls-8.c:jpeg_undifference3
Line
Count
Source
128
4.50k
{
129
4.50k
  UNDIFFERENCE_2D(PREDICTOR3);
130
4.50k
}
jdlossls-12.c:jpeg_undifference3
Line
Count
Source
128
1.81k
{
129
1.81k
  UNDIFFERENCE_2D(PREDICTOR3);
130
1.81k
}
jdlossls-16.c:jpeg_undifference3
Line
Count
Source
128
1.59k
{
129
1.59k
  UNDIFFERENCE_2D(PREDICTOR3);
130
1.59k
}
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.71k
{
137
5.71k
  UNDIFFERENCE_2D(PREDICTOR4);
138
5.71k
}
jdlossls-8.c:jpeg_undifference4
Line
Count
Source
136
3.60k
{
137
3.60k
  UNDIFFERENCE_2D(PREDICTOR4);
138
3.60k
}
jdlossls-12.c:jpeg_undifference4
Line
Count
Source
136
1.34k
{
137
1.34k
  UNDIFFERENCE_2D(PREDICTOR4);
138
1.34k
}
jdlossls-16.c:jpeg_undifference4
Line
Count
Source
136
772
{
137
772
  UNDIFFERENCE_2D(PREDICTOR4);
138
772
}
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
23.5k
{
145
23.5k
  UNDIFFERENCE_2D(PREDICTOR5);
146
23.5k
}
jdlossls-8.c:jpeg_undifference5
Line
Count
Source
144
20.0k
{
145
20.0k
  UNDIFFERENCE_2D(PREDICTOR5);
146
20.0k
}
jdlossls-12.c:jpeg_undifference5
Line
Count
Source
144
1.97k
{
145
1.97k
  UNDIFFERENCE_2D(PREDICTOR5);
146
1.97k
}
jdlossls-16.c:jpeg_undifference5
Line
Count
Source
144
1.51k
{
145
1.51k
  UNDIFFERENCE_2D(PREDICTOR5);
146
1.51k
}
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
2.80k
{
153
2.80k
  UNDIFFERENCE_2D(PREDICTOR6);
154
2.80k
}
jdlossls-8.c:jpeg_undifference6
Line
Count
Source
152
1.20k
{
153
1.20k
  UNDIFFERENCE_2D(PREDICTOR6);
154
1.20k
}
jdlossls-12.c:jpeg_undifference6
Line
Count
Source
152
899
{
153
899
  UNDIFFERENCE_2D(PREDICTOR6);
154
899
}
jdlossls-16.c:jpeg_undifference6
Line
Count
Source
152
701
{
153
701
  UNDIFFERENCE_2D(PREDICTOR6);
154
701
}
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.15k
{
161
4.15k
  UNDIFFERENCE_2D(PREDICTOR7);
162
4.15k
  (void)(Rc);
163
4.15k
}
jdlossls-8.c:jpeg_undifference7
Line
Count
Source
160
2.17k
{
161
2.17k
  UNDIFFERENCE_2D(PREDICTOR7);
162
2.17k
  (void)(Rc);
163
2.17k
}
jdlossls-12.c:jpeg_undifference7
Line
Count
Source
160
955
{
161
955
  UNDIFFERENCE_2D(PREDICTOR7);
162
955
  (void)(Rc);
163
955
}
jdlossls-16.c:jpeg_undifference7
Line
Count
Source
160
1.03k
{
161
1.03k
  UNDIFFERENCE_2D(PREDICTOR7);
162
1.03k
  (void)(Rc);
163
1.03k
}
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
3.65k
{
178
3.65k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
3.65k
  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
3.65k
  switch (cinfo->Ss) {
188
731
  case 1:
189
731
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
731
    break;
191
577
  case 2:
192
577
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
577
    break;
194
622
  case 3:
195
622
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
622
    break;
197
318
  case 4:
198
318
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
318
    break;
200
352
  case 5:
201
352
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
352
    break;
203
542
  case 6:
204
542
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
542
    break;
206
510
  case 7:
207
510
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
510
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
3.65k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
3.65k
  }
213
3.65k
}
jdlossls-8.c:jpeg_undifference_first_row
Line
Count
Source
177
1.68k
{
178
1.68k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
1.68k
  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.68k
  switch (cinfo->Ss) {
188
322
  case 1:
189
322
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
322
    break;
191
226
  case 2:
192
226
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
226
    break;
194
375
  case 3:
195
375
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
375
    break;
197
131
  case 4:
198
131
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
131
    break;
200
113
  case 5:
201
113
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
113
    break;
203
211
  case 6:
204
211
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
211
    break;
206
306
  case 7:
207
306
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
306
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
1.68k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
1.68k
  }
213
1.68k
}
jdlossls-12.c:jpeg_undifference_first_row
Line
Count
Source
177
1.03k
{
178
1.03k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
1.03k
  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.03k
  switch (cinfo->Ss) {
188
176
  case 1:
189
176
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
176
    break;
191
162
  case 2:
192
162
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
162
    break;
194
142
  case 3:
195
142
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
142
    break;
197
98
  case 4:
198
98
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
98
    break;
200
158
  case 5:
201
158
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
158
    break;
203
213
  case 6:
204
213
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
213
    break;
206
88
  case 7:
207
88
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
88
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
1.03k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
1.03k
  }
213
1.03k
}
jdlossls-16.c:jpeg_undifference_first_row
Line
Count
Source
177
931
{
178
931
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
931
  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
931
  switch (cinfo->Ss) {
188
233
  case 1:
189
233
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
233
    break;
191
189
  case 2:
192
189
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
189
    break;
194
105
  case 3:
195
105
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
105
    break;
197
89
  case 4:
198
89
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
89
    break;
200
81
  case 5:
201
81
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
81
    break;
203
118
  case 6:
204
118
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
118
    break;
206
116
  case 7:
207
116
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
116
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
931
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
931
  }
213
931
}
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
81.2k
{
222
685k
  do {
223
685k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
685k
  } while (--width);
225
81.2k
}
jdlossls-8.c:simple_upscale
Line
Count
Source
221
25.0k
{
222
371k
  do {
223
371k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
371k
  } while (--width);
225
25.0k
}
jdlossls-12.c:simple_upscale
Line
Count
Source
221
6.70k
{
222
189k
  do {
223
189k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
189k
  } while (--width);
225
6.70k
}
jdlossls-16.c:simple_upscale
Line
Count
Source
221
49.4k
{
222
123k
  do {
223
123k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
123k
  } while (--width);
225
49.4k
}
226
227
METHODDEF(void)
228
noscale(j_decompress_ptr cinfo,
229
        JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
230
20.8k
{
231
228k
  do {
232
228k
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
228k
  } while (--width);
234
20.8k
}
jdlossls-8.c:noscale
Line
Count
Source
230
12.9k
{
231
163k
  do {
232
163k
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
163k
  } while (--width);
234
12.9k
}
jdlossls-12.c:noscale
Line
Count
Source
230
4.76k
{
231
47.2k
  do {
232
47.2k
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
47.2k
  } while (--width);
234
4.76k
}
jdlossls-16.c:noscale
Line
Count
Source
230
3.12k
{
231
18.1k
  do {
232
18.1k
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
18.1k
  } while (--width);
234
3.12k
}
235
236
237
/*
238
 * Initialize for an input processing pass.
239
 */
240
241
METHODDEF(void)
242
start_pass_lossless(j_decompress_ptr cinfo)
243
3.77k
{
244
3.77k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
3.77k
  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
3.77k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
3.72k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
3.66k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
118
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
3.77k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
14.7k
  for (ci = 0; ci < cinfo->num_components; ci++)
265
11.0k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
3.77k
  if (cinfo->Al)
269
1.74k
    losslessd->scaler_scale = simple_upscale;
270
2.03k
  else
271
2.03k
    losslessd->scaler_scale = noscale;
272
3.77k
}
jdlossls-8.c:start_pass_lossless
Line
Count
Source
243
1.65k
{
244
1.65k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
1.65k
  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.65k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
1.64k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
1.62k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
29
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
1.65k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
6.55k
  for (ci = 0; ci < cinfo->num_components; ci++)
265
4.89k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
1.65k
  if (cinfo->Al)
269
600
    losslessd->scaler_scale = simple_upscale;
270
1.05k
  else
271
1.05k
    losslessd->scaler_scale = noscale;
272
1.65k
}
jdlossls-12.c:start_pass_lossless
Line
Count
Source
243
1.11k
{
244
1.11k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
1.11k
  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.11k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
1.09k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
1.06k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
48
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
1.11k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
4.32k
  for (ci = 0; ci < cinfo->num_components; ci++)
265
3.20k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
1.11k
  if (cinfo->Al)
269
572
    losslessd->scaler_scale = simple_upscale;
270
544
  else
271
544
    losslessd->scaler_scale = noscale;
272
1.11k
}
jdlossls-16.c:start_pass_lossless
Line
Count
Source
243
1.00k
{
244
1.00k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
1.00k
  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.00k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
988
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
970
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
41
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
1.00k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
3.91k
  for (ci = 0; ci < cinfo->num_components; ci++)
265
2.90k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
1.00k
  if (cinfo->Al)
269
575
    losslessd->scaler_scale = simple_upscale;
270
430
  else
271
430
    losslessd->scaler_scale = noscale;
272
1.00k
}
273
274
275
/*
276
 * Initialize the lossless decompressor.
277
 */
278
279
GLOBAL(void)
280
_jinit_lossless_decompressor(j_decompress_ptr cinfo)
281
1.23k
{
282
1.23k
  lossless_decomp_ptr losslessd;
283
284
#if BITS_IN_JSAMPLE == 8
285
470
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
286
#else
287
768
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
768
      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.23k
  losslessd = (lossless_decomp_ptr)
294
1.23k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
1.23k
                                sizeof(jpeg_lossless_decompressor));
296
1.23k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
1.23k
  losslessd->pub.start_pass = start_pass_lossless;
298
1.23k
}
jinit_lossless_decompressor
Line
Count
Source
281
470
{
282
470
  lossless_decomp_ptr losslessd;
283
284
470
#if BITS_IN_JSAMPLE == 8
285
470
  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
470
  losslessd = (lossless_decomp_ptr)
294
470
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
470
                                sizeof(jpeg_lossless_decompressor));
296
470
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
470
  losslessd->pub.start_pass = start_pass_lossless;
298
470
}
j12init_lossless_decompressor
Line
Count
Source
281
379
{
282
379
  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
379
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
379
      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
379
  losslessd = (lossless_decomp_ptr)
294
379
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
379
                                sizeof(jpeg_lossless_decompressor));
296
379
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
379
  losslessd->pub.start_pass = start_pass_lossless;
298
379
}
j16init_lossless_decompressor
Line
Count
Source
281
389
{
282
389
  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
389
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
389
      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
389
  losslessd = (lossless_decomp_ptr)
294
389
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
389
                                sizeof(jpeg_lossless_decompressor));
296
389
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
389
  losslessd->pub.start_pass = start_pass_lossless;
298
389
}
299
300
#endif /* D_LOSSLESS_SUPPORTED */