Coverage Report

Created: 2025-11-09 06:50

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
14.6M
  int Ra; \
60
14.6M
  \
61
14.6M
  Ra = (*diff_buf++ + INITIAL_PREDICTOR) & 0xFFFF; \
62
14.6M
  *undiff_buf++ = Ra; \
63
14.6M
  \
64
113M
  while (--width) { \
65
98.7M
    Ra = (*diff_buf++ + PREDICTOR1) & 0xFFFF; \
66
98.7M
    *undiff_buf++ = Ra; \
67
98.7M
  }
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
4.94M
  int Ra, Rb, Rc; \
87
4.94M
  \
88
4.94M
  Rb = *prev_row++; \
89
4.94M
  Ra = (*diff_buf++ + PREDICTOR2) & 0xFFFF; \
90
4.94M
  *undiff_buf++ = Ra; \
91
4.94M
  \
92
78.7M
  while (--width) { \
93
73.8M
    Rc = Rb; \
94
73.8M
    Rb = *prev_row++; \
95
73.8M
    Ra = (*diff_buf++ + PREDICTOR) & 0xFFFF; \
96
73.8M
    *undiff_buf++ = Ra; \
97
73.8M
  }
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
913k
{
112
913k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
913k
}
jdlossls-8.c:jpeg_undifference1
Line
Count
Source
111
381k
{
112
381k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
381k
}
jdlossls-12.c:jpeg_undifference1
Line
Count
Source
111
313k
{
112
313k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
313k
}
jdlossls-16.c:jpeg_undifference1
Line
Count
Source
111
219k
{
112
219k
  UNDIFFERENCE_1D(INITIAL_PREDICTOR2);
113
219k
}
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
584k
{
120
584k
  UNDIFFERENCE_2D(PREDICTOR2);
121
584k
  (void)(Rc);
122
584k
}
jdlossls-8.c:jpeg_undifference2
Line
Count
Source
119
193k
{
120
193k
  UNDIFFERENCE_2D(PREDICTOR2);
121
193k
  (void)(Rc);
122
193k
}
jdlossls-12.c:jpeg_undifference2
Line
Count
Source
119
95.8k
{
120
95.8k
  UNDIFFERENCE_2D(PREDICTOR2);
121
95.8k
  (void)(Rc);
122
95.8k
}
jdlossls-16.c:jpeg_undifference2
Line
Count
Source
119
294k
{
120
294k
  UNDIFFERENCE_2D(PREDICTOR2);
121
294k
  (void)(Rc);
122
294k
}
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
718k
{
129
718k
  UNDIFFERENCE_2D(PREDICTOR3);
130
718k
}
jdlossls-8.c:jpeg_undifference3
Line
Count
Source
128
337k
{
129
337k
  UNDIFFERENCE_2D(PREDICTOR3);
130
337k
}
jdlossls-12.c:jpeg_undifference3
Line
Count
Source
128
282k
{
129
282k
  UNDIFFERENCE_2D(PREDICTOR3);
130
282k
}
jdlossls-16.c:jpeg_undifference3
Line
Count
Source
128
98.6k
{
129
98.6k
  UNDIFFERENCE_2D(PREDICTOR3);
130
98.6k
}
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
2.21M
{
137
2.21M
  UNDIFFERENCE_2D(PREDICTOR4);
138
2.21M
}
jdlossls-8.c:jpeg_undifference4
Line
Count
Source
136
610k
{
137
610k
  UNDIFFERENCE_2D(PREDICTOR4);
138
610k
}
jdlossls-12.c:jpeg_undifference4
Line
Count
Source
136
873k
{
137
873k
  UNDIFFERENCE_2D(PREDICTOR4);
138
873k
}
jdlossls-16.c:jpeg_undifference4
Line
Count
Source
136
732k
{
137
732k
  UNDIFFERENCE_2D(PREDICTOR4);
138
732k
}
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
611k
{
145
611k
  UNDIFFERENCE_2D(PREDICTOR5);
146
611k
}
jdlossls-8.c:jpeg_undifference5
Line
Count
Source
144
261k
{
145
261k
  UNDIFFERENCE_2D(PREDICTOR5);
146
261k
}
jdlossls-12.c:jpeg_undifference5
Line
Count
Source
144
190k
{
145
190k
  UNDIFFERENCE_2D(PREDICTOR5);
146
190k
}
jdlossls-16.c:jpeg_undifference5
Line
Count
Source
144
159k
{
145
159k
  UNDIFFERENCE_2D(PREDICTOR5);
146
159k
}
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
195k
{
153
195k
  UNDIFFERENCE_2D(PREDICTOR6);
154
195k
}
jdlossls-8.c:jpeg_undifference6
Line
Count
Source
152
82.9k
{
153
82.9k
  UNDIFFERENCE_2D(PREDICTOR6);
154
82.9k
}
jdlossls-12.c:jpeg_undifference6
Line
Count
Source
152
50.5k
{
153
50.5k
  UNDIFFERENCE_2D(PREDICTOR6);
154
50.5k
}
jdlossls-16.c:jpeg_undifference6
Line
Count
Source
152
62.0k
{
153
62.0k
  UNDIFFERENCE_2D(PREDICTOR6);
154
62.0k
}
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
620k
{
161
620k
  UNDIFFERENCE_2D(PREDICTOR7);
162
620k
  (void)(Rc);
163
620k
}
jdlossls-8.c:jpeg_undifference7
Line
Count
Source
160
96.5k
{
161
96.5k
  UNDIFFERENCE_2D(PREDICTOR7);
162
96.5k
  (void)(Rc);
163
96.5k
}
jdlossls-12.c:jpeg_undifference7
Line
Count
Source
160
290k
{
161
290k
  UNDIFFERENCE_2D(PREDICTOR7);
162
290k
  (void)(Rc);
163
290k
}
jdlossls-16.c:jpeg_undifference7
Line
Count
Source
160
233k
{
161
233k
  UNDIFFERENCE_2D(PREDICTOR7);
162
233k
  (void)(Rc);
163
233k
}
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
13.7M
{
178
13.7M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
13.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
13.7M
  switch (cinfo->Ss) {
188
8.83M
  case 1:
189
8.83M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
8.83M
    break;
191
981k
  case 2:
192
981k
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
981k
    break;
194
853k
  case 3:
195
853k
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
853k
    break;
197
1.78M
  case 4:
198
1.78M
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
1.78M
    break;
200
519k
  case 5:
201
519k
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
519k
    break;
203
190k
  case 6:
204
190k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
190k
    break;
206
562k
  case 7:
207
562k
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
562k
    break;
209
13.7M
  }
210
13.7M
}
jdlossls-8.c:jpeg_undifference_first_row
Line
Count
Source
177
1.68M
{
178
1.68M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
1.68M
  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.68M
  switch (cinfo->Ss) {
188
338k
  case 1:
189
338k
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
338k
    break;
191
185k
  case 2:
192
185k
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
185k
    break;
194
343k
  case 3:
195
343k
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
343k
    break;
197
555k
  case 4:
198
555k
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
555k
    break;
200
139k
  case 5:
201
139k
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
139k
    break;
203
49.9k
  case 6:
204
49.9k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
49.9k
    break;
206
71.5k
  case 7:
207
71.5k
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
71.5k
    break;
209
1.68M
  }
210
1.68M
}
jdlossls-12.c:jpeg_undifference_first_row
Line
Count
Source
177
2.09M
{
178
2.09M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
2.09M
  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.09M
  switch (cinfo->Ss) {
188
365k
  case 1:
189
365k
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
365k
    break;
191
128k
  case 2:
192
128k
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
128k
    break;
194
310k
  case 3:
195
310k
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
310k
    break;
197
709k
  case 4:
198
709k
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
709k
    break;
200
274k
  case 5:
201
274k
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
274k
    break;
203
90.4k
  case 6:
204
90.4k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
90.4k
    break;
206
217k
  case 7:
207
217k
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
217k
    break;
209
2.09M
  }
210
2.09M
}
jdlossls-16.c:jpeg_undifference_first_row
Line
Count
Source
177
9.94M
{
178
9.94M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
179
180
9.94M
  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
9.94M
  switch (cinfo->Ss) {
188
8.13M
  case 1:
189
8.13M
    losslessd->predict_undifference[comp_index] = jpeg_undifference1;
190
8.13M
    break;
191
667k
  case 2:
192
667k
    losslessd->predict_undifference[comp_index] = jpeg_undifference2;
193
667k
    break;
194
199k
  case 3:
195
199k
    losslessd->predict_undifference[comp_index] = jpeg_undifference3;
196
199k
    break;
197
515k
  case 4:
198
515k
    losslessd->predict_undifference[comp_index] = jpeg_undifference4;
199
515k
    break;
200
105k
  case 5:
201
105k
    losslessd->predict_undifference[comp_index] = jpeg_undifference5;
202
105k
    break;
203
50.2k
  case 6:
204
50.2k
    losslessd->predict_undifference[comp_index] = jpeg_undifference6;
205
50.2k
    break;
206
273k
  case 7:
207
273k
    losslessd->predict_undifference[comp_index] = jpeg_undifference7;
208
273k
    break;
209
9.94M
  }
210
9.94M
}
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
14.2M
{
219
139M
  do {
220
139M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
139M
  } while (--width);
222
14.2M
}
jdlossls-8.c:simple_upscale
Line
Count
Source
218
2.01M
{
219
44.4M
  do {
220
44.4M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
44.4M
  } while (--width);
222
2.01M
}
jdlossls-12.c:simple_upscale
Line
Count
Source
218
2.43M
{
219
41.1M
  do {
220
41.1M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
41.1M
  } while (--width);
222
2.43M
}
jdlossls-16.c:simple_upscale
Line
Count
Source
218
9.77M
{
219
53.5M
  do {
220
53.5M
    *output_buf++ = (_JSAMPLE)(*diff_buf++ << cinfo->Al);
221
53.5M
  } while (--width);
222
9.77M
}
223
224
METHODDEF(void)
225
noscale(j_decompress_ptr cinfo,
226
        JDIFFROW diff_buf, _JSAMPROW output_buf, JDIMENSION width)
227
5.36M
{
228
52.9M
  do {
229
52.9M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
52.9M
  } while (--width);
231
5.36M
}
jdlossls-8.c:noscale
Line
Count
Source
227
1.63M
{
228
18.7M
  do {
229
18.7M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
18.7M
  } while (--width);
231
1.63M
}
jdlossls-12.c:noscale
Line
Count
Source
227
1.75M
{
228
18.3M
  do {
229
18.3M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
18.3M
  } while (--width);
231
1.75M
}
jdlossls-16.c:noscale
Line
Count
Source
227
1.97M
{
228
15.8M
  do {
229
15.8M
    *output_buf++ = (_JSAMPLE)(*diff_buf++);
230
15.8M
  } while (--width);
231
1.97M
}
232
233
234
/*
235
 * Initialize for an input processing pass.
236
 */
237
238
METHODDEF(void)
239
start_pass_lossless(j_decompress_ptr cinfo)
240
16.8M
{
241
16.8M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
16.8M
  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
16.8M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
16.8M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
16.8M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
102
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
16.8M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
67.2M
  for (ci = 0; ci < cinfo->num_components; ci++)
262
50.4M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
16.8M
  if (cinfo->Al)
266
12.8M
    losslessd->scaler_scale = simple_upscale;
267
3.97M
  else
268
3.97M
    losslessd->scaler_scale = noscale;
269
16.8M
}
jdlossls-8.c:start_pass_lossless
Line
Count
Source
240
2.85M
{
241
2.85M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
2.85M
  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.85M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
2.85M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
2.85M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
29
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
2.85M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
11.4M
  for (ci = 0; ci < cinfo->num_components; ci++)
262
8.55M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
2.85M
  if (cinfo->Al)
266
1.50M
    losslessd->scaler_scale = simple_upscale;
267
1.34M
  else
268
1.34M
    losslessd->scaler_scale = noscale;
269
2.85M
}
jdlossls-12.c:start_pass_lossless
Line
Count
Source
240
3.20M
{
241
3.20M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
3.20M
  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
3.20M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
3.20M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
3.20M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
31
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
3.20M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
12.8M
  for (ci = 0; ci < cinfo->num_components; ci++)
262
9.60M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
3.20M
  if (cinfo->Al)
266
1.92M
    losslessd->scaler_scale = simple_upscale;
267
1.27M
  else
268
1.27M
    losslessd->scaler_scale = noscale;
269
3.20M
}
jdlossls-16.c:start_pass_lossless
Line
Count
Source
240
10.7M
{
241
10.7M
  lossless_decomp_ptr losslessd = (lossless_decomp_ptr)cinfo->idct;
242
10.7M
  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
10.7M
  if (cinfo->Ss < 1 || cinfo->Ss > 7 ||
255
10.7M
      cinfo->Se != 0 || cinfo->Ah != 0 ||
256
10.7M
      cinfo->Al < 0 || cinfo->Al >= cinfo->data_precision)
257
42
    ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
258
10.7M
             cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
259
260
  /* Set undifference functions to first row function */
261
43.0M
  for (ci = 0; ci < cinfo->num_components; ci++)
262
32.2M
    losslessd->predict_undifference[ci] = jpeg_undifference_first_row;
263
264
  /* Set scaler function based on Pt */
265
10.7M
  if (cinfo->Al)
266
9.41M
    losslessd->scaler_scale = simple_upscale;
267
1.34M
  else
268
1.34M
    losslessd->scaler_scale = noscale;
269
10.7M
}
270
271
272
/*
273
 * Initialize the lossless decompressor.
274
 */
275
276
GLOBAL(void)
277
_jinit_lossless_decompressor(j_decompress_ptr cinfo)
278
1.35k
{
279
1.35k
  lossless_decomp_ptr losslessd;
280
281
#if BITS_IN_JSAMPLE == 8
282
430
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
283
#else
284
928
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
928
      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.35k
  losslessd = (lossless_decomp_ptr)
291
1.35k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
1.35k
                                sizeof(jpeg_lossless_decompressor));
293
1.35k
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
1.35k
  losslessd->pub.start_pass = start_pass_lossless;
295
1.35k
}
jinit_lossless_decompressor
Line
Count
Source
278
430
{
279
430
  lossless_decomp_ptr losslessd;
280
281
430
#if BITS_IN_JSAMPLE == 8
282
430
  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
430
  losslessd = (lossless_decomp_ptr)
291
430
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
430
                                sizeof(jpeg_lossless_decompressor));
293
430
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
430
  losslessd->pub.start_pass = start_pass_lossless;
295
430
}
j12init_lossless_decompressor
Line
Count
Source
278
444
{
279
444
  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
444
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
444
      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
444
  losslessd = (lossless_decomp_ptr)
291
444
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
444
                                sizeof(jpeg_lossless_decompressor));
293
444
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
444
  losslessd->pub.start_pass = start_pass_lossless;
295
444
}
j16init_lossless_decompressor
Line
Count
Source
278
484
{
279
484
  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
484
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
285
484
      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
484
  losslessd = (lossless_decomp_ptr)
291
484
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
292
484
                                sizeof(jpeg_lossless_decompressor));
293
484
  cinfo->idct = (struct jpeg_inverse_dct *)losslessd;
294
484
  losslessd->pub.start_pass = start_pass_lossless;
295
484
}
296
297
#endif /* D_LOSSLESS_SUPPORTED */