Coverage Report

Created: 2025-12-05 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo/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
9.45k
  int Ra; \
60
9.45k
  \
61
9.45k
  Ra = (*diff_buf++ + INITIAL_PREDICTOR) & 0xFFFF; \
62
9.45k
  *undiff_buf++ = Ra; \
63
9.45k
  \
64
216k
  while (--width) { \
65
207k
    Ra = (*diff_buf++ + PREDICTOR1) & 0xFFFF; \
66
207k
    *undiff_buf++ = Ra; \
67
207k
  }
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
60.7k
  int Ra, Rb, Rc; \
87
60.7k
  \
88
60.7k
  Rb = *prev_row++; \
89
60.7k
  Ra = (*diff_buf++ + PREDICTOR2) & 0xFFFF; \
90
60.7k
  *undiff_buf++ = Ra; \
91
60.7k
  \
92
585k
  while (--width) { \
93
524k
    Rc = Rb; \
94
524k
    Rb = *prev_row++; \
95
524k
    Ra = (*diff_buf++ + PREDICTOR) & 0xFFFF; \
96
524k
    *undiff_buf++ = Ra; \
97
524k
  }
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
7.29k
{
112
7.29k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
7.29k
}
jdlossls-8.c:jpeg_undifference1
Line
Count
Source
111
4.22k
{
112
4.22k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
4.22k
}
jdlossls-12.c:jpeg_undifference1
Line
Count
Source
111
1.57k
{
112
1.57k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
1.57k
}
jdlossls-16.c:jpeg_undifference1
Line
Count
Source
111
1.49k
{
112
1.49k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
1.49k
}
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.5k
{
120
11.5k
  UNDIFFERENCE_2D(PREDICTOR2);
121
11.5k
  (void)(Rc);
122
11.5k
}
jdlossls-8.c:jpeg_undifference2
Line
Count
Source
119
3.54k
{
120
3.54k
  UNDIFFERENCE_2D(PREDICTOR2);
121
3.54k
  (void)(Rc);
122
3.54k
}
jdlossls-12.c:jpeg_undifference2
Line
Count
Source
119
3.33k
{
120
3.33k
  UNDIFFERENCE_2D(PREDICTOR2);
121
3.33k
  (void)(Rc);
122
3.33k
}
jdlossls-16.c:jpeg_undifference2
Line
Count
Source
119
4.65k
{
120
4.65k
  UNDIFFERENCE_2D(PREDICTOR2);
121
4.65k
  (void)(Rc);
122
4.65k
}
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
6.72k
{
129
6.72k
  UNDIFFERENCE_2D(PREDICTOR3);
130
6.72k
}
jdlossls-8.c:jpeg_undifference3
Line
Count
Source
128
2.46k
{
129
2.46k
  UNDIFFERENCE_2D(PREDICTOR3);
130
2.46k
}
jdlossls-12.c:jpeg_undifference3
Line
Count
Source
128
1.83k
{
129
1.83k
  UNDIFFERENCE_2D(PREDICTOR3);
130
1.83k
}
jdlossls-16.c:jpeg_undifference3
Line
Count
Source
128
2.42k
{
129
2.42k
  UNDIFFERENCE_2D(PREDICTOR3);
130
2.42k
}
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
4.39k
{
137
4.39k
  UNDIFFERENCE_2D(PREDICTOR4);
138
4.39k
}
jdlossls-8.c:jpeg_undifference4
Line
Count
Source
136
2.30k
{
137
2.30k
  UNDIFFERENCE_2D(PREDICTOR4);
138
2.30k
}
jdlossls-12.c:jpeg_undifference4
Line
Count
Source
136
795
{
137
795
  UNDIFFERENCE_2D(PREDICTOR4);
138
795
}
jdlossls-16.c:jpeg_undifference4
Line
Count
Source
136
1.29k
{
137
1.29k
  UNDIFFERENCE_2D(PREDICTOR4);
138
1.29k
}
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
21.7k
{
145
21.7k
  UNDIFFERENCE_2D(PREDICTOR5);
146
21.7k
}
jdlossls-8.c:jpeg_undifference5
Line
Count
Source
144
2.82k
{
145
2.82k
  UNDIFFERENCE_2D(PREDICTOR5);
146
2.82k
}
jdlossls-12.c:jpeg_undifference5
Line
Count
Source
144
18.2k
{
145
18.2k
  UNDIFFERENCE_2D(PREDICTOR5);
146
18.2k
}
jdlossls-16.c:jpeg_undifference5
Line
Count
Source
144
664
{
145
664
  UNDIFFERENCE_2D(PREDICTOR5);
146
664
}
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
10.2k
{
153
10.2k
  UNDIFFERENCE_2D(PREDICTOR6);
154
10.2k
}
jdlossls-8.c:jpeg_undifference6
Line
Count
Source
152
4.83k
{
153
4.83k
  UNDIFFERENCE_2D(PREDICTOR6);
154
4.83k
}
jdlossls-12.c:jpeg_undifference6
Line
Count
Source
152
3.68k
{
153
3.68k
  UNDIFFERENCE_2D(PREDICTOR6);
154
3.68k
}
jdlossls-16.c:jpeg_undifference6
Line
Count
Source
152
1.73k
{
153
1.73k
  UNDIFFERENCE_2D(PREDICTOR6);
154
1.73k
}
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
6.14k
{
161
6.14k
  UNDIFFERENCE_2D(PREDICTOR7);
162
6.14k
  (void)(Rc);
163
6.14k
}
jdlossls-8.c:jpeg_undifference7
Line
Count
Source
160
2.75k
{
161
2.75k
  UNDIFFERENCE_2D(PREDICTOR7);
162
2.75k
  (void)(Rc);
163
2.75k
}
jdlossls-12.c:jpeg_undifference7
Line
Count
Source
160
1.89k
{
161
1.89k
  UNDIFFERENCE_2D(PREDICTOR7);
162
1.89k
  (void)(Rc);
163
1.89k
}
jdlossls-16.c:jpeg_undifference7
Line
Count
Source
160
1.49k
{
161
1.49k
  UNDIFFERENCE_2D(PREDICTOR7);
162
1.49k
  (void)(Rc);
163
1.49k
}
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
2.15k
{
178
2.15k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
2.15k
  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
2.15k
  switch (cinfo->Ss) {
188
285
  case 1:
189
285
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
285
    break;
191
352
  case 2:
192
352
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
352
    break;
194
313
  case 3:
195
313
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
313
    break;
197
314
  case 4:
198
314
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
314
    break;
200
245
  case 5:
201
245
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
245
    break;
203
443
  case 6:
204
443
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
443
    break;
206
201
  case 7:
207
201
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
201
    break;
209
2.15k
  }
210
2.15k
}
jdlossls-8.c:jpeg_undifference_first_row
Line
Count
Source
177
1.58k
{
178
1.58k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
1.58k
  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
1.58k
  switch (cinfo->Ss) {
188
178
  case 1:
189
178
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
178
    break;
191
231
  case 2:
192
231
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
231
    break;
194
213
  case 3:
195
213
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
213
    break;
197
251
  case 4:
198
251
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
251
    break;
200
181
  case 5:
201
181
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
181
    break;
203
386
  case 6:
204
386
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
386
    break;
206
142
  case 7:
207
142
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
142
    break;
209
1.58k
  }
210
1.58k
}
jdlossls-12.c:jpeg_undifference_first_row
Line
Count
Source
177
283
{
178
283
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
283
  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
283
  switch (cinfo->Ss) {
188
48
  case 1:
189
48
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
48
    break;
191
67
  case 2:
192
67
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
67
    break;
194
53
  case 3:
195
53
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
53
    break;
197
26
  case 4:
198
26
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
26
    break;
200
34
  case 5:
201
34
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
34
    break;
203
29
  case 6:
204
29
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
29
    break;
206
26
  case 7:
207
26
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
26
    break;
209
283
  }
210
283
}
jdlossls-16.c:jpeg_undifference_first_row
Line
Count
Source
177
288
{
178
288
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
288
  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
288
  switch (cinfo->Ss) {
188
59
  case 1:
189
59
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
59
    break;
191
54
  case 2:
192
54
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
54
    break;
194
47
  case 3:
195
47
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
47
    break;
197
37
  case 4:
198
37
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
37
    break;
200
30
  case 5:
201
30
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
30
    break;
203
28
  case 6:
204
28
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
28
    break;
206
33
  case 7:
207
33
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
33
    break;
209
288
  }
210
288
}
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
20.5k
{
219
386k
  do {
220
386k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
386k
  } while (--width);
222
20.5k
}
jdlossls-8.c:simple_upscale
Line
Count
Source
218
11.6k
{
219
237k
  do {
220
237k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
237k
  } while (--width);
222
11.6k
}
jdlossls-12.c:simple_upscale
Line
Count
Source
218
3.39k
{
219
71.5k
  do {
220
71.5k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
71.5k
  } while (--width);
222
3.39k
}
jdlossls-16.c:simple_upscale
Line
Count
Source
218
5.49k
{
219
77.0k
  do {
220
77.0k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
77.0k
  } while (--width);
222
5.49k
}
223
224
METHODDEF(void)
225
noscale(j_decompress_ptr cinfo,
226
        JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
227
49.6k
{
228
416k
  do {
229
416k
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
416k
  } while (--width);
231
49.6k
}
jdlossls-8.c:noscale
Line
Count
Source
227
12.8k
{
228
250k
  do {
229
250k
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
250k
  } while (--width);
231
12.8k
}
jdlossls-12.c:noscale
Line
Count
Source
227
28.2k
{
228
108k
  do {
229
108k
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
108k
  } while (--width);
231
28.2k
}
jdlossls-16.c:noscale
Line
Count
Source
227
8.55k
{
228
56.9k
  do {
229
56.9k
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
56.9k
  } while (--width);
231
8.55k
}
232
233
234
/*
235
 * Initialize for an input processing pass.
236
 */
237
238
METHODDEF(void)
239
start_pass_lossless(j_decompress_ptr cinfo)
240
1.69k
{
241
1.69k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
1.69k
  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
1.69k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
1.63k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
1.58k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
114
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
1.69k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
6.82k
  for (ci = 0; ci < cinfo->num_components; ci++)
262
5.13k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
1.69k
  if (cinfo->Al)
266
653
    losslessd->scaler_scale = simple_upscale;
267
1.03k
  else
268
1.03k
    losslessd->scaler_scale = noscale;
269
1.69k
}
jdlossls-8.c:start_pass_lossless
Line
Count
Source
240
998
{
241
998
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
998
  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
998
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
979
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
959
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
43
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
998
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
4.25k
  for (ci = 0; ci < cinfo->num_components; ci++)
262
3.25k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
998
  if (cinfo->Al)
266
411
    losslessd->scaler_scale = simple_upscale;
267
587
  else
268
587
    losslessd->scaler_scale = noscale;
269
998
}
jdlossls-12.c:start_pass_lossless
Line
Count
Source
240
350
{
241
350
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
350
  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
350
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
335
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
319
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
37
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
350
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
1.30k
  for (ci = 0; ci < cinfo->num_components; ci++)
262
955
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
350
  if (cinfo->Al)
266
78
    losslessd->scaler_scale = simple_upscale;
267
272
  else
268
272
    losslessd->scaler_scale = noscale;
269
350
}
jdlossls-16.c:start_pass_lossless
Line
Count
Source
240
342
{
241
342
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
342
  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
342
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
325
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
309
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
34
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
342
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
1.26k
  for (ci = 0; ci < cinfo->num_components; ci++)
262
926
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
342
  if (cinfo->Al)
266
164
    losslessd->scaler_scale = simple_upscale;
267
178
  else
268
178
    losslessd->scaler_scale = noscale;
269
342
}
270
271
272
/*
273
 * Initialize the lossless decompressor.
274
 */
275
276
GLOBAL(void)
277
_jinit_lossless_decompressor(j_decompress_ptr cinfo)
278
1.27k
{
279
1.27k
  lossless_decomp_ptr losslessd;
280
281
#if BITS_IN_JSAMPLE == 8
282
568
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
283
#else
284
708
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
708
      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.27k
  losslessd = (lossless_decomp_ptr)
291
1.27k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
1.27k
                                sizeof(jpeg_lossless_decompressor));
293
1.27k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
1.27k
  losslessd->pub.start_pass = start_pass_lossless;
295
1.27k
}
jinit_lossless_decompressor
Line
Count
Source
278
568
{
279
568
  lossless_decomp_ptr losslessd;
280
281
568
#if BITS_IN_JSAMPLE == 8
282
568
  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
568
  losslessd = (lossless_decomp_ptr)
291
568
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
568
                                sizeof(jpeg_lossless_decompressor));
293
568
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
568
  losslessd->pub.start_pass = start_pass_lossless;
295
568
}
j12init_lossless_decompressor
Line
Count
Source
278
364
{
279
364
  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
364
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
364
      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
364
  losslessd = (lossless_decomp_ptr)
291
364
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
364
                                sizeof(jpeg_lossless_decompressor));
293
364
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
364
  losslessd->pub.start_pass = start_pass_lossless;
295
364
}
j16init_lossless_decompressor
Line
Count
Source
278
344
{
279
344
  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
344
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
344
      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
344
  losslessd = (lossless_decomp_ptr)
291
344
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
344
                                sizeof(jpeg_lossless_decompressor));
293
344
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
344
  losslessd->pub.start_pass = start_pass_lossless;
295
344
}
296
297
#endif /* D_LOSSLESS_SUPPORTED */