Coverage Report

Created: 2026-01-25 06:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/src/jclossls.c
Line
Count
Source
1
/*
2
 * jclossls.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 differencing, and point transform
14
 * routines for the lossless JPEG compressor.
15
 */
16
17
#define JPEG_INTERNALS
18
#include "jinclude.h"
19
#include "jpeglib.h"
20
#include "jlossls.h"
21
22
#ifdef C_LOSSLESS_SUPPORTED
23
24
25
/************************** Sample differencing **************************/
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 differencing
31
 * functions for each predictor selection value.
32
 *
33
 * We are able to avoid duplicating source code by implementing the predictors
34
 * and differencers as macros.  Each of the differencing functions is simply a
35
 * wrapper around a DIFFERENCE macro with the appropriate PREDICTOR macro
36
 * passed as an argument.
37
 */
38
39
/* Forward declarations */
40
LOCAL(void) reset_predictor(j_compress_ptr cinfo, int ci);
41
42
43
/* Predictor for the first column of the first row: 2^(P-Pt-1) */
44
#define INITIAL_PREDICTORx  (1 << (cinfo->data_precision - cinfo->Al - 1))
45
46
/* Predictor for the first column of the remaining rows: Rb */
47
#define INITIAL_PREDICTOR2  prev_row[0]
48
49
50
/*
51
 * 1-Dimensional differencer routine.
52
 *
53
 * This macro implements the 1-D horizontal predictor (1).  INITIAL_PREDICTOR
54
 * is used as the special case predictor for the first column, which must be
55
 * either INITIAL_PREDICTOR2 or INITIAL_PREDICTORx.  The remaining samples
56
 * use PREDICTOR1.
57
 */
58
59
#define DIFFERENCE_1D(INITIAL_PREDICTOR) \
60
165M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct; \
61
165M
  boolean restart = FALSE; \
62
165M
  int samp, Ra; \
63
165M
  \
64
165M
  samp = *input_buf++; \
65
165M
  *diff_buf++ = samp - INITIAL_PREDICTOR; \
66
165M
  \
67
1.29G
  while (--width) { \
68
1.13G
    Ra = samp; \
69
1.13G
    samp = *input_buf++; \
70
1.13G
    *diff_buf++ = samp - PREDICTOR1; \
71
1.13G
  } \
72
165M
  \
73
165M
  /* Account for restart interval (no-op if not using restarts) */ \
74
165M
  if (cinfo->restart_interval) { \
75
165M
    if (--(losslessc->restart_rows_to_go[ci]) == 0) { \
76
165M
      reset_predictor(cinfo, ci); \
77
165M
      restart = TRUE; \
78
165M
    } \
79
165M
  }
80
81
82
/*
83
 * 2-Dimensional differencer routine.
84
 *
85
 * This macro implements the 2-D horizontal predictors (#2-7).  PREDICTOR2 is
86
 * used as the special case predictor for the first column.  The remaining
87
 * samples use PREDICTOR, which is a function of Ra, Rb, and Rc.
88
 *
89
 * Because prev_row and output_buf may point to the same storage area (in an
90
 * interleaved image with Vi=1, for example), we must take care to buffer Rb/Rc
91
 * before writing the current reconstructed sample value into output_buf.
92
 */
93
94
#define DIFFERENCE_2D(PREDICTOR) \
95
304M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct; \
96
304M
  int samp, Ra, Rb, Rc; \
97
304M
  \
98
304M
  Rb = *prev_row++; \
99
304M
  samp = *input_buf++; \
100
304M
  *diff_buf++ = samp - PREDICTOR2; \
101
304M
  \
102
1.30G
  while (--width) { \
103
999M
    Rc = Rb; \
104
999M
    Rb = *prev_row++; \
105
999M
    Ra = samp; \
106
999M
    samp = *input_buf++; \
107
999M
    *diff_buf++ = samp - PREDICTOR; \
108
999M
  } \
109
304M
  \
110
304M
  /* Account for restart interval (no-op if not using restarts) */ \
111
304M
  if (cinfo->restart_interval) { \
112
0
    if (--losslessc->restart_rows_to_go[ci] == 0) \
113
0
      reset_predictor(cinfo, ci); \
114
0
  }
115
116
117
/*
118
 * Differencers for the second and subsequent rows in a scan or restart
119
 * interval.  The first sample in the row is differenced using the vertical
120
 * predictor (2).  The rest of the samples are differenced using the predictor
121
 * specified in the scan header.
122
 */
123
124
METHODDEF(void)
125
jpeg_difference1(j_compress_ptr cinfo, int ci,
126
                 _JSAMPROW input_buf, _JSAMPROW prev_row,
127
                 JDIFFROW diff_buf, JDIMENSION width)
128
0
{
129
0
  DIFFERENCE_1D(INITIAL_PREDICTOR2);
130
0
  (void)(restart);
131
0
}
Unexecuted instantiation: jclossls-8.c:jpeg_difference1
Unexecuted instantiation: jclossls-12.c:jpeg_difference1
Unexecuted instantiation: jclossls-16.c:jpeg_difference1
132
133
METHODDEF(void)
134
jpeg_difference2(j_compress_ptr cinfo, int ci,
135
                 _JSAMPROW input_buf, _JSAMPROW prev_row,
136
                 JDIFFROW diff_buf, JDIMENSION width)
137
70.9M
{
138
70.9M
  DIFFERENCE_2D(PREDICTOR2);
139
70.9M
  (void)(Ra);
140
70.9M
  (void)(Rc);
141
70.9M
}
jclossls-8.c:jpeg_difference2
Line
Count
Source
137
27.0M
{
138
27.0M
  DIFFERENCE_2D(PREDICTOR2);
139
27.0M
  (void)(Ra);
140
27.0M
  (void)(Rc);
141
27.0M
}
jclossls-12.c:jpeg_difference2
Line
Count
Source
137
19.1M
{
138
19.1M
  DIFFERENCE_2D(PREDICTOR2);
139
19.1M
  (void)(Ra);
140
19.1M
  (void)(Rc);
141
19.1M
}
jclossls-16.c:jpeg_difference2
Line
Count
Source
137
24.7M
{
138
24.7M
  DIFFERENCE_2D(PREDICTOR2);
139
24.7M
  (void)(Ra);
140
24.7M
  (void)(Rc);
141
24.7M
}
142
143
METHODDEF(void)
144
jpeg_difference3(j_compress_ptr cinfo, int ci,
145
                 _JSAMPROW input_buf, _JSAMPROW prev_row,
146
                 JDIFFROW diff_buf, JDIMENSION width)
147
70.9M
{
148
70.9M
  DIFFERENCE_2D(PREDICTOR3);
149
70.9M
  (void)(Ra);
150
70.9M
}
jclossls-8.c:jpeg_difference3
Line
Count
Source
147
26.9M
{
148
26.9M
  DIFFERENCE_2D(PREDICTOR3);
149
26.9M
  (void)(Ra);
150
26.9M
}
jclossls-12.c:jpeg_difference3
Line
Count
Source
147
19.1M
{
148
19.1M
  DIFFERENCE_2D(PREDICTOR3);
149
19.1M
  (void)(Ra);
150
19.1M
}
jclossls-16.c:jpeg_difference3
Line
Count
Source
147
24.7M
{
148
24.7M
  DIFFERENCE_2D(PREDICTOR3);
149
24.7M
  (void)(Ra);
150
24.7M
}
151
152
METHODDEF(void)
153
jpeg_difference4(j_compress_ptr cinfo, int ci,
154
                 _JSAMPROW input_buf, _JSAMPROW prev_row,
155
                 JDIFFROW diff_buf, JDIMENSION width)
156
70.9M
{
157
70.9M
  DIFFERENCE_2D(PREDICTOR4);
158
70.9M
}
jclossls-8.c:jpeg_difference4
Line
Count
Source
156
26.9M
{
157
26.9M
  DIFFERENCE_2D(PREDICTOR4);
158
26.9M
}
jclossls-12.c:jpeg_difference4
Line
Count
Source
156
19.1M
{
157
19.1M
  DIFFERENCE_2D(PREDICTOR4);
158
19.1M
}
jclossls-16.c:jpeg_difference4
Line
Count
Source
156
24.7M
{
157
24.7M
  DIFFERENCE_2D(PREDICTOR4);
158
24.7M
}
159
160
METHODDEF(void)
161
jpeg_difference5(j_compress_ptr cinfo, int ci,
162
                 _JSAMPROW input_buf, _JSAMPROW prev_row,
163
                 JDIFFROW diff_buf, JDIMENSION width)
164
70.9M
{
165
70.9M
  DIFFERENCE_2D(PREDICTOR5);
166
70.9M
}
jclossls-8.c:jpeg_difference5
Line
Count
Source
164
26.9M
{
165
26.9M
  DIFFERENCE_2D(PREDICTOR5);
166
26.9M
}
jclossls-12.c:jpeg_difference5
Line
Count
Source
164
19.1M
{
165
19.1M
  DIFFERENCE_2D(PREDICTOR5);
166
19.1M
}
jclossls-16.c:jpeg_difference5
Line
Count
Source
164
24.7M
{
165
24.7M
  DIFFERENCE_2D(PREDICTOR5);
166
24.7M
}
167
168
METHODDEF(void)
169
jpeg_difference6(j_compress_ptr cinfo, int ci,
170
                 _JSAMPROW input_buf, _JSAMPROW prev_row,
171
                 JDIFFROW diff_buf, JDIMENSION width)
172
21.1M
{
173
21.1M
  DIFFERENCE_2D(PREDICTOR6);
174
21.1M
}
jclossls-8.c:jpeg_difference6
Line
Count
Source
172
6.68M
{
173
6.68M
  DIFFERENCE_2D(PREDICTOR6);
174
6.68M
}
jclossls-12.c:jpeg_difference6
Line
Count
Source
172
6.19M
{
173
6.19M
  DIFFERENCE_2D(PREDICTOR6);
174
6.19M
}
jclossls-16.c:jpeg_difference6
Line
Count
Source
172
8.23M
{
173
8.23M
  DIFFERENCE_2D(PREDICTOR6);
174
8.23M
}
175
176
METHODDEF(void)
177
jpeg_difference7(j_compress_ptr cinfo, int ci,
178
                 _JSAMPROW input_buf, _JSAMPROW prev_row,
179
                 JDIFFROW diff_buf, JDIMENSION width)
180
0
{
181
0
  DIFFERENCE_2D(PREDICTOR7);
182
0
  (void)(Rc);
183
0
}
Unexecuted instantiation: jclossls-8.c:jpeg_difference7
Unexecuted instantiation: jclossls-12.c:jpeg_difference7
Unexecuted instantiation: jclossls-16.c:jpeg_difference7
184
185
186
/*
187
 * Differencer for the first row in a scan or restart interval.  The first
188
 * sample in the row is differenced using the special predictor constant
189
 * x = 2 ^ (P-Pt-1).  The rest of the samples are differenced using the
190
 * 1-D horizontal predictor (1).
191
 */
192
193
METHODDEF(void)
194
jpeg_difference_first_row(j_compress_ptr cinfo, int ci,
195
                          _JSAMPROW input_buf, _JSAMPROW prev_row,
196
                          JDIFFROW diff_buf, JDIMENSION width)
197
165M
{
198
165M
  DIFFERENCE_1D(INITIAL_PREDICTORx);
199
200
  /*
201
   * Now that we have differenced the first row, we want to use the
202
   * differencer that corresponds to the predictor specified in the
203
   * scan header.
204
   *
205
   * Note that we don't do this if we have just reset the predictor
206
   * for a new restart interval.
207
   */
208
165M
  if (!restart) {
209
122k
    switch (cinfo->Ss) {
210
0
    case 1:
211
0
      losslessc->predict_difference[ci] = jpeg_difference1;
212
0
      break;
213
28.8k
    case 2:
214
28.8k
      losslessc->predict_difference[ci] = jpeg_difference2;
215
28.8k
      break;
216
27.5k
    case 3:
217
27.5k
      losslessc->predict_difference[ci] = jpeg_difference3;
218
27.5k
      break;
219
27.5k
    case 4:
220
27.5k
      losslessc->predict_difference[ci] = jpeg_difference4;
221
27.5k
      break;
222
27.5k
    case 5:
223
27.5k
      losslessc->predict_difference[ci] = jpeg_difference5;
224
27.5k
      break;
225
10.5k
    case 6:
226
10.5k
      losslessc->predict_difference[ci] = jpeg_difference6;
227
10.5k
      break;
228
0
    case 7:
229
0
      losslessc->predict_difference[ci] = jpeg_difference7;
230
0
      break;
231
122k
    }
232
122k
  }
233
165M
}
jclossls-8.c:jpeg_difference_first_row
Line
Count
Source
197
63.0M
{
198
63.0M
  DIFFERENCE_1D(INITIAL_PREDICTORx);
199
200
  /*
201
   * Now that we have differenced the first row, we want to use the
202
   * differencer that corresponds to the predictor specified in the
203
   * scan header.
204
   *
205
   * Note that we don't do this if we have just reset the predictor
206
   * for a new restart interval.
207
   */
208
63.0M
  if (!restart) {
209
46.2k
    switch (cinfo->Ss) {
210
0
    case 1:
211
0
      losslessc->predict_difference[ci] = jpeg_difference1;
212
0
      break;
213
11.0k
    case 2:
214
11.0k
      losslessc->predict_difference[ci] = jpeg_difference2;
215
11.0k
      break;
216
10.3k
    case 3:
217
10.3k
      losslessc->predict_difference[ci] = jpeg_difference3;
218
10.3k
      break;
219
10.3k
    case 4:
220
10.3k
      losslessc->predict_difference[ci] = jpeg_difference4;
221
10.3k
      break;
222
10.3k
    case 5:
223
10.3k
      losslessc->predict_difference[ci] = jpeg_difference5;
224
10.3k
      break;
225
4.24k
    case 6:
226
4.24k
      losslessc->predict_difference[ci] = jpeg_difference6;
227
4.24k
      break;
228
0
    case 7:
229
0
      losslessc->predict_difference[ci] = jpeg_difference7;
230
0
      break;
231
46.2k
    }
232
46.2k
  }
233
63.0M
}
jclossls-12.c:jpeg_difference_first_row
Line
Count
Source
197
44.6M
{
198
44.6M
  DIFFERENCE_1D(INITIAL_PREDICTORx);
199
200
  /*
201
   * Now that we have differenced the first row, we want to use the
202
   * differencer that corresponds to the predictor specified in the
203
   * scan header.
204
   *
205
   * Note that we don't do this if we have just reset the predictor
206
   * for a new restart interval.
207
   */
208
44.6M
  if (!restart) {
209
36.2k
    switch (cinfo->Ss) {
210
0
    case 1:
211
0
      losslessc->predict_difference[ci] = jpeg_difference1;
212
0
      break;
213
8.56k
    case 2:
214
8.56k
      losslessc->predict_difference[ci] = jpeg_difference2;
215
8.56k
      break;
216
8.21k
    case 3:
217
8.21k
      losslessc->predict_difference[ci] = jpeg_difference3;
218
8.21k
      break;
219
8.21k
    case 4:
220
8.21k
      losslessc->predict_difference[ci] = jpeg_difference4;
221
8.21k
      break;
222
8.21k
    case 5:
223
8.21k
      losslessc->predict_difference[ci] = jpeg_difference5;
224
8.21k
      break;
225
3.04k
    case 6:
226
3.04k
      losslessc->predict_difference[ci] = jpeg_difference6;
227
3.04k
      break;
228
0
    case 7:
229
0
      losslessc->predict_difference[ci] = jpeg_difference7;
230
0
      break;
231
36.2k
    }
232
36.2k
  }
233
44.6M
}
jclossls-16.c:jpeg_difference_first_row
Line
Count
Source
197
57.9M
{
198
57.9M
  DIFFERENCE_1D(INITIAL_PREDICTORx);
199
200
  /*
201
   * Now that we have differenced the first row, we want to use the
202
   * differencer that corresponds to the predictor specified in the
203
   * scan header.
204
   *
205
   * Note that we don't do this if we have just reset the predictor
206
   * for a new restart interval.
207
   */
208
57.9M
  if (!restart) {
209
39.5k
    switch (cinfo->Ss) {
210
0
    case 1:
211
0
      losslessc->predict_difference[ci] = jpeg_difference1;
212
0
      break;
213
9.28k
    case 2:
214
9.28k
      losslessc->predict_difference[ci] = jpeg_difference2;
215
9.28k
      break;
216
8.98k
    case 3:
217
8.98k
      losslessc->predict_difference[ci] = jpeg_difference3;
218
8.98k
      break;
219
8.98k
    case 4:
220
8.98k
      losslessc->predict_difference[ci] = jpeg_difference4;
221
8.98k
      break;
222
8.98k
    case 5:
223
8.98k
      losslessc->predict_difference[ci] = jpeg_difference5;
224
8.98k
      break;
225
3.30k
    case 6:
226
3.30k
      losslessc->predict_difference[ci] = jpeg_difference6;
227
3.30k
      break;
228
0
    case 7:
229
0
      losslessc->predict_difference[ci] = jpeg_difference7;
230
0
      break;
231
39.5k
    }
232
39.5k
  }
233
57.9M
}
234
235
/*
236
 * Reset predictor at the start of a pass or restart interval.
237
 */
238
239
LOCAL(void)
240
reset_predictor(j_compress_ptr cinfo, int ci)
241
165M
{
242
165M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
243
244
  /* Initialize restart counter */
245
165M
  losslessc->restart_rows_to_go[ci] =
246
165M
    cinfo->restart_interval / cinfo->MCUs_per_row;
247
248
  /* Set difference function to first row function */
249
165M
  losslessc->predict_difference[ci] = jpeg_difference_first_row;
250
165M
}
jclossls-8.c:reset_predictor
Line
Count
Source
241
63.0M
{
242
63.0M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
243
244
  /* Initialize restart counter */
245
63.0M
  losslessc->restart_rows_to_go[ci] =
246
63.0M
    cinfo->restart_interval / cinfo->MCUs_per_row;
247
248
  /* Set difference function to first row function */
249
63.0M
  losslessc->predict_difference[ci] = jpeg_difference_first_row;
250
63.0M
}
jclossls-12.c:reset_predictor
Line
Count
Source
241
44.6M
{
242
44.6M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
243
244
  /* Initialize restart counter */
245
44.6M
  losslessc->restart_rows_to_go[ci] =
246
44.6M
    cinfo->restart_interval / cinfo->MCUs_per_row;
247
248
  /* Set difference function to first row function */
249
44.6M
  losslessc->predict_difference[ci] = jpeg_difference_first_row;
250
44.6M
}
jclossls-16.c:reset_predictor
Line
Count
Source
241
57.9M
{
242
57.9M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
243
244
  /* Initialize restart counter */
245
57.9M
  losslessc->restart_rows_to_go[ci] =
246
57.9M
    cinfo->restart_interval / cinfo->MCUs_per_row;
247
248
  /* Set difference function to first row function */
249
57.9M
  losslessc->predict_difference[ci] = jpeg_difference_first_row;
250
57.9M
}
251
252
253
/********************** Sample downscaling by 2^Pt ***********************/
254
255
METHODDEF(void)
256
simple_downscale(j_compress_ptr cinfo,
257
                 _JSAMPROW input_buf, _JSAMPROW output_buf, JDIMENSION width)
258
304M
{
259
1.68G
  do {
260
1.68G
    *output_buf++ = (_JSAMPLE)RIGHT_SHIFT(*input_buf++, cinfo->Al);
261
1.68G
  } while (--width);
262
304M
}
jclossls-8.c:simple_downscale
Line
Count
Source
258
114M
{
259
720M
  do {
260
720M
    *output_buf++ = (_JSAMPLE)RIGHT_SHIFT(*input_buf++, cinfo->Al);
261
720M
  } while (--width);
262
114M
}
jclossls-12.c:simple_downscale
Line
Count
Source
258
82.7M
{
259
388M
  do {
260
388M
    *output_buf++ = (_JSAMPLE)RIGHT_SHIFT(*input_buf++, cinfo->Al);
261
388M
  } while (--width);
262
82.7M
}
jclossls-16.c:simple_downscale
Line
Count
Source
258
107M
{
259
574M
  do {
260
574M
    *output_buf++ = (_JSAMPLE)RIGHT_SHIFT(*input_buf++, cinfo->Al);
261
574M
  } while (--width);
262
107M
}
263
264
265
METHODDEF(void)
266
noscale(j_compress_ptr cinfo,
267
        _JSAMPROW input_buf, _JSAMPROW output_buf, JDIMENSION width)
268
165M
{
269
165M
  memcpy(output_buf, input_buf, width * sizeof(_JSAMPLE));
270
165M
}
jclossls-8.c:noscale
Line
Count
Source
268
63.0M
{
269
63.0M
  memcpy(output_buf, input_buf, width * sizeof(_JSAMPLE));
270
63.0M
}
jclossls-12.c:noscale
Line
Count
Source
268
44.6M
{
269
44.6M
  memcpy(output_buf, input_buf, width * sizeof(_JSAMPLE));
270
44.6M
}
jclossls-16.c:noscale
Line
Count
Source
268
57.8M
{
269
57.8M
  memcpy(output_buf, input_buf, width * sizeof(_JSAMPLE));
270
57.8M
}
271
272
273
/*
274
 * Initialize for a processing pass.
275
 */
276
277
METHODDEF(void)
278
start_pass_lossless(j_compress_ptr cinfo)
279
66.5k
{
280
66.5k
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
281
66.5k
  int ci;
282
283
  /* Set scaler function based on Pt */
284
66.5k
  if (cinfo->Al)
285
47.7k
    losslessc->scaler_scale = simple_downscale;
286
18.7k
  else
287
18.7k
    losslessc->scaler_scale = noscale;
288
289
  /* Check that the restart interval is an integer multiple of the number
290
   * of MCUs in an MCU row.
291
   */
292
66.5k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
293
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
294
66.5k
             cinfo->restart_interval, cinfo->MCUs_per_row);
295
296
  /* Set predictors for start of pass */
297
254k
  for (ci = 0; ci < cinfo->num_components; ci++)
298
187k
    reset_predictor(cinfo, ci);
299
66.5k
}
jclossls-8.c:start_pass_lossless
Line
Count
Source
279
25.3k
{
280
25.3k
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
281
25.3k
  int ci;
282
283
  /* Set scaler function based on Pt */
284
25.3k
  if (cinfo->Al)
285
18.2k
    losslessc->scaler_scale = simple_downscale;
286
7.11k
  else
287
7.11k
    losslessc->scaler_scale = noscale;
288
289
  /* Check that the restart interval is an integer multiple of the number
290
   * of MCUs in an MCU row.
291
   */
292
25.3k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
293
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
294
25.3k
             cinfo->restart_interval, cinfo->MCUs_per_row);
295
296
  /* Set predictors for start of pass */
297
96.4k
  for (ci = 0; ci < cinfo->num_components; ci++)
298
71.0k
    reset_predictor(cinfo, ci);
299
25.3k
}
jclossls-12.c:start_pass_lossless
Line
Count
Source
279
19.7k
{
280
19.7k
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
281
19.7k
  int ci;
282
283
  /* Set scaler function based on Pt */
284
19.7k
  if (cinfo->Al)
285
14.1k
    losslessc->scaler_scale = simple_downscale;
286
5.59k
  else
287
5.59k
    losslessc->scaler_scale = noscale;
288
289
  /* Check that the restart interval is an integer multiple of the number
290
   * of MCUs in an MCU row.
291
   */
292
19.7k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
293
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
294
19.7k
             cinfo->restart_interval, cinfo->MCUs_per_row);
295
296
  /* Set predictors for start of pass */
297
75.4k
  for (ci = 0; ci < cinfo->num_components; ci++)
298
55.7k
    reset_predictor(cinfo, ci);
299
19.7k
}
jclossls-16.c:start_pass_lossless
Line
Count
Source
279
21.4k
{
280
21.4k
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
281
21.4k
  int ci;
282
283
  /* Set scaler function based on Pt */
284
21.4k
  if (cinfo->Al)
285
15.3k
    losslessc->scaler_scale = simple_downscale;
286
6.09k
  else
287
6.09k
    losslessc->scaler_scale = noscale;
288
289
  /* Check that the restart interval is an integer multiple of the number
290
   * of MCUs in an MCU row.
291
   */
292
21.4k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
293
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
294
21.4k
             cinfo->restart_interval, cinfo->MCUs_per_row);
295
296
  /* Set predictors for start of pass */
297
82.3k
  for (ci = 0; ci < cinfo->num_components; ci++)
298
60.8k
    reset_predictor(cinfo, ci);
299
21.4k
}
300
301
302
/*
303
 * Initialize the lossless compressor.
304
 */
305
306
GLOBAL(void)
307
_jinit_lossless_compressor(j_compress_ptr cinfo)
308
33.2k
{
309
33.2k
  lossless_comp_ptr losslessc;
310
311
#if BITS_IN_JSAMPLE == 8
312
12.6k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
313
#else
314
20.5k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
315
20.5k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
316
0
#endif
317
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
318
319
  /* Create subobject in permanent pool */
320
33.2k
  losslessc = (lossless_comp_ptr)
321
33.2k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
322
33.2k
                                sizeof(jpeg_lossless_compressor));
323
33.2k
  cinfo->fdct = (struct jpeg_forward_dct *)losslessc;
324
33.2k
  losslessc->pub.start_pass = start_pass_lossless;
325
33.2k
}
jinit_lossless_compressor
Line
Count
Source
308
12.6k
{
309
12.6k
  lossless_comp_ptr losslessc;
310
311
12.6k
#if BITS_IN_JSAMPLE == 8
312
12.6k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
313
#else
314
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
315
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
316
#endif
317
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
318
319
  /* Create subobject in permanent pool */
320
12.6k
  losslessc = (lossless_comp_ptr)
321
12.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
322
12.6k
                                sizeof(jpeg_lossless_compressor));
323
12.6k
  cinfo->fdct = (struct jpeg_forward_dct *)losslessc;
324
12.6k
  losslessc->pub.start_pass = start_pass_lossless;
325
12.6k
}
j12init_lossless_compressor
Line
Count
Source
308
9.85k
{
309
9.85k
  lossless_comp_ptr losslessc;
310
311
#if BITS_IN_JSAMPLE == 8
312
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
313
#else
314
9.85k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
315
9.85k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
316
0
#endif
317
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
318
319
  /* Create subobject in permanent pool */
320
9.85k
  losslessc = (lossless_comp_ptr)
321
9.85k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
322
9.85k
                                sizeof(jpeg_lossless_compressor));
323
9.85k
  cinfo->fdct = (struct jpeg_forward_dct *)losslessc;
324
9.85k
  losslessc->pub.start_pass = start_pass_lossless;
325
9.85k
}
j16init_lossless_compressor
Line
Count
Source
308
10.7k
{
309
10.7k
  lossless_comp_ptr losslessc;
310
311
#if BITS_IN_JSAMPLE == 8
312
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
313
#else
314
10.7k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
315
10.7k
      cinfo->data_precision < BITS_IN_JSAMPLE - 3)
316
0
#endif
317
0
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
318
319
  /* Create subobject in permanent pool */
320
10.7k
  losslessc = (lossless_comp_ptr)
321
10.7k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
322
10.7k
                                sizeof(jpeg_lossless_compressor));
323
10.7k
  cinfo->fdct = (struct jpeg_forward_dct *)losslessc;
324
10.7k
  losslessc->pub.start_pass = start_pass_lossless;
325
10.7k
}
326
327
#endif /* C_LOSSLESS_SUPPORTED */