Coverage Report

Created: 2025-11-24 06:49

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