Coverage Report

Created: 2026-10-17 06:57

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
2.74k
{
48
2.74k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
2.74k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
2.74k
  upsample->rows_to_go = cinfo->output_height;
54
2.74k
}
jdsample-8.c:start_pass_upsample
Line
Count
Source
47
2.55k
{
48
2.55k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
2.55k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
2.55k
  upsample->rows_to_go = cinfo->output_height;
54
2.55k
}
jdsample-12.c:start_pass_upsample
Line
Count
Source
47
139
{
48
139
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
139
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
139
  upsample->rows_to_go = cinfo->output_height;
54
139
}
jdsample-16.c:start_pass_upsample
Line
Count
Source
47
50
{
48
50
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
50
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
50
  upsample->rows_to_go = cinfo->output_height;
54
50
}
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
4.03M
{
71
4.03M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
4.03M
  int ci;
73
4.03M
  jpeg_component_info *compptr;
74
4.03M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
4.03M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
4.94M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
2.66M
         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
2.66M
      (*upsample->methods[ci]) (cinfo, compptr,
87
2.66M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
2.66M
        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
2.66M
    }
95
2.28M
    upsample->next_row_out = 0;
96
2.28M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
4.03M
  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
4.03M
  if (num_rows > upsample->rows_to_go)
106
620
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
4.03M
  out_rows_avail -= *out_row_ctr;
109
4.03M
  if (num_rows > out_rows_avail)
110
1.75M
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
4.03M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
4.03M
                                      (JDIMENSION)upsample->next_row_out,
117
4.03M
                                      output_buf + *out_row_ctr,
118
4.03M
                                      (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
4.03M
  *out_row_ctr += num_rows;
127
4.03M
  upsample->rows_to_go -= num_rows;
128
4.03M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
4.03M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
2.28M
    (*in_row_group_ctr)++;
132
4.03M
}
jdsample-8.c:sep_upsample
Line
Count
Source
70
4.03M
{
71
4.03M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
4.03M
  int ci;
73
4.03M
  jpeg_component_info *compptr;
74
4.03M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
4.03M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
4.94M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
2.66M
         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
2.66M
      (*upsample->methods[ci]) (cinfo, compptr,
87
2.66M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
2.66M
        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
2.66M
    }
95
2.28M
    upsample->next_row_out = 0;
96
2.28M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
4.03M
  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
4.03M
  if (num_rows > upsample->rows_to_go)
106
620
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
4.03M
  out_rows_avail -= *out_row_ctr;
109
4.03M
  if (num_rows > out_rows_avail)
110
1.75M
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
4.03M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
4.03M
                                      (JDIMENSION)upsample->next_row_out,
117
4.03M
                                      output_buf + *out_row_ctr,
118
4.03M
                                      (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
4.03M
  *out_row_ctr += num_rows;
127
4.03M
  upsample->rows_to_go -= num_rows;
128
4.03M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
4.03M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
2.28M
    (*in_row_group_ctr)++;
132
4.03M
}
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
2.18M
{
152
2.18M
  *output_data_ptr = input_data;
153
2.18M
}
jdsample-8.c:fullsize_upsample
Line
Count
Source
151
2.18M
{
152
2.18M
  *output_data_ptr = input_data;
153
2.18M
}
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
96.4k
{
184
96.4k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
96.4k
  _JSAMPARRAY output_data = *output_data_ptr;
186
96.4k
  register _JSAMPROW inptr, outptr;
187
96.4k
  register _JSAMPLE invalue;
188
96.4k
  register int h;
189
96.4k
  _JSAMPROW outend;
190
96.4k
  int h_expand, v_expand;
191
96.4k
  int inrow, outrow;
192
193
96.4k
  h_expand = upsample->h_expand[compptr->component_index];
194
96.4k
  v_expand = upsample->v_expand[compptr->component_index];
195
196
96.4k
  inrow = outrow = 0;
197
253k
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
156k
    inptr = input_data[inrow];
200
156k
    outptr = output_data[outrow];
201
156k
    outend = outptr + cinfo->output_width;
202
2.11M
    while (outptr < outend) {
203
1.95M
      invalue = *inptr++;
204
6.69M
      for (h = h_expand; h > 0; h--) {
205
4.73M
        *outptr++ = invalue;
206
4.73M
      }
207
1.95M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
156k
    if (v_expand > 1) {
210
53.4k
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
53.4k
                         v_expand - 1, cinfo->output_width);
212
53.4k
    }
213
156k
    inrow++;
214
156k
    outrow += v_expand;
215
156k
  }
216
96.4k
}
jdsample-8.c:int_upsample
Line
Count
Source
183
96.4k
{
184
96.4k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
96.4k
  _JSAMPARRAY output_data = *output_data_ptr;
186
96.4k
  register _JSAMPROW inptr, outptr;
187
96.4k
  register _JSAMPLE invalue;
188
96.4k
  register int h;
189
96.4k
  _JSAMPROW outend;
190
96.4k
  int h_expand, v_expand;
191
96.4k
  int inrow, outrow;
192
193
96.4k
  h_expand = upsample->h_expand[compptr->component_index];
194
96.4k
  v_expand = upsample->v_expand[compptr->component_index];
195
196
96.4k
  inrow = outrow = 0;
197
253k
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
156k
    inptr = input_data[inrow];
200
156k
    outptr = output_data[outrow];
201
156k
    outend = outptr + cinfo->output_width;
202
2.11M
    while (outptr < outend) {
203
1.95M
      invalue = *inptr++;
204
6.69M
      for (h = h_expand; h > 0; h--) {
205
4.73M
        *outptr++ = invalue;
206
4.73M
      }
207
1.95M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
156k
    if (v_expand > 1) {
210
53.4k
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
53.4k
                         v_expand - 1, cinfo->output_width);
212
53.4k
    }
213
156k
    inrow++;
214
156k
    outrow += v_expand;
215
156k
  }
216
96.4k
}
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
90.2k
{
228
90.2k
  _JSAMPARRAY output_data = *output_data_ptr;
229
90.2k
  register _JSAMPROW inptr, outptr;
230
90.2k
  register _JSAMPLE invalue;
231
90.2k
  _JSAMPROW outend;
232
90.2k
  int inrow;
233
234
313k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
223k
    inptr = input_data[inrow];
236
223k
    outptr = output_data[inrow];
237
223k
    outend = outptr + cinfo->output_width;
238
503k
    while (outptr < outend) {
239
279k
      invalue = *inptr++;
240
279k
      *outptr++ = invalue;
241
279k
      *outptr++ = invalue;
242
279k
    }
243
223k
  }
244
90.2k
}
jdsample-8.c:h2v1_upsample
Line
Count
Source
227
90.2k
{
228
90.2k
  _JSAMPARRAY output_data = *output_data_ptr;
229
90.2k
  register _JSAMPROW inptr, outptr;
230
90.2k
  register _JSAMPLE invalue;
231
90.2k
  _JSAMPROW outend;
232
90.2k
  int inrow;
233
234
313k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
223k
    inptr = input_data[inrow];
236
223k
    outptr = output_data[inrow];
237
223k
    outend = outptr + cinfo->output_width;
238
503k
    while (outptr < outend) {
239
279k
      invalue = *inptr++;
240
279k
      *outptr++ = invalue;
241
279k
      *outptr++ = invalue;
242
279k
    }
243
223k
  }
244
90.2k
}
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
69.4k
{
256
69.4k
  _JSAMPARRAY output_data = *output_data_ptr;
257
69.4k
  register _JSAMPROW inptr, outptr;
258
69.4k
  register _JSAMPLE invalue;
259
69.4k
  _JSAMPROW outend;
260
69.4k
  int inrow, outrow;
261
262
69.4k
  inrow = outrow = 0;
263
158k
  while (outrow < cinfo->max_v_samp_factor) {
264
89.4k
    inptr = input_data[inrow];
265
89.4k
    outptr = output_data[outrow];
266
89.4k
    outend = outptr + cinfo->output_width;
267
226k
    while (outptr < outend) {
268
136k
      invalue = *inptr++;
269
136k
      *outptr++ = invalue;
270
136k
      *outptr++ = invalue;
271
136k
    }
272
89.4k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
89.4k
                       cinfo->output_width);
274
89.4k
    inrow++;
275
89.4k
    outrow += 2;
276
89.4k
  }
