Coverage Report

Created: 2025-10-13 06:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.dev/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
175M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct; \
61
175M
  boolean restart = FALSE; \
62
175M
  int samp, Ra; \
63
175M
  \
64
175M
  samp = *input_buf++; \
65
175M
  *diff_buf++ = samp - INITIAL_PREDICTOR; \
66
175M
  \
67
1.14G
  while (--width) { \
68
972M
    Ra = samp; \
69
972M
    samp = *input_buf++; \
70
972M
    *diff_buf++ = samp - PREDICTOR1; \
71
972M
  } \
72
175M
  \
73
175M
  /* Account for restart interval (no-op if not using restarts) */ \
74
175M
  if (cinfo->restart_interval) { \
75
175M
    if (--(losslessc->restart_rows_to_go[ci]) == 0) { \
76
175M
      reset_predictor(cinfo, ci); \
77
175M
      restart = TRUE; \
78
175M
    } \
79
175M
  }
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
323M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct; \
96
323M
  int samp, Ra, Rb, Rc; \
97
323M
  \
98
323M
  Rb = *prev_row++; \
99
323M
  samp = *input_buf++; \
100
323M
  *diff_buf++ = samp - PREDICTOR2; \
101
323M
  \
102
1.12G
  while (--width) { \
103
798M
    Rc = Rb; \
104
798M
    Rb = *prev_row++; \
105
798M
    Ra = samp; \
106
798M
    samp = *input_buf++; \
107
798M
    *diff_buf++ = samp - PREDICTOR; \
108
798M
  } \
109
323M
  \
110
323M
  /* Account for restart interval (no-op if not using restarts) */ \
111
323M
  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
75.1M
{
138
75.1M
  DIFFERENCE_2D(PREDICTOR2);
139
75.1M
  (void)(Ra);
140
75.1M
  (void)(Rc);
141
75.1M
}
jclossls-8.c:jpeg_difference2
Line
Count
Source
137
24.0M
{
138
24.0M
  DIFFERENCE_2D(PREDICTOR2);
139
24.0M
  (void)(Ra);
140
24.0M
  (void)(Rc);
141
24.0M
}
jclossls-12.c:jpeg_difference2
Line
Count
Source
137
25.9M
{
138
25.9M
  DIFFERENCE_2D(PREDICTOR2);
139
25.9M
  (void)(Ra);
140
25.9M
  (void)(Rc);
141
25.9M
}
jclossls-16.c:jpeg_difference2
Line
Count
Source
137
25.0M
{
138
25.0M
  DIFFERENCE_2D(PREDICTOR2);
139
25.0M
  (void)(Ra);
140
25.0M
  (void)(Rc);
141
25.0M
}
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
75.1M
{
148
75.1M
  DIFFERENCE_2D(PREDICTOR3);
149
75.1M
  (void)(Ra);
150
75.1M
}
jclossls-8.c:jpeg_difference3
Line
Count
Source
147
24.0M
{
148
24.0M
  DIFFERENCE_2D(PREDICTOR3);
149
24.0M
  (void)(Ra);
150
24.0M
}
jclossls-12.c:jpeg_difference3
Line
Count
Source
147
25.9M
{
148
25.9M
  DIFFERENCE_2D(PREDICTOR3);
149
25.9M
  (void)(Ra);
150
25.9M
}
jclossls-16.c:jpeg_difference3
Line
Count
Source
147
25.0M
{
148
25.0M
  DIFFERENCE_2D(PREDICTOR3);
149
25.0M
  (void)(Ra);
150
25.0M
}
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
75.1M
{
157
75.1M
  DIFFERENCE_2D(PREDICTOR4);
158
75.1M
}
jclossls-8.c:jpeg_difference4
Line
Count
Source
156
24.0M
{
157
24.0M
  DIFFERENCE_2D(PREDICTOR4);
158
24.0M
}
jclossls-12.c:jpeg_difference4
Line
Count
Source
156
25.9M
{
157
25.9M
  DIFFERENCE_2D(PREDICTOR4);
158
25.9M
}
jclossls-16.c:jpeg_difference4
Line
Count
Source
156
25.0M
{
157
25.0M
  DIFFERENCE_2D(PREDICTOR4);
158
25.0M
}
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
75.1M
{
165
75.1M
  DIFFERENCE_2D(PREDICTOR5);
166
75.1M
}
jclossls-8.c:jpeg_difference5
Line
Count
Source
164
24.0M
{
165
24.0M
  DIFFERENCE_2D(PREDICTOR5);
166
24.0M
}
jclossls-12.c:jpeg_difference5
Line
Count
Source
164
25.9M
{
165
25.9M
  DIFFERENCE_2D(PREDICTOR5);
166
25.9M
}
jclossls-16.c:jpeg_difference5
Line
Count
Source
164
25.0M
{
165
25.0M
  DIFFERENCE_2D(PREDICTOR5);
166
25.0M
}
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
23.2M
{
173
23.2M
  DIFFERENCE_2D(PREDICTOR6);
174
23.2M
}
jclossls-8.c:jpeg_difference6
Line
Count
Source
172
6.42M
{
173
6.42M
  DIFFERENCE_2D(PREDICTOR6);
174
6.42M
}
jclossls-12.c:jpeg_difference6
Line
Count
Source
172
8.51M
{
173
8.51M
  DIFFERENCE_2D(PREDICTOR6);
174
8.51M
}
jclossls-16.c:jpeg_difference6
Line
Count
Source
172
8.33M
{
173
8.33M
  DIFFERENCE_2D(PREDICTOR6);
174
8.33M
}
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
175M
{
198
175M
  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
175M
  if (!restart) {
209
92.5k
    switch (cinfo->Ss) {
210
0
    case 1:
211
0
      losslessc->predict_difference[ci] = jpeg_difference1;
212
0
      break;
213
21.6k
    case 2:
214
21.6k
      losslessc->predict_difference[ci] = jpeg_difference2;
215
21.6k
      break;
216
21.6k
    case 3:
217
21.6k
      losslessc->predict_difference[ci] = jpeg_difference3;
218
21.6k
      break;
219
21.6k
    case 4:
220
21.6k
      losslessc->predict_difference[ci] = jpeg_difference4;
221
21.6k
      break;
222
21.6k
    case 5:
223
21.6k
      losslessc->predict_difference[ci] = jpeg_difference5;
224
21.6k
      break;
225
6.05k
    case 6:
226
6.05k
      losslessc->predict_difference[ci] = jpeg_difference6;
227
6.05k
      break;
228
0
    case 7:
229
0
      losslessc->predict_difference[ci] = jpeg_difference7;
230
0
      break;
231
92.5k
    }
232
92.5k
  }
233
175M
}
jclossls-8.c:jpeg_difference_first_row
Line
Count
Source
197
56.2M
{
198
56.2M
  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
56.2M
  if (!restart) {
209
32.0k
    switch (cinfo->Ss) {
210
0
    case 1:
211
0
      losslessc->predict_difference[ci] = jpeg_difference1;
212
0
      break;
213
7.51k
    case 2:
214
7.51k
      losslessc->predict_difference[ci] = jpeg_difference2;
215
7.51k
      break;
216
7.51k
    case 3:
217
7.51k
      losslessc->predict_difference[ci] = jpeg_difference3;
218
7.51k
      break;
219
7.51k
    case 4:
220
7.51k
      losslessc->predict_difference[ci] = jpeg_difference4;
221
7.51k
      break;
222
7.51k
    case 5:
223
7.51k
      losslessc->predict_difference[ci] = jpeg_difference5;
224
7.51k
      break;
225
1.99k
    case 6:
226
1.99k
      losslessc->predict_difference[ci] = jpeg_difference6;
227
1.99k
      break;
228
0
    case 7:
229
0
      losslessc->predict_difference[ci] = jpeg_difference7;
230
0
      break;
231
32.0k
    }
232
32.0k
  }
233
56.2M
}
jclossls-12.c:jpeg_difference_first_row
Line
Count
Source
197
60.6M
{
198
60.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
60.6M
  if (!restart) {
209
29.5k
    switch (cinfo->Ss) {
210
0
    case 1:
211
0
      losslessc->predict_difference[ci] = jpeg_difference1;
212
0
      break;
213
6.90k
    case 2:
214
6.90k
      losslessc->predict_difference[ci] = jpeg_difference2;
215
6.90k
      break;
216
6.90k
    case 3:
217
6.90k
      losslessc->predict_difference[ci] = jpeg_difference3;
218
6.90k
      break;
219
6.90k
    case 4:
220
6.90k
      losslessc->predict_difference[ci] = jpeg_difference4;
221
6.90k
      break;
222
6.90k
    case 5:
223
6.90k
      losslessc->predict_difference[ci] = jpeg_difference5;
224
6.90k
      break;
225
1.91k
    case 6:
226
1.91k
      losslessc->predict_difference[ci] = jpeg_difference6;
227
1.91k
      break;
228
0
    case 7:
229
0
      losslessc->predict_difference[ci] = jpeg_difference7;
230
0
      break;
231
29.5k
    }
232
29.5k
  }
233
60.6M
}
jclossls-16.c:jpeg_difference_first_row
Line
Count
Source
197
58.4M
{
198
58.4M
  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
58.4M
  if (!restart) {
209
30.9k
    switch (cinfo->Ss) {
210
0
    case 1:
211
0
      losslessc->predict_difference[ci] = jpeg_difference1;
212
0
      break;
213
7.20k
    case 2:
214
7.20k
      losslessc->predict_difference[ci] = jpeg_difference2;
215
7.20k
      break;
216
7.20k
    case 3:
217
7.20k
      losslessc->predict_difference[ci] = jpeg_difference3;
218
7.20k
      break;
219
7.20k
    case 4:
220
7.20k
      losslessc->predict_difference[ci] = jpeg_difference4;
221
7.20k
      break;
222
7.20k
    case 5:
223
7.20k
      losslessc->predict_difference[ci] = jpeg_difference5;
224
7.20k
      break;
225
2.14k
    case 6:
226
2.14k
      losslessc->predict_difference[ci] = jpeg_difference6;
227
2.14k
      break;
228
0
    case 7:
229
0
      losslessc->predict_difference[ci] = jpeg_difference7;
230
0
      break;
231
30.9k
    }
232
30.9k
  }
233
58.4M
}
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
175M
{
242
175M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
243
244
  /* Initialize restart counter */
245
175M
  losslessc->restart_rows_to_go[ci] =
246
175M
    cinfo->restart_interval / cinfo->MCUs_per_row;
247
248
  /* Set difference function to first row function */
249
175M
  losslessc->predict_difference[ci] = jpeg_difference_first_row;
250
175M
}
jclossls-8.c:reset_predictor
Line
Count
Source
241
56.2M
{
242
56.2M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
243
244
  /* Initialize restart counter */
245
56.2M
  losslessc->restart_rows_to_go[ci] =
246
56.2M
    cinfo->restart_interval / cinfo->MCUs_per_row;
247
248
  /* Set difference function to first row function */
249
56.2M
  losslessc->predict_difference[ci] = jpeg_difference_first_row;
250
56.2M
}
jclossls-12.c:reset_predictor
Line
Count
Source
241
60.7M
{
242
60.7M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
243
244
  /* Initialize restart counter */
245
60.7M
  losslessc->restart_rows_to_go[ci] =
246
60.7M
    cinfo->restart_interval / cinfo->MCUs_per_row;
247
248
  /* Set difference function to first row function */
249
60.7M
  losslessc->predict_difference[ci] = jpeg_difference_first_row;
250
60.7M
}
jclossls-16.c:reset_predictor
Line
Count
Source
241
58.4M
{
242
58.4M
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
243
244
  /* Initialize restart counter */
245
58.4M
  losslessc->restart_rows_to_go[ci] =
246
58.4M
    cinfo->restart_interval / cinfo->MCUs_per_row;
247
248
  /* Set difference function to first row function */
249
58.4M
  losslessc->predict_difference[ci] = jpeg_difference_first_row;
250
58.4M
}
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
323M
{
259
1.46G
  do {
260
1.46G
    *output_buf++ = (_JSAMPLE)RIGHT_SHIFT(*input_buf++, cinfo->Al);
261
1.46G
  } while (--width);
262
323M
}
jclossls-8.c:simple_downscale
Line
Count
Source
258
102M
{
259
660M
  do {
260
660M
    *output_buf++ = (_JSAMPLE)RIGHT_SHIFT(*input_buf++, cinfo->Al);
261
660M
  } while (--width);
262
102M
}
jclossls-12.c:simple_downscale
Line
Count
Source
258
112M
{
259
265M
  do {
260
265M
    *output_buf++ = (_JSAMPLE)RIGHT_SHIFT(*input_buf++, cinfo->Al);
261
265M
  } while (--width);
262
112M
}
jclossls-16.c:simple_downscale
Line
Count
Source
258
108M
{
259
544M
  do {
260
544M
    *output_buf++ = (_JSAMPLE)RIGHT_SHIFT(*input_buf++, cinfo->Al);
261
544M
  } while (--width);
262
108M
}
263
264
265
METHODDEF(void)
266
noscale(j_compress_ptr cinfo,
267
        _JSAMPROW input_buf, _JSAMPROW output_buf, JDIMENSION width)
268
175M
{
269
175M
  memcpy(output_buf, input_buf, width * sizeof(_JSAMPLE));
270
175M
}
jclossls-8.c:noscale
Line
Count
Source
268
56.2M
{
269
56.2M
  memcpy(output_buf, input_buf, width * sizeof(_JSAMPLE));
270
56.2M
}
jclossls-12.c:noscale
Line
Count
Source
268
60.6M
{
269
60.6M
  memcpy(output_buf, input_buf, width * sizeof(_JSAMPLE));
270
60.6M
}
jclossls-16.c:noscale
Line
Count
Source
268
58.4M
{
269
58.4M
  memcpy(output_buf, input_buf, width * sizeof(_JSAMPLE));
270
58.4M
}
271
272
273
/*
274
 * Initialize for a processing pass.
275
 */
276
277
METHODDEF(void)
278
start_pass_lossless(j_compress_ptr cinfo)
279
49.2k
{
280
49.2k
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
281
49.2k
  int ci;
282
283
  /* Set scaler function based on Pt */
284
49.2k
  if (cinfo->Al)
285
34.8k
    losslessc->scaler_scale = simple_downscale;
286
14.4k
  else
287
14.4k
    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
49.2k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
293
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
294
49.2k
             cinfo->restart_interval, cinfo->MCUs_per_row);
295
296
  /* Set predictors for start of pass */
297
192k
  for (ci = 0; ci < cinfo->num_components; ci++)
298
142k
    reset_predictor(cinfo, ci);
299
49.2k
}
jclossls-8.c:start_pass_lossless
Line
Count
Source
279
17.0k
{
280
17.0k
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
281
17.0k
  int ci;
282
283
  /* Set scaler function based on Pt */
284
17.0k
  if (cinfo->Al)
285
12.0k
    losslessc->scaler_scale = simple_downscale;
286
5.00k
  else
287
5.00k
    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
17.0k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
293
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
294
17.0k
             cinfo->restart_interval, cinfo->MCUs_per_row);
295
296
  /* Set predictors for start of pass */
297
66.5k
  for (ci = 0; ci < cinfo->num_components; ci++)
298
49.5k
    reset_predictor(cinfo, ci);
299
17.0k
}
jclossls-12.c:start_pass_lossless
Line
Count
Source
279
15.7k
{
280
15.7k
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
281
15.7k
  int ci;
282
283
  /* Set scaler function based on Pt */
284
15.7k
  if (cinfo->Al)
285
11.1k
    losslessc->scaler_scale = simple_downscale;
286
4.60k
  else
287
4.60k
    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
15.7k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
293
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
294
15.7k
             cinfo->restart_interval, cinfo->MCUs_per_row);
295
296
  /* Set predictors for start of pass */
297
61.3k
  for (ci = 0; ci < cinfo->num_components; ci++)
298
45.6k
    reset_predictor(cinfo, ci);
299
15.7k
}
jclossls-16.c:start_pass_lossless
Line
Count
Source
279
16.5k
{
280
16.5k
  lossless_comp_ptr losslessc = (lossless_comp_ptr)cinfo->fdct;
281
16.5k
  int ci;
282
283
  /* Set scaler function based on Pt */
284
16.5k
  if (cinfo->Al)
285
11.7k
    losslessc->scaler_scale = simple_downscale;
286
4.80k
  else
287
4.80k
    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
16.5k
  if (cinfo->restart_interval % cinfo->MCUs_per_row != 0)
293
0
    ERREXIT2(cinfo, JERR_BAD_RESTART,
294
16.5k
             cinfo->restart_interval, cinfo->MCUs_per_row);
295
296
  /* Set predictors for start of pass */
297
64.2k
  for (ci = 0; ci < cinfo->num_components; ci++)
298
47.7k
    reset_predictor(cinfo, ci);
299
16.5k
}
300
301
302
/*
303
 * Initialize the lossless compressor.
304
 */
305
306
GLOBAL(void)
307
_jinit_lossless_compressor(j_compress_ptr cinfo)
308
24.6k
{
309
24.6k
  lossless_comp_ptr losslessc;
310
311
#if BITS_IN_JSAMPLE == 8
312
8.51k
  if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
313
#else
314
16.1k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
315
16.1k
      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
24.6k
  losslessc = (lossless_comp_ptr)
321
24.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
322
24.6k
                                sizeof(jpeg_lossless_compressor));
323
24.6k
  cinfo->fdct = (struct jpeg_forward_dct *)losslessc;
324
24.6k
  losslessc->pub.start_pass = start_pass_lossless;
325
24.6k
}
jinit_lossless_compressor
Line
Count
Source
308
8.51k
{
309
8.51k
  lossless_comp_ptr losslessc;
310
311
8.51k
#if BITS_IN_JSAMPLE == 8
312
8.51k
  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
8.51k
  losslessc = (lossless_comp_ptr)
321
8.51k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
322
8.51k
                                sizeof(jpeg_lossless_compressor));
323
8.51k
  cinfo->fdct = (struct jpeg_forward_dct *)losslessc;
324
8.51k
  losslessc->pub.start_pass = start_pass_lossless;
325
8.51k
}
j12init_lossless_compressor
Line
Count
Source
308
7.85k
{
309
7.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
7.85k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
315
7.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
7.85k
  losslessc = (lossless_comp_ptr)
321
7.85k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
322
7.85k
                                sizeof(jpeg_lossless_compressor));
323
7.85k
  cinfo->fdct = (struct jpeg_forward_dct *)losslessc;
324
7.85k
  losslessc->pub.start_pass = start_pass_lossless;
325
7.85k
}
j16init_lossless_compressor
Line
Count
Source
308
8.27k
{
309
8.27k
  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
8.27k
  if (cinfo->data_precision > BITS_IN_JSAMPLE ||
315
8.27k
      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
8.27k
  losslessc = (lossless_comp_ptr)
321
8.27k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
322
8.27k
                                sizeof(jpeg_lossless_compressor));
323
8.27k
  cinfo->fdct = (struct jpeg_forward_dct *)losslessc;
324
8.27k
  losslessc->pub.start_pass = start_pass_lossless;
325
8.27k
}
326
327
#endif /* C_LOSSLESS_SUPPORTED */