Coverage Report

Created: 2025-12-14 06:14

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
195M
  int Ra; \
60
195M
  \
61
195M
  Ra = (*diff_buf++ + INITIAL_PREDICTOR) & 0xFFFF; \
62
195M
  *undiff_buf++ = Ra; \
63
195M
  \
64
1.37G
  while (--width) { \
65
1.17G
    Ra = (*diff_buf++ + PREDICTOR1) & 0xFFFF; \
66
1.17G
    *undiff_buf++ = Ra; \
67
1.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
36.2M
  int Ra, Rb, Rc; \
87
36.2M
  \
88
36.2M
  Rb = *prev_row++; \
89
36.2M
  Ra = (*diff_buf++ + PREDICTOR2) & 0xFFFF; \
90
36.2M
  *undiff_buf++ = Ra; \
91
36.2M
  \
92
501M
  while (--width) { \
93
465M
    Rc = Rb; \
94
465M
    Rb = *prev_row++; \
95
465M
    Ra = (*diff_buf++ + PREDICTOR) & 0xFFFF; \
96
465M
    *undiff_buf++ = Ra; \
97
465M
  }
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
3.78M
{
112
3.78M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
3.78M
}
jdlossls-8.c:jpeg_undifference1
Line
Count
Source
111
1.62M
{
112
1.62M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
1.62M
}
jdlossls-12.c:jpeg_undifference1
Line
Count
Source
111
1.63M
{
112
1.63M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
1.63M
}
jdlossls-16.c:jpeg_undifference1
Line
Count
Source
111
526k
{
112
526k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
526k
}
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.39M
{
120
5.39M
  UNDIFFERENCE_2D(PREDICTOR2);
121
5.39M
  (void)(Rc);
122
5.39M
}
jdlossls-8.c:jpeg_undifference2
Line
Count
Source
119
1.29M
{
120
1.29M
  UNDIFFERENCE_2D(PREDICTOR2);
121
1.29M
  (void)(Rc);
122
1.29M
}
jdlossls-12.c:jpeg_undifference2
Line
Count
Source
119
2.51M
{
120
2.51M
  UNDIFFERENCE_2D(PREDICTOR2);
121
2.51M
  (void)(Rc);
122
2.51M
}
jdlossls-16.c:jpeg_undifference2
Line
Count
Source
119
1.58M
{
120
1.58M
  UNDIFFERENCE_2D(PREDICTOR2);
121
1.58M
  (void)(Rc);
122
1.58M
}
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
4.88M
{
129
4.88M
  UNDIFFERENCE_2D(PREDICTOR3);
130
4.88M
}
jdlossls-8.c:jpeg_undifference3
Line
Count
Source
128
1.07M
{
129
1.07M
  UNDIFFERENCE_2D(PREDICTOR3);
130
1.07M
}
jdlossls-12.c:jpeg_undifference3
Line
Count
Source
128
2.89M
{
129
2.89M
  UNDIFFERENCE_2D(PREDICTOR3);
130
2.89M
}
jdlossls-16.c:jpeg_undifference3
Line
Count
Source
128
915k
{
129
915k
  UNDIFFERENCE_2D(PREDICTOR3);
130
915k
}
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
6.16M
{
137
6.16M
  UNDIFFERENCE_2D(PREDICTOR4);
138
6.16M
}
jdlossls-8.c:jpeg_undifference4
Line
Count
Source
136
657k
{
137
657k
  UNDIFFERENCE_2D(PREDICTOR4);
138
657k
}
jdlossls-12.c:jpeg_undifference4
Line
Count
Source
136
4.20M
{
137
4.20M
  UNDIFFERENCE_2D(PREDICTOR4);
138
4.20M
}
jdlossls-16.c:jpeg_undifference4
Line
Count
Source
136
1.30M
{
137
1.30M
  UNDIFFERENCE_2D(PREDICTOR4);
138
1.30M
}
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
5.37M
{
145
5.37M
  UNDIFFERENCE_2D(PREDICTOR5);
146
5.37M
}
jdlossls-8.c:jpeg_undifference5
Line
Count
Source
144
729k
{
145
729k
  UNDIFFERENCE_2D(PREDICTOR5);
146
729k
}
jdlossls-12.c:jpeg_undifference5
Line
Count
Source
144
2.74M
{
145
2.74M
  UNDIFFERENCE_2D(PREDICTOR5);
146
2.74M
}
jdlossls-16.c:jpeg_undifference5
Line
Count
Source
144
1.90M
{
145
1.90M
  UNDIFFERENCE_2D(PREDICTOR5);
146
1.90M
}
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
9.17M
{
153
9.17M
  UNDIFFERENCE_2D(PREDICTOR6);
154
9.17M
}
jdlossls-8.c:jpeg_undifference6
Line
Count
Source
152
379k
{
153
379k
  UNDIFFERENCE_2D(PREDICTOR6);
154
379k
}
jdlossls-12.c:jpeg_undifference6
Line
Count
Source
152
8.31M
{
153
8.31M
  UNDIFFERENCE_2D(PREDICTOR6);
154
8.31M
}
jdlossls-16.c:jpeg_undifference6
Line
Count
Source
152
474k
{
153
474k
  UNDIFFERENCE_2D(PREDICTOR6);
154
474k
}
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
5.25M
{
161
5.25M
  UNDIFFERENCE_2D(PREDICTOR7);
162
5.25M
  (void)(Rc);
163
5.25M
}
jdlossls-8.c:jpeg_undifference7
Line
Count
Source
160
426k
{
161
426k
  UNDIFFERENCE_2D(PREDICTOR7);
162
426k
  (void)(Rc);
163
426k
}
jdlossls-12.c:jpeg_undifference7
Line
Count
Source
160
4.12M
{
161
4.12M
  UNDIFFERENCE_2D(PREDICTOR7);
162
4.12M
  (void)(Rc);
163
4.12M
}
jdlossls-16.c:jpeg_undifference7
Line
Count
Source
160
698k
{
161
698k
  UNDIFFERENCE_2D(PREDICTOR7);
162
698k
  (void)(Rc);
163
698k
}
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
191M
{
178
191M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
191M
  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
191M
  switch (cinfo->Ss) {
188
80.5M
  case 1:
189
80.5M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
80.5M
    break;
191
20.3M
  case 2:
192
20.3M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
20.3M
    break;
194
25.9M
  case 3:
195
25.9M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
25.9M
    break;
197
16.5M
  case 4:
198
16.5M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
16.5M
    break;
200
11.2M
  case 5:
201
11.2M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
11.2M
    break;
203
17.0M
  case 6:
204
17.0M
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
17.0M
    break;
206
19.8M
  case 7:
207
19.8M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
19.8M
    break;
209
191M
  }
210
191M
}
jdlossls-8.c:jpeg_undifference_first_row
Line
Count
Source
177
20.5M
{
178
20.5M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
20.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
20.5M
  switch (cinfo->Ss) {
188
3.82M
  case 1:
189
3.82M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
3.82M
    break;
191
4.98M
  case 2:
192
4.98M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
4.98M
    break;
194
4.37M
  case 3:
195
4.37M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
4.37M
    break;
197
2.94M
  case 4:
198
2.94M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
2.94M
    break;
200
1.24M
  case 5:
201
1.24M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
1.24M
    break;
203
452k
  case 6:
204
452k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
452k
    break;
206
2.67M
  case 7:
207
2.67M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
2.67M
    break;
209
20.5M
  }
210
20.5M
}
jdlossls-12.c:jpeg_undifference_first_row
Line
Count
Source
177
79.8M
{
178
79.8M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
79.8M
  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
79.8M
  switch (cinfo->Ss) {
188
21.8M
  case 1:
189
21.8M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
21.8M
    break;
191
12.8M
  case 2:
192
12.8M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
12.8M
    break;
194
20.0M
  case 3:
195
20.0M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
20.0M
    break;
197
5.49M
  case 4:
198
5.49M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
5.49M
    break;
200
4.24M
  case 5:
201
4.24M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
4.24M
    break;
203
8.98M
  case 6:
204
8.98M
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
8.98M
    break;
206
6.35M
  case 7:
207
6.35M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
6.35M
    break;
209
79.8M
  }
210
79.8M
}
jdlossls-16.c:jpeg_undifference_first_row
Line
Count
Source
177
91.0M
{
178
91.0M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
91.0M
  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
91.0M
  switch (cinfo->Ss) {
188
54.8M
  case 1:
189
54.8M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
54.8M
    break;
191
2.46M
  case 2:
192
2.46M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
2.46M
    break;
194
1.52M
  case 3:
195
1.52M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
1.52M
    break;
197
8.07M
  case 4:
198
8.07M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
8.07M
    break;
200
5.74M
  case 5:
201
5.74M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
5.74M
    break;
203
7.60M
  case 6:
204
7.60M
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
7.60M
    break;
206
10.7M
  case 7:
207
10.7M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
10.7M
    break;
209
91.0M
  }
210
91.0M
}
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
93.2M
{
219
958M
  do {
220
958M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
958M
  } while (--width);
222
93.2M
}
jdlossls-8.c:simple_upscale
Line
Count
Source
218
12.3M
{
219
337M
  do {
220
337M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
337M
  } while (--width);
222
12.3M
}
jdlossls-12.c:simple_upscale
Line
Count
Source
218
48.9M
{
219
437M
  do {
220
437M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
437M
  } while (--width);
222
48.9M
}
jdlossls-16.c:simple_upscale
Line
Count
Source
218
31.9M
{
219
183M
  do {
220
183M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
183M
  } while (--width);
222
31.9M
}
223
224
METHODDEF(void)
225
noscale(j_decompress_ptr cinfo,
226
        JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
227
138M
{
228
916M
  do {
229
916M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
916M
  } while (--width);
231
138M
}
jdlossls-8.c:noscale
Line
Count
Source
227
14.3M
{
228
318M
  do {
229
318M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
318M
  } while (--width);
231
14.3M
}
jdlossls-12.c:noscale
Line
Count
Source
227
57.3M
{
228
348M
  do {
229
348M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
348M
  } while (--width);
231
57.3M
}
jdlossls-16.c:noscale
Line
Count
Source
227
66.5M
{
228
249M
  do {
229
249M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
249M
  } while (--width);
231
66.5M
}
232
233
234
/*
235
 * Initialize for an input processing pass.
236
 */
237
238
METHODDEF(void)
239
start_pass_lossless(j_decompress_ptr cinfo)
240
190M
{
241
190M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
190M
  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
190M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
190M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
190M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
424
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
190M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
763M
  for (ci = 0; ci < cinfo->num_components; ci++)
262
572M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
190M
  if (cinfo->Al)
266
87.0M
    losslessd->scaler_scale = simple_upscale;
267
103M
  else
268
103M
    losslessd->scaler_scale = noscale;
269
190M
}
jdlossls-8.c:start_pass_lossless
Line
Count
Source
240
23.6M
{
241
23.6M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
23.6M
  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
23.6M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
23.6M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
23.6M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
154
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
23.6M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
94.5M
  for (ci = 0; ci < cinfo->num_components; ci++)
262
70.9M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
23.6M
  if (cinfo->Al)
266
10.7M
    losslessd->scaler_scale = simple_upscale;
267
12.8M
  else
268
12.8M
    losslessd->scaler_scale = noscale;
269
23.6M
}
jdlossls-12.c:start_pass_lossless
Line
Count
Source
240
90.3M
{
241
90.3M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
90.3M
  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
90.3M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
90.3M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
90.3M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
124
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
90.3M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
361M
  for (ci = 0; ci < cinfo->num_components; ci++)
262
270M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
90.3M
  if (cinfo->Al)
266
43.6M
    losslessd->scaler_scale = simple_upscale;
267
46.6M
  else
268
46.6M
    losslessd->scaler_scale = noscale;
269
90.3M
}
jdlossls-16.c:start_pass_lossless
Line
Count
Source
240
77.0M
{
241
77.0M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
77.0M
  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
77.0M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
77.0M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
77.0M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
146
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
77.0M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
308M
  for (ci = 0; ci < cinfo->num_components; ci++)
262
231M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
77.0M
  if (cinfo->Al)
266
32.6M
    losslessd->scaler_scale = simple_upscale;
267
44.3M
  else
268
44.3M
    losslessd->scaler_scale = noscale;
269
77.0M
}
270
271
272
/*
273
 * Initialize the lossless decompressor.
274
 */
275
276
GLOBAL(void)
277
_jinit_lossless_decompressor(j_decompress_ptr cinfo)
278
5.38k
{
279
5.38k
  lossless_decomp_ptr losslessd;
280
281
#if BITS_IN_JSAMPLE == 8
282
1.77k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
283
#else
284
3.61k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
3.61k
      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.38k
  losslessd = (lossless_decomp_ptr)
291
5.38k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
5.38k
                                sizeof(jpeg_lossless_decompressor));
293
5.38k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
5.38k
  losslessd->pub.start_pass = start_pass_lossless;
295
5.38k
}
jinit_lossless_decompressor
Line
Count
Source
278
1.77k
{
279
1.77k
  lossless_decomp_ptr losslessd;
280
281
1.77k
#if BITS_IN_JSAMPLE == 8
282
1.77k
  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
1.77k
  losslessd = (lossless_decomp_ptr)
291
1.77k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
1.77k
                                sizeof(jpeg_lossless_decompressor));
293
1.77k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
1.77k
  losslessd->pub.start_pass = start_pass_lossless;
295
1.77k
}
j12init_lossless_decompressor
Line
Count
Source
278
1.77k
{
279
1.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
1.77k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
1.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
1.77k
  losslessd = (lossless_decomp_ptr)
291
1.77k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
1.77k
                                sizeof(jpeg_lossless_decompressor));
293
1.77k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
1.77k
  losslessd->pub.start_pass = start_pass_lossless;
295
1.77k
}
j16init_lossless_decompressor
Line
Count
Source
278
1.83k
{
279
1.83k
  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
1.83k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
1.83k
      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
1.83k
  losslessd = (lossless_decomp_ptr)
291
1.83k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
1.83k
                                sizeof(jpeg_lossless_decompressor));
293
1.83k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
1.83k
  losslessd->pub.start_pass = start_pass_lossless;
295
1.83k
}
296
297
#endif /* D_LOSSLESS_SUPPORTED */