Coverage Report

Created: 2026-09-01 06:36

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
40.2M
  int Ra; \
60
40.2M
  \
61
40.2M
  Ra = (*diff_buf++ + INITIAL_PREDICTOR) & 0xFFFF; \
62
40.2M
  *undiff_buf++ = Ra; \
63
40.2M
  \
64
681M
  while (--width) { \
65
640M
    Ra = (*diff_buf++ + PREDICTOR1) & 0xFFFF; \
66
640M
    *undiff_buf++ = Ra; \
67
640M
  }
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
12.1M
  int Ra, Rb, Rc; \
87
12.1M
  \
88
12.1M
  Rb = *prev_row++; \
89
12.1M
  Ra = (*diff_buf++ + PREDICTOR2) & 0xFFFF; \
90
12.1M
  *undiff_buf++ = Ra; \
91
12.1M
  \
92
344M
  while (--width) { \
93
332M
    Rc = Rb; \
94
332M
    Rb = *prev_row++; \
95
332M
    Ra = (*diff_buf++ + PREDICTOR) & 0xFFFF; \
96
332M
    *undiff_buf++ = Ra; \
97
332M
  }
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
2.68M
{
112
2.68M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
2.68M
}
jdlossls-8.c:jpeg_undifference1
Line
Count
Source
111
1.39M
{
112
1.39M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
1.39M
}
jdlossls-12.c:jpeg_undifference1
Line
Count
Source
111
517k
{
112
517k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
517k
}
jdlossls-16.c:jpeg_undifference1
Line
Count
Source
111
777k
{
112
777k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
777k
}
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
5.92M
{
120
5.92M
  UNDIFFERENCE_2D(PREDICTOR2);
121
5.92M
  (void)(Rc);
122
5.92M
}
jdlossls-8.c:jpeg_undifference2
Line
Count
Source
119
2.82M
{
120
2.82M
  UNDIFFERENCE_2D(PREDICTOR2);
121
2.82M
  (void)(Rc);
122
2.82M
}
jdlossls-12.c:jpeg_undifference2
Line
Count
Source
119
532k
{
120
532k
  UNDIFFERENCE_2D(PREDICTOR2);
121
532k
  (void)(Rc);
122
532k
}
jdlossls-16.c:jpeg_undifference2
Line
Count
Source
119
2.57M
{
120
2.57M
  UNDIFFERENCE_2D(PREDICTOR2);
121
2.57M
  (void)(Rc);
122
2.57M
}
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
1.06M
{
129
1.06M
  UNDIFFERENCE_2D(PREDICTOR3);
130
1.06M
}
jdlossls-8.c:jpeg_undifference3
Line
Count
Source
128
152k
{
129
152k
  UNDIFFERENCE_2D(PREDICTOR3);
130
152k
}
jdlossls-12.c:jpeg_undifference3
Line
Count
Source
128
483k
{
129
483k
  UNDIFFERENCE_2D(PREDICTOR3);
130
483k
}
jdlossls-16.c:jpeg_undifference3
Line
Count
Source
128
430k
{
129
430k
  UNDIFFERENCE_2D(PREDICTOR3);
130
430k
}
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
1.17M
{
137
1.17M
  UNDIFFERENCE_2D(PREDICTOR4);
138
1.17M
}
jdlossls-8.c:jpeg_undifference4
Line
Count
Source
136
330k
{
137
330k
  UNDIFFERENCE_2D(PREDICTOR4);
138
330k
}
jdlossls-12.c:jpeg_undifference4
Line
Count
Source
136
572k
{
137
572k
  UNDIFFERENCE_2D(PREDICTOR4);
138
572k
}
jdlossls-16.c:jpeg_undifference4
Line
Count
Source
136
270k
{
137
270k
  UNDIFFERENCE_2D(PREDICTOR4);
138
270k
}
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
855k
{
145
855k
  UNDIFFERENCE_2D(PREDICTOR5);
146
855k
}
jdlossls-8.c:jpeg_undifference5
Line
Count
Source
144
119k
{
145
119k
  UNDIFFERENCE_2D(PREDICTOR5);
146
119k
}
jdlossls-12.c:jpeg_undifference5
Line
Count
Source
144
398k
{
145
398k
  UNDIFFERENCE_2D(PREDICTOR5);
146
398k
}
jdlossls-16.c:jpeg_undifference5
Line
Count
Source
144
337k
{
145
337k
  UNDIFFERENCE_2D(PREDICTOR5);
146
337k
}
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
1.61M
{
153
1.61M
  UNDIFFERENCE_2D(PREDICTOR6);
154
1.61M
}
jdlossls-8.c:jpeg_undifference6
Line
Count
Source
152
395k
{
153
395k
  UNDIFFERENCE_2D(PREDICTOR6);
154
395k
}
jdlossls-12.c:jpeg_undifference6
Line
Count
Source
152
373k
{
153
373k
  UNDIFFERENCE_2D(PREDICTOR6);
154
373k
}
jdlossls-16.c:jpeg_undifference6
Line
Count
Source
152
844k
{
153
844k
  UNDIFFERENCE_2D(PREDICTOR6);
154
844k
}
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
1.47M
{
161
1.47M
  UNDIFFERENCE_2D(PREDICTOR7);
162
1.47M
  (void)(Rc);
163
1.47M
}
jdlossls-8.c:jpeg_undifference7
Line
Count
Source
160
609k
{
161
609k
  UNDIFFERENCE_2D(PREDICTOR7);
162
609k
  (void)(Rc);
163
609k
}
jdlossls-12.c:jpeg_undifference7
Line
Count
Source
160
332k
{
161
332k
  UNDIFFERENCE_2D(PREDICTOR7);
162
332k
  (void)(Rc);
163
332k
}
jdlossls-16.c:jpeg_undifference7
Line
Count
Source
160
535k
{
161
535k
  UNDIFFERENCE_2D(PREDICTOR7);
162
535k
  (void)(Rc);
163
535k
}
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
37.5M
{
178
37.5M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
37.5M
  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
37.5M
  switch (cinfo->Ss) {
188
5.11M
  case 1:
189
5.11M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
5.11M
    break;
191
10.6M
  case 2:
192
10.6M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
10.6M
    break;
194
1.77M
  case 3:
195
1.77M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
1.77M
    break;
197
4.07M
  case 4:
198
4.07M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
4.07M
    break;
200
11.6M
  case 5:
201
11.6M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
11.6M
    break;
203
1.99M
  case 6:
204
1.99M
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
1.99M
    break;
206
2.38M
  case 7:
207
2.38M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
2.38M
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
37.5M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
37.5M
  }
213
37.5M
}
jdlossls-8.c:jpeg_undifference_first_row
Line
Count
Source
177
13.3M
{
178
13.3M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
13.3M
  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
13.3M
  switch (cinfo->Ss) {
188
2.25M
  case 1:
189
2.25M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
2.25M
    break;
191
6.76M
  case 2:
192
6.76M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
6.76M
    break;
194
209k
  case 3:
195
209k
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
209k
    break;
197
980k
  case 4:
198
980k
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
980k
    break;
200
791k
  case 5:
201
791k
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
791k
    break;
203
733k
  case 6:
204
733k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
733k
    break;
206
1.59M
  case 7:
207
1.59M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
1.59M
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
13.3M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
13.3M
  }
213
13.3M
}
jdlossls-12.c:jpeg_undifference_first_row
Line
Count
Source
177
5.00M
{
178
5.00M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
5.00M
  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
5.00M
  switch (cinfo->Ss) {
188
494k
  case 1:
189
494k
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
494k
    break;
191
949k
  case 2:
192
949k
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
949k
    break;
194
945k
  case 3:
195
945k
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
945k
    break;
197
546k
  case 4:
198
546k
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
546k
    break;
200
1.34M
  case 5:
201
1.34M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
1.34M
    break;
203
490k
  case 6:
204
490k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
490k
    break;
206
240k
  case 7:
207
240k
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
240k
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
5.00M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
5.00M
  }
213
5.00M
}
jdlossls-16.c:jpeg_undifference_first_row
Line
Count
Source
177
19.2M
{
178
19.2M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
19.2M
  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
19.2M
  switch (cinfo->Ss) {
188
2.36M
  case 1:
189
2.36M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
2.36M
    break;
191
2.90M
  case 2:
192
2.90M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
2.90M
    break;
194
620k
  case 3:
195
620k
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
620k
    break;
197
2.54M
  case 4:
198
2.54M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
2.54M
    break;
200
9.50M
  case 5:
201
9.50M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
9.50M
    break;
203
774k
  case 6:
204
774k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
774k
    break;
206
543k
  case 7:
207
543k
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
543k
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
19.2M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
19.2M
  }
213
19.2M
}
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
26.7M
{
222
514M
  do {
223
514M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
514M
  } while (--width);
225
26.7M
}
jdlossls-8.c:simple_upscale
Line
Count
Source
221
5.45M
{
222
147M
  do {
223
147M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
147M
  } while (--width);
225
5.45M
}
jdlossls-12.c:simple_upscale
Line
Count
Source
221
5.93M
{
222
231M
  do {
223
231M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
231M
  } while (--width);
225
5.93M
}
jdlossls-16.c:simple_upscale
Line
Count
Source
221
15.3M
{
222
135M
  do {
223
135M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
135M
  } while (--width);
225
15.3M
}
226
227
METHODDEF(void)
228
noscale(j_decompress_ptr cinfo,
229
        JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
230
25.6M
{
231
511M
  do {
232
511M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
511M
  } while (--width);
234
25.6M
}
jdlossls-8.c:noscale
Line
Count
Source
230
13.7M
{
231
166M
  do {
232
166M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
166M
  } while (--width);
234
13.7M
}
jdlossls-12.c:noscale
Line
Count
Source
230
2.28M
{
231
178M
  do {
232
178M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
178M
  } while (--width);
234
2.28M
}
jdlossls-16.c:noscale
Line
Count
Source
230
9.63M
{
231
165M
  do {
232
165M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
165M
  } while (--width);
234
9.63M
}
235
236
237
/*
238
 * Initialize for an input processing pass.
239
 */
240
241
METHODDEF(void)
242
start_pass_lossless(j_decompress_ptr cinfo)
243
46.8M
{
244
46.8M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
46.8M
  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
46.8M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
46.8M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
46.8M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
300
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
46.8M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
170M
  for (ci = 0; ci < cinfo->num_components; ci++)
265
123M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
46.8M
  if (cinfo->Al)
269
30.8M
    losslessd->scaler_scale = simple_upscale;
270
16.0M
  else
271
16.0M
    losslessd->scaler_scale = noscale;
272
46.8M
}
jdlossls-8.c:start_pass_lossless
Line
Count
Source
243
8.53M
{
244
8.53M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
8.53M
  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
8.53M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
8.53M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
8.53M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
79
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
8.53M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
29.3M
  for (ci = 0; ci < cinfo->num_components; ci++)
265
20.7M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
8.53M
  if (cinfo->Al)
269
3.11M
    losslessd->scaler_scale = simple_upscale;
270
5.41M
  else
271
5.41M
    losslessd->scaler_scale = noscale;
272
8.53M
}
jdlossls-12.c:start_pass_lossless
Line
Count
Source
243
6.53M
{
244
6.53M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
6.53M
  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
6.53M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
6.53M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
6.53M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
94
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
6.53M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
20.0M
  for (ci = 0; ci < cinfo->num_components; ci++)
265
13.5M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
6.53M
  if (cinfo->Al)
269
4.28M
    losslessd->scaler_scale = simple_upscale;
270
2.25M
  else
271
2.25M
    losslessd->scaler_scale = noscale;
272
6.53M
}
jdlossls-16.c:start_pass_lossless
Line
Count
Source
243
31.8M
{
244
31.8M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
31.8M
  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
31.8M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
31.8M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
31.8M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
127
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
31.8M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
121M
  for (ci = 0; ci < cinfo->num_components; ci++)
265
89.4M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
31.8M
  if (cinfo->Al)
269
23.4M
    losslessd->scaler_scale = simple_upscale;
270
8.33M
  else
271
8.33M
    losslessd->scaler_scale = noscale;
272
31.8M
}
273
274
275
/*
276
 * Initialize the lossless decompressor.
277
 */
278
279
GLOBAL(void)
280
_jinit_lossless_decompressor(j_decompress_ptr cinfo)
281
3.40k
{
282
3.40k
  lossless_decomp_ptr losslessd;
283
284
#if BITS_IN_JSAMPLE == 8
285
1.06k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
286
#else
287
2.33k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
2.33k
      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
3.40k
  losslessd = (lossless_decomp_ptr)
294
3.40k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
3.40k
                                sizeof(jpeg_lossless_decompressor));
296
3.40k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
3.40k
  losslessd->pub.start_pass = start_pass_lossless;
298
3.40k
}
jinit_lossless_decompressor
Line
Count
Source
281
1.06k
{
282
1.06k
  lossless_decomp_ptr losslessd;
283
284
1.06k
#if BITS_IN_JSAMPLE == 8
285
1.06k
  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
1.06k
  losslessd = (lossless_decomp_ptr)
294
1.06k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
1.06k
                                sizeof(jpeg_lossless_decompressor));
296
1.06k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
1.06k
  losslessd->pub.start_pass = start_pass_lossless;
298
1.06k
}
j12init_lossless_decompressor
Line
Count
Source
281
1.04k
{
282
1.04k
  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
1.04k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
1.04k
      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.04k
  losslessd = (lossless_decomp_ptr)
294
1.04k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
1.04k
                                sizeof(jpeg_lossless_decompressor));
296
1.04k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
1.04k
  losslessd->pub.start_pass = start_pass_lossless;
298
1.04k
}
j16init_lossless_decompressor
Line
Count
Source
281
1.29k
{
282
1.29k
  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
1.29k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
1.29k
      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.29k
  losslessd = (lossless_decomp_ptr)
294
1.29k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
1.29k
                                sizeof(jpeg_lossless_decompressor));
296
1.29k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
1.29k
  losslessd->pub.start_pass = start_pass_lossless;
298
1.29k
}
299
300
#endif /* D_LOSSLESS_SUPPORTED */