Coverage Report

Created: 2026-12-01 06:32

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
94.1k
{
48
94.1k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
94.1k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
94.1k
  upsample->rows_to_go = cinfo->output_height;
54
94.1k
}
jdsample-8.c:start_pass_upsample
Line
Count
Source
47
75.9k
{
48
75.9k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
75.9k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
75.9k
  upsample->rows_to_go = cinfo->output_height;
54
75.9k
}
jdsample-12.c:start_pass_upsample
Line
Count
Source
47
14.8k
{
48
14.8k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
14.8k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
14.8k
  upsample->rows_to_go = cinfo->output_height;
54
14.8k
}
jdsample-16.c:start_pass_upsample
Line
Count
Source
47
3.26k
{
48
3.26k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
3.26k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
3.26k
  upsample->rows_to_go = cinfo->output_height;
54
3.26k
}
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
255M
{
71
255M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
255M
  int ci;
73
255M
  jpeg_component_info *compptr;
74
255M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
255M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
495M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
336M
         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
336M
      (*upsample->methods[ci]) (cinfo, compptr,
87
336M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
336M
        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
336M
    }
95
158M
    upsample->next_row_out = 0;
96
158M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
255M
  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
255M
  if (num_rows > upsample->rows_to_go)
106
47.2k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
255M
  out_rows_avail -= *out_row_ctr;
109
255M
  if (num_rows > out_rows_avail)
110
96.2M
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
255M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
255M
                                      (JDIMENSION)upsample->next_row_out,
117
255M
                                      output_buf + *out_row_ctr,
118
255M
                                      (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
255M
  *out_row_ctr += num_rows;
127
255M
  upsample->rows_to_go -= num_rows;
128
255M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
255M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
158M
    (*in_row_group_ctr)++;
132
255M
}
jdsample-8.c:sep_upsample
Line
Count
Source
70
233M
{
71
233M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
233M
  int ci;
73
233M
  jpeg_component_info *compptr;
74
233M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
233M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
436M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
299M
         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
299M
      (*upsample->methods[ci]) (cinfo, compptr,
87
299M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
299M
        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
299M
    }
95
136M
    upsample->next_row_out = 0;
96
136M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
233M
  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
233M
  if (num_rows > upsample->rows_to_go)
106
41.6k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
233M
  out_rows_avail -= *out_row_ctr;
109
233M
  if (num_rows > out_rows_avail)
110
96.2M
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
233M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
233M
                                      (JDIMENSION)upsample->next_row_out,
117
233M
                                      output_buf + *out_row_ctr,
118
233M
                                      (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
233M
  *out_row_ctr += num_rows;
127
233M
  upsample->rows_to_go -= num_rows;
128
233M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
233M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
136M
    (*in_row_group_ctr)++;
132
233M
}
jdsample-12.c:sep_upsample
Line
Count
Source
70
17.9M
{
71
17.9M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
17.9M
  int ci;
73
17.9M
  jpeg_component_info *compptr;
74
17.9M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
17.9M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
48.0M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
30.1M
         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
30.1M
      (*upsample->methods[ci]) (cinfo, compptr,
87
30.1M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
30.1M
        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
30.1M
    }
95
17.9M
    upsample->next_row_out = 0;
96
17.9M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
17.9M
  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
17.9M
  if (num_rows > upsample->rows_to_go)
106
5.06k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
17.9M
  out_rows_avail -= *out_row_ctr;
109
17.9M
  if (num_rows > out_rows_avail)
110
6.14k
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
17.9M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
17.9M
                                      (JDIMENSION)upsample->next_row_out,
117
17.9M
                                      output_buf + *out_row_ctr,
118
17.9M
                                      (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
17.9M
  *out_row_ctr += num_rows;
127
17.9M
  upsample->rows_to_go -= num_rows;
128
17.9M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
17.9M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
17.9M
    (*in_row_group_ctr)++;
132
17.9M
}
jdsample-16.c:sep_upsample
Line
Count
Source
70
3.84M
{
71
3.84M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
3.84M
  int ci;
73
3.84M
  jpeg_component_info *compptr;
74
3.84M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
3.84M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
10.4M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
6.64M
         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
6.64M
      (*upsample->methods[ci]) (cinfo, compptr,
87
6.64M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
6.64M
        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
6.64M
    }
95
3.84M
    upsample->next_row_out = 0;
96
3.84M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
3.84M
  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
3.84M
  if (num_rows > upsample->rows_to_go)
106
513
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
3.84M
  out_rows_avail -= *out_row_ctr;
109
3.84M
  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
3.84M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
3.84M
                                      (JDIMENSION)upsample->next_row_out,
117
3.84M
                                      output_buf + *out_row_ctr,
118
3.84M
                                      (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
3.84M
  *out_row_ctr += num_rows;
127
3.84M
  upsample->rows_to_go -= num_rows;
128
3.84M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
3.84M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
3.84M
    (*in_row_group_ctr)++;
132
3.84M
}
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
149M
{
152
149M
  *output_data_ptr = input_data;
153
149M
}
jdsample-8.c:fullsize_upsample
Line
Count
Source
151
128M
{
152
128M
  *output_data_ptr = input_data;
153
128M
}
jdsample-12.c:fullsize_upsample
Line
Count
Source
151
17.2M
{
152
17.2M
  *output_data_ptr = input_data;
153
17.2M
}
jdsample-16.c:fullsize_upsample
Line
Count
Source
151
3.33M
{
152
3.33M
  *output_data_ptr = input_data;
153
3.33M
}
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
9.93M
{
165
9.93M
  *output_data_ptr = NULL;      /* safety check */
166
9.93M
}
jdsample-8.c:noop_upsample
Line
Count
Source
164
5.94M
{
165
  *output_data_ptr = NULL;      /* safety check */
166
5.94M
}
jdsample-12.c:noop_upsample
Line
Count
Source
164
3.98M
{
165
  *output_data_ptr = NULL;      /* safety check */
166
3.98M
}
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
67.2M
{
184
67.2M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
67.2M
  _JSAMPARRAY output_data = *output_data_ptr;
186
67.2M
  register _JSAMPROW inptr, outptr;
187
67.2M
  register _JSAMPLE invalue;
188
67.2M
  register int h;
189
67.2M
  _JSAMPROW outend;
190
67.2M
  int h_expand, v_expand;
191
67.2M
  int inrow, outrow;
192
193
67.2M
  h_expand = upsample->h_expand[compptr->component_index];
194
67.2M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
67.2M
  inrow = outrow = 0;
197
151M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
84.1M
    inptr = input_data[inrow];
200
84.1M
    outptr = output_data[outrow];
201
84.1M
    outend = outptr + cinfo->output_width;
202
1.45G
    while (outptr < outend) {
203
1.37G
      invalue = *inptr++;
204
3.73G
      for (h = h_expand; h > 0; h--) {
205
2.36G
        *outptr++ = invalue;
206
2.36G
      }
207
1.37G
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
84.1M
    if (v_expand > 1) {
210
52.9M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
52.9M
                         v_expand - 1, cinfo->output_width);
212
52.9M
    }
213
84.1M
    inrow++;
214
84.1M
    outrow += v_expand;
215
84.1M
  }
216
67.2M
}
jdsample-8.c:int_upsample
Line
Count
Source
183
60.7M
{
184
60.7M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
60.7M
  _JSAMPARRAY output_data = *output_data_ptr;
186
60.7M
  register _JSAMPROW inptr, outptr;
187
60.7M
  register _JSAMPLE invalue;
188
60.7M
  register int h;
189
60.7M
  _JSAMPROW outend;
190
60.7M
  int h_expand, v_expand;
191
60.7M
  int inrow, outrow;
192
193
60.7M
  h_expand = upsample->h_expand[compptr->component_index];
194
60.7M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
60.7M
  inrow = outrow = 0;
197
136M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
75.6M
    inptr = input_data[inrow];
200
75.6M
    outptr = output_data[outrow];
201
75.6M
    outend = outptr + cinfo->output_width;
202
1.26G
    while (outptr < outend) {
203
1.18G
      invalue = *inptr++;
204
3.24G
      for (h = h_expand; h > 0; h--) {
205
2.05G
        *outptr++ = invalue;
206
2.05G
      }
207
1.18G
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
75.6M
    if (v_expand > 1) {
210
48.7M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
48.7M
                         v_expand - 1, cinfo->output_width);
212
48.7M
    }
213
75.6M
    inrow++;
214
75.6M
    outrow += v_expand;
215
75.6M
  }
216
60.7M
}
jdsample-12.c:int_upsample
Line
Count
Source
183
4.07M
{
184
4.07M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
4.07M
  _JSAMPARRAY output_data = *output_data_ptr;
186
4.07M
  register _JSAMPROW inptr, outptr;
187
4.07M
  register _JSAMPLE invalue;
188
4.07M
  register int h;
189
4.07M
  _JSAMPROW outend;
190
4.07M
  int h_expand, v_expand;
191
4.07M
  int inrow, outrow;
192
193
4.07M
  h_expand = upsample->h_expand[compptr->component_index];
194
4.07M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
4.07M
  inrow = outrow = 0;
197
9.27M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
5.20M
    inptr = input_data[inrow];
200
5.20M
    outptr = output_data[outrow];
201
5.20M
    outend = outptr + cinfo->output_width;
202
134M
    while (outptr < outend) {
203
128M
      invalue = *inptr++;
204
340M
      for (h = h_expand; h > 0; h--) {
205
211M
        *outptr++ = invalue;
206
211M
      }
207
128M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
5.20M
    if (v_expand > 1) {
210
2.99M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
2.99M
                         v_expand - 1, cinfo->output_width);
212
2.99M
    }
213
5.20M
    inrow++;
214
5.20M
    outrow += v_expand;
215
5.20M
  }
216
4.07M
}
jdsample-16.c:int_upsample
Line
Count
Source
183
2.40M
{
184
2.40M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
2.40M
  _JSAMPARRAY output_data = *output_data_ptr;
186
2.40M
  register _JSAMPROW inptr, outptr;
187
2.40M
  register _JSAMPLE invalue;
188
2.40M
  register int h;
189
2.40M
  _JSAMPROW outend;
190
2.40M
  int h_expand, v_expand;
191
2.40M
  int inrow, outrow;
192
193
2.40M
  h_expand = upsample->h_expand[compptr->component_index];
194
2.40M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
2.40M
  inrow = outrow = 0;
197
5.70M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
3.30M
    inptr = input_data[inrow];
200
3.30M
    outptr = output_data[outrow];
201
3.30M
    outend = outptr + cinfo->output_width;
202
56.4M
    while (outptr < outend) {
203
53.1M
      invalue = *inptr++;
204
149M
      for (h = h_expand; h > 0; h--) {
205
95.9M
        *outptr++ = invalue;
206
95.9M
      }
207
53.1M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
3.30M
    if (v_expand > 1) {
210
1.12M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
1.12M
                         v_expand - 1, cinfo->output_width);
212
1.12M
    }
213
3.30M
    inrow++;
214
3.30M
    outrow += v_expand;
215
3.30M
  }
216
2.40M
}
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
2.00M
{
228
2.00M
  _JSAMPARRAY output_data = *output_data_ptr;
229
2.00M
  register _JSAMPROW inptr, outptr;
230
2.00M
  register _JSAMPLE invalue;
231
2.00M
  _JSAMPROW outend;
232
2.00M
  int inrow;
233
234
6.04M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
4.03M
    inptr = input_data[inrow];
236
4.03M
    outptr = output_data[inrow];
237
4.03M
    outend = outptr + cinfo->output_width;
238
79.1M
    while (outptr < outend) {
239
75.1M
      invalue = *inptr++;
240
75.1M
      *outptr++ = invalue;
241
75.1M
      *outptr++ = invalue;
242
75.1M
    }
243
4.03M
  }
244
2.00M
}
Unexecuted instantiation: jdsample-8.c:h2v1_upsample
jdsample-12.c:h2v1_upsample
Line
Count
Source
227
1.31M
{
228
1.31M
  _JSAMPARRAY output_data = *output_data_ptr;
229
1.31M
  register _JSAMPROW inptr, outptr;
230
1.31M
  register _JSAMPLE invalue;
231
1.31M
  _JSAMPROW outend;
232
1.31M
  int inrow;
233
234
4.12M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
2.81M
    inptr = input_data[inrow];
236
2.81M
    outptr = output_data[inrow];
237
2.81M
    outend = outptr + cinfo->output_width;
238
56.5M
    while (outptr < outend) {
239
53.7M
      invalue = *inptr++;
240
53.7M
      *outptr++ = invalue;
241
53.7M
      *outptr++ = invalue;
242
53.7M
    }
243
2.81M
  }
244
1.31M
}
jdsample-16.c:h2v1_upsample
Line
Count
Source
227
696k
{
228
696k
  _JSAMPARRAY output_data = *output_data_ptr;
229
696k
  register _JSAMPROW inptr, outptr;
230
696k
  register _JSAMPLE invalue;
231
696k
  _JSAMPROW outend;
232
696k
  int inrow;
233
234
1.91M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
1.21M
    inptr = input_data[inrow];
236
1.21M
    outptr = output_data[inrow];
237
1.21M
    outend = outptr + cinfo->output_width;
238
22.5M
    while (outptr < outend) {
239
21.3M
      invalue = *inptr++;
240
21.3M
      *outptr++ = invalue;
241
21.3M
      *outptr++ = invalue;
242
21.3M
    }
243
1.21M
  }
244
696k
}
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
1.72M
{
256
1.72M
  _JSAMPARRAY output_data = *output_data_ptr;
257
1.72M
  register _JSAMPROW inptr, outptr;
258
1.72M
  register _JSAMPLE invalue;
259
1.72M
  _JSAMPROW outend;
260
1.72M
  int inrow, outrow;
261
262
1.72M
  inrow = outrow = 0;
263
3.73M
  while (outrow < cinfo->max_v_samp_factor) {
264
2.01M
    inptr = input_data[inrow];
265
2.01M
    outptr = output_data[outrow];
266
2.01M
    outend = outptr + cinfo->output_width;
267
52.6M
    while (outptr < outend) {
268
50.6M
      invalue = *inptr++;
269
50.6M
      *outptr++ = invalue;
270
50.6M
      *outptr++ = invalue;
271
50.6M
    }
272
2.01M
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
2.01M
                       cinfo->output_width);
274
2.01M
    inrow++;
275
2.01M
    outrow += 2;
276
2.01M
  }
277
1.72M
}
Unexecuted instantiation: jdsample-8.c:h2v2_upsample
jdsample-12.c:h2v2_upsample
Line
Count
Source
255
1.50M
{
256
1.50M
  _JSAMPARRAY output_data = *output_data_ptr;
257
1.50M
  register _JSAMPROW inptr, outptr;
258
1.50M
  register _JSAMPLE invalue;
259
1.50M
  _JSAMPROW outend;
260
1.50M
  int inrow, outrow;
261
262
1.50M
  inrow = outrow = 0;
263
3.21M
  while (outrow < cinfo->max_v_samp_factor) {
264
1.70M
    inptr = input_data[inrow];
265
1.70M
    outptr = output_data[outrow];
266
1.70M
    outend = outptr + cinfo->output_width;
267
39.6M
    while (outptr < outend) {
268
37.9M
      invalue = *inptr++;
269
37.9M
      *outptr++ = invalue;
270
37.9M
      *outptr++ = invalue;
271
37.9M
    }
272
1.70M
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
1.70M
                       cinfo->output_width);
274
1.70M
    inrow++;
275
1.70M
    outrow += 2;
276
1.70M
  }
277
1.50M
}
jdsample-16.c:h2v2_upsample
Line
Count
Source
255
215k
{
256
215k
  _JSAMPARRAY output_data = *output_data_ptr;
257
215k
  register _JSAMPROW inptr, outptr;
258
215k
  register _JSAMPLE invalue;
259
215k
  _JSAMPROW outend;
260
215k
  int inrow, outrow;
261
262
215k
  inrow = outrow = 0;
263
523k
  while (outrow < cinfo->max_v_samp_factor) {
264
308k
    inptr = input_data[inrow];
265
308k
    outptr = output_data[outrow];
266
308k
    outend = outptr + cinfo->output_width;
267
13.0M
    while (outptr < outend) {
268
12.7M
      invalue = *inptr++;
269
12.7M
      *outptr++ = invalue;
270
12.7M
      *outptr++ = invalue;
271
12.7M
    }
272
308k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
308k
                       cinfo->output_width);
274
308k
    inrow++;
275
308k
    outrow += 2;
276
308k
  }
277
215k
}
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
445k
{
299
445k
  _JSAMPARRAY output_data = *output_data_ptr;
300
445k
  register _JSAMPROW inptr, outptr;
301
445k
  register int invalue;
302
445k
  register JDIMENSION colctr;
303
445k
  int inrow;
304
305
1.38M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
936k
    inptr = input_data[inrow];
307
936k
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
936k
    invalue = *inptr++;
310
936k
    *outptr++ = (_JSAMPLE)invalue;
311
936k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
49.2M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer component + 1/4 * further component */
315
48.2M
      invalue = (*inptr++) * 3;
316
48.2M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
48.2M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
48.2M
    }
319
320
    /* Special case for last column */
321
936k
    invalue = *inptr;
322
936k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
936k
    *outptr++ = (_JSAMPLE)invalue;
324
936k
  }
325
445k
}
Unexecuted instantiation: jdsample-8.c:h2v1_fancy_upsample
jdsample-12.c:h2v1_fancy_upsample
Line
Count
Source
298
445k
{
299
445k
  _JSAMPARRAY output_data = *output_data_ptr;
300
445k
  register _JSAMPROW inptr, outptr;
301
445k
  register int invalue;
302
445k
  register JDIMENSION colctr;
303
445k
  int inrow;
304
305
1.38M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
936k
    inptr = input_data[inrow];
307
936k
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
936k
    invalue = *inptr++;
310
936k
    *outptr++ = (_JSAMPLE)invalue;
311
936k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
49.2M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer component + 1/4 * further component */
315
48.2M
      invalue = (*inptr++) * 3;
316
48.2M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
48.2M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
48.2M
    }
319
320
    /* Special case for last column */
321
936k
    invalue = *inptr;
322
936k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
936k
    *outptr++ = (_JSAMPLE)invalue;
324
936k
  }
325
445k
}
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
18.6M
{
339
18.6M
  _JSAMPARRAY output_data = *output_data_ptr;
340
18.6M
  _JSAMPROW inptr0, inptr1, outptr;
341
#if BITS_IN_JSAMPLE == 8
342
  int thiscolsum, bias;
343
#else
344
  JLONG thiscolsum, bias;
345
#endif
346
18.6M
  JDIMENSION colctr;
347
18.6M
  int inrow, outrow, v;
348
349
18.6M
  inrow = outrow = 0;
350
43.6M
  while (outrow < cinfo->max_v_samp_factor) {
351
75.1M
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
50.0M
      inptr0 = input_data[inrow];
354
50.0M
      if (v == 0) {             /* next nearest is row above */
355
25.0M
        inptr1 = input_data[inrow - 1];
356
25.0M
        bias = 1;
357
25.0M
      } else {                  /* next nearest is row below */
358
25.0M
        inptr1 = input_data[inrow + 1];
359
25.0M
        bias = 2;
360
25.0M
      }
361
50.0M
      outptr = output_data[outrow++];
362
363
2.26G
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
2.21G
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
2.21G
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
2.21G
      }
367
50.0M
    }
368
25.0M
    inrow++;
369
25.0M
  }
370
18.6M
}
jdsample-8.c:h1v2_fancy_upsample
Line
Count
Source
338
18.0M
{
339
18.0M
  _JSAMPARRAY output_data = *output_data_ptr;
340
18.0M
  _JSAMPROW inptr0, inptr1, outptr;
341
18.0M
#if BITS_IN_JSAMPLE == 8
342
18.0M
  int thiscolsum, bias;
343
#else
344
  JLONG thiscolsum, bias;
345
#endif
346
18.0M
  JDIMENSION colctr;
347
18.0M
  int inrow, outrow, v;
348
349
18.0M
  inrow = outrow = 0;
350
42.3M
  while (outrow < cinfo->max_v_samp_factor) {
351
72.8M
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
48.5M
      inptr0 = input_data[inrow];
354
48.5M
      if (v == 0) {             /* next nearest is row above */
355
24.2M
        inptr1 = input_data[inrow - 1];
356
24.2M
        bias = 1;
357
24.2M
      } else {                  /* next nearest is row below */
358
24.2M
        inptr1 = input_data[inrow + 1];
359
24.2M
        bias = 2;
360
24.2M
      }
361
48.5M
      outptr = output_data[outrow++];
362
363
2.19G
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
2.14G
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
2.14G
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
2.14G
      }
367
48.5M
    }
368
24.2M
    inrow++;
369
24.2M
  }
370
18.0M
}
jdsample-12.c:h1v2_fancy_upsample
Line
Count
Source
338
610k
{
339
610k
  _JSAMPARRAY output_data = *output_data_ptr;
340
610k
  _JSAMPROW inptr0, inptr1, outptr;
341
#if BITS_IN_JSAMPLE == 8
342
  int thiscolsum, bias;
343
#else
344
610k
  JLONG thiscolsum, bias;
345
610k
#endif
346
610k
  JDIMENSION colctr;
347
610k
  int inrow, outrow, v;
348
349
610k
  inrow = outrow = 0;
350
1.36M
  while (outrow < cinfo->max_v_samp_factor) {
351
2.24M
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
1.49M
      inptr0 = input_data[inrow];
354
1.49M
      if (v == 0) {             /* next nearest is row above */
355
749k
        inptr1 = input_data[inrow - 1];
356
749k
        bias = 1;
357
749k
      } else {                  /* next nearest is row below */
358
749k
        inptr1 = input_data[inrow + 1];
359
749k
        bias = 2;
360
749k
      }
361
1.49M
      outptr = output_data[outrow++];
362
363
71.9M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
70.4M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
70.4M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
70.4M
      }
367
1.49M
    }
368
749k
    inrow++;
369
749k
  }
370
610k
}
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
944k
{
385
944k
  _JSAMPARRAY output_data = *output_data_ptr;
386
944k
  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
944k
  register JDIMENSION colctr;
393
944k
  int inrow, outrow, v;
394
395
944k
  inrow = outrow = 0;
396
1.95M
  while (outrow < cinfo->max_v_samp_factor) {
397
3.02M
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
2.01M
      inptr0 = input_data[inrow];
400
2.01M
      if (v == 0)               /* next nearest is row above */
401
1.00M
        inptr1 = input_data[inrow - 1];
402
1.00M
      else                      /* next nearest is row below */
403
1.00M
        inptr1 = input_data[inrow + 1];
404
2.01M
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
2.01M
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
2.01M
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
2.01M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
2.01M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
2.01M
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
19.5M
      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
17.5M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
17.5M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
17.5M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
17.5M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
17.5M
      }
422
423
      /* Special case for last column */
424
2.01M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
2.01M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
2.01M
    }
427
1.00M
    inrow++;
428
1.00M
  }
429
944k
}
Unexecuted instantiation: jdsample-8.c:h2v2_fancy_upsample
jdsample-12.c:h2v2_fancy_upsample
Line
Count
Source
384
944k
{
385
944k
  _JSAMPARRAY output_data = *output_data_ptr;
386
944k
  register _JSAMPROW inptr0, inptr1, outptr;
387
#if BITS_IN_JSAMPLE == 8
388
  register int thiscolsum, lastcolsum, nextcolsum;
389
#else
390
944k
  register JLONG thiscolsum, lastcolsum, nextcolsum;
391
944k
#endif
392
944k
  register JDIMENSION colctr;
393
944k
  int inrow, outrow, v;
394
395
944k
  inrow = outrow = 0;
396
1.95M
  while (outrow < cinfo->max_v_samp_factor) {
397
3.02M
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
2.01M
      inptr0 = input_data[inrow];
400
2.01M
      if (v == 0)               /* next nearest is row above */
401
1.00M
        inptr1 = input_data[inrow - 1];
402
1.00M
      else                      /* next nearest is row below */
403
1.00M
        inptr1 = input_data[inrow + 1];
404
2.01M
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
2.01M
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
2.01M
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
2.01M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
2.01M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
2.01M
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
19.5M
      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
17.5M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
17.5M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
17.5M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
17.5M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
17.5M
      }
422
423
      /* Special case for last column */
424
2.01M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
2.01M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
2.01M
    }
427
1.00M
    inrow++;
428
1.00M
  }
429
944k
}
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
86.4k
{
439
86.4k
  my_upsample_ptr upsample;
440
86.4k
  int ci;
441
86.4k
  jpeg_component_info *compptr;
442
86.4k
  boolean need_buffer, do_fancy;
443
86.4k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
86.4k
#ifdef D_LOSSLESS_SUPPORTED
446
86.4k
  if (cinfo->master->lossless) {
447
#if BITS_IN_JSAMPLE == 8
448
6.28k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
449
#else
450
12.5k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
12.5k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
18.7k
  } else
455
67.6k
#endif
456
67.6k
  {
457
67.6k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
67.6k
  }
460
461
86.4k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
86.4k
    upsample = (my_upsample_ptr)
463
86.4k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
86.4k
                                  sizeof(my_upsampler));
465
86.4k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
86.4k
    upsample->pub.start_pass = start_pass_upsample;
467
86.4k
    upsample->pub._upsample = sep_upsample;
468
86.4k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
86.4k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
86.4k
  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
86.4k
  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
265k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
179k
       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
179k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
179k
                 cinfo->_min_DCT_scaled_size;
490
179k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
179k
                 cinfo->_min_DCT_scaled_size;
492
179k
    h_out_group = cinfo->max_h_samp_factor;
493
179k
    v_out_group = cinfo->max_v_samp_factor;
494
179k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
179k
    need_buffer = TRUE;
496
179k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
6.13k
      upsample->methods[ci] = noop_upsample;
499
6.13k
      need_buffer = FALSE;
500
173k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
76.0k
      upsample->methods[ci] = fullsize_upsample;
503
76.0k
      need_buffer = FALSE;
504
97.0k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
18.3k
      if (do_fancy && compptr->downsampled_width > 2) {
507
#ifdef WITH_SIMD
508
8.07k
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
8.07k
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
0
        else
511
0
#endif
512
0
          upsample->methods[ci] = h2v1_fancy_upsample;
513
9.18k
      } else {
514
#ifdef WITH_SIMD
515
4.04k
        if (jsimd_set_h2v1_upsample(cinfo))
516
4.04k
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
0
        else
518
0
#endif
519
0
          upsample->methods[ci] = h2v1_upsample;
520
9.13k
      }
521
78.7k
    } else if (h_in_group == h_out_group &&
522
29.7k
               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
7.79k
        upsample->methods[ci] = h1v2_fancy_upsample;
530
7.79k
      upsample->pub.need_context_rows = TRUE;
531
70.9k
    } else if (h_in_group * 2 == h_out_group &&
532
33.1k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
24.4k
      if (do_fancy && compptr->downsampled_width > 2) {
535
#ifdef WITH_SIMD
536
8.19k
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
8.19k
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
0
        else
539
0
#endif
540
0
          upsample->methods[ci] = h2v2_fancy_upsample;
541
8.73k
        upsample->pub.need_context_rows = TRUE;
542
15.7k
      } else {
543
#ifdef WITH_SIMD
544
5.56k
        if (jsimd_set_h2v2_upsample(cinfo))
545
5.56k
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
0
        else
547
0
#endif
548
0
          upsample->methods[ci] = h2v2_upsample;
549
15.7k
      }
550
46.4k
    } else if ((h_out_group % h_in_group) == 0 &&
551
44.7k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
42.2k
      upsample->methods[ci] = int_upsample;
554
42.2k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
42.2k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
42.2k
    } else
557
4.19k
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
179k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
92.8k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
92.8k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
92.8k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
92.8k
                               (long)cinfo->max_h_samp_factor),
563
92.8k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
92.8k
    }
565
179k
  }
566
86.4k
}
jinit_upsampler
Line
Count
Source
438
55.8k
{
439
55.8k
  my_upsample_ptr upsample;
440
55.8k
  int ci;
441
55.8k
  jpeg_component_info *compptr;
442
55.8k
  boolean need_buffer, do_fancy;
443
55.8k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
55.8k
#ifdef D_LOSSLESS_SUPPORTED
446
55.8k
  if (cinfo->master->lossless) {
447
6.28k
#if BITS_IN_JSAMPLE == 8
448
6.28k
    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
6.28k
  } else
455
49.5k
#endif
456
49.5k
  {
457
49.5k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
49.5k
  }
460
461
55.8k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
55.8k
    upsample = (my_upsample_ptr)
463
55.8k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
55.8k
                                  sizeof(my_upsampler));
465
55.8k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
55.8k
    upsample->pub.start_pass = start_pass_upsample;
467
55.8k
    upsample->pub._upsample = sep_upsample;
468
55.8k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
55.8k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
55.8k
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
473
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
474
475
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
476
   * so don't ask for it.
477
   */
478
55.8k
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
479
480
  /* Verify we can handle the sampling factors, select per-component methods,
481
   * and create storage as needed.
482
   */
483
170k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
114k
       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
114k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
114k
                 cinfo->_min_DCT_scaled_size;
490
114k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
114k
                 cinfo->_min_DCT_scaled_size;
492
114k
    h_out_group = cinfo->max_h_samp_factor;
493
114k
    v_out_group = cinfo->max_v_samp_factor;
494
114k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
114k
    need_buffer = TRUE;
496
114k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
3.33k
      upsample->methods[ci] = noop_upsample;
499
3.33k
      need_buffer = FALSE;
500
111k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
48.4k
      upsample->methods[ci] = fullsize_upsample;
503
48.4k
      need_buffer = FALSE;
504
63.1k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
12.1k
      if (do_fancy && compptr->downsampled_width > 2) {
507
8.07k
#ifdef WITH_SIMD
508
8.07k
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
8.07k
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
0
        else
511
0
#endif
512
0
          upsample->methods[ci] = h2v1_fancy_upsample;
513
8.07k
      } else {
514
4.04k
#ifdef WITH_SIMD
515
4.04k
        if (jsimd_set_h2v1_upsample(cinfo))
516
4.04k
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
0
        else
518
0
#endif
519
0
          upsample->methods[ci] = h2v1_upsample;
520
4.04k
      }
521
51.0k
    } else if (h_in_group == h_out_group &&
522
20.3k
               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
6.60k
        upsample->methods[ci] = h1v2_fancy_upsample;
530
6.60k
      upsample->pub.need_context_rows = TRUE;
531
44.4k
    } else if (h_in_group * 2 == h_out_group &&
532
20.5k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
13.7k
      if (do_fancy && compptr->downsampled_width > 2) {
535
8.19k
#ifdef WITH_SIMD
536
8.19k
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
8.19k
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
0
        else
539
0
#endif
540
0
          upsample->methods[ci] = h2v2_fancy_upsample;
541
8.19k
        upsample->pub.need_context_rows = TRUE;
542
8.19k
      } else {
543
5.56k
#ifdef WITH_SIMD
544
5.56k
        if (jsimd_set_h2v2_upsample(cinfo))
545
5.56k
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
0
        else
547
0
#endif
548
0
          upsample->methods[ci] = h2v2_upsample;
549
5.56k
      }
550
30.7k
    } else if ((h_out_group % h_in_group) == 0 &&
551
29.9k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
28.6k
      upsample->methods[ci] = int_upsample;
554
28.6k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
28.6k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
28.6k
    } else
557
2.06k
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
114k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
61.1k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
61.1k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
61.1k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
61.1k
                               (long)cinfo->max_h_samp_factor),
563
61.1k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
61.1k
    }
565
114k
  }
566
55.8k
}
j12init_upsampler
Line
Count
Source
438
24.2k
{
439
24.2k
  my_upsample_ptr upsample;
440
24.2k
  int ci;
441
24.2k
  jpeg_component_info *compptr;
442
24.2k
  boolean need_buffer, do_fancy;
443
24.2k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
24.2k
#ifdef D_LOSSLESS_SUPPORTED
446
24.2k
  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
6.18k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
6.18k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
6.18k
  } else
455
18.1k
#endif
456
18.1k
  {
457
18.1k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
18.1k
  }
460
461
24.2k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
24.2k
    upsample = (my_upsample_ptr)
463
24.2k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
24.2k
                                  sizeof(my_upsampler));
465
24.2k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
24.2k
    upsample->pub.start_pass = start_pass_upsample;
467
24.2k
    upsample->pub._upsample = sep_upsample;
468
24.2k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
24.2k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
24.2k
  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
24.2k
  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
71.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
47.3k
       ci++, compptr++) {
485
    /* Compute size of an "input group" after IDCT scaling.  This many samples
486
     * are to be converted to max_h_samp_factor * max_v_samp_factor components.
487
     */
488
47.3k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
47.3k
                 cinfo->_min_DCT_scaled_size;
490
47.3k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
47.3k
                 cinfo->_min_DCT_scaled_size;
492
47.3k
    h_out_group = cinfo->max_h_samp_factor;
493
47.3k
    v_out_group = cinfo->max_v_samp_factor;
494
47.3k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
47.3k
    need_buffer = TRUE;
496
47.3k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
2.79k
      upsample->methods[ci] = noop_upsample;
499
2.79k
      need_buffer = FALSE;
500
44.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
22.0k
      upsample->methods[ci] = fullsize_upsample;
503
22.0k
      need_buffer = FALSE;
504
22.4k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
4.34k
      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
1.11k
          upsample->methods[ci] = h2v1_fancy_upsample;
513
3.23k
      } else {
514
#ifdef WITH_SIMD
515
        if (jsimd_set_h2v1_upsample(cinfo))
516
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
        else
518
#endif
519
3.23k
          upsample->methods[ci] = h2v1_upsample;
520
3.23k
      }
521
18.1k
    } else if (h_in_group == h_out_group &&
522
6.70k
               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
1.18k
        upsample->methods[ci] = h1v2_fancy_upsample;
530
1.18k
      upsample->pub.need_context_rows = TRUE;
531
16.9k
    } else if (h_in_group * 2 == h_out_group &&
532
7.16k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
5.70k
      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
540
          upsample->methods[ci] = h2v2_fancy_upsample;
541
540
        upsample->pub.need_context_rows = TRUE;
542
5.16k
      } else {
543
#ifdef WITH_SIMD
544
        if (jsimd_set_h2v2_upsample(cinfo))
545
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
        else
547
#endif
548
5.16k
          upsample->methods[ci] = h2v2_upsample;
549
5.16k
      }
550
11.2k
    } else if ((h_out_group % h_in_group) == 0 &&
551
10.3k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
9.19k
      upsample->methods[ci] = int_upsample;
554
9.19k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
9.19k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
9.19k
    } else
557
2.06k
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
47.3k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
20.4k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
20.4k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
20.4k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
20.4k
                               (long)cinfo->max_h_samp_factor),
563
20.4k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
20.4k
    }
565
47.3k
  }
566
24.2k
}
j16init_upsampler
Line
Count
Source
438
6.32k
{
439
6.32k
  my_upsample_ptr upsample;
440
6.32k
  int ci;
441
6.32k
  jpeg_component_info *compptr;
442
6.32k
  boolean need_buffer, do_fancy;
443
6.32k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
6.32k
#ifdef D_LOSSLESS_SUPPORTED
446
6.32k
  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
6.32k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
6.32k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
6.32k
  } 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
6.32k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
6.32k
    upsample = (my_upsample_ptr)
463
6.32k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
6.32k
                                  sizeof(my_upsampler));
465
6.32k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
6.32k
    upsample->pub.start_pass = start_pass_upsample;
467
6.32k
    upsample->pub._upsample = sep_upsample;
468
6.32k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
6.32k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
6.32k
  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
6.32k
  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
23.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
16.9k
       ci++, compptr++) {
485
    /* Compute size of an "input group" after IDCT scaling.  This many samples
486
     * are to be converted to max_h_samp_factor * max_v_samp_factor components.
487
     */
488
16.9k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
16.9k
                 cinfo->_min_DCT_scaled_size;
490
16.9k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
16.9k
                 cinfo->_min_DCT_scaled_size;
492
16.9k
    h_out_group = cinfo->max_h_samp_factor;
493
16.9k
    v_out_group = cinfo->max_v_samp_factor;
494
16.9k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
16.9k
    need_buffer = TRUE;
496
16.9k
    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
16.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
5.56k
      upsample->methods[ci] = fullsize_upsample;
503
5.56k
      need_buffer = FALSE;
504
11.3k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
1.86k
      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
1.86k
      } else {
514
#ifdef WITH_SIMD
515
        if (jsimd_set_h2v1_upsample(cinfo))
516
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
        else
518
#endif
519
1.86k
          upsample->methods[ci] = h2v1_upsample;
520
1.86k
      }
521
9.50k
    } else if (h_in_group == h_out_group &&
522
2.66k
               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
9.50k
    } else if (h_in_group * 2 == h_out_group &&
532
5.49k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
4.99k
      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
4.99k
      } else {
543
#ifdef WITH_SIMD
544
        if (jsimd_set_h2v2_upsample(cinfo))
545
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
        else
547
#endif
548
4.99k
          upsample->methods[ci] = h2v2_upsample;
549
4.99k
      }
550
4.99k
    } else if ((h_out_group % h_in_group) == 0 &&
551
4.47k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
4.43k
      upsample->methods[ci] = int_upsample;
554
4.43k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
4.43k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
4.43k
    } else
557
63
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
16.9k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
11.3k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
11.3k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
11.3k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
11.3k
                               (long)cinfo->max_h_samp_factor),
563
11.3k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
11.3k
    }
565
16.9k
  }
566
6.32k
}
567
568
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */