Coverage Report

Created: 2026-09-13 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo/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
136k
{
48
136k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
136k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
136k
  upsample->rows_to_go = cinfo->output_height;
54
136k
}
jdsample-8.c:start_pass_upsample
Line
Count
Source
47
107k
{
48
107k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
107k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
107k
  upsample->rows_to_go = cinfo->output_height;
54
107k
}
jdsample-12.c:start_pass_upsample
Line
Count
Source
47
23.5k
{
48
23.5k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
23.5k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
23.5k
  upsample->rows_to_go = cinfo->output_height;
54
23.5k
}
jdsample-16.c:start_pass_upsample
Line
Count
Source
47
5.89k
{
48
5.89k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
49
50
  /* Mark the conversion buffer empty */
51
5.89k
  upsample->next_row_out = cinfo->max_v_samp_factor;
52
  /* Initialize total-height counter for detecting bottom of image */
53
5.89k
  upsample->rows_to_go = cinfo->output_height;
54
5.89k
}
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
30.8M
{
71
30.8M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
30.8M
  int ci;
73
30.8M
  jpeg_component_info *compptr;
74
30.8M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
30.8M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
49.9M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
31.2M
         ci++, compptr++) {
80
      /* Invoke per-component upsample method.  Notice we pass a POINTER
81
       * to color_buf[ci], so that fullsize_upsample can change it.
82
       */
83
#ifdef WITH_PROFILE
84
      cinfo->master->start = getTime();
85
#endif
86
31.2M
      (*upsample->methods[ci]) (cinfo, compptr,
87
31.2M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
31.2M
        upsample->color_buf + ci);
89
#ifdef WITH_PROFILE
90
      cinfo->master->upsample_elapsed += getTime() - cinfo->master->start;
91
      cinfo->master->upsample_msamples +=
92
        (double)cinfo->output_width * cinfo->max_v_samp_factor / 1000000.;
93
#endif
94
31.2M
    }
95
18.6M
    upsample->next_row_out = 0;
96
18.6M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
30.8M
  num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out);
102
  /* Not more than the distance to the end of the image.  Need this test
103
   * in case the image height is not a multiple of max_v_samp_factor:
104
   */
105
30.8M
  if (num_rows > upsample->rows_to_go)
106
38.9k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
30.8M
  out_rows_avail -= *out_row_ctr;
109
30.8M
  if (num_rows > out_rows_avail)
110
12.1M
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
30.8M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
30.8M
                                      (JDIMENSION)upsample->next_row_out,
117
30.8M
                                      output_buf + *out_row_ctr,
118
30.8M
                                      (int)num_rows);
119
#ifdef WITH_PROFILE
120
  cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
121
  cinfo->master->cconvert_mpixels +=
122
    (double)cinfo->output_width * num_rows / 1000000.;
123
#endif
124
125
  /* Adjust counts */
126
30.8M
  *out_row_ctr += num_rows;
127
30.8M
  upsample->rows_to_go -= num_rows;
128
30.8M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
30.8M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
18.6M
    (*in_row_group_ctr)++;
132
30.8M
}
jdsample-8.c:sep_upsample
Line
Count
Source
70
21.5M
{
71
21.5M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
21.5M
  int ci;
73
21.5M
  jpeg_component_info *compptr;
74
21.5M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
21.5M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
35.2M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
21.7M
         ci++, compptr++) {
80
      /* Invoke per-component upsample method.  Notice we pass a POINTER
81
       * to color_buf[ci], so that fullsize_upsample can change it.
82
       */
83
#ifdef WITH_PROFILE
84
      cinfo->master->start = getTime();
85
#endif
86
21.7M
      (*upsample->methods[ci]) (cinfo, compptr,
87
21.7M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
21.7M
        upsample->color_buf + ci);
89
#ifdef WITH_PROFILE
90
      cinfo->master->upsample_elapsed += getTime() - cinfo->master->start;
91
      cinfo->master->upsample_msamples +=
92
        (double)cinfo->output_width * cinfo->max_v_samp_factor / 1000000.;
93
#endif
94
21.7M
    }
95
13.5M
    upsample->next_row_out = 0;
96
13.5M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
21.5M
  num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out);
102
  /* Not more than the distance to the end of the image.  Need this test
103
   * in case the image height is not a multiple of max_v_samp_factor:
104
   */
105
21.5M
  if (num_rows > upsample->rows_to_go)
106
23.7k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
21.5M
  out_rows_avail -= *out_row_ctr;
109
21.5M
  if (num_rows > out_rows_avail)
110
8.00M
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
21.5M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
21.5M
                                      (JDIMENSION)upsample->next_row_out,
117
21.5M
                                      output_buf + *out_row_ctr,
118
21.5M
                                      (int)num_rows);
119
#ifdef WITH_PROFILE
120
  cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
121
  cinfo->master->cconvert_mpixels +=
122
    (double)cinfo->output_width * num_rows / 1000000.;
123
#endif
124
125
  /* Adjust counts */
126
21.5M
  *out_row_ctr += num_rows;
127
21.5M
  upsample->rows_to_go -= num_rows;
128
21.5M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
21.5M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
13.5M
    (*in_row_group_ctr)++;
132
21.5M
}
jdsample-12.c:sep_upsample
Line
Count
Source
70
8.60M
{
71
8.60M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
8.60M
  int ci;
73
8.60M
  jpeg_component_info *compptr;
74
8.60M
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
8.60M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
13.6M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
8.80M
         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
8.80M
      (*upsample->methods[ci]) (cinfo, compptr,
87
8.80M
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
8.80M
        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
8.80M
    }
95
4.81M
    upsample->next_row_out = 0;
96
4.81M
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
8.60M
  num_rows = (JDIMENSION)(cinfo->max_v_samp_factor - upsample->next_row_out);
102
  /* Not more than the distance to the end of the image.  Need this test
103
   * in case the image height is not a multiple of max_v_samp_factor:
104
   */
105
8.60M
  if (num_rows > upsample->rows_to_go)
106
13.1k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
8.60M
  out_rows_avail -= *out_row_ctr;
109
8.60M
  if (num_rows > out_rows_avail)
110
3.79M
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
8.60M
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
8.60M
                                      (JDIMENSION)upsample->next_row_out,
117
8.60M
                                      output_buf + *out_row_ctr,
118
8.60M
                                      (int)num_rows);
119
#ifdef WITH_PROFILE
120
  cinfo->master->cconvert_elapsed += getTime() - cinfo->master->start;
121
  cinfo->master->cconvert_mpixels +=
122
    (double)cinfo->output_width * num_rows / 1000000.;
123
#endif
124
125
  /* Adjust counts */
126
8.60M
  *out_row_ctr += num_rows;
127
8.60M
  upsample->rows_to_go -= num_rows;
128
8.60M
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
8.60M
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
4.80M
    (*in_row_group_ctr)++;
132
8.60M
}
jdsample-16.c:sep_upsample
Line
Count
Source
70
736k
{
71
736k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
72
736k
  int ci;
73
736k
  jpeg_component_info *compptr;
74
736k
  JDIMENSION num_rows;
75
76
  /* Fill the conversion buffer, if it's empty */
77
736k
  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
78
1.08M
    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
79
727k
         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
727k
      (*upsample->methods[ci]) (cinfo, compptr,
87
727k
        input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
88
727k
        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
727k
    }
95
353k
    upsample->next_row_out = 0;
96
353k
  }
97
98
  /* Color-convert and emit rows */
99
100
  /* How many we have in the buffer: */
101
736k
  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
736k
  if (num_rows > upsample->rows_to_go)
106
2.11k
    num_rows = upsample->rows_to_go;
107
  /* And not more than what the client can accept: */
108
736k
  out_rows_avail -= *out_row_ctr;
109
736k
  if (num_rows > out_rows_avail)
110
382k
    num_rows = out_rows_avail;
111
112
#ifdef WITH_PROFILE
113
  cinfo->master->start = getTime();
114
#endif
115
736k
  (*cinfo->cconvert->_color_convert) (cinfo, upsample->color_buf,
116
736k
                                      (JDIMENSION)upsample->next_row_out,
117
736k
                                      output_buf + *out_row_ctr,
118
736k
                                      (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
736k
  *out_row_ctr += num_rows;
127
736k
  upsample->rows_to_go -= num_rows;
128
736k
  upsample->next_row_out += num_rows;
129
  /* When the buffer is emptied, declare this input row group consumed */
130
736k
  if (upsample->next_row_out >= cinfo->max_v_samp_factor)
131
352k
    (*in_row_group_ctr)++;
132
736k
}
133
134
135
/*
136
 * These are the routines invoked by sep_upsample to upsample values of a
137
 * single component.  One row group is processed per call.
138
 */
139
140
141
/*
142
 * For full-size components, we just make color_buf[ci] point at the
143
 * input buffer, and thus avoid copying any data.  Note that this is
144
 * safe only because sep_upsample doesn't declare the input row group
145
 * "consumed" until we are done color converting and emitting it.
146
 */
147
148
METHODDEF(void)
149
fullsize_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
150
                  _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
151
18.8M
{
152
18.8M
  *output_data_ptr = input_data;
153
18.8M
}
jdsample-8.c:fullsize_upsample
Line
Count
Source
151
14.1M
{
152
14.1M
  *output_data_ptr = input_data;
153
14.1M
}
jdsample-12.c:fullsize_upsample
Line
Count
Source
151
4.40M
{
152
4.40M
  *output_data_ptr = input_data;
153
4.40M
}
jdsample-16.c:fullsize_upsample
Line
Count
Source
151
285k
{
152
285k
  *output_data_ptr = input_data;
153
285k
}
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
0
{
165
0
  *output_data_ptr = NULL;      /* safety check */
166
0
}
Unexecuted instantiation: jdsample-8.c:noop_upsample
Unexecuted instantiation: jdsample-12.c:noop_upsample
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
4.79M
{
184
4.79M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
4.79M
  _JSAMPARRAY output_data = *output_data_ptr;
186
4.79M
  register _JSAMPROW inptr, outptr;
187
4.79M
  register _JSAMPLE invalue;
188
4.79M
  register int h;
189
4.79M
  _JSAMPROW outend;
190
4.79M
  int h_expand, v_expand;
191
4.79M
  int inrow, outrow;
192
193
4.79M
  h_expand = upsample->h_expand[compptr->component_index];
194
4.79M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
4.79M
  inrow = outrow = 0;
197
11.7M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
6.90M
    inptr = input_data[inrow];
200
6.90M
    outptr = output_data[outrow];
201
6.90M
    outend = outptr + cinfo->output_width;
202
1.12G
    while (outptr < outend) {
203
1.12G
      invalue = *inptr++;
204
3.48G
      for (h = h_expand; h > 0; h--) {
205
2.36G
        *outptr++ = invalue;
206
2.36G
      }
207
1.12G
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
6.90M
    if (v_expand > 1) {
210
2.95M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
2.95M
                         v_expand - 1, cinfo->output_width);
212
2.95M
    }
213
6.90M
    inrow++;
214
6.90M
    outrow += v_expand;
215
6.90M
  }
216
4.79M
}
jdsample-8.c:int_upsample
Line
Count
Source
183
2.79M
{
184
2.79M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
2.79M
  _JSAMPARRAY output_data = *output_data_ptr;
186
2.79M
  register _JSAMPROW inptr, outptr;
187
2.79M
  register _JSAMPLE invalue;
188
2.79M
  register int h;
189
2.79M
  _JSAMPROW outend;
190
2.79M
  int h_expand, v_expand;
191
2.79M
  int inrow, outrow;
192
193
2.79M
  h_expand = upsample->h_expand[compptr->component_index];
194
2.79M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
2.79M
  inrow = outrow = 0;
197
6.79M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
4.00M
    inptr = input_data[inrow];
200
4.00M
    outptr = output_data[outrow];
201
4.00M
    outend = outptr + cinfo->output_width;
202
692M
    while (outptr < outend) {
203
688M
      invalue = *inptr++;
204
2.20G
      for (h = h_expand; h > 0; h--) {
205
1.51G
        *outptr++ = invalue;
206
1.51G
      }
207
688M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
4.00M
    if (v_expand > 1) {
210
1.81M
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
1.81M
                         v_expand - 1, cinfo->output_width);
212
1.81M
    }
213
4.00M
    inrow++;
214
4.00M
    outrow += v_expand;
215
4.00M
  }
216
2.79M
}
jdsample-12.c:int_upsample
Line
Count
Source
183
1.76M
{
184
1.76M
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
1.76M
  _JSAMPARRAY output_data = *output_data_ptr;
186
1.76M
  register _JSAMPROW inptr, outptr;
187
1.76M
  register _JSAMPLE invalue;
188
1.76M
  register int h;
189
1.76M
  _JSAMPROW outend;
190
1.76M
  int h_expand, v_expand;
191
1.76M
  int inrow, outrow;
192
193
1.76M
  h_expand = upsample->h_expand[compptr->component_index];
194
1.76M
  v_expand = upsample->v_expand[compptr->component_index];
195
196
1.76M
  inrow = outrow = 0;
197
4.35M
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
2.58M
    inptr = input_data[inrow];
200
2.58M
    outptr = output_data[outrow];
201
2.58M
    outend = outptr + cinfo->output_width;
202
351M
    while (outptr < outend) {
203
349M
      invalue = *inptr++;
204
1.08G
      for (h = h_expand; h > 0; h--) {
205
736M
        *outptr++ = invalue;
206
736M
      }
207
349M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
2.58M
    if (v_expand > 1) {
210
933k
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
933k
                         v_expand - 1, cinfo->output_width);
212
933k
    }
213
2.58M
    inrow++;
214
2.58M
    outrow += v_expand;
215
2.58M
  }
216
1.76M
}
jdsample-16.c:int_upsample
Line
Count
Source
183
236k
{
184
236k
  my_upsample_ptr upsample = (my_upsample_ptr)cinfo->upsample;
185
236k
  _JSAMPARRAY output_data = *output_data_ptr;
186
236k
  register _JSAMPROW inptr, outptr;
187
236k
  register _JSAMPLE invalue;
188
236k
  register int h;
189
236k
  _JSAMPROW outend;
190
236k
  int h_expand, v_expand;
191
236k
  int inrow, outrow;
192
193
236k
  h_expand = upsample->h_expand[compptr->component_index];
194
236k
  v_expand = upsample->v_expand[compptr->component_index];
195
196
236k
  inrow = outrow = 0;
197
554k
  while (outrow < cinfo->max_v_samp_factor) {
198
    /* Generate one output row with proper horizontal expansion */
199
317k
    inptr = input_data[inrow];
200
317k
    outptr = output_data[outrow];
201
317k
    outend = outptr + cinfo->output_width;
202
84.7M
    while (outptr < outend) {
203
84.4M
      invalue = *inptr++;
204
198M
      for (h = h_expand; h > 0; h--) {
205
114M
        *outptr++ = invalue;
206
114M
      }
207
84.4M
    }
208
    /* Generate any additional output rows by duplicating the first one */
209
317k
    if (v_expand > 1) {
210
210k
      _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1,
211
210k
                         v_expand - 1, cinfo->output_width);
212
210k
    }
213
317k
    inrow++;
214
317k
    outrow += v_expand;
215
317k
  }
216
236k
}
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
487k
{
228
487k
  _JSAMPARRAY output_data = *output_data_ptr;
229
487k
  register _JSAMPROW inptr, outptr;
230
487k
  register _JSAMPLE invalue;
231
487k
  _JSAMPROW outend;
232
487k
  int inrow;
233
234
1.60M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
1.11M
    inptr = input_data[inrow];
236
1.11M
    outptr = output_data[inrow];
237
1.11M
    outend = outptr + cinfo->output_width;
238
249M
    while (outptr < outend) {
239
248M
      invalue = *inptr++;
240
248M
      *outptr++ = invalue;
241
248M
      *outptr++ = invalue;
242
248M
    }
243
1.11M
  }
244
487k
}
jdsample-8.c:h2v1_upsample
Line
Count
Source
227
210k
{
228
210k
  _JSAMPARRAY output_data = *output_data_ptr;
229
210k
  register _JSAMPROW inptr, outptr;
230
210k
  register _JSAMPLE invalue;
231
210k
  _JSAMPROW outend;
232
210k
  int inrow;
233
234
681k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
471k
    inptr = input_data[inrow];
236
471k
    outptr = output_data[inrow];
237
471k
    outend = outptr + cinfo->output_width;
238
84.5M
    while (outptr < outend) {
239
84.0M
      invalue = *inptr++;
240
84.0M
      *outptr++ = invalue;
241
84.0M
      *outptr++ = invalue;
242
84.0M
    }
243
471k
  }
244
210k
}
jdsample-12.c:h2v1_upsample
Line
Count
Source
227
153k
{
228
153k
  _JSAMPARRAY output_data = *output_data_ptr;
229
153k
  register _JSAMPROW inptr, outptr;
230
153k
  register _JSAMPLE invalue;
231
153k
  _JSAMPROW outend;
232
153k
  int inrow;
233
234
502k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
349k
    inptr = input_data[inrow];
236
349k
    outptr = output_data[inrow];
237
349k
    outend = outptr + cinfo->output_width;
238
80.4M
    while (outptr < outend) {
239
80.1M
      invalue = *inptr++;
240
80.1M
      *outptr++ = invalue;
241
80.1M
      *outptr++ = invalue;
242
80.1M
    }
243
349k
  }
244
153k
}
jdsample-16.c:h2v1_upsample
Line
Count
Source
227
123k
{
228
123k
  _JSAMPARRAY output_data = *output_data_ptr;
229
123k
  register _JSAMPROW inptr, outptr;
230
123k
  register _JSAMPLE invalue;
231
123k
  _JSAMPROW outend;
232
123k
  int inrow;
233
234
421k
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
235
297k
    inptr = input_data[inrow];
236
297k
    outptr = output_data[inrow];
237
297k
    outend = outptr + cinfo->output_width;
238
84.2M
    while (outptr < outend) {
239
83.9M
      invalue = *inptr++;
240
83.9M
      *outptr++ = invalue;
241
83.9M
      *outptr++ = invalue;
242
83.9M
    }
243
297k
  }
244
123k
}
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
339k
{
256
339k
  _JSAMPARRAY output_data = *output_data_ptr;
257
339k
  register _JSAMPROW inptr, outptr;
258
339k
  register _JSAMPLE invalue;
259
339k
  _JSAMPROW outend;
260
339k
  int inrow, outrow;
261
262
339k
  inrow = outrow = 0;
263
807k
  while (outrow < cinfo->max_v_samp_factor) {
264
468k
    inptr = input_data[inrow];
265
468k
    outptr = output_data[outrow];
266
468k
    outend = outptr + cinfo->output_width;
267
121M
    while (outptr < outend) {
268
121M
      invalue = *inptr++;
269
121M
      *outptr++ = invalue;
270
121M
      *outptr++ = invalue;
271
121M
    }
272
468k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
468k
                       cinfo->output_width);
274
468k
    inrow++;
275
468k
    outrow += 2;
276
468k
  }
277
339k
}
jdsample-8.c:h2v2_upsample
Line
Count
Source
255
140k
{
256
140k
  _JSAMPARRAY output_data = *output_data_ptr;
257
140k
  register _JSAMPROW inptr, outptr;
258
140k
  register _JSAMPLE invalue;
259
140k
  _JSAMPROW outend;
260
140k
  int inrow, outrow;
261
262
140k
  inrow = outrow = 0;
263
330k
  while (outrow < cinfo->max_v_samp_factor) {
264
190k
    inptr = input_data[inrow];
265
190k
    outptr = output_data[outrow];
266
190k
    outend = outptr + cinfo->output_width;
267
39.9M
    while (outptr < outend) {
268
39.7M
      invalue = *inptr++;
269
39.7M
      *outptr++ = invalue;
270
39.7M
      *outptr++ = invalue;
271
39.7M
    }
272
190k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
190k
                       cinfo->output_width);
274
190k
    inrow++;
275
190k
    outrow += 2;
276
190k
  }
277
140k
}
jdsample-12.c:h2v2_upsample
Line
Count
Source
255
118k
{
256
118k
  _JSAMPARRAY output_data = *output_data_ptr;
257
118k
  register _JSAMPROW inptr, outptr;
258
118k
  register _JSAMPLE invalue;
259
118k
  _JSAMPROW outend;
260
118k
  int inrow, outrow;
261
262
118k
  inrow = outrow = 0;
263
275k
  while (outrow < cinfo->max_v_samp_factor) {
264
157k
    inptr = input_data[inrow];
265
157k
    outptr = output_data[outrow];
266
157k
    outend = outptr + cinfo->output_width;
267
45.2M
    while (outptr < outend) {
268
45.0M
      invalue = *inptr++;
269
45.0M
      *outptr++ = invalue;
270
45.0M
      *outptr++ = invalue;
271
45.0M
    }
272
157k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
157k
                       cinfo->output_width);
274
157k
    inrow++;
275
157k
    outrow += 2;
276
157k
  }
277
118k
}
jdsample-16.c:h2v2_upsample
Line
Count
Source
255
80.7k
{
256
80.7k
  _JSAMPARRAY output_data = *output_data_ptr;
257
80.7k
  register _JSAMPROW inptr, outptr;
258
80.7k
  register _JSAMPLE invalue;
259
80.7k
  _JSAMPROW outend;
260
80.7k
  int inrow, outrow;
261
262
80.7k
  inrow = outrow = 0;
263
200k
  while (outrow < cinfo->max_v_samp_factor) {
264
120k
    inptr = input_data[inrow];
265
120k
    outptr = output_data[outrow];
266
120k
    outend = outptr + cinfo->output_width;
267
36.7M
    while (outptr < outend) {
268
36.6M
      invalue = *inptr++;
269
36.6M
      *outptr++ = invalue;
270
36.6M
      *outptr++ = invalue;
271
36.6M
    }
272
120k
    _jcopy_sample_rows(output_data, outrow, output_data, outrow + 1, 1,
273
120k
                       cinfo->output_width);
274
120k
    inrow++;
275
120k
    outrow += 2;
276
120k
  }
277
80.7k
}
278
279
280
/*
281
 * Fancy processing for the common case of 2:1 horizontal and 1:1 vertical.
282
 *
283
 * The upsampling algorithm is linear interpolation between component centers,
284
 * also known as a "triangle filter".  This is a good compromise between speed
285
 * and visual quality.  The centers of the output components are 1/4 and 3/4 of
286
 * the way between input component centers.
287
 *
288
 * A note about the "bias" calculations: when rounding fractional values to
289
 * integer, we do not want to always round 0.5 up to the next integer.
290
 * If we did that, we'd introduce a noticeable bias towards larger values.
291
 * Instead, this code is arranged so that 0.5 will be rounded up or down at
292
 * alternate pixel locations (a simple ordered dither pattern).
293
 */
294
295
METHODDEF(void)
296
h2v1_fancy_upsample(j_decompress_ptr cinfo, jpeg_component_info *compptr,
297
                    _JSAMPARRAY input_data, _JSAMPARRAY *output_data_ptr)
298
3.22M
{
299
3.22M
  _JSAMPARRAY output_data = *output_data_ptr;
300
3.22M
  register _JSAMPROW inptr, outptr;
301
3.22M
  register int invalue;
302
3.22M
  register JDIMENSION colctr;
303
3.22M
  int inrow;
304
305
8.69M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
5.47M
    inptr = input_data[inrow];
307
5.47M
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
5.47M
    invalue = *inptr++;
310
5.47M
    *outptr++ = (_JSAMPLE)invalue;
311
5.47M
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
1.80G
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer component + 1/4 * further component */
315
1.80G
      invalue = (*inptr++) * 3;
316
1.80G
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
1.80G
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
1.80G
    }
319
320
    /* Special case for last column */
321
5.47M
    invalue = *inptr;
322
5.47M
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
5.47M
    *outptr++ = (_JSAMPLE)invalue;
324
5.47M
  }
325
3.22M
}
jdsample-8.c:h2v1_fancy_upsample
Line
Count
Source
298
2.36M
{
299
2.36M
  _JSAMPARRAY output_data = *output_data_ptr;
300
2.36M
  register _JSAMPROW inptr, outptr;
301
2.36M
  register int invalue;
302
2.36M
  register JDIMENSION colctr;
303
2.36M
  int inrow;
304
305
6.23M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
3.87M
    inptr = input_data[inrow];
307
3.87M
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
3.87M
    invalue = *inptr++;
310
3.87M
    *outptr++ = (_JSAMPLE)invalue;
311
3.87M
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
1.37G
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer component + 1/4 * further component */
315
1.37G
      invalue = (*inptr++) * 3;
316
1.37G
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
1.37G
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
1.37G
    }
319
320
    /* Special case for last column */
321
3.87M
    invalue = *inptr;
322
3.87M
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
3.87M
    *outptr++ = (_JSAMPLE)invalue;
324
3.87M
  }
325
2.36M
}
jdsample-12.c:h2v1_fancy_upsample
Line
Count
Source
298
860k
{
299
860k
  _JSAMPARRAY output_data = *output_data_ptr;
300
860k
  register _JSAMPROW inptr, outptr;
301
860k
  register int invalue;
302
860k
  register JDIMENSION colctr;
303
860k
  int inrow;
304
305
2.45M
  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
306
1.59M
    inptr = input_data[inrow];
307
1.59M
    outptr = output_data[inrow];
308
    /* Special case for first column */
309
1.59M
    invalue = *inptr++;
310
1.59M
    *outptr++ = (_JSAMPLE)invalue;
311
1.59M
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[0] + 2) >> 2);
312
313
431M
    for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
314
      /* General case: 3/4 * nearer component + 1/4 * further component */
315
429M
      invalue = (*inptr++) * 3;
316
429M
      *outptr++ = (_JSAMPLE)((invalue + inptr[-2] + 1) >> 2);
317
429M
      *outptr++ = (_JSAMPLE)((invalue + inptr[0] + 2) >> 2);
318
429M
    }
319
320
    /* Special case for last column */
321
1.59M
    invalue = *inptr;
322
1.59M
    *outptr++ = (_JSAMPLE)((invalue * 3 + inptr[-1] + 1) >> 2);
323
1.59M
    *outptr++ = (_JSAMPLE)invalue;
324
1.59M
  }
325
860k
}
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
2.13M
{
339
2.13M
  _JSAMPARRAY output_data = *output_data_ptr;
340
2.13M
  _JSAMPROW inptr0, inptr1, outptr;
341
#if BITS_IN_JSAMPLE == 8
342
  int thiscolsum, bias;
343
#else
344
  JLONG thiscolsum, bias;
345
#endif
346
2.13M
  JDIMENSION colctr;
347
2.13M
  int inrow, outrow, v;
348
349
2.13M
  inrow = outrow = 0;
350
4.70M
  while (outrow < cinfo->max_v_samp_factor) {
351
7.71M
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
5.14M
      inptr0 = input_data[inrow];
354
5.14M
      if (v == 0) {             /* next nearest is row above */
355
2.57M
        inptr1 = input_data[inrow - 1];
356
2.57M
        bias = 1;
357
2.57M
      } else {                  /* next nearest is row below */
358
2.57M
        inptr1 = input_data[inrow + 1];
359
2.57M
        bias = 2;
360
2.57M
      }
361
5.14M
      outptr = output_data[outrow++];
362
363
2.90G
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
2.90G
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
2.90G
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
2.90G
      }
367
5.14M
    }
368
2.57M
    inrow++;
369
2.57M
  }
370
2.13M
}
jdsample-8.c:h1v2_fancy_upsample
Line
Count
Source
338
1.14M
{
339
1.14M
  _JSAMPARRAY output_data = *output_data_ptr;
340
1.14M
  _JSAMPROW inptr0, inptr1, outptr;
341
1.14M
#if BITS_IN_JSAMPLE == 8
342
1.14M
  int thiscolsum, bias;
343
#else
344
  JLONG thiscolsum, bias;
345
#endif
346
1.14M
  JDIMENSION colctr;
347
1.14M
  int inrow, outrow, v;
348
349
1.14M
  inrow = outrow = 0;
350
2.60M
  while (outrow < cinfo->max_v_samp_factor) {
351
4.37M
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
2.91M
      inptr0 = input_data[inrow];
354
2.91M
      if (v == 0) {             /* next nearest is row above */
355
1.45M
        inptr1 = input_data[inrow - 1];
356
1.45M
        bias = 1;
357
1.45M
      } else {                  /* next nearest is row below */
358
1.45M
        inptr1 = input_data[inrow + 1];
359
1.45M
        bias = 2;
360
1.45M
      }
361
2.91M
      outptr = output_data[outrow++];
362
363
2.16G
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
2.16G
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
2.16G
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
2.16G
      }
367
2.91M
    }
368
1.45M
    inrow++;
369
1.45M
  }
370
1.14M
}
jdsample-12.c:h1v2_fancy_upsample
Line
Count
Source
338
994k
{
339
994k
  _JSAMPARRAY output_data = *output_data_ptr;
340
994k
  _JSAMPROW inptr0, inptr1, outptr;
341
#if BITS_IN_JSAMPLE == 8
342
  int thiscolsum, bias;
343
#else
344
994k
  JLONG thiscolsum, bias;
345
994k
#endif
346
994k
  JDIMENSION colctr;
347
994k
  int inrow, outrow, v;
348
349
994k
  inrow = outrow = 0;
350
2.10M
  while (outrow < cinfo->max_v_samp_factor) {
351
3.33M
    for (v = 0; v < 2; v++) {
352
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
353
2.22M
      inptr0 = input_data[inrow];
354
2.22M
      if (v == 0) {             /* next nearest is row above */
355
1.11M
        inptr1 = input_data[inrow - 1];
356
1.11M
        bias = 1;
357
1.11M
      } else {                  /* next nearest is row below */
358
1.11M
        inptr1 = input_data[inrow + 1];
359
1.11M
        bias = 2;
360
1.11M
      }
361
2.22M
      outptr = output_data[outrow++];
362
363
738M
      for (colctr = 0; colctr < compptr->downsampled_width; colctr++) {
364
736M
        thiscolsum = (*inptr0++) * 3 + (*inptr1++);
365
736M
        *outptr++ = (_JSAMPLE)((thiscolsum + bias) >> 2);
366
736M
      }
367
2.22M
    }
368
1.11M
    inrow++;
369
1.11M
  }
370
994k
}
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
1.45M
{
385
1.45M
  _JSAMPARRAY output_data = *output_data_ptr;
386
1.45M
  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
1.45M
  register JDIMENSION colctr;
393
1.45M
  int inrow, outrow, v;
394
395
1.45M
  inrow = outrow = 0;
396
3.15M
  while (outrow < cinfo->max_v_samp_factor) {
397
5.11M
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
3.41M
      inptr0 = input_data[inrow];
400
3.41M
      if (v == 0)               /* next nearest is row above */
401
1.70M
        inptr1 = input_data[inrow - 1];
402
1.70M
      else                      /* next nearest is row below */
403
1.70M
        inptr1 = input_data[inrow + 1];
404
3.41M
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
3.41M
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
3.41M
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
3.41M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
3.41M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
3.41M
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
550M
      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
547M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
547M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
547M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
547M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
547M
      }
422
423
      /* Special case for last column */
424
3.41M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
3.41M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
3.41M
    }
427
1.70M
    inrow++;
428
1.70M
  }
429
1.45M
}
jdsample-8.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
944k
#if BITS_IN_JSAMPLE == 8
388
944k
  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
2.08M
  while (outrow < cinfo->max_v_samp_factor) {
397
3.41M
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
2.27M
      inptr0 = input_data[inrow];
400
2.27M
      if (v == 0)               /* next nearest is row above */
401
1.13M
        inptr1 = input_data[inrow - 1];
402
1.13M
      else                      /* next nearest is row below */
403
1.13M
        inptr1 = input_data[inrow + 1];
404
2.27M
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
2.27M
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
2.27M
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
2.27M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
2.27M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
2.27M
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
375M
      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
373M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
373M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
373M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
373M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
373M
      }
422
423
      /* Special case for last column */
424
2.27M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
2.27M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
2.27M
    }
427
1.13M
    inrow++;
428
1.13M
  }
429
944k
}
jdsample-12.c:h2v2_fancy_upsample
Line
Count
Source
384
508k
{
385
508k
  _JSAMPARRAY output_data = *output_data_ptr;
386
508k
  register _JSAMPROW inptr0, inptr1, outptr;
387
#if BITS_IN_JSAMPLE == 8
388
  register int thiscolsum, lastcolsum, nextcolsum;
389
#else
390
508k
  register JLONG thiscolsum, lastcolsum, nextcolsum;
391
508k
#endif
392
508k
  register JDIMENSION colctr;
393
508k
  int inrow, outrow, v;
394
395
508k
  inrow = outrow = 0;
396
1.07M
  while (outrow < cinfo->max_v_samp_factor) {
397
1.70M
    for (v = 0; v < 2; v++) {
398
      /* inptr0 points to nearest input row, inptr1 points to next nearest */
399
1.13M
      inptr0 = input_data[inrow];
400
1.13M
      if (v == 0)               /* next nearest is row above */
401
567k
        inptr1 = input_data[inrow - 1];
402
567k
      else                      /* next nearest is row below */
403
567k
        inptr1 = input_data[inrow + 1];
404
1.13M
      outptr = output_data[outrow++];
405
406
      /* Special case for first column */
407
1.13M
      thiscolsum = (*inptr0++) * 3 + (*inptr1++);
408
1.13M
      nextcolsum = (*inptr0++) * 3 + (*inptr1++);
409
1.13M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 8) >> 4);
410
1.13M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
411
1.13M
      lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
412
413
175M
      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
174M
        nextcolsum = (*inptr0++) * 3 + (*inptr1++);
418
174M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
419
174M
        *outptr++ = (_JSAMPLE)((thiscolsum * 3 + nextcolsum + 7) >> 4);
420
174M
        lastcolsum = thiscolsum;  thiscolsum = nextcolsum;
421
174M
      }
422
423
      /* Special case for last column */
424
1.13M
      *outptr++ = (_JSAMPLE)((thiscolsum * 3 + lastcolsum + 8) >> 4);
425
1.13M
      *outptr++ = (_JSAMPLE)((thiscolsum * 4 + 7) >> 4);
426
1.13M
    }
427
567k
    inrow++;
428
567k
  }
429
508k
}
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
153k
{
439
153k
  my_upsample_ptr upsample;
440
153k
  int ci;
441
153k
  jpeg_component_info *compptr;
442
153k
  boolean need_buffer, do_fancy;
443
153k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
153k
#ifdef D_LOSSLESS_SUPPORTED
446
153k
  if (cinfo->master->lossless) {
447
#if BITS_IN_JSAMPLE == 8
448
16.6k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
449
#else
450
14.3k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
14.3k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
30.9k
  } else
455
122k
#endif
456
122k
  {
457
122k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
122k
  }
460
461
153k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
153k
    upsample = (my_upsample_ptr)
463
153k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
153k
                                  sizeof(my_upsampler));
465
153k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
153k
    upsample->pub.start_pass = start_pass_upsample;
467
153k
    upsample->pub._upsample = sep_upsample;
468
153k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
153k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
153k
  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
153k
  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
455k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
302k
       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
302k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
302k
                 cinfo->_min_DCT_scaled_size;
490
302k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
302k
                 cinfo->_min_DCT_scaled_size;
492
302k
    h_out_group = cinfo->max_h_samp_factor;
493
302k
    v_out_group = cinfo->max_v_samp_factor;
494
302k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
302k
    need_buffer = TRUE;
496
302k
    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
302k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
141k
      upsample->methods[ci] = fullsize_upsample;
503
141k
      need_buffer = FALSE;
504
160k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
29.5k
      if (do_fancy && compptr->downsampled_width > 2) {
507
#ifdef WITH_SIMD
508
8.96k
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
0
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
8.96k
        else
511
8.96k
#endif
512
8.96k
          upsample->methods[ci] = h2v1_fancy_upsample;
513
15.7k
      } else {
514
#ifdef WITH_SIMD
515
5.28k
        if (jsimd_set_h2v1_upsample(cinfo))
516
0
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
5.28k
        else
518
5.28k
#endif
519
5.28k
          upsample->methods[ci] = h2v1_upsample;
520
13.7k
      }
521
130k
    } else if (h_in_group == h_out_group &&
522
55.1k
               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
18.4k
        upsample->methods[ci] = h1v2_fancy_upsample;
530
18.4k
      upsample->pub.need_context_rows = TRUE;
531
112k
    } else if (h_in_group * 2 == h_out_group &&
532
36.3k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
21.7k
      if (do_fancy && compptr->downsampled_width > 2) {
535
#ifdef WITH_SIMD
536
6.66k
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
0
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
6.66k
        else
539
6.66k
#endif
540
6.66k
          upsample->methods[ci] = h2v2_fancy_upsample;
541
11.3k
        upsample->pub.need_context_rows = TRUE;
542
11.3k
      } else {
543
#ifdef WITH_SIMD
544
3.86k
        if (jsimd_set_h2v2_upsample(cinfo))
545
0
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
3.86k
        else
547
3.86k
#endif
548
3.86k
          upsample->methods[ci] = h2v2_upsample;
549
10.3k
      }
550
90.6k
    } else if ((h_out_group % h_in_group) == 0 &&
551
90.3k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
90.2k
      upsample->methods[ci] = int_upsample;
554
90.2k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
90.2k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
90.2k
    } else
557
466
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
302k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
159k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
159k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
159k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
159k
                               (long)cinfo->max_h_samp_factor),
563
159k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
159k
    }
565
302k
  }
566
153k
}
jinit_upsampler
Line
Count
Source
438
117k
{
439
117k
  my_upsample_ptr upsample;
440
117k
  int ci;
441
117k
  jpeg_component_info *compptr;
442
117k
  boolean need_buffer, do_fancy;
443
117k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
117k
#ifdef D_LOSSLESS_SUPPORTED
446
117k
  if (cinfo->master->lossless) {
447
16.6k
#if BITS_IN_JSAMPLE == 8
448
16.6k
    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
16.6k
  } else
455
100k
#endif
456
100k
  {
457
100k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
100k
  }
460
461
117k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
117k
    upsample = (my_upsample_ptr)
463
117k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
117k
                                  sizeof(my_upsampler));
465
117k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
117k
    upsample->pub.start_pass = start_pass_upsample;
467
117k
    upsample->pub._upsample = sep_upsample;
468
117k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
117k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
117k
  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
117k
  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
306k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
189k
       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
189k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
189k
                 cinfo->_min_DCT_scaled_size;
490
189k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
189k
                 cinfo->_min_DCT_scaled_size;
492
189k
    h_out_group = cinfo->max_h_samp_factor;
493
189k
    v_out_group = cinfo->max_v_samp_factor;
494
189k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
189k
    need_buffer = TRUE;
496
189k
    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
189k
    } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
501
      /* Fullsize components can be processed without any work. */
502
114k
      upsample->methods[ci] = fullsize_upsample;
503
114k
      need_buffer = FALSE;
504
114k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
14.2k
      if (do_fancy && compptr->downsampled_width > 2) {
507
8.96k
#ifdef WITH_SIMD
508
8.96k
        if (jsimd_set_h2v1_fancy_upsample(cinfo))
509
0
          upsample->methods[ci] = jsimd_h2v1_fancy_upsample;
510
8.96k
        else
511
8.96k
#endif
512
8.96k
          upsample->methods[ci] = h2v1_fancy_upsample;
513
8.96k
      } else {
514
5.28k
#ifdef WITH_SIMD
515
5.28k
        if (jsimd_set_h2v1_upsample(cinfo))
516
0
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
5.28k
        else
518
5.28k
#endif
519
5.28k
          upsample->methods[ci] = h2v1_upsample;
520
5.28k
      }
521
60.5k
    } else if (h_in_group == h_out_group &&
522
26.8k
               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
9.11k
        upsample->methods[ci] = h1v2_fancy_upsample;
530
9.11k
      upsample->pub.need_context_rows = TRUE;
531
51.4k
    } else if (h_in_group * 2 == h_out_group &&
532
16.8k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
10.5k
      if (do_fancy && compptr->downsampled_width > 2) {
535
6.66k
#ifdef WITH_SIMD
536
6.66k
        if (jsimd_set_h2v2_fancy_upsample(cinfo))
537
0
          upsample->methods[ci] = jsimd_h2v2_fancy_upsample;
538
6.66k
        else
539
6.66k
#endif
540
6.66k
          upsample->methods[ci] = h2v2_fancy_upsample;
541
6.66k
        upsample->pub.need_context_rows = TRUE;
542
6.66k
      } else {
543
3.86k
#ifdef WITH_SIMD
544
3.86k
        if (jsimd_set_h2v2_upsample(cinfo))
545
0
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
3.86k
        else
547
3.86k
#endif
548
3.86k
          upsample->methods[ci] = h2v2_upsample;
549
3.86k
      }
550
40.9k
    } else if ((h_out_group % h_in_group) == 0 &&
551
40.8k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
40.7k
      upsample->methods[ci] = int_upsample;
554
40.7k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
40.7k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
40.7k
    } else
557
194
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
189k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
74.6k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
74.6k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
74.6k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
74.6k
                               (long)cinfo->max_h_samp_factor),
563
74.6k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
74.6k
    }
565
189k
  }
566
117k
}
j12init_upsampler
Line
Count
Source
438
27.6k
{
439
27.6k
  my_upsample_ptr upsample;
440
27.6k
  int ci;
441
27.6k
  jpeg_component_info *compptr;
442
27.6k
  boolean need_buffer, do_fancy;
443
27.6k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
27.6k
#ifdef D_LOSSLESS_SUPPORTED
446
27.6k
  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.34k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
6.34k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
6.34k
  } else
455
21.3k
#endif
456
21.3k
  {
457
21.3k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
458
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
459
21.3k
  }
460
461
27.6k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
27.6k
    upsample = (my_upsample_ptr)
463
27.6k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
27.6k
                                  sizeof(my_upsampler));
465
27.6k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
27.6k
    upsample->pub.start_pass = start_pass_upsample;
467
27.6k
    upsample->pub._upsample = sep_upsample;
468
27.6k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
27.6k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
27.6k
  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
27.6k
  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
108k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
80.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
80.9k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
80.9k
                 cinfo->_min_DCT_scaled_size;
490
80.9k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
80.9k
                 cinfo->_min_DCT_scaled_size;
492
80.9k
    h_out_group = cinfo->max_h_samp_factor;
493
80.9k
    v_out_group = cinfo->max_v_samp_factor;
494
80.9k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
80.9k
    need_buffer = TRUE;
496
80.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
80.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
21.5k
      upsample->methods[ci] = fullsize_upsample;
503
21.5k
      need_buffer = FALSE;
504
59.4k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
11.5k
      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
6.81k
          upsample->methods[ci] = h2v1_fancy_upsample;
513
6.81k
      } else {
514
#ifdef WITH_SIMD
515
        if (jsimd_set_h2v1_upsample(cinfo))
516
          upsample->methods[ci] = jsimd_h2v1_upsample;
517
        else
518
#endif
519
4.76k
          upsample->methods[ci] = h2v1_upsample;
520
4.76k
      }
521
47.8k
    } else if (h_in_group == h_out_group &&
522
20.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
9.31k
        upsample->methods[ci] = h1v2_fancy_upsample;
530
9.31k
      upsample->pub.need_context_rows = TRUE;
531
38.5k
    } else if (h_in_group * 2 == h_out_group &&
532
13.2k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
8.23k
      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
4.70k
          upsample->methods[ci] = h2v2_fancy_upsample;
541
4.70k
        upsample->pub.need_context_rows = TRUE;
542
4.70k
      } else {
543
#ifdef WITH_SIMD
544
        if (jsimd_set_h2v2_upsample(cinfo))
545
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
        else
547
#endif
548
3.53k
          upsample->methods[ci] = h2v2_upsample;
549
3.53k
      }
550
30.2k
    } else if ((h_out_group % h_in_group) == 0 &&
551
30.1k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
30.1k
      upsample->methods[ci] = int_upsample;
554
30.1k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
30.1k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
30.1k
    } else
557
160
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
80.9k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
59.2k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
59.2k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
59.2k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
59.2k
                               (long)cinfo->max_h_samp_factor),
563
59.2k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
59.2k
    }
565
80.9k
  }
566
27.6k
}
j16init_upsampler
Line
Count
Source
438
7.98k
{
439
7.98k
  my_upsample_ptr upsample;
440
7.98k
  int ci;
441
7.98k
  jpeg_component_info *compptr;
442
7.98k
  boolean need_buffer, do_fancy;
443
7.98k
  int h_in_group, v_in_group, h_out_group, v_out_group;
444
445
7.98k
#ifdef D_LOSSLESS_SUPPORTED
446
7.98k
  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
7.98k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
451
7.98k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
452
0
#endif
453
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
454
7.98k
  } 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
7.98k
  if (!cinfo->master->jinit_upsampler_no_alloc) {
462
7.98k
    upsample = (my_upsample_ptr)
463
7.98k
      (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
464
7.98k
                                  sizeof(my_upsampler));
465
7.98k
    cinfo->upsample = (struct jpeg_upsampler *)upsample;
466
7.98k
    upsample->pub.start_pass = start_pass_upsample;
467
7.98k
    upsample->pub._upsample = sep_upsample;
468
7.98k
    upsample->pub.need_context_rows = FALSE; /* until we find out differently */
469
7.98k
  } else
470
0
    upsample = (my_upsample_ptr)cinfo->upsample;
471
472
7.98k
  if (cinfo->CCIR601_sampling)  /* this isn't supported */
473
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
474
475
  /* jdmainct.c doesn't support context rows when min_DCT_scaled_size = 1,
476
   * so don't ask for it.
477
   */
478
7.98k
  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
39.9k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
484
31.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
31.9k
    h_in_group = (compptr->h_samp_factor * compptr->_DCT_scaled_size) /
489
31.9k
                 cinfo->_min_DCT_scaled_size;
490
31.9k
    v_in_group = (compptr->v_samp_factor * compptr->_DCT_scaled_size) /
491
31.9k
                 cinfo->_min_DCT_scaled_size;
492
31.9k
    h_out_group = cinfo->max_h_samp_factor;
493
31.9k
    v_out_group = cinfo->max_v_samp_factor;
494
31.9k
    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
495
31.9k
    need_buffer = TRUE;
496
31.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
31.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.82k
      upsample->methods[ci] = fullsize_upsample;
503
5.82k
      need_buffer = FALSE;
504
26.1k
    } else if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {
505
      /* Special cases for 2h1v upsampling */
506
3.67k
      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
3.67k
      } 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.67k
          upsample->methods[ci] = h2v1_upsample;
520
3.67k
      }
521
22.4k
    } else if (h_in_group == h_out_group &&
522
7.60k
               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
22.4k
    } else if (h_in_group * 2 == h_out_group &&
532
6.28k
               v_in_group * 2 == v_out_group) {
533
      /* Special cases for 2h2v upsampling */
534
2.98k
      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
2.98k
      } else {
543
#ifdef WITH_SIMD
544
        if (jsimd_set_h2v2_upsample(cinfo))
545
          upsample->methods[ci] = jsimd_h2v2_upsample;
546
        else
547
#endif
548
2.98k
          upsample->methods[ci] = h2v2_upsample;
549
2.98k
      }
550
19.4k
    } else if ((h_out_group % h_in_group) == 0 &&
551
19.3k
               (v_out_group % v_in_group) == 0) {
552
      /* Generic integral-factors upsampling method */
553
19.3k
      upsample->methods[ci] = int_upsample;
554
19.3k
      upsample->h_expand[ci] = (UINT8)(h_out_group / h_in_group);
555
19.3k
      upsample->v_expand[ci] = (UINT8)(v_out_group / v_in_group);
556
19.3k
    } else
557
112
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
558
31.9k
    if (need_buffer && !cinfo->master->jinit_upsampler_no_alloc) {
559
26.0k
      upsample->color_buf[ci] = (_JSAMPARRAY)(*cinfo->mem->alloc_sarray)
560
26.0k
        ((j_common_ptr)cinfo, JPOOL_IMAGE,
561
26.0k
         (JDIMENSION)jround_up((long)cinfo->output_width,
562
26.0k
                               (long)cinfo->max_h_samp_factor),
563
26.0k
         (JDIMENSION)cinfo->max_v_samp_factor);
564
26.0k
    }
565
31.9k
  }
566
7.98k
}
567
568
#endif /* BITS_IN_JSAMPLE != 16 || defined(D_LOSSLESS_SUPPORTED) */