Coverage Report

Created: 2026-05-11 06:55

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-2026, D. R. Commander.
9
 * Copyright (C) 2015, Google, Inc.
10
 * Copyright (C) 2019-2020, Arm Limited.
11
 * For conditions of distribution and use, see the accompanying README.ijg
12
 * file.
13
 *
14
 * This file contains upsampling routines.
15
 *
16
 * Upsampling input data is counted in "row groups".  A row group is defined to
17
 * be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size) sample rows of
18
 * each component.  Upsampling will normally produce max_v_samp_factor rows of
19
 * each component from each row group (but this could vary if the upsampler is
20
 * applying a scale factor of its own).
21
 *
22
 * An excellent reference for image resampling is
23
 *   Digital Image Warping, George Wolberg, 1990.
24
 *   Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
25
 */
26
27
#include "jinclude.h"
28
#include "jdsample.h"
29
#ifdef WITH_SIMD
30
#include "../simd/jsimd.h"
31
#endif
32
#include "jpegapicomp.h"
33
#ifdef WITH_PROFILE
34
#include "tjutil.h"
35
#endif
36
37
38
39
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
40
41
/*
42
 * Initialize for an upsampling pass.
43
 */
44
45
METHODDEF(void)
46
start_pass_upsample(j_decompress_ptr cinfo)
47
14.9k
{
48
14.9k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
14.9k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
14.9k
  upsample->rows_to_go = cinfo->output_height;
54
14.9k
}
jdsample-8.c:start_pass_upsample
Line
Count
Source
47
7.21k
{
48
7.21k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
7.21k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
7.21k
  upsample->rows_to_go = cinfo->output_height;
54
7.21k
}
jdsample-12.c:start_pass_upsample
Line
Count
Source
47
6.77k
{
48
6.77k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
6.77k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
6.77k
  upsample->rows_to_go = cinfo->output_height;
54
6.77k
}
jdsample-16.c:start_pass_upsample
Line
Count
Source
47
1.00k
{
48
1.00k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
1.00k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
1.00k
  upsample->rows_to_go = cinfo->output_height;
54
1.00k
}
55
56
57
/*
58
 * Control routine to do upsampling (and color conversion).
59
 *
60
 * In this version we upsample each component independently.
61
 * We upsample one row group into the conversion buffer, then apply
62
 * color conversion a row at a time.
63
 */
64
65
METHODDEF(void)
66
sep_upsample(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
67
             JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail,
68
             _JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
69
             JDIMENSION out_rows_avail)
70
19.8M
{
71
19.8M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
19.8M
  int ci;
73
19.8M
  jpeg_component_info *compptr;
74
19.8M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
19.8M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
54.6M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
34.7M
         ci++, compptr++) {
80
      /* Invoke per-component upsample method.  Notice we pass a POINTER
81
       * to color_buf[ci], so that fullsize_upsample can change it.
82
       */
83
#ifdef WITH_PROFILE
84
      cinfo->master->start = getTime();
85
#endif
86
34.7M
      (*upsample->methods[ci]) (cinfo, compptr,
87
34.7M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
34.7M
        upsample->color_buf + ci);
89
#ifdef WITH_PROFILE
90
      cinfo->master->upsample_elapsed += getTime() - cinfo->master->start;
91
      cinfo->master->upsample_msamples +=
92
        (double)cinfo->output_width * cinfo->max_v_samp_factor / 1000000.;
93
#endif
94
34.7M
    }
95
19.8M
    upsample->next_row_out = 0;
96
19.8M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
19.8M
  num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out);
102
  /* Not more than the distance to the end of the image.  Need this test
103
   * in case the image height is not a multiple of max_v_samp_factor:
104
   */
105
19.8M
  if (num_rows > upsample->rows_to_go)
106
4.79k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
19.8M
  out_rows_avail -= *out_row_ctr;
109
19.8M
  if (num_rows > out_rows_avail)
110
1.21k
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
19.8M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
19.8M
                                      (JDIMENSION)upsample->next_row_out,
117
19.8M
                                      output_buf + *out_row_ctr,
118
19.8M
                                      (int)num_rows);
119
#ifdef WITH_PROFILE
120
  cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
121
  cinfo->master->cconvert_mpixels +=
122
    (double)cinfo->output_width * num_rows / 1000000.;
123
#endif
124
125
  /* Adjust counts */
126
19.8M
  *out_row_ctr += num_rows;
127
19.8M
  upsample->rows_to_go -= num_rows;
128
19.8M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
19.8M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
19.8M
    (*in_row_group_ctr)++;
132
19.8M
}
jdsample-8.c:sep_upsample
Line
Count
Source
70
10.4M
{
71
10.4M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
10.4M
  int ci;
73
10.4M
  jpeg_component_info *compptr;
74
10.4M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
10.4M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
27.7M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
17.2M
         ci++, compptr++) {
80
      /* Invoke per-component upsample method.  Notice we pass a POINTER
81
       * to color_buf[ci], so that fullsize_upsample can change it.
82
       */
83
#ifdef WITH_PROFILE
84
      cinfo->master->start = getTime();
85
#endif
86
17.2M
      (*upsample->methods[ci]) (cinfo, compptr,
87
17.2M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
17.2M
        upsample->color_buf + ci);
89
#ifdef WITH_PROFILE
90
      cinfo->master->upsample_elapsed += getTime() - cinfo->master->start;
91
      cinfo->master->upsample_msamples +=
92
        (double)cinfo->output_width * cinfo->max_v_samp_factor / 1000000.;
93
#endif
94
17.2M
    }
95
10.4M
    upsample->next_row_out = 0;
96
10.4M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
10.4M
  num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out);
102
  /* Not more than the distance to the end of the image.  Need this test
103
   * in case the image height is not a multiple of max_v_samp_factor:
104
   */
105
10.4M
  if (num_rows > upsample->rows_to_go)
106
2.07k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
10.4M
  out_rows_avail -= *out_row_ctr;
109
10.4M
  if (num_rows > out_rows_avail)
110
498
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
10.4M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
10.4M
                                      (JDIMENSION)upsample->next_row_out,
117
10.4M
                                      output_buf + *out_row_ctr,
118
10.4M
                                      (int)num_rows);
119
#ifdef WITH_PROFILE
120
  cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
121
  cinfo->master->cconvert_mpixels +=
122
    (double)cinfo->output_width * num_rows / 1000000.;
123
#endif
124
125
  /* Adjust counts */
126
10.4M
  *out_row_ctr += num_rows;
127
10.4M
  upsample->rows_to_go -= num_rows;
128
10.4M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
10.4M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
10.4M
    (*in_row_group_ctr)++;
132
10.4M
}
jdsample-12.c:sep_upsample
Line
Count
Source
70
8.35M
{
71
8.35M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
8.35M
  int ci;
73
8.35M
  jpeg_component_info *compptr;
74
8.35M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
8.35M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
23.0M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
14.6M
         ci++, compptr++) {
80
      /* Invoke per-component upsample method.  Notice we pass a POINTER
81
       * to color_buf[ci], so that fullsize_upsample can change it.
82
       */
83
#ifdef WITH_PROFILE
84
      cinfo->master->start = getTime();
85
#endif
86
14.6M
      (*upsample->methods[ci]) (cinfo, compptr,
87
14.6M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
14.6M
        upsample->color_buf + ci);
89
#ifdef WITH_PROFILE
90
      cinfo->master->upsample_elapsed += getTime() - cinfo->master->start;
91
      cinfo->master->upsample_msamples +=
92
        (double)cinfo->output_width * cinfo->max_v_samp_factor / 1000000.;
93
#endif
94
14.6M
    }
95
8.35M
    upsample->next_row_out = 0;
96
8.35M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
8.35M
  num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out);
102
  /* Not more than the distance to the end of the image.  Need this test
103
   * in case the image height is not a multiple of max_v_samp_factor:
104
   */
105
8.35M
  if (num_rows > upsample->rows_to_go)
106
2.54k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
8.35M
  out_rows_avail -= *out_row_ctr;
109
8.35M
  if (num_rows > out_rows_avail)
110
713
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
8.35M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
8.35M
                                      (JDIMENSION)upsample->next_row_out,
117
8.35M
                                      output_buf + *out_row_ctr,
118
8.35M
                                      (int)num_rows);
119
#ifdef WITH_PROFILE
120
  cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
121
  cinfo->master->cconvert_mpixels +=
122
    (double)cinfo->output_width * num_rows / 1000000.;
123
#endif
124
125
  /* Adjust counts */
126
8.35M
  *out_row_ctr += num_rows;
127
8.35M
  upsample->rows_to_go -= num_rows;
128
8.35M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
8.35M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
8.35M
    (*in_row_group_ctr)++;
132
8.35M
}
jdsample-16.c:sep_upsample
Line
Count
Source
70
1.07M
{
71
1.07M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
1.07M
  int ci;
73
1.07M
  jpeg_component_info *compptr;
74
1.07M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
1.07M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
3.93M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
2.85M
         ci++, compptr++) {
80
      /* Invoke per-component upsample method.  Notice we pass a POINTER
81
       * to color_buf[ci], so that fullsize_upsample can change it.
82
       */
83
#ifdef WITH_PROFILE
84
      cinfo->master->start = getTime();
85
#endif
86
2.85M
      (*upsample->methods[ci]) (cinfo, compptr,
87
2.85M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
2.85M
        upsample->color_buf + ci);
89
#ifdef WITH_PROFILE
90
      cinfo->master->upsample_elapsed += getTime() - cinfo->master->start;
91
      cinfo->master->upsample_msamples +=
92
        (double)cinfo->output_width * cinfo->max_v_samp_factor / 1000000.;
93
#endif
94
2.85M
    }
95
1.07M
    upsample->next_row_out = 0;
96
1.07M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
1.07M
  num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out);
102
  /* Not more than the distance to the end of the image.  Need this test
103
   * in case the image height is not a multiple of max_v_samp_factor:
104
   */
105
1.07M
  if (num_rows > upsample->rows_to_go)
106
180
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
1.07M
  out_rows_avail -= *out_row_ctr;
109
1.07M
  if (num_rows > out_rows_avail)
110
0
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
1.07M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
1.07M
                                      (JDIMENSION)upsample->next_row_out,
117
1.07M
                                      output_buf + *out_row_ctr,
118
1.07M
                                      (int)num_rows);
119
#ifdef WITH_PROFILE
120
  cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
121
  cinfo->master->cconvert_mpixels +=
122
    (double)cinfo->output_width * num_rows / 1000000.;
123
#endif
124
125
  /* Adjust counts */
126
1.07M
  *out_row_ctr += num_rows;
127
1.07M
  upsample->rows_to_go -= num_rows;
128
1.07M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
1.07M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
1.07M
    (*in_row_group_ctr)++;
132
1.07M
}
133
134
135
/*
136
 * These are the routines invoked by sep_upsample to upsample values of a
137
 * single component.  One row group is processed per call.
138
 */
139
140
141
/*
142
 * For full-size components, we just make color_buf[ci] point at the
143
 * input buffer, and thus avoid copying any data.  Note that this is
144
 * safe only because sep_upsample doesn't declare the input row group
145
 * "consumed" until we are done color converting and emitting it.
146
 */
147
148
METHODDEF(void)
149
fullsize_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
150
                  _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
151
18.9M
{
152
18.9M
  *output_data_ptr = input_data;
153
18.9M
}
jdsample-8.c:fullsize_upsample
Line
Count
Source
151
9.88M
{
152
9.88M
  *output_data_ptr = input_data;
153
9.88M
}
jdsample-12.c:fullsize_upsample
Line
Count
Source
151
8.34M
{
152
8.34M
  *output_data_ptr = input_data;
153
8.34M
}
jdsample-16.c:fullsize_upsample
Line
Count
Source
151
743k
{
152
743k
  *output_data_ptr = input_data;
153
743k
}
154
155
156
/*
157
 * This is a no-op version used for "uninteresting" components.
158
 * These components will not be referenced by color conversion.
159
 */
160
161
METHODDEF(void)
162
noop_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
163
              _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
164
5.52M
{
165
5.52M
  *output_data_ptr = NULL;      /* safety check */
166
5.52M
}
jdsample-8.c:noop_upsample
Line
Count
Source
164
3.19M
{
165
  *output_data_ptr = NULL;      /* safety check */
166
3.19M
}
jdsample-12.c:noop_upsample
Line
Count
Source
164
2.33M
{
165
  *output_data_ptr = NULL;      /* safety check */
166
2.33M
}
Unexecuted instantiation: jdsample-16.c:noop_upsample
167
168
169
/*
170
 * This version handles any integral sampling ratios.
171
 * This is not used for typical JPEG files, so it need not be fast.  Nor, for
172
 * that matter, is it particularly accurate: the algorithm is simple
173
 * replication of the input sample onto the corresponding output components.
174
 * The hi-falutin sampling literature refers to this as a "box filter".  A box
175
 * filter tends to introduce visible artifacts, so if you are actually going to
176
 * use 3:1 or 4:1 sampling ratios you would be well advised to improve this
177
 * code.
178
 */
179
180
METHODDEF(void)
181
int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
182
             _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
183
5.29M
{
184
5.29M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
5.29M
  _JSAMPARRAY output_data = *output_data_ptr;
186
5.29M
  register _JSAMPROW inptr, outptr;
187
5.29M
  register _JSAMPLE invalue;
188
5.29M
  register int h;
189
5.29M
  _JSAMPROW outend;
190
5.29M
  int h_expand, v_expand;
191
5.29M
  int inrow, outrow;
192
193
5.29M
  h_expand = upsample->h_expand[compptr->component_index];
194
5.29M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
5.29M
  inrow = outrow = 0;
197
12.0M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
6.75M
    inptr = input_data[inrow];
200
6.75M
    outptr = output_data[outrow];
201
6.75M
    outend = outptr + cinfo->output_width;
202
139M
    while (outptr < outend) {
203
132M
      invalue = *inptr++;
204
368M
      for (h = h_expand; h > 0; h--) {
205
235M
        *outptr++ = invalue;
206
235M
      }
207
132M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
6.75M
    if (v_expand > 1) {
210
3.67M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
3.67M
                         v_expand - 1, cinfo->output_width);
212
3.67M
    }
213
6.75M
    inrow++;
214
6.75M
    outrow += v_expand;
215
6.75M
  }
216
5.29M
}
jdsample-8.c:int_upsample
Line
Count
Source
183
2.40M
{
184
2.40M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
2.40M
  _JSAMPARRAY output_data = *output_data_ptr;
186
2.40M
  register _JSAMPROW inptr, outptr;
187
2.40M
  register _JSAMPLE invalue;
188
2.40M
  register int h;
189
2.40M
  _JSAMPROW outend;
190
2.40M
  int h_expand, v_expand;
191
2.40M
  int inrow, outrow;
192
193
2.40M
  h_expand = upsample->h_expand[compptr->component_index];
194
2.40M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
2.40M
  inrow = outrow = 0;
197
5.67M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
3.26M
    inptr = input_data[inrow];
200
3.26M
    outptr = output_data[outrow];
201
3.26M
    outend = outptr + cinfo->output_width;
202
66.4M
    while (outptr < outend) {
203
63.2M
      invalue = *inptr++;
204
182M
      for (h = h_expand; h > 0; h--) {
205
119M
        *outptr++ = invalue;
206
119M
      }
207
63.2M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
3.26M
    if (v_expand > 1) {
210
1.64M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
1.64M
                         v_expand - 1, cinfo->output_width);
212
1.64M
    }
213
3.26M
    inrow++;
214
3.26M
    outrow += v_expand;
215
3.26M
  }
216
2.40M
}
jdsample-12.c:int_upsample
Line
Count
Source
183
1.37M
{
184
1.37M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
1.37M
  _JSAMPARRAY output_data = *output_data_ptr;
186
1.37M
  register _JSAMPROW inptr, outptr;
187
1.37M
  register _JSAMPLE invalue;
188
1.37M
  register int h;
189
1.37M
  _JSAMPROW outend;
190
1.37M
  int h_expand, v_expand;
191
1.37M
  int inrow, outrow;
192
193
1.37M
  h_expand = upsample->h_expand[compptr->component_index];
194
1.37M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
1.37M
  inrow = outrow = 0;
197
2.99M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
1.61M
    inptr = input_data[inrow];
200
1.61M
    outptr = output_data[outrow];
201
1.61M
    outend = outptr + cinfo->output_width;
202
46.5M
    while (outptr < outend) {
203
44.8M
      invalue = *inptr++;
204
122M
      for (h = h_expand; h > 0; h--) {
205
78.1M
        *outptr++ = invalue;
206
78.1M
      }
207
44.8M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
1.61M
    if (v_expand > 1) {
210
1.08M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
1.08M
                         v_expand - 1, cinfo->output_width);
212
1.08M
    }
213
1.61M
    inrow++;
214
1.61M
    outrow += v_expand;
215
1.61M
  }
216
1.37M
}
jdsample-16.c:int_upsample
Line
Count
Source
183
1.51M
{
184
1.51M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
1.51M
  _JSAMPARRAY output_data = *output_data_ptr;
186
1.51M
  register _JSAMPROW inptr, outptr;
187
1.51M
  register _JSAMPLE invalue;
188
1.51M
  register int h;
189
1.51M
  _JSAMPROW outend;
190
1.51M
  int h_expand, v_expand;
191
1.51M
  int inrow, outrow;
192
193
1.51M
  h_expand = upsample->h_expand[compptr->component_index];
194
1.51M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
1.51M
  inrow = outrow = 0;
197
3.39M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
1.87M
    inptr = input_data[inrow];
200
1.87M
    outptr = output_data[outrow];
201
1.87M
    outend = outptr + cinfo->output_width;
202
26.4M
    while (outptr < outend) {
203
24.6M
      invalue = *inptr++;
204
63.2M
      for (h = h_expand; h > 0; h--) {
205
38.6M
        *outptr++ = invalue;
206
38.6M
      }
207
24.6M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
1.87M
    if (v_expand > 1) {
210
953k
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
953k
                         v_expand - 1, cinfo->output_width);
212
953k
    }
213
1.87M
    inrow++;
214
1.87M
    outrow += v_expand;
215
1.87M
  }
216
1.51M
}
217
218
219
/*
220
 * Fast processing for the common case of 2:1 horizontal and 1:1 vertical.
221
 * It's still a box filter.
222
 */
223
224
METHODDEF(void)
225
h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
226
              _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
227
1.97M
{
228
1.97M
  _JSAMPARRAY output_data = *output_data_ptr;
229
1.97M
  register _JSAMPROW inptr, outptr;
230
1.97M
  register _JSAMPLE invalue;
231
1.97M
  _JSAMPROW outend;
232
1.97M
  int inrow;
233
234
6.13M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
4.16M
    inptr = input_data[inrow];
236
4.16M
    outptr = output_data[inrow];
237
4.16M
    outend = outptr + cinfo->output_width;
238
47.7M
    while (outptr < outend) {
239
43.5M
      invalue = *inptr++;
240
43.5M
      *outptr++ = invalue;
241
43.5M
      *outptr++ = invalue;
242
43.5M
    }
243
4.16M
  }
244
1.97M
}
Unexecuted instantiation: jdsample-8.c:h2v1_upsample
jdsample-12.c:h2v1_upsample
Line
Count
Source
227
1.43M
{
228
1.43M
  _JSAMPARRAY output_data = *output_data_ptr;
229
1.43M
  register _JSAMPROW inptr, outptr;
230
1.43M
  register _JSAMPLE invalue;
231
1.43M
  _JSAMPROW outend;
232
1.43M
  int inrow;
233
234
4.31M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
2.88M
    inptr = input_data[inrow];
236
2.88M
    outptr = output_data[inrow];
237
2.88M
    outend = outptr + cinfo->output_width;
238
26.0M
    while (outptr < outend) {
239
23.1M
      invalue = *inptr++;
240
23.1M
      *outptr++ = invalue;
241
23.1M
      *outptr++ = invalue;
242
23.1M
    }
243
2.88M
  }
244
1.43M
}
jdsample-16.c:h2v1_upsample
Line
Count
Source
227
542k
{
228
542k
  _JSAMPARRAY output_data = *output_data_ptr;
229
542k
  register _JSAMPROW inptr, outptr;
230
542k
  register _JSAMPLE invalue;
231
542k
  _JSAMPROW outend;
232
542k
  int inrow;
233
234
1.82M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
1.28M
    inptr = input_data[inrow];
236
1.28M
    outptr = output_data[inrow];
237
1.28M
    outend = outptr + cinfo->output_width;
238
21.6M
    while (outptr < outend) {
239
20.3M
      invalue = *inptr++;
240
20.3M
      *outptr++ = invalue;
241
20.3M
      *outptr++ = invalue;
242
20.3M
    }
243
1.28M
  }
244
542k
}
245
246
247
/*
248
 * Fast processing for the common case of 2:1 horizontal and 2:1 vertical.
249
 * It's still a box filter.
250
 */
251
252
METHODDEF(void)
253
h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
254
              _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
255
452k
{
256
452k
  _JSAMPARRAY output_data = *output_data_ptr;
257
452k
  register _JSAMPROW inptr, outptr;
258
452k
  register _JSAMPLE invalue;
259
452k
  _JSAMPROW outend;
260
452k
  int inrow, outrow;
261
262
452k
  inrow = outrow = 0;
263
1.06M
  while (outrow < cinfo->max_v_samp_factor) {
264
609k
    inptr = input_data[inrow];
265
609k
    outptr = output_data[outrow];
266
609k
    outend = outptr + cinfo->output_width;
267
25.7M
    while (outptr < outend) {
268
25.1M
      invalue = *inptr++;
269
25.1M
      *outptr++ = invalue;
270
25.1M
      *outptr++ = invalue;
271
25.1M
    }
272
609k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
609k
                       cinfo->output_width);
274
609k
    inrow++;
275
609k
    outrow += 2;
276
609k
  }
277
452k
}
Unexecuted instantiation: jdsample-8.c:h2v2_upsample
jdsample-12.c:h2v2_upsample
Line
Count
Source
255
400k
{
256
400k
  _JSAMPARRAY output_data = *output_data_ptr;
257
400k
  register _JSAMPROW inptr, outptr;
258
400k
  register _JSAMPLE invalue;
259
400k
  _JSAMPROW outend;
260
400k
  int inrow, outrow;
261
262
400k
  inrow = outrow = 0;
263
909k
  while (outrow < cinfo->max_v_samp_factor) {
264
508k
    inptr = input_data[inrow];
265
508k
    outptr = output_data[outrow];
266
508k
    outend = outptr + cinfo->output_width;
267
15.8M
    while (outptr < outend) {
268
15.2M
      invalue = *inptr++;
269
15.2M
      *outptr++ = invalue;
270
15.2M
      *outptr++ = invalue;
271
15.2M
    }
272
508k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
508k
                       cinfo->output_width);
274
508k
    inrow++;
275
508k
    outrow += 2;
276
508k
  }
277
400k
}
jdsample-16.c:h2v2_upsample
Line
Count
Source
255
52.0k
{
256
52.0k
  _JSAMPARRAY output_data = *output_data_ptr;
257
52.0k
  register _JSAMPROW inptr, outptr;
258
52.0k
  register _JSAMPLE invalue;
259
52.0k
  _JSAMPROW outend;
260
52.0k
  int inrow, outrow;
261
262
52.0k
  inrow = outrow = 0;
263
152k
  while (outrow < cinfo->max_v_samp_factor) {
264
100k
    inptr = input_data[inrow];
265
100k
    outptr = output_data[outrow];
266
100k
    outend = outptr + cinfo->output_width;
267
9.91M
    while (outptr < outend) {
268
9.81M
      invalue = *inptr++;
269
9.81M
      *outptr++ = invalue;
270
9.81M
      *outptr++ = invalue;
271
9.81M
    }
272
100k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
100k
                       cinfo->output_width);
274
100k
    inrow++;
275
100k
    outrow += 2;
276
100k
  }
277
52.0k
}
278
279
280
/*
281
 * Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
282
 *
283
 * The upsampling algorithm is linear interpolation between component centers,
284
 * also known as a "triangle filter".  This is a good compromise between speed
285
 * and visual quality.  The centers of the output components are 1/4 and 3/4 of
286
 * the way between input component centers.
287
 *
288
 * A note about the "bias" calculations: when rounding fractional values to
289
 * integer, we do not want to always round 0.5 up to the next integer.
290
 * If we did that, we'd introduce a noticeable bias towards larger values.
291
 * Instead, this code is arranged so that 0.5 will be rounded up or down at
292
 * alternate pixel locations (a simple ordered dither pattern).
293
 */
294
295
METHODDEF(void)
296
h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
297
                    _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
298
319k
{
299
319k
  _JSAMPARRAY output_data = *output_data_ptr;
300
319k
  register _JSAMPROW inptr, outptr;
301
319k
  register int invalue;
302
319k
  register JDIMENSION colctr;
303
319k
  int inrow;
304
305
1.00M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
688k
    inptr = input_data[inrow];
307
688k
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
688k
    invalue = *inptr++;
310
688k
    *outptr++ = (_JSAMPLE)invalue;
311
688k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
6.57M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer component + 1/4 * further component */
315
5.88M
      invalue = (*inptr++) * 3;
316
5.88M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
5.88M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
5.88M
    }
319
320
    /* Special case for last column */
321
688k
    invalue = *inptr;
322
688k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
688k
    *outptr++ = (_JSAMPLE)invalue;
324
688k
  }
325
319k
}
Unexecuted instantiation: jdsample-8.c:h2v1_fancy_upsample
jdsample-12.c:h2v1_fancy_upsample
Line
Count
Source
298
319k
{
299
319k
  _JSAMPARRAY output_data = *output_data_ptr;
300
319k
  register _JSAMPROW inptr, outptr;
301
319k
  register int invalue;
302
319k
  register JDIMENSION colctr;
303
319k
  int inrow;
304
305
1.00M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
688k
    inptr = input_data[inrow];
307
688k
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
688k
    invalue = *inptr++;
310
688k
    *outptr++ = (_JSAMPLE)invalue;
311
688k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
6.57M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer component + 1/4 * further component */
315
5.88M
      invalue = (*inptr++) * 3;
316
5.88M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
5.88M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
5.88M
    }
319
320
    /* Special case for last column */
321
688k
    invalue = *inptr;
322
688k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
688k
    *outptr++ = (_JSAMPLE)invalue;
324
688k
  }
325
319k
}
Unexecuted instantiation: jdsample-16.c:h2v1_fancy_upsample
326
327
328
/*
329
 * Fancy processing for 1:1 horizontal and 2:1 vertical (4:4:0 subsampling).
330
 *
331
 * This is a less common case, but it can be encountered when losslessly
332
 * rotating/transposing a JPEG file that uses 4:2:2 chroma subsampling.
333
 */
334
335
METHODDEF(void)
336
h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
337
                    _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
338
599k
{
339
599k
  _JSAMPARRAY output_data = *output_data_ptr;
340
599k
  _JSAMPROW inptr0, inptr1, outptr;
341
#if BITS_IN_JSAMPLE == 8
342
  int thiscolsum, bias;
343
#else
344
  JLONG thiscolsum, bias;
345
#endif
346
599k
  JDIMENSION colctr;
347
599k
  int inrow, outrow, v;
348
349
599k
  inrow = outrow = 0;
350
1.42M
  while (outrow < cinfo->max_v_samp_factor) {
351
2.46M
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
1.64M
      inptr0 = input_data[inrow];
354
1.64M
      if (v == 0) {             /* next nearest is row above */
355
820k
        inptr1 = input_data[inrow - 1];
356
820k
        bias = 1;
357
820k
      } else {                  /* next nearest is row below */
358
820k
        inptr1 = input_data[inrow + 1];
359
820k
        bias = 2;
360
820k
      }
361
1.64M
      outptr = output_data[outrow++];
362
363
43.6M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
42.0M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
42.0M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
42.0M
      }
367
1.64M
    }
368
820k
    inrow++;
369
820k
  }
370
599k
}
jdsample-8.c:h1v2_fancy_upsample
Line
Count
Source
338
395k
{
339
395k
  _JSAMPARRAY output_data = *output_data_ptr;
340
395k
  _JSAMPROW inptr0, inptr1, outptr;
341
395k
#if BITS_IN_JSAMPLE == 8
342
395k
  int thiscolsum, bias;
343
#else
344
  JLONG thiscolsum, bias;
345
#endif
346
395k
  JDIMENSION colctr;
347
395k
  int inrow, outrow, v;
348
349
395k
  inrow = outrow = 0;
350
856k
  while (outrow < cinfo->max_v_samp_factor) {
351
1.38M
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
921k
      inptr0 = input_data[inrow];
354
921k
      if (v == 0) {             /* next nearest is row above */
355
460k
        inptr1 = input_data[inrow - 1];
356
460k
        bias = 1;
357
460k
      } else {                  /* next nearest is row below */
358
460k
        inptr1 = input_data[inrow + 1];
359
460k
        bias = 2;
360
460k
      }
361
921k
      outptr = output_data[outrow++];
362
363
22.9M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
21.9M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
21.9M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
21.9M
      }
367
921k
    }
368
460k
    inrow++;
369
460k
  }
370
395k
}
jdsample-12.c:h1v2_fancy_upsample
Line
Count
Source
338
203k
{
339
203k
  _JSAMPARRAY output_data = *output_data_ptr;
340
203k
  _JSAMPROW inptr0, inptr1, outptr;
341
#if BITS_IN_JSAMPLE == 8
342
  int thiscolsum, bias;
343
#else
344
203k
  JLONG thiscolsum, bias;
345
203k
#endif
346
203k
  JDIMENSION colctr;
347
203k
  int inrow, outrow, v;
348
349
203k
  inrow = outrow = 0;
350
563k
  while (outrow < cinfo->max_v_samp_factor) {
351
1.08M
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
720k
      inptr0 = input_data[inrow];
354
720k
      if (v == 0) {             /* next nearest is row above */
355
360k
        inptr1 = input_data[inrow - 1];
356
360k
        bias = 1;
357
360k
      } else {                  /* next nearest is row below */
358
360k
        inptr1 = input_data[inrow + 1];
359
360k
        bias = 2;
360
360k
      }
361
720k
      outptr = output_data[outrow++];
362
363
20.7M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
20.0M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
20.0M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
20.0M
      }
367
720k
    }
368
360k
    inrow++;
369
360k
  }
370
203k
}
Unexecuted instantiation: jdsample-16.c:h1v2_fancy_upsample
371
372
373
/*
374
 * Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
375
 * Again a triangle filter; see comments for h2v1 case, above.
376
 *
377
 * It is OK for us to reference the adjacent input rows because we demanded
378
 * context from the main buffer controller (see initialization code).
379
 */
380
381
METHODDEF(void)
382
h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
383
                    _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
384
237k
{
385
237k
  _JSAMPARRAY output_data = *output_data_ptr;
386
237k
  register _JSAMPROW inptr0, inptr1, outptr;
387
#if BITS_IN_JSAMPLE == 8
388
  register int thiscolsum, lastcolsum, nextcolsum;
389
#else
390
  register JLONG thiscolsum, lastcolsum, nextcolsum;
391
#endif
392
237k
  register JDIMENSION colctr;
393
237k
  int inrow, outrow, v;
394
395
237k
  inrow = outrow = 0;
396
542k
  while (outrow < cinfo->max_v_samp_factor) {
397
914k
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
609k
      inptr0 = input_data[inrow];
400
609k
      if (v == 0)               /* next nearest is row above */
401
304k
        inptr1 = input_data[inrow - 1];
402
304k
      else                      /* next nearest is row below */
403
304k
        inptr1 = input_data[inrow + 1];
404
609k
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
609k
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
609k
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
609k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
609k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
609k
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
5.67M
      for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
414
        /* General case: 3/4 * nearer component + 1/4 * further component in
415
         * each dimension, thus 9/16, 3/16, 3/16, 1/16 overall
416
         */
417
5.06M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
5.06M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
5.06M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
5.06M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
5.06M
      }
422
423
      /* Special case for last column */
424
609k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
609k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
609k
    }
427
304k
    inrow++;
428
304k
  }
429
237k
}
Unexecuted instantiation: jdsample-8.c:h2v2_fancy_upsample
jdsample-12.c:h2v2_fancy_upsample
Line
Count
Source
384
237k
{
385
237k
  _JSAMPARRAY output_data = *output_data_ptr;
386
237k
  register _JSAMPROW inptr0, inptr1, outptr;
387
#if BITS_IN_JSAMPLE == 8
388
  register int thiscolsum, lastcolsum, nextcolsum;
389
#else
390
237k
  register JLONG thiscolsum, lastcolsum, nextcolsum;
391
237k
#endif
392
237k
  register JDIMENSION colctr;
393
237k
  int inrow, outrow, v;
394
395
237k
  inrow = outrow = 0;
396
542k
  while (outrow < cinfo->max_v_samp_factor) {
397
914k
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
609k
      inptr0 = input_data[inrow];
400
609k
      if (v == 0)               /* next nearest is row above */
401
304k
        inptr1 = input_data[inrow - 1];
402
304k
      else                      /* next nearest is row below */
403
304k
        inptr1 = input_data[inrow + 1];
404
609k
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
609k
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
609k
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
609k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
609k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
609k
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
5.67M
      for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
414
        /* General case: 3/4 * nearer component + 1/4 * further component in
415
         * each dimension, thus 9/16, 3/16, 3/16, 1/16 overall
416
         */
417
5.06M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
5.06M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
5.06M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
5.06M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
5.06M
      }
422
423
      /* Special case for last column */
424
609k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
609k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
609k
    }
427
304k
    inrow++;
428
304k
  }
429
237k
}
Unexecuted instantiation: jdsample-16.c:h2v2_fancy_upsample
430
431
432
/*
433
 * Module initialization routine for upsampling.
434
 */
435
436
GLOBAL(void)
437
_jinit_upsampler(j_decompress_ptr cinfo)
438
22.0k
{
439
22.0k
  my_upsample_ptr upsample;
440
22.0k
  int ci;
441
22.0k
  jpeg_component_info *compptr;
442
22.0k
  boolean need_buffer, do_fancy;
443
22.0k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
22.0k
#ifdef D_LOSSLESS_SUPPORTED
446
22.0k
  if (cinfo->master->lossless) {
447
#if BITS_IN_JSAMPLE == 8
448
1.26k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
449
#else
450
2.68k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
2.68k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
3.95k
  } else
455
18.1k
#endif
456
18.1k
  {
457
18.1k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
18.1k
  }
460
461
22.0k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
22.0k
    upsample = (my_upsample_ptr)
463
22.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
22.0k
                                  sizeof(my_upsampler));
465
22.0k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
22.0k
    upsample->pub.start_pass = start_pass_upsample;
467
22.0k
    upsample->pub._upsample = sep_upsample;
468
22.0k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
22.0k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
22.0k
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
473
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
474
475
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
476
   * so don't ask for it.
477
   */
478
22.0k
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
479
480
  /* Verify we can handle the sampling factors, select per-component methods,
481
   * and create storage as needed.
482
   */
483
63.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
41.1k
       ci++, compptr++) {
485
    /* Compute size of an "input group" after IDCT scaling.  This many samples
486
     * are to be converted to max_h_samp_factor * max_v_samp_factor components.
487
     */
488
41.1k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
41.1k
                 cinfo->_min_DCT_scaled_size;
490
41.1k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
41.1k
                 cinfo->_min_DCT_scaled_size;
492
41.1k
    h_out_group = cinfo->max_h_samp_factor;
493
41.1k
    v_out_group = cinfo->max_v_samp_factor;
494
41.1k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
41.1k
    need_buffer = TRUE;
496
41.1k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
2.95k
      upsample->methods[ci] = noop_upsample;
499
2.95k
      need_buffer = FALSE;
500
38.1k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
20.4k
      upsample->methods[ci] = fullsize_upsample;
503
20.4k
      need_buffer = FALSE;
504
20.4k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
4.15k
      if (do_fancy && compptr->downsampled_width > 2) {
507
#ifdef WITH_SIMD
508
261
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
261
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
0
        else
511
0
#endif
512
0
          upsample->methods[ci] = h2v1_fancy_upsample;
513
3.61k
      } else {
514
#ifdef WITH_SIMD
515
1.16k
        if (jsimd_set_h2v1_upsample(cinfo))
516
1.16k
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
0
        else
518
0
#endif
519
0
          upsample->methods[ci] = h2v1_upsample;
520
3.61k
      }
521
13.5k
    } else if (h_in_group == h_out_group &&
522
5.76k
               v_in_group * 2 == v_out_group && do_fancy) {
523
      /* Non-fancy upsampling is handled by the generic method */
524
#if defined(WITH_SIMD) && (SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM)
525
      if (jsimd_set_h1v2_fancy_upsample(cinfo))
526
        upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
527
      else
528
#endif
529
658
        upsample->methods[ci] = h1v2_fancy_upsample;
530
658
      upsample->pub.need_context_rows = TRUE;
531
12.8k
    } else if (h_in_group * 2 == h_out_group &&
532
3.71k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
2.63k
      if (do_fancy && compptr->downsampled_width > 2) {
535
#ifdef WITH_SIMD
536
66
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
66
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
0
        else
539
0
#endif
540
0
          upsample->methods[ci] = h2v2_fancy_upsample;
541
233
        upsample->pub.need_context_rows = TRUE;
542
2.40k
      } else {
543
#ifdef WITH_SIMD
544
753
        if (jsimd_set_h2v2_upsample(cinfo))
545
753
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
0
        else
547
0
#endif
548
0
          upsample->methods[ci] = h2v2_upsample;
549
2.40k
      }
550
10.2k
    } else if ((h_out_group % h_in_group) == 0 &&
551
9.54k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
8.56k
      upsample->methods[ci] = int_upsample;
554
8.56k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
8.56k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
8.56k
    } else
557
1.68k
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
41.1k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
16.0k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
16.0k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
16.0k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
16.0k
                               (long)cinfo->max_h_samp_factor),
563
16.0k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
16.0k
    }
565
41.1k
  }
566
22.0k
}
jinit_upsampler
Line
Count
Source
438
11.8k
{
439
11.8k
  my_upsample_ptr upsample;
440
11.8k
  int ci;
441
11.8k
  jpeg_component_info *compptr;
442
11.8k
  boolean need_buffer, do_fancy;
443
11.8k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
11.8k
#ifdef D_LOSSLESS_SUPPORTED
446
11.8k
  if (cinfo->master->lossless) {
447
1.26k
#if BITS_IN_JSAMPLE == 8
448
1.26k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
449
#else
450
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
1.26k
  } else
455
10.5k
#endif
456
10.5k
  {
457
10.5k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
10.5k
  }
460
461
11.8k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
11.8k
    upsample = (my_upsample_ptr)
463
11.8k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
11.8k
                                  sizeof(my_upsampler));
465
11.8k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
11.8k
    upsample->pub.start_pass = start_pass_upsample;
467
11.8k
    upsample->pub._upsample = sep_upsample;
468
11.8k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
11.8k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
11.8k
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
473
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
474
475
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
476
   * so don't ask for it.
477
   */
478
11.8k
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
479
480
  /* Verify we can handle the sampling factors, select per-component methods,
481
   * and create storage as needed.
482
   */
483
32.1k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
20.3k
       ci++, compptr++) {
485
    /* Compute size of an "input group" after IDCT scaling.  This many samples
486
     * are to be converted to max_h_samp_factor * max_v_samp_factor components.
487
     */
488
20.3k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
20.3k
                 cinfo->_min_DCT_scaled_size;
490
20.3k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
20.3k
                 cinfo->_min_DCT_scaled_size;
492
20.3k
    h_out_group = cinfo->max_h_samp_factor;
493
20.3k
    v_out_group = cinfo->max_v_samp_factor;
494
20.3k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
20.3k
    need_buffer = TRUE;
496
20.3k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
1.58k
      upsample->methods[ci] = noop_upsample;
499
1.58k
      need_buffer = FALSE;
500
18.7k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
11.1k
      upsample->methods[ci] = fullsize_upsample;
503
11.1k
      need_buffer = FALSE;
504
11.1k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
1.42k
      if (do_fancy && compptr->downsampled_width > 2) {
507
261
#ifdef WITH_SIMD
508
261
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
261
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
0
        else
511
0
#endif
512
0
          upsample->methods[ci] = h2v1_fancy_upsample;
513
1.16k
      } else {
514
1.16k
#ifdef WITH_SIMD
515
1.16k
        if (jsimd_set_h2v1_upsample(cinfo))
516
1.16k
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
0
        else
518
0
#endif
519
0
          upsample->methods[ci] = h2v1_upsample;
520
1.16k
      }
521
6.15k
    } else if (h_in_group == h_out_group &&
522
2.83k
               v_in_group * 2 == v_out_group && do_fancy) {
523
      /* Non-fancy upsampling is handled by the generic method */
524
#if defined(WITH_SIMD) && (SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM)
525
      if (jsimd_set_h1v2_fancy_upsample(cinfo))
526
        upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
527
      else
528
#endif
529
337
        upsample->methods[ci] = h1v2_fancy_upsample;
530
337
      upsample->pub.need_context_rows = TRUE;
531
5.82k
    } else if (h_in_group * 2 == h_out_group &&
532
1.38k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
819
      if (do_fancy && compptr->downsampled_width > 2) {
535
66
#ifdef WITH_SIMD
536
66
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
66
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
0
        else
539
0
#endif
540
0
          upsample->methods[ci] = h2v2_fancy_upsample;
541
66
        upsample->pub.need_context_rows = TRUE;
542
753
      } else {
543
753
#ifdef WITH_SIMD
544
753
        if (jsimd_set_h2v2_upsample(cinfo))
545
753
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
0
        else
547
0
#endif
548
0
          upsample->methods[ci] = h2v2_upsample;
549
753
      }
550
5.00k
    } else if ((h_out_group % h_in_group) == 0 &&
551
4.73k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
3.98k
      upsample->methods[ci] = int_upsample;
554
3.98k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
3.98k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
3.98k
    } else
557
1.01k
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
20.3k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
6.56k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
6.56k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
6.56k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
6.56k
                               (long)cinfo->max_h_samp_factor),
563
6.56k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
6.56k
    }
565
20.3k
  }
566
11.8k
}
j12init_upsampler
Line
Count
Source
438
8.81k
{
439
8.81k
  my_upsample_ptr upsample;
440
8.81k
  int ci;
441
8.81k
  jpeg_component_info *compptr;
442
8.81k
  boolean need_buffer, do_fancy;
443
8.81k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
8.81k
#ifdef D_LOSSLESS_SUPPORTED
446
8.81k
  if (cinfo->master->lossless) {
447
#if BITS_IN_JSAMPLE == 8
448
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
449
#else
450
1.23k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
1.23k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
1.23k
  } else
455
7.57k
#endif
456
7.57k
  {
457
7.57k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
7.57k
  }
460
461
8.81k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
8.81k
    upsample = (my_upsample_ptr)
463
8.81k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
8.81k
                                  sizeof(my_upsampler));
465
8.81k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
8.81k
    upsample->pub.start_pass = start_pass_upsample;
467
8.81k
    upsample->pub._upsample = sep_upsample;
468
8.81k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
8.81k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
8.81k
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
473
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
474
475
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
476
   * so don't ask for it.
477
   */
478
8.81k
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
479
480
  /* Verify we can handle the sampling factors, select per-component methods,
481
   * and create storage as needed.
482
   */
483
25.4k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
16.6k
       ci++, compptr++) {
485
    /* Compute size of an "input group" after IDCT scaling.  This many samples
486
     * are to be converted to max_h_samp_factor * max_v_samp_factor components.
487
     */
488
16.6k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
16.6k
                 cinfo->_min_DCT_scaled_size;
490
16.6k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
16.6k
                 cinfo->_min_DCT_scaled_size;
492
16.6k
    h_out_group = cinfo->max_h_samp_factor;
493
16.6k
    v_out_group = cinfo->max_v_samp_factor;
494
16.6k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
16.6k
    need_buffer = TRUE;
496
16.6k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
1.37k
      upsample->methods[ci] = noop_upsample;
499
1.37k
      need_buffer = FALSE;
500
15.2k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
8.44k
      upsample->methods[ci] = fullsize_upsample;
503
8.44k
      need_buffer = FALSE;
504
8.44k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
1.73k
      if (do_fancy && compptr->downsampled_width > 2) {
507
#ifdef WITH_SIMD
508
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
        else
511
#endif
512
285
          upsample->methods[ci] = h2v1_fancy_upsample;
513
1.45k
      } else {
514
#ifdef WITH_SIMD
515
        if (jsimd_set_h2v1_upsample(cinfo))
516
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
        else
518
#endif
519
1.45k
          upsample->methods[ci] = h2v1_upsample;
520
1.45k
      }
521
5.11k
    } else if (h_in_group == h_out_group &&
522
2.03k
               v_in_group * 2 == v_out_group && do_fancy) {
523
      /* Non-fancy upsampling is handled by the generic method */
524
#if defined(WITH_SIMD) && (SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM)
525
      if (jsimd_set_h1v2_fancy_upsample(cinfo))
526
        upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
527
      else
528
#endif
529
321
        upsample->methods[ci] = h1v2_fancy_upsample;
530
321
      upsample->pub.need_context_rows = TRUE;
531
4.79k
    } else if (h_in_group * 2 == h_out_group &&
532
1.38k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
999
      if (do_fancy && compptr->downsampled_width > 2) {
535
#ifdef WITH_SIMD
536
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
        else
539
#endif
540
167
          upsample->methods[ci] = h2v2_fancy_upsample;
541
167
        upsample->pub.need_context_rows = TRUE;
542
832
      } else {
543
#ifdef WITH_SIMD
544
        if (jsimd_set_h2v2_upsample(cinfo))
545
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
        else
547
#endif
548
832
          upsample->methods[ci] = h2v2_upsample;
549
832
      }
550
3.79k
    } else if ((h_out_group % h_in_group) == 0 &&
551
3.35k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
3.13k
      upsample->methods[ci] = int_upsample;
554
3.13k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
3.13k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
3.13k
    } else
557
653
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
16.6k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
6.19k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
6.19k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
6.19k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
6.19k
                               (long)cinfo->max_h_samp_factor),
563
6.19k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
6.19k
    }
565
16.6k
  }
566
8.81k
}
j16init_upsampler
Line
Count
Source
438
1.44k
{
439
1.44k
  my_upsample_ptr upsample;
440
1.44k
  int ci;
441
1.44k
  jpeg_component_info *compptr;
442
1.44k
  boolean need_buffer, do_fancy;
443
1.44k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
1.44k
#ifdef D_LOSSLESS_SUPPORTED
446
1.44k
  if (cinfo->master->lossless) {
447
#if BITS_IN_JSAMPLE == 8
448
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
449
#else
450
1.44k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
1.44k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
1.44k
  } else
455
0
#endif
456
0
  {
457
0
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
0
  }
460
461
1.44k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
1.44k
    upsample = (my_upsample_ptr)
463
1.44k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
1.44k
                                  sizeof(my_upsampler));
465
1.44k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
1.44k
    upsample->pub.start_pass = start_pass_upsample;
467
1.44k
    upsample->pub._upsample = sep_upsample;
468
1.44k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
1.44k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
1.44k
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
473
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
474
475
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
476
   * so don't ask for it.
477
   */
478
1.44k
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
479
480
  /* Verify we can handle the sampling factors, select per-component methods,
481
   * and create storage as needed.
482
   */
483
5.57k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
4.13k
       ci++, compptr++) {
485
    /* Compute size of an "input group" after IDCT scaling.  This many samples
486
     * are to be converted to max_h_samp_factor * max_v_samp_factor components.
487
     */
488
4.13k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
4.13k
                 cinfo->_min_DCT_scaled_size;
490
4.13k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
4.13k
                 cinfo->_min_DCT_scaled_size;
492
4.13k
    h_out_group = cinfo->max_h_samp_factor;
493
4.13k
    v_out_group = cinfo->max_v_samp_factor;
494
4.13k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
4.13k
    need_buffer = TRUE;
496
4.13k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
0
      upsample->methods[ci] = noop_upsample;
499
0
      need_buffer = FALSE;
500
4.13k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
860
      upsample->methods[ci] = fullsize_upsample;
503
860
      need_buffer = FALSE;
504
3.27k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
998
      if (do_fancy && compptr->downsampled_width > 2) {
507
#ifdef WITH_SIMD
508
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
        else
511
#endif
512
0
          upsample->methods[ci] = h2v1_fancy_upsample;
513
998
      } else {
514
#ifdef WITH_SIMD
515
        if (jsimd_set_h2v1_upsample(cinfo))
516
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
        else
518
#endif
519
998
          upsample->methods[ci] = h2v1_upsample;
520
998
      }
521
2.27k
    } else if (h_in_group == h_out_group &&
522
892
               v_in_group * 2 == v_out_group && do_fancy) {
523
      /* Non-fancy upsampling is handled by the generic method */
524
#if defined(WITH_SIMD) && (SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM)
525
      if (jsimd_set_h1v2_fancy_upsample(cinfo))
526
        upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
527
      else
528
#endif
529
0
        upsample->methods[ci] = h1v2_fancy_upsample;
530
0
      upsample->pub.need_context_rows = TRUE;
531
2.27k
    } else if (h_in_group * 2 == h_out_group &&
532
933
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
817
      if (do_fancy && compptr->downsampled_width > 2) {
535
#ifdef WITH_SIMD
536
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
        else
539
#endif
540
0
          upsample->methods[ci] = h2v2_fancy_upsample;
541
0
        upsample->pub.need_context_rows = TRUE;
542
817
      } else {
543
#ifdef WITH_SIMD
544
        if (jsimd_set_h2v2_upsample(cinfo))
545
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
        else
547
#endif
548
817
          upsample->methods[ci] = h2v2_upsample;
549
817
      }
550
1.45k
    } else if ((h_out_group % h_in_group) == 0 &&
551
1.44k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
1.43k
      upsample->methods[ci] = int_upsample;
554
1.43k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
1.43k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
1.43k
    } else
557
21
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
4.13k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
3.25k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
3.25k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
3.25k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
3.25k
                               (long)cinfo->max_h_samp_factor),
563
3.25k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
3.25k
    }
565
4.13k
  }
566
1.44k
}
567
568
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */