Coverage Report

Created: 2025-12-05 06:42

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) 2014, MIPS Technologies, Inc., California.
10
 * Copyright (C) 2015, Google, Inc.
11
 * Copyright (C) 2019-2020, Arm Limited.
12
 * For conditions of distribution and use, see the accompanying README.ijg
13
 * file.
14
 *
15
 * This file contains upsampling routines.
16
 *
17
 * Upsampling input data is counted in "row groups".  A row group
18
 * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)
19
 * sample rows of each component.  Upsampling will normally produce
20
 * max_v_samp_factor pixel rows from each row group (but this could vary
21
 * if the upsampler is applying a scale factor of its own).
22
 *
23
 * An excellent reference for image resampling is
24
 *   Digital Image Warping, George Wolberg, 1990.
25
 *   Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
26
 */
27
28
#include "jinclude.h"
29
#include "jdsample.h"
30
#ifdef WITH_SIMD
31
#include "../simd/jsimd.h"
32
#endif
33
#include "jpegapicomp.h"
34
#ifdef WITH_PROFILE
35
#include "tjutil.h"
36
#endif
37
38
39
40
#if BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED)
41
42
/*
43
 * Initialize for an upsampling pass.
44
 */
45
46
METHODDEF(void)
47
start_pass_upsample(j_decompress_ptr cinfo)
48
5.69k
{
49
5.69k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
50
51
  /* Mark the conversion buffer empty */
52
5.69k
  upsample->next_row_out = cinfo->max_v_samp_factor;
53
  /* Initialize total-height counter for detecting bottom of image */
54
5.69k
  upsample->rows_to_go = cinfo->output_height;
55
5.69k
}
jdsample-8.c:start_pass_upsample
Line
Count
Source
48
2.74k
{
49
2.74k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
50
51
  /* Mark the conversion buffer empty */
52
2.74k
  upsample->next_row_out = cinfo->max_v_samp_factor;
53
  /* Initialize total-height counter for detecting bottom of image */
54
2.74k
  upsample->rows_to_go = cinfo->output_height;
55
2.74k
}
jdsample-12.c:start_pass_upsample
Line
Count
Source
48
2.58k
{
49
2.58k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
50
51
  /* Mark the conversion buffer empty */
52
2.58k
  upsample->next_row_out = cinfo->max_v_samp_factor;
53
  /* Initialize total-height counter for detecting bottom of image */
54
2.58k
  upsample->rows_to_go = cinfo->output_height;
55
2.58k
}
jdsample-16.c:start_pass_upsample
Line
Count
Source
48
367
{
49
367
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
50
51
  /* Mark the conversion buffer empty */
52
367
  upsample->next_row_out = cinfo->max_v_samp_factor;
53
  /* Initialize total-height counter for detecting bottom of image */
54
367
  upsample->rows_to_go = cinfo->output_height;
55
367
}
56
57
58
/*
59
 * Control routine to do upsampling (and color conversion).
60
 *
61
 * In this version we upsample each component independently.
62
 * We upsample one row group into the conversion buffer, then apply
63
 * color conversion a row at a time.
64
 */
65
66
METHODDEF(void)
67
sep_upsample(j_decompress_ptr cinfo, _JSAMPIMAGE input_buf,
68
             JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail,
69
             _JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
70
             JDIMENSION out_rows_avail)
71
8.72M
{
72
8.72M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
73
8.72M
  int ci;
74
8.72M
  jpeg_component_info *compptr;
75
8.72M
  JDIMENSION num_rows;
76
77
  /* Fill the conversion buffer, if it's empty */
78
8.72M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
79
25.1M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
80
16.4M
         ci++, compptr++) {
81
      /* Invoke per-component upsample method.  Notice we pass a POINTER
82
       * to color_buf[ci], so that fullsize_upsample can change it.
83
       */
84
#ifdef WITH_PROFILE
85
      cinfo->master->start = getTime();
86
#endif
87
16.4M
      (*upsample->methods[ci]) (cinfo, compptr,
88
16.4M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
89
16.4M
        upsample->color_buf + ci);
90
#ifdef WITH_PROFILE
91
      cinfo->master->upsample_elapsed += getTime() - cinfo->master->start;
92
      cinfo->master->upsample_msamples +=
93
        (double)cinfo->output_width * cinfo->max_v_samp_factor / 1000000.;
94
#endif
95
16.4M
    }
96
8.72M
    upsample->next_row_out = 0;
97
8.72M
  }
98
99
  /* Color-convert and emit rows */
100
101
  /* How many we have in the buffer: */
102
8.72M
  num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out);
103
  /* Not more than the distance to the end of the image.  Need this test
104
   * in case the image height is not a multiple of max_v_samp_factor:
105
   */
106
8.72M
  if (num_rows > upsample->rows_to_go)
107
1.87k
    num_rows = upsample->rows_to_go;
108
  /* And not more than what the client can accept: */
109
8.72M
  out_rows_avail -= *out_row_ctr;
110
8.72M
  if (num_rows > out_rows_avail)
111
0
    num_rows = out_rows_avail;
112
113
#ifdef WITH_PROFILE
114
  cinfo->master->start = getTime();
115
#endif
116
8.72M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
117
8.72M
                                      (JDIMENSION)upsample->next_row_out,
118
8.72M
                                      output_buf + *out_row_ctr,
119
8.72M
                                      (int)num_rows);
120
#ifdef WITH_PROFILE
121
  cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
122
  cinfo->master->cconvert_mpixels +=
123
    (double)cinfo->output_width * num_rows / 1000000.;
124
#endif
125
126
  /* Adjust counts */
127
8.72M
  *out_row_ctr += num_rows;
128
8.72M
  upsample->rows_to_go -= num_rows;
129
8.72M
  upsample->next_row_out += num_rows;
130
  /* When the buffer is emptied, declare this input row group consumed */
131
8.72M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
132
8.72M
    (*in_row_group_ctr)++;
133
8.72M
}
jdsample-8.c:sep_upsample
Line
Count
Source
71
4.12M
{
72
4.12M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
73
4.12M
  int ci;
74
4.12M
  jpeg_component_info *compptr;
75
4.12M
  JDIMENSION num_rows;
76
77
  /* Fill the conversion buffer, if it's empty */
78
4.12M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
79
12.3M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
80
8.20M
         ci++, compptr++) {
81
      /* Invoke per-component upsample method.  Notice we pass a POINTER
82
       * to color_buf[ci], so that fullsize_upsample can change it.
83
       */
84
#ifdef WITH_PROFILE
85
      cinfo->master->start = getTime();
86
#endif
87
8.20M
      (*upsample->methods[ci]) (cinfo, compptr,
88
8.20M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
89
8.20M
        upsample->color_buf + ci);
90
#ifdef WITH_PROFILE
91
      cinfo->master->upsample_elapsed += getTime() - cinfo->master->start;
92
      cinfo->master->upsample_msamples +=
93
        (double)cinfo->output_width * cinfo->max_v_samp_factor / 1000000.;
94
#endif
95
8.20M
    }
96
4.12M
    upsample->next_row_out = 0;
97
4.12M
  }
98
99
  /* Color-convert and emit rows */
100
101
  /* How many we have in the buffer: */
102
4.12M
  num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out);
103
  /* Not more than the distance to the end of the image.  Need this test
104
   * in case the image height is not a multiple of max_v_samp_factor:
105
   */
106
4.12M
  if (num_rows > upsample->rows_to_go)
107
1.08k
    num_rows = upsample->rows_to_go;
108
  /* And not more than what the client can accept: */
109
4.12M
  out_rows_avail -= *out_row_ctr;
110
4.12M
  if (num_rows > out_rows_avail)
111
0
    num_rows = out_rows_avail;
112
113
#ifdef WITH_PROFILE
114
  cinfo->master->start = getTime();
115
#endif
116
4.12M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
117
4.12M
                                      (JDIMENSION)upsample->next_row_out,
118
4.12M
                                      output_buf + *out_row_ctr,
119
4.12M
                                      (int)num_rows);
120
#ifdef WITH_PROFILE
121
  cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
122
  cinfo->master->cconvert_mpixels +=
123
    (double)cinfo->output_width * num_rows / 1000000.;
124
#endif
125
126
  /* Adjust counts */
127
4.12M
  *out_row_ctr += num_rows;
128
4.12M
  upsample->rows_to_go -= num_rows;
129
4.12M
  upsample->next_row_out += num_rows;
130
  /* When the buffer is emptied, declare this input row group consumed */
131
4.12M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
132
4.12M
    (*in_row_group_ctr)++;
133
4.12M
}
jdsample-12.c:sep_upsample
Line
Count
Source
71
4.37M
{
72
4.37M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
73
4.37M
  int ci;
74
4.37M
  jpeg_component_info *compptr;
75
4.37M
  JDIMENSION num_rows;
76
77
  /* Fill the conversion buffer, if it's empty */
78
4.37M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
79
11.8M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
80
7.52M
         ci++, compptr++) {
81
      /* Invoke per-component upsample method.  Notice we pass a POINTER
82
       * to color_buf[ci], so that fullsize_upsample can change it.
83
       */
84
#ifdef WITH_PROFILE
85
      cinfo->master->start = getTime();
86
#endif
87
7.52M
      (*upsample->methods[ci]) (cinfo, compptr,
88
7.52M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
89
7.52M
        upsample->color_buf + ci);
90
#ifdef WITH_PROFILE
91
      cinfo->master->upsample_elapsed += getTime() - cinfo->master->start;
92
      cinfo->master->upsample_msamples +=
93
        (double)cinfo->output_width * cinfo->max_v_samp_factor / 1000000.;
94
#endif
95
7.52M
    }
96
4.37M
    upsample->next_row_out = 0;
97
4.37M
  }
98
99
  /* Color-convert and emit rows */
100
101
  /* How many we have in the buffer: */
102
4.37M
  num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out);
103
  /* Not more than the distance to the end of the image.  Need this test
104
   * in case the image height is not a multiple of max_v_samp_factor:
105
   */
106
4.37M
  if (num_rows > upsample->rows_to_go)
107
747
    num_rows = upsample->rows_to_go;
108
  /* And not more than what the client can accept: */
109
4.37M
  out_rows_avail -= *out_row_ctr;
110
4.37M
  if (num_rows > out_rows_avail)
111
0
    num_rows = out_rows_avail;
112
113
#ifdef WITH_PROFILE
114
  cinfo->master->start = getTime();
115
#endif
116
4.37M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
117
4.37M
                                      (JDIMENSION)upsample->next_row_out,
118
4.37M
                                      output_buf + *out_row_ctr,
119
4.37M
                                      (int)num_rows);
120
#ifdef WITH_PROFILE
121
  cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
122
  cinfo->master->cconvert_mpixels +=
123
    (double)cinfo->output_width * num_rows / 1000000.;
124
#endif
125
126
  /* Adjust counts */
127
4.37M
  *out_row_ctr += num_rows;
128
4.37M
  upsample->rows_to_go -= num_rows;
129
4.37M
  upsample->next_row_out += num_rows;
130
  /* When the buffer is emptied, declare this input row group consumed */
131
4.37M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
132
4.37M
    (*in_row_group_ctr)++;
133
4.37M
}
jdsample-16.c:sep_upsample
Line
Count
Source
71
226k
{
72
226k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
73
226k
  int ci;
74
226k
  jpeg_component_info *compptr;
75
226k
  JDIMENSION num_rows;
76
77
  /* Fill the conversion buffer, if it's empty */
78
226k
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
79
905k
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
80
679k
         ci++, compptr++) {
81
      /* Invoke per-component upsample method.  Notice we pass a POINTER
82
       * to color_buf[ci], so that fullsize_upsample can change it.
83
       */
84
#ifdef WITH_PROFILE
85
      cinfo->master->start = getTime();
86
#endif
87
679k
      (*upsample->methods[ci]) (cinfo, compptr,
88
679k
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
89
679k
        upsample->color_buf + ci);
90
#ifdef WITH_PROFILE
91
      cinfo->master->upsample_elapsed += getTime() - cinfo->master->start;
92
      cinfo->master->upsample_msamples +=
93
        (double)cinfo->output_width * cinfo->max_v_samp_factor / 1000000.;
94
#endif
95
679k
    }
96
226k
    upsample->next_row_out = 0;
97
226k
  }
98
99
  /* Color-convert and emit rows */
100
101
  /* How many we have in the buffer: */
102
226k
  num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out);
103
  /* Not more than the distance to the end of the image.  Need this test
104
   * in case the image height is not a multiple of max_v_samp_factor:
105
   */
106
226k
  if (num_rows > upsample->rows_to_go)
107
45
    num_rows = upsample->rows_to_go;
108
  /* And not more than what the client can accept: */
109
226k
  out_rows_avail -= *out_row_ctr;
110
226k
  if (num_rows > out_rows_avail)
111
0
    num_rows = out_rows_avail;
112
113
#ifdef WITH_PROFILE
114
  cinfo->master->start = getTime();
115
#endif
116
226k
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
117
226k
                                      (JDIMENSION)upsample->next_row_out,
118
226k
                                      output_buf + *out_row_ctr,
119
226k
                                      (int)num_rows);
120
#ifdef WITH_PROFILE
121
  cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
122
  cinfo->master->cconvert_mpixels +=
123
    (double)cinfo->output_width * num_rows / 1000000.;
124
#endif
125
126
  /* Adjust counts */
127
226k
  *out_row_ctr += num_rows;
128
226k
  upsample->rows_to_go -= num_rows;
129
226k
  upsample->next_row_out += num_rows;
130
  /* When the buffer is emptied, declare this input row group consumed */
131
226k
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
132
226k
    (*in_row_group_ctr)++;
133
226k
}
134
135
136
/*
137
 * These are the routines invoked by sep_upsample to upsample pixel values
138
 * of a single component.  One row group is processed per call.
139
 */
140
141
142
/*
143
 * For full-size components, we just make color_buf[ci] point at the
144
 * input buffer, and thus avoid copying any data.  Note that this is
145
 * safe only because sep_upsample doesn't declare the input row group
146
 * "consumed" until we are done color converting and emitting it.
147
 */
148
149
METHODDEF(void)
150
fullsize_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
151
                  _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
152
8.02M
{
153
8.02M
  *output_data_ptr = input_data;
154
8.02M
}
jdsample-8.c:fullsize_upsample
Line
Count
Source
152
3.69M
{
153
3.69M
  *output_data_ptr = input_data;
154
3.69M
}
jdsample-12.c:fullsize_upsample
Line
Count
Source
152
4.12M
{
153
4.12M
  *output_data_ptr = input_data;
154
4.12M
}
jdsample-16.c:fullsize_upsample
Line
Count
Source
152
201k
{
153
201k
  *output_data_ptr = input_data;
154
201k
}
155
156
157
/*
158
 * This is a no-op version used for "uninteresting" components.
159
 * These components will not be referenced by color conversion.
160
 */
161
162
METHODDEF(void)
163
noop_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
164
              _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
165
1.36M
{
166
1.36M
  *output_data_ptr = NULL;      /* safety check */
167
1.36M
}
jdsample-8.c:noop_upsample
Line
Count
Source
165
602k
{
166
  *output_data_ptr = NULL;      /* safety check */
167
602k
}
jdsample-12.c:noop_upsample
Line
Count
Source
165
759k
{
166
  *output_data_ptr = NULL;      /* safety check */
167
759k
}
Unexecuted instantiation: jdsample-16.c:noop_upsample
168
169
170
/*
171
 * This version handles any integral sampling ratios.
172
 * This is not used for typical JPEG files, so it need not be fast.
173
 * Nor, for that matter, is it particularly accurate: the algorithm is
174
 * simple replication of the input pixel onto the corresponding output
175
 * pixels.  The hi-falutin sampling literature refers to this as a
176
 * "box filter".  A box filter tends to introduce visible artifacts,
177
 * so if you are actually going to use 3:1 or 4:1 sampling ratios
178
 * you would be well advised to improve this code.
179
 */
180
181
METHODDEF(void)
182
int_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
183
             _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
184
3.49M
{
185
3.49M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
186
3.49M
  _JSAMPARRAY output_data = *output_data_ptr;
187
3.49M
  register _JSAMPROW inptr, outptr;
188
3.49M
  register _JSAMPLE invalue;
189
3.49M
  register int h;
190
3.49M
  _JSAMPROW outend;
191
3.49M
  int h_expand, v_expand;
192
3.49M
  int inrow, outrow;
193
194
3.49M
  h_expand = upsample->h_expand[compptr->component_index];
195
3.49M
  v_expand = upsample->v_expand[compptr->component_index];
196
197
3.49M
  inrow = outrow = 0;
198
7.42M
  while (outrow < cinfo->max_v_samp_factor) {
199
    /* Generate one output row with proper horizontal expansion */
200
3.93M
    inptr = input_data[inrow];
201
3.93M
    outptr = output_data[outrow];
202
3.93M
    outend = outptr + cinfo->output_width;
203
128M
    while (outptr < outend) {
204
124M
      invalue = *inptr++;
205
316M
      for (h = h_expand; h > 0; h--) {
206
192M
        *outptr++ = invalue;
207
192M
      }
208
124M
    }
209
    /* Generate any additional output rows by duplicating the first one */
210
3.93M
    if (v_expand > 1) {
211
2.79M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
212
2.79M
                         v_expand - 1, cinfo->output_width);
213
2.79M
    }
214
3.93M
    inrow++;
215
3.93M
    outrow += v_expand;
216
3.93M
  }
217
3.49M
}
jdsample-8.c:int_upsample
Line
Count
Source
184
2.09M
{
185
2.09M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
186
2.09M
  _JSAMPARRAY output_data = *output_data_ptr;
187
2.09M
  register _JSAMPROW inptr, outptr;
188
2.09M
  register _JSAMPLE invalue;
189
2.09M
  register int h;
190
2.09M
  _JSAMPROW outend;
191
2.09M
  int h_expand, v_expand;
192
2.09M
  int inrow, outrow;
193
194
2.09M
  h_expand = upsample->h_expand[compptr->component_index];
195
2.09M
  v_expand = upsample->v_expand[compptr->component_index];
196
197
2.09M
  inrow = outrow = 0;
198
4.40M
  while (outrow < cinfo->max_v_samp_factor) {
199
    /* Generate one output row with proper horizontal expansion */
200
2.31M
    inptr = input_data[inrow];
201
2.31M
    outptr = output_data[outrow];
202
2.31M
    outend = outptr + cinfo->output_width;
203
95.5M
    while (outptr < outend) {
204
93.2M
      invalue = *inptr++;
205
235M
      for (h = h_expand; h > 0; h--) {
206
141M
        *outptr++ = invalue;
207
141M
      }
208
93.2M
    }
209
    /* Generate any additional output rows by duplicating the first one */
210
2.31M
    if (v_expand > 1) {
211
1.84M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
212
1.84M
                         v_expand - 1, cinfo->output_width);
213
1.84M
    }
214
2.31M
    inrow++;
215
2.31M
    outrow += v_expand;
216
2.31M
  }
217
2.09M
}
jdsample-12.c:int_upsample
Line
Count
Source
184
1.08M
{
185
1.08M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
186
1.08M
  _JSAMPARRAY output_data = *output_data_ptr;
187
1.08M
  register _JSAMPROW inptr, outptr;
188
1.08M
  register _JSAMPLE invalue;
189
1.08M
  register int h;
190
1.08M
  _JSAMPROW outend;
191
1.08M
  int h_expand, v_expand;
192
1.08M
  int inrow, outrow;
193
194
1.08M
  h_expand = upsample->h_expand[compptr->component_index];
195
1.08M
  v_expand = upsample->v_expand[compptr->component_index];
196
197
1.08M
  inrow = outrow = 0;
198
2.29M
  while (outrow < cinfo->max_v_samp_factor) {
199
    /* Generate one output row with proper horizontal expansion */
200
1.21M
    inptr = input_data[inrow];
201
1.21M
    outptr = output_data[outrow];
202
1.21M
    outend = outptr + cinfo->output_width;
203
28.4M
    while (outptr < outend) {
204
27.2M
      invalue = *inptr++;
205
71.6M
      for (h = h_expand; h > 0; h--) {
206
44.4M
        *outptr++ = invalue;
207
44.4M
      }
208
27.2M
    }
209
    /* Generate any additional output rows by duplicating the first one */
210
1.21M
    if (v_expand > 1) {
211
837k
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
212
837k
                         v_expand - 1, cinfo->output_width);
213
837k
    }
214
1.21M
    inrow++;
215
1.21M
    outrow += v_expand;
216
1.21M
  }
217
1.08M
}
jdsample-16.c:int_upsample
Line
Count
Source
184
318k
{
185
318k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
186
318k
  _JSAMPARRAY output_data = *output_data_ptr;
187
318k
  register _JSAMPROW inptr, outptr;
188
318k
  register _JSAMPLE invalue;
189
318k
  register int h;
190
318k
  _JSAMPROW outend;
191
318k
  int h_expand, v_expand;
192
318k
  int inrow, outrow;
193
194
318k
  h_expand = upsample->h_expand[compptr->component_index];
195
318k
  v_expand = upsample->v_expand[compptr->component_index];
196
197
318k
  inrow = outrow = 0;
198
720k
  while (outrow < cinfo->max_v_samp_factor) {
199
    /* Generate one output row with proper horizontal expansion */
200
401k
    inptr = input_data[inrow];
201
401k
    outptr = output_data[outrow];
202
401k
    outend = outptr + cinfo->output_width;
203
4.15M
    while (outptr < outend) {
204
3.75M
      invalue = *inptr++;
205
10.0M
      for (h = h_expand; h > 0; h--) {
206
6.31M
        *outptr++ = invalue;
207
6.31M
      }
208
3.75M
    }
209
    /* Generate any additional output rows by duplicating the first one */
210
401k
    if (v_expand > 1) {
211
109k
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
212
109k
                         v_expand - 1, cinfo->output_width);
213
109k
    }
214
401k
    inrow++;
215
401k
    outrow += v_expand;
216
401k
  }
217
318k
}
218
219
220
/*
221
 * Fast processing for the common case of 2:1 horizontal and 1:1 vertical.
222
 * It's still a box filter.
223
 */
224
225
METHODDEF(void)
226
h2v1_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
227
              _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
228
946k
{
229
946k
  _JSAMPARRAY output_data = *output_data_ptr;
230
946k
  register _JSAMPROW inptr, outptr;
231
946k
  register _JSAMPLE invalue;
232
946k
  _JSAMPROW outend;
233
946k
  int inrow;
234
235
2.46M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
236
1.52M
    inptr = input_data[inrow];
237
1.52M
    outptr = output_data[inrow];
238
1.52M
    outend = outptr + cinfo->output_width;
239
14.8M
    while (outptr < outend) {
240
13.3M
      invalue = *inptr++;
241
13.3M
      *outptr++ = invalue;
242
13.3M
      *outptr++ = invalue;
243
13.3M
    }
244
1.52M
  }
245
946k
}
Unexecuted instantiation: jdsample-8.c:h2v1_upsample
jdsample-12.c:h2v1_upsample
Line
Count
Source
228
845k
{
229
845k
  _JSAMPARRAY output_data = *output_data_ptr;
230
845k
  register _JSAMPROW inptr, outptr;
231
845k
  register _JSAMPLE invalue;
232
845k
  _JSAMPROW outend;
233
845k
  int inrow;
234
235
2.26M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
236
1.41M
    inptr = input_data[inrow];
237
1.41M
    outptr = output_data[inrow];
238
1.41M
    outend = outptr + cinfo->output_width;
239
12.2M
    while (outptr < outend) {
240
10.8M
      invalue = *inptr++;
241
10.8M
      *outptr++ = invalue;
242
10.8M
      *outptr++ = invalue;
243
10.8M
    }
244
1.41M
  }
245
845k
}
jdsample-16.c:h2v1_upsample
Line
Count
Source
228
101k
{
229
101k
  _JSAMPARRAY output_data = *output_data_ptr;
230
101k
  register _JSAMPROW inptr, outptr;
231
101k
  register _JSAMPLE invalue;
232
101k
  _JSAMPROW outend;
233
101k
  int inrow;
234
235
205k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
236
104k
    inptr = input_data[inrow];
237
104k
    outptr = output_data[inrow];
238
104k
    outend = outptr + cinfo->output_width;
239
2.63M
    while (outptr < outend) {
240
2.52M
      invalue = *inptr++;
241
2.52M
      *outptr++ = invalue;
242
2.52M
      *outptr++ = invalue;
243
2.52M
    }
244
104k
  }
245
101k
}
246
247
248
/*
249
 * Fast processing for the common case of 2:1 horizontal and 2:1 vertical.
250
 * It's still a box filter.
251
 */
252
253
METHODDEF(void)
254
h2v2_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
255
              _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
256
452k
{
257
452k
  _JSAMPARRAY output_data = *output_data_ptr;
258
452k
  register _JSAMPROW inptr, outptr;
259
452k
  register _JSAMPLE invalue;
260
452k
  _JSAMPROW outend;
261
452k
  int inrow, outrow;
262
263
452k
  inrow = outrow = 0;
264
1.00M
  while (outrow < cinfo->max_v_samp_factor) {
265
551k
    inptr = input_data[inrow];
266
551k
    outptr = output_data[outrow];
267
551k
    outend = outptr + cinfo->output_width;
268
9.30M
    while (outptr < outend) {
269
8.74M
      invalue = *inptr++;
270
8.74M
      *outptr++ = invalue;
271
8.74M
      *outptr++ = invalue;
272
8.74M
    }
273
551k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
274
551k
                       cinfo->output_width);
275
551k
    inrow++;
276
551k
    outrow += 2;
277
551k
  }
278
452k
}
Unexecuted instantiation: jdsample-8.c:h2v2_upsample
jdsample-12.c:h2v2_upsample
Line
Count
Source
256
394k
{
257
394k
  _JSAMPARRAY output_data = *output_data_ptr;
258
394k
  register _JSAMPROW inptr, outptr;
259
394k
  register _JSAMPLE invalue;
260
394k
  _JSAMPROW outend;
261
394k
  int inrow, outrow;
262
263
394k
  inrow = outrow = 0;
264
831k
  while (outrow < cinfo->max_v_samp_factor) {
265
437k
    inptr = input_data[inrow];
266
437k
    outptr = output_data[outrow];
267
437k
    outend = outptr + cinfo->output_width;
268
7.64M
    while (outptr < outend) {
269
7.20M
      invalue = *inptr++;
270
7.20M
      *outptr++ = invalue;
271
7.20M
      *outptr++ = invalue;
272
7.20M
    }
273
437k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
274
437k
                       cinfo->output_width);
275
437k
    inrow++;
276
437k
    outrow += 2;
277
437k
  }
278
394k
}
jdsample-16.c:h2v2_upsample
Line
Count
Source
256
58.3k
{
257
58.3k
  _JSAMPARRAY output_data = *output_data_ptr;
258
58.3k
  register _JSAMPROW inptr, outptr;
259
58.3k
  register _JSAMPLE invalue;
260
58.3k
  _JSAMPROW outend;
261
58.3k
  int inrow, outrow;
262
263
58.3k
  inrow = outrow = 0;
264
173k
  while (outrow < cinfo->max_v_samp_factor) {
265
114k
    inptr = input_data[inrow];
266
114k
    outptr = output_data[outrow];
267
114k
    outend = outptr + cinfo->output_width;
268
1.65M
    while (outptr < outend) {
269
1.54M
      invalue = *inptr++;
270
1.54M
      *outptr++ = invalue;
271
1.54M
      *outptr++ = invalue;
272
1.54M
    }
273
114k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
274
114k
                       cinfo->output_width);
275
114k
    inrow++;
276
114k
    outrow += 2;
277
114k
  }
278
58.3k
}
279
280
281
/*
282
 * Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
283
 *
284
 * The upsampling algorithm is linear interpolation between pixel centers,
285
 * also known as a "triangle filter".  This is a good compromise between
286
 * speed and visual quality.  The centers of the output pixels are 1/4 and 3/4
287
 * of the way between input pixel centers.
288
 *
289
 * A note about the "bias" calculations: when rounding fractional values to
290
 * integer, we do not want to always round 0.5 up to the next integer.
291
 * If we did that, we'd introduce a noticeable bias towards larger values.
292
 * Instead, this code is arranged so that 0.5 will be rounded up or down at
293
 * alternate pixel locations (a simple ordered dither pattern).
294
 */
295
296
METHODDEF(void)
297
h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
298
                    _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
299
48.7k
{
300
48.7k
  _JSAMPARRAY output_data = *output_data_ptr;
301
48.7k
  register _JSAMPROW inptr, outptr;
302
48.7k
  register int invalue;
303
48.7k
  register JDIMENSION colctr;
304
48.7k
  int inrow;
305
306
199k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
307
150k
    inptr = input_data[inrow];
308
150k
    outptr = output_data[inrow];
309
    /* Special case for first column */
310
150k
    invalue = *inptr++;
311
150k
    *outptr++ = (_JSAMPLE)invalue;
312
150k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
313
314
3.42M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
315
      /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
316
3.27M
      invalue = (*inptr++) * 3;
317
3.27M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
318
3.27M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
319
3.27M
    }
320
321
    /* Special case for last column */
322
150k
    invalue = *inptr;
323
150k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
324
150k
    *outptr++ = (_JSAMPLE)invalue;
325
150k
  }
326
48.7k
}
Unexecuted instantiation: jdsample-8.c:h2v1_fancy_upsample
jdsample-12.c:h2v1_fancy_upsample
Line
Count
Source
299
48.7k
{
300
48.7k
  _JSAMPARRAY output_data = *output_data_ptr;
301
48.7k
  register _JSAMPROW inptr, outptr;
302
48.7k
  register int invalue;
303
48.7k
  register JDIMENSION colctr;
304
48.7k
  int inrow;
305
306
199k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
307
150k
    inptr = input_data[inrow];
308
150k
    outptr = output_data[inrow];
309
    /* Special case for first column */
310
150k
    invalue = *inptr++;
311
150k
    *outptr++ = (_JSAMPLE)invalue;
312
150k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
313
314
3.42M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
315
      /* General case: 3/4 * nearer pixel + 1/4 * further pixel */
316
3.27M
      invalue = (*inptr++) * 3;
317
3.27M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
318
3.27M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
319
3.27M
    }
320
321
    /* Special case for last column */
322
150k
    invalue = *inptr;
323
150k
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
324
150k
    *outptr++ = (_JSAMPLE)invalue;
325
150k
  }
326
48.7k
}
Unexecuted instantiation: jdsample-16.c:h2v1_fancy_upsample
327
328
329
/*
330
 * Fancy processing for 1:1 horizontal and 2:1 vertical (4:4:0 subsampling).
331
 *
332
 * This is a less common case, but it can be encountered when losslessly
333
 * rotating/transposing a JPEG file that uses 4:2:2 chroma subsampling.
334
 */
335
336
METHODDEF(void)
337
h1v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
338
                    _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
339
272k
{
340
272k
  _JSAMPARRAY output_data = *output_data_ptr;
341
272k
  _JSAMPROW inptr0, inptr1, outptr;
342
#if BITS_IN_JSAMPLE == 8
343
  int thiscolsum, bias;
344
#else
345
  JLONG thiscolsum, bias;
346
#endif
347
272k
  JDIMENSION colctr;
348
272k
  int inrow, outrow, v;
349
350
272k
  inrow = outrow = 0;
351
578k
  while (outrow < cinfo->max_v_samp_factor) {
352
920k
    for (v = 0; v < 2; v++) {
353
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
354
613k
      inptr0 = input_data[inrow];
355
613k
      if (v == 0) {             /* next nearest is row above */
356
306k
        inptr1 = input_data[inrow - 1];
357
306k
        bias = 1;
358
306k
      } else {                  /* next nearest is row below */
359
306k
        inptr1 = input_data[inrow + 1];
360
306k
        bias = 2;
361
306k
      }
362
613k
      outptr = output_data[outrow++];
363
364
23.9M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
365
23.2M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
366
23.2M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
367
23.2M
      }
368
613k
    }
369
306k
    inrow++;
370
306k
  }
371
272k
}
jdsample-8.c:h1v2_fancy_upsample
Line
Count
Source
339
80.8k
{
340
80.8k
  _JSAMPARRAY output_data = *output_data_ptr;
341
80.8k
  _JSAMPROW inptr0, inptr1, outptr;
342
80.8k
#if BITS_IN_JSAMPLE == 8
343
80.8k
  int thiscolsum, bias;
344
#else
345
  JLONG thiscolsum, bias;
346
#endif
347
80.8k
  JDIMENSION colctr;
348
80.8k
  int inrow, outrow, v;
349
350
80.8k
  inrow = outrow = 0;
351
176k
  while (outrow < cinfo->max_v_samp_factor) {
352
286k
    for (v = 0; v < 2; v++) {
353
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
354
191k
      inptr0 = input_data[inrow];
355
191k
      if (v == 0) {             /* next nearest is row above */
356
95.5k
        inptr1 = input_data[inrow - 1];
357
95.5k
        bias = 1;
358
95.5k
      } else {                  /* next nearest is row below */
359
95.5k
        inptr1 = input_data[inrow + 1];
360
95.5k
        bias = 2;
361
95.5k
      }
362
191k
      outptr = output_data[outrow++];
363
364
9.61M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
365
9.42M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
366
9.42M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
367
9.42M
      }
368
191k
    }
369
95.5k
    inrow++;
370
95.5k
  }
371
80.8k
}
jdsample-12.c:h1v2_fancy_upsample
Line
Count
Source
339
191k
{
340
191k
  _JSAMPARRAY output_data = *output_data_ptr;
341
191k
  _JSAMPROW inptr0, inptr1, outptr;
342
#if BITS_IN_JSAMPLE == 8
343
  int thiscolsum, bias;
344
#else
345
191k
  JLONG thiscolsum, bias;
346
191k
#endif
347
191k
  JDIMENSION colctr;
348
191k
  int inrow, outrow, v;
349
350
191k
  inrow = outrow = 0;
351
402k
  while (outrow < cinfo->max_v_samp_factor) {
352
633k
    for (v = 0; v < 2; v++) {
353
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
354
422k
      inptr0 = input_data[inrow];
355
422k
      if (v == 0) {             /* next nearest is row above */
356
211k
        inptr1 = input_data[inrow - 1];
357
211k
        bias = 1;
358
211k
      } else {                  /* next nearest is row below */
359
211k
        inptr1 = input_data[inrow + 1];
360
211k
        bias = 2;
361
211k
      }
362
422k
      outptr = output_data[outrow++];
363
364
14.2M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
365
13.8M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
366
13.8M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
367
13.8M
      }
368
422k
    }
369
211k
    inrow++;
370
211k
  }
371
191k
}
Unexecuted instantiation: jdsample-16.c:h1v2_fancy_upsample
372
373
374
/*
375
 * Fancy processing for the common case of 2:1 horizontal and 2:1 vertical.
376
 * Again a triangle filter; see comments for h2v1 case, above.
377
 *
378
 * It is OK for us to reference the adjacent input rows because we demanded
379
 * context from the main buffer controller (see initialization code).
380
 */
381
382
METHODDEF(void)
383
h2v2_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
384
                    _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
385
77.4k
{
386
77.4k
  _JSAMPARRAY output_data = *output_data_ptr;
387
77.4k
  register _JSAMPROW inptr0, inptr1, outptr;
388
#if BITS_IN_JSAMPLE == 8
389
  register int thiscolsum, lastcolsum, nextcolsum;
390
#else
391
  register JLONG thiscolsum, lastcolsum, nextcolsum;
392
#endif
393
77.4k
  register JDIMENSION colctr;
394
77.4k
  int inrow, outrow, v;
395
396
77.4k
  inrow = outrow = 0;
397
187k
  while (outrow < cinfo->max_v_samp_factor) {
398
331k
    for (v = 0; v < 2; v++) {
399
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
400
220k
      inptr0 = input_data[inrow];
401
220k
      if (v == 0)               /* next nearest is row above */
402
110k
        inptr1 = input_data[inrow - 1];
403
110k
      else                      /* next nearest is row below */
404
110k
        inptr1 = input_data[inrow + 1];
405
220k
      outptr = output_data[outrow++];
406
407
      /* Special case for first column */
408
220k
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
409
220k
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
410
220k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
411
220k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
412
220k
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
413
414
5.48M
      for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
415
        /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
416
        /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
417
5.26M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
5.26M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
5.26M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
5.26M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
5.26M
      }
422
423
      /* Special case for last column */
424
220k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
220k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
220k
    }
427
110k
    inrow++;
428
110k
  }
429
77.4k
}
Unexecuted instantiation: jdsample-8.c:h2v2_fancy_upsample
jdsample-12.c:h2v2_fancy_upsample
Line
Count
Source
385
77.4k
{
386
77.4k
  _JSAMPARRAY output_data = *output_data_ptr;
387
77.4k
  register _JSAMPROW inptr0, inptr1, outptr;
388
#if BITS_IN_JSAMPLE == 8
389
  register int thiscolsum, lastcolsum, nextcolsum;
390
#else
391
77.4k
  register JLONG thiscolsum, lastcolsum, nextcolsum;
392
77.4k
#endif
393
77.4k
  register JDIMENSION colctr;
394
77.4k
  int inrow, outrow, v;
395
396
77.4k
  inrow = outrow = 0;
397
187k
  while (outrow < cinfo->max_v_samp_factor) {
398
331k
    for (v = 0; v < 2; v++) {
399
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
400
220k
      inptr0 = input_data[inrow];
401
220k
      if (v == 0)               /* next nearest is row above */
402
110k
        inptr1 = input_data[inrow - 1];
403
110k
      else                      /* next nearest is row below */
404
110k
        inptr1 = input_data[inrow + 1];
405
220k
      outptr = output_data[outrow++];
406
407
      /* Special case for first column */
408
220k
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
409
220k
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
410
220k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
411
220k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
412
220k
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
413
414
5.48M
      for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
415
        /* General case: 3/4 * nearer pixel + 1/4 * further pixel in each */
416
        /* dimension, thus 9/16, 3/16, 3/16, 1/16 overall */
417
5.26M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
5.26M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
5.26M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
5.26M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
5.26M
      }
422
423
      /* Special case for last column */
424
220k
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
220k
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
220k
    }
427
110k
    inrow++;
428
110k
  }
429
77.4k
}
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
6.91k
{
439
6.91k
  my_upsample_ptr upsample;
440
6.91k
  int ci;
441
6.91k
  jpeg_component_info *compptr;
442
6.91k
  boolean need_buffer, do_fancy;
443
6.91k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
6.91k
#ifdef D_LOSSLESS_SUPPORTED
446
6.91k
  if (cinfo->master->lossless) {
447
#if BITS_IN_JSAMPLE == 8
448
447
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
449
#else
450
1.00k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
1.00k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
1.45k
  } else
455
5.46k
#endif
456
5.46k
  {
457
5.46k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
5.46k
  }
460
461
6.91k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
6.91k
    upsample = (my_upsample_ptr)
463
6.91k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
6.91k
                                  sizeof(my_upsampler));
465
6.91k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
6.91k
    upsample->pub.start_pass = start_pass_upsample;
467
6.91k
    upsample->pub._upsample = sep_upsample;
468
6.91k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
6.91k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
6.91k
  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.91k
  do_fancy = cinfo->do_fancy_upsampling && cinfo->_min_DCT_scaled_size > 1;
479
480
  /* Verify we can handle the sampling factors, select per-component methods,
481
   * and create storage as needed.
482
   */
483
22.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
15.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 pixels.
487
     */
488
15.3k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
15.3k
                 cinfo->_min_DCT_scaled_size;
490
15.3k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
15.3k
                 cinfo->_min_DCT_scaled_size;
492
15.3k
    h_out_group = cinfo->max_h_samp_factor;
493
15.3k
    v_out_group = cinfo->max_v_samp_factor;
494
15.3k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
15.3k
    need_buffer = TRUE;
496
15.3k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
1.08k
      upsample->methods[ci] = noop_upsample;
499
1.08k
      need_buffer = FALSE;
500
14.2k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
6.51k
      upsample->methods[ci] = fullsize_upsample;
503
6.51k
      need_buffer = FALSE;
504
7.72k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
1.97k
      if (do_fancy && compptr->downsampled_width > 2) {
507
#ifdef WITH_SIMD
508
58
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
58
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
0
        else
511
0
#endif
512
0
          upsample->methods[ci] = h2v1_fancy_upsample;
513
1.86k
      } else {
514
#ifdef WITH_SIMD
515
1.02k
        if (jsimd_set_h2v1_upsample(cinfo))
516
1.02k
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
0
        else
518
0
#endif
519
0
          upsample->methods[ci] = h2v1_upsample;
520
1.86k
      }
521
5.74k
    } else if (h_in_group == h_out_group &&
522
2.82k
               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
267
        upsample->methods[ci] = h1v2_fancy_upsample;
530
267
      upsample->pub.need_context_rows = TRUE;
531
5.47k
    } else if (h_in_group * 2 == h_out_group &&
532
2.01k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
725
      if (do_fancy && compptr->downsampled_width > 2) {
535
#ifdef WITH_SIMD
536
24
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
24
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
0
        else
539
0
#endif
540
0
          upsample->methods[ci] = h2v2_fancy_upsample;
541
59
        upsample->pub.need_context_rows = TRUE;
542
666
      } else {
543
#ifdef WITH_SIMD
544
259
        if (jsimd_set_h2v2_upsample(cinfo))
545
259
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
0
        else
547
0
#endif
548
0
          upsample->methods[ci] = h2v2_upsample;
549
666
      }
550
4.75k
    } else if ((h_out_group % h_in_group) == 0 &&
551
4.73k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
#if defined(WITH_SIMD) && SIMD_ARCHITECTURE == MIPS
554
      if (jsimd_set_int_upsample(cinfo))
555
        upsample->methods[ci] = jsimd_int_upsample;
556
      else
557
#endif
558
4.71k
        upsample->methods[ci] = int_upsample;
559
4.71k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
560
4.71k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
561
4.71k
    } else
562
35
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
563
15.3k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
564
7.68k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
565
7.68k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
566
7.68k
         (JDIMENSION)jround_up((long)cinfo->output_width,
567
7.68k
                               (long)cinfo->max_h_samp_factor),
568
7.68k
         (JDIMENSION)cinfo->max_v_samp_factor);
569
7.68k
    }
570
15.3k
  }
571
6.91k
}
jinit_upsampler
Line
Count
Source
438
3.50k
{
439
3.50k
  my_upsample_ptr upsample;
440
3.50k
  int ci;
441
3.50k
  jpeg_component_info *compptr;
442
3.50k
  boolean need_buffer, do_fancy;
443
3.50k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
3.50k
#ifdef D_LOSSLESS_SUPPORTED
446
3.50k
  if (cinfo->master->lossless) {
447
447
#if BITS_IN_JSAMPLE == 8
448
447
    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
447
  } else
455
3.06k
#endif
456
3.06k
  {
457
3.06k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
3.06k
  }
460
461
3.50k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
3.50k
    upsample = (my_upsample_ptr)
463
3.50k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
3.50k
                                  sizeof(my_upsampler));
465
3.50k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
3.50k
    upsample->pub.start_pass = start_pass_upsample;
467
3.50k
    upsample->pub._upsample = sep_upsample;
468
3.50k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
3.50k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
3.50k
  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
3.50k
  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
11.6k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
8.14k
       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 pixels.
487
     */
488
8.14k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
8.14k
                 cinfo->_min_DCT_scaled_size;
490
8.14k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
8.14k
                 cinfo->_min_DCT_scaled_size;
492
8.14k
    h_out_group = cinfo->max_h_samp_factor;
493
8.14k
    v_out_group = cinfo->max_v_samp_factor;
494
8.14k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
8.14k
    need_buffer = TRUE;
496
8.14k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
680
      upsample->methods[ci] = noop_upsample;
499
680
      need_buffer = FALSE;
500
7.46k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
3.47k
      upsample->methods[ci] = fullsize_upsample;
503
3.47k
      need_buffer = FALSE;
504
3.99k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
1.08k
      if (do_fancy && compptr->downsampled_width > 2) {
507
58
#ifdef WITH_SIMD
508
58
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
58
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
0
        else
511
0
#endif
512
0
          upsample->methods[ci] = h2v1_fancy_upsample;
513
1.02k
      } else {
514
1.02k
#ifdef WITH_SIMD
515
1.02k
        if (jsimd_set_h2v1_upsample(cinfo))
516
1.02k
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
0
        else
518
0
#endif
519
0
          upsample->methods[ci] = h2v1_upsample;
520
1.02k
      }
521
2.90k
    } else if (h_in_group == h_out_group &&
522
1.49k
               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
94
        upsample->methods[ci] = h1v2_fancy_upsample;
530
94
      upsample->pub.need_context_rows = TRUE;
531
2.81k
    } else if (h_in_group * 2 == h_out_group &&
532
935
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
283
      if (do_fancy && compptr->downsampled_width > 2) {
535
24
#ifdef WITH_SIMD
536
24
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
24
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
0
        else
539
0
#endif
540
0
          upsample->methods[ci] = h2v2_fancy_upsample;
541
24
        upsample->pub.need_context_rows = TRUE;
542
259
      } else {
543
259
#ifdef WITH_SIMD
544
259
        if (jsimd_set_h2v2_upsample(cinfo))
545
259
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
0
        else
547
0
#endif
548
0
          upsample->methods[ci] = h2v2_upsample;
549
259
      }
550
2.53k
    } else if ((h_out_group % h_in_group) == 0 &&
551
2.52k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
#if defined(WITH_SIMD) && SIMD_ARCHITECTURE == MIPS
554
      if (jsimd_set_int_upsample(cinfo))
555
        upsample->methods[ci] = jsimd_int_upsample;
556
      else
557
#endif
558
2.51k
        upsample->methods[ci] = int_upsample;
559
2.51k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
560
2.51k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
561
2.51k
    } else
562
15
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
563
8.14k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
564
3.97k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
565
3.97k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
566
3.97k
         (JDIMENSION)jround_up((long)cinfo->output_width,
567
3.97k
                               (long)cinfo->max_h_samp_factor),
568
3.97k
         (JDIMENSION)cinfo->max_v_samp_factor);
569
3.97k
    }
570
8.14k
  }
571
3.50k
}
j12init_upsampler
Line
Count
Source
438
2.88k
{
439
2.88k
  my_upsample_ptr upsample;
440
2.88k
  int ci;
441
2.88k
  jpeg_component_info *compptr;
442
2.88k
  boolean need_buffer, do_fancy;
443
2.88k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
2.88k
#ifdef D_LOSSLESS_SUPPORTED
446
2.88k
  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
484
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
484
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
484
  } else
455
2.40k
#endif
456
2.40k
  {
457
2.40k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
2.40k
  }
460
461
2.88k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
2.88k
    upsample = (my_upsample_ptr)
463
2.88k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
2.88k
                                  sizeof(my_upsampler));
465
2.88k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
2.88k
    upsample->pub.start_pass = start_pass_upsample;
467
2.88k
    upsample->pub._upsample = sep_upsample;
468
2.88k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
2.88k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
2.88k
  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
2.88k
  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
8.49k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
5.61k
       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 pixels.
487
     */
488
5.61k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
5.61k
                 cinfo->_min_DCT_scaled_size;
490
5.61k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
5.61k
                 cinfo->_min_DCT_scaled_size;
492
5.61k
    h_out_group = cinfo->max_h_samp_factor;
493
5.61k
    v_out_group = cinfo->max_v_samp_factor;
494
5.61k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
5.61k
    need_buffer = TRUE;
496
5.61k
    if (!compptr->component_needed) {
497
      /* Don't bother to upsample an uninteresting component. */
498
406
      upsample->methods[ci] = noop_upsample;
499
406
      need_buffer = FALSE;
500
5.20k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
2.69k
      upsample->methods[ci] = fullsize_upsample;
503
2.69k
      need_buffer = FALSE;
504
2.69k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
575
      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
57
          upsample->methods[ci] = h2v1_fancy_upsample;
513
518
      } else {
514
#ifdef WITH_SIMD
515
        if (jsimd_set_h2v1_upsample(cinfo))
516
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
        else
518
#endif
519
518
          upsample->methods[ci] = h2v1_upsample;
520
518
      }
521
1.93k
    } else if (h_in_group == h_out_group &&
522
937
               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
173
        upsample->methods[ci] = h1v2_fancy_upsample;
530
173
      upsample->pub.need_context_rows = TRUE;
531
1.76k
    } else if (h_in_group * 2 == h_out_group &&
532
719
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
330
      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
35
          upsample->methods[ci] = h2v2_fancy_upsample;
541
35
        upsample->pub.need_context_rows = TRUE;
542
295
      } else {
543
#ifdef WITH_SIMD
544
        if (jsimd_set_h2v2_upsample(cinfo))
545
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
        else
547
#endif
548
295
          upsample->methods[ci] = h2v2_upsample;
549
295
      }
550
1.43k
    } else if ((h_out_group % h_in_group) == 0 &&
551
1.42k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
#if defined(WITH_SIMD) && SIMD_ARCHITECTURE == MIPS
554
      if (jsimd_set_int_upsample(cinfo))
555
        upsample->methods[ci] = jsimd_int_upsample;
556
      else
557
#endif
558
1.42k
        upsample->methods[ci] = int_upsample;
559
1.42k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
560
1.42k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
561
1.42k
    } else
562
11
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
563
5.61k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
564
2.50k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
565
2.50k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
566
2.50k
         (JDIMENSION)jround_up((long)cinfo->output_width,
567
2.50k
                               (long)cinfo->max_h_samp_factor),
568
2.50k
         (JDIMENSION)cinfo->max_v_samp_factor);
569
2.50k
    }
570
5.61k
  }
571
2.88k
}
j16init_upsampler
Line
Count
Source
438
525
{
439
525
  my_upsample_ptr upsample;
440
525
  int ci;
441
525
  jpeg_component_info *compptr;
442
525
  boolean need_buffer, do_fancy;
443
525
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
525
#ifdef D_LOSSLESS_SUPPORTED
446
525
  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
525
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
525
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
525
  } 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
525
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
525
    upsample = (my_upsample_ptr)
463
525
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
525
                                  sizeof(my_upsampler));
465
525
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
525
    upsample->pub.start_pass = start_pass_upsample;
467
525
    upsample->pub._upsample = sep_upsample;
468
525
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
525
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
525
  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
525
  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
2.08k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
1.56k
       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 pixels.
487
     */
488
1.56k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
1.56k
                 cinfo->_min_DCT_scaled_size;
490
1.56k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
1.56k
                 cinfo->_min_DCT_scaled_size;
492
1.56k
    h_out_group = cinfo->max_h_samp_factor;
493
1.56k
    v_out_group = cinfo->max_v_samp_factor;
494
1.56k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
1.56k
    need_buffer = TRUE;
496
1.56k
    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
1.56k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
345
      upsample->methods[ci] = fullsize_upsample;
503
345
      need_buffer = FALSE;
504
1.21k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
316
      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
316
      } else {
514
#ifdef WITH_SIMD
515
        if (jsimd_set_h2v1_upsample(cinfo))
516
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
        else
518
#endif
519
316
          upsample->methods[ci] = h2v1_upsample;
520
316
      }
521
901
    } else if (h_in_group == h_out_group &&
522
398
               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
901
    } else if (h_in_group * 2 == h_out_group &&
532
363
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
112
      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
112
      } else {
543
#ifdef WITH_SIMD
544
        if (jsimd_set_h2v2_upsample(cinfo))
545
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
        else
547
#endif
548
112
          upsample->methods[ci] = h2v2_upsample;
549
112
      }
550
789
    } else if ((h_out_group % h_in_group) == 0 &&
551
785
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
#if defined(WITH_SIMD) && SIMD_ARCHITECTURE == MIPS
554
      if (jsimd_set_int_upsample(cinfo))
555
        upsample->methods[ci] = jsimd_int_upsample;
556
      else
557
#endif
558
780
        upsample->methods[ci] = int_upsample;
559
780
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
560
780
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
561
780
    } else
562
9
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
563
1.56k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
564
1.20k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
565
1.20k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
566
1.20k
         (JDIMENSION)jround_up((long)cinfo->output_width,
567
1.20k
                               (long)cinfo->max_h_samp_factor),
568
1.20k
         (JDIMENSION)cinfo->max_v_samp_factor);
569
1.20k
    }
570
1.56k
  }
571
525
}
572
573
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */