Coverage Report

Created: 2026-08-13 07:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.3.1.x/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
261M
  int Ra; \
60
261M
  \
61
261M
  Ra = (*diff_buf++ + INITIAL_PREDICTOR) & 0xFFFF; \
62
261M
  *undiff_buf++ = Ra; \
63
261M
  \
64
2.43G
  while (--width) { \
65
2.17G
    Ra = (*diff_buf++ + PREDICTOR1) & 0xFFFF; \
66
2.17G
    *undiff_buf++ = Ra; \
67
2.17G
  }
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
106M
  int Ra, Rb, Rc; \
87
106M
  \
88
106M
  Rb = *prev_row++; \
89
106M
  Ra = (*diff_buf++ + PREDICTOR2) & 0xFFFF; \
90
106M
  *undiff_buf++ = Ra; \
91
106M
  \
92
1.29G
  while (--width) { \
93
1.18G
    Rc = Rb; \
94
1.18G
    Rb = *prev_row++; \
95
1.18G
    Ra = (*diff_buf++ + PREDICTOR) & 0xFFFF; \
96
1.18G
    *undiff_buf++ = Ra; \
97
1.18G
  }
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
28.3M
{
112
28.3M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
28.3M
}
jdlossls-8.c:jpeg_undifference1
Line
Count
Source
111
15.5M
{
112
15.5M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
15.5M
}
jdlossls-12.c:jpeg_undifference1
Line
Count
Source
111
3.99M
{
112
3.99M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
3.99M
}
jdlossls-16.c:jpeg_undifference1
Line
Count
Source
111
8.76M
{
112
8.76M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
8.76M
}
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
11.9M
{
120
11.9M
  UNDIFFERENCE_2D(PREDICTOR2);
121
11.9M
  (void)(Rc);
122
11.9M
}
jdlossls-8.c:jpeg_undifference2
Line
Count
Source
119
6.62M
{
120
6.62M
  UNDIFFERENCE_2D(PREDICTOR2);
121
6.62M
  (void)(Rc);
122
6.62M
}
jdlossls-12.c:jpeg_undifference2
Line
Count
Source
119
3.05M
{
120
3.05M
  UNDIFFERENCE_2D(PREDICTOR2);
121
3.05M
  (void)(Rc);
122
3.05M
}
jdlossls-16.c:jpeg_undifference2
Line
Count
Source
119
2.29M
{
120
2.29M
  UNDIFFERENCE_2D(PREDICTOR2);
121
2.29M
  (void)(Rc);
122
2.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
17.3M
{
129
17.3M
  UNDIFFERENCE_2D(PREDICTOR3);
130
17.3M
}
jdlossls-8.c:jpeg_undifference3
Line
Count
Source
128
2.99M
{
129
2.99M
  UNDIFFERENCE_2D(PREDICTOR3);
130
2.99M
}
jdlossls-12.c:jpeg_undifference3
Line
Count
Source
128
4.59M
{
129
4.59M
  UNDIFFERENCE_2D(PREDICTOR3);
130
4.59M
}
jdlossls-16.c:jpeg_undifference3
Line
Count
Source
128
9.78M
{
129
9.78M
  UNDIFFERENCE_2D(PREDICTOR3);
130
9.78M
}
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
15.5M
{
137
15.5M
  UNDIFFERENCE_2D(PREDICTOR4);
138
15.5M
}
jdlossls-8.c:jpeg_undifference4
Line
Count
Source
136
6.40M
{
137
6.40M
  UNDIFFERENCE_2D(PREDICTOR4);
138
6.40M
}
jdlossls-12.c:jpeg_undifference4
Line
Count
Source
136
3.08M
{
137
3.08M
  UNDIFFERENCE_2D(PREDICTOR4);
138
3.08M
}
jdlossls-16.c:jpeg_undifference4
Line
Count
Source
136
6.05M
{
137
6.05M
  UNDIFFERENCE_2D(PREDICTOR4);
138
6.05M
}
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
11.6M
{
145
11.6M
  UNDIFFERENCE_2D(PREDICTOR5);
146
11.6M
}
jdlossls-8.c:jpeg_undifference5
Line
Count
Source
144
2.73M
{
145
2.73M
  UNDIFFERENCE_2D(PREDICTOR5);
146
2.73M
}
jdlossls-12.c:jpeg_undifference5
Line
Count
Source
144
3.99M
{
145
3.99M
  UNDIFFERENCE_2D(PREDICTOR5);
146
3.99M
}
jdlossls-16.c:jpeg_undifference5
Line
Count
Source
144
4.94M
{
145
4.94M
  UNDIFFERENCE_2D(PREDICTOR5);
146
4.94M
}
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
16.5M
{
153
16.5M
  UNDIFFERENCE_2D(PREDICTOR6);
154
16.5M
}
jdlossls-8.c:jpeg_undifference6
Line
Count
Source
152
3.09M
{
153
3.09M
  UNDIFFERENCE_2D(PREDICTOR6);
154
3.09M
}
jdlossls-12.c:jpeg_undifference6
Line
Count
Source
152
2.51M
{
153
2.51M
  UNDIFFERENCE_2D(PREDICTOR6);
154
2.51M
}
jdlossls-16.c:jpeg_undifference6
Line
Count
Source
152
10.9M
{
153
10.9M
  UNDIFFERENCE_2D(PREDICTOR6);
154
10.9M
}
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
32.8M
{
161
32.8M
  UNDIFFERENCE_2D(PREDICTOR7);
162
32.8M
  (void)(Rc);
163
32.8M
}
jdlossls-8.c:jpeg_undifference7
Line
Count
Source
160
4.73M
{
161
4.73M
  UNDIFFERENCE_2D(PREDICTOR7);
162
4.73M
  (void)(Rc);
163
4.73M
}
jdlossls-12.c:jpeg_undifference7
Line
Count
Source
160
25.1M
{
161
25.1M
  UNDIFFERENCE_2D(PREDICTOR7);
162
25.1M
  (void)(Rc);
163
25.1M
}
jdlossls-16.c:jpeg_undifference7
Line
Count
Source
160
2.99M
{
161
2.99M
  UNDIFFERENCE_2D(PREDICTOR7);
162
2.99M
  (void)(Rc);
163
2.99M
}
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
233M
{
178
233M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
233M
  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
233M
  switch (cinfo->Ss) {
188
64.0M
  case 1:
189
64.0M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
64.0M
    break;
191
22.8M
  case 2:
192
22.8M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
22.8M
    break;
194
23.3M
  case 3:
195
23.3M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
23.3M
    break;
197
32.8M
  case 4:
198
32.8M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
32.8M
    break;
200
32.8M
  case 5:
201
32.8M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
32.8M
    break;
203
18.2M
  case 6:
204
18.2M
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
18.2M
    break;
206
39.1M
  case 7:
207
39.1M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
39.1M
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
233M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
233M
  }
213
233M
}
jdlossls-8.c:jpeg_undifference_first_row
Line
Count
Source
177
64.5M
{
178
64.5M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
64.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
64.5M
  switch (cinfo->Ss) {
188
17.7M
  case 1:
189
17.7M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
17.7M
    break;
191
14.9M
  case 2:
192
14.9M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
14.9M
    break;
194
4.88M
  case 3:
195
4.88M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
4.88M
    break;
197
11.3M
  case 4:
198
11.3M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
11.3M
    break;
200
6.84M
  case 5:
201
6.84M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
6.84M
    break;
203
2.85M
  case 6:
204
2.85M
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
2.85M
    break;
206
5.99M
  case 7:
207
5.99M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
5.99M
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
64.5M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
64.5M
  }
213
64.5M
}
jdlossls-12.c:jpeg_undifference_first_row
Line
Count
Source
177
74.2M
{
178
74.2M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
74.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
74.2M
  switch (cinfo->Ss) {
188
13.9M
  case 1:
189
13.9M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
13.9M
    break;
191
3.78M
  case 2:
192
3.78M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
3.78M
    break;
194
8.06M
  case 3:
195
8.06M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
8.06M
    break;
197
9.56M
  case 4:
198
9.56M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
9.56M
    break;
200
5.35M
  case 5:
201
5.35M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
5.35M
    break;
203
4.20M
  case 6:
204
4.20M
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
4.20M
    break;
206
29.3M
  case 7:
207
29.3M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
29.3M
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
74.2M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
74.2M
  }
213
74.2M
}
jdlossls-16.c:jpeg_undifference_first_row
Line
Count
Source
177
94.6M
{
178
94.6M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
94.6M
  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
94.6M
  switch (cinfo->Ss) {
188
32.3M
  case 1:
189
32.3M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
32.3M
    break;
191
4.08M
  case 2:
192
4.08M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
4.08M
    break;
194
10.4M
  case 3:
195
10.4M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
10.4M
    break;
197
11.9M
  case 4:
198
11.9M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
11.9M
    break;
200
20.7M
  case 5:
201
20.7M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
20.7M
    break;
203
11.2M
  case 6:
204
11.2M
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
11.2M
    break;
206
3.79M
  case 7:
207
3.79M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
3.79M
    break;
209
0
  default:
210
0
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
211
94.6M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
212
94.6M
  }
213
94.6M
}
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
109M
{
222
1.37G
  do {
223
1.37G
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
1.37G
  } while (--width);
225
109M
}
jdlossls-8.c:simple_upscale
Line
Count
Source
221
26.9M
{
222
523M
  do {
223
523M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
523M
  } while (--width);
225
26.9M
}
jdlossls-12.c:simple_upscale
Line
Count
Source
221
28.8M
{
222
396M
  do {
223
396M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
396M
  } while (--width);
225
28.8M
}
jdlossls-16.c:simple_upscale
Line
Count
Source
221
54.0M
{
222
453M
  do {
223
453M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
224
453M
  } while (--width);
225
54.0M
}
226
227
METHODDEF(void)
228
noscale(j_decompress_ptr cinfo,
229
        JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
230
257M
{
231
2.35G
  do {
232
2.35G
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
2.35G
  } while (--width);
234
257M
}
jdlossls-8.c:noscale
Line
Count
Source
230
79.7M
{
231
836M
  do {
232
836M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
836M
  } while (--width);
234
79.7M
}
jdlossls-12.c:noscale
Line
Count
Source
230
91.7M
{
231
947M
  do {
232
947M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
947M
  } while (--width);
234
91.7M
}
jdlossls-16.c:noscale
Line
Count
Source
230
86.4M
{
231
571M
  do {
232
571M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
233
571M
  } while (--width);
234
86.4M
}
235
236
237
/*
238
 * Initialize for an input processing pass.
239
 */
240
241
METHODDEF(void)
242
start_pass_lossless(j_decompress_ptr cinfo)
243
340M
{
244
340M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
340M
  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
340M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
340M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
340M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
1.45k
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
340M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
1.33G
  for (ci = 0; ci < cinfo->num_components; ci++)
265
993M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
340M
  if (cinfo->Al)
269
105M
    losslessd->scaler_scale = simple_upscale;
270
235M
  else
271
235M
    losslessd->scaler_scale = noscale;
272
340M
}
jdlossls-8.c:start_pass_lossless
Line
Count
Source
243
77.0M
{
244
77.0M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
77.0M
  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
77.0M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
77.0M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
77.0M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
526
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
77.0M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
300M
  for (ci = 0; ci < cinfo->num_components; ci++)
265
223M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
77.0M
  if (cinfo->Al)
269
20.5M
    losslessd->scaler_scale = simple_upscale;
270
56.4M
  else
271
56.4M
    losslessd->scaler_scale = noscale;
272
77.0M
}
jdlossls-12.c:start_pass_lossless
Line
Count
Source
243
105M
{
244
105M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
105M
  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
105M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
105M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
105M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
396
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
105M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
411M
  for (ci = 0; ci < cinfo->num_components; ci++)
265
306M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
105M
  if (cinfo->Al)
269
25.9M
    losslessd->scaler_scale = simple_upscale;
270
79.1M
  else
271
79.1M
    losslessd->scaler_scale = noscale;
272
105M
}
jdlossls-16.c:start_pass_lossless
Line
Count
Source
243
158M
{
244
158M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
245
158M
  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
158M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
258
158M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
259
158M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
260
532
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
261
158M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
262
263
  /* Set undifference functions to first row function */
264
622M
  for (ci = 0; ci < cinfo->num_components; ci++)
265
464M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
266
267
  /* Set scaler function based on Pt */
268
158M
  if (cinfo->Al)
269
58.8M
    losslessd->scaler_scale = simple_upscale;
270
99.5M
  else
271
99.5M
    losslessd->scaler_scale = noscale;
272
158M
}
273
274
275
/*
276
 * Initialize the lossless decompressor.
277
 */
278
279
GLOBAL(void)
280
_jinit_lossless_decompressor(j_decompress_ptr cinfo)
281
19.1k
{
282
19.1k
  lossless_decomp_ptr losslessd;
283
284
#if BITS_IN_JSAMPLE == 8
285
6.58k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
286
#else
287
12.5k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
12.5k
      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
19.1k
  losslessd = (lossless_decomp_ptr)
294
19.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
19.1k
                                sizeof(jpeg_lossless_decompressor));
296
19.1k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
19.1k
  losslessd->pub.start_pass = start_pass_lossless;
298
19.1k
}
jinit_lossless_decompressor
Line
Count
Source
281
6.58k
{
282
6.58k
  lossless_decomp_ptr losslessd;
283
284
6.58k
#if BITS_IN_JSAMPLE == 8
285
6.58k
  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.58k
  losslessd = (lossless_decomp_ptr)
294
6.58k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
6.58k
                                sizeof(jpeg_lossless_decompressor));
296
6.58k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
6.58k
  losslessd->pub.start_pass = start_pass_lossless;
298
6.58k
}
j12init_lossless_decompressor
Line
Count
Source
281
6.07k
{
282
6.07k
  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
6.07k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
6.07k
      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
6.07k
  losslessd = (lossless_decomp_ptr)
294
6.07k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
6.07k
                                sizeof(jpeg_lossless_decompressor));
296
6.07k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
6.07k
  losslessd->pub.start_pass = start_pass_lossless;
298
6.07k
}
j16init_lossless_decompressor
Line
Count
Source
281
6.47k
{
282
6.47k
  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
6.47k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
288
6.47k
      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
6.47k
  losslessd = (lossless_decomp_ptr)
294
6.47k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
295
6.47k
                                sizeof(jpeg_lossless_decompressor));
296
6.47k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
297
6.47k
  losslessd->pub.start_pass = start_pass_lossless;
298
6.47k
}
299
300
#endif /* D_LOSSLESS_SUPPORTED */