Coverage Report

Created: 2025-12-14 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/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
5.45k
{
44
5.45k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
45
46
  /* Mark the conversion buffer empty */
47
5.45k
  upsample->next_row_out = cinfo->max_v_samp_factor;
48
  /* Initialize total-height counter for detecting bottom of image */
49
5.45k
  upsample->rows_to_go = cinfo->output_height;
50
5.45k
}
jdsample-8.c:start_pass_upsample
Line
Count
Source
43
2.14k
{
44
2.14k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
45
46
  /* Mark the conversion buffer empty */
47
2.14k
  upsample->next_row_out = cinfo->max_v_samp_factor;
48
  /* Initialize total-height counter for detecting bottom of image */
49
2.14k
  upsample->rows_to_go = cinfo->output_height;
50
2.14k
}
jdsample-12.c:start_pass_upsample
Line
Count
Source
43
2.85k
{
44
2.85k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
45
46
  /* Mark the conversion buffer empty */
47
2.85k
  upsample->next_row_out = cinfo->max_v_samp_factor;
48
  /* Initialize total-height counter for detecting bottom of image */
49
2.85k
  upsample->rows_to_go = cinfo->output_height;
50
2.85k
}
jdsample-16.c:start_pass_upsample
Line
Count
Source
43
451
{
44
451
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
45
46
  /* Mark the conversion buffer empty */
47
451
  upsample->next_row_out = cinfo->max_v_samp_factor;
48
  /* Initialize total-height counter for detecting bottom of image */
49
451
  upsample->rows_to_go = cinfo->output_height;
50
451
}
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
10.3M
{
67
10.3M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
68
10.3M
  int ci;
69
10.3M
  jpeg_component_info *compptr;
70
10.3M
  JDIMENSION num_rows;
71
72
  /* Fill the conversion buffer, if it's empty */
73
10.3M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
74
26.6M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
75
16.2M
         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
16.2M
      (*upsample->methods[ci]) (cinfo, compptr,
80
16.2M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
81
16.2M
        upsample->color_buf + ci);
82
16.2M
    }
83
10.3M
    upsample->next_row_out = 0;
84
10.3M
  }
85
86
  /* Color-convert and emit rows */
87
88
  /* How many we have in the buffer: */
89
10.3M
  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
10.3M
  if (num_rows > upsample->rows_to_go)
94
2.42k
    num_rows = upsample->rows_to_go;
95
  /* And not more than what the client can accept: */
96
10.3M
  out_rows_avail -= *out_row_ctr;
97
10.3M
  if (num_rows > out_rows_avail)
98
0
    num_rows = out_rows_avail;
99
100
10.3M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
101
10.3M
                                      (JDIMENSION)upsample->next_row_out,
102
10.3M
                                      output_buf + *out_row_ctr,
103
10.3M
                                      (int)num_rows);
104
105
  /* Adjust counts */
106
10.3M
  *out_row_ctr += num_rows;
107
10.3M
  upsample->rows_to_go -= num_rows;
108
10.3M
  upsample->next_row_out += num_rows;
109
  /* When the buffer is emptied, declare this input row group consumed */
110
10.3M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
111
10.3M
    (*in_row_group_ctr)++;
112
10.3M
}
jdsample-8.c:sep_upsample
Line
Count
Source
66
5.61M
{
67
5.61M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
68
5.61M
  int ci;
69
5.61M
  jpeg_component_info *compptr;
70
5.61M
  JDIMENSION num_rows;
71
72
  /* Fill the conversion buffer, if it's empty */
73
5.61M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
74
14.1M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
75
8.58M
         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
8.58M
      (*upsample->methods[ci]) (cinfo, compptr,
80
8.58M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
81
8.58M
        upsample->color_buf + ci);
82
8.58M
    }
83
5.61M
    upsample->next_row_out = 0;
84
5.61M
  }
85
86
  /* Color-convert and emit rows */
87
88
  /* How many we have in the buffer: */
89
5.61M
  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
5.61M
  if (num_rows > upsample->rows_to_go)
94
760
    num_rows = upsample->rows_to_go;
95
  /* And not more than what the client can accept: */
96
5.61M
  out_rows_avail -= *out_row_ctr;
97
5.61M
  if (num_rows > out_rows_avail)
98
0
    num_rows = out_rows_avail;
99
100
5.61M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
101
5.61M
                                      (JDIMENSION)upsample->next_row_out,
102
5.61M
                                      output_buf + *out_row_ctr,
103
5.61M
                                      (int)num_rows);
104
105
  /* Adjust counts */
106
5.61M
  *out_row_ctr += num_rows;
107
5.61M
  upsample->rows_to_go -= num_rows;
108
5.61M
  upsample->next_row_out += num_rows;
109
  /* When the buffer is emptied, declare this input row group consumed */
110
5.61M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
111
5.61M
    (*in_row_group_ctr)++;
112
5.61M
}
jdsample-12.c:sep_upsample
Line
Count
Source
66
4.52M
{
67
4.52M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
68
4.52M
  int ci;
69
4.52M
  jpeg_component_info *compptr;
70
4.52M
  JDIMENSION num_rows;
71
72
  /* Fill the conversion buffer, if it's empty */
73
4.52M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
74
11.4M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
75
6.92M
         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
6.92M
      (*upsample->methods[ci]) (cinfo, compptr,
80
6.92M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
81
6.92M
        upsample->color_buf + ci);
82
6.92M
    }
83
4.52M
    upsample->next_row_out = 0;
84
4.52M
  }
85
86
  /* Color-convert and emit rows */
87
88
  /* How many we have in the buffer: */
89
4.52M
  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
4.52M
  if (num_rows > upsample->rows_to_go)
94
1.58k
    num_rows = upsample->rows_to_go;
95
  /* And not more than what the client can accept: */
96
4.52M
  out_rows_avail -= *out_row_ctr;
97
4.52M
  if (num_rows > out_rows_avail)
98
0
    num_rows = out_rows_avail;
99
100
4.52M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
101
4.52M
                                      (JDIMENSION)upsample->next_row_out,
102
4.52M
                                      output_buf + *out_row_ctr,
103
4.52M
                                      (int)num_rows);
104
105
  /* Adjust counts */
106
4.52M
  *out_row_ctr += num_rows;
107
4.52M
  upsample->rows_to_go -= num_rows;
108
4.52M
  upsample->next_row_out += num_rows;
109
  /* When the buffer is emptied, declare this input row group consumed */
110
4.52M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
111
4.52M
    (*in_row_group_ctr)++;
112
4.52M
}
jdsample-16.c:sep_upsample
Line
Count
Source
66
258k
{
67
258k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
68
258k
  int ci;
69
258k
  jpeg_component_info *compptr;
70
258k
  JDIMENSION num_rows;
71
72
  /* Fill the conversion buffer, if it's empty */
73
258k
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
74
1.03M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
75
775k
         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
775k
      (*upsample->methods[ci]) (cinfo, compptr,
80
775k
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
81
775k
        upsample->color_buf + ci);
82
775k
    }
83
258k
    upsample->next_row_out = 0;
84
258k
  }
85
86
  /* Color-convert and emit rows */
87
88
  /* How many we have in the buffer: */
89
258k
  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
258k
  if (num_rows > upsample->rows_to_go)
94
74
    num_rows = upsample->rows_to_go;
95
  /* And not more than what the client can accept: */
96
258k
  out_rows_avail -= *out_row_ctr;
97
258k
  if (num_rows > out_rows_avail)
98
0
    num_rows = out_rows_avail;
99
100
258k
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
101
258k
                                      (JDIMENSION)upsample->next_row_out,
102
258k
                                      output_buf + *out_row_ctr,
103
258k
                                      (int)num_rows);
104
105
  /* Adjust counts */
106
258k
  *out_row_ctr += num_rows;
107
258k
  upsample->rows_to_go -= num_rows;
108
258k
  upsample->next_row_out += num_rows;
109
  /* When the buffer is emptied, declare this input row group consumed */
110
258k
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
111
258k
    (*in_row_group_ctr)++;
112
258k
}
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
9.80M
{
132
9.80M
  *output_data_ptr = input_data;
133
9.80M
}
jdsample-8.c:fullsize_upsample
Line
Count
Source
131
5.46M
{
132
5.46M
  *output_data_ptr = input_data;
133
5.46M
}
jdsample-12.c:fullsize_upsample
Line
Count
Source
131
4.14M
{
132
4.14M
  *output_data_ptr = input_data;
133
4.14M
}
jdsample-16.c:fullsize_upsample
Line
Count
Source
131
206k
{
132
206k
  *output_data_ptr = input_data;
133
206k
}
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
918k
{
145
918k
  *output_data_ptr = NULL;      /* safety check */
146
918k
}
jdsample-8.c:noop_upsample
Line
Count
Source
144
411k
{
145
  *output_data_ptr = NULL;      /* safety check */
146
411k
}
jdsample-12.c:noop_upsample
Line
Count
Source
144
507k
{
145
  *output_data_ptr = NULL;      /* safety check */
146
507k
}
Unexecuted instantiation: jdsample-16.c:noop_upsample
147
148
149
/*
150
 * This version handles any integral sampling ratios.
151
 * This is not used for typical JPEG files, so it need not be fast.
152
 * Nor, for that matter, is it particularly accurate: the algorithm is
153
 * simple replication of the input pixel onto the corresponding output
154
 * pixels.  The hi-falutin sampling literature refers to this as a
155
 * "box filter".  A box filter tends to introduce visible artifacts,
156
 * so if you are actually going to use 3:1 or 4:1 sampling ratios
157
 * you would be well advised to improve this code.
158
 */
159
160
METHODDEF(void)
161
int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
162
             _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
163
3.20M
{
164
3.20M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
165
3.20M
  _JSAMPARRAY output_data = *output_data_ptr;
166
3.20M
  register _JSAMPROW inptr, outptr;
167
3.20M
  register _JSAMPLE invalue;
168
3.20M
  register int h;
169
3.20M
  _JSAMPROW outend;
170
3.20M
  int h_expand, v_expand;
171
3.20M
  int inrow, outrow;
172
173
3.20M
  h_expand = upsample->h_expand[compptr->component_index];
174
3.20M
  v_expand = upsample->v_expand[compptr->component_index];
175
176
3.20M
  inrow = outrow = 0;
177
7.10M
  while (outrow < cinfo->max_v_samp_factor) {
178
    /* Generate one output row with proper horizontal expansion */
179
3.90M
    inptr = input_data[inrow];
180
3.90M
    outptr = output_data[outrow];
181
3.90M
    outend = outptr + cinfo->output_width;
182
83.8M
    while (outptr < outend) {
183
79.9M
      invalue = *inptr++;
184
227M
      for (h = h_expand; h > 0; h--) {
185
147M
        *outptr++ = invalue;
186
147M
      }
187
79.9M
    }
188
    /* Generate any additional output rows by duplicating the first one */
189
3.90M
    if (v_expand > 1) {
190
2.58M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
191
2.58M
                         v_expand - 1, cinfo->output_width);
192
2.58M
    }
193
3.90M
    inrow++;
194
3.90M
    outrow += v_expand;
195
3.90M
  }
196
3.20M
}
jdsample-8.c:int_upsample
Line
Count
Source
163
1.49M
{
164
1.49M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
165
1.49M
  _JSAMPARRAY output_data = *output_data_ptr;
166
1.49M
  register _JSAMPROW inptr, outptr;
167
1.49M
  register _JSAMPLE invalue;
168
1.49M
  register int h;
169
1.49M
  _JSAMPROW outend;
170
1.49M
  int h_expand, v_expand;
171
1.49M
  int inrow, outrow;
172
173
1.49M
  h_expand = upsample->h_expand[compptr->component_index];
174
1.49M
  v_expand = upsample->v_expand[compptr->component_index];
175
176
1.49M
  inrow = outrow = 0;
177
3.25M
  while (outrow < cinfo->max_v_samp_factor) {
178
    /* Generate one output row with proper horizontal expansion */
179
1.75M
    inptr = input_data[inrow];
180
1.75M
    outptr = output_data[outrow];
181
1.75M
    outend = outptr + cinfo->output_width;
182
50.0M
    while (outptr < outend) {
183
48.2M
      invalue = *inptr++;
184
137M
      for (h = h_expand; h > 0; h--) {
185
89.0M
        *outptr++ = invalue;
186
89.0M
      }
187
48.2M
    }
188
    /* Generate any additional output rows by duplicating the first one */
189
1.75M
    if (v_expand > 1) {
190
1.30M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
191
1.30M
                         v_expand - 1, cinfo->output_width);
192
1.30M
    }
193
1.75M
    inrow++;
194
1.75M
    outrow += v_expand;
195
1.75M
  }
196
1.49M
}
jdsample-12.c:int_upsample
Line
Count
Source
163
1.44M
{
164
1.44M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
165
1.44M
  _JSAMPARRAY output_data = *output_data_ptr;
166
1.44M
  register _JSAMPROW inptr, outptr;
167
1.44M
  register _JSAMPLE invalue;
168
1.44M
  register int h;
169
1.44M
  _JSAMPROW outend;
170
1.44M
  int h_expand, v_expand;
171
1.44M
  int inrow, outrow;
172
173
1.44M
  h_expand = upsample->h_expand[compptr->component_index];
174
1.44M
  v_expand = upsample->v_expand[compptr->component_index];
175
176
1.44M
  inrow = outrow = 0;
177
3.25M
  while (outrow < cinfo->max_v_samp_factor) {
178
    /* Generate one output row with proper horizontal expansion */
179
1.81M
    inptr = input_data[inrow];
180
1.81M
    outptr = output_data[outrow];
181
1.81M
    outend = outptr + cinfo->output_width;
182
28.8M
    while (outptr < outend) {
183
27.0M
      invalue = *inptr++;
184
78.0M
      for (h = h_expand; h > 0; h--) {
185
50.9M
        *outptr++ = invalue;
186
50.9M
      }
187
27.0M
    }
188
    /* Generate any additional output rows by duplicating the first one */
189
1.81M
    if (v_expand > 1) {
190
1.15M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
191
1.15M
                         v_expand - 1, cinfo->output_width);
192
1.15M
    }
193
1.81M
    inrow++;
194
1.81M
    outrow += v_expand;
195
1.81M
  }
196
1.44M
}
jdsample-16.c:int_upsample
Line
Count
Source
163
267k
{
164
267k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
165
267k
  _JSAMPARRAY output_data = *output_data_ptr;
166
267k
  register _JSAMPROW inptr, outptr;
167
267k
  register _JSAMPLE invalue;
168
267k
  register int h;
169
267k
  _JSAMPROW outend;
170
267k
  int h_expand, v_expand;
171
267k
  int inrow, outrow;
172
173
267k
  h_expand = upsample->h_expand[compptr->component_index];
174
267k
  v_expand = upsample->v_expand[compptr->component_index];
175
176
267k
  inrow = outrow = 0;
177
603k
  while (outrow < cinfo->max_v_samp_factor) {
178
    /* Generate one output row with proper horizontal expansion */
179
335k
    inptr = input_data[inrow];
180
335k
    outptr = output_data[outrow];
181
335k
    outend = outptr + cinfo->output_width;
182
4.95M
    while (outptr < outend) {
183
4.62M
      invalue = *inptr++;
184
12.2M
      for (h = h_expand; h > 0; h--) {
185
7.65M
        *outptr++ = invalue;
186
7.65M
      }
187
4.62M
    }
188
    /* Generate any additional output rows by duplicating the first one */
189
335k
    if (v_expand > 1) {
190
120k
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
191
120k
                         v_expand - 1, cinfo->output_width);
192
120k
    }
193
335k
    inrow++;
194
335k
    outrow += v_expand;
195
335k
  }
196
267k
}
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
715k
{
208
715k
  _JSAMPARRAY output_data = *output_data_ptr;
209
715k
  register _JSAMPROW inptr, outptr;
210
715k
  register _JSAMPLE invalue;
211
715k
  _JSAMPROW outend;
212
715k
  int inrow;
213
214
1.96M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
215
1.25M
    inptr = input_data[inrow];
216
1.25M
    outptr = output_data[inrow];
217
1.25M
    outend = outptr + cinfo->output_width;
218
19.1M
    while (outptr < outend) {
219
17.9M
      invalue = *inptr++;
220
17.9M
      *outptr++ = invalue;
221
17.9M
      *outptr++ = invalue;
222
17.9M
    }
223
1.25M
  }
224
715k
}
Unexecuted instantiation: jdsample-8.c:h2v1_upsample
jdsample-12.c:h2v1_upsample
Line
Count
Source
207
447k
{
208
447k
  _JSAMPARRAY output_data = *output_data_ptr;
209
447k
  register _JSAMPROW inptr, outptr;
210
447k
  register _JSAMPLE invalue;
211
447k
  _JSAMPROW outend;
212
447k
  int inrow;
213
214
1.25M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
215
806k
    inptr = input_data[inrow];
216
806k
    outptr = output_data[inrow];
217
806k
    outend = outptr + cinfo->output_width;
218
12.9M
    while (outptr < outend) {
219
12.1M
      invalue = *inptr++;
220
12.1M
      *outptr++ = invalue;
221
12.1M
      *outptr++ = invalue;
222
12.1M
    }
223
806k
  }
224
447k
}
jdsample-16.c:h2v1_upsample
Line
Count
Source
207
268k
{
208
268k
  _JSAMPARRAY output_data = *output_data_ptr;
209
268k
  register _JSAMPROW inptr, outptr;
210
268k
  register _JSAMPLE invalue;
211
268k
  _JSAMPROW outend;
212
268k
  int inrow;
213
214
711k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
215
443k
    inptr = input_data[inrow];
216
443k
    outptr = output_data[inrow];
217
443k
    outend = outptr + cinfo->output_width;
218
6.18M
    while (outptr < outend) {
219
5.74M
      invalue = *inptr++;
220
5.74M
      *outptr++ = invalue;
221
5.74M
      *outptr++ = invalue;
222
5.74M
    }
223
443k
  }
224
268k
}
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
127k
{
236
127k
  _JSAMPARRAY output_data = *output_data_ptr;
237
127k
  register _JSAMPROW inptr, outptr;
238
127k
  register _JSAMPLE invalue;
239
127k
  _JSAMPROW outend;
240
127k
  int inrow, outrow;
241
242
127k
  inrow = outrow = 0;
243
326k
  while (outrow < cinfo->max_v_samp_factor) {
244
198k
    inptr = input_data[inrow];
245
198k
    outptr = output_data[outrow];
246
198k
    outend = outptr + cinfo->output_width;
247
5.77M
    while (outptr < outend) {
248
5.58M
      invalue = *inptr++;
249
5.58M
      *outptr++ = invalue;
250
5.58M
      *outptr++ = invalue;
251
5.58M
    }
252
198k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
253
198k
                       cinfo->output_width);
254
198k
    inrow++;
255
198k
    outrow += 2;
256
198k
  }
257
127k
}
Unexecuted instantiation: jdsample-8.c:h2v2_upsample
jdsample-12.c:h2v2_upsample
Line
Count
Source
235
94.5k
{
236
94.5k
  _JSAMPARRAY output_data = *output_data_ptr;
237
94.5k
  register _JSAMPROW inptr, outptr;
238
94.5k
  register _JSAMPLE invalue;
239
94.5k
  _JSAMPROW outend;
240
94.5k
  int inrow, outrow;
241
242
94.5k
  inrow = outrow = 0;
243
226k
  while (outrow < cinfo->max_v_samp_factor) {
244
131k
    inptr = input_data[inrow];
245
131k
    outptr = output_data[outrow];
246
131k
    outend = outptr + cinfo->output_width;
247
4.28M
    while (outptr < outend) {
248
4.15M
      invalue = *inptr++;
249
4.15M
      *outptr++ = invalue;
250
4.15M
      *outptr++ = invalue;
251
4.15M
    }
252
131k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
253
131k
                       cinfo->output_width);
254
131k
    inrow++;
255
131k
    outrow += 2;
256
131k
  }
257
94.5k
}
jdsample-16.c:h2v2_upsample
Line
Count
Source
235
33.4k
{
236
33.4k
  _JSAMPARRAY output_data = *output_data_ptr;
237
33.4k
  register _JSAMPROW inptr, outptr;
238
33.4k
  register _JSAMPLE invalue;
239
33.4k
  _JSAMPROW outend;
240
33.4k
  int inrow, outrow;
241
242
33.4k
  inrow = outrow = 0;
243
99.9k
  while (outrow < cinfo->max_v_samp_factor) {
244
66.5k
    inptr = input_data[inrow];
245
66.5k
    outptr = output_data[outrow];
246
66.5k
    outend = outptr + cinfo->output_width;
247
1.49M
    while (outptr < outend) {
248
1.42M
      invalue = *inptr++;
249
1.42M
      *outptr++ = invalue;
250
1.42M
      *outptr++ = invalue;
251
1.42M
    }
252
66.5k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
253
66.5k
                       cinfo->output_width);
254
66.5k
    inrow++;
255
66.5k
    outrow += 2;
256
66.5k
  }
257
33.4k
}
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
116k
{
279
116k
  _JSAMPARRAY output_data = *output_data_ptr;
280
116k
  register _JSAMPROW inptr, outptr;
281
116k
  register int invalue;
282
116k
  register JDIMENSION colctr;
283
116k
  int inrow;
284
285
323k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
286
206k
    inptr = input_data[inrow];
287
206k
    outptr = output_data[inrow];
288
    /* Special case for first column */
289
206k
    invalue = *inptr++;
290
206k
    *outptr++ = (_JSAMPLE)invalue;
291
206k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
292
293
5.71M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
294
      /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
295
5.51M
      invalue = (*inptr++) * 3;
296
5.51M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
297
5.51M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
298
5.51M
    }
299
300
    /* Special case for last column */
301
206k
    invalue = *inptr;
302
206k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
303
206k
    *outptr++ = (_JSAMPLE)invalue;
304
206k
  }
305
116k
}
Unexecuted instantiation: jdsample-8.c:h2v1_fancy_upsample
jdsample-12.c:h2v1_fancy_upsample
Line
Count
Source
278
116k
{
279
116k
  _JSAMPARRAY output_data = *output_data_ptr;
280
116k
  register _JSAMPROW inptr, outptr;
281
116k
  register int invalue;
282
116k
  register JDIMENSION colctr;
283
116k
  int inrow;
284
285
323k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
286
206k
    inptr = input_data[inrow];
287
206k
    outptr = output_data[inrow];
288
    /* Special case for first column */
289
206k
    invalue = *inptr++;
290
206k
    *outptr++ = (_JSAMPLE)invalue;
291
206k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
292
293
5.71M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
294
      /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
295
5.51M
      invalue = (*inptr++) * 3;
296
5.51M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
297
5.51M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
298
5.51M
    }
299
300
    /* Special case for last column */
301
206k
    invalue = *inptr;
302
206k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
303
206k
    *outptr++ = (_JSAMPLE)invalue;
304
206k
  }
305
116k
}
Unexecuted instantiation: jdsample-16.c:h2v1_fancy_upsample
306
307
308
/*
309
 * Fancy processing for 1:1 horizontal and 2:1 vertical (4:4:0 subsampling).
310
 *
311
 * This is a less common case, but it can be encountered when losslessly
312
 * rotating/transposing a JPEG file that uses 4:2:2 chroma subsampling.
313
 */
314
315
METHODDEF(void)
316
h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
317
                    _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
318
253k
{
319
253k
  _JSAMPARRAY output_data = *output_data_ptr;
320
253k
  _JSAMPROW inptr0, inptr1, outptr;
321
#if BITS_IN_JSAMPLE == 8
322
  int thiscolsum, bias;
323
#else
324
  JLONG thiscolsum, bias;
325
#endif
326
253k
  JDIMENSION colctr;
327
253k
  int inrow, outrow, v;
328
329
253k
  inrow = outrow = 0;
330
587k
  while (outrow < cinfo->max_v_samp_factor) {
331
1.00M
    for (v = 0; v < 2; v++) {
332
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
333
666k
      inptr0 = input_data[inrow];
334
666k
      if (v == 0) {             /* next nearest is row above */
335
333k
        inptr1 = input_data[inrow - 1];
336
333k
        bias = 1;
337
333k
      } else {                  /* next nearest is row below */
338
333k
        inptr1 = input_data[inrow + 1];
339
333k
        bias = 2;
340
333k
      }
341
666k
      outptr = output_data[outrow++];
342
343
23.8M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
344
23.1M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
345
23.1M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
346
23.1M
      }
347
666k
    }
348
333k
    inrow++;
349
333k
  }
350
253k
}
jdsample-8.c:h1v2_fancy_upsample
Line
Count
Source
318
95.5k
{
319
95.5k
  _JSAMPARRAY output_data = *output_data_ptr;
320
95.5k
  _JSAMPROW inptr0, inptr1, outptr;
321
95.5k
#if BITS_IN_JSAMPLE == 8
322
95.5k
  int thiscolsum, bias;
323
#else
324
  JLONG thiscolsum, bias;
325
#endif
326
95.5k
  JDIMENSION colctr;
327
95.5k
  int inrow, outrow, v;
328
329
95.5k
  inrow = outrow = 0;
330
220k
  while (outrow < cinfo->max_v_samp_factor) {
331
375k
    for (v = 0; v < 2; v++) {
332
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
333
250k
      inptr0 = input_data[inrow];
334
250k
      if (v == 0) {             /* next nearest is row above */
335
125k
        inptr1 = input_data[inrow - 1];
336
125k
        bias = 1;
337
125k
      } else {                  /* next nearest is row below */
338
125k
        inptr1 = input_data[inrow + 1];
339
125k
        bias = 2;
340
125k
      }
341
250k
      outptr = output_data[outrow++];
342
343
8.84M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
344
8.59M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
345
8.59M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
346
8.59M
      }
347
250k
    }
348
125k
    inrow++;
349
125k
  }
350
95.5k
}
jdsample-12.c:h1v2_fancy_upsample
Line
Count
Source
318
158k
{
319
158k
  _JSAMPARRAY output_data = *output_data_ptr;
320
158k
  _JSAMPROW inptr0, inptr1, outptr;
321
#if BITS_IN_JSAMPLE == 8
322
  int thiscolsum, bias;
323
#else
324
158k
  JLONG thiscolsum, bias;
325
158k
#endif
326
158k
  JDIMENSION colctr;
327
158k
  int inrow, outrow, v;
328
329
158k
  inrow = outrow = 0;
330
366k
  while (outrow < cinfo->max_v_samp_factor) {
331
625k
    for (v = 0; v < 2; v++) {
332
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
333
416k
      inptr0 = input_data[inrow];
334
416k
      if (v == 0) {             /* next nearest is row above */
335
208k
        inptr1 = input_data[inrow - 1];
336
208k
        bias = 1;
337
208k
      } else {                  /* next nearest is row below */
338
208k
        inptr1 = input_data[inrow + 1];
339
208k
        bias = 2;
340
208k
      }
341
416k
      outptr = output_data[outrow++];
342
343
14.9M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
344
14.5M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
345
14.5M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
346
14.5M
      }
347
416k
    }
348
208k
    inrow++;
349
208k
  }
350
158k
}
Unexecuted instantiation: jdsample-16.c:h1v2_fancy_upsample
351
352
353
/*
354
 * Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
355
 * Again a triangle filter; see comments for h2v1 case, above.
356
 *
357
 * It is OK for us to reference the adjacent input rows because we demanded
358
 * context from the main buffer controller (see initialization code).
359
 */
360
361
METHODDEF(void)
362
h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
363
                    _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
364
18.2k
{
365
18.2k
  _JSAMPARRAY output_data = *output_data_ptr;
366
18.2k
  register _JSAMPROW inptr0, inptr1, outptr;
367
#if BITS_IN_JSAMPLE == 8
368
  register int thiscolsum, lastcolsum, nextcolsum;
369
#else
370
  register JLONG thiscolsum, lastcolsum, nextcolsum;
371
#endif
372
18.2k
  register JDIMENSION colctr;
373
18.2k
  int inrow, outrow, v;
374
375
18.2k
  inrow = outrow = 0;
376
39.6k
  while (outrow < cinfo->max_v_samp_factor) {
377
64.0k
    for (v = 0; v < 2; v++) {
378
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
379
42.6k
      inptr0 = input_data[inrow];
380
42.6k
      if (v == 0)               /* next nearest is row above */
381
21.3k
        inptr1 = input_data[inrow - 1];
382
21.3k
      else                      /* next nearest is row below */
383
21.3k
        inptr1 = input_data[inrow + 1];
384
42.6k
      outptr = output_data[outrow++];
385
386
      /* Special case for first column */
387
42.6k
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
388
42.6k
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
389
42.6k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
390
42.6k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
391
42.6k
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
392
393
2.17M
      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
2.13M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
397
2.13M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
398
2.13M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
399
2.13M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
400
2.13M
      }
401
402
      /* Special case for last column */
403
42.6k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
404
42.6k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
405
42.6k
    }
406
21.3k
    inrow++;
407
21.3k
  }
408
18.2k
}
Unexecuted instantiation: jdsample-8.c:h2v2_fancy_upsample
jdsample-12.c:h2v2_fancy_upsample
Line
Count
Source
364
18.2k
{
365
18.2k
  _JSAMPARRAY output_data = *output_data_ptr;
366
18.2k
  register _JSAMPROW inptr0, inptr1, outptr;
367
#if BITS_IN_JSAMPLE == 8
368
  register int thiscolsum, lastcolsum, nextcolsum;
369
#else
370
18.2k
  register JLONG thiscolsum, lastcolsum, nextcolsum;
371
18.2k
#endif
372
18.2k
  register JDIMENSION colctr;
373
18.2k
  int inrow, outrow, v;
374
375
18.2k
  inrow = outrow = 0;
376
39.6k
  while (outrow < cinfo->max_v_samp_factor) {
377
64.0k
    for (v = 0; v < 2; v++) {
378
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
379
42.6k
      inptr0 = input_data[inrow];
380
42.6k
      if (v == 0)               /* next nearest is row above */
381
21.3k
        inptr1 = input_data[inrow - 1];
382
21.3k
      else                      /* next nearest is row below */
383
21.3k
        inptr1 = input_data[inrow + 1];
384
42.6k
      outptr = output_data[outrow++];
385
386
      /* Special case for first column */
387
42.6k
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
388
42.6k
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
389
42.6k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
390
42.6k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
391
42.6k
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
392
393
2.17M
      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
2.13M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
397
2.13M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
398
2.13M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
399
2.13M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
400
2.13M
      }
401
402
      /* Special case for last column */
403
42.6k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
404
42.6k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
405
42.6k
    }
406
21.3k
    inrow++;
407
21.3k
  }
408
18.2k
}
Unexecuted instantiation: jdsample-16.c:h2v2_fancy_upsample
409
410
411
/*
412
 * Module initialization routine for upsampling.
413
 */
414
415
GLOBAL(void)
416
_jinit_upsampler(j_decompress_ptr cinfo)
417
6.69k
{
418
6.69k
  my_upsample_ptr upsample;
419
6.69k
  int ci;
420
6.69k
  jpeg_component_info *compptr;
421
6.69k
  boolean need_buffer, do_fancy;
422
6.69k
  int h_in_group, v_in_group, h_out_group, v_out_group;
423
424
6.69k
#ifdef D_LOSSLESS_SUPPORTED
425
6.69k
  if (cinfo->master->lossless) {
426
#if BITS_IN_JSAMPLE == 8
427
461
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
428
#else
429
1.11k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
430
1.11k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
431
0
#endif
432
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
433
1.57k
  } else
434
5.12k
#endif
435
5.12k
  {
436
5.12k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
437
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
438
5.12k
  }
439
440
6.69k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
441
6.69k
    upsample = (my_upsample_ptr)
442
6.69k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
443
6.69k
                                  sizeof(my_upsampler));
444
6.69k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
445
6.69k
    upsample->pub.start_pass = start_pass_upsample;
446
6.69k
    upsample->pub._upsample = sep_upsample;
447
6.69k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
448
6.69k
  } else
449
0
    upsample = (my_upsample_ptr)cinfo->upsample;
450
451
6.69k
  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
6.69k
  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
20.3k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
463
13.6k
       ci++, compptr++) {
464
    /* Compute size of an "input group" after IDCT scaling.  This many samples
465
     * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
466
     */
467
13.6k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
468
13.6k
                 cinfo->_min_DCT_scaled_size;
469
13.6k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
470
13.6k
                 cinfo->_min_DCT_scaled_size;
471
13.6k
    h_out_group = cinfo->max_h_samp_factor;
472
13.6k
    v_out_group = cinfo->max_v_samp_factor;
473
13.6k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
474
13.6k
    need_buffer = TRUE;
475
13.6k
    if (!compptr->component_needed) {
476
      /* Don't bother to upsample an uninteresting component. */
477
856
      upsample->methods[ci] = noop_upsample;
478
856
      need_buffer = FALSE;
479
12.8k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
480
      /* Fullsize components can be processed without any work. */
481
5.87k
      upsample->methods[ci] = fullsize_upsample;
482
5.87k
      need_buffer = FALSE;
483
6.96k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
484
      /* Special cases for 2h1v upsampling */
485
1.80k
      if (do_fancy && compptr->downsampled_width > 2) {
486
#ifdef WITH_SIMD
487
44
        if (jsimd_can_h2v1_fancy_upsample())
488
44
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
489
0
        else
490
0
#endif
491
0
          upsample->methods[ci] = h2v1_fancy_upsample;
492
1.54k
      } else {
493
#ifdef WITH_SIMD
494
402
        if (jsimd_can_h2v1_upsample())
495
402
          upsample->methods[ci] = jsimd_h2v1_upsample;
496
0
        else
497
0
#endif
498
0
          upsample->methods[ci] = h2v1_upsample;
499
1.54k
      }
500
5.16k
    } else if (h_in_group == h_out_group &&
501
2.00k
               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
241
        upsample->methods[ci] = h1v2_fancy_upsample;
511
241
      upsample->pub.need_context_rows = TRUE;
512
4.91k
    } else if (h_in_group * 2 == h_out_group &&
513
1.33k
               v_in_group * 2 == v_out_group) {
514
      /* Special cases for 2h2v upsampling */
515
946
      if (do_fancy && compptr->downsampled_width > 2) {
516
#ifdef WITH_SIMD
517
13
        if (jsimd_can_h2v2_fancy_upsample())
518
13
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
519
0
        else
520
0
#endif
521
0
          upsample->methods[ci] = h2v2_fancy_upsample;
522
42
        upsample->pub.need_context_rows = TRUE;
523
904
      } else {
524
#ifdef WITH_SIMD
525
299
        if (jsimd_can_h2v2_upsample())
526
299
          upsample->methods[ci] = jsimd_h2v2_upsample;
527
0
        else
528
0
#endif
529
0
          upsample->methods[ci] = h2v2_upsample;
530
904
      }
531
3.97k
    } else if ((h_out_group % h_in_group) == 0 &&
532
3.96k
               (v_out_group % v_in_group) == 0) {
533
      /* Generic integral-factors upsampling method */
534
#if defined(WITH_SIMD) && defined(__mips__)
535
      if (jsimd_can_int_upsample())
536
        upsample->methods[ci] = jsimd_int_upsample;
537
      else
538
#endif
539
3.94k
        upsample->methods[ci] = int_upsample;
540
3.94k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
541
3.94k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
542
3.94k
    } else
543
28
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
544
13.6k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
545
6.93k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
546
6.93k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
547
6.93k
         (JDIMENSION)jround_up((long)cinfo->output_width,
548
6.93k
                               (long)cinfo->max_h_samp_factor),
549
6.93k
         (JDIMENSION)cinfo->max_v_samp_factor);
550
6.93k
    }
551
13.6k
  }
552
6.69k
}
jinit_upsampler
Line
Count
Source
417
2.96k
{
418
2.96k
  my_upsample_ptr upsample;
419
2.96k
  int ci;
420
2.96k
  jpeg_component_info *compptr;
421
2.96k
  boolean need_buffer, do_fancy;
422
2.96k
  int h_in_group, v_in_group, h_out_group, v_out_group;
423
424
2.96k
#ifdef D_LOSSLESS_SUPPORTED
425
2.96k
  if (cinfo->master->lossless) {
426
461
#if BITS_IN_JSAMPLE == 8
427
461
    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
461
  } else
434
2.50k
#endif
435
2.50k
  {
436
2.50k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
437
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
438
2.50k
  }
439
440
2.96k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
441
2.96k
    upsample = (my_upsample_ptr)
442
2.96k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
443
2.96k
                                  sizeof(my_upsampler));
444
2.96k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
445
2.96k
    upsample->pub.start_pass = start_pass_upsample;
446
2.96k
    upsample->pub._upsample = sep_upsample;
447
2.96k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
448
2.96k
  } else
449
0
    upsample = (my_upsample_ptr)cinfo->upsample;
450
451
2.96k
  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
2.96k
  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
8.10k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
463
5.14k
       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
5.14k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
468
5.14k
                 cinfo->_min_DCT_scaled_size;
469
5.14k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
470
5.14k
                 cinfo->_min_DCT_scaled_size;
471
5.14k
    h_out_group = cinfo->max_h_samp_factor;
472
5.14k
    v_out_group = cinfo->max_v_samp_factor;
473
5.14k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
474
5.14k
    need_buffer = TRUE;
475
5.14k
    if (!compptr->component_needed) {
476
      /* Don't bother to upsample an uninteresting component. */
477
170
      upsample->methods[ci] = noop_upsample;
478
170
      need_buffer = FALSE;
479
4.97k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
480
      /* Fullsize components can be processed without any work. */
481
2.76k
      upsample->methods[ci] = fullsize_upsample;
482
2.76k
      need_buffer = FALSE;
483
2.76k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
484
      /* Special cases for 2h1v upsampling */
485
446
      if (do_fancy && compptr->downsampled_width > 2) {
486
44
#ifdef WITH_SIMD
487
44
        if (jsimd_can_h2v1_fancy_upsample())
488
44
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
489
0
        else
490
0
#endif
491
0
          upsample->methods[ci] = h2v1_fancy_upsample;
492
402
      } else {
493
402
#ifdef WITH_SIMD
494
402
        if (jsimd_can_h2v1_upsample())
495
402
          upsample->methods[ci] = jsimd_h2v1_upsample;
496
0
        else
497
0
#endif
498
0
          upsample->methods[ci] = h2v1_upsample;
499
402
      }
500
1.76k
    } else if (h_in_group == h_out_group &&
501
640
               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
60
        upsample->methods[ci] = h1v2_fancy_upsample;
511
60
      upsample->pub.need_context_rows = TRUE;
512
1.70k
    } else if (h_in_group * 2 == h_out_group &&
513
495
               v_in_group * 2 == v_out_group) {
514
      /* Special cases for 2h2v upsampling */
515
312
      if (do_fancy && compptr->downsampled_width > 2) {
516
13
#ifdef WITH_SIMD
517
13
        if (jsimd_can_h2v2_fancy_upsample())
518
13
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
519
0
        else
520
0
#endif
521
0
          upsample->methods[ci] = h2v2_fancy_upsample;
522
13
        upsample->pub.need_context_rows = TRUE;
523
299
      } else {
524
299
#ifdef WITH_SIMD
525
299
        if (jsimd_can_h2v2_upsample())
526
299
          upsample->methods[ci] = jsimd_h2v2_upsample;
527
0
        else
528
0
#endif
529
0
          upsample->methods[ci] = h2v2_upsample;
530
299
      }
531
1.39k
    } else if ((h_out_group % h_in_group) == 0 &&
532
1.38k
               (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
1.37k
        upsample->methods[ci] = int_upsample;
540
1.37k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
541
1.37k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
542
1.37k
    } else
543
12
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
544
5.14k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
545
2.19k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
546
2.19k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
547
2.19k
         (JDIMENSION)jround_up((long)cinfo->output_width,
548
2.19k
                               (long)cinfo->max_h_samp_factor),
549
2.19k
         (JDIMENSION)cinfo->max_v_samp_factor);
550
2.19k
    }
551
5.14k
  }
552
2.96k
}
j12init_upsampler
Line
Count
Source
417
3.13k
{
418
3.13k
  my_upsample_ptr upsample;
419
3.13k
  int ci;
420
3.13k
  jpeg_component_info *compptr;
421
3.13k
  boolean need_buffer, do_fancy;
422
3.13k
  int h_in_group, v_in_group, h_out_group, v_out_group;
423
424
3.13k
#ifdef D_LOSSLESS_SUPPORTED
425
3.13k
  if (cinfo->master->lossless) {
426
#if BITS_IN_JSAMPLE == 8
427
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
428
#else
429
511
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
430
511
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
431
0
#endif
432
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
433
511
  } else
434
2.62k
#endif
435
2.62k
  {
436
2.62k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
437
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
438
2.62k
  }
439
440
3.13k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
441
3.13k
    upsample = (my_upsample_ptr)
442
3.13k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
443
3.13k
                                  sizeof(my_upsampler));
444
3.13k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
445
3.13k
    upsample->pub.start_pass = start_pass_upsample;
446
3.13k
    upsample->pub._upsample = sep_upsample;
447
3.13k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
448
3.13k
  } else
449
0
    upsample = (my_upsample_ptr)cinfo->upsample;
450
451
3.13k
  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
3.13k
  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
9.89k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
463
6.75k
       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
6.75k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
468
6.75k
                 cinfo->_min_DCT_scaled_size;
469
6.75k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
470
6.75k
                 cinfo->_min_DCT_scaled_size;
471
6.75k
    h_out_group = cinfo->max_h_samp_factor;
472
6.75k
    v_out_group = cinfo->max_v_samp_factor;
473
6.75k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
474
6.75k
    need_buffer = TRUE;
475
6.75k
    if (!compptr->component_needed) {
476
      /* Don't bother to upsample an uninteresting component. */
477
686
      upsample->methods[ci] = noop_upsample;
478
686
      need_buffer = FALSE;
479
6.07k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
480
      /* Fullsize components can be processed without any work. */
481
2.78k
      upsample->methods[ci] = fullsize_upsample;
482
2.78k
      need_buffer = FALSE;
483
3.29k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
484
      /* Special cases for 2h1v upsampling */
485
872
      if (do_fancy && compptr->downsampled_width > 2) {
486
#ifdef WITH_SIMD
487
        if (jsimd_can_h2v1_fancy_upsample())
488
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
489
        else
490
#endif
491
217
          upsample->methods[ci] = h2v1_fancy_upsample;
492
655
      } else {
493
#ifdef WITH_SIMD
494
        if (jsimd_can_h2v1_upsample())
495
          upsample->methods[ci] = jsimd_h2v1_upsample;
496
        else
497
#endif
498
655
          upsample->methods[ci] = h2v1_upsample;
499
655
      }
500
2.41k
    } else if (h_in_group == h_out_group &&
501
963
               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
181
        upsample->methods[ci] = h1v2_fancy_upsample;
511
181
      upsample->pub.need_context_rows = TRUE;
512
2.23k
    } else if (h_in_group * 2 == h_out_group &&
513
473
               v_in_group * 2 == v_out_group) {
514
      /* Special cases for 2h2v upsampling */
515
336
      if (do_fancy && compptr->downsampled_width > 2) {
516
#ifdef WITH_SIMD
517
        if (jsimd_can_h2v2_fancy_upsample())
518
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
519
        else
520
#endif
521
29
          upsample->methods[ci] = h2v2_fancy_upsample;
522
29
        upsample->pub.need_context_rows = TRUE;
523
307
      } else {
524
#ifdef WITH_SIMD
525
        if (jsimd_can_h2v2_upsample())
526
          upsample->methods[ci] = jsimd_h2v2_upsample;
527
        else
528
#endif
529
307
          upsample->methods[ci] = h2v2_upsample;
530
307
      }
531
1.90k
    } else if ((h_out_group % h_in_group) == 0 &&
532
1.90k
               (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
1.89k
        upsample->methods[ci] = int_upsample;
540
1.89k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
541
1.89k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
542
1.89k
    } else
543
10
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
544
6.75k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
545
3.28k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
546
3.28k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
547
3.28k
         (JDIMENSION)jround_up((long)cinfo->output_width,
548
3.28k
                               (long)cinfo->max_h_samp_factor),
549
3.28k
         (JDIMENSION)cinfo->max_v_samp_factor);
550
3.28k
    }
551
6.75k
  }
552
3.13k
}
j16init_upsampler
Line
Count
Source
417
600
{
418
600
  my_upsample_ptr upsample;
419
600
  int ci;
420
600
  jpeg_component_info *compptr;
421
600
  boolean need_buffer, do_fancy;
422
600
  int h_in_group, v_in_group, h_out_group, v_out_group;
423
424
600
#ifdef D_LOSSLESS_SUPPORTED
425
600
  if (cinfo->master->lossless) {
426
#if BITS_IN_JSAMPLE == 8
427
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
428
#else
429
600
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
430
600
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
431
0
#endif
432
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
433
600
  } else
434
0
#endif
435
0
  {
436
0
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
437
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
438
0
  }
439
440
600
  if (!cinfo->master->jinit_upsampler_no_alloc) {
441
600
    upsample = (my_upsample_ptr)
442
600
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
443
600
                                  sizeof(my_upsampler));
444
600
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
445
600
    upsample->pub.start_pass = start_pass_upsample;
446
600
    upsample->pub._upsample = sep_upsample;
447
600
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
448
600
  } else
449
0
    upsample = (my_upsample_ptr)cinfo->upsample;
450
451
600
  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
600
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
458
459
  /* Verify we can handle the sampling factors, select per-component methods,
460
   * and create storage as needed.
461
   */
462
2.39k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
463
1.79k
       ci++, compptr++) {
464
    /* Compute size of an "input group" after IDCT scaling.  This many samples
465
     * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
466
     */
467
1.79k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
468
1.79k
                 cinfo->_min_DCT_scaled_size;
469
1.79k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
470
1.79k
                 cinfo->_min_DCT_scaled_size;
471
1.79k
    h_out_group = cinfo->max_h_samp_factor;
472
1.79k
    v_out_group = cinfo->max_v_samp_factor;
473
1.79k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
474
1.79k
    need_buffer = TRUE;
475
1.79k
    if (!compptr->component_needed) {
476
      /* Don't bother to upsample an uninteresting component. */
477
0
      upsample->methods[ci] = noop_upsample;
478
0
      need_buffer = FALSE;
479
1.79k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
480
      /* Fullsize components can be processed without any work. */
481
334
      upsample->methods[ci] = fullsize_upsample;
482
334
      need_buffer = FALSE;
483
1.46k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
484
      /* Special cases for 2h1v upsampling */
485
483
      if (do_fancy && compptr->downsampled_width > 2) {
486
#ifdef WITH_SIMD
487
        if (jsimd_can_h2v1_fancy_upsample())
488
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
489
        else
490
#endif
491
0
          upsample->methods[ci] = h2v1_fancy_upsample;
492
483
      } else {
493
#ifdef WITH_SIMD
494
        if (jsimd_can_h2v1_upsample())
495
          upsample->methods[ci] = jsimd_h2v1_upsample;
496
        else
497
#endif
498
483
          upsample->methods[ci] = h2v1_upsample;
499
483
      }
500
978
    } else if (h_in_group == h_out_group &&
501
404
               v_in_group * 2 == v_out_group && do_fancy) {
502
      /* Non-fancy upsampling is handled by the generic method */
503
#if defined(WITH_SIMD) && (defined(__arm__) || defined(__aarch64__) || \
504
                           defined(_M_ARM) || defined(_M_ARM64) || \
505
                           defined(_M_ARM64EC))
506
      if (jsimd_can_h1v2_fancy_upsample())
507
        upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
508
      else
509
#endif
510
0
        upsample->methods[ci] = h1v2_fancy_upsample;
511
0
      upsample->pub.need_context_rows = TRUE;
512
978
    } else if (h_in_group * 2 == h_out_group &&
513
368
               v_in_group * 2 == v_out_group) {
514
      /* Special cases for 2h2v upsampling */
515
298
      if (do_fancy && compptr->downsampled_width > 2) {
516
#ifdef WITH_SIMD
517
        if (jsimd_can_h2v2_fancy_upsample())
518
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
519
        else
520
#endif
521
0
          upsample->methods[ci] = h2v2_fancy_upsample;
522
0
        upsample->pub.need_context_rows = TRUE;
523
298
      } else {
524
#ifdef WITH_SIMD
525
        if (jsimd_can_h2v2_upsample())
526
          upsample->methods[ci] = jsimd_h2v2_upsample;
527
        else
528
#endif
529
298
          upsample->methods[ci] = h2v2_upsample;
530
298
      }
531
680
    } else if ((h_out_group % h_in_group) == 0 &&
532
678
               (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
674
        upsample->methods[ci] = int_upsample;
540
674
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
541
674
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
542
674
    } else
543
6
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
544
1.79k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
545
1.45k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
546
1.45k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
547
1.45k
         (JDIMENSION)jround_up((long)cinfo->output_width,
548
1.45k
                               (long)cinfo->max_h_samp_factor),
549
1.45k
         (JDIMENSION)cinfo->max_v_samp_factor);
550
1.45k
    }
551
1.79k
  }
552
600
}
553
554
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */