Coverage Report

Created: 2025-12-05 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.dev/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.46G
  while (--width) { \
65
1.27G
    Ra = (*diff_buf++ + PREDICTOR1) & 0xFFFF; \
66
1.27G
    *undiff_buf++ = Ra; \
67
1.27G
  }
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.5M
  int Ra, Rb, Rc; \
87
36.5M
  \
88
36.5M
  Rb = *prev_row++; \
89
36.5M
  Ra = (*diff_buf++ + PREDICTOR2) & 0xFFFF; \
90
36.5M
  *undiff_buf++ = Ra; \
91
36.5M
  \
92
535M
  while (--width) { \
93
498M
    Rc = Rb; \
94
498M
    Rb = *prev_row++; \
95
498M
    Ra = (*diff_buf++ + PREDICTOR) & 0xFFFF; \
96
498M
    *undiff_buf++ = Ra; \
97
498M
  }
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
4.01M
{
112
4.01M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
4.01M
}
jdlossls-8.c:jpeg_undifference1
Line
Count
Source
111
1.69M
{
112
1.69M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
1.69M
}
jdlossls-12.c:jpeg_undifference1
Line
Count
Source
111
1.72M
{
112
1.72M
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
1.72M
}
jdlossls-16.c:jpeg_undifference1
Line
Count
Source
111
598k
{
112
598k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
598k
}
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.45M
{
120
5.45M
  UNDIFFERENCE_2D(PREDICTOR2);
121
5.45M
  (void)(Rc);
122
5.45M
}
jdlossls-8.c:jpeg_undifference2
Line
Count
Source
119
1.30M
{
120
1.30M
  UNDIFFERENCE_2D(PREDICTOR2);
121
1.30M
  (void)(Rc);
122
1.30M
}
jdlossls-12.c:jpeg_undifference2
Line
Count
Source
119
2.56M
{
120
2.56M
  UNDIFFERENCE_2D(PREDICTOR2);
121
2.56M
  (void)(Rc);
122
2.56M
}
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
5.65M
{
129
5.65M
  UNDIFFERENCE_2D(PREDICTOR3);
130
5.65M
}
jdlossls-8.c:jpeg_undifference3
Line
Count
Source
128
2.01M
{
129
2.01M
  UNDIFFERENCE_2D(PREDICTOR3);
130
2.01M
}
jdlossls-12.c:jpeg_undifference3
Line
Count
Source
128
2.70M
{
129
2.70M
  UNDIFFERENCE_2D(PREDICTOR3);
130
2.70M
}
jdlossls-16.c:jpeg_undifference3
Line
Count
Source
128
933k
{
129
933k
  UNDIFFERENCE_2D(PREDICTOR3);
130
933k
}
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.29M
{
137
6.29M
  UNDIFFERENCE_2D(PREDICTOR4);
138
6.29M
}
jdlossls-8.c:jpeg_undifference4
Line
Count
Source
136
1.07M
{
137
1.07M
  UNDIFFERENCE_2D(PREDICTOR4);
138
1.07M
}
jdlossls-12.c:jpeg_undifference4
Line
Count
Source
136
3.89M
{
137
3.89M
  UNDIFFERENCE_2D(PREDICTOR4);
138
3.89M
}
jdlossls-16.c:jpeg_undifference4
Line
Count
Source
136
1.32M
{
137
1.32M
  UNDIFFERENCE_2D(PREDICTOR4);
138
1.32M
}
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.40M
{
145
5.40M
  UNDIFFERENCE_2D(PREDICTOR5);
146
5.40M
}
jdlossls-8.c:jpeg_undifference5
Line
Count
Source
144
772k
{
145
772k
  UNDIFFERENCE_2D(PREDICTOR5);
146
772k
}
jdlossls-12.c:jpeg_undifference5
Line
Count
Source
144
2.72M
{
145
2.72M
  UNDIFFERENCE_2D(PREDICTOR5);
146
2.72M
}
jdlossls-16.c:jpeg_undifference5
Line
Count
Source
144
1.91M
{
145
1.91M
  UNDIFFERENCE_2D(PREDICTOR5);
146
1.91M
}
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.15M
{
153
9.15M
  UNDIFFERENCE_2D(PREDICTOR6);
154
9.15M
}
jdlossls-8.c:jpeg_undifference6
Line
Count
Source
152
418k
{
153
418k
  UNDIFFERENCE_2D(PREDICTOR6);
154
418k
}
jdlossls-12.c:jpeg_undifference6
Line
Count
Source
152
8.25M
{
153
8.25M
  UNDIFFERENCE_2D(PREDICTOR6);
154
8.25M
}
jdlossls-16.c:jpeg_undifference6
Line
Count
Source
152
482k
{
153
482k
  UNDIFFERENCE_2D(PREDICTOR6);
154
482k
}
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
4.60M
{
161
4.60M
  UNDIFFERENCE_2D(PREDICTOR7);
162
4.60M
  (void)(Rc);
163
4.60M
}
jdlossls-8.c:jpeg_undifference7
Line
Count
Source
160
471k
{
161
471k
  UNDIFFERENCE_2D(PREDICTOR7);
162
471k
  (void)(Rc);
163
471k
}
jdlossls-12.c:jpeg_undifference7
Line
Count
Source
160
3.41M
{
161
3.41M
  UNDIFFERENCE_2D(PREDICTOR7);
162
3.41M
  (void)(Rc);
163
3.41M
}
jdlossls-16.c:jpeg_undifference7
Line
Count
Source
160
715k
{
161
715k
  UNDIFFERENCE_2D(PREDICTOR7);
162
715k
  (void)(Rc);
163
715k
}
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
86.2M
  case 1:
189
86.2M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
86.2M
    break;
191
14.7M
  case 2:
192
14.7M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
14.7M
    break;
194
26.4M
  case 3:
195
26.4M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
26.4M
    break;
197
16.7M
  case 4:
198
16.7M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
16.7M
    break;
200
11.0M
  case 5:
201
11.0M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
11.0M
    break;
203
17.0M
  case 6:
204
17.0M
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
17.0M
    break;
206
19.0M
  case 7:
207
19.0M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
19.0M
    break;
209
191M
  }
210
191M
}
jdlossls-8.c:jpeg_undifference_first_row
Line
Count
Source
177
21.7M
{
178
21.7M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
21.7M
  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
21.7M
  switch (cinfo->Ss) {
188
3.85M
  case 1:
189
3.85M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
3.85M
    break;
191
4.65M
  case 2:
192
4.65M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
4.65M
    break;
194
5.25M
  case 3:
195
5.25M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
5.25M
    break;
197
3.19M
  case 4:
198
3.19M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
3.19M
    break;
200
1.33M
  case 5:
201
1.33M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
1.33M
    break;
203
490k
  case 6:
204
490k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
490k
    break;
206
2.94M
  case 7:
207
2.94M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
2.94M
    break;
209
21.7M
  }
210
21.7M
}
jdlossls-12.c:jpeg_undifference_first_row
Line
Count
Source
177
61.5M
{
178
61.5M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
61.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
61.5M
  switch (cinfo->Ss) {
188
10.6M
  case 1:
189
10.6M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
10.6M
    break;
191
7.55M
  case 2:
192
7.55M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
7.55M
    break;
194
19.6M
  case 3:
195
19.6M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
19.6M
    break;
197
5.22M
  case 4:
198
5.22M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
5.22M
    break;
200
4.22M
  case 5:
201
4.22M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
4.22M
    break;
203
8.94M
  case 6:
204
8.94M
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
8.94M
    break;
206
5.25M
  case 7:
207
5.25M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
5.25M
    break;
209
61.5M
  }
210
61.5M
}
jdlossls-16.c:jpeg_undifference_first_row
Line
Count
Source
177
108M
{
178
108M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
108M
  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
108M
  switch (cinfo->Ss) {
188
71.7M
  case 1:
189
71.7M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
71.7M
    break;
191
2.50M
  case 2:
192
2.50M
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
2.50M
    break;
194
1.56M
  case 3:
195
1.56M
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
1.56M
    break;
197
8.33M
  case 4:
198
8.33M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
8.33M
    break;
200
5.50M
  case 5:
201
5.50M
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
5.50M
    break;
203
7.65M
  case 6:
204
7.65M
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
7.65M
    break;
206
10.8M
  case 7:
207
10.8M
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
10.8M
    break;
209
108M
  }
210
108M
}
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
111M
{
219
1.10G
  do {
220
1.10G
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
1.10G
  } while (--width);
222
111M
}
jdlossls-8.c:simple_upscale
Line
Count
Source
218
14.9M
{
219
375M
  do {
220
375M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
375M
  } while (--width);
222
14.9M
}
jdlossls-12.c:simple_upscale
Line
Count
Source
218
47.6M
{
219
477M
  do {
220
477M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
477M
  } while (--width);
222
47.6M
}
jdlossls-16.c:simple_upscale
Line
Count
Source
218
49.0M
{
219
255M
  do {
220
255M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
255M
  } while (--width);
222
49.0M
}
223
224
METHODDEF(void)
225
noscale(j_decompress_ptr cinfo,
226
        JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
227
120M
{
228
893M
  do {
229
893M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
893M
  } while (--width);
231
120M
}
jdlossls-8.c:noscale
Line
Count
Source
227
14.5M
{
228
313M
  do {
229
313M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
313M
  } while (--width);
231
14.5M
}
jdlossls-12.c:noscale
Line
Count
Source
227
39.1M
{
228
326M
  do {
229
326M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
326M
  } while (--width);
231
39.1M
}
jdlossls-16.c:noscale
Line
Count
Source
227
66.6M
{
228
252M
  do {
229
252M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
252M
  } while (--width);
231
66.6M
}
232
233
234
/*
235
 * Initialize for an input processing pass.
236
 */
237
238
METHODDEF(void)
239
start_pass_lossless(j_decompress_ptr cinfo)
240
192M
{
241
192M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
192M
  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
192M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
192M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
192M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
460
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
192M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
771M
  for (ci = 0; ci < cinfo->num_components; ci++)
262
578M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
192M
  if (cinfo->Al)
266
106M
    losslessd->scaler_scale = simple_upscale;
267
86.5M
  else
268
86.5M
    losslessd->scaler_scale = noscale;
269
192M
}
jdlossls-8.c:start_pass_lossless
Line
Count
Source
240
26.5M
{
241
26.5M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
26.5M
  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
26.5M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
26.5M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
26.5M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
166
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
26.5M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
106M
  for (ci = 0; ci < cinfo->num_components; ci++)
262
79.5M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
26.5M
  if (cinfo->Al)
266
13.4M
    losslessd->scaler_scale = simple_upscale;
267
13.0M
  else
268
13.0M
    losslessd->scaler_scale = noscale;
269
26.5M
}
jdlossls-12.c:start_pass_lossless
Line
Count
Source
240
72.1M
{
241
72.1M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
72.1M
  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
72.1M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
72.1M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
72.1M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
139
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
72.1M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
288M
  for (ci = 0; ci < cinfo->num_components; ci++)
262
216M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
72.1M
  if (cinfo->Al)
266
43.1M
    losslessd->scaler_scale = simple_upscale;
267
28.9M
  else
268
28.9M
    losslessd->scaler_scale = noscale;
269
72.1M
}
jdlossls-16.c:start_pass_lossless
Line
Count
Source
240
94.2M
{
241
94.2M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
94.2M
  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
94.2M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
94.2M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
94.2M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
155
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
94.2M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
376M
  for (ci = 0; ci < cinfo->num_components; ci++)
262
282M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
94.2M
  if (cinfo->Al)
266
49.6M
    losslessd->scaler_scale = simple_upscale;
267
44.5M
  else
268
44.5M
    losslessd->scaler_scale = noscale;
269
94.2M
}
270
271
272
/*
273
 * Initialize the lossless decompressor.
274
 */
275
276
GLOBAL(void)
277
_jinit_lossless_decompressor(j_decompress_ptr cinfo)
278
5.56k
{
279
5.56k
  lossless_decomp_ptr losslessd;
280
281
#if BITS_IN_JSAMPLE == 8
282
1.85k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
283
#else
284
3.71k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
3.71k
      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.56k
  losslessd = (lossless_decomp_ptr)
291
5.56k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
5.56k
                                sizeof(jpeg_lossless_decompressor));
293
5.56k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
5.56k
  losslessd->pub.start_pass = start_pass_lossless;
295
5.56k
}
jinit_lossless_decompressor
Line
Count
Source
278
1.85k
{
279
1.85k
  lossless_decomp_ptr losslessd;
280
281
1.85k
#if BITS_IN_JSAMPLE == 8
282
1.85k
  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.85k
  losslessd = (lossless_decomp_ptr)
291
1.85k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
1.85k
                                sizeof(jpeg_lossless_decompressor));
293
1.85k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
1.85k
  losslessd->pub.start_pass = start_pass_lossless;
295
1.85k
}
j12init_lossless_decompressor
Line
Count
Source
278
1.82k
{
279
1.82k
  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.82k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
1.82k
      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.82k
  losslessd = (lossless_decomp_ptr)
291
1.82k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
1.82k
                                sizeof(jpeg_lossless_decompressor));
293
1.82k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
1.82k
  losslessd->pub.start_pass = start_pass_lossless;
295
1.82k
}
j16init_lossless_decompressor
Line
Count
Source
278
1.88k
{
279
1.88k
  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.88k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
1.88k
      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.88k
  losslessd = (lossless_decomp_ptr)
291
1.88k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
1.88k
                                sizeof(jpeg_lossless_decompressor));
293
1.88k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
1.88k
  losslessd->pub.start_pass = start_pass_lossless;
295
1.88k
}
296
297
#endif /* D_LOSSLESS_SUPPORTED */