Coverage Report

Created: 2026-06-15 06:21

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
164k
  int Ra; \
60
164k
  \
61
164k
  Ra = (*diff_buf++ + INITIAL_PREDICTOR) & 0xFFFF; \
62
164k
  *undiff_buf++ = Ra; \
63
164k
  \
64
3.07M
  while (--width) { \
65
2.91M
    Ra = (*diff_buf++ + PREDICTOR1) & 0xFFFF; \
66
2.91M
    *undiff_buf++ = Ra; \
67
2.91M
  }
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
1.03M
  int Ra, Rb, Rc; \
87
1.03M
  \
88
1.03M
  Rb = *prev_row++; \
89
1.03M
  Ra = (*diff_buf++ + PREDICTOR2) & 0xFFFF; \
90
1.03M
  *undiff_buf++ = Ra; \
91
1.03M
  \
92
10.2M
  while (--width) { \
93
9.23M
    Rc = Rb; \
94
9.23M
    Rb = *prev_row++; \
95
9.23M
    Ra = (*diff_buf++ + PREDICTOR) & 0xFFFF; \
96
9.23M
    *undiff_buf++ = Ra; \
97
9.23M
  }
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
113k
{
112
113k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
113k
}
jdlossls-8.c:jpeg_undifference1
Line
Count
Source
111
37.1k
{
112
37.1k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
37.1k
}
jdlossls-12.c:jpeg_undifference1
Line
Count
Source
111
22.7k
{
112
22.7k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
22.7k
}
jdlossls-16.c:jpeg_undifference1
Line
Count
Source
111
53.5k
{
112
53.5k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
53.5k
}
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
321k
{
120
321k
  UNDIFFERENCE_2D(PREDICTOR2);
121
321k
  (void)(Rc);
122
321k
}
jdlossls-8.c:jpeg_undifference2
Line
Count
Source
119
239k
{
120
239k
  UNDIFFERENCE_2D(PREDICTOR2);
121
239k
  (void)(Rc);
122
239k
}
jdlossls-12.c:jpeg_undifference2
Line
Count
Source
119
29.5k
{
120
29.5k
  UNDIFFERENCE_2D(PREDICTOR2);
121
29.5k
  (void)(Rc);
122
29.5k
}
jdlossls-16.c:jpeg_undifference2
Line
Count
Source
119
52.2k
{
120
52.2k
  UNDIFFERENCE_2D(PREDICTOR2);
121
52.2k
  (void)(Rc);
122
52.2k
}
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
156k
{
129
156k
  UNDIFFERENCE_2D(PREDICTOR3);
130
156k
}
jdlossls-8.c:jpeg_undifference3
Line
Count
Source
128
73.7k
{
129
73.7k
  UNDIFFERENCE_2D(PREDICTOR3);
130
73.7k
}
jdlossls-12.c:jpeg_undifference3
Line
Count
Source
128
31.9k
{
129
31.9k
  UNDIFFERENCE_2D(PREDICTOR3);
130
31.9k
}
jdlossls-16.c:jpeg_undifference3
Line
Count
Source
128
50.7k
{
129
50.7k
  UNDIFFERENCE_2D(PREDICTOR3);
130
50.7k
}
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
85.2k
{
137
85.2k
  UNDIFFERENCE_2D(PREDICTOR4);
138
85.2k
}
jdlossls-8.c:jpeg_undifference4
Line
Count
Source
136
37.5k
{
137
37.5k
  UNDIFFERENCE_2D(PREDICTOR4);
138
37.5k
}
jdlossls-12.c:jpeg_undifference4
Line
Count
Source
136
26.2k
{
137
26.2k
  UNDIFFERENCE_2D(PREDICTOR4);
138
26.2k
}
jdlossls-16.c:jpeg_undifference4
Line
Count
Source
136
21.4k
{
137
21.4k
  UNDIFFERENCE_2D(PREDICTOR4);
138
21.4k
}
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
129k
{
145
129k
  UNDIFFERENCE_2D(PREDICTOR5);
146
129k
}
jdlossls-8.c:jpeg_undifference5
Line
Count
Source
144
86.0k
{
145
86.0k
  UNDIFFERENCE_2D(PREDICTOR5);
146
86.0k
}
jdlossls-12.c:jpeg_undifference5
Line
Count
Source
144
19.2k
{
145
19.2k
  UNDIFFERENCE_2D(PREDICTOR5);
146
19.2k
}
jdlossls-16.c:jpeg_undifference5
Line
Count
Source
144
24.0k
{
145
24.0k
  UNDIFFERENCE_2D(PREDICTOR5);
146
24.0k
}
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
178k
{
153
178k
  UNDIFFERENCE_2D(PREDICTOR6);
154
178k
}
jdlossls-8.c:jpeg_undifference6
Line
Count
Source
152
90.8k
{
153
90.8k
  UNDIFFERENCE_2D(PREDICTOR6);
154
90.8k
}
jdlossls-12.c:jpeg_undifference6
Line
Count
Source
152
69.3k
{
153
69.3k
  UNDIFFERENCE_2D(PREDICTOR6);
154
69.3k
}
jdlossls-16.c:jpeg_undifference6
Line
Count
Source
152
18.3k
{
153
18.3k
  UNDIFFERENCE_2D(PREDICTOR6);
154
18.3k
}
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
159k
{
161
159k
  UNDIFFERENCE_2D(PREDICTOR7);
162
159k
  (void)(Rc);
163
159k
}
jdlossls-8.c:jpeg_undifference7
Line
Count
Source
160
54.2k
{
161
54.2k
  UNDIFFERENCE_2D(PREDICTOR7);
162
54.2k
  (void)(Rc);
163
54.2k
}
jdlossls-12.c:jpeg_undifference7
Line
Count
Source
160
18.2k
{
161
18.2k
  UNDIFFERENCE_2D(PREDICTOR7);
162
18.2k
  (void)(Rc);
163
18.2k
}
jdlossls-16.c:jpeg_undifference7
Line
Count
Source
160
87.3k
{
161
87.3k
  UNDIFFERENCE_2D(PREDICTOR7);
162
87.3k
  (void)(Rc);
163
87.3k
}
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
50.9k
{
178
50.9k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
50.9k
  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
50.9k
  switch (cinfo->Ss) {
188
10.5k
  case 1:
189
10.5k
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
10.5k
    break;
191
7.17k
  case 2:
192
7.17k
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
7.17k
    break;
194
8.89k
  case 3:
195
8.89k
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
8.89k
    break;
197
5.41k
  case 4:
198
5.41k
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
5.41k
    break;
200
6.56k
  case 5:
201
6.56k
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
6.56k
    break;
203
6.77k
  case 6:
204
6.77k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
6.77k
    break;
206
5.61k
  case 7:
207
5.61k
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
5.61k
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
50.9k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
50.9k
  }
213
50.9k
}
jdlossls-8.c:jpeg_undifference_first_row
Line
Count
Source
177
20.3k
{
178
20.3k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
20.3k
  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
20.3k
  switch (cinfo->Ss) {
188
3.68k
  case 1:
189
3.68k
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
3.68k
    break;
191
2.90k
  case 2:
192
2.90k
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
2.90k
    break;
194
3.17k
  case 3:
195
3.17k
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
3.17k
    break;
197
2.22k
  case 4:
198
2.22k
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
2.22k
    break;
200
3.20k
  case 5:
201
3.20k
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
3.20k
    break;
203
2.78k
  case 6:
204
2.78k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
2.78k
    break;
206
2.40k
  case 7:
207
2.40k
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
2.40k
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
20.3k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
20.3k
  }
213
20.3k
}
jdlossls-12.c:jpeg_undifference_first_row
Line
Count
Source
177
16.1k
{
178
16.1k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
16.1k
  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
16.1k
  switch (cinfo->Ss) {
188
3.51k
  case 1:
189
3.51k
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
3.51k
    break;
191
2.30k
  case 2:
192
2.30k
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
2.30k
    break;
194
3.62k
  case 3:
195
3.62k
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
3.62k
    break;
197
1.60k
  case 4:
198
1.60k
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
1.60k
    break;
200
1.89k
  case 5:
201
1.89k
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
1.89k
    break;
203
1.56k
  case 6:
204
1.56k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
1.56k
    break;
206
1.64k
  case 7:
207
1.64k
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
1.64k
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
16.1k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
16.1k
  }
213
16.1k
}
jdlossls-16.c:jpeg_undifference_first_row
Line
Count
Source
177
14.4k
{
178
14.4k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
14.4k
  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
14.4k
  switch (cinfo->Ss) {
188
3.30k
  case 1:
189
3.30k
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
3.30k
    break;
191
1.96k
  case 2:
192
1.96k
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
1.96k
    break;
194
2.09k
  case 3:
195
2.09k
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
2.09k
    break;
197
1.59k
  case 4:
198
1.59k
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
1.59k
    break;
200
1.46k
  case 5:
201
1.46k
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
1.46k
    break;
203
2.42k
  case 6:
204
2.42k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
2.42k
    break;
206
1.56k
  case 7:
207
1.56k
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
1.56k
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
14.4k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
14.4k
  }
213
14.4k
}
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
367k
{
222
4.23M
  do {
223
4.23M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
4.23M
  } while (--width);
225
367k
}
jdlossls-8.c:simple_upscale
Line
Count
Source
221
214k
{
222
2.02M
  do {
223
2.02M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
2.02M
  } while (--width);
225
214k
}
jdlossls-12.c:simple_upscale
Line
Count
Source
221
63.6k
{
222
879k
  do {
223
879k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
879k
  } while (--width);
225
63.6k
}
jdlossls-16.c:simple_upscale
Line
Count
Source
221
89.1k
{
222
1.32M
  do {
223
1.32M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
1.32M
  } while (--width);
225
89.1k
}
226
227
METHODDEF(void)
228
noscale(j_decompress_ptr cinfo,
229
        JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
230
827k
{
231
9.11M
  do {
232
9.11M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
9.11M
  } while (--width);
234
827k
}
jdlossls-8.c:noscale
Line
Count
Source
230
424k
{
231
6.07M
  do {
232
6.07M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
6.07M
  } while (--width);
234
424k
}
jdlossls-12.c:noscale
Line
Count
Source
230
169k
{
231
1.31M
  do {
232
1.31M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
1.31M
  } while (--width);
234
169k
}
jdlossls-16.c:noscale
Line
Count
Source
230
233k
{
231
1.72M
  do {
232
1.72M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
1.72M
  } while (--width);
234
233k
}
235
236
237
/*
238
 * Initialize for an input processing pass.
239
 */
240
241
METHODDEF(void)
242
start_pass_lossless(j_decompress_ptr cinfo)
243
45.3k
{
244
45.3k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
45.3k
  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
45.3k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
44.7k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
44.2k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
1.15k
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
45.3k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
174k
  for (ci = 0; ci < cinfo->num_components; ci++)
265
129k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
45.3k
  if (cinfo->Al)
269
18.1k
    losslessd->scaler_scale = simple_upscale;
270
27.2k
  else
271
27.2k
    losslessd->scaler_scale = noscale;
272
45.3k
}
jdlossls-8.c:start_pass_lossless
Line
Count
Source
243
18.0k
{
244
18.0k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
18.0k
  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
18.0k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
17.8k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
17.6k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
407
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
18.0k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
67.0k
  for (ci = 0; ci < cinfo->num_components; ci++)
265
48.9k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
18.0k
  if (cinfo->Al)
269
6.43k
    losslessd->scaler_scale = simple_upscale;
270
11.5k
  else
271
11.5k
    losslessd->scaler_scale = noscale;
272
18.0k
}
jdlossls-12.c:start_pass_lossless
Line
Count
Source
243
14.3k
{
244
14.3k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
14.3k
  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
14.3k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
14.2k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
14.0k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
362
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
14.3k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
56.7k
  for (ci = 0; ci < cinfo->num_components; ci++)
265
42.3k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
14.3k
  if (cinfo->Al)
269
6.10k
    losslessd->scaler_scale = simple_upscale;
270
8.28k
  else
271
8.28k
    losslessd->scaler_scale = noscale;
272
14.3k
}
jdlossls-16.c:start_pass_lossless
Line
Count
Source
243
12.9k
{
244
12.9k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
12.9k
  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
12.9k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
12.7k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
12.5k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
382
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
12.9k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
50.9k
  for (ci = 0; ci < cinfo->num_components; ci++)
265
38.0k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
12.9k
  if (cinfo->Al)
269
5.57k
    losslessd->scaler_scale = simple_upscale;
270
7.33k
  else
271
7.33k
    losslessd->scaler_scale = noscale;
272
12.9k
}
273
274
275
/*
276
 * Initialize the lossless decompressor.
277
 */
278
279
GLOBAL(void)
280
_jinit_lossless_decompressor(j_decompress_ptr cinfo)
281
16.5k
{
282
16.5k
  lossless_decomp_ptr losslessd;
283
284
#if BITS_IN_JSAMPLE == 8
285
6.56k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
286
#else
287
10.0k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
10.0k
      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
16.5k
  losslessd = (lossless_decomp_ptr)
294
16.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
16.5k
                                sizeof(jpeg_lossless_decompressor));
296
16.5k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
16.5k
  losslessd->pub.start_pass = start_pass_lossless;
298
16.5k
}
jinit_lossless_decompressor
Line
Count
Source
281
6.56k
{
282
6.56k
  lossless_decomp_ptr losslessd;
283
284
6.56k
#if BITS_IN_JSAMPLE == 8
285
6.56k
  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
6.56k
  losslessd = (lossless_decomp_ptr)
294
6.56k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
6.56k
                                sizeof(jpeg_lossless_decompressor));
296
6.56k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
6.56k
  losslessd->pub.start_pass = start_pass_lossless;
298
6.56k
}
j12init_lossless_decompressor
Line
Count
Source
281
4.91k
{
282
4.91k
  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
4.91k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
4.91k
      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
4.91k
  losslessd = (lossless_decomp_ptr)
294
4.91k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
4.91k
                                sizeof(jpeg_lossless_decompressor));
296
4.91k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
4.91k
  losslessd->pub.start_pass = start_pass_lossless;
298
4.91k
}
j16init_lossless_decompressor
Line
Count
Source
281
5.10k
{
282
5.10k
  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
5.10k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
5.10k
      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
5.10k
  losslessd = (lossless_decomp_ptr)
294
5.10k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
5.10k
                                sizeof(jpeg_lossless_decompressor));
296
5.10k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
5.10k
  losslessd->pub.start_pass = start_pass_lossless;
298
5.10k
}
299
300
#endif /* D_LOSSLESS_SUPPORTED */