Coverage Report

Created: 2026-04-12 07:01

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
29.3k
{
48
29.3k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
29.3k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
29.3k
  upsample->rows_to_go = cinfo->output_height;
54
29.3k
}
jdsample-8.c:start_pass_upsample
Line
Count
Source
47
27.7k
{
48
27.7k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
27.7k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
27.7k
  upsample->rows_to_go = cinfo->output_height;
54
27.7k
}
jdsample-12.c:start_pass_upsample
Line
Count
Source
47
1.39k
{
48
1.39k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
1.39k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
1.39k
  upsample->rows_to_go = cinfo->output_height;
54
1.39k
}
jdsample-16.c:start_pass_upsample
Line
Count
Source
47
135
{
48
135
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
135
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
135
  upsample->rows_to_go = cinfo->output_height;
54
135
}
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
71.3M
{
71
71.3M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
71.3M
  int ci;
73
71.3M
  jpeg_component_info *compptr;
74
71.3M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
71.3M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
125M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
86.8M
         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
86.8M
      (*upsample->methods[ci]) (cinfo, compptr,
87
86.8M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
86.8M
        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
86.8M
    }
95
38.2M
    upsample->next_row_out = 0;
96
38.2M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
71.3M
  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
71.3M
  if (num_rows > upsample->rows_to_go)
106
10.1k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
71.3M
  out_rows_avail -= *out_row_ctr;
109
71.3M
  if (num_rows > out_rows_avail)
110
33.0M
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
71.3M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
71.3M
                                      (JDIMENSION)upsample->next_row_out,
117
71.3M
                                      output_buf + *out_row_ctr,
118
71.3M
                                      (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
71.3M
  *out_row_ctr += num_rows;
127
71.3M
  upsample->rows_to_go -= num_rows;
128
71.3M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
71.3M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
38.2M
    (*in_row_group_ctr)++;
132
71.3M
}
jdsample-8.c:sep_upsample
Line
Count
Source
70
71.3M
{
71
71.3M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
71.3M
  int ci;
73
71.3M
  jpeg_component_info *compptr;
74
71.3M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
71.3M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
125M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
86.8M
         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
86.8M
      (*upsample->methods[ci]) (cinfo, compptr,
87
86.8M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
86.8M
        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
86.8M
    }
95
38.2M
    upsample->next_row_out = 0;
96
38.2M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
71.3M
  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
71.3M
  if (num_rows > upsample->rows_to_go)
106
10.1k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
71.3M
  out_rows_avail -= *out_row_ctr;
109
71.3M
  if (num_rows > out_rows_avail)
110
33.0M
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
71.3M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
71.3M
                                      (JDIMENSION)upsample->next_row_out,
117
71.3M
                                      output_buf + *out_row_ctr,
118
71.3M
                                      (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
71.3M
  *out_row_ctr += num_rows;
127
71.3M
  upsample->rows_to_go -= num_rows;
128
71.3M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
71.3M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
38.2M
    (*in_row_group_ctr)++;
132
71.3M
}
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
42.0M
{
152
42.0M
  *output_data_ptr = input_data;
153
42.0M
}
jdsample-8.c:fullsize_upsample
Line
Count
Source
151
42.0M
{
152
42.0M
  *output_data_ptr = input_data;
153
42.0M
}
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
12.4M
{
184
12.4M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
12.4M
  _JSAMPARRAY output_data = *output_data_ptr;
186
12.4M
  register _JSAMPROW inptr, outptr;
187
12.4M
  register _JSAMPLE invalue;
188
12.4M
  register int h;
189
12.4M
  _JSAMPROW outend;
190
12.4M
  int h_expand, v_expand;
191
12.4M
  int inrow, outrow;
192
193
12.4M
  h_expand = upsample->h_expand[compptr->component_index];
194
12.4M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
12.4M
  inrow = outrow = 0;
197
26.7M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
14.2M
    inptr = input_data[inrow];
200
14.2M
    outptr = output_data[outrow];
201
14.2M
    outend = outptr + cinfo->output_width;
202
940M
    while (outptr < outend) {
203
926M
      invalue = *inptr++;
204
2.60G
      for (h = h_expand; h > 0; h--) {
205
1.68G
        *outptr++ = invalue;
206
1.68G
      }
207
926M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
14.2M
    if (v_expand > 1) {
210
10.2M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
10.2M
                         v_expand - 1, cinfo->output_width);
212
10.2M
    }
213
14.2M
    inrow++;
214
14.2M
    outrow += v_expand;
215
14.2M
  }
216
12.4M
}
jdsample-8.c:int_upsample
Line
Count
Source
183
12.4M
{
184
12.4M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
12.4M
  _JSAMPARRAY output_data = *output_data_ptr;
186
12.4M
  register _JSAMPROW inptr, outptr;
187
12.4M
  register _JSAMPLE invalue;
188
12.4M
  register int h;
189
12.4M
  _JSAMPROW outend;
190
12.4M
  int h_expand, v_expand;
191
12.4M
  int inrow, outrow;
192
193
12.4M
  h_expand = upsample->h_expand[compptr->component_index];
194
12.4M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
12.4M
  inrow = outrow = 0;
197
26.7M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
14.2M
    inptr = input_data[inrow];
200
14.2M
    outptr = output_data[outrow];
201
14.2M
    outend = outptr + cinfo->output_width;
202
940M
    while (outptr < outend) {
203
926M
      invalue = *inptr++;
204
2.60G
      for (h = h_expand; h > 0; h--) {
205
1.68G
        *outptr++ = invalue;
206
1.68G
      }
207
926M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
14.2M
    if (v_expand > 1) {
210
10.2M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
10.2M
                         v_expand - 1, cinfo->output_width);
212
10.2M
    }
213
14.2M
    inrow++;
214
14.2M
    outrow += v_expand;
215
14.2M
  }
216
12.4M
}
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
1.30M
{
228
1.30M
  _JSAMPARRAY output_data = *output_data_ptr;
229
1.30M
  register _JSAMPROW inptr, outptr;
230
1.30M
  register _JSAMPLE invalue;
231
1.30M
  _JSAMPROW outend;
232
1.30M
  int inrow;
233
234
5.03M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
3.73M
    inptr = input_data[inrow];
236
3.73M
    outptr = output_data[inrow];
237
3.73M
    outend = outptr + cinfo->output_width;
238
10.9M
    while (outptr < outend) {
239
7.19M
      invalue = *inptr++;
240
7.19M
      *outptr++ = invalue;
241
7.19M
      *outptr++ = invalue;
242
7.19M
    }
243
3.73M
  }
244
1.30M
}
jdsample-8.c:h2v1_upsample
Line
Count
Source
227
1.30M
{
228
1.30M
  _JSAMPARRAY output_data = *output_data_ptr;
229
1.30M
  register _JSAMPROW inptr, outptr;
230
1.30M
  register _JSAMPLE invalue;
231
1.30M
  _JSAMPROW outend;
232
1.30M
  int inrow;
233
234
5.03M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
3.73M
    inptr = input_data[inrow];
236
3.73M
    outptr = output_data[inrow];
237
3.73M
    outend = outptr + cinfo->output_width;
238
10.9M
    while (outptr < outend) {
239
7.19M
      invalue = *inptr++;
240
7.19M
      *outptr++ = invalue;
241
7.19M
      *outptr++ = invalue;
242
7.19M
    }
243
3.73M
  }
244
1.30M
}
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
1.81M
{
256
1.81M
  _JSAMPARRAY output_data = *output_data_ptr;
257
1.81M
  register _JSAMPROW inptr, outptr;
258
1.81M
  register _JSAMPLE invalue;
259
1.81M
  _JSAMPROW outend;
260
1.81M
  int inrow, outrow;
261
262
1.81M
  inrow = outrow = 0;
263
4.22M
  while (outrow < cinfo->max_v_samp_factor) {
264
2.41M
    inptr = input_data[inrow];
265
2.41M
    outptr = output_data[outrow];
266
2.41M
    outend = outptr + cinfo->output_width;
267
7.06M
    while (outptr < outend) {
268
4.65M
      invalue = *inptr++;
269
4.65M
      *outptr++ = invalue;
270
4.65M
      *outptr++ = invalue;
271
4.65M
    }
272
2.41M
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
2.41M
                       cinfo->output_width);
274
2.41M
    inrow++;
275
2.41M
    outrow += 2;
276
2.41M
  }
277
1.81M
}
jdsample-8.c:h2v2_upsample
Line
Count
Source
255
1.81M
{
256
1.81M
  _JSAMPARRAY output_data = *output_data_ptr;
257
1.81M
  register _JSAMPROW inptr, outptr;
258
1.81M
  register _JSAMPLE invalue;
259
1.81M
  _JSAMPROW outend;
260
1.81M
  int inrow, outrow;
261
262
1.81M
  inrow = outrow = 0;
263
4.22M
  while (outrow < cinfo->max_v_samp_factor) {
264
2.41M
    inptr = input_data[inrow];
265
2.41M
    outptr = output_data[outrow];
266
2.41M
    outend = outptr + cinfo->output_width;
267
7.06M
    while (outptr < outend) {
268
4.65M
      invalue = *inptr++;
269
4.65M
      *outptr++ = invalue;
270
4.65M
      *outptr++ = invalue;
271
4.65M
    }
272
2.41M
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
2.41M
                       cinfo->output_width);
274
2.41M
    inrow++;
275
2.41M
    outrow += 2;
276
2.41M
  }
277
1.81M
}
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
14.1M
{
299
14.1M
  _JSAMPARRAY output_data = *output_data_ptr;
300
14.1M
  register _JSAMPROW inptr, outptr;
301
14.1M
  register int invalue;
302
14.1M
  register JDIMENSION colctr;
303
14.1M
  int inrow;
304
305
36.5M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
22.3M
    inptr = input_data[inrow];
307
22.3M
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
22.3M
    invalue = *inptr++;
310
22.3M
    *outptr++ = (_JSAMPLE)invalue;
311
22.3M
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
885M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer component + 1/4 * further component */
315
862M
      invalue = (*inptr++) * 3;
316
862M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
862M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
862M
    }
319
320
    /* Special case for last column */
321
22.3M
    invalue = *inptr;
322
22.3M
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
22.3M
    *outptr++ = (_JSAMPLE)invalue;
324
22.3M
  }
325
14.1M
}
jdsample-8.c:h2v1_fancy_upsample
Line
Count
Source
298
14.1M
{
299
14.1M
  _JSAMPARRAY output_data = *output_data_ptr;
300
14.1M
  register _JSAMPROW inptr, outptr;
301
14.1M
  register int invalue;
302
14.1M
  register JDIMENSION colctr;
303
14.1M
  int inrow;
304
305
36.5M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
22.3M
    inptr = input_data[inrow];
307
22.3M
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
22.3M
    invalue = *inptr++;
310
22.3M
    *outptr++ = (_JSAMPLE)invalue;
311
22.3M
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
885M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer component + 1/4 * further component */
315
862M
      invalue = (*inptr++) * 3;
316
862M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
862M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
862M
    }
319
320
    /* Special case for last column */
321
22.3M
    invalue = *inptr;
322
22.3M
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
22.3M
    *outptr++ = (_JSAMPLE)invalue;
324
22.3M
  }
325
14.1M
}
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
8.09M
{
339
8.09M
  _JSAMPARRAY output_data = *output_data_ptr;
340
8.09M
  _JSAMPROW inptr0, inptr1, outptr;
341
#if BITS_IN_JSAMPLE == 8
342
  int thiscolsum, bias;
343
#else
344
  JLONG thiscolsum, bias;
345
#endif
346
8.09M
  JDIMENSION colctr;
347
8.09M
  int inrow, outrow, v;
348
349
8.09M
  inrow = outrow = 0;
350
17.6M
  while (outrow < cinfo->max_v_samp_factor) {
351
28.7M
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
19.1M
      inptr0 = input_data[inrow];
354
19.1M
      if (v == 0) {             /* next nearest is row above */
355
9.58M
        inptr1 = input_data[inrow - 1];
356
9.58M
        bias = 1;
357
9.58M
      } else {                  /* next nearest is row below */
358
9.58M
        inptr1 = input_data[inrow + 1];
359
9.58M
        bias = 2;
360
9.58M
      }
361
19.1M
      outptr = output_data[outrow++];
362
363
2.05G
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
2.03G
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
2.03G
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
2.03G
      }
367
19.1M
    }
368
9.58M
    inrow++;
369
9.58M
  }
370
8.09M
}
jdsample-8.c:h1v2_fancy_upsample
Line
Count
Source
338
8.09M
{
339
8.09M
  _JSAMPARRAY output_data = *output_data_ptr;
340
8.09M
  _JSAMPROW inptr0, inptr1, outptr;
341
8.09M
#if BITS_IN_JSAMPLE == 8
342
8.09M
  int thiscolsum, bias;
343
#else
344
  JLONG thiscolsum, bias;
345
#endif
346
8.09M
  JDIMENSION colctr;
347
8.09M
  int inrow, outrow, v;
348
349
8.09M
  inrow = outrow = 0;
350
17.6M
  while (outrow < cinfo->max_v_samp_factor) {
351
28.7M
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
19.1M
      inptr0 = input_data[inrow];
354
19.1M
      if (v == 0) {             /* next nearest is row above */
355
9.58M
        inptr1 = input_data[inrow - 1];
356
9.58M
        bias = 1;
357
9.58M
      } else {                  /* next nearest is row below */
358
9.58M
        inptr1 = input_data[inrow + 1];
359
9.58M
        bias = 2;
360
9.58M
      }
361
19.1M
      outptr = output_data[outrow++];
362
363
2.05G
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
2.03G
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
2.03G
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
2.03G
      }
367
19.1M
    }
368
9.58M
    inrow++;
369
9.58M
  }
370
8.09M
}
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
6.92M
{
385
6.92M
  _JSAMPARRAY output_data = *output_data_ptr;
386
6.92M
  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
6.92M
  register JDIMENSION colctr;
393
6.92M
  int inrow, outrow, v;
394
395
6.92M
  inrow = outrow = 0;
396
15.7M
  while (outrow < cinfo->max_v_samp_factor) {
397
26.5M
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
17.6M
      inptr0 = input_data[inrow];
400
17.6M
      if (v == 0)               /* next nearest is row above */
401
8.84M
        inptr1 = input_data[inrow - 1];
402
8.84M
      else                      /* next nearest is row below */
403
8.84M
        inptr1 = input_data[inrow + 1];
404
17.6M
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
17.6M
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
17.6M
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
17.6M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
17.6M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
17.6M
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
1.64G
      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
1.62G
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
1.62G
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
1.62G
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
1.62G
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
1.62G
      }
422
423
      /* Special case for last column */
424
17.6M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
17.6M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
17.6M
    }
427
8.84M
    inrow++;
428
8.84M
  }
429
6.92M
}
jdsample-8.c:h2v2_fancy_upsample
Line
Count
Source
384
6.92M
{
385
6.92M
  _JSAMPARRAY output_data = *output_data_ptr;
386
6.92M
  register _JSAMPROW inptr0, inptr1, outptr;
387
6.92M
#if BITS_IN_JSAMPLE == 8
388
6.92M
  register int thiscolsum, lastcolsum, nextcolsum;
389
#else
390
  register JLONG thiscolsum, lastcolsum, nextcolsum;
391
#endif
392
6.92M
  register JDIMENSION colctr;
393
6.92M
  int inrow, outrow, v;
394
395
6.92M
  inrow = outrow = 0;
396
15.7M
  while (outrow < cinfo->max_v_samp_factor) {
397
26.5M
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
17.6M
      inptr0 = input_data[inrow];
400
17.6M
      if (v == 0)               /* next nearest is row above */
401
8.84M
        inptr1 = input_data[inrow - 1];
402
8.84M
      else                      /* next nearest is row below */
403
8.84M
        inptr1 = input_data[inrow + 1];
404
17.6M
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
17.6M
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
17.6M
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
17.6M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
17.6M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
17.6M
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
1.64G
      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
1.62G
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
1.62G
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
1.62G
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
1.62G
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
1.62G
      }
422
423
      /* Special case for last column */
424
17.6M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
17.6M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
17.6M
    }
427
8.84M
    inrow++;
428
8.84M
  }
429
6.92M
}
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
53.0k
{
439
53.0k
  my_upsample_ptr upsample;
440
53.0k
  int ci;
441
53.0k
  jpeg_component_info *compptr;
442
53.0k
  boolean need_buffer, do_fancy;
443
53.0k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
53.0k
#ifdef D_LOSSLESS_SUPPORTED
446
53.0k
  if (cinfo->master->lossless) {
447
#if BITS_IN_JSAMPLE == 8
448
6.54k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
449
#else
450
10.0k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
10.0k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
16.5k
  } else
455
36.4k
#endif
456
36.4k
  {
457
36.4k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
36.4k
  }
460
461
53.0k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
53.0k
    upsample = (my_upsample_ptr)
463
53.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
53.0k
                                  sizeof(my_upsampler));
465
53.0k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
53.0k
    upsample->pub.start_pass = start_pass_upsample;
467
53.0k
    upsample->pub._upsample = sep_upsample;
468
53.0k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
53.0k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
53.0k
  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
53.0k
  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
189k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
136k
       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
136k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
136k
                 cinfo->_min_DCT_scaled_size;
490
136k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
136k
                 cinfo->_min_DCT_scaled_size;
492
136k
    h_out_group = cinfo->max_h_samp_factor;
493
136k
    v_out_group = cinfo->max_v_samp_factor;
494
136k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
136k
    need_buffer = TRUE;
496
136k
    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
136k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
55.1k
      upsample->methods[ci] = fullsize_upsample;
503
55.1k
      need_buffer = FALSE;
504
80.9k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
10.6k
      if (do_fancy && compptr->downsampled_width > 2) {
507
#ifdef WITH_SIMD
508
4.01k
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
0
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
4.01k
        else
511
4.01k
#endif
512
4.01k
          upsample->methods[ci] = h2v1_fancy_upsample;
513
5.67k
      } else {
514
#ifdef WITH_SIMD
515
3.04k
        if (jsimd_set_h2v1_upsample(cinfo))
516
0
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
3.04k
        else
518
3.04k
#endif
519
3.04k
          upsample->methods[ci] = h2v1_upsample;
520
5.67k
      }
521
70.3k
    } else if (h_in_group == h_out_group &&
522
22.2k
               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
8.66k
        upsample->methods[ci] = h1v2_fancy_upsample;
530
8.66k
      upsample->pub.need_context_rows = TRUE;
531
61.6k
    } else if (h_in_group * 2 == h_out_group &&
532
31.6k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
25.9k
      if (do_fancy && compptr->downsampled_width > 2) {
535
#ifdef WITH_SIMD
536
18.8k
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
0
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
18.8k
        else
539
18.8k
#endif
540
18.8k
          upsample->methods[ci] = h2v2_fancy_upsample;
541
20.6k
        upsample->pub.need_context_rows = TRUE;
542
20.6k
      } else {
543
#ifdef WITH_SIMD
544
2.93k
        if (jsimd_set_h2v2_upsample(cinfo))
545
0
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
2.93k
        else
547
2.93k
#endif
548
2.93k
          upsample->methods[ci] = h2v2_upsample;
549
5.29k
      }
550
35.7k
    } else if ((h_out_group % h_in_group) == 0 &&
551
35.5k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
35.3k
      upsample->methods[ci] = int_upsample;
554
35.3k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
35.3k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
35.3k
    } else
557
363
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
136k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
80.5k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
80.5k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
80.5k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
80.5k
                               (long)cinfo->max_h_samp_factor),
563
80.5k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
80.5k
    }
565
136k
  }
566
53.0k
}
jinit_upsampler
Line
Count
Source
438
38.7k
{
439
38.7k
  my_upsample_ptr upsample;
440
38.7k
  int ci;
441
38.7k
  jpeg_component_info *compptr;
442
38.7k
  boolean need_buffer, do_fancy;
443
38.7k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
38.7k
#ifdef D_LOSSLESS_SUPPORTED
446
38.7k
  if (cinfo->master->lossless) {
447
6.54k
#if BITS_IN_JSAMPLE == 8
448
6.54k
    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
6.54k
  } else
455
32.1k
#endif
456
32.1k
  {
457
32.1k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
32.1k
  }
460
461
38.7k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
38.7k
    upsample = (my_upsample_ptr)
463
38.7k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
38.7k
                                  sizeof(my_upsampler));
465
38.7k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
38.7k
    upsample->pub.start_pass = start_pass_upsample;
467
38.7k
    upsample->pub._upsample = sep_upsample;
468
38.7k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
38.7k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
38.7k
  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
38.7k
  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
134k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
95.3k
       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
95.3k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
95.3k
                 cinfo->_min_DCT_scaled_size;
490
95.3k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
95.3k
                 cinfo->_min_DCT_scaled_size;
492
95.3k
    h_out_group = cinfo->max_h_samp_factor;
493
95.3k
    v_out_group = cinfo->max_v_samp_factor;
494
95.3k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
95.3k
    need_buffer = TRUE;
496
95.3k
    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
95.3k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
41.8k
      upsample->methods[ci] = fullsize_upsample;
503
41.8k
      need_buffer = FALSE;
504
53.5k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
7.06k
      if (do_fancy && compptr->downsampled_width > 2) {
507
4.01k
#ifdef WITH_SIMD
508
4.01k
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
0
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
4.01k
        else
511
4.01k
#endif
512
4.01k
          upsample->methods[ci] = h2v1_fancy_upsample;
513
4.01k
      } else {
514
3.04k
#ifdef WITH_SIMD
515
3.04k
        if (jsimd_set_h2v1_upsample(cinfo))
516
0
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
3.04k
        else
518
3.04k
#endif
519
3.04k
          upsample->methods[ci] = h2v1_upsample;
520
3.04k
      }
521
46.4k
    } else if (h_in_group == h_out_group &&
522
14.2k
               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
6.92k
        upsample->methods[ci] = h1v2_fancy_upsample;
530
6.92k
      upsample->pub.need_context_rows = TRUE;
531
39.5k
    } else if (h_in_group * 2 == h_out_group &&
532
25.1k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
21.8k
      if (do_fancy && compptr->downsampled_width > 2) {
535
18.8k
#ifdef WITH_SIMD
536
18.8k
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
0
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
18.8k
        else
539
18.8k
#endif
540
18.8k
          upsample->methods[ci] = h2v2_fancy_upsample;
541
18.8k
        upsample->pub.need_context_rows = TRUE;
542
18.8k
      } else {
543
2.93k
#ifdef WITH_SIMD
544
2.93k
        if (jsimd_set_h2v2_upsample(cinfo))
545
0
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
2.93k
        else
547
2.93k
#endif
548
2.93k
          upsample->methods[ci] = h2v2_upsample;
549
2.93k
      }
550
21.8k
    } else if ((h_out_group % h_in_group) == 0 &&
551
17.6k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
17.6k
      upsample->methods[ci] = int_upsample;
554
17.6k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
17.6k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
17.6k
    } else
557
123
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
95.3k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
53.4k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
53.4k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
53.4k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
53.4k
                               (long)cinfo->max_h_samp_factor),
563
53.4k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
53.4k
    }
565
95.3k
  }
566
38.7k
}
j12init_upsampler
Line
Count
Source
438
9.16k
{
439
9.16k
  my_upsample_ptr upsample;
440
9.16k
  int ci;
441
9.16k
  jpeg_component_info *compptr;
442
9.16k
  boolean need_buffer, do_fancy;
443
9.16k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
9.16k
#ifdef D_LOSSLESS_SUPPORTED
446
9.16k
  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
4.89k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
4.89k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
4.89k
  } else
455
4.27k
#endif
456
4.27k
  {
457
4.27k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
4.27k
  }
460
461
9.16k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
9.16k
    upsample = (my_upsample_ptr)
463
9.16k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
9.16k
                                  sizeof(my_upsampler));
465
9.16k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
9.16k
    upsample->pub.start_pass = start_pass_upsample;
467
9.16k
    upsample->pub._upsample = sep_upsample;
468
9.16k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
9.16k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
9.16k
  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
9.16k
  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
35.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
26.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
26.0k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
26.0k
                 cinfo->_min_DCT_scaled_size;
490
26.0k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
26.0k
                 cinfo->_min_DCT_scaled_size;
492
26.0k
    h_out_group = cinfo->max_h_samp_factor;
493
26.0k
    v_out_group = cinfo->max_v_samp_factor;
494
26.0k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
26.0k
    need_buffer = TRUE;
496
26.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
26.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
8.77k
      upsample->methods[ci] = fullsize_upsample;
503
8.77k
      need_buffer = FALSE;
504
17.3k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
2.27k
      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
923
          upsample->methods[ci] = h2v1_fancy_upsample;
513
1.34k
      } else {
514
#ifdef WITH_SIMD
515
        if (jsimd_set_h2v1_upsample(cinfo))
516
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
        else
518
#endif
519
1.34k
          upsample->methods[ci] = h2v1_upsample;
520
1.34k
      }
521
15.0k
    } else if (h_in_group == h_out_group &&
522
5.07k
               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
1.73k
        upsample->methods[ci] = h1v2_fancy_upsample;
530
1.73k
      upsample->pub.need_context_rows = TRUE;
531
13.2k
    } else if (h_in_group * 2 == h_out_group &&
532
4.64k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
2.97k
      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
1.75k
          upsample->methods[ci] = h2v2_fancy_upsample;
541
1.75k
        upsample->pub.need_context_rows = TRUE;
542
1.75k
      } else {
543
#ifdef WITH_SIMD
544
        if (jsimd_set_h2v2_upsample(cinfo))
545
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
        else
547
#endif
548
1.22k
          upsample->methods[ci] = h2v2_upsample;
549
1.22k
      }
550
10.3k
    } else if ((h_out_group % h_in_group) == 0 &&
551
10.2k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
10.1k
      upsample->methods[ci] = int_upsample;
554
10.1k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
10.1k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
10.1k
    } else
557
133
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
26.0k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
17.1k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
17.1k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
17.1k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
17.1k
                               (long)cinfo->max_h_samp_factor),
563
17.1k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
17.1k
    }
565
26.0k
  }
566
9.16k
}
j16init_upsampler
Line
Count
Source
438
5.12k
{
439
5.12k
  my_upsample_ptr upsample;
440
5.12k
  int ci;
441
5.12k
  jpeg_component_info *compptr;
442
5.12k
  boolean need_buffer, do_fancy;
443
5.12k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
5.12k
#ifdef D_LOSSLESS_SUPPORTED
446
5.12k
  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
5.12k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
5.12k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
5.12k
  } 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
5.12k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
5.12k
    upsample = (my_upsample_ptr)
463
5.12k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
5.12k
                                  sizeof(my_upsampler));
465
5.12k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
5.12k
    upsample->pub.start_pass = start_pass_upsample;
467
5.12k
    upsample->pub._upsample = sep_upsample;
468
5.12k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
5.12k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
5.12k
  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.12k
  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
19.7k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
14.6k
       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
14.6k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
14.6k
                 cinfo->_min_DCT_scaled_size;
490
14.6k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
14.6k
                 cinfo->_min_DCT_scaled_size;
492
14.6k
    h_out_group = cinfo->max_h_samp_factor;
493
14.6k
    v_out_group = cinfo->max_v_samp_factor;
494
14.6k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
14.6k
    need_buffer = TRUE;
496
14.6k
    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
14.6k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
4.53k
      upsample->methods[ci] = fullsize_upsample;
503
4.53k
      need_buffer = FALSE;
504
10.0k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
1.27k
      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
1.27k
      } else {
514
#ifdef WITH_SIMD
515
        if (jsimd_set_h2v1_upsample(cinfo))
516
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
        else
518
#endif
519
1.27k
          upsample->methods[ci] = h2v1_upsample;
520
1.27k
      }
521
8.81k
    } else if (h_in_group == h_out_group &&
522
2.89k
               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
8.81k
    } else if (h_in_group * 2 == h_out_group &&
532
1.90k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
1.14k
      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
1.14k
      } else {
543
#ifdef WITH_SIMD
544
        if (jsimd_set_h2v2_upsample(cinfo))
545
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
        else
547
#endif
548
1.14k
          upsample->methods[ci] = h2v2_upsample;
549
1.14k
      }
550
7.67k
    } else if ((h_out_group % h_in_group) == 0 &&
551
7.62k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
7.56k
      upsample->methods[ci] = int_upsample;
554
7.56k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
7.56k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
7.56k
    } else
557
107
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
14.6k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
9.98k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
9.98k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
9.98k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
9.98k
                               (long)cinfo->max_h_samp_factor),
563
9.98k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
9.98k
    }
565
14.6k
  }
566
5.12k
}
567
568
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */