Coverage Report

Created: 2026-07-16 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo/src/jdsample.c
Line
Count
Source
1
/*
2
 * jdsample.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1991-1996, Thomas G. Lane.
6
 * libjpeg-turbo Modifications:
7
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
8
 * Copyright (C) 2010, 2015-2016, 2022, 2024-2026, D. R. Commander.
9
 * Copyright (C) 2015, Google, Inc.
10
 * Copyright (C) 2019-2020, Arm Limited.
11
 * For conditions of distribution and use, see the accompanying README.ijg
12
 * file.
13
 *
14
 * This file contains upsampling routines.
15
 *
16
 * Upsampling input data is counted in "row groups".  A row group is defined to
17
 * be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size) sample rows of
18
 * each component.  Upsampling will normally produce max_v_samp_factor rows of
19
 * each component from each row group (but this could vary if the upsampler is
20
 * applying a scale factor of its own).
21
 *
22
 * An excellent reference for image resampling is
23
 *   Digital Image Warping, George Wolberg, 1990.
24
 *   Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
25
 */
26
27
#include "jinclude.h"
28
#include "jdsample.h"
29
#ifdef WITH_SIMD
30
#include "../simd/jsimd.h"
31
#endif
32
#include "jpegapicomp.h"
33
#ifdef WITH_PROFILE
34
#include "tjutil.h"
35
#endif
36
37
38
39
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
40
41
/*
42
 * Initialize for an upsampling pass.
43
 */
44
45
METHODDEF(void)
46
start_pass_upsample(j_decompress_ptr cinfo)
47
4.41k
{
48
4.41k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
4.41k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
4.41k
  upsample->rows_to_go = cinfo->output_height;
54
4.41k
}
jdsample-8.c:start_pass_upsample
Line
Count
Source
47
4.15k
{
48
4.15k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
4.15k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
4.15k
  upsample->rows_to_go = cinfo->output_height;
54
4.15k
}
jdsample-12.c:start_pass_upsample
Line
Count
Source
47
247
{
48
247
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
247
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
247
  upsample->rows_to_go = cinfo->output_height;
54
247
}
jdsample-16.c:start_pass_upsample
Line
Count
Source
47
17
{
48
17
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
17
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
17
  upsample->rows_to_go = cinfo->output_height;
54
17
}
55
56
57
/*
58
 * Control routine to do upsampling (and color conversion).
59
 *
60
 * In this version we upsample each component independently.
61
 * We upsample one row group into the conversion buffer, then apply
62
 * color conversion a row at a time.
63
 */
64
65
METHODDEF(void)
66
sep_upsample(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
67
             JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail,
68
             _JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
69
             JDIMENSION out_rows_avail)
70
3.78M
{
71
3.78M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
3.78M
  int ci;
73
3.78M
  jpeg_component_info *compptr;
74
3.78M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
3.78M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
5.05M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
3.05M
         ci++, compptr++) {
80
      /* Invoke per-component upsample method.  Notice we pass a POINTER
81
       * to color_buf[ci], so that fullsize_upsample can change it.
82
       */
83
#ifdef WITH_PROFILE
84
      cinfo->master->start = getTime();
85
#endif
86
3.05M
      (*upsample->methods[ci]) (cinfo, compptr,
87
3.05M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
3.05M
        upsample->color_buf + ci);
89
#ifdef WITH_PROFILE
90
      cinfo->master->upsample_elapsed += getTime() - cinfo->master->start;
91
      cinfo->master->upsample_msamples +=
92
        (double)cinfo->output_width * cinfo->max_v_samp_factor / 1000000.;
93
#endif
94
3.05M
    }
95
2.00M
    upsample->next_row_out = 0;
96
2.00M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
3.78M
  num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out);
102
  /* Not more than the distance to the end of the image.  Need this test
103
   * in case the image height is not a multiple of max_v_samp_factor:
104
   */
105
3.78M
  if (num_rows > upsample->rows_to_go)
106
967
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
3.78M
  out_rows_avail -= *out_row_ctr;
109
3.78M
  if (num_rows > out_rows_avail)
110
1.78M
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
3.78M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
3.78M
                                      (JDIMENSION)upsample->next_row_out,
117
3.78M
                                      output_buf + *out_row_ctr,
118
3.78M
                                      (int)num_rows);
119
#ifdef WITH_PROFILE
120
  cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
121
  cinfo->master->cconvert_mpixels +=
122
    (double)cinfo->output_width * num_rows / 1000000.;
123
#endif
124
125
  /* Adjust counts */
126
3.78M
  *out_row_ctr += num_rows;
127
3.78M
  upsample->rows_to_go -= num_rows;
128
3.78M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
3.78M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
2.00M
    (*in_row_group_ctr)++;
132
3.78M
}
jdsample-8.c:sep_upsample
Line
Count
Source
70
3.78M
{
71
3.78M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
3.78M
  int ci;
73
3.78M
  jpeg_component_info *compptr;
74
3.78M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
3.78M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
5.05M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
3.05M
         ci++, compptr++) {
80
      /* Invoke per-component upsample method.  Notice we pass a POINTER
81
       * to color_buf[ci], so that fullsize_upsample can change it.
82
       */
83
#ifdef WITH_PROFILE
84
      cinfo->master->start = getTime();
85
#endif
86
3.05M
      (*upsample->methods[ci]) (cinfo, compptr,
87
3.05M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
3.05M
        upsample->color_buf + ci);
89
#ifdef WITH_PROFILE
90
      cinfo->master->upsample_elapsed += getTime() - cinfo->master->start;
91
      cinfo->master->upsample_msamples +=
92
        (double)cinfo->output_width * cinfo->max_v_samp_factor / 1000000.;
93
#endif
94
3.05M
    }
95
2.00M
    upsample->next_row_out = 0;
96
2.00M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
3.78M
  num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out);
102
  /* Not more than the distance to the end of the image.  Need this test
103
   * in case the image height is not a multiple of max_v_samp_factor:
104
   */
105
3.78M
  if (num_rows > upsample->rows_to_go)
106
967
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
3.78M
  out_rows_avail -= *out_row_ctr;
109
3.78M
  if (num_rows > out_rows_avail)
110
1.78M
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
3.78M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
3.78M
                                      (JDIMENSION)upsample->next_row_out,
117
3.78M
                                      output_buf + *out_row_ctr,
118
3.78M
                                      (int)num_rows);
119
#ifdef WITH_PROFILE
120
  cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
121
  cinfo->master->cconvert_mpixels +=
122
    (double)cinfo->output_width * num_rows / 1000000.;
123
#endif
124
125
  /* Adjust counts */
126
3.78M
  *out_row_ctr += num_rows;
127
3.78M
  upsample->rows_to_go -= num_rows;
128
3.78M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
3.78M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
2.00M
    (*in_row_group_ctr)++;
132
3.78M
}
Unexecuted instantiation: jdsample-12.c:sep_upsample
Unexecuted instantiation: jdsample-16.c:sep_upsample
133
134
135
/*
136
 * These are the routines invoked by sep_upsample to upsample values of a
137
 * single component.  One row group is processed per call.
138
 */
139
140
141
/*
142
 * For full-size components, we just make color_buf[ci] point at the
143
 * input buffer, and thus avoid copying any data.  Note that this is
144
 * safe only because sep_upsample doesn't declare the input row group
145
 * "consumed" until we are done color converting and emitting it.
146
 */
147
148
METHODDEF(void)
149
fullsize_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
150
                  _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
151
1.75M
{
152
1.75M
  *output_data_ptr = input_data;
153
1.75M
}
jdsample-8.c:fullsize_upsample
Line
Count
Source
151
1.75M
{
152
1.75M
  *output_data_ptr = input_data;
153
1.75M
}
Unexecuted instantiation: jdsample-12.c:fullsize_upsample
Unexecuted instantiation: jdsample-16.c:fullsize_upsample
154
155
156
/*
157
 * This is a no-op version used for "uninteresting" components.
158
 * These components will not be referenced by color conversion.
159
 */
160
161
METHODDEF(void)
162
noop_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
163
              _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
164
0
{
165
0
  *output_data_ptr = NULL;      /* safety check */
166
0
}
Unexecuted instantiation: jdsample-8.c:noop_upsample
Unexecuted instantiation: jdsample-12.c:noop_upsample
Unexecuted instantiation: jdsample-16.c:noop_upsample
167
168
169
/*
170
 * This version handles any integral sampling ratios.
171
 * This is not used for typical JPEG files, so it need not be fast.  Nor, for
172
 * that matter, is it particularly accurate: the algorithm is simple
173
 * replication of the input sample onto the corresponding output components.
174
 * The hi-falutin sampling literature refers to this as a "box filter".  A box
175
 * filter tends to introduce visible artifacts, so if you are actually going to
176
 * use 3:1 or 4:1 sampling ratios you would be well advised to improve this
177
 * code.
178
 */
179
180
METHODDEF(void)
181
int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
182
             _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
183
422k
{
184
422k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
422k
  _JSAMPARRAY output_data = *output_data_ptr;
186
422k
  register _JSAMPROW inptr, outptr;
187
422k
  register _JSAMPLE invalue;
188
422k
  register int h;
189
422k
  _JSAMPROW outend;
190
422k
  int h_expand, v_expand;
191
422k
  int inrow, outrow;
192
193
422k
  h_expand = upsample->h_expand[compptr->component_index];
194
422k
  v_expand = upsample->v_expand[compptr->component_index];
195
196
422k
  inrow = outrow = 0;
197
850k
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
427k
    inptr = input_data[inrow];
200
427k
    outptr = output_data[outrow];
201
427k
    outend = outptr + cinfo->output_width;
202
11.4M
    while (outptr < outend) {
203
11.0M
      invalue = *inptr++;
204
28.6M
      for (h = h_expand; h > 0; h--) {
205
17.6M
        *outptr++ = invalue;
206
17.6M
      }
207
11.0M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
427k
    if (v_expand > 1) {
210
418k
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
418k
                         v_expand - 1, cinfo->output_width);
212
418k
    }
213
427k
    inrow++;
214
427k
    outrow += v_expand;
215
427k
  }
216
422k
}
jdsample-8.c:int_upsample
Line
Count
Source
183
422k
{
184
422k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
422k
  _JSAMPARRAY output_data = *output_data_ptr;
186
422k
  register _JSAMPROW inptr, outptr;
187
422k
  register _JSAMPLE invalue;
188
422k
  register int h;
189
422k
  _JSAMPROW outend;
190
422k
  int h_expand, v_expand;
191
422k
  int inrow, outrow;
192
193
422k
  h_expand = upsample->h_expand[compptr->component_index];
194
422k
  v_expand = upsample->v_expand[compptr->component_index];
195
196
422k
  inrow = outrow = 0;
197
850k
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
427k
    inptr = input_data[inrow];
200
427k
    outptr = output_data[outrow];
201
427k
    outend = outptr + cinfo->output_width;
202
11.4M
    while (outptr < outend) {
203
11.0M
      invalue = *inptr++;
204
28.6M
      for (h = h_expand; h > 0; h--) {
205
17.6M
        *outptr++ = invalue;
206
17.6M
      }
207
11.0M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
427k
    if (v_expand > 1) {
210
418k
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
418k
                         v_expand - 1, cinfo->output_width);
212
418k
    }
213
427k
    inrow++;
214
427k
    outrow += v_expand;
215
427k
  }
216
422k
}
Unexecuted instantiation: jdsample-12.c:int_upsample
Unexecuted instantiation: jdsample-16.c:int_upsample
217
218
219
/*
220
 * Fast processing for the common case of 2:1 horizontal and 1:1 vertical.
221
 * It's still a box filter.
222
 */
223
224
METHODDEF(void)
225
h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
226
              _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
227
10.8k
{
228
10.8k
  _JSAMPARRAY output_data = *output_data_ptr;
229
10.8k
  register _JSAMPROW inptr, outptr;
230
10.8k
  register _JSAMPLE invalue;
231
10.8k
  _JSAMPROW outend;
232
10.8k
  int inrow;
233
234
51.0k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
40.2k
    inptr = input_data[inrow];
236
40.2k
    outptr = output_data[inrow];
237
40.2k
    outend = outptr + cinfo->output_width;
238
169k
    while (outptr < outend) {
239
129k
      invalue = *inptr++;
240
129k
      *outptr++ = invalue;
241
129k
      *outptr++ = invalue;
242
129k
    }
243
40.2k
  }
244
10.8k
}
jdsample-8.c:h2v1_upsample
Line
Count
Source
227
10.8k
{
228
10.8k
  _JSAMPARRAY output_data = *output_data_ptr;
229
10.8k
  register _JSAMPROW inptr, outptr;
230
10.8k
  register _JSAMPLE invalue;
231
10.8k
  _JSAMPROW outend;
232
10.8k
  int inrow;
233
234
51.0k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
40.2k
    inptr = input_data[inrow];
236
40.2k
    outptr = output_data[inrow];
237
40.2k
    outend = outptr + cinfo->output_width;
238
169k
    while (outptr < outend) {
239
129k
      invalue = *inptr++;
240
129k
      *outptr++ = invalue;
241
129k
      *outptr++ = invalue;
242
129k
    }
243
40.2k
  }
244
10.8k
}
Unexecuted instantiation: jdsample-12.c:h2v1_upsample
Unexecuted instantiation: jdsample-16.c:h2v1_upsample
245
246
247
/*
248
 * Fast processing for the common case of 2:1 horizontal and 2:1 vertical.
249
 * It's still a box filter.
250
 */
251
252
METHODDEF(void)
253
h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
254
              _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
255
31.6k
{
256
31.6k
  _JSAMPARRAY output_data = *output_data_ptr;
257
31.6k
  register _JSAMPROW inptr, outptr;
258
31.6k
  register _JSAMPLE invalue;
259
31.6k
  _JSAMPROW outend;
260
31.6k
  int inrow, outrow;
261
262
31.6k
  inrow = outrow = 0;
263
72.7k
  while (outrow < cinfo->max_v_samp_factor) {
264
41.0k
    inptr = input_data[inrow];
265
41.0k
    outptr = output_data[outrow];
266
41.0k
    outend = outptr + cinfo->output_width;
267
134k
    while (outptr < outend) {
268
93.4k
      invalue = *inptr++;
269
93.4k
      *outptr++ = invalue;
270
93.4k
      *outptr++ = invalue;
271
93.4k
    }
272
41.0k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
41.0k
                       cinfo->output_width);
274
41.0k
    inrow++;
275
41.0k
    outrow += 2;
276
41.0k
  }
277
31.6k
}
jdsample-8.c:h2v2_upsample
Line
Count
Source
255
31.6k
{
256
31.6k
  _JSAMPARRAY output_data = *output_data_ptr;
257
31.6k
  register _JSAMPROW inptr, outptr;
258
31.6k
  register _JSAMPLE invalue;
259
31.6k
  _JSAMPROW outend;
260
31.6k
  int inrow, outrow;
261
262
31.6k
  inrow = outrow = 0;
263
72.7k
  while (outrow < cinfo->max_v_samp_factor) {
264
41.0k
    inptr = input_data[inrow];
265
41.0k
    outptr = output_data[outrow];
266
41.0k
    outend = outptr + cinfo->output_width;
267
134k
    while (outptr < outend) {
268
93.4k
      invalue = *inptr++;
269
93.4k
      *outptr++ = invalue;
270
93.4k
      *outptr++ = invalue;
271
93.4k
    }
272
41.0k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
41.0k
                       cinfo->output_width);
274
41.0k
    inrow++;
275
41.0k
    outrow += 2;
276
41.0k
  }
277
31.6k
}
Unexecuted instantiation: jdsample-12.c:h2v2_upsample
Unexecuted instantiation: jdsample-16.c:h2v2_upsample
278
279
280
/*
281
 * Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
282
 *
283
 * The upsampling algorithm is linear interpolation between component centers,
284
 * also known as a "triangle filter".  This is a good compromise between speed
285
 * and visual quality.  The centers of the output components are 1/4 and 3/4 of
286
 * the way between input component centers.
287
 *
288
 * A note about the "bias" calculations: when rounding fractional values to
289
 * integer, we do not want to always round 0.5 up to the next integer.
290
 * If we did that, we'd introduce a noticeable bias towards larger values.
291
 * Instead, this code is arranged so that 0.5 will be rounded up or down at
292
 * alternate pixel locations (a simple ordered dither pattern).
293
 */
294
295
METHODDEF(void)
296
h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
297
                    _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
298
332k
{
299
332k
  _JSAMPARRAY output_data = *output_data_ptr;
300
332k
  register _JSAMPROW inptr, outptr;
301
332k
  register int invalue;
302
332k
  register JDIMENSION colctr;
303
332k
  int inrow;
304
305
1.28M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
956k
    inptr = input_data[inrow];
307
956k
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
956k
    invalue = *inptr++;
310
956k
    *outptr++ = (_JSAMPLE)invalue;
311
956k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
10.2M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer component + 1/4 * further component */
315
9.27M
      invalue = (*inptr++) * 3;
316
9.27M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
9.27M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
9.27M
    }
319
320
    /* Special case for last column */
321
956k
    invalue = *inptr;
322
956k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
956k
    *outptr++ = (_JSAMPLE)invalue;
324
956k
  }
325
332k
}
jdsample-8.c:h2v1_fancy_upsample
Line
Count
Source
298
332k
{
299
332k
  _JSAMPARRAY output_data = *output_data_ptr;
300
332k
  register _JSAMPROW inptr, outptr;
301
332k
  register int invalue;
302
332k
  register JDIMENSION colctr;
303
332k
  int inrow;
304
305
1.28M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
956k
    inptr = input_data[inrow];
307
956k
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
956k
    invalue = *inptr++;
310
956k
    *outptr++ = (_JSAMPLE)invalue;
311
956k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
10.2M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer component + 1/4 * further component */
315
9.27M
      invalue = (*inptr++) * 3;
316
9.27M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
9.27M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
9.27M
    }
319
320
    /* Special case for last column */
321
956k
    invalue = *inptr;
322
956k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
956k
    *outptr++ = (_JSAMPLE)invalue;
324
956k
  }
325
332k
}
Unexecuted instantiation: jdsample-12.c:h2v1_fancy_upsample
Unexecuted instantiation: jdsample-16.c:h2v1_fancy_upsample
326
327
328
/*
329
 * Fancy processing for 1:1 horizontal and 2:1 vertical (4:4:0 subsampling).
330
 *
331
 * This is a less common case, but it can be encountered when losslessly
332
 * rotating/transposing a JPEG file that uses 4:2:2 chroma subsampling.
333
 */
334
335
METHODDEF(void)
336
h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
337
                    _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
338
79.1k
{
339
79.1k
  _JSAMPARRAY output_data = *output_data_ptr;
340
79.1k
  _JSAMPROW inptr0, inptr1, outptr;
341
#if BITS_IN_JSAMPLE == 8
342
  int thiscolsum, bias;
343
#else
344
  JLONG thiscolsum, bias;
345
#endif
346
79.1k
  JDIMENSION colctr;
347
79.1k
  int inrow, outrow, v;
348
349
79.1k
  inrow = outrow = 0;
350
166k
  while (outrow < cinfo->max_v_samp_factor) {
351
262k
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
174k
      inptr0 = input_data[inrow];
354
174k
      if (v == 0) {             /* next nearest is row above */
355
87.3k
        inptr1 = input_data[inrow - 1];
356
87.3k
        bias = 1;
357
87.3k
      } else {                  /* next nearest is row below */
358
87.3k
        inptr1 = input_data[inrow + 1];
359
87.3k
        bias = 2;
360
87.3k
      }
361
174k
      outptr = output_data[outrow++];
362
363
5.30M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
5.12M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
5.12M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
5.12M
      }
367
174k
    }
368
87.3k
    inrow++;
369
87.3k
  }
370
79.1k
}
jdsample-8.c:h1v2_fancy_upsample
Line
Count
Source
338
79.1k
{
339
79.1k
  _JSAMPARRAY output_data = *output_data_ptr;
340
79.1k
  _JSAMPROW inptr0, inptr1, outptr;
341
79.1k
#if BITS_IN_JSAMPLE == 8
342
79.1k
  int thiscolsum, bias;
343
#else
344
  JLONG thiscolsum, bias;
345
#endif
346
79.1k
  JDIMENSION colctr;
347
79.1k
  int inrow, outrow, v;
348
349
79.1k
  inrow = outrow = 0;
350
166k
  while (outrow < cinfo->max_v_samp_factor) {
351
262k
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
174k
      inptr0 = input_data[inrow];
354
174k
      if (v == 0) {             /* next nearest is row above */
355
87.3k
        inptr1 = input_data[inrow - 1];
356
87.3k
        bias = 1;
357
87.3k
      } else {                  /* next nearest is row below */
358
87.3k
        inptr1 = input_data[inrow + 1];
359
87.3k
        bias = 2;
360
87.3k
      }
361
174k
      outptr = output_data[outrow++];
362
363
5.30M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
5.12M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
5.12M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
5.12M
      }
367
174k
    }
368
87.3k
    inrow++;
369
87.3k
  }
370
79.1k
}
Unexecuted instantiation: jdsample-12.c:h1v2_fancy_upsample
Unexecuted instantiation: jdsample-16.c:h1v2_fancy_upsample
371
372
373
/*
374
 * Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
375
 * Again a triangle filter; see comments for h2v1 case, above.
376
 *
377
 * It is OK for us to reference the adjacent input rows because we demanded
378
 * context from the main buffer controller (see initialization code).
379
 */
380
381
METHODDEF(void)
382
h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
383
                    _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
384
419k
{
385
419k
  _JSAMPARRAY output_data = *output_data_ptr;
386
419k
  register _JSAMPROW inptr0, inptr1, outptr;
387
#if BITS_IN_JSAMPLE == 8
388
  register int thiscolsum, lastcolsum, nextcolsum;
389
#else
390
  register JLONG thiscolsum, lastcolsum, nextcolsum;
391
#endif
392
419k
  register JDIMENSION colctr;
393
419k
  int inrow, outrow, v;
394
395
419k
  inrow = outrow = 0;
396
1.01M
  while (outrow < cinfo->max_v_samp_factor) {
397
1.79M
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
1.19M
      inptr0 = input_data[inrow];
400
1.19M
      if (v == 0)               /* next nearest is row above */
401
597k
        inptr1 = input_data[inrow - 1];
402
597k
      else                      /* next nearest is row below */
403
597k
        inptr1 = input_data[inrow + 1];
404
1.19M
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
1.19M
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
1.19M
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
1.19M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
1.19M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
1.19M
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
31.6M
      for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
414
        /* General case: 3/4 * nearer component + 1/4 * further component in
415
         * each dimension, thus 9/16, 3/16, 3/16, 1/16 overall
416
         */
417
30.4M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
30.4M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
30.4M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
30.4M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
30.4M
      }
422
423
      /* Special case for last column */
424
1.19M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
1.19M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
1.19M
    }
427
597k
    inrow++;
428
597k
  }
429
419k
}
jdsample-8.c:h2v2_fancy_upsample
Line
Count
Source
384
419k
{
385
419k
  _JSAMPARRAY output_data = *output_data_ptr;
386
419k
  register _JSAMPROW inptr0, inptr1, outptr;
387
419k
#if BITS_IN_JSAMPLE == 8
388
419k
  register int thiscolsum, lastcolsum, nextcolsum;
389
#else
390
  register JLONG thiscolsum, lastcolsum, nextcolsum;
391
#endif
392
419k
  register JDIMENSION colctr;
393
419k
  int inrow, outrow, v;
394
395
419k
  inrow = outrow = 0;
396
1.01M
  while (outrow < cinfo->max_v_samp_factor) {
397
1.79M
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
1.19M
      inptr0 = input_data[inrow];
400
1.19M
      if (v == 0)               /* next nearest is row above */
401
597k
        inptr1 = input_data[inrow - 1];
402
597k
      else                      /* next nearest is row below */
403
597k
        inptr1 = input_data[inrow + 1];
404
1.19M
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
1.19M
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
1.19M
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
1.19M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
1.19M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
1.19M
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
31.6M
      for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
414
        /* General case: 3/4 * nearer component + 1/4 * further component in
415
         * each dimension, thus 9/16, 3/16, 3/16, 1/16 overall
416
         */
417
30.4M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
30.4M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
30.4M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
30.4M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
30.4M
      }
422
423
      /* Special case for last column */
424
1.19M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
1.19M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
1.19M
    }
427
597k
    inrow++;
428
597k
  }
429
419k
}
Unexecuted instantiation: jdsample-12.c:h2v2_fancy_upsample
Unexecuted instantiation: jdsample-16.c:h2v2_fancy_upsample
430
431
432
/*
433
 * Module initialization routine for upsampling.
434
 */
435
436
GLOBAL(void)
437
_jinit_upsampler(j_decompress_ptr cinfo)
438
7.11k
{
439
7.11k
  my_upsample_ptr upsample;
440
7.11k
  int ci;
441
7.11k
  jpeg_component_info *compptr;
442
7.11k
  boolean need_buffer, do_fancy;
443
7.11k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
7.11k
#ifdef D_LOSSLESS_SUPPORTED
446
7.11k
  if (cinfo->master->lossless) {
447
#if BITS_IN_JSAMPLE == 8
448
676
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
449
#else
450
1.23k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
1.23k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
1.91k
  } else
455
5.20k
#endif
456
5.20k
  {
457
5.20k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
5.20k
  }
460
461
7.11k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
7.11k
    upsample = (my_upsample_ptr)
463
7.11k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
7.11k
                                  sizeof(my_upsampler));
465
7.11k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
7.11k
    upsample->pub.start_pass = start_pass_upsample;
467
7.11k
    upsample->pub._upsample = sep_upsample;
468
7.11k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
7.11k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
7.11k
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
473
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
474
475
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
476
   * so don't ask for it.
477
   */
478
7.11k
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
479
480
  /* Verify we can handle the sampling factors, select per-component methods,
481
   * and create storage as needed.
482
   */
483
24.1k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
17.0k
       ci++, compptr++) {
485
    /* Compute size of an "input group" after IDCT scaling.  This many samples
486
     * are to be converted to max_h_samp_factor * max_v_samp_factor components.
487
     */
488
17.0k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
17.0k
                 cinfo->_min_DCT_scaled_size;
490
17.0k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
17.0k
                 cinfo->_min_DCT_scaled_size;
492
17.0k
    h_out_group = cinfo->max_h_samp_factor;
493
17.0k
    v_out_group = cinfo->max_v_samp_factor;
494
17.0k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
17.0k
    need_buffer = TRUE;
496
17.0k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
0
      upsample->methods[ci] = noop_upsample;
499
0
      need_buffer = FALSE;
500
17.0k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
7.53k
      upsample->methods[ci] = fullsize_upsample;
503
7.53k
      need_buffer = FALSE;
504
9.50k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
1.32k
      if (do_fancy && compptr->downsampled_width > 2) {
507
#ifdef WITH_SIMD
508
363
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
0
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
363
        else
511
363
#endif
512
363
          upsample->methods[ci] = h2v1_fancy_upsample;
513
925
      } else {
514
#ifdef WITH_SIMD
515
394
        if (jsimd_set_h2v1_upsample(cinfo))
516
0
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
394
        else
518
394
#endif
519
394
          upsample->methods[ci] = h2v1_upsample;
520
925
      }
521
8.17k
    } else if (h_in_group == h_out_group &&
522
1.57k
               v_in_group * 2 == v_out_group && do_fancy) {
523
      /* Non-fancy upsampling is handled by the generic method */
524
#if defined(WITH_SIMD) && (SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM)
525
      if (jsimd_set_h1v2_fancy_upsample(cinfo))
526
        upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
527
      else
528
#endif
529
320
        upsample->methods[ci] = h1v2_fancy_upsample;
530
320
      upsample->pub.need_context_rows = TRUE;
531
7.85k
    } else if (h_in_group * 2 == h_out_group &&
532
5.71k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
4.70k
      if (do_fancy && compptr->downsampled_width > 2) {
535
#ifdef WITH_SIMD
536
3.03k
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
0
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
3.03k
        else
539
3.03k
#endif
540
3.03k
          upsample->methods[ci] = h2v2_fancy_upsample;
541
3.14k
        upsample->pub.need_context_rows = TRUE;
542
3.14k
      } else {
543
#ifdef WITH_SIMD
544
518
        if (jsimd_set_h2v2_upsample(cinfo))
545
0
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
518
        else
547
518
#endif
548
518
          upsample->methods[ci] = h2v2_upsample;
549
1.55k
      }
550
4.70k
    } else if ((h_out_group % h_in_group) == 0 &&
551
3.11k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
3.09k
      upsample->methods[ci] = int_upsample;
554
3.09k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
3.09k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
3.09k
    } else
557
63
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
17.0k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
9.44k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
9.44k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
9.44k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
9.44k
                               (long)cinfo->max_h_samp_factor),
563
9.44k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
9.44k
    }
565
17.0k
  }
566
7.11k
}
jinit_upsampler
Line
Count
Source
438
5.25k
{
439
5.25k
  my_upsample_ptr upsample;
440
5.25k
  int ci;
441
5.25k
  jpeg_component_info *compptr;
442
5.25k
  boolean need_buffer, do_fancy;
443
5.25k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
5.25k
#ifdef D_LOSSLESS_SUPPORTED
446
5.25k
  if (cinfo->master->lossless) {
447
676
#if BITS_IN_JSAMPLE == 8
448
676
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
449
#else
450
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
676
  } else
455
4.58k
#endif
456
4.58k
  {
457
4.58k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
4.58k
  }
460
461
5.25k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
5.25k
    upsample = (my_upsample_ptr)
463
5.25k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
5.25k
                                  sizeof(my_upsampler));
465
5.25k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
5.25k
    upsample->pub.start_pass = start_pass_upsample;
467
5.25k
    upsample->pub._upsample = sep_upsample;
468
5.25k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
5.25k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
5.25k
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
473
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
474
475
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
476
   * so don't ask for it.
477
   */
478
5.25k
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
479
480
  /* Verify we can handle the sampling factors, select per-component methods,
481
   * and create storage as needed.
482
   */
483
16.8k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
11.5k
       ci++, compptr++) {
485
    /* Compute size of an "input group" after IDCT scaling.  This many samples
486
     * are to be converted to max_h_samp_factor * max_v_samp_factor components.
487
     */
488
11.5k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
11.5k
                 cinfo->_min_DCT_scaled_size;
490
11.5k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
11.5k
                 cinfo->_min_DCT_scaled_size;
492
11.5k
    h_out_group = cinfo->max_h_samp_factor;
493
11.5k
    v_out_group = cinfo->max_v_samp_factor;
494
11.5k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
11.5k
    need_buffer = TRUE;
496
11.5k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
0
      upsample->methods[ci] = noop_upsample;
499
0
      need_buffer = FALSE;
500
11.5k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
5.34k
      upsample->methods[ci] = fullsize_upsample;
503
5.34k
      need_buffer = FALSE;
504
6.21k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
757
      if (do_fancy && compptr->downsampled_width > 2) {
507
363
#ifdef WITH_SIMD
508
363
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
0
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
363
        else
511
363
#endif
512
363
          upsample->methods[ci] = h2v1_fancy_upsample;
513
394
      } else {
514
394
#ifdef WITH_SIMD
515
394
        if (jsimd_set_h2v1_upsample(cinfo))
516
0
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
394
        else
518
394
#endif
519
394
          upsample->methods[ci] = h2v1_upsample;
520
394
      }
521
5.45k
    } else if (h_in_group == h_out_group &&
522
986
               v_in_group * 2 == v_out_group && do_fancy) {
523
      /* Non-fancy upsampling is handled by the generic method */
524
#if defined(WITH_SIMD) && (SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM)
525
      if (jsimd_set_h1v2_fancy_upsample(cinfo))
526
        upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
527
      else
528
#endif
529
191
        upsample->methods[ci] = h1v2_fancy_upsample;
530
191
      upsample->pub.need_context_rows = TRUE;
531
5.26k
    } else if (h_in_group * 2 == h_out_group &&
532
3.95k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
3.54k
      if (do_fancy && compptr->downsampled_width > 2) {
535
3.03k
#ifdef WITH_SIMD
536
3.03k
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
0
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
3.03k
        else
539
3.03k
#endif
540
3.03k
          upsample->methods[ci] = h2v2_fancy_upsample;
541
3.03k
        upsample->pub.need_context_rows = TRUE;
542
3.03k
      } else {
543
518
#ifdef WITH_SIMD
544
518
        if (jsimd_set_h2v2_upsample(cinfo))
545
0
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
518
        else
547
518
#endif
548
518
          upsample->methods[ci] = h2v2_upsample;
549
518
      }
550
3.54k
    } else if ((h_out_group % h_in_group) == 0 &&
551
1.70k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
1.70k
      upsample->methods[ci] = int_upsample;
554
1.70k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
1.70k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
1.70k
    } else
557
18
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
11.5k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
6.19k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
6.19k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
6.19k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
6.19k
                               (long)cinfo->max_h_samp_factor),
563
6.19k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
6.19k
    }
565
11.5k
  }
566
5.25k
}
j12init_upsampler
Line
Count
Source
438
1.22k
{
439
1.22k
  my_upsample_ptr upsample;
440
1.22k
  int ci;
441
1.22k
  jpeg_component_info *compptr;
442
1.22k
  boolean need_buffer, do_fancy;
443
1.22k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
1.22k
#ifdef D_LOSSLESS_SUPPORTED
446
1.22k
  if (cinfo->master->lossless) {
447
#if BITS_IN_JSAMPLE == 8
448
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
449
#else
450
599
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
599
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
599
  } else
455
622
#endif
456
622
  {
457
622
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
622
  }
460
461
1.22k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
1.22k
    upsample = (my_upsample_ptr)
463
1.22k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
1.22k
                                  sizeof(my_upsampler));
465
1.22k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
1.22k
    upsample->pub.start_pass = start_pass_upsample;
467
1.22k
    upsample->pub._upsample = sep_upsample;
468
1.22k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
1.22k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
1.22k
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
473
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
474
475
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
476
   * so don't ask for it.
477
   */
478
1.22k
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
479
480
  /* Verify we can handle the sampling factors, select per-component methods,
481
   * and create storage as needed.
482
   */
483
4.76k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
3.54k
       ci++, compptr++) {
485
    /* Compute size of an "input group" after IDCT scaling.  This many samples
486
     * are to be converted to max_h_samp_factor * max_v_samp_factor components.
487
     */
488
3.54k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
3.54k
                 cinfo->_min_DCT_scaled_size;
490
3.54k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
3.54k
                 cinfo->_min_DCT_scaled_size;
492
3.54k
    h_out_group = cinfo->max_h_samp_factor;
493
3.54k
    v_out_group = cinfo->max_v_samp_factor;
494
3.54k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
3.54k
    need_buffer = TRUE;
496
3.54k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
0
      upsample->methods[ci] = noop_upsample;
499
0
      need_buffer = FALSE;
500
3.54k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
1.55k
      upsample->methods[ci] = fullsize_upsample;
503
1.55k
      need_buffer = FALSE;
504
1.98k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
309
      if (do_fancy && compptr->downsampled_width > 2) {
507
#ifdef WITH_SIMD
508
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
        else
511
#endif
512
37
          upsample->methods[ci] = h2v1_fancy_upsample;
513
272
      } else {
514
#ifdef WITH_SIMD
515
        if (jsimd_set_h2v1_upsample(cinfo))
516
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
        else
518
#endif
519
272
          upsample->methods[ci] = h2v1_upsample;
520
272
      }
521
1.67k
    } else if (h_in_group == h_out_group &&
522
430
               v_in_group * 2 == v_out_group && do_fancy) {
523
      /* Non-fancy upsampling is handled by the generic method */
524
#if defined(WITH_SIMD) && (SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM)
525
      if (jsimd_set_h1v2_fancy_upsample(cinfo))
526
        upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
527
      else
528
#endif
529
129
        upsample->methods[ci] = h1v2_fancy_upsample;
530
129
      upsample->pub.need_context_rows = TRUE;
531
1.54k
    } else if (h_in_group * 2 == h_out_group &&
532
939
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
558
      if (do_fancy && compptr->downsampled_width > 2) {
535
#ifdef WITH_SIMD
536
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
        else
539
#endif
540
117
          upsample->methods[ci] = h2v2_fancy_upsample;
541
117
        upsample->pub.need_context_rows = TRUE;
542
441
      } else {
543
#ifdef WITH_SIMD
544
        if (jsimd_set_h2v2_upsample(cinfo))
545
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
        else
547
#endif
548
441
          upsample->methods[ci] = h2v2_upsample;
549
441
      }
550
987
    } else if ((h_out_group % h_in_group) == 0 &&
551
971
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
960
      upsample->methods[ci] = int_upsample;
554
960
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
960
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
960
    } else
557
27
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
3.54k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
1.95k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
1.95k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
1.95k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
1.95k
                               (long)cinfo->max_h_samp_factor),
563
1.95k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
1.95k
    }
565
3.54k
  }
566
1.22k
}
j16init_upsampler
Line
Count
Source
438
640
{
439
640
  my_upsample_ptr upsample;
440
640
  int ci;
441
640
  jpeg_component_info *compptr;
442
640
  boolean need_buffer, do_fancy;
443
640
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
640
#ifdef D_LOSSLESS_SUPPORTED
446
640
  if (cinfo->master->lossless) {
447
#if BITS_IN_JSAMPLE == 8
448
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
449
#else
450
640
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
640
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
640
  } else
455
0
#endif
456
0
  {
457
0
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
0
  }
460
461
640
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
640
    upsample = (my_upsample_ptr)
463
640
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
640
                                  sizeof(my_upsampler));
465
640
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
640
    upsample->pub.start_pass = start_pass_upsample;
467
640
    upsample->pub._upsample = sep_upsample;
468
640
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
640
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
640
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
473
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
474
475
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
476
   * so don't ask for it.
477
   */
478
640
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
479
480
  /* Verify we can handle the sampling factors, select per-component methods,
481
   * and create storage as needed.
482
   */
483
2.57k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
1.93k
       ci++, compptr++) {
485
    /* Compute size of an "input group" after IDCT scaling.  This many samples
486
     * are to be converted to max_h_samp_factor * max_v_samp_factor components.
487
     */
488
1.93k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
1.93k
                 cinfo->_min_DCT_scaled_size;
490
1.93k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
1.93k
                 cinfo->_min_DCT_scaled_size;
492
1.93k
    h_out_group = cinfo->max_h_samp_factor;
493
1.93k
    v_out_group = cinfo->max_v_samp_factor;
494
1.93k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
1.93k
    need_buffer = TRUE;
496
1.93k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
0
      upsample->methods[ci] = noop_upsample;
499
0
      need_buffer = FALSE;
500
1.93k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
633
      upsample->methods[ci] = fullsize_upsample;
503
633
      need_buffer = FALSE;
504
1.30k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
259
      if (do_fancy && compptr->downsampled_width > 2) {
507
#ifdef WITH_SIMD
508
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
        else
511
#endif
512
0
          upsample->methods[ci] = h2v1_fancy_upsample;
513
259
      } else {
514
#ifdef WITH_SIMD
515
        if (jsimd_set_h2v1_upsample(cinfo))
516
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
        else
518
#endif
519
259
          upsample->methods[ci] = h2v1_upsample;
520
259
      }
521
1.04k
    } else if (h_in_group == h_out_group &&
522
163
               v_in_group * 2 == v_out_group && do_fancy) {
523
      /* Non-fancy upsampling is handled by the generic method */
524
#if defined(WITH_SIMD) && (SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM)
525
      if (jsimd_set_h1v2_fancy_upsample(cinfo))
526
        upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
527
      else
528
#endif
529
0
        upsample->methods[ci] = h1v2_fancy_upsample;
530
0
      upsample->pub.need_context_rows = TRUE;
531
1.04k
    } else if (h_in_group * 2 == h_out_group &&
532
826
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
598
      if (do_fancy && compptr->downsampled_width > 2) {
535
#ifdef WITH_SIMD
536
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
        else
539
#endif
540
0
          upsample->methods[ci] = h2v2_fancy_upsample;
541
0
        upsample->pub.need_context_rows = TRUE;
542
598
      } else {
543
#ifdef WITH_SIMD
544
        if (jsimd_set_h2v2_upsample(cinfo))
545
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
        else
547
#endif
548
598
          upsample->methods[ci] = h2v2_upsample;
549
598
      }
550
598
    } else if ((h_out_group % h_in_group) == 0 &&
551
440
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
430
      upsample->methods[ci] = int_upsample;
554
430
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
430
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
430
    } else
557
18
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
1.93k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
1.28k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
1.28k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
1.28k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
1.28k
                               (long)cinfo->max_h_samp_factor),
563
1.28k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
1.28k
    }
565
1.93k
  }
566
640
}
567
568
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */