Coverage Report

Created: 2026-01-25 06:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.dev/src/jdsample.c
Line
Count
Source
1
/*
2
 * jdsample.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1991-1996, Thomas G. Lane.
6
 * libjpeg-turbo Modifications:
7
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
8
 * Copyright (C) 2010, 2015-2016, 2022, 2024-2025, D. R. Commander.
9
 * Copyright (C) 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
17
 * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
18
 * sample rows of each component.  Upsampling will normally produce
19
 * max_v_samp_factor pixel rows from each row group (but this could vary
20
 * if the upsampler is 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
143k
{
48
143k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
143k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
143k
  upsample->rows_to_go = cinfo->output_height;
54
143k
}
jdsample-8.c:start_pass_upsample
Line
Count
Source
47
127k
{
48
127k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
127k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
127k
  upsample->rows_to_go = cinfo->output_height;
54
127k
}
jdsample-12.c:start_pass_upsample
Line
Count
Source
47
12.5k
{
48
12.5k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
12.5k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
12.5k
  upsample->rows_to_go = cinfo->output_height;
54
12.5k
}
jdsample-16.c:start_pass_upsample
Line
Count
Source
47
3.61k
{
48
3.61k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
3.61k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
3.61k
  upsample->rows_to_go = cinfo->output_height;
54
3.61k
}
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
149M
{
71
149M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
149M
  int ci;
73
149M
  jpeg_component_info *compptr;
74
149M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
149M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
330M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
228M
         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
228M
      (*upsample->methods[ci]) (cinfo, compptr,
87
228M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
228M
        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
228M
    }
95
101M
    upsample->next_row_out = 0;
96
101M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
149M
  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
149M
  if (num_rows > upsample->rows_to_go)
106
71.0k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
149M
  out_rows_avail -= *out_row_ctr;
109
149M
  if (num_rows > out_rows_avail)
110
47.8M
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
149M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
149M
                                      (JDIMENSION)upsample->next_row_out,
117
149M
                                      output_buf + *out_row_ctr,
118
149M
                                      (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
149M
  *out_row_ctr += num_rows;
127
149M
  upsample->rows_to_go -= num_rows;
128
149M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
149M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
101M
    (*in_row_group_ctr)++;
132
149M
}
jdsample-8.c:sep_upsample
Line
Count
Source
70
133M
{
71
133M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
133M
  int ci;
73
133M
  jpeg_component_info *compptr;
74
133M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
133M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
285M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
199M
         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
199M
      (*upsample->methods[ci]) (cinfo, compptr,
87
199M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
199M
        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
199M
    }
95
85.7M
    upsample->next_row_out = 0;
96
85.7M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
133M
  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
133M
  if (num_rows > upsample->rows_to_go)
106
67.1k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
133M
  out_rows_avail -= *out_row_ctr;
109
133M
  if (num_rows > out_rows_avail)
110
47.8M
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
133M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
133M
                                      (JDIMENSION)upsample->next_row_out,
117
133M
                                      output_buf + *out_row_ctr,
118
133M
                                      (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
133M
  *out_row_ctr += num_rows;
127
133M
  upsample->rows_to_go -= num_rows;
128
133M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
133M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
85.6M
    (*in_row_group_ctr)++;
132
133M
}
jdsample-12.c:sep_upsample
Line
Count
Source
70
14.3M
{
71
14.3M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
14.3M
  int ci;
73
14.3M
  jpeg_component_info *compptr;
74
14.3M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
14.3M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
39.1M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
24.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
24.7M
      (*upsample->methods[ci]) (cinfo, compptr,
87
24.7M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
24.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
24.7M
    }
95
14.3M
    upsample->next_row_out = 0;
96
14.3M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
14.3M
  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
14.3M
  if (num_rows > upsample->rows_to_go)
106
3.65k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
14.3M
  out_rows_avail -= *out_row_ctr;
109
14.3M
  if (num_rows > out_rows_avail)
110
887
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
14.3M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
14.3M
                                      (JDIMENSION)upsample->next_row_out,
117
14.3M
                                      output_buf + *out_row_ctr,
118
14.3M
                                      (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
14.3M
  *out_row_ctr += num_rows;
127
14.3M
  upsample->rows_to_go -= num_rows;
128
14.3M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
14.3M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
14.3M
    (*in_row_group_ctr)++;
132
14.3M
}
jdsample-16.c:sep_upsample
Line
Count
Source
70
1.36M
{
71
1.36M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
1.36M
  int ci;
73
1.36M
  jpeg_component_info *compptr;
74
1.36M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
1.36M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
5.35M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
3.99M
         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.99M
      (*upsample->methods[ci]) (cinfo, compptr,
87
3.99M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
3.99M
        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.99M
    }
95
1.36M
    upsample->next_row_out = 0;
96
1.36M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
1.36M
  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.36M
  if (num_rows > upsample->rows_to_go)
106
230
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
1.36M
  out_rows_avail -= *out_row_ctr;
109
1.36M
  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.36M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
1.36M
                                      (JDIMENSION)upsample->next_row_out,
117
1.36M
                                      output_buf + *out_row_ctr,
118
1.36M
                                      (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.36M
  *out_row_ctr += num_rows;
127
1.36M
  upsample->rows_to_go -= num_rows;
128
1.36M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
1.36M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
1.36M
    (*in_row_group_ctr)++;
132
1.36M
}
133
134
135
/*
136
 * These are the routines invoked by sep_upsample to upsample pixel values
137
 * of a 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
126M
{
152
126M
  *output_data_ptr = input_data;
153
126M
}
jdsample-8.c:fullsize_upsample
Line
Count
Source
151
111M
{
152
111M
  *output_data_ptr = input_data;
153
111M
}
jdsample-12.c:fullsize_upsample
Line
Count
Source
151
13.8M
{
152
13.8M
  *output_data_ptr = input_data;
153
13.8M
}
jdsample-16.c:fullsize_upsample
Line
Count
Source
151
1.01M
{
152
1.01M
  *output_data_ptr = input_data;
153
1.01M
}
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
13.5M
{
165
13.5M
  *output_data_ptr = NULL;      /* safety check */
166
13.5M
}
jdsample-8.c:noop_upsample
Line
Count
Source
164
9.36M
{
165
  *output_data_ptr = NULL;      /* safety check */
166
9.36M
}
jdsample-12.c:noop_upsample
Line
Count
Source
164
4.20M
{
165
  *output_data_ptr = NULL;      /* safety check */
166
4.20M
}
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.
172
 * Nor, for that matter, is it particularly accurate: the algorithm is
173
 * simple replication of the input pixel onto the corresponding output
174
 * pixels.  The hi-falutin sampling literature refers to this as a
175
 * "box filter".  A box filter tends to introduce visible artifacts,
176
 * so if you are actually going to use 3:1 or 4:1 sampling ratios
177
 * you would be well advised to improve this 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
35.0M
{
184
35.0M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
35.0M
  _JSAMPARRAY output_data = *output_data_ptr;
186
35.0M
  register _JSAMPROW inptr, outptr;
187
35.0M
  register _JSAMPLE invalue;
188
35.0M
  register int h;
189
35.0M
  _JSAMPROW outend;
190
35.0M
  int h_expand, v_expand;
191
35.0M
  int inrow, outrow;
192
193
35.0M
  h_expand = upsample->h_expand[compptr->component_index];
194
35.0M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
35.0M
  inrow = outrow = 0;
197
72.6M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
37.5M
    inptr = input_data[inrow];
200
37.5M
    outptr = output_data[outrow];
201
37.5M
    outend = outptr + cinfo->output_width;
202
831M
    while (outptr < outend) {
203
794M
      invalue = *inptr++;
204
2.12G
      for (h = h_expand; h > 0; h--) {
205
1.33G
        *outptr++ = invalue;
206
1.33G
      }
207
794M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
37.5M
    if (v_expand > 1) {
210
29.0M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
29.0M
                         v_expand - 1, cinfo->output_width);
212
29.0M
    }
213
37.5M
    inrow++;
214
37.5M
    outrow += v_expand;
215
37.5M
  }
216
35.0M
}
jdsample-8.c:int_upsample
Line
Count
Source
183
30.5M
{
184
30.5M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
30.5M
  _JSAMPARRAY output_data = *output_data_ptr;
186
30.5M
  register _JSAMPROW inptr, outptr;
187
30.5M
  register _JSAMPLE invalue;
188
30.5M
  register int h;
189
30.5M
  _JSAMPROW outend;
190
30.5M
  int h_expand, v_expand;
191
30.5M
  int inrow, outrow;
192
193
30.5M
  h_expand = upsample->h_expand[compptr->component_index];
194
30.5M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
30.5M
  inrow = outrow = 0;
197
62.6M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
32.1M
    inptr = input_data[inrow];
200
32.1M
    outptr = output_data[outrow];
201
32.1M
    outend = outptr + cinfo->output_width;
202
731M
    while (outptr < outend) {
203
699M
      invalue = *inptr++;
204
1.86G
      for (h = h_expand; h > 0; h--) {
205
1.16G
        *outptr++ = invalue;
206
1.16G
      }
207
699M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
32.1M
    if (v_expand > 1) {
210
26.6M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
26.6M
                         v_expand - 1, cinfo->output_width);
212
26.6M
    }
213
32.1M
    inrow++;
214
32.1M
    outrow += v_expand;
215
32.1M
  }
216
30.5M
}
jdsample-12.c:int_upsample
Line
Count
Source
183
2.51M
{
184
2.51M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
2.51M
  _JSAMPARRAY output_data = *output_data_ptr;
186
2.51M
  register _JSAMPROW inptr, outptr;
187
2.51M
  register _JSAMPLE invalue;
188
2.51M
  register int h;
189
2.51M
  _JSAMPROW outend;
190
2.51M
  int h_expand, v_expand;
191
2.51M
  int inrow, outrow;
192
193
2.51M
  h_expand = upsample->h_expand[compptr->component_index];
194
2.51M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
2.51M
  inrow = outrow = 0;
197
5.38M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
2.87M
    inptr = input_data[inrow];
200
2.87M
    outptr = output_data[outrow];
201
2.87M
    outend = outptr + cinfo->output_width;
202
72.6M
    while (outptr < outend) {
203
69.7M
      invalue = *inptr++;
204
199M
      for (h = h_expand; h > 0; h--) {
205
129M
        *outptr++ = invalue;
206
129M
      }
207
69.7M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
2.87M
    if (v_expand > 1) {
210
1.56M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
1.56M
                         v_expand - 1, cinfo->output_width);
212
1.56M
    }
213
2.87M
    inrow++;
214
2.87M
    outrow += v_expand;
215
2.87M
  }
216
2.51M
}
jdsample-16.c:int_upsample
Line
Count
Source
183
1.99M
{
184
1.99M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
1.99M
  _JSAMPARRAY output_data = *output_data_ptr;
186
1.99M
  register _JSAMPROW inptr, outptr;
187
1.99M
  register _JSAMPLE invalue;
188
1.99M
  register int h;
189
1.99M
  _JSAMPROW outend;
190
1.99M
  int h_expand, v_expand;
191
1.99M
  int inrow, outrow;
192
193
1.99M
  h_expand = upsample->h_expand[compptr->component_index];
194
1.99M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
1.99M
  inrow = outrow = 0;
197
4.56M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
2.57M
    inptr = input_data[inrow];
200
2.57M
    outptr = output_data[outrow];
201
2.57M
    outend = outptr + cinfo->output_width;
202
27.0M
    while (outptr < outend) {
203
24.4M
      invalue = *inptr++;
204
63.7M
      for (h = h_expand; h > 0; h--) {
205
39.3M
        *outptr++ = invalue;
206
39.3M
      }
207
24.4M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
2.57M
    if (v_expand > 1) {
210
851k
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
851k
                         v_expand - 1, cinfo->output_width);
212
851k
    }
213
2.57M
    inrow++;
214
2.57M
    outrow += v_expand;
215
2.57M
  }
216
1.99M
}
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
3.55M
{
228
3.55M
  _JSAMPARRAY output_data = *output_data_ptr;
229
3.55M
  register _JSAMPROW inptr, outptr;
230
3.55M
  register _JSAMPLE invalue;
231
3.55M
  _JSAMPROW outend;
232
3.55M
  int inrow;
233
234
9.31M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
5.75M
    inptr = input_data[inrow];
236
5.75M
    outptr = output_data[inrow];
237
5.75M
    outend = outptr + cinfo->output_width;
238
59.9M
    while (outptr < outend) {
239
54.2M
      invalue = *inptr++;
240
54.2M
      *outptr++ = invalue;
241
54.2M
      *outptr++ = invalue;
242
54.2M
    }
243
5.75M
  }
244
3.55M
}
Unexecuted instantiation: jdsample-8.c:h2v1_upsample
jdsample-12.c:h2v1_upsample
Line
Count
Source
227
2.74M
{
228
2.74M
  _JSAMPARRAY output_data = *output_data_ptr;
229
2.74M
  register _JSAMPROW inptr, outptr;
230
2.74M
  register _JSAMPLE invalue;
231
2.74M
  _JSAMPROW outend;
232
2.74M
  int inrow;
233
234
6.93M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
4.19M
    inptr = input_data[inrow];
236
4.19M
    outptr = output_data[inrow];
237
4.19M
    outend = outptr + cinfo->output_width;
238
37.6M
    while (outptr < outend) {
239
33.4M
      invalue = *inptr++;
240
33.4M
      *outptr++ = invalue;
241
33.4M
      *outptr++ = invalue;
242
33.4M
    }
243
4.19M
  }
244
2.74M
}
jdsample-16.c:h2v1_upsample
Line
Count
Source
227
817k
{
228
817k
  _JSAMPARRAY output_data = *output_data_ptr;
229
817k
  register _JSAMPROW inptr, outptr;
230
817k
  register _JSAMPLE invalue;
231
817k
  _JSAMPROW outend;
232
817k
  int inrow;
233
234
2.38M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
1.56M
    inptr = input_data[inrow];
236
1.56M
    outptr = output_data[inrow];
237
1.56M
    outend = outptr + cinfo->output_width;
238
22.3M
    while (outptr < outend) {
239
20.7M
      invalue = *inptr++;
240
20.7M
      *outptr++ = invalue;
241
20.7M
      *outptr++ = invalue;
242
20.7M
    }
243
1.56M
  }
244
817k
}
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
834k
{
256
834k
  _JSAMPARRAY output_data = *output_data_ptr;
257
834k
  register _JSAMPROW inptr, outptr;
258
834k
  register _JSAMPLE invalue;
259
834k
  _JSAMPROW outend;
260
834k
  int inrow, outrow;
261
262
834k
  inrow = outrow = 0;
263
1.92M
  while (outrow < cinfo->max_v_samp_factor) {
264
1.09M
    inptr = input_data[inrow];
265
1.09M
    outptr = output_data[outrow];
266
1.09M
    outend = outptr + cinfo->output_width;
267
29.1M
    while (outptr < outend) {
268
28.0M
      invalue = *inptr++;
269
28.0M
      *outptr++ = invalue;
270
28.0M
      *outptr++ = invalue;
271
28.0M
    }
272
1.09M
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
1.09M
                       cinfo->output_width);
274
1.09M
    inrow++;
275
1.09M
    outrow += 2;
276
1.09M
  }
277
834k
}
Unexecuted instantiation: jdsample-8.c:h2v2_upsample
jdsample-12.c:h2v2_upsample
Line
Count
Source
255
667k
{
256
667k
  _JSAMPARRAY output_data = *output_data_ptr;
257
667k
  register _JSAMPROW inptr, outptr;
258
667k
  register _JSAMPLE invalue;
259
667k
  _JSAMPROW outend;
260
667k
  int inrow, outrow;
261
262
667k
  inrow = outrow = 0;
263
1.42M
  while (outrow < cinfo->max_v_samp_factor) {
264
761k
    inptr = input_data[inrow];
265
761k
    outptr = output_data[outrow];
266
761k
    outend = outptr + cinfo->output_width;
267
19.6M
    while (outptr < outend) {
268
18.9M
      invalue = *inptr++;
269
18.9M
      *outptr++ = invalue;
270
18.9M
      *outptr++ = invalue;
271
18.9M
    }
272
761k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
761k
                       cinfo->output_width);
274
761k
    inrow++;
275
761k
    outrow += 2;
276
761k
  }
277
667k
}
jdsample-16.c:h2v2_upsample
Line
Count
Source
255
166k
{
256
166k
  _JSAMPARRAY output_data = *output_data_ptr;
257
166k
  register _JSAMPROW inptr, outptr;
258
166k
  register _JSAMPLE invalue;
259
166k
  _JSAMPROW outend;
260
166k
  int inrow, outrow;
261
262
166k
  inrow = outrow = 0;
263
498k
  while (outrow < cinfo->max_v_samp_factor) {
264
331k
    inptr = input_data[inrow];
265
331k
    outptr = output_data[outrow];
266
331k
    outend = outptr + cinfo->output_width;
267
9.46M
    while (outptr < outend) {
268
9.13M
      invalue = *inptr++;
269
9.13M
      *outptr++ = invalue;
270
9.13M
      *outptr++ = invalue;
271
9.13M
    }
272
331k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
331k
                       cinfo->output_width);
274
331k
    inrow++;
275
331k
    outrow += 2;
276
331k
  }
277
166k
}
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 pixel centers,
284
 * also known as a "triangle filter".  This is a good compromise between
285
 * speed and visual quality.  The centers of the output pixels are 1/4 and 3/4
286
 * of the way between input pixel 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
378k
{
299
378k
  _JSAMPARRAY output_data = *output_data_ptr;
300
378k
  register _JSAMPROW inptr, outptr;
301
378k
  register int invalue;
302
378k
  register JDIMENSION colctr;
303
378k
  int inrow;
304
305
899k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
520k
    inptr = input_data[inrow];
307
520k
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
520k
    invalue = *inptr++;
310
520k
    *outptr++ = (_JSAMPLE)invalue;
311
520k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
11.6M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
315
11.1M
      invalue = (*inptr++) * 3;
316
11.1M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
11.1M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
11.1M
    }
319
320
    /* Special case for last column */
321
520k
    invalue = *inptr;
322
520k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
520k
    *outptr++ = (_JSAMPLE)invalue;
324
520k
  }
325
378k
}
Unexecuted instantiation: jdsample-8.c:h2v1_fancy_upsample
jdsample-12.c:h2v1_fancy_upsample
Line
Count
Source
298
378k
{
299
378k
  _JSAMPARRAY output_data = *output_data_ptr;
300
378k
  register _JSAMPROW inptr, outptr;
301
378k
  register int invalue;
302
378k
  register JDIMENSION colctr;
303
378k
  int inrow;
304
305
899k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
520k
    inptr = input_data[inrow];
307
520k
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
520k
    invalue = *inptr++;
310
520k
    *outptr++ = (_JSAMPLE)invalue;
311
520k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
11.6M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
315
11.1M
      invalue = (*inptr++) * 3;
316
11.1M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
11.1M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
11.1M
    }
319
320
    /* Special case for last column */
321
520k
    invalue = *inptr;
322
520k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
520k
    *outptr++ = (_JSAMPLE)invalue;
324
520k
  }
325
378k
}
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
4.22M
{
339
4.22M
  _JSAMPARRAY output_data = *output_data_ptr;
340
4.22M
  _JSAMPROW inptr0, inptr1, outptr;
341
#if BITS_IN_JSAMPLE == 8
342
  int thiscolsum, bias;
343
#else
344
  JLONG thiscolsum, bias;
345
#endif
346
4.22M
  JDIMENSION colctr;
347
4.22M
  int inrow, outrow, v;
348
349
4.22M
  inrow = outrow = 0;
350
10.6M
  while (outrow < cinfo->max_v_samp_factor) {
351
19.3M
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
12.8M
      inptr0 = input_data[inrow];
354
12.8M
      if (v == 0) {             /* next nearest is row above */
355
6.44M
        inptr1 = input_data[inrow - 1];
356
6.44M
        bias = 1;
357
6.44M
      } else {                  /* next nearest is row below */
358
6.44M
        inptr1 = input_data[inrow + 1];
359
6.44M
        bias = 2;
360
6.44M
      }
361
12.8M
      outptr = output_data[outrow++];
362
363
1.19G
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
1.17G
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
1.17G
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
1.17G
      }
367
12.8M
    }
368
6.44M
    inrow++;
369
6.44M
  }
370
4.22M
}
jdsample-8.c:h1v2_fancy_upsample
Line
Count
Source
338
3.88M
{
339
3.88M
  _JSAMPARRAY output_data = *output_data_ptr;
340
3.88M
  _JSAMPROW inptr0, inptr1, outptr;
341
3.88M
#if BITS_IN_JSAMPLE == 8
342
3.88M
  int thiscolsum, bias;
343
#else
344
  JLONG thiscolsum, bias;
345
#endif
346
3.88M
  JDIMENSION colctr;
347
3.88M
  int inrow, outrow, v;
348
349
3.88M
  inrow = outrow = 0;
350
9.95M
  while (outrow < cinfo->max_v_samp_factor) {
351
18.1M
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
12.1M
      inptr0 = input_data[inrow];
354
12.1M
      if (v == 0) {             /* next nearest is row above */
355
6.06M
        inptr1 = input_data[inrow - 1];
356
6.06M
        bias = 1;
357
6.06M
      } else {                  /* next nearest is row below */
358
6.06M
        inptr1 = input_data[inrow + 1];
359
6.06M
        bias = 2;
360
6.06M
      }
361
12.1M
      outptr = output_data[outrow++];
362
363
1.15G
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
1.14G
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
1.14G
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
1.14G
      }
367
12.1M
    }
368
6.06M
    inrow++;
369
6.06M
  }
370
3.88M
}
jdsample-12.c:h1v2_fancy_upsample
Line
Count
Source
338
333k
{
339
333k
  _JSAMPARRAY output_data = *output_data_ptr;
340
333k
  _JSAMPROW inptr0, inptr1, outptr;
341
#if BITS_IN_JSAMPLE == 8
342
  int thiscolsum, bias;
343
#else
344
333k
  JLONG thiscolsum, bias;
345
333k
#endif
346
333k
  JDIMENSION colctr;
347
333k
  int inrow, outrow, v;
348
349
333k
  inrow = outrow = 0;
350
713k
  while (outrow < cinfo->max_v_samp_factor) {
351
1.14M
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
760k
      inptr0 = input_data[inrow];
354
760k
      if (v == 0) {             /* next nearest is row above */
355
380k
        inptr1 = input_data[inrow - 1];
356
380k
        bias = 1;
357
380k
      } else {                  /* next nearest is row below */
358
380k
        inptr1 = input_data[inrow + 1];
359
380k
        bias = 2;
360
380k
      }
361
760k
      outptr = output_data[outrow++];
362
363
31.6M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
30.8M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
30.8M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
30.8M
      }
367
760k
    }
368
380k
    inrow++;
369
380k
  }
370
333k
}
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
121k
{
385
121k
  _JSAMPARRAY output_data = *output_data_ptr;
386
121k
  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
121k
  register JDIMENSION colctr;
393
121k
  int inrow, outrow, v;
394
395
121k
  inrow = outrow = 0;
396
259k
  while (outrow < cinfo->max_v_samp_factor) {
397
414k
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
276k
      inptr0 = input_data[inrow];
400
276k
      if (v == 0)               /* next nearest is row above */
401
138k
        inptr1 = input_data[inrow - 1];
402
138k
      else                      /* next nearest is row below */
403
138k
        inptr1 = input_data[inrow + 1];
404
276k
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
276k
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
276k
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
276k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
276k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
276k
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
9.96M
      for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
414
        /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
415
        /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
416
9.68M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
417
9.68M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
418
9.68M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
419
9.68M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
420
9.68M
      }
421
422
      /* Special case for last column */
423
276k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
424
276k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
425
276k
    }
426
138k
    inrow++;
427
138k
  }
428
121k
}
Unexecuted instantiation: jdsample-8.c:h2v2_fancy_upsample
jdsample-12.c:h2v2_fancy_upsample
Line
Count
Source
384
121k
{
385
121k
  _JSAMPARRAY output_data = *output_data_ptr;
386
121k
  register _JSAMPROW inptr0, inptr1, outptr;
387
#if BITS_IN_JSAMPLE == 8
388
  register int thiscolsum, lastcolsum, nextcolsum;
389
#else
390
121k
  register JLONG thiscolsum, lastcolsum, nextcolsum;
391
121k
#endif
392
121k
  register JDIMENSION colctr;
393
121k
  int inrow, outrow, v;
394
395
121k
  inrow = outrow = 0;
396
259k
  while (outrow < cinfo->max_v_samp_factor) {
397
414k
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
276k
      inptr0 = input_data[inrow];
400
276k
      if (v == 0)               /* next nearest is row above */
401
138k
        inptr1 = input_data[inrow - 1];
402
138k
      else                      /* next nearest is row below */
403
138k
        inptr1 = input_data[inrow + 1];
404
276k
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
276k
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
276k
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
276k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
276k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
276k
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
9.96M
      for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
414
        /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
415
        /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
416
9.68M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
417
9.68M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
418
9.68M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
419
9.68M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
420
9.68M
      }
421
422
      /* Special case for last column */
423
276k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
424
276k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
425
276k
    }
426
138k
    inrow++;
427
138k
  }
428
121k
}
Unexecuted instantiation: jdsample-16.c:h2v2_fancy_upsample
429
430
431
/*
432
 * Module initialization routine for upsampling.
433
 */
434
435
GLOBAL(void)
436
_jinit_upsampler(j_decompress_ptr cinfo)
437
72.6k
{
438
72.6k
  my_upsample_ptr upsample;
439
72.6k
  int ci;
440
72.6k
  jpeg_component_info *compptr;
441
72.6k
  boolean need_buffer, do_fancy;
442
72.6k
  int h_in_group, v_in_group, h_out_group, v_out_group;
443
444
72.6k
#ifdef D_LOSSLESS_SUPPORTED
445
72.6k
  if (cinfo->master->lossless) {
446
#if BITS_IN_JSAMPLE == 8
447
6.15k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
448
#else
449
11.5k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
450
11.5k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
451
0
#endif
452
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
453
17.7k
  } else
454
54.9k
#endif
455
54.9k
  {
456
54.9k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
457
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
458
54.9k
  }
459
460
72.6k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
461
72.6k
    upsample = (my_upsample_ptr)
462
72.6k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
463
72.6k
                                  sizeof(my_upsampler));
464
72.6k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
465
72.6k
    upsample->pub.start_pass = start_pass_upsample;
466
72.6k
    upsample->pub._upsample = sep_upsample;
467
72.6k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
468
72.6k
  } else
469
0
    upsample = (my_upsample_ptr)cinfo->upsample;
470
471
72.6k
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
472
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
473
474
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
475
   * so don't ask for it.
476
   */
477
72.6k
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
478
479
  /* Verify we can handle the sampling factors, select per-component methods,
480
   * and create storage as needed.
481
   */
482
244k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
483
172k
       ci++, compptr++) {
484
    /* Compute size of an "input group" after IDCT scaling.  This many samples
485
     * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
486
     */
487
172k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
488
172k
                 cinfo->_min_DCT_scaled_size;
489
172k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
490
172k
                 cinfo->_min_DCT_scaled_size;
491
172k
    h_out_group = cinfo->max_h_samp_factor;
492
172k
    v_out_group = cinfo->max_v_samp_factor;
493
172k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
494
172k
    need_buffer = TRUE;
495
172k
    if (!compptr->component_needed) {
496
      /* Don't bother to upsample an uninteresting component. */
497
6.30k
      upsample->methods[ci] = noop_upsample;
498
6.30k
      need_buffer = FALSE;
499
165k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
500
      /* Fullsize components can be processed without any work. */
501
64.2k
      upsample->methods[ci] = fullsize_upsample;
502
64.2k
      need_buffer = FALSE;
503
101k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
504
      /* Special cases for 2h1v upsampling */
505
21.2k
      if (do_fancy && compptr->downsampled_width > 2) {
506
#ifdef WITH_SIMD
507
8.40k
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
508
8.40k
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
509
0
        else
510
0
#endif
511
0
          upsample->methods[ci] = h2v1_fancy_upsample;
512
12.2k
      } else {
513
#ifdef WITH_SIMD
514
5.85k
        if (jsimd_set_h2v1_upsample(cinfo))
515
5.85k
          upsample->methods[ci] = jsimd_h2v1_upsample;
516
0
        else
517
0
#endif
518
0
          upsample->methods[ci] = h2v1_upsample;
519
12.2k
      }
520
80.2k
    } else if (h_in_group == h_out_group &&
521
28.2k
               v_in_group * 2 == v_out_group && do_fancy) {
522
      /* Non-fancy upsampling is handled by the generic method */
523
#if defined(WITH_SIMD) && (SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM)
524
      if (jsimd_set_h1v2_fancy_upsample(cinfo))
525
        upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
526
      else
527
#endif
528
6.11k
        upsample->methods[ci] = h1v2_fancy_upsample;
529
6.11k
      upsample->pub.need_context_rows = TRUE;
530
74.0k
    } else if (h_in_group * 2 == h_out_group &&
531
39.6k
               v_in_group * 2 == v_out_group) {
532
      /* Special cases for 2h2v upsampling */
533
27.5k
      if (do_fancy && compptr->downsampled_width > 2) {
534
#ifdef WITH_SIMD
535
9.34k
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
536
9.34k
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
537
0
        else
538
0
#endif
539
0
          upsample->methods[ci] = h2v2_fancy_upsample;
540
9.72k
        upsample->pub.need_context_rows = TRUE;
541
17.8k
      } else {
542
#ifdef WITH_SIMD
543
7.23k
        if (jsimd_set_h2v2_upsample(cinfo))
544
7.23k
          upsample->methods[ci] = jsimd_h2v2_upsample;
545
0
        else
546
0
#endif
547
0
          upsample->methods[ci] = h2v2_upsample;
548
17.8k
      }
549
46.5k
    } else if ((h_out_group % h_in_group) == 0 &&
550
45.9k
               (v_out_group % v_in_group) == 0) {
551
      /* Generic integral-factors upsampling method */
552
44.7k
      upsample->methods[ci] = int_upsample;
553
44.7k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
554
44.7k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
555
44.7k
    } else
556
1.82k
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
557
172k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
558
99.6k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
559
99.6k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
560
99.6k
         (JDIMENSION)jround_up((long)cinfo->output_width,
561
99.6k
                               (long)cinfo->max_h_samp_factor),
562
99.6k
         (JDIMENSION)cinfo->max_v_samp_factor);
563
99.6k
    }
564
172k
  }
565
72.6k
}
jinit_upsampler
Line
Count
Source
437
49.5k
{
438
49.5k
  my_upsample_ptr upsample;
439
49.5k
  int ci;
440
49.5k
  jpeg_component_info *compptr;
441
49.5k
  boolean need_buffer, do_fancy;
442
49.5k
  int h_in_group, v_in_group, h_out_group, v_out_group;
443
444
49.5k
#ifdef D_LOSSLESS_SUPPORTED
445
49.5k
  if (cinfo->master->lossless) {
446
6.15k
#if BITS_IN_JSAMPLE == 8
447
6.15k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
448
#else
449
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
450
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
451
#endif
452
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
453
6.15k
  } else
454
43.4k
#endif
455
43.4k
  {
456
43.4k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
457
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
458
43.4k
  }
459
460
49.5k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
461
49.5k
    upsample = (my_upsample_ptr)
462
49.5k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
463
49.5k
                                  sizeof(my_upsampler));
464
49.5k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
465
49.5k
    upsample->pub.start_pass = start_pass_upsample;
466
49.5k
    upsample->pub._upsample = sep_upsample;
467
49.5k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
468
49.5k
  } else
469
0
    upsample = (my_upsample_ptr)cinfo->upsample;
470
471
49.5k
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
472
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
473
474
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
475
   * so don't ask for it.
476
   */
477
49.5k
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
478
479
  /* Verify we can handle the sampling factors, select per-component methods,
480
   * and create storage as needed.
481
   */
482
166k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
483
116k
       ci++, compptr++) {
484
    /* Compute size of an "input group" after IDCT scaling.  This many samples
485
     * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
486
     */
487
116k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
488
116k
                 cinfo->_min_DCT_scaled_size;
489
116k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
490
116k
                 cinfo->_min_DCT_scaled_size;
491
116k
    h_out_group = cinfo->max_h_samp_factor;
492
116k
    v_out_group = cinfo->max_v_samp_factor;
493
116k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
494
116k
    need_buffer = TRUE;
495
116k
    if (!compptr->component_needed) {
496
      /* Don't bother to upsample an uninteresting component. */
497
4.36k
      upsample->methods[ci] = noop_upsample;
498
4.36k
      need_buffer = FALSE;
499
112k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
500
      /* Fullsize components can be processed without any work. */
501
43.1k
      upsample->methods[ci] = fullsize_upsample;
502
43.1k
      need_buffer = FALSE;
503
69.2k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
504
      /* Special cases for 2h1v upsampling */
505
14.2k
      if (do_fancy && compptr->downsampled_width > 2) {
506
8.40k
#ifdef WITH_SIMD
507
8.40k
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
508
8.40k
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
509
0
        else
510
0
#endif
511
0
          upsample->methods[ci] = h2v1_fancy_upsample;
512
8.40k
      } else {
513
5.85k
#ifdef WITH_SIMD
514
5.85k
        if (jsimd_set_h2v1_upsample(cinfo))
515
5.85k
          upsample->methods[ci] = jsimd_h2v1_upsample;
516
0
        else
517
0
#endif
518
0
          upsample->methods[ci] = h2v1_upsample;
519
5.85k
      }
520
54.9k
    } else if (h_in_group == h_out_group &&
521
20.9k
               v_in_group * 2 == v_out_group && do_fancy) {
522
      /* Non-fancy upsampling is handled by the generic method */
523
#if defined(WITH_SIMD) && (SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM)
524
      if (jsimd_set_h1v2_fancy_upsample(cinfo))
525
        upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
526
      else
527
#endif
528
5.41k
        upsample->methods[ci] = h1v2_fancy_upsample;
529
5.41k
      upsample->pub.need_context_rows = TRUE;
530
49.5k
    } else if (h_in_group * 2 == h_out_group &&
531
25.6k
               v_in_group * 2 == v_out_group) {
532
      /* Special cases for 2h2v upsampling */
533
16.5k
      if (do_fancy && compptr->downsampled_width > 2) {
534
9.34k
#ifdef WITH_SIMD
535
9.34k
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
536
9.34k
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
537
0
        else
538
0
#endif
539
0
          upsample->methods[ci] = h2v2_fancy_upsample;
540
9.34k
        upsample->pub.need_context_rows = TRUE;
541
9.34k
      } else {
542
7.23k
#ifdef WITH_SIMD
543
7.23k
        if (jsimd_set_h2v2_upsample(cinfo))
544
7.23k
          upsample->methods[ci] = jsimd_h2v2_upsample;
545
0
        else
546
0
#endif
547
0
          upsample->methods[ci] = h2v2_upsample;
548
7.23k
      }
549
32.9k
    } else if ((h_out_group % h_in_group) == 0 &&
550
32.6k
               (v_out_group % v_in_group) == 0) {
551
      /* Generic integral-factors upsampling method */
552
31.6k
      upsample->methods[ci] = int_upsample;
553
31.6k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
554
31.6k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
555
31.6k
    } else
556
1.28k
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
557
116k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
558
67.9k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
559
67.9k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
560
67.9k
         (JDIMENSION)jround_up((long)cinfo->output_width,
561
67.9k
                               (long)cinfo->max_h_samp_factor),
562
67.9k
         (JDIMENSION)cinfo->max_v_samp_factor);
563
67.9k
    }
564
116k
  }
565
49.5k
}
j12init_upsampler
Line
Count
Source
437
17.2k
{
438
17.2k
  my_upsample_ptr upsample;
439
17.2k
  int ci;
440
17.2k
  jpeg_component_info *compptr;
441
17.2k
  boolean need_buffer, do_fancy;
442
17.2k
  int h_in_group, v_in_group, h_out_group, v_out_group;
443
444
17.2k
#ifdef D_LOSSLESS_SUPPORTED
445
17.2k
  if (cinfo->master->lossless) {
446
#if BITS_IN_JSAMPLE == 8
447
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
448
#else
449
5.71k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
450
5.71k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
451
0
#endif
452
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
453
5.71k
  } else
454
11.5k
#endif
455
11.5k
  {
456
11.5k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
457
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
458
11.5k
  }
459
460
17.2k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
461
17.2k
    upsample = (my_upsample_ptr)
462
17.2k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
463
17.2k
                                  sizeof(my_upsampler));
464
17.2k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
465
17.2k
    upsample->pub.start_pass = start_pass_upsample;
466
17.2k
    upsample->pub._upsample = sep_upsample;
467
17.2k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
468
17.2k
  } else
469
0
    upsample = (my_upsample_ptr)cinfo->upsample;
470
471
17.2k
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
472
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
473
474
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
475
   * so don't ask for it.
476
   */
477
17.2k
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
478
479
  /* Verify we can handle the sampling factors, select per-component methods,
480
   * and create storage as needed.
481
   */
482
55.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
483
37.9k
       ci++, compptr++) {
484
    /* Compute size of an "input group" after IDCT scaling.  This many samples
485
     * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
486
     */
487
37.9k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
488
37.9k
                 cinfo->_min_DCT_scaled_size;
489
37.9k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
490
37.9k
                 cinfo->_min_DCT_scaled_size;
491
37.9k
    h_out_group = cinfo->max_h_samp_factor;
492
37.9k
    v_out_group = cinfo->max_v_samp_factor;
493
37.9k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
494
37.9k
    need_buffer = TRUE;
495
37.9k
    if (!compptr->component_needed) {
496
      /* Don't bother to upsample an uninteresting component. */
497
1.94k
      upsample->methods[ci] = noop_upsample;
498
1.94k
      need_buffer = FALSE;
499
36.0k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
500
      /* Fullsize components can be processed without any work. */
501
16.3k
      upsample->methods[ci] = fullsize_upsample;
502
16.3k
      need_buffer = FALSE;
503
19.6k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
504
      /* Special cases for 2h1v upsampling */
505
4.17k
      if (do_fancy && compptr->downsampled_width > 2) {
506
#ifdef WITH_SIMD
507
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
508
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
509
        else
510
#endif
511
573
          upsample->methods[ci] = h2v1_fancy_upsample;
512
3.60k
      } else {
513
#ifdef WITH_SIMD
514
        if (jsimd_set_h2v1_upsample(cinfo))
515
          upsample->methods[ci] = jsimd_h2v1_upsample;
516
        else
517
#endif
518
3.60k
          upsample->methods[ci] = h2v1_upsample;
519
3.60k
      }
520
15.4k
    } else if (h_in_group == h_out_group &&
521
4.75k
               v_in_group * 2 == v_out_group && do_fancy) {
522
      /* Non-fancy upsampling is handled by the generic method */
523
#if defined(WITH_SIMD) && (SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM)
524
      if (jsimd_set_h1v2_fancy_upsample(cinfo))
525
        upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
526
      else
527
#endif
528
703
        upsample->methods[ci] = h1v2_fancy_upsample;
529
703
      upsample->pub.need_context_rows = TRUE;
530
14.7k
    } else if (h_in_group * 2 == h_out_group &&
531
7.72k
               v_in_group * 2 == v_out_group) {
532
      /* Special cases for 2h2v upsampling */
533
5.89k
      if (do_fancy && compptr->downsampled_width > 2) {
534
#ifdef WITH_SIMD
535
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
536
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
537
        else
538
#endif
539
387
          upsample->methods[ci] = h2v2_fancy_upsample;
540
387
        upsample->pub.need_context_rows = TRUE;
541
5.51k
      } else {
542
#ifdef WITH_SIMD
543
        if (jsimd_set_h2v2_upsample(cinfo))
544
          upsample->methods[ci] = jsimd_h2v2_upsample;
545
        else
546
#endif
547
5.51k
          upsample->methods[ci] = h2v2_upsample;
548
5.51k
      }
549
8.86k
    } else if ((h_out_group % h_in_group) == 0 &&
550
8.60k
               (v_out_group % v_in_group) == 0) {
551
      /* Generic integral-factors upsampling method */
552
8.38k
      upsample->methods[ci] = int_upsample;
553
8.38k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
554
8.38k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
555
8.38k
    } else
556
477
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
557
37.9k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
558
19.1k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
559
19.1k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
560
19.1k
         (JDIMENSION)jround_up((long)cinfo->output_width,
561
19.1k
                               (long)cinfo->max_h_samp_factor),
562
19.1k
         (JDIMENSION)cinfo->max_v_samp_factor);
563
19.1k
    }
564
37.9k
  }
565
17.2k
}
j16init_upsampler
Line
Count
Source
437
5.83k
{
438
5.83k
  my_upsample_ptr upsample;
439
5.83k
  int ci;
440
5.83k
  jpeg_component_info *compptr;
441
5.83k
  boolean need_buffer, do_fancy;
442
5.83k
  int h_in_group, v_in_group, h_out_group, v_out_group;
443
444
5.83k
#ifdef D_LOSSLESS_SUPPORTED
445
5.83k
  if (cinfo->master->lossless) {
446
#if BITS_IN_JSAMPLE == 8
447
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
448
#else
449
5.83k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
450
5.83k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
451
0
#endif
452
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
453
5.83k
  } else
454
0
#endif
455
0
  {
456
0
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
457
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
458
0
  }
459
460
5.83k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
461
5.83k
    upsample = (my_upsample_ptr)
462
5.83k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
463
5.83k
                                  sizeof(my_upsampler));
464
5.83k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
465
5.83k
    upsample->pub.start_pass = start_pass_upsample;
466
5.83k
    upsample->pub._upsample = sep_upsample;
467
5.83k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
468
5.83k
  } else
469
0
    upsample = (my_upsample_ptr)cinfo->upsample;
470
471
5.83k
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
472
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
473
474
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
475
   * so don't ask for it.
476
   */
477
5.83k
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
478
479
  /* Verify we can handle the sampling factors, select per-component methods,
480
   * and create storage as needed.
481
   */
482
23.1k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
483
17.3k
       ci++, compptr++) {
484
    /* Compute size of an "input group" after IDCT scaling.  This many samples
485
     * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.
486
     */
487
17.3k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
488
17.3k
                 cinfo->_min_DCT_scaled_size;
489
17.3k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
490
17.3k
                 cinfo->_min_DCT_scaled_size;
491
17.3k
    h_out_group = cinfo->max_h_samp_factor;
492
17.3k
    v_out_group = cinfo->max_v_samp_factor;
493
17.3k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
494
17.3k
    need_buffer = TRUE;
495
17.3k
    if (!compptr->component_needed) {
496
      /* Don't bother to upsample an uninteresting component. */
497
0
      upsample->methods[ci] = noop_upsample;
498
0
      need_buffer = FALSE;
499
17.3k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
500
      /* Fullsize components can be processed without any work. */
501
4.70k
      upsample->methods[ci] = fullsize_upsample;
502
4.70k
      need_buffer = FALSE;
503
12.6k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
504
      /* Special cases for 2h1v upsampling */
505
2.80k
      if (do_fancy && compptr->downsampled_width > 2) {
506
#ifdef WITH_SIMD
507
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
508
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
509
        else
510
#endif
511
0
          upsample->methods[ci] = h2v1_fancy_upsample;
512
2.80k
      } else {
513
#ifdef WITH_SIMD
514
        if (jsimd_set_h2v1_upsample(cinfo))
515
          upsample->methods[ci] = jsimd_h2v1_upsample;
516
        else
517
#endif
518
2.80k
          upsample->methods[ci] = h2v1_upsample;
519
2.80k
      }
520
9.80k
    } else if (h_in_group == h_out_group &&
521
2.47k
               v_in_group * 2 == v_out_group && do_fancy) {
522
      /* Non-fancy upsampling is handled by the generic method */
523
#if defined(WITH_SIMD) && (SIMD_ARCHITECTURE == ARM64 || SIMD_ARCHITECTURE == ARM)
524
      if (jsimd_set_h1v2_fancy_upsample(cinfo))
525
        upsample->methods[ci] = jsimd_h1v2_fancy_upsample;
526
      else
527
#endif
528
0
        upsample->methods[ci] = h1v2_fancy_upsample;
529
0
      upsample->pub.need_context_rows = TRUE;
530
9.80k
    } else if (h_in_group * 2 == h_out_group &&
531
6.22k
               v_in_group * 2 == v_out_group) {
532
      /* Special cases for 2h2v upsampling */
533
5.07k
      if (do_fancy && compptr->downsampled_width > 2) {
534
#ifdef WITH_SIMD
535
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
536
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
537
        else
538
#endif
539
0
          upsample->methods[ci] = h2v2_fancy_upsample;
540
0
        upsample->pub.need_context_rows = TRUE;
541
5.07k
      } else {
542
#ifdef WITH_SIMD
543
        if (jsimd_set_h2v2_upsample(cinfo))
544
          upsample->methods[ci] = jsimd_h2v2_upsample;
545
        else
546
#endif
547
5.07k
          upsample->methods[ci] = h2v2_upsample;
548
5.07k
      }
549
5.07k
    } else if ((h_out_group % h_in_group) == 0 &&
550
4.69k
               (v_out_group % v_in_group) == 0) {
551
      /* Generic integral-factors upsampling method */
552
4.66k
      upsample->methods[ci] = int_upsample;
553
4.66k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
554
4.66k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
555
4.66k
    } else
556
60
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
557
17.3k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
558
12.5k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
559
12.5k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
560
12.5k
         (JDIMENSION)jround_up((long)cinfo->output_width,
561
12.5k
                               (long)cinfo->max_h_samp_factor),
562
12.5k
         (JDIMENSION)cinfo->max_v_samp_factor);
563
12.5k
    }
564
17.3k
  }
565
5.83k
}
566
567
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */