Coverage Report

Created: 2026-10-28 06:05

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
13.0k
{
48
13.0k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
13.0k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
13.0k
  upsample->rows_to_go = cinfo->output_height;
54
13.0k
}
jdsample-8.c:start_pass_upsample
Line
Count
Source
47
6.65k
{
48
6.65k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
6.65k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
6.65k
  upsample->rows_to_go = cinfo->output_height;
54
6.65k
}
jdsample-12.c:start_pass_upsample
Line
Count
Source
47
5.55k
{
48
5.55k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
5.55k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
5.55k
  upsample->rows_to_go = cinfo->output_height;
54
5.55k
}
jdsample-16.c:start_pass_upsample
Line
Count
Source
47
796
{
48
796
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
796
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
796
  upsample->rows_to_go = cinfo->output_height;
54
796
}
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
20.7M
{
71
20.7M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
20.7M
  int ci;
73
20.7M
  jpeg_component_info *compptr;
74
20.7M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
20.7M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
55.1M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
34.3M
         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.3M
      (*upsample->methods[ci]) (cinfo, compptr,
87
34.3M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
34.3M
        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.3M
    }
95
20.7M
    upsample->next_row_out = 0;
96
20.7M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
20.7M
  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
20.7M
  if (num_rows > upsample->rows_to_go)
106
4.50k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
20.7M
  out_rows_avail -= *out_row_ctr;
109
20.7M
  if (num_rows > out_rows_avail)
110
4.69k
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
20.7M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
20.7M
                                      (JDIMENSION)upsample->next_row_out,
117
20.7M
                                      output_buf + *out_row_ctr,
118
20.7M
                                      (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
20.7M
  *out_row_ctr += num_rows;
127
20.7M
  upsample->rows_to_go -= num_rows;
128
20.7M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
20.7M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
20.7M
    (*in_row_group_ctr)++;
132
20.7M
}
jdsample-8.c:sep_upsample
Line
Count
Source
70
10.5M
{
71
10.5M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
10.5M
  int ci;
73
10.5M
  jpeg_component_info *compptr;
74
10.5M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
10.5M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
28.1M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
17.5M
         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.5M
      (*upsample->methods[ci]) (cinfo, compptr,
87
17.5M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
17.5M
        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.5M
    }
95
10.5M
    upsample->next_row_out = 0;
96
10.5M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
10.5M
  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.5M
  if (num_rows > upsample->rows_to_go)
106
2.09k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
10.5M
  out_rows_avail -= *out_row_ctr;
109
10.5M
  if (num_rows > out_rows_avail)
110
2.29k
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
10.5M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
10.5M
                                      (JDIMENSION)upsample->next_row_out,
117
10.5M
                                      output_buf + *out_row_ctr,
118
10.5M
                                      (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.5M
  *out_row_ctr += num_rows;
127
10.5M
  upsample->rows_to_go -= num_rows;
128
10.5M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
10.5M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
10.5M
    (*in_row_group_ctr)++;
132
10.5M
}
jdsample-12.c:sep_upsample
Line
Count
Source
70
8.14M
{
71
8.14M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
8.14M
  int ci;
73
8.14M
  jpeg_component_info *compptr;
74
8.14M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
8.14M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
21.4M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
13.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
13.2M
      (*upsample->methods[ci]) (cinfo, compptr,
87
13.2M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
13.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
13.2M
    }
95
8.14M
    upsample->next_row_out = 0;
96
8.14M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
8.14M
  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.14M
  if (num_rows > upsample->rows_to_go)
106
2.17k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
8.14M
  out_rows_avail -= *out_row_ctr;
109
8.14M
  if (num_rows > out_rows_avail)
110
2.40k
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
8.14M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
8.14M
                                      (JDIMENSION)upsample->next_row_out,
117
8.14M
                                      output_buf + *out_row_ctr,
118
8.14M
                                      (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.14M
  *out_row_ctr += num_rows;
127
8.14M
  upsample->rows_to_go -= num_rows;
128
8.14M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
8.14M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
8.13M
    (*in_row_group_ctr)++;
132
8.14M
}
jdsample-16.c:sep_upsample
Line
Count
Source
70
2.03M
{
71
2.03M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
2.03M
  int ci;
73
2.03M
  jpeg_component_info *compptr;
74
2.03M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
2.03M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
5.59M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
3.56M
         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
3.56M
      (*upsample->methods[ci]) (cinfo, compptr,
87
3.56M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
3.56M
        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
3.56M
    }
95
2.03M
    upsample->next_row_out = 0;
96
2.03M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
2.03M
  num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out);
102
  /* Not more than the distance to the end of the image.  Need this test
103
   * in case the image height is not a multiple of max_v_samp_factor:
104
   */
105
2.03M
  if (num_rows > upsample->rows_to_go)
106
233
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
2.03M
  out_rows_avail -= *out_row_ctr;
109
2.03M
  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
2.03M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
2.03M
                                      (JDIMENSION)upsample->next_row_out,
117
2.03M
                                      output_buf + *out_row_ctr,
118
2.03M
                                      (int)num_rows);
119
#ifdef WITH_PROFILE
120
  cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
121
  cinfo->master->cconvert_mpixels +=
122
    (double)cinfo->output_width * num_rows / 1000000.;
123
#endif
124
125
  /* Adjust counts */
126
2.03M
  *out_row_ctr += num_rows;
127
2.03M
  upsample->rows_to_go -= num_rows;
128
2.03M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
2.03M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
2.03M
    (*in_row_group_ctr)++;
132
2.03M
}
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
19.1M
{
152
19.1M
  *output_data_ptr = input_data;
153
19.1M
}
jdsample-8.c:fullsize_upsample
Line
Count
Source
151
9.47M
{
152
9.47M
  *output_data_ptr = input_data;
153
9.47M
}
jdsample-12.c:fullsize_upsample
Line
Count
Source
151
7.84M
{
152
7.84M
  *output_data_ptr = input_data;
153
7.84M
}
jdsample-16.c:fullsize_upsample
Line
Count
Source
151
1.82M
{
152
1.82M
  *output_data_ptr = input_data;
153
1.82M
}
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.23M
{
165
5.23M
  *output_data_ptr = NULL;      /* safety check */
166
5.23M
}
jdsample-8.c:noop_upsample
Line
Count
Source
164
2.96M
{
165
  *output_data_ptr = NULL;      /* safety check */
166
2.96M
}
jdsample-12.c:noop_upsample
Line
Count
Source
164
2.27M
{
165
  *output_data_ptr = NULL;      /* safety check */
166
2.27M
}
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.86M
{
184
5.86M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
5.86M
  _JSAMPARRAY output_data = *output_data_ptr;
186
5.86M
  register _JSAMPROW inptr, outptr;
187
5.86M
  register _JSAMPLE invalue;
188
5.86M
  register int h;
189
5.86M
  _JSAMPROW outend;
190
5.86M
  int h_expand, v_expand;
191
5.86M
  int inrow, outrow;
192
193
5.86M
  h_expand = upsample->h_expand[compptr->component_index];
194
5.86M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
5.86M
  inrow = outrow = 0;
197
13.6M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
7.83M
    inptr = input_data[inrow];
200
7.83M
    outptr = output_data[outrow];
201
7.83M
    outend = outptr + cinfo->output_width;
202
148M
    while (outptr < outend) {
203
140M
      invalue = *inptr++;
204
396M
      for (h = h_expand; h > 0; h--) {
205
256M
        *outptr++ = invalue;
206
256M
      }
207
140M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
7.83M
    if (v_expand > 1) {
210
4.10M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
4.10M
                         v_expand - 1, cinfo->output_width);
212
4.10M
    }
213
7.83M
    inrow++;
214
7.83M
    outrow += v_expand;
215
7.83M
  }
216
5.86M
}
jdsample-8.c:int_upsample
Line
Count
Source
183
3.25M
{
184
3.25M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
3.25M
  _JSAMPARRAY output_data = *output_data_ptr;
186
3.25M
  register _JSAMPROW inptr, outptr;
187
3.25M
  register _JSAMPLE invalue;
188
3.25M
  register int h;
189
3.25M
  _JSAMPROW outend;
190
3.25M
  int h_expand, v_expand;
191
3.25M
  int inrow, outrow;
192
193
3.25M
  h_expand = upsample->h_expand[compptr->component_index];
194
3.25M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
3.25M
  inrow = outrow = 0;
197
7.71M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
4.46M
    inptr = input_data[inrow];
200
4.46M
    outptr = output_data[outrow];
201
4.46M
    outend = outptr + cinfo->output_width;
202
63.1M
    while (outptr < outend) {
203
58.7M
      invalue = *inptr++;
204
162M
      for (h = h_expand; h > 0; h--) {
205
104M
        *outptr++ = invalue;
206
104M
      }
207
58.7M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
4.46M
    if (v_expand > 1) {
210
2.39M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
2.39M
                         v_expand - 1, cinfo->output_width);
212
2.39M
    }
213
4.46M
    inrow++;
214
4.46M
    outrow += v_expand;
215
4.46M
  }
216
3.25M
}
jdsample-12.c:int_upsample
Line
Count
Source
183
1.65M
{
184
1.65M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
1.65M
  _JSAMPARRAY output_data = *output_data_ptr;
186
1.65M
  register _JSAMPROW inptr, outptr;
187
1.65M
  register _JSAMPLE invalue;
188
1.65M
  register int h;
189
1.65M
  _JSAMPROW outend;
190
1.65M
  int h_expand, v_expand;
191
1.65M
  int inrow, outrow;
192
193
1.65M
  h_expand = upsample->h_expand[compptr->component_index];
194
1.65M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
1.65M
  inrow = outrow = 0;
197
3.63M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
1.98M
    inptr = input_data[inrow];
200
1.98M
    outptr = output_data[outrow];
201
1.98M
    outend = outptr + cinfo->output_width;
202
53.0M
    while (outptr < outend) {
203
51.0M
      invalue = *inptr++;
204
137M
      for (h = h_expand; h > 0; h--) {
205
86.7M
        *outptr++ = invalue;
206
86.7M
      }
207
51.0M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
1.98M
    if (v_expand > 1) {
210
1.25M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
1.25M
                         v_expand - 1, cinfo->output_width);
212
1.25M
    }
213
1.98M
    inrow++;
214
1.98M
    outrow += v_expand;
215
1.98M
  }
216
1.65M
}
jdsample-16.c:int_upsample
Line
Count
Source
183
959k
{
184
959k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
959k
  _JSAMPARRAY output_data = *output_data_ptr;
186
959k
  register _JSAMPROW inptr, outptr;
187
959k
  register _JSAMPLE invalue;
188
959k
  register int h;
189
959k
  _JSAMPROW outend;
190
959k
  int h_expand, v_expand;
191
959k
  int inrow, outrow;
192
193
959k
  h_expand = upsample->h_expand[compptr->component_index];
194
959k
  v_expand = upsample->v_expand[compptr->component_index];
195
196
959k
  inrow = outrow = 0;
197
2.34M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
1.38M
    inptr = input_data[inrow];
200
1.38M
    outptr = output_data[outrow];
201
1.38M
    outend = outptr + cinfo->output_width;
202
31.8M
    while (outptr < outend) {
203
30.4M
      invalue = *inptr++;
204
96.1M
      for (h = h_expand; h > 0; h--) {
205
65.6M
        *outptr++ = invalue;
206
65.6M
      }
207
30.4M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
1.38M
    if (v_expand > 1) {
210
462k
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
462k
                         v_expand - 1, cinfo->output_width);
212
462k
    }
213
1.38M
    inrow++;
214
1.38M
    outrow += v_expand;
215
1.38M
  }
216
959k
}
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.45M
{
228
1.45M
  _JSAMPARRAY output_data = *output_data_ptr;
229
1.45M
  register _JSAMPROW inptr, outptr;
230
1.45M
  register _JSAMPLE invalue;
231
1.45M
  _JSAMPROW outend;
232
1.45M
  int inrow;
233
234
4.02M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
2.56M
    inptr = input_data[inrow];
236
2.56M
    outptr = output_data[inrow];
237
2.56M
    outend = outptr + cinfo->output_width;
238
41.9M
    while (outptr < outend) {
239
39.4M
      invalue = *inptr++;
240
39.4M
      *outptr++ = invalue;
241
39.4M
      *outptr++ = invalue;
242
39.4M
    }
243
2.56M
  }
244
1.45M
}
Unexecuted instantiation: jdsample-8.c:h2v1_upsample
jdsample-12.c:h2v1_upsample
Line
Count
Source
227
724k
{
228
724k
  _JSAMPARRAY output_data = *output_data_ptr;
229
724k
  register _JSAMPROW inptr, outptr;
230
724k
  register _JSAMPLE invalue;
231
724k
  _JSAMPROW outend;
232
724k
  int inrow;
233
234
2.46M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
1.74M
    inptr = input_data[inrow];
236
1.74M
    outptr = output_data[inrow];
237
1.74M
    outend = outptr + cinfo->output_width;
238
25.3M
    while (outptr < outend) {
239
23.6M
      invalue = *inptr++;
240
23.6M
      *outptr++ = invalue;
241
23.6M
      *outptr++ = invalue;
242
23.6M
    }
243
1.74M
  }
244
724k
}
jdsample-16.c:h2v1_upsample
Line
Count
Source
227
734k
{
228
734k
  _JSAMPARRAY output_data = *output_data_ptr;
229
734k
  register _JSAMPROW inptr, outptr;
230
734k
  register _JSAMPLE invalue;
231
734k
  _JSAMPROW outend;
232
734k
  int inrow;
233
234
1.55M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
821k
    inptr = input_data[inrow];
236
821k
    outptr = output_data[inrow];
237
821k
    outend = outptr + cinfo->output_width;
238
16.5M
    while (outptr < outend) {
239
15.7M
      invalue = *inptr++;
240
15.7M
      *outptr++ = invalue;
241
15.7M
      *outptr++ = invalue;
242
15.7M
    }
243
821k
  }
244
734k
}
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
349k
{
256
349k
  _JSAMPARRAY output_data = *output_data_ptr;
257
349k
  register _JSAMPROW inptr, outptr;
258
349k
  register _JSAMPLE invalue;
259
349k
  _JSAMPROW outend;
260
349k
  int inrow, outrow;
261
262
349k
  inrow = outrow = 0;
263
806k
  while (outrow < cinfo->max_v_samp_factor) {
264
457k
    inptr = input_data[inrow];
265
457k
    outptr = output_data[outrow];
266
457k
    outend = outptr + cinfo->output_width;
267
25.8M
    while (outptr < outend) {
268
25.4M
      invalue = *inptr++;
269
25.4M
      *outptr++ = invalue;
270
25.4M
      *outptr++ = invalue;
271
25.4M
    }
272
457k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
457k
                       cinfo->output_width);
274
457k
    inrow++;
275
457k
    outrow += 2;
276
457k
  }
277
349k
}
Unexecuted instantiation: jdsample-8.c:h2v2_upsample
jdsample-12.c:h2v2_upsample
Line
Count
Source
255
310k
{
256
310k
  _JSAMPARRAY output_data = *output_data_ptr;
257
310k
  register _JSAMPROW inptr, outptr;
258
310k
  register _JSAMPLE invalue;
259
310k
  _JSAMPROW outend;
260
310k
  int inrow, outrow;
261
262
310k
  inrow = outrow = 0;
263
723k
  while (outrow < cinfo->max_v_samp_factor) {
264
413k
    inptr = input_data[inrow];
265
413k
    outptr = output_data[outrow];
266
413k
    outend = outptr + cinfo->output_width;
267
17.8M
    while (outptr < outend) {
268
17.4M
      invalue = *inptr++;
269
17.4M
      *outptr++ = invalue;
270
17.4M
      *outptr++ = invalue;
271
17.4M
    }
272
413k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
413k
                       cinfo->output_width);
274
413k
    inrow++;
275
413k
    outrow += 2;
276
413k
  }
277
310k
}
jdsample-16.c:h2v2_upsample
Line
Count
Source
255
38.7k
{
256
38.7k
  _JSAMPARRAY output_data = *output_data_ptr;
257
38.7k
  register _JSAMPROW inptr, outptr;
258
38.7k
  register _JSAMPLE invalue;
259
38.7k
  _JSAMPROW outend;
260
38.7k
  int inrow, outrow;
261
262
38.7k
  inrow = outrow = 0;
263
82.7k
  while (outrow < cinfo->max_v_samp_factor) {
264
43.9k
    inptr = input_data[inrow];
265
43.9k
    outptr = output_data[outrow];
266
43.9k
    outend = outptr + cinfo->output_width;
267
8.08M
    while (outptr < outend) {
268
8.03M
      invalue = *inptr++;
269
8.03M
      *outptr++ = invalue;
270
8.03M
      *outptr++ = invalue;
271
8.03M
    }
272
43.9k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
43.9k
                       cinfo->output_width);
274
43.9k
    inrow++;
275
43.9k
    outrow += 2;
276
43.9k
  }
277
38.7k
}
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
182k
{
299
182k
  _JSAMPARRAY output_data = *output_data_ptr;
300
182k
  register _JSAMPROW inptr, outptr;
301
182k
  register int invalue;
302
182k
  register JDIMENSION colctr;
303
182k
  int inrow;
304
305
622k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
440k
    inptr = input_data[inrow];
307
440k
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
440k
    invalue = *inptr++;
310
440k
    *outptr++ = (_JSAMPLE)invalue;
311
440k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
9.03M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer component + 1/4 * further component */
315
8.59M
      invalue = (*inptr++) * 3;
316
8.59M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
8.59M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
8.59M
    }
319
320
    /* Special case for last column */
321
440k
    invalue = *inptr;
322
440k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
440k
    *outptr++ = (_JSAMPLE)invalue;
324
440k
  }
325
182k
}
Unexecuted instantiation: jdsample-8.c:h2v1_fancy_upsample
jdsample-12.c:h2v1_fancy_upsample
Line
Count
Source
298
182k
{
299
182k
  _JSAMPARRAY output_data = *output_data_ptr;
300
182k
  register _JSAMPROW inptr, outptr;
301
182k
  register int invalue;
302
182k
  register JDIMENSION colctr;
303
182k
  int inrow;
304
305
622k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
440k
    inptr = input_data[inrow];
307
440k
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
440k
    invalue = *inptr++;
310
440k
    *outptr++ = (_JSAMPLE)invalue;
311
440k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
9.03M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer component + 1/4 * further component */
315
8.59M
      invalue = (*inptr++) * 3;
316
8.59M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
8.59M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
8.59M
    }
319
320
    /* Special case for last column */
321
440k
    invalue = *inptr;
322
440k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
440k
    *outptr++ = (_JSAMPLE)invalue;
324
440k
  }
325
182k
}
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
503k
{
339
503k
  _JSAMPARRAY output_data = *output_data_ptr;
340
503k
  _JSAMPROW inptr0, inptr1, outptr;
341
#if BITS_IN_JSAMPLE == 8
342
  int thiscolsum, bias;
343
#else
344
  JLONG thiscolsum, bias;
345
#endif
346
503k
  JDIMENSION colctr;
347
503k
  int inrow, outrow, v;
348
349
503k
  inrow = outrow = 0;
350
1.12M
  while (outrow < cinfo->max_v_samp_factor) {
351
1.85M
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
1.23M
      inptr0 = input_data[inrow];
354
1.23M
      if (v == 0) {             /* next nearest is row above */
355
617k
        inptr1 = input_data[inrow - 1];
356
617k
        bias = 1;
357
617k
      } else {                  /* next nearest is row below */
358
617k
        inptr1 = input_data[inrow + 1];
359
617k
        bias = 2;
360
617k
      }
361
1.23M
      outptr = output_data[outrow++];
362
363
44.9M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
43.7M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
43.7M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
43.7M
      }
367
1.23M
    }
368
617k
    inrow++;
369
617k
  }
370
503k
}
jdsample-8.c:h1v2_fancy_upsample
Line
Count
Source
338
312k
{
339
312k
  _JSAMPARRAY output_data = *output_data_ptr;
340
312k
  _JSAMPROW inptr0, inptr1, outptr;
341
312k
#if BITS_IN_JSAMPLE == 8
342
312k
  int thiscolsum, bias;
343
#else
344
  JLONG thiscolsum, bias;
345
#endif
346
312k
  JDIMENSION colctr;
347
312k
  int inrow, outrow, v;
348
349
312k
  inrow = outrow = 0;
350
669k
  while (outrow < cinfo->max_v_samp_factor) {
351
1.07M
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
714k
      inptr0 = input_data[inrow];
354
714k
      if (v == 0) {             /* next nearest is row above */
355
357k
        inptr1 = input_data[inrow - 1];
356
357k
        bias = 1;
357
357k
      } else {                  /* next nearest is row below */
358
357k
        inptr1 = input_data[inrow + 1];
359
357k
        bias = 2;
360
357k
      }
361
714k
      outptr = output_data[outrow++];
362
363
24.8M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
24.1M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
24.1M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
24.1M
      }
367
714k
    }
368
357k
    inrow++;
369
357k
  }
370
312k
}
jdsample-12.c:h1v2_fancy_upsample
Line
Count
Source
338
190k
{
339
190k
  _JSAMPARRAY output_data = *output_data_ptr;
340
190k
  _JSAMPROW inptr0, inptr1, outptr;
341
#if BITS_IN_JSAMPLE == 8
342
  int thiscolsum, bias;
343
#else
344
190k
  JLONG thiscolsum, bias;
345
190k
#endif
346
190k
  JDIMENSION colctr;
347
190k
  int inrow, outrow, v;
348
349
190k
  inrow = outrow = 0;
350
451k
  while (outrow < cinfo->max_v_samp_factor) {
351
782k
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
521k
      inptr0 = input_data[inrow];
354
521k
      if (v == 0) {             /* next nearest is row above */
355
260k
        inptr1 = input_data[inrow - 1];
356
260k
        bias = 1;
357
260k
      } else {                  /* next nearest is row below */
358
260k
        inptr1 = input_data[inrow + 1];
359
260k
        bias = 2;
360
260k
      }
361
521k
      outptr = output_data[outrow++];
362
363
20.0M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
19.5M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
19.5M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
19.5M
      }
367
521k
    }
368
260k
    inrow++;
369
260k
  }
370
190k
}
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
103k
{
385
103k
  _JSAMPARRAY output_data = *output_data_ptr;
386
103k
  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
103k
  register JDIMENSION colctr;
393
103k
  int inrow, outrow, v;
394
395
103k
  inrow = outrow = 0;
396
249k
  while (outrow < cinfo->max_v_samp_factor) {
397
437k
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
291k
      inptr0 = input_data[inrow];
400
291k
      if (v == 0)               /* next nearest is row above */
401
145k
        inptr1 = input_data[inrow - 1];
402
145k
      else                      /* next nearest is row below */
403
145k
        inptr1 = input_data[inrow + 1];
404
291k
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
291k
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
291k
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
291k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
291k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
291k
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
7.40M
      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
7.11M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
7.11M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
7.11M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
7.11M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
7.11M
      }
422
423
      /* Special case for last column */
424
291k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
291k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
291k
    }
427
145k
    inrow++;
428
145k
  }
429
103k
}
Unexecuted instantiation: jdsample-8.c:h2v2_fancy_upsample
jdsample-12.c:h2v2_fancy_upsample
Line
Count
Source
384
103k
{
385
103k
  _JSAMPARRAY output_data = *output_data_ptr;
386
103k
  register _JSAMPROW inptr0, inptr1, outptr;
387
#if BITS_IN_JSAMPLE == 8
388
  register int thiscolsum, lastcolsum, nextcolsum;
389
#else
390
103k
  register JLONG thiscolsum, lastcolsum, nextcolsum;
391
103k
#endif
392
103k
  register JDIMENSION colctr;
393
103k
  int inrow, outrow, v;
394
395
103k
  inrow = outrow = 0;
396
249k
  while (outrow < cinfo->max_v_samp_factor) {
397
437k
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
291k
      inptr0 = input_data[inrow];
400
291k
      if (v == 0)               /* next nearest is row above */
401
145k
        inptr1 = input_data[inrow - 1];
402
145k
      else                      /* next nearest is row below */
403
145k
        inptr1 = input_data[inrow + 1];
404
291k
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
291k
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
291k
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
291k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
291k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
291k
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
7.40M
      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
7.11M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
7.11M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
7.11M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
7.11M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
7.11M
      }
422
423
      /* Special case for last column */
424
291k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
291k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
291k
    }
427
145k
    inrow++;
428
145k
  }
429
103k
}
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
20.0k
{
439
20.0k
  my_upsample_ptr upsample;
440
20.0k
  int ci;
441
20.0k
  jpeg_component_info *compptr;
442
20.0k
  boolean need_buffer, do_fancy;
443
20.0k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
20.0k
#ifdef D_LOSSLESS_SUPPORTED
446
20.0k
  if (cinfo->master->lossless) {
447
#if BITS_IN_JSAMPLE == 8
448
1.01k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
449
#else
450
2.22k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
2.22k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
3.23k
  } else
455
16.8k
#endif
456
16.8k
  {
457
16.8k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
16.8k
  }
460
461
20.0k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
20.0k
    upsample = (my_upsample_ptr)
463
20.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
20.0k
                                  sizeof(my_upsampler));
465
20.0k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
20.0k
    upsample->pub.start_pass = start_pass_upsample;
467
20.0k
    upsample->pub._upsample = sep_upsample;
468
20.0k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
20.0k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
20.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
20.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
55.1k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
35.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
35.1k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
35.1k
                 cinfo->_min_DCT_scaled_size;
490
35.1k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
35.1k
                 cinfo->_min_DCT_scaled_size;
492
35.1k
    h_out_group = cinfo->max_h_samp_factor;
493
35.1k
    v_out_group = cinfo->max_v_samp_factor;
494
35.1k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
35.1k
    need_buffer = TRUE;
496
35.1k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
2.60k
      upsample->methods[ci] = noop_upsample;
499
2.60k
      need_buffer = FALSE;
500
32.5k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
18.8k
      upsample->methods[ci] = fullsize_upsample;
503
18.8k
      need_buffer = FALSE;
504
18.8k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
2.90k
      if (do_fancy && compptr->downsampled_width > 2) {
507
#ifdef WITH_SIMD
508
247
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
247
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
0
        else
511
0
#endif
512
0
          upsample->methods[ci] = h2v1_fancy_upsample;
513
2.40k
      } else {
514
#ifdef WITH_SIMD
515
796
        if (jsimd_set_h2v1_upsample(cinfo))
516
796
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
0
        else
518
0
#endif
519
0
          upsample->methods[ci] = h2v1_upsample;
520
2.40k
      }
521
10.7k
    } else if (h_in_group == h_out_group &&
522
4.42k
               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
571
        upsample->methods[ci] = h1v2_fancy_upsample;
530
571
      upsample->pub.need_context_rows = TRUE;
531
10.1k
    } else if (h_in_group * 2 == h_out_group &&
532
2.76k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
1.69k
      if (do_fancy && compptr->downsampled_width > 2) {
535
#ifdef WITH_SIMD
536
47
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
47
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
0
        else
539
0
#endif
540
0
          upsample->methods[ci] = h2v2_fancy_upsample;
541
196
        upsample->pub.need_context_rows = TRUE;
542
1.49k
      } else {
543
#ifdef WITH_SIMD
544
369
        if (jsimd_set_h2v2_upsample(cinfo))
545
369
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
0
        else
547
0
#endif
548
0
          upsample->methods[ci] = h2v2_upsample;
549
1.49k
      }
550
8.47k
    } else if ((h_out_group % h_in_group) == 0 &&
551
7.49k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
6.71k
      upsample->methods[ci] = int_upsample;
554
6.71k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
6.71k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
6.71k
    } else
557
1.76k
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
35.1k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
11.8k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
11.8k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
11.8k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
11.8k
                               (long)cinfo->max_h_samp_factor),
563
11.8k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
11.8k
    }
565
35.1k
  }
566
20.0k
}
jinit_upsampler
Line
Count
Source
438
11.0k
{
439
11.0k
  my_upsample_ptr upsample;
440
11.0k
  int ci;
441
11.0k
  jpeg_component_info *compptr;
442
11.0k
  boolean need_buffer, do_fancy;
443
11.0k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
11.0k
#ifdef D_LOSSLESS_SUPPORTED
446
11.0k
  if (cinfo->master->lossless) {
447
1.01k
#if BITS_IN_JSAMPLE == 8
448
1.01k
    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.01k
  } else
455
10.0k
#endif
456
10.0k
  {
457
10.0k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
10.0k
  }
460
461
11.0k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
11.0k
    upsample = (my_upsample_ptr)
463
11.0k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
11.0k
                                  sizeof(my_upsampler));
465
11.0k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
11.0k
    upsample->pub.start_pass = start_pass_upsample;
467
11.0k
    upsample->pub._upsample = sep_upsample;
468
11.0k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
11.0k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
11.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
11.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
28.7k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
17.7k
       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
17.7k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
17.7k
                 cinfo->_min_DCT_scaled_size;
490
17.7k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
17.7k
                 cinfo->_min_DCT_scaled_size;
492
17.7k
    h_out_group = cinfo->max_h_samp_factor;
493
17.7k
    v_out_group = cinfo->max_v_samp_factor;
494
17.7k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
17.7k
    need_buffer = TRUE;
496
17.7k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
1.36k
      upsample->methods[ci] = noop_upsample;
499
1.36k
      need_buffer = FALSE;
500
16.3k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
10.6k
      upsample->methods[ci] = fullsize_upsample;
503
10.6k
      need_buffer = FALSE;
504
10.6k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
1.04k
      if (do_fancy && compptr->downsampled_width > 2) {
507
247
#ifdef WITH_SIMD
508
247
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
247
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
0
        else
511
0
#endif
512
0
          upsample->methods[ci] = h2v1_fancy_upsample;
513
796
      } else {
514
796
#ifdef WITH_SIMD
515
796
        if (jsimd_set_h2v1_upsample(cinfo))
516
796
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
0
        else
518
0
#endif
519
0
          upsample->methods[ci] = h2v1_upsample;
520
796
      }
521
4.64k
    } else if (h_in_group == h_out_group &&
522
2.08k
               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
280
        upsample->methods[ci] = h1v2_fancy_upsample;
530
280
      upsample->pub.need_context_rows = TRUE;
531
4.36k
    } else if (h_in_group * 2 == h_out_group &&
532
939
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
416
      if (do_fancy && compptr->downsampled_width > 2) {
535
47
#ifdef WITH_SIMD
536
47
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
47
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
0
        else
539
0
#endif
540
0
          upsample->methods[ci] = h2v2_fancy_upsample;
541
47
        upsample->pub.need_context_rows = TRUE;
542
369
      } else {
543
369
#ifdef WITH_SIMD
544
369
        if (jsimd_set_h2v2_upsample(cinfo))
545
369
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
0
        else
547
0
#endif
548
0
          upsample->methods[ci] = h2v2_upsample;
549
369
      }
550
3.94k
    } else if ((h_out_group % h_in_group) == 0 &&
551
3.59k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
3.09k
      upsample->methods[ci] = int_upsample;
554
3.09k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
3.09k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
3.09k
    } else
557
858
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
17.7k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
4.83k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
4.83k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
4.83k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
4.83k
                               (long)cinfo->max_h_samp_factor),
563
4.83k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
4.83k
    }
565
17.7k
  }
566
11.0k
}
j12init_upsampler
Line
Count
Source
438
7.79k
{
439
7.79k
  my_upsample_ptr upsample;
440
7.79k
  int ci;
441
7.79k
  jpeg_component_info *compptr;
442
7.79k
  boolean need_buffer, do_fancy;
443
7.79k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
7.79k
#ifdef D_LOSSLESS_SUPPORTED
446
7.79k
  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.01k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
1.01k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
1.01k
  } else
455
6.78k
#endif
456
6.78k
  {
457
6.78k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
6.78k
  }
460
461
7.79k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
7.79k
    upsample = (my_upsample_ptr)
463
7.79k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
7.79k
                                  sizeof(my_upsampler));
465
7.79k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
7.79k
    upsample->pub.start_pass = start_pass_upsample;
467
7.79k
    upsample->pub._upsample = sep_upsample;
468
7.79k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
7.79k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
7.79k
  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
7.79k
  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
22.0k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
14.2k
       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
14.2k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
14.2k
                 cinfo->_min_DCT_scaled_size;
490
14.2k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
14.2k
                 cinfo->_min_DCT_scaled_size;
492
14.2k
    h_out_group = cinfo->max_h_samp_factor;
493
14.2k
    v_out_group = cinfo->max_v_samp_factor;
494
14.2k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
14.2k
    need_buffer = TRUE;
496
14.2k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
1.24k
      upsample->methods[ci] = noop_upsample;
499
1.24k
      need_buffer = FALSE;
500
12.9k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
7.33k
      upsample->methods[ci] = fullsize_upsample;
503
7.33k
      need_buffer = FALSE;
504
7.33k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
1.24k
      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
251
          upsample->methods[ci] = h2v1_fancy_upsample;
513
991
      } else {
514
#ifdef WITH_SIMD
515
        if (jsimd_set_h2v1_upsample(cinfo))
516
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
        else
518
#endif
519
991
          upsample->methods[ci] = h2v1_upsample;
520
991
      }
521
4.41k
    } else if (h_in_group == h_out_group &&
522
1.75k
               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
291
        upsample->methods[ci] = h1v2_fancy_upsample;
530
291
      upsample->pub.need_context_rows = TRUE;
531
4.12k
    } else if (h_in_group * 2 == h_out_group &&
532
1.14k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
706
      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
149
          upsample->methods[ci] = h2v2_fancy_upsample;
541
149
        upsample->pub.need_context_rows = TRUE;
542
557
      } else {
543
#ifdef WITH_SIMD
544
        if (jsimd_set_h2v2_upsample(cinfo))
545
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
        else
547
#endif
548
557
          upsample->methods[ci] = h2v2_upsample;
549
557
      }
550
3.41k
    } else if ((h_out_group % h_in_group) == 0 &&
551
2.80k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
2.53k
      upsample->methods[ci] = int_upsample;
554
2.53k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
2.53k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
2.53k
    } else
557
884
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
14.2k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
4.77k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
4.77k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
4.77k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
4.77k
                               (long)cinfo->max_h_samp_factor),
563
4.77k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
4.77k
    }
565
14.2k
  }
566
7.79k
}
j16init_upsampler
Line
Count
Source
438
1.20k
{
439
1.20k
  my_upsample_ptr upsample;
440
1.20k
  int ci;
441
1.20k
  jpeg_component_info *compptr;
442
1.20k
  boolean need_buffer, do_fancy;
443
1.20k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
1.20k
#ifdef D_LOSSLESS_SUPPORTED
446
1.20k
  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.20k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
1.20k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
1.20k
  } 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.20k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
1.20k
    upsample = (my_upsample_ptr)
463
1.20k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
1.20k
                                  sizeof(my_upsampler));
465
1.20k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
1.20k
    upsample->pub.start_pass = start_pass_upsample;
467
1.20k
    upsample->pub._upsample = sep_upsample;
468
1.20k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
1.20k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
1.20k
  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.20k
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
479
480
  /* Verify we can handle the sampling factors, select per-component methods,
481
   * and create storage as needed.
482
   */
483
4.36k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
3.15k
       ci++, compptr++) {
485
    /* Compute size of an "input group" after IDCT scaling.  This many samples
486
     * are to be converted to max_h_samp_factor * max_v_samp_factor components.
487
     */
488
3.15k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
3.15k
                 cinfo->_min_DCT_scaled_size;
490
3.15k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
3.15k
                 cinfo->_min_DCT_scaled_size;
492
3.15k
    h_out_group = cinfo->max_h_samp_factor;
493
3.15k
    v_out_group = cinfo->max_v_samp_factor;
494
3.15k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
3.15k
    need_buffer = TRUE;
496
3.15k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
0
      upsample->methods[ci] = noop_upsample;
499
0
      need_buffer = FALSE;
500
3.15k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
851
      upsample->methods[ci] = fullsize_upsample;
503
851
      need_buffer = FALSE;
504
2.30k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
621
      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
621
      } else {
514
#ifdef WITH_SIMD
515
        if (jsimd_set_h2v1_upsample(cinfo))
516
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
        else
518
#endif
519
621
          upsample->methods[ci] = h2v1_upsample;
520
621
      }
521
1.68k
    } else if (h_in_group == h_out_group &&
522
590
               v_in_group * 2 == v_out_group && do_fancy) {
523
      /* Non-fancy upsampling is handled by the generic method */
524
#if defined(WITH_SIMD) && (SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM)
525
      if (jsimd_set_h1v2_fancy_upsample(cinfo))
526
        upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
527
      else
528
#endif
529
0
        upsample->methods[ci] = h1v2_fancy_upsample;
530
0
      upsample->pub.need_context_rows = TRUE;
531
1.68k
    } else if (h_in_group * 2 == h_out_group &&
532
683
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
572
      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
572
      } else {
543
#ifdef WITH_SIMD
544
        if (jsimd_set_h2v2_upsample(cinfo))
545
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
        else
547
#endif
548
572
          upsample->methods[ci] = h2v2_upsample;
549
572
      }
550
1.10k
    } else if ((h_out_group % h_in_group) == 0 &&
551
1.09k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
1.08k
      upsample->methods[ci] = int_upsample;
554
1.08k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
1.08k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
1.08k
    } else
557
19
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
3.15k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
2.28k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
2.28k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
2.28k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
2.28k
                               (long)cinfo->max_h_samp_factor),
563
2.28k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
2.28k
    }
565
3.15k
  }
566
1.20k
}
567
568
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */