Coverage Report

Created: 2025-12-31 10:39

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-2025, D. R. Commander.
9
 * Copyright (C) 2014, MIPS Technologies, Inc., California.
10
 * Copyright (C) 2015, Google, Inc.
11
 * Copyright (C) 2019-2020, Arm Limited.
12
 * For conditions of distribution and use, see the accompanying README.ijg
13
 * file.
14
 *
15
 * This file contains upsampling routines.
16
 *
17
 * Upsampling input data is counted in "row groups".  A row group
18
 * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
19
 * sample rows of each component.  Upsampling will normally produce
20
 * max_v_samp_factor pixel rows from each row group (but this could vary
21
 * if the upsampler is applying a scale factor of its own).
22
 *
23
 * An excellent reference for image resampling is
24
 *   Digital Image Warping, George Wolberg, 1990.
25
 *   Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
26
 */
27
28
#include "jinclude.h"
29
#include "jdsample.h"
30
#include "jsimd.h"
31
#include "jpegapicomp.h"
32
33
34
35
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
36
37
/*
38
 * Initialize for an upsampling pass.
39
 */
40
41
METHODDEF(void)
42
start_pass_upsample(j_decompress_ptr cinfo)
43
38.2k
{
44
38.2k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
45
46
  /* Mark the conversion buffer empty */
47
38.2k
  upsample->next_row_out = cinfo->max_v_samp_factor;
48
  /* Initialize total-height counter for detecting bottom of image */
49
38.2k
  upsample->rows_to_go = cinfo->output_height;
50
38.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
184M
{
67
184M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
68
184M
  int ci;
69
184M
  jpeg_component_info *compptr;
70
184M
  JDIMENSION num_rows;
71
72
  /* Fill the conversion buffer, if it's empty */
73
184M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
74
468M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
75
340M
         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
340M
      (*upsample->methods[ci]) (cinfo, compptr,
80
340M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
81
340M
        upsample->color_buf + ci);
82
340M
    }
83
127M
    upsample->next_row_out = 0;
84
127M
  }
85
86
  /* Color-convert and emit rows */
87
88
  /* How many we have in the buffer: */
89
184M
  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
184M
  if (num_rows > upsample->rows_to_go)
94
23.5k
    num_rows = upsample->rows_to_go;
95
  /* And not more than what the client can accept: */
96
184M
  out_rows_avail -= *out_row_ctr;
97
184M
  if (num_rows > out_rows_avail)
98
57.5M
    num_rows = out_rows_avail;
99
100
184M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
101
184M
                                      (JDIMENSION)upsample->next_row_out,
102
184M
                                      output_buf + *out_row_ctr,
103
184M
                                      (int)num_rows);
104
105
  /* Adjust counts */
106
184M
  *out_row_ctr += num_rows;
107
184M
  upsample->rows_to_go -= num_rows;
108
184M
  upsample->next_row_out += num_rows;
109
  /* When the buffer is emptied, declare this input row group consumed */
110
184M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
111
127M
    (*in_row_group_ctr)++;
112
184M
}
113
114
115
/*
116
 * These are the routines invoked by sep_upsample to upsample pixel values
117
 * of a single component.  One row group is processed per call.
118
 */
119
120
121
/*
122
 * For full-size components, we just make color_buf[ci] point at the
123
 * input buffer, and thus avoid copying any data.  Note that this is
124
 * safe only because sep_upsample doesn't declare the input row group
125
 * "consumed" until we are done color converting and emitting it.
126
 */
127
128
METHODDEF(void)
129
fullsize_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
130
                  _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
131
128M
{
132
128M
  *output_data_ptr = input_data;
133
128M
}
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.
152
 * Nor, for that matter, is it particularly accurate: the algorithm is
153
 * simple replication of the input pixel onto the corresponding output
154
 * pixels.  The hi-falutin sampling literature refers to this as a
155
 * "box filter".  A box filter tends to introduce visible artifacts,
156
 * so if you are actually going to use 3:1 or 4:1 sampling ratios
157
 * you would be well advised to improve this code.
158
 */
159
160
METHODDEF(void)
161
int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
162
             _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
163
23.8M
{
164
23.8M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
165
23.8M
  _JSAMPARRAY output_data = *output_data_ptr;
166
23.8M
  register _JSAMPROW inptr, outptr;
167
23.8M
  register _JSAMPLE invalue;
168
23.8M
  register int h;
169
23.8M
  _JSAMPROW outend;
170
23.8M
  int h_expand, v_expand;
171
23.8M
  int inrow, outrow;
172
173
23.8M
  h_expand = upsample->h_expand[compptr->component_index];
174
23.8M
  v_expand = upsample->v_expand[compptr->component_index];
175
176
23.8M
  inrow = outrow = 0;
177
49.1M
  while (outrow < cinfo->max_v_samp_factor) {
178
    /* Generate one output row with proper horizontal expansion */
179
25.2M
    inptr = input_data[inrow];
180
25.2M
    outptr = output_data[outrow];
181
25.2M
    outend = outptr + cinfo->output_width;
182
305M
    while (outptr < outend) {
183
280M
      invalue = *inptr++;
184
846M
      for (h = h_expand; h > 0; h--) {
185
566M
        *outptr++ = invalue;
186
566M
      }
187
280M
    }
188
    /* Generate any additional output rows by duplicating the first one */
189
25.2M
    if (v_expand > 1) {
190
15.3M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
191
15.3M
                         v_expand - 1, cinfo->output_width);
192
15.3M
    }
193
25.2M
    inrow++;
194
25.2M
    outrow += v_expand;
195
25.2M
  }
196
23.8M
}
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
6.84M
{
208
6.84M
  _JSAMPARRAY output_data = *output_data_ptr;
209
6.84M
  register _JSAMPROW inptr, outptr;
210
6.84M
  register _JSAMPLE invalue;
211
6.84M
  _JSAMPROW outend;
212
6.84M
  int inrow;
213
214
14.4M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
215
7.56M
    inptr = input_data[inrow];
216
7.56M
    outptr = output_data[inrow];
217
7.56M
    outend = outptr + cinfo->output_width;
218
77.7M
    while (outptr < outend) {
219
70.2M
      invalue = *inptr++;
220
70.2M
      *outptr++ = invalue;
221
70.2M
      *outptr++ = invalue;
222
70.2M
    }
223
7.56M
  }
224
6.84M
}
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
4.50M
{
236
4.50M
  _JSAMPARRAY output_data = *output_data_ptr;
237
4.50M
  register _JSAMPROW inptr, outptr;
238
4.50M
  register _JSAMPLE invalue;
239
4.50M
  _JSAMPROW outend;
240
4.50M
  int inrow, outrow;
241
242
4.50M
  inrow = outrow = 0;
243
9.04M
  while (outrow < cinfo->max_v_samp_factor) {
244
4.53M
    inptr = input_data[inrow];
245
4.53M
    outptr = output_data[outrow];
246
4.53M
    outend = outptr + cinfo->output_width;
247
45.1M
    while (outptr < outend) {
248
40.6M
      invalue = *inptr++;
249
40.6M
      *outptr++ = invalue;
250
40.6M
      *outptr++ = invalue;
251
40.6M
    }
252
4.53M
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
253
4.53M
                       cinfo->output_width);
254
4.53M
    inrow++;
255
4.53M
    outrow += 2;
256
4.53M
  }
257
4.50M
}
258
259
260
/*
261
 * Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
262
 *
263
 * The upsampling algorithm is linear interpolation between pixel centers,
264
 * also known as a "triangle filter".  This is a good compromise between
265
 * speed and visual quality.  The centers of the output pixels are 1/4 and 3/4
266
 * of the way between input pixel centers.
267
 *
268
 * A note about the "bias" calculations: when rounding fractional values to
269
 * integer, we do not want to always round 0.5 up to the next integer.
270
 * If we did that, we'd introduce a noticeable bias towards larger values.
271
 * Instead, this code is arranged so that 0.5 will be rounded up or down at
272
 * alternate pixel locations (a simple ordered dither pattern).
273
 */
274
275
METHODDEF(void)
276
h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
277
                    _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
278
138M
{
279
138M
  _JSAMPARRAY output_data = *output_data_ptr;
280
138M
  register _JSAMPROW inptr, outptr;
281
138M
  register int invalue;
282
138M
  register JDIMENSION colctr;
283
138M
  int inrow;
284
285
277M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
286
139M
    inptr = input_data[inrow];
287
139M
    outptr = output_data[inrow];
288
    /* Special case for first column */
289
139M
    invalue = *inptr++;
290
139M
    *outptr++ = (_JSAMPLE)invalue;
291
139M
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
292
293
441M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
294
      /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
295
302M
      invalue = (*inptr++) * 3;
296
302M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
297
302M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
298
302M
    }
299
300
    /* Special case for last column */
301
139M
    invalue = *inptr;
302
139M
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
303
139M
    *outptr++ = (_JSAMPLE)invalue;
304
139M
  }
305
138M
}
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
1.03M
{
319
1.03M
  _JSAMPARRAY output_data = *output_data_ptr;
320
1.03M
  _JSAMPROW inptr0, inptr1, outptr;
321
1.03M
#if BITS_IN_JSAMPLE == 8
322
1.03M
  int thiscolsum, bias;
323
#else
324
  JLONG thiscolsum, bias;
325
#endif
326
1.03M
  JDIMENSION colctr;
327
1.03M
  int inrow, outrow, v;
328
329
1.03M
  inrow = outrow = 0;
330
2.22M
  while (outrow < cinfo->max_v_samp_factor) {
331
3.55M
    for (v = 0; v < 2; v++) {
332
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
333
2.37M
      inptr0 = input_data[inrow];
334
2.37M
      if (v == 0) {             /* next nearest is row above */
335
1.18M
        inptr1 = input_data[inrow - 1];
336
1.18M
        bias = 1;
337
1.18M
      } else {                  /* next nearest is row below */
338
1.18M
        inptr1 = input_data[inrow + 1];
339
1.18M
        bias = 2;
340
1.18M
      }
341
2.37M
      outptr = output_data[outrow++];
342
343
360M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
344
358M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
345
358M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
346
358M
      }
347
2.37M
    }
348
1.18M
    inrow++;
349
1.18M
  }
350
1.03M
}
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
37.8M
{
365
37.8M
  _JSAMPARRAY output_data = *output_data_ptr;
366
37.8M
  register _JSAMPROW inptr0, inptr1, outptr;
367
37.8M
#if BITS_IN_JSAMPLE == 8
368
37.8M
  register int thiscolsum, lastcolsum, nextcolsum;
369
#else
370
  register JLONG thiscolsum, lastcolsum, nextcolsum;
371
#endif
372
37.8M
  register JDIMENSION colctr;
373
37.8M
  int inrow, outrow, v;
374
375
37.8M
  inrow = outrow = 0;
376
75.6M
  while (outrow < cinfo->max_v_samp_factor) {
377
113M
    for (v = 0; v < 2; v++) {
378
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
379
75.7M
      inptr0 = input_data[inrow];
380
75.7M
      if (v == 0)               /* next nearest is row above */
381
37.8M
        inptr1 = input_data[inrow - 1];
382
37.8M
      else                      /* next nearest is row below */
383
37.8M
        inptr1 = input_data[inrow + 1];
384
75.7M
      outptr = output_data[outrow++];
385
386
      /* Special case for first column */
387
75.7M
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
388
75.7M
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
389
75.7M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
390
75.7M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
391
75.7M
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
392
393
336M
      for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
394
        /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
395
        /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
396
260M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
397
260M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
398
260M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
399
260M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
400
260M
      }
401
402
      /* Special case for last column */
403
75.7M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
404
75.7M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
405
75.7M
    }
406
37.8M
    inrow++;
407
37.8M
  }
408
37.8M
}
409
410
411
/*
412
 * Module initialization routine for upsampling.
413
 */
414
415
GLOBAL(void)
416
_jinit_upsampler(j_decompress_ptr cinfo)
417
39.8k
{
418
39.8k
  my_upsample_ptr upsample;
419
39.8k
  int ci;
420
39.8k
  jpeg_component_info *compptr;
421
39.8k
  boolean need_buffer, do_fancy;
422
39.8k
  int h_in_group, v_in_group, h_out_group, v_out_group;
423
424
39.8k
#ifdef D_LOSSLESS_SUPPORTED
425
39.8k
  if (cinfo->master->lossless) {
426
1.97k
#if BITS_IN_JSAMPLE == 8
427
1.97k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
428
#else
429
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
430
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
431
#endif
432
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
433
1.97k
  } else
434
37.9k
#endif
435
37.9k
  {
436
37.9k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
437
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
438
37.9k
  }
439
440
39.8k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
441
39.8k
    upsample = (my_upsample_ptr)
442
39.8k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
443
39.8k
                                  sizeof(my_upsampler));
444
39.8k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
445
39.8k
    upsample->pub.start_pass = start_pass_upsample;
446
39.8k
    upsample->pub._upsample = sep_upsample;
447
39.8k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
448
39.8k
  } else
449
0
    upsample = (my_upsample_ptr)cinfo->upsample;
450
451
39.8k
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
452
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
453
454
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
455
   * so don't ask for it.
456
   */
457
39.8k
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
458
459
  /* Verify we can handle the sampling factors, select per-component methods,
460
   * and create storage as needed.
461
   */
462
142k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
463
102k
       ci++, compptr++) {
464
    /* Compute size of an "input group" after IDCT scaling.  This many samples
465
     * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
466
     */
467
102k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
468
102k
                 cinfo->_min_DCT_scaled_size;
469
102k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
470
102k
                 cinfo->_min_DCT_scaled_size;
471
102k
    h_out_group = cinfo->max_h_samp_factor;
472
102k
    v_out_group = cinfo->max_v_samp_factor;
473
102k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
474
102k
    need_buffer = TRUE;
475
102k
    if (!compptr->component_needed) {
476
      /* Don't bother to upsample an uninteresting component. */
477
0
      upsample->methods[ci] = noop_upsample;
478
0
      need_buffer = FALSE;
479
102k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
480
      /* Fullsize components can be processed without any work. */
481
41.2k
      upsample->methods[ci] = fullsize_upsample;
482
41.2k
      need_buffer = FALSE;
483
61.3k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
484
      /* Special cases for 2h1v upsampling */
485
10.3k
      if (do_fancy && compptr->downsampled_width > 2) {
486
9.41k
#ifdef WITH_SIMD
487
9.41k
        if (jsimd_can_h2v1_fancy_upsample())
488
0
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
489
9.41k
        else
490
9.41k
#endif
491
9.41k
          upsample->methods[ci] = h2v1_fancy_upsample;
492
9.41k
      } else {
493
959
#ifdef WITH_SIMD
494
959
        if (jsimd_can_h2v1_upsample())
495
0
          upsample->methods[ci] = jsimd_h2v1_upsample;
496
959
        else
497
959
#endif
498
959
          upsample->methods[ci] = h2v1_upsample;
499
959
      }
500
50.9k
    } else if (h_in_group == h_out_group &&
501
4.43k
               v_in_group * 2 == v_out_group && do_fancy) {
502
      /* Non-fancy upsampling is handled by the generic method */
503
#if defined(WITH_SIMD) && (defined(__arm__) || defined(__aarch64__) || \
504
                           defined(_M_ARM) || defined(_M_ARM64) || \
505
                           defined(_M_ARM64EC))
506
      if (jsimd_can_h1v2_fancy_upsample())
507
        upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
508
      else
509
#endif
510
2.39k
        upsample->methods[ci] = h1v2_fancy_upsample;
511
2.39k
      upsample->pub.need_context_rows = TRUE;
512
48.5k
    } else if (h_in_group * 2 == h_out_group &&
513
45.0k
               v_in_group * 2 == v_out_group) {
514
      /* Special cases for 2h2v upsampling */
515
42.9k
      if (do_fancy && compptr->downsampled_width > 2) {
516
37.7k
#ifdef WITH_SIMD
517
37.7k
        if (jsimd_can_h2v2_fancy_upsample())
518
0
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
519
37.7k
        else
520
37.7k
#endif
521
37.7k
          upsample->methods[ci] = h2v2_fancy_upsample;
522
37.7k
        upsample->pub.need_context_rows = TRUE;
523
37.7k
      } else {
524
5.19k
#ifdef WITH_SIMD
525
5.19k
        if (jsimd_can_h2v2_upsample())
526
0
          upsample->methods[ci] = jsimd_h2v2_upsample;
527
5.19k
        else
528
5.19k
#endif
529
5.19k
          upsample->methods[ci] = h2v2_upsample;
530
5.19k
      }
531
42.9k
    } else if ((h_out_group % h_in_group) == 0 &&
532
5.65k
               (v_out_group % v_in_group) == 0) {
533
      /* Generic integral-factors upsampling method */
534
#if defined(WITH_SIMD) && defined(__mips__)
535
      if (jsimd_can_int_upsample())
536
        upsample->methods[ci] = jsimd_int_upsample;
537
      else
538
#endif
539
5.64k
        upsample->methods[ci] = int_upsample;
540
5.64k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
541
5.64k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
542
5.64k
    } else
543
14
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
544
102k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
545
61.3k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
546
61.3k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
547
61.3k
         (JDIMENSION)jround_up((long)cinfo->output_width,
548
61.3k
                               (long)cinfo->max_h_samp_factor),
549
61.3k
         (JDIMENSION)cinfo->max_v_samp_factor);
550
61.3k
    }
551
102k
  }
552
39.8k
}
553
554
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */