Coverage Report

Created: 2026-01-25 06:04

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, 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
388M
  int Ra; \
60
388M
  \
61
388M
  Ra = (*diff_buf++ + INITIAL_PREDICTOR) & 0xFFFF; \
62
388M
  *undiff_buf++ = Ra; \
63
388M
  \
64
4.42G
  while (--width) { \
65
4.03G
    Ra = (*diff_buf++ + PREDICTOR1) & 0xFFFF; \
66
4.03G
    *undiff_buf++ = Ra; \
67
4.03G
  }
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
142M
  int Ra, Rb, Rc; \
87
142M
  \
88
142M
  Rb = *prev_row++; \
89
142M
  Ra = (*diff_buf++ + PREDICTOR2) & 0xFFFF; \
90
142M
  *undiff_buf++ = Ra; \
91
142M
  \
92
1.59G
  while (--width) { \
93
1.45G
    Rc = Rb; \
94
1.45G
    Rb = *prev_row++; \
95
1.45G
    Ra = (*diff_buf++ + PREDICTOR) & 0xFFFF; \
96
1.45G
    *undiff_buf++ = Ra; \
97
1.45G
  }
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
21.2M
{
112
21.2M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
21.2M
}
jdlossls-8.c:jpeg_undifference1
Line
Count
Source
111
15.9M
{
112
15.9M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
15.9M
}
jdlossls-12.c:jpeg_undifference1
Line
Count
Source
111
3.86M
{
112
3.86M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
3.86M
}
jdlossls-16.c:jpeg_undifference1
Line
Count
Source
111
1.46M
{
112
1.46M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
1.46M
}
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
14.4M
{
120
14.4M
  UNDIFFERENCE_2D(PREDICTOR2);
121
14.4M
  (void)(Rc);
122
14.4M
}
jdlossls-8.c:jpeg_undifference2
Line
Count
Source
119
4.51M
{
120
4.51M
  UNDIFFERENCE_2D(PREDICTOR2);
121
4.51M
  (void)(Rc);
122
4.51M
}
jdlossls-12.c:jpeg_undifference2
Line
Count
Source
119
4.65M
{
120
4.65M
  UNDIFFERENCE_2D(PREDICTOR2);
121
4.65M
  (void)(Rc);
122
4.65M
}
jdlossls-16.c:jpeg_undifference2
Line
Count
Source
119
5.29M
{
120
5.29M
  UNDIFFERENCE_2D(PREDICTOR2);
121
5.29M
  (void)(Rc);
122
5.29M
}
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
18.9M
{
129
18.9M
  UNDIFFERENCE_2D(PREDICTOR3);
130
18.9M
}
jdlossls-8.c:jpeg_undifference3
Line
Count
Source
128
7.97M
{
129
7.97M
  UNDIFFERENCE_2D(PREDICTOR3);
130
7.97M
}
jdlossls-12.c:jpeg_undifference3
Line
Count
Source
128
8.58M
{
129
8.58M
  UNDIFFERENCE_2D(PREDICTOR3);
130
8.58M
}
jdlossls-16.c:jpeg_undifference3
Line
Count
Source
128
2.41M
{
129
2.41M
  UNDIFFERENCE_2D(PREDICTOR3);
130
2.41M
}
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
22.5M
{
137
22.5M
  UNDIFFERENCE_2D(PREDICTOR4);
138
22.5M
}
jdlossls-8.c:jpeg_undifference4
Line
Count
Source
136
2.03M
{
137
2.03M
  UNDIFFERENCE_2D(PREDICTOR4);
138
2.03M
}
jdlossls-12.c:jpeg_undifference4
Line
Count
Source
136
18.8M
{
137
18.8M
  UNDIFFERENCE_2D(PREDICTOR4);
138
18.8M
}
jdlossls-16.c:jpeg_undifference4
Line
Count
Source
136
1.57M
{
137
1.57M
  UNDIFFERENCE_2D(PREDICTOR4);
138
1.57M
}
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
9.58M
{
145
9.58M
  UNDIFFERENCE_2D(PREDICTOR5);
146
9.58M
}
jdlossls-8.c:jpeg_undifference5
Line
Count
Source
144
2.28M
{
145
2.28M
  UNDIFFERENCE_2D(PREDICTOR5);
146
2.28M
}
jdlossls-12.c:jpeg_undifference5
Line
Count
Source
144
3.12M
{
145
3.12M
  UNDIFFERENCE_2D(PREDICTOR5);
146
3.12M
}
jdlossls-16.c:jpeg_undifference5
Line
Count
Source
144
4.16M
{
145
4.16M
  UNDIFFERENCE_2D(PREDICTOR5);
146
4.16M
}
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
50.1M
{
153
50.1M
  UNDIFFERENCE_2D(PREDICTOR6);
154
50.1M
}
jdlossls-8.c:jpeg_undifference6
Line
Count
Source
152
1.19M
{
153
1.19M
  UNDIFFERENCE_2D(PREDICTOR6);
154
1.19M
}
jdlossls-12.c:jpeg_undifference6
Line
Count
Source
152
47.4M
{
153
47.4M
  UNDIFFERENCE_2D(PREDICTOR6);
154
47.4M
}
jdlossls-16.c:jpeg_undifference6
Line
Count
Source
152
1.49M
{
153
1.49M
  UNDIFFERENCE_2D(PREDICTOR6);
154
1.49M
}
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
26.4M
{
161
26.4M
  UNDIFFERENCE_2D(PREDICTOR7);
162
26.4M
  (void)(Rc);
163
26.4M
}
jdlossls-8.c:jpeg_undifference7
Line
Count
Source
160
2.96M
{
161
2.96M
  UNDIFFERENCE_2D(PREDICTOR7);
162
2.96M
  (void)(Rc);
163
2.96M
}
jdlossls-12.c:jpeg_undifference7
Line
Count
Source
160
21.4M
{
161
21.4M
  UNDIFFERENCE_2D(PREDICTOR7);
162
21.4M
  (void)(Rc);
163
21.4M
}
jdlossls-16.c:jpeg_undifference7
Line
Count
Source
160
1.94M
{
161
1.94M
  UNDIFFERENCE_2D(PREDICTOR7);
162
1.94M
  (void)(Rc);
163
1.94M
}
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
367M
{
178
367M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
367M
  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
367M
  switch (cinfo->Ss) {
188
115M
  case 1:
189
115M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
115M
    break;
191
25.4M
  case 2:
192
25.4M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
25.4M
    break;
194
41.4M
  case 3:
195
41.4M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
41.4M
    break;
197
42.8M
  case 4:
198
42.8M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
42.8M
    break;
200
26.6M
  case 5:
201
26.6M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
26.6M
    break;
203
62.8M
  case 6:
204
62.8M
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
62.8M
    break;
206
52.9M
  case 7:
207
52.9M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
52.9M
    break;
209
367M
  }
210
367M
}
jdlossls-8.c:jpeg_undifference_first_row
Line
Count
Source
177
81.9M
{
178
81.9M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
81.9M
  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
81.9M
  switch (cinfo->Ss) {
188
23.6M
  case 1:
189
23.6M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
23.6M
    break;
191
12.0M
  case 2:
192
12.0M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
12.0M
    break;
194
19.4M
  case 3:
195
19.4M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
19.4M
    break;
197
8.86M
  case 4:
198
8.86M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
8.86M
    break;
200
4.39M
  case 5:
201
4.39M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
4.39M
    break;
203
1.46M
  case 6:
204
1.46M
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
1.46M
    break;
206
12.0M
  case 7:
207
12.0M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
12.0M
    break;
209
81.9M
  }
210
81.9M
}
jdlossls-12.c:jpeg_undifference_first_row
Line
Count
Source
177
146M
{
178
146M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
146M
  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
146M
  switch (cinfo->Ss) {
188
13.4M
  case 1:
189
13.4M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
13.4M
    break;
191
5.62M
  case 2:
192
5.62M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
5.62M
    break;
194
18.8M
  case 3:
195
18.8M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
18.8M
    break;
197
22.5M
  case 4:
198
22.5M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
22.5M
    break;
200
3.64M
  case 5:
201
3.64M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
3.64M
    break;
203
49.7M
  case 6:
204
49.7M
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
49.7M
    break;
206
32.2M
  case 7:
207
32.2M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
32.2M
    break;
209
146M
  }
210
146M
}
jdlossls-16.c:jpeg_undifference_first_row
Line
Count
Source
177
139M
{
178
139M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
139M
  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
139M
  switch (cinfo->Ss) {
188
78.0M
  case 1:
189
78.0M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
78.0M
    break;
191
7.72M
  case 2:
192
7.72M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
7.72M
    break;
194
3.23M
  case 3:
195
3.23M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
3.23M
    break;
197
11.3M
  case 4:
198
11.3M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
11.3M
    break;
200
18.5M
  case 5:
201
18.5M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
18.5M
    break;
203
11.7M
  case 6:
204
11.7M
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
11.7M
    break;
206
8.64M
  case 7:
207
8.64M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
8.64M
    break;
209
139M
  }
210
139M
}
211
212
213
/*********************** Sample upscaling by 2^Pt ************************/
214
215
METHODDEF(void)
216
simple_upscale(j_decompress_ptr cinfo,
217
               JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
218
310M
{
219
3.86G
  do {
220
3.86G
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
3.86G
  } while (--width);
222
310M
}
jdlossls-8.c:simple_upscale
Line
Count
Source
218
63.5M
{
219
2.17G
  do {
220
2.17G
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
2.17G
  } while (--width);
222
63.5M
}
jdlossls-12.c:simple_upscale
Line
Count
Source
218
168M
{
219
1.20G
  do {
220
1.20G
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
1.20G
  } while (--width);
222
168M
}
jdlossls-16.c:simple_upscale
Line
Count
Source
218
78.7M
{
219
486M
  do {
220
486M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
486M
  } while (--width);
222
78.7M
}
223
224
METHODDEF(void)
225
noscale(j_decompress_ptr cinfo,
226
        JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
227
220M
{
228
2.15G
  do {
229
2.15G
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
2.15G
  } while (--width);
231
220M
}
jdlossls-8.c:noscale
Line
Count
Source
227
55.3M
{
228
993M
  do {
229
993M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
993M
  } while (--width);
231
55.3M
}
jdlossls-12.c:noscale
Line
Count
Source
227
86.0M
{
228
694M
  do {
229
694M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
694M
  } while (--width);
231
86.0M
}
jdlossls-16.c:noscale
Line
Count
Source
227
78.9M
{
228
463M
  do {
229
463M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
463M
  } while (--width);
231
78.9M
}
232
233
234
/*
235
 * Initialize for an input processing pass.
236
 */
237
238
METHODDEF(void)
239
start_pass_lossless(j_decompress_ptr cinfo)
240
465M
{
241
465M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
465M
  int ci;
243
244
  /* Check that the scan parameters Ss, Se, Ah, Al are OK for lossless JPEG.
245
   *
246
   * Ss is the predictor selection value (psv).  Legal values for sequential
247
   * lossless JPEG are: 1 <= psv <= 7.
248
   *
249
   * Se and Ah are not used and should be zero.
250
   *
251
   * Al specifies the point transform (Pt).
252
   * Legal values are: 0 <= Pt <= (data precision - 1).
253
   */
254
465M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
465M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
465M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
1.58k
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
465M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
1.86G
  for (ci = 0; ci < cinfo->num_components; ci++)
262
1.39G
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
465M
  if (cinfo->Al)
266
292M
    losslessd->scaler_scale = simple_upscale;
267
172M
  else
268
172M
    losslessd->scaler_scale = noscale;
269
465M
}
jdlossls-8.c:start_pass_lossless
Line
Count
Source
240
106M
{
241
106M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
106M
  int ci;
243
244
  /* Check that the scan parameters Ss, Se, Ah, Al are OK for lossless JPEG.
245
   *
246
   * Ss is the predictor selection value (psv).  Legal values for sequential
247
   * lossless JPEG are: 1 <= psv <= 7.
248
   *
249
   * Se and Ah are not used and should be zero.
250
   *
251
   * Al specifies the point transform (Pt).
252
   * Legal values are: 0 <= Pt <= (data precision - 1).
253
   */
254
106M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
106M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
106M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
615
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
106M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
422M
  for (ci = 0; ci < cinfo->num_components; ci++)
262
316M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
106M
  if (cinfo->Al)
266
58.8M
    losslessd->scaler_scale = simple_upscale;
267
47.3M
  else
268
47.3M
    losslessd->scaler_scale = noscale;
269
106M
}
jdlossls-12.c:start_pass_lossless
Line
Count
Source
240
217M
{
241
217M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
217M
  int ci;
243
244
  /* Check that the scan parameters Ss, Se, Ah, Al are OK for lossless JPEG.
245
   *
246
   * Ss is the predictor selection value (psv).  Legal values for sequential
247
   * lossless JPEG are: 1 <= psv <= 7.
248
   *
249
   * Se and Ah are not used and should be zero.
250
   *
251
   * Al specifies the point transform (Pt).
252
   * Legal values are: 0 <= Pt <= (data precision - 1).
253
   */
254
217M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
217M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
217M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
484
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
217M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
868M
  for (ci = 0; ci < cinfo->num_components; ci++)
262
651M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
217M
  if (cinfo->Al)
266
148M
    losslessd->scaler_scale = simple_upscale;
267
68.9M
  else
268
68.9M
    losslessd->scaler_scale = noscale;
269
217M
}
jdlossls-16.c:start_pass_lossless
Line
Count
Source
240
142M
{
241
142M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
142M
  int ci;
243
244
  /* Check that the scan parameters Ss, Se, Ah, Al are OK for lossless JPEG.
245
   *
246
   * Ss is the predictor selection value (psv).  Legal values for sequential
247
   * lossless JPEG are: 1 <= psv <= 7.
248
   *
249
   * Se and Ah are not used and should be zero.
250
   *
251
   * Al specifies the point transform (Pt).
252
   * Legal values are: 0 <= Pt <= (data precision - 1).
253
   */
254
142M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
142M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
142M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
482
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
142M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
569M
  for (ci = 0; ci < cinfo->num_components; ci++)
262
427M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
142M
  if (cinfo->Al)
266
85.8M
    losslessd->scaler_scale = simple_upscale;
267
56.6M
  else
268
56.6M
    losslessd->scaler_scale = noscale;
269
142M
}
270
271
272
/*
273
 * Initialize the lossless decompressor.
274
 */
275
276
GLOBAL(void)
277
_jinit_lossless_decompressor(j_decompress_ptr cinfo)
278
17.6k
{
279
17.6k
  lossless_decomp_ptr losslessd;
280
281
#if BITS_IN_JSAMPLE == 8
282
6.14k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
283
#else
284
11.4k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
11.4k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
286
0
#endif
287
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
288
289
  /* Create subobject in permanent pool */
290
17.6k
  losslessd = (lossless_decomp_ptr)
291
17.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
17.6k
                                sizeof(jpeg_lossless_decompressor));
293
17.6k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
17.6k
  losslessd->pub.start_pass = start_pass_lossless;
295
17.6k
}
jinit_lossless_decompressor
Line
Count
Source
278
6.14k
{
279
6.14k
  lossless_decomp_ptr losslessd;
280
281
6.14k
#if BITS_IN_JSAMPLE == 8
282
6.14k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
283
#else
284
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
286
#endif
287
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
288
289
  /* Create subobject in permanent pool */
290
6.14k
  losslessd = (lossless_decomp_ptr)
291
6.14k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
6.14k
                                sizeof(jpeg_lossless_decompressor));
293
6.14k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
6.14k
  losslessd->pub.start_pass = start_pass_lossless;
295
6.14k
}
j12init_lossless_decompressor
Line
Count
Source
278
5.68k
{
279
5.68k
  lossless_decomp_ptr losslessd;
280
281
#if BITS_IN_JSAMPLE == 8
282
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
283
#else
284
5.68k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
5.68k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
286
0
#endif
287
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
288
289
  /* Create subobject in permanent pool */
290
5.68k
  losslessd = (lossless_decomp_ptr)
291
5.68k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
5.68k
                                sizeof(jpeg_lossless_decompressor));
293
5.68k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
5.68k
  losslessd->pub.start_pass = start_pass_lossless;
295
5.68k
}
j16init_lossless_decompressor
Line
Count
Source
278
5.77k
{
279
5.77k
  lossless_decomp_ptr losslessd;
280
281
#if BITS_IN_JSAMPLE == 8
282
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
283
#else
284
5.77k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
5.77k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
286
0
#endif
287
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
288
289
  /* Create subobject in permanent pool */
290
5.77k
  losslessd = (lossless_decomp_ptr)
291
5.77k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
5.77k
                                sizeof(jpeg_lossless_decompressor));
293
5.77k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
5.77k
  losslessd->pub.start_pass = start_pass_lossless;
295
5.77k
}
296
297
#endif /* D_LOSSLESS_SUPPORTED */