Coverage Report

Created: 2026-06-30 11:14

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