Coverage Report

Created: 2026-07-16 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/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
13.8M
  int Ra; \
60
13.8M
  \
61
13.8M
  Ra = (*diff_buf++ + INITIAL_PREDICTOR) & 0xFFFF; \
62
13.8M
  *undiff_buf++ = Ra; \
63
13.8M
  \
64
113M
  while (--width) { \
65
99.9M
    Ra = (*diff_buf++ + PREDICTOR1) & 0xFFFF; \
66
99.9M
    *undiff_buf++ = Ra; \
67
99.9M
  }
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
8.15M
  int Ra, Rb, Rc; \
87
8.15M
  \
88
8.15M
  Rb = *prev_row++; \
89
8.15M
  Ra = (*diff_buf++ + PREDICTOR2) & 0xFFFF; \
90
8.15M
  *undiff_buf++ = Ra; \
91
8.15M
  \
92
81.9M
  while (--width) { \
93
73.7M
    Rc = Rb; \
94
73.7M
    Rb = *prev_row++; \
95
73.7M
    Ra = (*diff_buf++ + PREDICTOR) & 0xFFFF; \
96
73.7M
    *undiff_buf++ = Ra; \
97
73.7M
  }
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
4.88M
{
112
4.88M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
4.88M
}
jdlossls-8.c:jpeg_undifference1
Line
Count
Source
111
4.72M
{
112
4.72M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
4.72M
}
jdlossls-12.c:jpeg_undifference1
Line
Count
Source
111
134k
{
112
134k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
134k
}
jdlossls-16.c:jpeg_undifference1
Line
Count
Source
111
31.0k
{
112
31.0k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
31.0k
}
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
604k
{
120
604k
  UNDIFFERENCE_2D(PREDICTOR2);
121
604k
  (void)(Rc);
122
604k
}
jdlossls-8.c:jpeg_undifference2
Line
Count
Source
119
323k
{
120
323k
  UNDIFFERENCE_2D(PREDICTOR2);
121
323k
  (void)(Rc);
122
323k
}
jdlossls-12.c:jpeg_undifference2
Line
Count
Source
119
260k
{
120
260k
  UNDIFFERENCE_2D(PREDICTOR2);
121
260k
  (void)(Rc);
122
260k
}
jdlossls-16.c:jpeg_undifference2
Line
Count
Source
119
21.6k
{
120
21.6k
  UNDIFFERENCE_2D(PREDICTOR2);
121
21.6k
  (void)(Rc);
122
21.6k
}
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
5.13M
{
129
5.13M
  UNDIFFERENCE_2D(PREDICTOR3);
130
5.13M
}
jdlossls-8.c:jpeg_undifference3
Line
Count
Source
128
4.91M
{
129
4.91M
  UNDIFFERENCE_2D(PREDICTOR3);
130
4.91M
}
jdlossls-12.c:jpeg_undifference3
Line
Count
Source
128
150k
{
129
150k
  UNDIFFERENCE_2D(PREDICTOR3);
130
150k
}
jdlossls-16.c:jpeg_undifference3
Line
Count
Source
128
76.2k
{
129
76.2k
  UNDIFFERENCE_2D(PREDICTOR3);
130
76.2k
}
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
399k
{
137
399k
  UNDIFFERENCE_2D(PREDICTOR4);
138
399k
}
jdlossls-8.c:jpeg_undifference4
Line
Count
Source
136
59.0k
{
137
59.0k
  UNDIFFERENCE_2D(PREDICTOR4);
138
59.0k
}
jdlossls-12.c:jpeg_undifference4
Line
Count
Source
136
168k
{
137
168k
  UNDIFFERENCE_2D(PREDICTOR4);
138
168k
}
jdlossls-16.c:jpeg_undifference4
Line
Count
Source
136
172k
{
137
172k
  UNDIFFERENCE_2D(PREDICTOR4);
138
172k
}
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
341k
{
145
341k
  UNDIFFERENCE_2D(PREDICTOR5);
146
341k
}
jdlossls-8.c:jpeg_undifference5
Line
Count
Source
144
200k
{
145
200k
  UNDIFFERENCE_2D(PREDICTOR5);
146
200k
}
jdlossls-12.c:jpeg_undifference5
Line
Count
Source
144
48.8k
{
145
48.8k
  UNDIFFERENCE_2D(PREDICTOR5);
146
48.8k
}
jdlossls-16.c:jpeg_undifference5
Line
Count
Source
144
92.2k
{
145
92.2k
  UNDIFFERENCE_2D(PREDICTOR5);
146
92.2k
}
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
939k
{
153
939k
  UNDIFFERENCE_2D(PREDICTOR6);
154
939k
}
jdlossls-8.c:jpeg_undifference6
Line
Count
Source
152
139k
{
153
139k
  UNDIFFERENCE_2D(PREDICTOR6);
154
139k
}
jdlossls-12.c:jpeg_undifference6
Line
Count
Source
152
326k
{
153
326k
  UNDIFFERENCE_2D(PREDICTOR6);
154
326k
}
jdlossls-16.c:jpeg_undifference6
Line
Count
Source
152
473k
{
153
473k
  UNDIFFERENCE_2D(PREDICTOR6);
154
473k
}
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
732k
{
161
732k
  UNDIFFERENCE_2D(PREDICTOR7);
162
732k
  (void)(Rc);
163
732k
}
jdlossls-8.c:jpeg_undifference7
Line
Count
Source
160
327k
{
161
327k
  UNDIFFERENCE_2D(PREDICTOR7);
162
327k
  (void)(Rc);
163
327k
}
jdlossls-12.c:jpeg_undifference7
Line
Count
Source
160
287k
{
161
287k
  UNDIFFERENCE_2D(PREDICTOR7);
162
287k
  (void)(Rc);
163
287k
}
jdlossls-16.c:jpeg_undifference7
Line
Count
Source
160
117k
{
161
117k
  UNDIFFERENCE_2D(PREDICTOR7);
162
117k
  (void)(Rc);
163
117k
}
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
8.91M
{
178
8.91M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
8.91M
  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
8.91M
  switch (cinfo->Ss) {
188
4.01M
  case 1:
189
4.01M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
4.01M
    break;
191
539k
  case 2:
192
539k
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
539k
    break;
194
2.26M
  case 3:
195
2.26M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
2.26M
    break;
197
516k
  case 4:
198
516k
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
516k
    break;
200
219k
  case 5:
201
219k
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
219k
    break;
203
662k
  case 6:
204
662k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
662k
    break;
206
698k
  case 7:
207
698k
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
698k
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
8.91M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
8.91M
  }
213
8.91M
}
jdlossls-8.c:jpeg_undifference_first_row
Line
Count
Source
177
6.63M
{
178
6.63M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
6.63M
  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
6.63M
  switch (cinfo->Ss) {
188
3.61M
  case 1:
189
3.61M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
3.61M
    break;
191
316k
  case 2:
192
316k
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
316k
    break;
194
2.10M
  case 3:
195
2.10M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
2.10M
    break;
197
79.5k
  case 4:
198
79.5k
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
79.5k
    break;
200
113k
  case 5:
201
113k
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
113k
    break;
203
125k
  case 6:
204
125k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
125k
    break;
206
279k
  case 7:
207
279k
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
279k
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
6.63M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
6.63M
  }
213
6.63M
}
jdlossls-12.c:jpeg_undifference_first_row
Line
Count
Source
177
1.13M
{
178
1.13M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
1.13M
  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.13M
  switch (cinfo->Ss) {
188
117k
  case 1:
189
117k
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
117k
    break;
191
186k
  case 2:
192
186k
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
186k
    break;
194
60.8k
  case 3:
195
60.8k
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
60.8k
    break;
197
182k
  case 4:
198
182k
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
182k
    break;
200
60.5k
  case 5:
201
60.5k
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
60.5k
    break;
203
278k
  case 6:
204
278k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
278k
    break;
206
243k
  case 7:
207
243k
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
243k
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
1.13M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
1.13M
  }
213
1.13M
}
jdlossls-16.c:jpeg_undifference_first_row
Line
Count
Source
177
1.15M
{
178
1.15M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
1.15M
  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.15M
  switch (cinfo->Ss) {
188
284k
  case 1:
189
284k
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
284k
    break;
191
37.0k
  case 2:
192
37.0k
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
37.0k
    break;
194
101k
  case 3:
195
101k
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
101k
    break;
197
254k
  case 4:
198
254k
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
254k
    break;
200
45.4k
  case 5:
201
45.4k
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
45.4k
    break;
203
258k
  case 6:
204
258k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
258k
    break;
206
175k
  case 7:
207
175k
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
175k
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
1.15M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
1.15M
  }
213
1.15M
}
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
18.2M
{
222
131M
  do {
223
131M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
131M
  } while (--width);
225
18.2M
}
jdlossls-8.c:simple_upscale
Line
Count
Source
221
15.2M
{
222
109M
  do {
223
109M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
109M
  } while (--width);
225
15.2M
}
jdlossls-12.c:simple_upscale
Line
Count
Source
221
1.60M
{
222
9.15M
  do {
223
9.15M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
9.15M
  } while (--width);
225
1.60M
}
jdlossls-16.c:simple_upscale
Line
Count
Source
221
1.33M
{
222
13.1M
  do {
223
13.1M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
13.1M
  } while (--width);
225
1.33M
}
226
227
METHODDEF(void)
228
noscale(j_decompress_ptr cinfo,
229
        JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
230
3.73M
{
231
64.0M
  do {
232
64.0M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
64.0M
  } while (--width);
234
3.73M
}
jdlossls-8.c:noscale
Line
Count
Source
230
2.02M
{
231
33.5M
  do {
232
33.5M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
33.5M
  } while (--width);
234
2.02M
}
jdlossls-12.c:noscale
Line
Count
Source
230
896k
{
231
13.2M
  do {
232
13.2M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
13.2M
  } while (--width);
234
896k
}
jdlossls-16.c:noscale
Line
Count
Source
230
805k
{
231
17.2M
  do {
232
17.2M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
17.2M
  } while (--width);
234
805k
}
235
236
237
/*
238
 * Initialize for an input processing pass.
239
 */
240
241
METHODDEF(void)
242
start_pass_lossless(j_decompress_ptr cinfo)
243
15.1M
{
244
15.1M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
15.1M
  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
15.1M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
15.1M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
15.1M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
98
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
15.1M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
45.5M
  for (ci = 0; ci < cinfo->num_components; ci++)
265
30.3M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
15.1M
  if (cinfo->Al)
269
12.1M
    losslessd->scaler_scale = simple_upscale;
270
3.00M
  else
271
3.00M
    losslessd->scaler_scale = noscale;
272
15.1M
}
jdlossls-8.c:start_pass_lossless
Line
Count
Source
243
10.5M
{
244
10.5M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
10.5M
  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
10.5M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
10.5M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
10.5M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
58
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
10.5M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
31.5M
  for (ci = 0; ci < cinfo->num_components; ci++)
265
21.0M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
10.5M
  if (cinfo->Al)
269
9.18M
    losslessd->scaler_scale = simple_upscale;
270
1.31M
  else
271
1.31M
    losslessd->scaler_scale = noscale;
272
10.5M
}
jdlossls-12.c:start_pass_lossless
Line
Count
Source
243
2.50M
{
244
2.50M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
2.50M
  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.50M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
2.50M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
2.50M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
15
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
2.50M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
7.52M
  for (ci = 0; ci < cinfo->num_components; ci++)
265
5.01M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
2.50M
  if (cinfo->Al)
269
1.61M
    losslessd->scaler_scale = simple_upscale;
270
890k
  else
271
890k
    losslessd->scaler_scale = noscale;
272
2.50M
}
jdlossls-16.c:start_pass_lossless
Line
Count
Source
243
2.15M
{
244
2.15M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
2.15M
  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.15M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
2.15M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
2.15M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
25
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
2.15M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
6.45M
  for (ci = 0; ci < cinfo->num_components; ci++)
265
4.30M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
2.15M
  if (cinfo->Al)
269
1.34M
    losslessd->scaler_scale = simple_upscale;
270
804k
  else
271
804k
    losslessd->scaler_scale = noscale;
272
2.15M
}
273
274
275
/*
276
 * Initialize the lossless decompressor.
277
 */
278
279
GLOBAL(void)
280
_jinit_lossless_decompressor(j_decompress_ptr cinfo)
281
1.31k
{
282
1.31k
  lossless_decomp_ptr losslessd;
283
284
#if BITS_IN_JSAMPLE == 8
285
581
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
286
#else
287
734
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
734
      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.31k
  losslessd = (lossless_decomp_ptr)
294
1.31k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
1.31k
                                sizeof(jpeg_lossless_decompressor));
296
1.31k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
1.31k
  losslessd->pub.start_pass = start_pass_lossless;
298
1.31k
}
jinit_lossless_decompressor
Line
Count
Source
281
581
{
282
581
  lossless_decomp_ptr losslessd;
283
284
581
#if BITS_IN_JSAMPLE == 8
285
581
  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
581
  losslessd = (lossless_decomp_ptr)
294
581
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
581
                                sizeof(jpeg_lossless_decompressor));
296
581
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
581
  losslessd->pub.start_pass = start_pass_lossless;
298
581
}
j12init_lossless_decompressor
Line
Count
Source
281
352
{
282
352
  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
352
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
352
      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
352
  losslessd = (lossless_decomp_ptr)
294
352
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
352
                                sizeof(jpeg_lossless_decompressor));
296
352
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
352
  losslessd->pub.start_pass = start_pass_lossless;
298
352
}
j16init_lossless_decompressor
Line
Count
Source
281
382
{
282
382
  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
382
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
382
      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
382
  losslessd = (lossless_decomp_ptr)
294
382
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
382
                                sizeof(jpeg_lossless_decompressor));
296
382
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
382
  losslessd->pub.start_pass = start_pass_lossless;
298
382
}
299
300
#endif /* D_LOSSLESS_SUPPORTED */