277
69.4k
}
jdsample-8.c:h2v2_upsample
Line
Count
Source
255
69.4k
{
256
69.4k
  _JSAMPARRAY output_data = *output_data_ptr;
257
69.4k
  register _JSAMPROW inptr, outptr;
258
69.4k
  register _JSAMPLE invalue;
259
69.4k
  _JSAMPROW outend;
260
69.4k
  int inrow, outrow;
261
262
69.4k
  inrow = outrow = 0;
263
158k
  while (outrow < cinfo->max_v_samp_factor) {
264
89.4k
    inptr = input_data[inrow];
265
89.4k
    outptr = output_data[outrow];
266
89.4k
    outend = outptr + cinfo->output_width;
267
226k
    while (outptr < outend) {
268
136k
      invalue = *inptr++;
269
136k
      *outptr++ = invalue;
270
136k
      *outptr++ = invalue;
271
136k
    }
272
89.4k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
89.4k
                       cinfo->output_width);
274
89.4k
    inrow++;
275
89.4k
    outrow += 2;
276
89.4k
  }
277
69.4k
}
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
68.3k
{
299
68.3k
  _JSAMPARRAY output_data = *output_data_ptr;
300
68.3k
  register _JSAMPROW inptr, outptr;
301
68.3k
  register int invalue;
302
68.3k
  register JDIMENSION colctr;
303
68.3k
  int inrow;
304
305
239k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
170k
    inptr = input_data[inrow];
307
170k
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
170k
    invalue = *inptr++;
310
170k
    *outptr++ = (_JSAMPLE)invalue;
311
170k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
5.31M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer component + 1/4 * further component */
315
5.14M
      invalue = (*inptr++) * 3;
316
5.14M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
5.14M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
5.14M
    }
319
320
    /* Special case for last column */
321
170k
    invalue = *inptr;
322
170k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
170k
    *outptr++ = (_JSAMPLE)invalue;
324
170k
  }
325
68.3k
}
jdsample-8.c:h2v1_fancy_upsample
Line
Count
Source
298
68.3k
{
299
68.3k
  _JSAMPARRAY output_data = *output_data_ptr;
300
68.3k
  register _JSAMPROW inptr, outptr;
301
68.3k
  register int invalue;
302
68.3k
  register JDIMENSION colctr;
303
68.3k
  int inrow;
304
305
239k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
170k
    inptr = input_data[inrow];
307
170k
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
170k
    invalue = *inptr++;
310
170k
    *outptr++ = (_JSAMPLE)invalue;
311
170k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
5.31M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer component + 1/4 * further component */
315
5.14M
      invalue = (*inptr++) * 3;
316
5.14M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
5.14M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
5.14M
    }
319
320
    /* Special case for last column */
321
170k
    invalue = *inptr;
322
170k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
170k
    *outptr++ = (_JSAMPLE)invalue;
324
170k
  }
325
68.3k
}
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
117k
{
339
117k
  _JSAMPARRAY output_data = *output_data_ptr;
340
117k
  _JSAMPROW inptr0, inptr1, outptr;
341
#if BITS_IN_JSAMPLE == 8
342
  int thiscolsum, bias;
343
#else
344
  JLONG thiscolsum, bias;
345
#endif
346
117k
  JDIMENSION colctr;
347
117k
  int inrow, outrow, v;
348
349
117k
  inrow = outrow = 0;
350
263k
  while (outrow < cinfo->max_v_samp_factor) {
351
437k
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
291k
      inptr0 = input_data[inrow];
354
291k
      if (v == 0) {             /* next nearest is row above */
355
145k
        inptr1 = input_data[inrow - 1];
356
145k
        bias = 1;
357
145k
      } else {                  /* next nearest is row below */
358
145k
        inptr1 = input_data[inrow + 1];
359
145k
        bias = 2;
360
145k
      }
361
291k
      outptr = output_data[outrow++];
362
363
9.08M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
8.78M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
8.78M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
8.78M
      }
367
291k
    }
368
145k
    inrow++;
369
145k
  }
370
117k
}
jdsample-8.c:h1v2_fancy_upsample
Line
Count
Source
338
117k
{
339
117k
  _JSAMPARRAY output_data = *output_data_ptr;
340
117k
  _JSAMPROW inptr0, inptr1, outptr;
341
117k
#if BITS_IN_JSAMPLE == 8
342
117k
  int thiscolsum, bias;
343
#else
344
  JLONG thiscolsum, bias;
345
#endif
346
117k
  JDIMENSION colctr;
347
117k
  int inrow, outrow, v;
348
349
117k
  inrow = outrow = 0;
350
263k
  while (outrow < cinfo->max_v_samp_factor) {
351
437k
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
291k
      inptr0 = input_data[inrow];
354
291k
      if (v == 0) {             /* next nearest is row above */
355
145k
        inptr1 = input_data[inrow - 1];
356
145k
        bias = 1;
357
145k
      } else {                  /* next nearest is row below */
358
145k
        inptr1 = input_data[inrow + 1];
359
145k
        bias = 2;
360
145k
      }
361
291k
      outptr = output_data[outrow++];
362
363
9.08M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
8.78M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
8.78M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
8.78M
      }
367
291k
    }
368
145k
    inrow++;
369
145k
  }
370
117k
}
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
35.7k
{
385
35.7k
  _JSAMPARRAY output_data = *output_data_ptr;
386
35.7k
  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
35.7k
  register JDIMENSION colctr;
393
35.7k
  int inrow, outrow, v;
394
395
35.7k
  inrow = outrow = 0;
396
81.5k
  while (outrow < cinfo->max_v_samp_factor) {
397
137k
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
91.5k
      inptr0 = input_data[inrow];
400
91.5k
      if (v == 0)               /* next nearest is row above */
401
45.7k
        inptr1 = input_data[inrow - 1];
402
45.7k
      else                      /* next nearest is row below */
403
45.7k
        inptr1 = input_data[inrow + 1];
404
91.5k
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
91.5k
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
91.5k
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
91.5k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
91.5k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
91.5k
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
4.01M
      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
3.92M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
3.92M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
3.92M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
3.92M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
3.92M
      }
422
423
      /* Special case for last column */
424
91.5k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
91.5k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
91.5k
    }
427
45.7k
    inrow++;
428
45.7k
  }
429
35.7k
}
jdsample-8.c:h2v2_fancy_upsample
Line
Count
Source
384
35.7k
{
385
35.7k
  _JSAMPARRAY output_data = *output_data_ptr;
386
35.7k
  register _JSAMPROW inptr0, inptr1, outptr;
387
35.7k
#if BITS_IN_JSAMPLE == 8
388
35.7k
  register int thiscolsum, lastcolsum, nextcolsum;
389
#else
390
  register JLONG thiscolsum, lastcolsum, nextcolsum;
391
#endif
392
35.7k
  register JDIMENSION colctr;
393
35.7k
  int inrow, outrow, v;
394
395
35.7k
  inrow = outrow = 0;
396
81.5k
  while (outrow < cinfo->max_v_samp_factor) {
397
137k
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
91.5k
      inptr0 = input_data[inrow];
400
91.5k
      if (v == 0)               /* next nearest is row above */
401
45.7k
        inptr1 = input_data[inrow - 1];
402
45.7k
      else                      /* next nearest is row below */
403
45.7k
        inptr1 = input_data[inrow + 1];
404
91.5k
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
91.5k
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
91.5k
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
91.5k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
91.5k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
91.5k
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
4.01M
      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
3.92M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
3.92M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
3.92M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
3.92M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
3.92M
      }
422
423
      /* Special case for last column */
424
91.5k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
91.5k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
91.5k
    }
427
45.7k
    inrow++;
428
45.7k
  }
429
35.7k
}
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
6.44k
{
439
6.44k
  my_upsample_ptr upsample;
440
6.44k
  int ci;
441
6.44k
  jpeg_component_info *compptr;
442
6.44k
  boolean need_buffer, do_fancy;
443
6.44k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
6.44k
#ifdef D_LOSSLESS_SUPPORTED
446
6.44k
  if (cinfo->master->lossless) {
447
#if BITS_IN_JSAMPLE == 8
448
1.33k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
449
#else
450
1.81k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
1.81k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
3.15k
  } else
455
3.29k
#endif
456
3.29k
  {
457
3.29k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
3.29k
  }
460
461
6.44k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
6.44k
    upsample = (my_upsample_ptr)
463
6.44k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
6.44k
                                  sizeof(my_upsampler));
465
6.44k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
6.44k
    upsample->pub.start_pass = start_pass_upsample;
467
6.44k
    upsample->pub._upsample = sep_upsample;
468
6.44k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
6.44k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
6.44k
  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
6.44k
  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
18.9k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
12.5k
       ci++, compptr++) {
485
    /* Compute size of an "input group" after IDCT scaling.  This many samples
486
     * are to be converted to max_h_samp_factor * max_v_samp_factor components.
487
     */
488
12.5k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
12.5k
                 cinfo->_min_DCT_scaled_size;
490
12.5k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
12.5k
                 cinfo->_min_DCT_scaled_size;
492
12.5k
    h_out_group = cinfo->max_h_samp_factor;
493
12.5k
    v_out_group = cinfo->max_v_samp_factor;
494
12.5k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
12.5k
    need_buffer = TRUE;
496
12.5k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
0
      upsample->methods[ci] = noop_upsample;
499
0
      need_buffer = FALSE;
500
12.5k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
4.79k
      upsample->methods[ci] = fullsize_upsample;
503
4.79k
      need_buffer = FALSE;
504
7.75k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
1.21k
      if (do_fancy && compptr->downsampled_width > 2) {
507
#ifdef WITH_SIMD
508
220
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
0
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
220
        else
511
220
#endif
512
220
          upsample->methods[ci] = h2v1_fancy_upsample;
513
893
      } else {
514
#ifdef WITH_SIMD
515
357
        if (jsimd_set_h2v1_upsample(cinfo))
516
0
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
357
        else
518
357
#endif
519
357
          upsample->methods[ci] = h2v1_upsample;
520
893
      }
521
6.54k
    } else if (h_in_group == h_out_group &&
522
3.03k
               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
748
        upsample->methods[ci] = h1v2_fancy_upsample;
530
748
      upsample->pub.need_context_rows = TRUE;
531
5.79k
    } else if (h_in_group * 2 == h_out_group &&
532
1.17k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
946
      if (do_fancy && compptr->downsampled_width > 2) {
535
#ifdef WITH_SIMD
536
213
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
0
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
213
        else
539
213
#endif
540
213
          upsample->methods[ci] = h2v2_fancy_upsample;
541
300
        upsample->pub.need_context_rows = TRUE;
542
646
      } else {
543
#ifdef WITH_SIMD
544
315
        if (jsimd_set_h2v2_upsample(cinfo))
545
0
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
315
        else
547
315
#endif
548
315
          upsample->methods[ci] = h2v2_upsample;
549
646
      }
550
4.84k
    } else if ((h_out_group % h_in_group) == 0 &&
551
4.83k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
4.81k
      upsample->methods[ci] = int_upsample;
554
4.81k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
4.81k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
4.81k
    } else
557
29
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
12.5k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
7.73k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
7.73k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
7.73k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
7.73k
                               (long)cinfo->max_h_samp_factor),
563
7.73k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
7.73k
    }
565
12.5k
  }
566
6.44k
}
jinit_upsampler
Line
Count
Source
438
3.98k
{
439
3.98k
  my_upsample_ptr upsample;
440
3.98k
  int ci;
441
3.98k
  jpeg_component_info *compptr;
442
3.98k
  boolean need_buffer, do_fancy;
443
3.98k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
3.98k
#ifdef D_LOSSLESS_SUPPORTED
446
3.98k
  if (cinfo->master->lossless) {
447
1.33k
#if BITS_IN_JSAMPLE == 8
448
1.33k
    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
1.33k
  } else
455
2.65k
#endif
456
2.65k
  {
457
2.65k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
2.65k
  }
460
461
3.98k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
3.98k
    upsample = (my_upsample_ptr)
463
3.98k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
3.98k
                                  sizeof(my_upsampler));
465
3.98k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
3.98k
    upsample->pub.start_pass = start_pass_upsample;
467
3.98k
    upsample->pub._upsample = sep_upsample;
468
3.98k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
3.98k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
3.98k
  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
3.98k
  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
10.7k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
6.78k
       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
6.78k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
6.78k
                 cinfo->_min_DCT_scaled_size;
490
6.78k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
6.78k
                 cinfo->_min_DCT_scaled_size;
492
6.78k
    h_out_group = cinfo->max_h_samp_factor;
493
6.78k
    v_out_group = cinfo->max_v_samp_factor;
494
6.78k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
6.78k
    need_buffer = TRUE;
496
6.78k
    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
6.78k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
3.35k
      upsample->methods[ci] = fullsize_upsample;
503
3.35k
      need_buffer = FALSE;
504
3.42k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
577
      if (do_fancy && compptr->downsampled_width > 2) {
507
220
#ifdef WITH_SIMD
508
220
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
0
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
220
        else
511
220
#endif
512
220
          upsample->methods[ci] = h2v1_fancy_upsample;
513
357
      } else {
514
357
#ifdef WITH_SIMD
515
357
        if (jsimd_set_h2v1_upsample(cinfo))
516
0
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
357
        else
518
357
#endif
519
357
          upsample->methods[ci] = h2v1_upsample;
520
357
      }
521
2.85k
    } else if (h_in_group == h_out_group &&
522
1.38k
               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
529
        upsample->methods[ci] = h1v2_fancy_upsample;
530
529
      upsample->pub.need_context_rows = TRUE;
531
2.32k
    } else if (h_in_group * 2 == h_out_group &&
532
614
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
528
      if (do_fancy && compptr->downsampled_width > 2) {
535
213
#ifdef WITH_SIMD
536
213
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
0
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
213
        else
539
213
#endif
540
213
          upsample->methods[ci] = h2v2_fancy_upsample;
541
213
        upsample->pub.need_context_rows = TRUE;
542
315
      } else {
543
315
#ifdef WITH_SIMD
544
315
        if (jsimd_set_h2v2_upsample(cinfo))
545
0
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
315
        else
547
315
#endif
548
315
          upsample->methods[ci] = h2v2_upsample;
549
315
      }
550
1.79k
    } else if ((h_out_group % h_in_group) == 0 &&
551
1.79k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
1.78k
      upsample->methods[ci] = int_upsample;
554
1.78k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
1.78k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
1.78k
    } else
557
10
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
6.78k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
3.41k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
3.41k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
3.41k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
3.41k
                               (long)cinfo->max_h_samp_factor),
563
3.41k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
3.41k
    }
565
6.78k
  }
566
3.98k
}
j12init_upsampler
Line
Count
Source
438
1.49k
{
439
1.49k
  my_upsample_ptr upsample;
440
1.49k
  int ci;
441
1.49k
  jpeg_component_info *compptr;
442
1.49k
  boolean need_buffer, do_fancy;
443
1.49k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
1.49k
#ifdef D_LOSSLESS_SUPPORTED
446
1.49k
  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
859
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
859
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
859
  } else
455
636
#endif
456
636
  {
457
636
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
636
  }
460
461
1.49k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
1.49k
    upsample = (my_upsample_ptr)
463
1.49k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
1.49k
                                  sizeof(my_upsampler));
465
1.49k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
1.49k
    upsample->pub.start_pass = start_pass_upsample;
467
1.49k
    upsample->pub._upsample = sep_upsample;
468
1.49k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
1.49k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
1.49k
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
473
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
474
475
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
476
   * so don't ask for it.
477
   */
478
1.49k
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
479
480
  /* Verify we can handle the sampling factors, select per-component methods,
481
   * and create storage as needed.
482
   */
483
4.94k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
3.45k
       ci++, compptr++) {
485
    /* Compute size of an "input group" after IDCT scaling.  This many samples
486
     * are to be converted to max_h_samp_factor * max_v_samp_factor components.
487
     */
488
3.45k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
3.45k
                 cinfo->_min_DCT_scaled_size;
490
3.45k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
3.45k
                 cinfo->_min_DCT_scaled_size;
492
3.45k
    h_out_group = cinfo->max_h_samp_factor;
493
3.45k
    v_out_group = cinfo->max_v_samp_factor;
494
3.45k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
3.45k
    need_buffer = TRUE;
496
3.45k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
0
      upsample->methods[ci] = noop_upsample;
499
0
      need_buffer = FALSE;
500
3.45k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
942
      upsample->methods[ci] = fullsize_upsample;
503
942
      need_buffer = FALSE;
504
2.51k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
406
      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
106
          upsample->methods[ci] = h2v1_fancy_upsample;
513
300
      } else {
514
#ifdef WITH_SIMD
515
        if (jsimd_set_h2v1_upsample(cinfo))
516
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
        else
518
#endif
519
300
          upsample->methods[ci] = h2v1_upsample;
520
300
      }
521
2.10k
    } else if (h_in_group == h_out_group &&
522
974
               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
219
        upsample->methods[ci] = h1v2_fancy_upsample;
530
219
      upsample->pub.need_context_rows = TRUE;
531
1.88k
    } else if (h_in_group * 2 == h_out_group &&
532
324
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
251
      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
87
          upsample->methods[ci] = h2v2_fancy_upsample;
541
87
        upsample->pub.need_context_rows = TRUE;
542
164
      } else {
543
#ifdef WITH_SIMD
544
        if (jsimd_set_h2v2_upsample(cinfo))
545
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
        else
547
#endif
548
164
          upsample->methods[ci] = h2v2_upsample;
549
164
      }
550
1.63k
    } else if ((h_out_group % h_in_group) == 0 &&
551
1.63k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
1.62k
      upsample->methods[ci] = int_upsample;
554
1.62k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
1.62k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
1.62k
    } else
557
9
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
3.45k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
2.50k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
2.50k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
2.50k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
2.50k
                               (long)cinfo->max_h_samp_factor),
563
2.50k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
2.50k
    }
565
3.45k
  }
566
1.49k
}
j16init_upsampler
Line
Count
Source
438
958
{
439
958
  my_upsample_ptr upsample;
440
958
  int ci;
441
958
  jpeg_component_info *compptr;
442
958
  boolean need_buffer, do_fancy;
443
958
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
958
#ifdef D_LOSSLESS_SUPPORTED
446
958
  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
958
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
958
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
958
  } 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
958
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
958
    upsample = (my_upsample_ptr)
463
958
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
958
                                  sizeof(my_upsampler));
465
958
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
958
    upsample->pub.start_pass = start_pass_upsample;
467
958
    upsample->pub._upsample = sep_upsample;
468
958
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
958
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
958
  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
958
  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
3.27k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
2.31k
       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
2.31k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
2.31k
                 cinfo->_min_DCT_scaled_size;
490
2.31k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
2.31k
                 cinfo->_min_DCT_scaled_size;
492
2.31k
    h_out_group = cinfo->max_h_samp_factor;
493
2.31k
    v_out_group = cinfo->max_v_samp_factor;
494
2.31k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
2.31k
    need_buffer = TRUE;
496
2.31k
    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
2.31k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
499
      upsample->methods[ci] = fullsize_upsample;
503
499
      need_buffer = FALSE;
504
1.81k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
236
      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
236
      } else {
514
#ifdef WITH_SIMD
515
        if (jsimd_set_h2v1_upsample(cinfo))
516
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
        else
518
#endif
519
236
          upsample->methods[ci] = h2v1_upsample;
520
236
      }
521
1.58k
    } else if (h_in_group == h_out_group &&
522
680
               v_in_group * 2 == v_out_group && do_fancy) {
523
      /* Non-fancy upsampling is handled by the generic method */
524
#if defined(WITH_SIMD) && (SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM)
525
      if (jsimd_set_h1v2_fancy_upsample(cinfo))
526
        upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
527
      else
528
#endif
529
0
        upsample->methods[ci] = h1v2_fancy_upsample;
530
0
      upsample->pub.need_context_rows = TRUE;
531
1.58k
    } else if (h_in_group * 2 == h_out_group &&
532
239
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
167
      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
167
      } else {
543
#ifdef WITH_SIMD
544
        if (jsimd_set_h2v2_upsample(cinfo))
545
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
        else
547
#endif
548
167
          upsample->methods[ci] = h2v2_upsample;
549
167
      }
550
1.41k
    } else if ((h_out_group % h_in_group) == 0 &&
551
1.41k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
1.40k
      upsample->methods[ci] = int_upsample;
554
1.40k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
1.40k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
1.40k
    } else
557
10
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
2.31k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
1.80k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
1.80k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
1.80k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
1.80k
                               (long)cinfo->max_h_samp_factor),
563
1.80k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
1.80k
    }
565
2.31k
  }
566
958
}
567
568
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */