Coverage Report

Created: 2025-08-03 06:15

/src/libjpeg-turbo/src/jdlossls.c
Line
Count
Source (jump to first uncovered line)
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
15.1k
  int Ra; \
60
15.1k
  \
61
15.1k
  Ra = (*diff_buf++ + INITIAL_PREDICTOR) & 0xFFFF; \
62
15.1k
  *undiff_buf++ = Ra; \
63
15.1k
  \
64
5.29M
  while (--width) { \
65
5.28M
    Ra = (*diff_buf++ + PREDICTOR1) & 0xFFFF; \
66
5.28M
    *undiff_buf++ = Ra; \
67
5.28M
  }
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
164k
  int Ra, Rb, Rc; \
87
164k
  \
88
164k
  Rb = *prev_row++; \
89
164k
  Ra = (*diff_buf++ + PREDICTOR2) & 0xFFFF; \
90
164k
  *undiff_buf++ = Ra; \
91
164k
  \
92
12.2M
  while (--width) { \
93
12.1M
    Rc = Rb; \
94
12.1M
    Rb = *prev_row++; \
95
12.1M
    Ra = (*diff_buf++ + PREDICTOR) & 0xFFFF; \
96
12.1M
    *undiff_buf++ = Ra; \
97
12.1M
  }
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
8.87k
{
112
8.87k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
8.87k
}
jdlossls-8.c:jpeg_undifference1
Line
Count
Source
111
6.44k
{
112
6.44k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
6.44k
}
jdlossls-12.c:jpeg_undifference1
Line
Count
Source
111
1.40k
{
112
1.40k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
1.40k
}
jdlossls-16.c:jpeg_undifference1
Line
Count
Source
111
1.03k
{
112
1.03k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
1.03k
}
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
62.8k
{
120
62.8k
  UNDIFFERENCE_2D(PREDICTOR2);
121
62.8k
  (void)(Rc);
122
62.8k
}
jdlossls-8.c:jpeg_undifference2
Line
Count
Source
119
36.0k
{
120
36.0k
  UNDIFFERENCE_2D(PREDICTOR2);
121
36.0k
  (void)(Rc);
122
36.0k
}
jdlossls-12.c:jpeg_undifference2
Line
Count
Source
119
2.67k
{
120
2.67k
  UNDIFFERENCE_2D(PREDICTOR2);
121
2.67k
  (void)(Rc);
122
2.67k
}
jdlossls-16.c:jpeg_undifference2
Line
Count
Source
119
24.0k
{
120
24.0k
  UNDIFFERENCE_2D(PREDICTOR2);
121
24.0k
  (void)(Rc);
122
24.0k
}
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
8.30k
{
129
8.30k
  UNDIFFERENCE_2D(PREDICTOR3);
130
8.30k
}
jdlossls-8.c:jpeg_undifference3
Line
Count
Source
128
3.33k
{
129
3.33k
  UNDIFFERENCE_2D(PREDICTOR3);
130
3.33k
}
jdlossls-12.c:jpeg_undifference3
Line
Count
Source
128
1.88k
{
129
1.88k
  UNDIFFERENCE_2D(PREDICTOR3);
130
1.88k
}
jdlossls-16.c:jpeg_undifference3
Line
Count
Source
128
3.08k
{
129
3.08k
  UNDIFFERENCE_2D(PREDICTOR3);
130
3.08k
}
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
3.41k
{
137
3.41k
  UNDIFFERENCE_2D(PREDICTOR4);
138
3.41k
}
jdlossls-8.c:jpeg_undifference4
Line
Count
Source
136
1.99k
{
137
1.99k
  UNDIFFERENCE_2D(PREDICTOR4);
138
1.99k
}
jdlossls-12.c:jpeg_undifference4
Line
Count
Source
136
704
{
137
704
  UNDIFFERENCE_2D(PREDICTOR4);
138
704
}
jdlossls-16.c:jpeg_undifference4
Line
Count
Source
136
714
{
137
714
  UNDIFFERENCE_2D(PREDICTOR4);
138
714
}
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.30k
{
145
5.30k
  UNDIFFERENCE_2D(PREDICTOR5);
146
5.30k
}
jdlossls-8.c:jpeg_undifference5
Line
Count
Source
144
2.17k
{
145
2.17k
  UNDIFFERENCE_2D(PREDICTOR5);
146
2.17k
}
jdlossls-12.c:jpeg_undifference5
Line
Count
Source
144
1.51k
{
145
1.51k
  UNDIFFERENCE_2D(PREDICTOR5);
146
1.51k
}
jdlossls-16.c:jpeg_undifference5
Line
Count
Source
144
1.62k
{
145
1.62k
  UNDIFFERENCE_2D(PREDICTOR5);
146
1.62k
}
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
79.3k
{
153
79.3k
  UNDIFFERENCE_2D(PREDICTOR6);
154
79.3k
}
jdlossls-8.c:jpeg_undifference6
Line
Count
Source
152
2.39k
{
153
2.39k
  UNDIFFERENCE_2D(PREDICTOR6);
154
2.39k
}
jdlossls-12.c:jpeg_undifference6
Line
Count
Source
152
74.3k
{
153
74.3k
  UNDIFFERENCE_2D(PREDICTOR6);
154
74.3k
}
jdlossls-16.c:jpeg_undifference6
Line
Count
Source
152
2.60k
{
153
2.60k
  UNDIFFERENCE_2D(PREDICTOR6);
154
2.60k
}
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.12k
{
161
5.12k
  UNDIFFERENCE_2D(PREDICTOR7);
162
5.12k
  (void)(Rc);
163
5.12k
}
jdlossls-8.c:jpeg_undifference7
Line
Count
Source
160
3.03k
{
161
3.03k
  UNDIFFERENCE_2D(PREDICTOR7);
162
3.03k
  (void)(Rc);
163
3.03k
}
jdlossls-12.c:jpeg_undifference7
Line
Count
Source
160
904
{
161
904
  UNDIFFERENCE_2D(PREDICTOR7);
162
904
  (void)(Rc);
163
904
}
jdlossls-16.c:jpeg_undifference7
Line
Count
Source
160
1.18k
{
161
1.18k
  UNDIFFERENCE_2D(PREDICTOR7);
162
1.18k
  (void)(Rc);
163
1.18k
}
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
6.28k
{
178
6.28k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
6.28k
  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
6.28k
  switch (cinfo->Ss) {
188
627
  case 1:
189
627
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
627
    break;
191
2.18k
  case 2:
192
2.18k
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
2.18k
    break;
194
851
  case 3:
195
851
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
851
    break;
197
742
  case 4:
198
742
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
742
    break;
200
571
  case 5:
201
571
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
571
    break;
203
891
  case 6:
204
891
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
891
    break;
206
418
  case 7:
207
418
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
418
    break;
209
6.28k
  }
210
6.28k
}
jdlossls-8.c:jpeg_undifference_first_row
Line
Count
Source
177
2.34k
{
178
2.34k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
2.34k
  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.34k
  switch (cinfo->Ss) {
188
251
  case 1:
189
251
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
251
    break;
191
895
  case 2:
192
895
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
895
    break;
194
327
  case 3:
195
327
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
327
    break;
197
219
  case 4:
198
219
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
219
    break;
200
180
  case 5:
201
180
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
180
    break;
203
321
  case 6:
204
321
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
321
    break;
206
153
  case 7:
207
153
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
153
    break;
209
2.34k
  }
210
2.34k
}
jdlossls-12.c:jpeg_undifference_first_row
Line
Count
Source
177
1.73k
{
178
1.73k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
1.73k
  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.73k
  switch (cinfo->Ss) {
188
211
  case 1:
189
211
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
211
    break;
191
600
  case 2:
192
600
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
600
    break;
194
242
  case 3:
195
242
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
242
    break;
197
188
  case 4:
198
188
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
188
    break;
200
163
  case 5:
201
163
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
163
    break;
203
245
  case 6:
204
245
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
245
    break;
206
87
  case 7:
207
87
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
87
    break;
209
1.73k
  }
210
1.73k
}
jdlossls-16.c:jpeg_undifference_first_row
Line
Count
Source
177
2.20k
{
178
2.20k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
2.20k
  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.20k
  switch (cinfo->Ss) {
188
165
  case 1:
189
165
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
165
    break;
191
692
  case 2:
192
692
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
692
    break;
194
282
  case 3:
195
282
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
282
    break;
197
335
  case 4:
198
335
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
335
    break;
200
228
  case 5:
201
228
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
228
    break;
203
325
  case 6:
204
325
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
325
    break;
206
178
  case 7:
207
178
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
178
    break;
209
2.20k
  }
210
2.20k
}
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
15.7k
{
219
3.49M
  do {
220
3.49M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
3.49M
  } while (--width);
222
15.7k
}
jdlossls-8.c:simple_upscale
Line
Count
Source
218
6.89k
{
219
879k
  do {
220
879k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
879k
  } while (--width);
222
6.89k
}
jdlossls-12.c:simple_upscale
Line
Count
Source
218
4.12k
{
219
882k
  do {
220
882k
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
882k
  } while (--width);
222
4.12k
}
jdlossls-16.c:simple_upscale
Line
Count
Source
218
4.68k
{
219
1.73M
  do {
220
1.73M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
1.73M
  } while (--width);
222
4.68k
}
223
224
METHODDEF(void)
225
noscale(j_decompress_ptr cinfo,
226
        JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
227
163k
{
228
14.0M
  do {
229
14.0M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
14.0M
  } while (--width);
231
163k
}
jdlossls-8.c:noscale
Line
Count
Source
227
50.8k
{
228
5.55M
  do {
229
5.55M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
5.55M
  } while (--width);
231
50.8k
}
jdlossls-12.c:noscale
Line
Count
Source
227
81.0k
{
228
3.77M
  do {
229
3.77M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
3.77M
  } while (--width);
231
81.0k
}
jdlossls-16.c:noscale
Line
Count
Source
227
31.8k
{
228
4.75M
  do {
229
4.75M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
4.75M
  } while (--width);
231
31.8k
}
232
233
234
/*
235
 * Initialize for an input processing pass.
236
 */
237
238
METHODDEF(void)
239
start_pass_lossless(j_decompress_ptr cinfo)
240
6.29k
{
241
6.29k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
6.29k
  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
6.29k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
6.29k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
6.29k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
149
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
6.29k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
19.7k
  for (ci = 0; ci < cinfo->num_components; ci++)
262
13.4k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
6.29k
  if (cinfo->Al)
266
2.31k
    losslessd->scaler_scale = simple_upscale;
267
3.98k
  else
268
3.98k
    losslessd->scaler_scale = noscale;
269
6.29k
}
jdlossls-8.c:start_pass_lossless
Line
Count
Source
240
2.82k
{
241
2.82k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
2.82k
  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
2.82k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
2.82k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
2.82k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
60
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
2.82k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
8.01k
  for (ci = 0; ci < cinfo->num_components; ci++)
262
5.19k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
2.82k
  if (cinfo->Al)
266
1.06k
    losslessd->scaler_scale = simple_upscale;
267
1.75k
  else
268
1.75k
    losslessd->scaler_scale = noscale;
269
2.82k
}
jdlossls-12.c:start_pass_lossless
Line
Count
Source
240
1.54k
{
241
1.54k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
1.54k
  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.54k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
1.54k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
1.54k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
51
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
1.54k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
5.20k
  for (ci = 0; ci < cinfo->num_components; ci++)
262
3.66k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
1.54k
  if (cinfo->Al)
266
545
    losslessd->scaler_scale = simple_upscale;
267
997
  else
268
997
    losslessd->scaler_scale = noscale;
269
1.54k
}
jdlossls-16.c:start_pass_lossless
Line
Count
Source
240
1.93k
{
241
1.93k
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
1.93k
  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.93k
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
1.93k
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
1.93k
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
38
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
1.93k
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
6.48k
  for (ci = 0; ci < cinfo->num_components; ci++)
262
4.55k
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
1.93k
  if (cinfo->Al)
266
703
    losslessd->scaler_scale = simple_upscale;
267
1.22k
  else
268
1.22k
    losslessd->scaler_scale = noscale;
269
1.93k
}
270
271
272
/*
273
 * Initialize the lossless decompressor.
274
 */
275
276
GLOBAL(void)
277
_jinit_lossless_decompressor(j_decompress_ptr cinfo)
278
3.01k
{
279
3.01k
  lossless_decomp_ptr losslessd;
280
281
#if BITS_IN_JSAMPLE == 8
282
1.27k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
283
#else
284
1.73k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
1.73k
      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
3.01k
  losslessd = (lossless_decomp_ptr)
291
3.01k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
3.01k
                                sizeof(jpeg_lossless_decompressor));
293
3.01k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
3.01k
  losslessd->pub.start_pass = start_pass_lossless;
295
3.01k
}
jinit_lossless_decompressor
Line
Count
Source
278
1.27k
{
279
1.27k
  lossless_decomp_ptr losslessd;
280
281
1.27k
#if BITS_IN_JSAMPLE == 8
282
1.27k
  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.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
}
j12init_lossless_decompressor
Line
Count
Source
278
836
{
279
836
  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
836
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
836
      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
836
  losslessd = (lossless_decomp_ptr)
291
836
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
836
                                sizeof(jpeg_lossless_decompressor));
293
836
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
836
  losslessd->pub.start_pass = start_pass_lossless;
295
836
}
j16init_lossless_decompressor
Line
Count
Source
278
901
{
279
901
  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
901
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
901
      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
901
  losslessd = (lossless_decomp_ptr)
291
901
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
901
                                sizeof(jpeg_lossless_decompressor));
293
901
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
901
  losslessd->pub.start_pass = start_pass_lossless;
295
901
}
296
297
#endif /* D_LOSSLESS_SUPPORTED */