Coverage Report

Created: 2026-08-13 07:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.main/src/jcsample.c
Line
Count
Source
1
/*
2
 * jcsample.c
3
 *
4
 * This file was part of the Independent JPEG Group's software:
5
 * Copyright (C) 1991-1996, Thomas G. Lane.
6
 * Lossless JPEG Modifications:
7
 * Copyright (C) 1999, Ken Murchison.
8
 * libjpeg-turbo Modifications:
9
 * Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
10
 * Copyright (C) 2015, 2019, 2022, 2024-2026, D. R. Commander.
11
 * For conditions of distribution and use, see the accompanying README.ijg
12
 * file.
13
 *
14
 * This file contains downsampling routines.
15
 *
16
 * Downsampling input data is counted in "row groups".  A row group is defined
17
 * to be max_v_samp_factor rows of each component, from which the downsampler
18
 * produces v_samp_factor sample rows.  A single row group is processed in each
19
 * call to the downsampler module.
20
 *
21
 * The downsampler is responsible for edge-expansion of its output data
22
 * to fill an integral number of DCT blocks horizontally.  The source buffer
23
 * may be modified if it is helpful for this purpose (the source buffer is
24
 * allocated wide enough to correspond to the desired output width).
25
 * The caller (the prep controller) is responsible for vertical padding.
26
 *
27
 * The downsampler may request "context rows" by setting need_context_rows
28
 * during startup.  In this case, the input arrays will contain at least one
29
 * row group's worth of components above and below the passed-in data; the
30
 * caller will create dummy rows at image top and bottom by replicating the
31
 * first or last real component row(s).
32
 *
33
 * An excellent reference for image resampling is
34
 *   Digital Image Warping, George Wolberg, 1990.
35
 *   Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.
36
 *
37
 * The downsampling algorithm used here is a simple average of the source
38
 * components covered by the output sample.  The hi-falutin sampling literature
39
 * refers to this as a "box filter".  In general, the characteristics of a box
40
 * filter are not very good.  However, for the specific cases we normally use
41
 * (1:1 and 2:1 ratios), the box is equivalent to a "triangle filter", which is
42
 * not nearly so bad.  If you intend to use other sampling ratios, you'd be
43
 * well advised to improve this code.
44
 *
45
 * A simple input-smoothing capability is provided.  This is mainly intended
46
 * for cleaning up color-dithered GIF input files.  (If you find it inadequate,
47
 * we suggest using an external filtering program such as pnmconvol).  When
48
 * enabled, each input component C is replaced by a weighted sum of itself and
49
 * its eight neighbors.  C's weight is 1-8*SF, and each neighbor's weight is
50
 * SF, where SF = (smoothing_factor / 1024).
51
 * Currently, smoothing is only supported for 2h2v sampling factors.
52
 */
53
54
#define JPEG_INTERNALS
55
#include "jinclude.h"
56
#include "jpeglib.h"
57
#ifdef WITH_SIMD
58
#include "../simd/jsimd.h"
59
#endif
60
#include "jsamplecomp.h"
61
62
63
#if BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED)
64
65
/* Pointer to routine to downsample a single component */
66
typedef void (*downsample1_ptr) (j_compress_ptr cinfo,
67
                                 jpeg_component_info *compptr,
68
                                 _JSAMPARRAY input_data,
69
                                 _JSAMPARRAY output_data);
70
71
/* Private subobject */
72
73
typedef struct {
74
  struct jpeg_downsampler pub;  /* public fields */
75
76
  /* Downsampling method pointers, one per component */
77
  downsample1_ptr methods[MAX_COMPONENTS];
78
} my_downsampler;
79
80
typedef my_downsampler *my_downsample_ptr;
81
82
83
/*
84
 * Initialize for a downsampling pass.
85
 */
86
87
METHODDEF(void)
88
start_pass_downsample(j_compress_ptr cinfo)
89
154k
{
90
  /* no work for now */
91
154k
}
jcsample-8.c:start_pass_downsample
Line
Count
Source
89
73.4k
{
90
  /* no work for now */
91
73.4k
}
jcsample-12.c:start_pass_downsample
Line
Count
Source
89
59.4k
{
90
  /* no work for now */
91
59.4k
}
jcsample-16.c:start_pass_downsample
Line
Count
Source
89
21.1k
{
90
  /* no work for now */
91
21.1k
}
92
93
94
/*
95
 * Expand a component horizontally from width input_cols to width output_cols,
96
 * by duplicating the rightmost samples.
97
 */
98
99
LOCAL(void)
100
expand_right_edge(_JSAMPARRAY image_data, int num_rows, JDIMENSION input_cols,
101
                  JDIMENSION output_cols)
102
635M
{
103
635M
  register _JSAMPROW ptr;
104
635M
  register _JSAMPLE pixval;
105
635M
  register int count;
106
635M
  int row;
107
635M
  int numcols = (int)(output_cols - input_cols);
108
109
635M
  if (numcols > 0) {
110
823M
    for (row = 0; row < num_rows; row++) {
111
455M
      ptr = image_data[row] + input_cols;
112
455M
      pixval = ptr[-1];
113
5.40G
      for (count = numcols; count > 0; count--)
114
4.94G
        *ptr++ = pixval;
115
455M
    }
116
368M
  }
117
635M
}
jcsample-8.c:expand_right_edge
Line
Count
Source
102
295M
{
103
295M
  register _JSAMPROW ptr;
104
295M
  register _JSAMPLE pixval;
105
295M
  register int count;
106
295M
  int row;
107
295M
  int numcols = (int)(output_cols - input_cols);
108
109
295M
  if (numcols > 0) {
110
475M
    for (row = 0; row < num_rows; row++) {
111
262M
      ptr = image_data[row] + input_cols;
112
262M
      pixval = ptr[-1];
113
3.11G
      for (count = numcols; count > 0; count--)
114
2.85G
        *ptr++ = pixval;
115
262M
    }
116
212M
  }
117
295M
}
jcsample-12.c:expand_right_edge
Line
Count
Source
102
242M
{
103
242M
  register _JSAMPROW ptr;
104
242M
  register _JSAMPLE pixval;
105
242M
  register int count;
106
242M
  int row;
107
242M
  int numcols = (int)(output_cols - input_cols);
108
109
242M
  if (numcols > 0) {
110
348M
    for (row = 0; row < num_rows; row++) {
111
193M
      ptr = image_data[row] + input_cols;
112
193M
      pixval = ptr[-1];
113
2.28G
      for (count = numcols; count > 0; count--)
114
2.09G
        *ptr++ = pixval;
115
193M
    }
116
155M
  }
117
242M
}
jcsample-16.c:expand_right_edge
Line
Count
Source
102
96.5M
{
103
96.5M
  register _JSAMPROW ptr;
104
96.5M
  register _JSAMPLE pixval;
105
96.5M
  register int count;
106
96.5M
  int row;
107
96.5M
  int numcols = (int)(output_cols - input_cols);
108
109
96.5M
  if (numcols > 0) {
110
0
    for (row = 0; row < num_rows; row++) {
111
0
      ptr = image_data[row] + input_cols;
112
0
      pixval = ptr[-1];
113
0
      for (count = numcols; count > 0; count--)
114
0
        *ptr++ = pixval;
115
0
    }
116
0
  }
117
96.5M
}
118
119
120
/*
121
 * Do downsampling for a whole row group (all components).
122
 *
123
 * In this version we simply downsample each component independently.
124
 */
125
126
METHODDEF(void)
127
sep_downsample(j_compress_ptr cinfo, _JSAMPIMAGE input_buf,
128
               JDIMENSION in_row_index, _JSAMPIMAGE output_buf,
129
               JDIMENSION out_row_group_index)
130
270M
{
131
270M
  my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample;
132
270M
  int ci;
133
270M
  jpeg_component_info *compptr;
134
270M
  _JSAMPARRAY in_ptr, out_ptr;
135
136
967M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
137
696M
       ci++, compptr++) {
138
696M
    in_ptr = input_buf[ci] + in_row_index;
139
696M
    out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
140
696M
    (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
141
696M
  }
142
270M
}
jcsample-8.c:sep_downsample
Line
Count
Source
130
142M
{
131
142M
  my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample;
132
142M
  int ci;
133
142M
  jpeg_component_info *compptr;
134
142M
  _JSAMPARRAY in_ptr, out_ptr;
135
136
500M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
137
357M
       ci++, compptr++) {
138
357M
    in_ptr = input_buf[ci] + in_row_index;
139
357M
    out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
140
357M
    (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
141
357M
  }
142
142M
}
jcsample-12.c:sep_downsample
Line
Count
Source
130
93.9M
{
131
93.9M
  my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample;
132
93.9M
  int ci;
133
93.9M
  jpeg_component_info *compptr;
134
93.9M
  _JSAMPARRAY in_ptr, out_ptr;
135
136
336M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
137
242M
       ci++, compptr++) {
138
242M
    in_ptr = input_buf[ci] + in_row_index;
139
242M
    out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
140
242M
    (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
141
242M
  }
142
93.9M
}
jcsample-16.c:sep_downsample
Line
Count
Source
130
33.7M
{
131
33.7M
  my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample;
132
33.7M
  int ci;
133
33.7M
  jpeg_component_info *compptr;
134
33.7M
  _JSAMPARRAY in_ptr, out_ptr;
135
136
130M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
137
96.5M
       ci++, compptr++) {
138
96.5M
    in_ptr = input_buf[ci] + in_row_index;
139
96.5M
    out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
140
96.5M
    (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
141
96.5M
  }
142
33.7M
}
143
144
145
/*
146
 * Downsample components from a single plane.
147
 * One row group is processed per call.
148
 * This version handles arbitrary integral sampling ratios, without smoothing.
149
 * Note that this version is not actually used for customary sampling ratios.
150
 */
151
152
METHODDEF(void)
153
int_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
154
               _JSAMPARRAY input_data, _JSAMPARRAY output_data)
155
85.2M
{
156
85.2M
  int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
157
85.2M
  JDIMENSION outcol, outcol_h;  /* outcol_h == outcol*h_expand */
158
85.2M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
159
85.2M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
160
85.2M
  _JSAMPROW inptr, outptr;
161
85.2M
  JLONG outvalue;
162
163
85.2M
  h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
164
85.2M
  v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
165
85.2M
  numpix = h_expand * v_expand;
166
85.2M
  numpix2 = numpix / 2;
167
168
  /* Expand input data enough to let all the output samples be generated
169
   * by the standard loop.  Special-casing padded output would be more
170
   * efficient.
171
   */
172
85.2M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
173
85.2M
                    output_cols * h_expand);
174
175
85.2M
  inrow = 0;
176
172M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
177
87.2M
    outptr = output_data[outrow];
178
988M
    for (outcol = 0, outcol_h = 0; outcol < output_cols;
179
901M
         outcol++, outcol_h += h_expand) {
180
901M
      outvalue = 0;
181
2.10G
      for (v = 0; v < v_expand; v++) {
182
1.19G
        inptr = input_data[inrow + v] + outcol_h;
183
4.20G
        for (h = 0; h < h_expand; h++) {
184
3.00G
          outvalue += (JLONG)(*inptr++);
185
3.00G
        }
186
1.19G
      }
187
901M
      *outptr++ = (_JSAMPLE)((outvalue + numpix2) / numpix);
188
901M
    }
189
87.2M
    inrow += v_expand;
190
87.2M
  }
191
85.2M
}
jcsample-8.c:int_downsample
Line
Count
Source
155
52.6M
{
156
52.6M
  int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
157
52.6M
  JDIMENSION outcol, outcol_h;  /* outcol_h == outcol*h_expand */
158
52.6M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
159
52.6M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
160
52.6M
  _JSAMPROW inptr, outptr;
161
52.6M
  JLONG outvalue;
162
163
52.6M
  h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
164
52.6M
  v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
165
52.6M
  numpix = h_expand * v_expand;
166
52.6M
  numpix2 = numpix / 2;
167
168
  /* Expand input data enough to let all the output samples be generated
169
   * by the standard loop.  Special-casing padded output would be more
170
   * efficient.
171
   */
172
52.6M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
173
52.6M
                    output_cols * h_expand);
174
175
52.6M
  inrow = 0;
176
107M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
177
54.6M
    outptr = output_data[outrow];
178
626M
    for (outcol = 0, outcol_h = 0; outcol < output_cols;
179
571M
         outcol++, outcol_h += h_expand) {
180
571M
      outvalue = 0;
181
1.30G
      for (v = 0; v < v_expand; v++) {
182
734M
        inptr = input_data[inrow + v] + outcol_h;
183
2.69G
        for (h = 0; h < h_expand; h++) {
184
1.96G
          outvalue += (JLONG)(*inptr++);
185
1.96G
        }
186
734M
      }
187
571M
      *outptr++ = (_JSAMPLE)((outvalue + numpix2) / numpix);
188
571M
    }
189
54.6M
    inrow += v_expand;
190
54.6M
  }
191
52.6M
}
jcsample-12.c:int_downsample
Line
Count
Source
155
32.5M
{
156
32.5M
  int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
157
32.5M
  JDIMENSION outcol, outcol_h;  /* outcol_h == outcol*h_expand */
158
32.5M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
159
32.5M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
160
32.5M
  _JSAMPROW inptr, outptr;
161
32.5M
  JLONG outvalue;
162
163
32.5M
  h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
164
32.5M
  v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
165
32.5M
  numpix = h_expand * v_expand;
166
32.5M
  numpix2 = numpix / 2;
167
168
  /* Expand input data enough to let all the output samples be generated
169
   * by the standard loop.  Special-casing padded output would be more
170
   * efficient.
171
   */
172
32.5M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
173
32.5M
                    output_cols * h_expand);
174
175
32.5M
  inrow = 0;
176
65.1M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
177
32.5M
    outptr = output_data[outrow];
178
361M
    for (outcol = 0, outcol_h = 0; outcol < output_cols;
179
329M
         outcol++, outcol_h += h_expand) {
180
329M
      outvalue = 0;
181
793M
      for (v = 0; v < v_expand; v++) {
182
464M
        inptr = input_data[inrow + v] + outcol_h;
183
1.51G
        for (h = 0; h < h_expand; h++) {
184
1.04G
          outvalue += (JLONG)(*inptr++);
185
1.04G
        }
186
464M
      }
187
329M
      *outptr++ = (_JSAMPLE)((outvalue + numpix2) / numpix);
188
329M
    }
189
32.5M
    inrow += v_expand;
190
32.5M
  }
191
32.5M
}
Unexecuted instantiation: jcsample-16.c:int_downsample
192
193
194
/*
195
 * Downsample components from a single plane.
196
 * This version handles the special case of a full-size component,
197
 * without smoothing.
198
 */
199
200
METHODDEF(void)
201
fullsize_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
202
                    _JSAMPARRAY input_data, _JSAMPARRAY output_data)
203
511M
{
204
511M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
205
206
  /* Copy the data */
207
511M
  _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
208
511M
                     cinfo->image_width);
209
  /* Edge-expand */
210
511M
  expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
211
511M
                    compptr->width_in_blocks * data_unit);
212
511M
}
jcsample-8.c:fullsize_downsample
Line
Count
Source
203
236M
{
204
236M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
205
206
  /* Copy the data */
207
236M
  _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
208
236M
                     cinfo->image_width);
209
  /* Edge-expand */
210
236M
  expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
211
236M
                    compptr->width_in_blocks * data_unit);
212
236M
}
jcsample-12.c:fullsize_downsample
Line
Count
Source
203
177M
{
204
177M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
205
206
  /* Copy the data */
207
177M
  _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
208
177M
                     cinfo->image_width);
209
  /* Edge-expand */
210
177M
  expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
211
177M
                    compptr->width_in_blocks * data_unit);
212
177M
}
jcsample-16.c:fullsize_downsample
Line
Count
Source
203
96.5M
{
204
96.5M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
205
206
  /* Copy the data */
207
96.5M
  _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
208
96.5M
                     cinfo->image_width);
209
  /* Edge-expand */
210
96.5M
  expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
211
96.5M
                    compptr->width_in_blocks * data_unit);
212
96.5M
}
213
214
215
/*
216
 * Downsample components from a single plane.
217
 * This version handles the common case of 2:1 horizontal and 1:1 vertical,
218
 * without smoothing.
219
 *
220
 * A note about the "bias" calculations: when rounding fractional values to
221
 * integer, we do not want to always round 0.5 up to the next integer.
222
 * If we did that, we'd introduce a noticeable bias towards larger values.
223
 * Instead, this code is arranged so that 0.5 will be rounded up or down at
224
 * alternate pixel locations (a simple ordered dither pattern).
225
 */
226
227
METHODDEF(void)
228
h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
229
                _JSAMPARRAY input_data, _JSAMPARRAY output_data)
230
21.7M
{
231
21.7M
  int outrow;
232
21.7M
  JDIMENSION outcol;
233
21.7M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
234
21.7M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
235
21.7M
  register _JSAMPROW inptr, outptr;
236
21.7M
  register int bias;
237
238
  /* Expand input data enough to let all the output samples be generated
239
   * by the standard loop.  Special-casing padded output would be more
240
   * efficient.
241
   */
242
21.7M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
243
21.7M
                    output_cols * 2);
244
245
43.4M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
246
21.7M
    outptr = output_data[outrow];
247
21.7M
    inptr = input_data[outrow];
248
21.7M
    bias = 0;                   /* bias = 0,1,0,1,... for successive samples */
249
238M
    for (outcol = 0; outcol < output_cols; outcol++) {
250
216M
      *outptr++ = (_JSAMPLE)((inptr[0] + inptr[1] + bias) >> 1);
251
216M
      bias ^= 1;                /* 0=>1, 1=>0 */
252
216M
      inptr += 2;
253
216M
    }
254
21.7M
  }
255
21.7M
}
Unexecuted instantiation: jcsample-8.c:h2v1_downsample
jcsample-12.c:h2v1_downsample
Line
Count
Source
230
21.7M
{
231
21.7M
  int outrow;
232
21.7M
  JDIMENSION outcol;
233
21.7M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
234
21.7M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
235
21.7M
  register _JSAMPROW inptr, outptr;
236
21.7M
  register int bias;
237
238
  /* Expand input data enough to let all the output samples be generated
239
   * by the standard loop.  Special-casing padded output would be more
240
   * efficient.
241
   */
242
21.7M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
243
21.7M
                    output_cols * 2);
244
245
43.4M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
246
21.7M
    outptr = output_data[outrow];
247
21.7M
    inptr = input_data[outrow];
248
21.7M
    bias = 0;                   /* bias = 0,1,0,1,... for successive samples */
249
238M
    for (outcol = 0; outcol < output_cols; outcol++) {
250
216M
      *outptr++ = (_JSAMPLE)((inptr[0] + inptr[1] + bias) >> 1);
251
216M
      bias ^= 1;                /* 0=>1, 1=>0 */
252
216M
      inptr += 2;
253
216M
    }
254
21.7M
  }
255
21.7M
}
Unexecuted instantiation: jcsample-16.c:h2v1_downsample
256
257
258
/*
259
 * Downsample components from a single plane.
260
 * This version handles the standard case of 2:1 horizontal and 2:1 vertical,
261
 * without smoothing.
262
 */
263
264
METHODDEF(void)
265
h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
266
                _JSAMPARRAY input_data, _JSAMPARRAY output_data)
267
10.8M
{
268
10.8M
  int inrow, outrow;
269
10.8M
  JDIMENSION outcol;
270
10.8M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
271
10.8M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
272
10.8M
  register _JSAMPROW inptr0, inptr1, outptr;
273
10.8M
  register int bias;
274
275
  /* Expand input data enough to let all the output samples be generated
276
   * by the standard loop.  Special-casing padded output would be more
277
   * efficient.
278
   */
279
10.8M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
280
10.8M
                    output_cols * 2);
281
282
10.8M
  inrow = 0;
283
21.7M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
284
10.8M
    outptr = output_data[outrow];
285
10.8M
    inptr0 = input_data[inrow];
286
10.8M
    inptr1 = input_data[inrow + 1];
287
10.8M
    bias = 1;                   /* bias = 1,2,1,2,... for successive samples */
288
121M
    for (outcol = 0; outcol < output_cols; outcol++) {
289
110M
      *outptr++ = (_JSAMPLE)
290
110M
        ((inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1] + bias) >> 2);
291
110M
      bias ^= 3;                /* 1=>2, 2=>1 */
292
110M
      inptr0 += 2;  inptr1 += 2;
293
110M
    }
294
10.8M
    inrow += 2;
295
10.8M
  }
296
10.8M
}
Unexecuted instantiation: jcsample-8.c:h2v2_downsample
jcsample-12.c:h2v2_downsample
Line
Count
Source
267
10.8M
{
268
10.8M
  int inrow, outrow;
269
10.8M
  JDIMENSION outcol;
270
10.8M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
271
10.8M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
272
10.8M
  register _JSAMPROW inptr0, inptr1, outptr;
273
10.8M
  register int bias;
274
275
  /* Expand input data enough to let all the output samples be generated
276
   * by the standard loop.  Special-casing padded output would be more
277
   * efficient.
278
   */
279
10.8M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
280
10.8M
                    output_cols * 2);
281
282
10.8M
  inrow = 0;
283
21.7M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
284
10.8M
    outptr = output_data[outrow];
285
10.8M
    inptr0 = input_data[inrow];
286
10.8M
    inptr1 = input_data[inrow + 1];
287
10.8M
    bias = 1;                   /* bias = 1,2,1,2,... for successive samples */
288
121M
    for (outcol = 0; outcol < output_cols; outcol++) {
289
110M
      *outptr++ = (_JSAMPLE)
290
110M
        ((inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1] + bias) >> 2);
291
110M
      bias ^= 3;                /* 1=>2, 2=>1 */
292
110M
      inptr0 += 2;  inptr1 += 2;
293
110M
    }
294
10.8M
    inrow += 2;
295
10.8M
  }
296
10.8M
}
Unexecuted instantiation: jcsample-16.c:h2v2_downsample
297
298
299
#ifdef INPUT_SMOOTHING_SUPPORTED
300
301
/*
302
 * Downsample components from a single plane.
303
 * This version handles the standard case of 2:1 horizontal and 2:1 vertical,
304
 * with smoothing.  One row of context is required.
305
 */
306
307
METHODDEF(void)
308
h2v2_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
309
                       _JSAMPARRAY input_data, _JSAMPARRAY output_data)
310
4.05M
{
311
4.05M
  int inrow, outrow;
312
4.05M
  JDIMENSION colctr;
313
4.05M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
314
4.05M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
315
4.05M
  register _JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
316
4.05M
  JLONG membersum, neighsum, memberscale, neighscale;
317
318
  /* Expand input data enough to let all the output samples be generated
319
   * by the standard loop.  Special-casing padded output would be more
320
   * efficient.
321
   */
322
4.05M
  expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
323
4.05M
                    cinfo->image_width, output_cols * 2);
324
325
  /* We don't bother to form the individual "smoothed" input component values;
326
   * we can directly compute the output which is the average of the four
327
   * smoothed values.  Each of the four member components contributes a
328
   * fraction (1-8*SF) to its own smoothed image and a fraction SF to each of
329
   * the three other smoothed components, therefore a total fraction (1-5*SF)/4
330
   * to the final output.  The four corner-adjacent neighbor components
331
   * contribute a fraction SF to just one smoothed component, or SF/4 to the
332
   * final output; while the eight edge-adjacent neighbors contribute SF to
333
   * each of two smoothed components, or SF/2 overall.  In order to use integer
334
   * arithmetic, these factors are scaled by 2^16 = 65536.  Also recall that
335
   * SF = smoothing_factor / 1024.
336
   */
337
338
4.05M
  memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
339
4.05M
  neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
340
341
4.05M
  inrow = 0;
342
8.10M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
343
4.05M
    outptr = output_data[outrow];
344
4.05M
    inptr0 = input_data[inrow];
345
4.05M
    inptr1 = input_data[inrow + 1];
346
4.05M
    above_ptr = input_data[inrow - 1];
347
4.05M
    below_ptr = input_data[inrow + 2];
348
349
    /* Special case for first column: pretend column -1 is same as column 0 */
350
4.05M
    membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1];
351
4.05M
    neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] +
352
4.05M
               inptr0[0] + inptr0[2] + inptr1[0] + inptr1[2];
353
4.05M
    neighsum += neighsum;
354
4.05M
    neighsum += above_ptr[0] + above_ptr[2] + below_ptr[0] + below_ptr[2];
355
4.05M
    membersum = membersum * memberscale + neighsum * neighscale;
356
4.05M
    *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
357
4.05M
    inptr0 += 2;  inptr1 += 2;  above_ptr += 2;  below_ptr += 2;
358
359
68.6M
    for (colctr = output_cols - 2; colctr > 0; colctr--) {
360
      /* sum of components directly mapped to this output element */
361
64.5M
      membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1];
362
      /* sum of edge-neighbor components */
363
64.5M
      neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] +
364
64.5M
                 inptr0[-1] + inptr0[2] + inptr1[-1] + inptr1[2];
365
      /* The edge-neighbors count twice as much as corner-neighbors */
366
64.5M
      neighsum += neighsum;
367
      /* Add in the corner-neighbors */
368
64.5M
      neighsum += above_ptr[-1] + above_ptr[2] + below_ptr[-1] + below_ptr[2];
369
      /* form final output scaled up by 2^16 */
370
64.5M
      membersum = membersum * memberscale + neighsum * neighscale;
371
      /* round, descale and output it */
372
64.5M
      *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
373
64.5M
      inptr0 += 2;  inptr1 += 2;  above_ptr += 2;  below_ptr += 2;
374
64.5M
    }
375
376
    /* Special case for last column */
377
4.05M
    membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1];
378
4.05M
    neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] +
379
4.05M
               inptr0[-1] + inptr0[1] + inptr1[-1] + inptr1[1];
380
4.05M
    neighsum += neighsum;
381
4.05M
    neighsum += above_ptr[-1] + above_ptr[1] + below_ptr[-1] + below_ptr[1];
382
4.05M
    membersum = membersum * memberscale + neighsum * neighscale;
383
4.05M
    *outptr = (_JSAMPLE)((membersum + 32768) >> 16);
384
385
4.05M
    inrow += 2;
386
4.05M
  }
387
4.05M
}
jcsample-8.c:h2v2_smooth_downsample
Line
Count
Source
310
4.05M
{
311
4.05M
  int inrow, outrow;
312
4.05M
  JDIMENSION colctr;
313
4.05M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
314
4.05M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
315
4.05M
  register _JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
316
4.05M
  JLONG membersum, neighsum, memberscale, neighscale;
317
318
  /* Expand input data enough to let all the output samples be generated
319
   * by the standard loop.  Special-casing padded output would be more
320
   * efficient.
321
   */
322
4.05M
  expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
323
4.05M
                    cinfo->image_width, output_cols * 2);
324
325
  /* We don't bother to form the individual "smoothed" input component values;
326
   * we can directly compute the output which is the average of the four
327
   * smoothed values.  Each of the four member components contributes a
328
   * fraction (1-8*SF) to its own smoothed image and a fraction SF to each of
329
   * the three other smoothed components, therefore a total fraction (1-5*SF)/4
330
   * to the final output.  The four corner-adjacent neighbor components
331
   * contribute a fraction SF to just one smoothed component, or SF/4 to the
332
   * final output; while the eight edge-adjacent neighbors contribute SF to
333
   * each of two smoothed components, or SF/2 overall.  In order to use integer
334
   * arithmetic, these factors are scaled by 2^16 = 65536.  Also recall that
335
   * SF = smoothing_factor / 1024.
336
   */
337
338
4.05M
  memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
339
4.05M
  neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
340
341
4.05M
  inrow = 0;
342
8.10M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
343
4.05M
    outptr = output_data[outrow];
344
4.05M
    inptr0 = input_data[inrow];
345
4.05M
    inptr1 = input_data[inrow + 1];
346
4.05M
    above_ptr = input_data[inrow - 1];
347
4.05M
    below_ptr = input_data[inrow + 2];
348
349
    /* Special case for first column: pretend column -1 is same as column 0 */
350
4.05M
    membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1];
351
4.05M
    neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] +
352
4.05M
               inptr0[0] + inptr0[2] + inptr1[0] + inptr1[2];
353
4.05M
    neighsum += neighsum;
354
4.05M
    neighsum += above_ptr[0] + above_ptr[2] + below_ptr[0] + below_ptr[2];
355
4.05M
    membersum = membersum * memberscale + neighsum * neighscale;
356
4.05M
    *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
357
4.05M
    inptr0 += 2;  inptr1 += 2;  above_ptr += 2;  below_ptr += 2;
358
359
68.6M
    for (colctr = output_cols - 2; colctr > 0; colctr--) {
360
      /* sum of components directly mapped to this output element */
361
64.5M
      membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1];
362
      /* sum of edge-neighbor components */
363
64.5M
      neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] +
364
64.5M
                 inptr0[-1] + inptr0[2] + inptr1[-1] + inptr1[2];
365
      /* The edge-neighbors count twice as much as corner-neighbors */
366
64.5M
      neighsum += neighsum;
367
      /* Add in the corner-neighbors */
368
64.5M
      neighsum += above_ptr[-1] + above_ptr[2] + below_ptr[-1] + below_ptr[2];
369
      /* form final output scaled up by 2^16 */
370
64.5M
      membersum = membersum * memberscale + neighsum * neighscale;
371
      /* round, descale and output it */
372
64.5M
      *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
373
64.5M
      inptr0 += 2;  inptr1 += 2;  above_ptr += 2;  below_ptr += 2;
374
64.5M
    }
375
376
    /* Special case for last column */
377
4.05M
    membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1];
378
4.05M
    neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] +
379
4.05M
               inptr0[-1] + inptr0[1] + inptr1[-1] + inptr1[1];
380
4.05M
    neighsum += neighsum;
381
4.05M
    neighsum += above_ptr[-1] + above_ptr[1] + below_ptr[-1] + below_ptr[1];
382
4.05M
    membersum = membersum * memberscale + neighsum * neighscale;
383
4.05M
    *outptr = (_JSAMPLE)((membersum + 32768) >> 16);
384
385
4.05M
    inrow += 2;
386
4.05M
  }
387
4.05M
}
Unexecuted instantiation: jcsample-12.c:h2v2_smooth_downsample
Unexecuted instantiation: jcsample-16.c:h2v2_smooth_downsample
388
389
390
/*
391
 * Downsample components from a single plane.
392
 * This version handles the special case of a full-size component,
393
 * with smoothing.  One row of context is required.
394
 */
395
396
METHODDEF(void)
397
fullsize_smooth_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr,
398
                           _JSAMPARRAY input_data, _JSAMPARRAY output_data)
399
2.27M
{
400
2.27M
  int outrow;
401
2.27M
  JDIMENSION colctr;
402
2.27M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
403
2.27M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
404
2.27M
  register _JSAMPROW inptr, above_ptr, below_ptr, outptr;
405
2.27M
  JLONG membersum, neighsum, memberscale, neighscale;
406
2.27M
  int colsum, lastcolsum, nextcolsum;
407
408
  /* Expand input data enough to let all the output samples be generated
409
   * by the standard loop.  Special-casing padded output would be more
410
   * efficient.
411
   */
412
2.27M
  expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
413
2.27M
                    cinfo->image_width, output_cols);
414
415
  /* Each of the eight neighbor components contributes a fraction SF to the
416
   * smoothed component, while the main component contributes (1-8*SF).  In
417
   * order to use integer arithmetic, these factors are multiplied by
418
   * 2^16 = 65536.  Also recall that SF = smoothing_factor / 1024.
419
   */
420
421
2.27M
  memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
422
2.27M
  neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
423
424
6.58M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
425
4.30M
    outptr = output_data[outrow];
426
4.30M
    inptr = input_data[outrow];
427
4.30M
    above_ptr = input_data[outrow - 1];
428
4.30M
    below_ptr = input_data[outrow + 1];
429
430
    /* Special case for first column */
431
4.30M
    colsum = (*above_ptr++) + (*below_ptr++) + inptr[0];
432
4.30M
    membersum = *inptr++;
433
4.30M
    nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0];
434
4.30M
    neighsum = colsum + (colsum - membersum) + nextcolsum;
435
4.30M
    membersum = membersum * memberscale + neighsum * neighscale;
436
4.30M
    *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
437
4.30M
    lastcolsum = colsum;  colsum = nextcolsum;
438
439
136M
    for (colctr = output_cols - 2; colctr > 0; colctr--) {
440
132M
      membersum = *inptr++;
441
132M
      above_ptr++;  below_ptr++;
442
132M
      nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0];
443
132M
      neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
444
132M
      membersum = membersum * memberscale + neighsum * neighscale;
445
132M
      *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
446
132M
      lastcolsum = colsum;  colsum = nextcolsum;
447
132M
    }
448
449
    /* Special case for last column */
450
4.30M
    membersum = *inptr;
451
4.30M
    neighsum = lastcolsum + (colsum - membersum) + colsum;
452
4.30M
    membersum = membersum * memberscale + neighsum * neighscale;
453
4.30M
    *outptr = (_JSAMPLE)((membersum + 32768) >> 16);
454
455
4.30M
  }
456
2.27M
}
jcsample-8.c:fullsize_smooth_downsample
Line
Count
Source
399
2.27M
{
400
2.27M
  int outrow;
401
2.27M
  JDIMENSION colctr;
402
2.27M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
403
2.27M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
404
2.27M
  register _JSAMPROW inptr, above_ptr, below_ptr, outptr;
405
2.27M
  JLONG membersum, neighsum, memberscale, neighscale;
406
2.27M
  int colsum, lastcolsum, nextcolsum;
407
408
  /* Expand input data enough to let all the output samples be generated
409
   * by the standard loop.  Special-casing padded output would be more
410
   * efficient.
411
   */
412
2.27M
  expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
413
2.27M
                    cinfo->image_width, output_cols);
414
415
  /* Each of the eight neighbor components contributes a fraction SF to the
416
   * smoothed component, while the main component contributes (1-8*SF).  In
417
   * order to use integer arithmetic, these factors are multiplied by
418
   * 2^16 = 65536.  Also recall that SF = smoothing_factor / 1024.
419
   */
420
421
2.27M
  memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
422
2.27M
  neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
423
424
6.58M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
425
4.30M
    outptr = output_data[outrow];
426
4.30M
    inptr = input_data[outrow];
427
4.30M
    above_ptr = input_data[outrow - 1];
428
4.30M
    below_ptr = input_data[outrow + 1];
429
430
    /* Special case for first column */
431
4.30M
    colsum = (*above_ptr++) + (*below_ptr++) + inptr[0];
432
4.30M
    membersum = *inptr++;
433
4.30M
    nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0];
434
4.30M
    neighsum = colsum + (colsum - membersum) + nextcolsum;
435
4.30M
    membersum = membersum * memberscale + neighsum * neighscale;
436
4.30M
    *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
437
4.30M
    lastcolsum = colsum;  colsum = nextcolsum;
438
439
136M
    for (colctr = output_cols - 2; colctr > 0; colctr--) {
440
132M
      membersum = *inptr++;
441
132M
      above_ptr++;  below_ptr++;
442
132M
      nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0];
443
132M
      neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
444
132M
      membersum = membersum * memberscale + neighsum * neighscale;
445
132M
      *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
446
132M
      lastcolsum = colsum;  colsum = nextcolsum;
447
132M
    }
448
449
    /* Special case for last column */
450
4.30M
    membersum = *inptr;
451
4.30M
    neighsum = lastcolsum + (colsum - membersum) + colsum;
452
4.30M
    membersum = membersum * memberscale + neighsum * neighscale;
453
4.30M
    *outptr = (_JSAMPLE)((membersum + 32768) >> 16);
454
455
4.30M
  }
456
2.27M
}
Unexecuted instantiation: jcsample-12.c:fullsize_smooth_downsample
Unexecuted instantiation: jcsample-16.c:fullsize_smooth_downsample
457
458
#endif /* INPUT_SMOOTHING_SUPPORTED */
459
460
461
/*
462
 * Module initialization routine for downsampling.
463
 * Note that we must select a routine for each component.
464
 */
465
466
GLOBAL(void)
467
_jinit_downsampler(j_compress_ptr cinfo)
468
179k
{
469
179k
  my_downsample_ptr downsample;
470
179k
  int ci;
471
179k
  jpeg_component_info *compptr;
472
179k
#ifdef INPUT_SMOOTHING_SUPPORTED
473
179k
  boolean smoothok = TRUE;
474
179k
#endif
475
476
179k
#ifdef C_LOSSLESS_SUPPORTED
477
179k
  if (cinfo->master->lossless) {
478
#if BITS_IN_JSAMPLE == 8
479
28.9k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
480
#else
481
43.8k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
482
43.8k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
483
0
#endif
484
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
485
72.7k
  } else
486
106k
#endif
487
106k
  {
488
106k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
489
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
490
106k
  }
491
492
179k
  downsample = (my_downsample_ptr)
493
179k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
494
179k
                                sizeof(my_downsampler));
495
179k
  cinfo->downsample = (struct jpeg_downsampler *)downsample;
496
179k
  downsample->pub.start_pass = start_pass_downsample;
497
179k
  downsample->pub._downsample = sep_downsample;
498
179k
  downsample->pub.need_context_rows = FALSE;
499
500
179k
  if (cinfo->CCIR601_sampling)
501
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
502
503
  /* Verify we can handle the sampling factors, and set up method pointers */
504
642k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
505
463k
       ci++, compptr++) {
506
463k
    if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
507
368k
        compptr->v_samp_factor == cinfo->max_v_samp_factor) {
508
345k
#ifdef INPUT_SMOOTHING_SUPPORTED
509
345k
      if (cinfo->smoothing_factor) {
510
3.61k
        downsample->methods[ci] = fullsize_smooth_downsample;
511
3.61k
        downsample->pub.need_context_rows = TRUE;
512
3.61k
      } else
513
342k
#endif
514
342k
        downsample->methods[ci] = fullsize_downsample;
515
345k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
516
64.0k
               compptr->v_samp_factor == cinfo->max_v_samp_factor) {
517
31.2k
#ifdef INPUT_SMOOTHING_SUPPORTED
518
31.2k
      smoothok = FALSE;
519
31.2k
#endif
520
#ifdef WITH_SIMD
521
20.7k
      if (jsimd_set_h2v1_downsample(cinfo))
522
20.7k
        downsample->methods[ci] = jsimd_h2v1_downsample;
523
0
      else
524
0
#endif
525
0
        downsample->methods[ci] = h2v1_downsample;
526
85.9k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
527
32.7k
               compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
528
32.7k
#ifdef INPUT_SMOOTHING_SUPPORTED
529
32.7k
      if (cinfo->smoothing_factor) {
530
4.12k
        downsample->methods[ci] = h2v2_smooth_downsample;
531
4.12k
        downsample->pub.need_context_rows = TRUE;
532
4.12k
      } else
533
28.6k
#endif
534
28.6k
      {
535
#ifdef WITH_SIMD
536
18.3k
        if (jsimd_set_h2v2_downsample(cinfo))
537
18.3k
          downsample->methods[ci] = jsimd_h2v2_downsample;
538
0
        else
539
0
#endif
540
0
          downsample->methods[ci] = h2v2_downsample;
541
28.6k
      }
542
53.1k
    } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
543
53.1k
               (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
544
53.1k
#ifdef INPUT_SMOOTHING_SUPPORTED
545
53.1k
      smoothok = FALSE;
546
53.1k
#endif
547
53.1k
      downsample->methods[ci] = int_downsample;
548
53.1k
    } else
549
0
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
550
463k
  }
551
552
179k
#ifdef INPUT_SMOOTHING_SUPPORTED
553
179k
  if (cinfo->smoothing_factor && !smoothok)
554
0
    TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
555
179k
#endif
556
179k
}
jinit_downsampler
Line
Count
Source
468
98.5k
{
469
98.5k
  my_downsample_ptr downsample;
470
98.5k
  int ci;
471
98.5k
  jpeg_component_info *compptr;
472
98.5k
#ifdef INPUT_SMOOTHING_SUPPORTED
473
98.5k
  boolean smoothok = TRUE;
474
98.5k
#endif
475
476
98.5k
#ifdef C_LOSSLESS_SUPPORTED
477
98.5k
  if (cinfo->master->lossless) {
478
28.9k
#if BITS_IN_JSAMPLE == 8
479
28.9k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
480
#else
481
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
482
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
483
#endif
484
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
485
28.9k
  } else
486
69.5k
#endif
487
69.5k
  {
488
69.5k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
489
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
490
69.5k
  }
491
492
98.5k
  downsample = (my_downsample_ptr)
493
98.5k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
494
98.5k
                                sizeof(my_downsampler));
495
98.5k
  cinfo->downsample = (struct jpeg_downsampler *)downsample;
496
98.5k
  downsample->pub.start_pass = start_pass_downsample;
497
98.5k
  downsample->pub._downsample = sep_downsample;
498
98.5k
  downsample->pub.need_context_rows = FALSE;
499
500
98.5k
  if (cinfo->CCIR601_sampling)
501
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
502
503
  /* Verify we can handle the sampling factors, and set up method pointers */
504
345k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
505
247k
       ci++, compptr++) {
506
247k
    if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
507
183k
        compptr->v_samp_factor == cinfo->max_v_samp_factor) {
508
171k
#ifdef INPUT_SMOOTHING_SUPPORTED
509
171k
      if (cinfo->smoothing_factor) {
510
3.61k
        downsample->methods[ci] = fullsize_smooth_downsample;
511
3.61k
        downsample->pub.need_context_rows = TRUE;
512
3.61k
      } else
513
167k
#endif
514
167k
        downsample->methods[ci] = fullsize_downsample;
515
171k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
516
43.2k
               compptr->v_samp_factor == cinfo->max_v_samp_factor) {
517
20.7k
#ifdef INPUT_SMOOTHING_SUPPORTED
518
20.7k
      smoothok = FALSE;
519
20.7k
#endif
520
20.7k
#ifdef WITH_SIMD
521
20.7k
      if (jsimd_set_h2v1_downsample(cinfo))
522
20.7k
        downsample->methods[ci] = jsimd_h2v1_downsample;
523
0
      else
524
0
#endif
525
0
        downsample->methods[ci] = h2v1_downsample;
526
55.0k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
527
22.4k
               compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
528
22.4k
#ifdef INPUT_SMOOTHING_SUPPORTED
529
22.4k
      if (cinfo->smoothing_factor) {
530
4.12k
        downsample->methods[ci] = h2v2_smooth_downsample;
531
4.12k
        downsample->pub.need_context_rows = TRUE;
532
4.12k
      } else
533
18.3k
#endif
534
18.3k
      {
535
18.3k
#ifdef WITH_SIMD
536
18.3k
        if (jsimd_set_h2v2_downsample(cinfo))
537
18.3k
          downsample->methods[ci] = jsimd_h2v2_downsample;
538
0
        else
539
0
#endif
540
0
          downsample->methods[ci] = h2v2_downsample;
541
18.3k
      }
542
32.6k
    } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
543
32.6k
               (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
544
32.6k
#ifdef INPUT_SMOOTHING_SUPPORTED
545
32.6k
      smoothok = FALSE;
546
32.6k
#endif
547
32.6k
      downsample->methods[ci] = int_downsample;
548
32.6k
    } else
549
0
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
550
247k
  }
551
552
98.5k
#ifdef INPUT_SMOOTHING_SUPPORTED
553
98.5k
  if (cinfo->smoothing_factor && !smoothok)
554
0
    TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
555
98.5k
#endif
556
98.5k
}
j12init_downsampler
Line
Count
Source
468
59.4k
{
469
59.4k
  my_downsample_ptr downsample;
470
59.4k
  int ci;
471
59.4k
  jpeg_component_info *compptr;
472
59.4k
#ifdef INPUT_SMOOTHING_SUPPORTED
473
59.4k
  boolean smoothok = TRUE;
474
59.4k
#endif
475
476
59.4k
#ifdef C_LOSSLESS_SUPPORTED
477
59.4k
  if (cinfo->master->lossless) {
478
#if BITS_IN_JSAMPLE == 8
479
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
480
#else
481
22.6k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
482
22.6k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
483
0
#endif
484
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
485
22.6k
  } else
486
36.8k
#endif
487
36.8k
  {
488
36.8k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
489
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
490
36.8k
  }
491
492
59.4k
  downsample = (my_downsample_ptr)
493
59.4k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
494
59.4k
                                sizeof(my_downsampler));
495
59.4k
  cinfo->downsample = (struct jpeg_downsampler *)downsample;
496
59.4k
  downsample->pub.start_pass = start_pass_downsample;
497
59.4k
  downsample->pub._downsample = sep_downsample;
498
59.4k
  downsample->pub.need_context_rows = FALSE;
499
500
59.4k
  if (cinfo->CCIR601_sampling)
501
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
502
503
  /* Verify we can handle the sampling factors, and set up method pointers */
504
216k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
505
156k
       ci++, compptr++) {
506
156k
    if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
507
125k
        compptr->v_samp_factor == cinfo->max_v_samp_factor) {
508
115k
#ifdef INPUT_SMOOTHING_SUPPORTED
509
115k
      if (cinfo->smoothing_factor) {
510
0
        downsample->methods[ci] = fullsize_smooth_downsample;
511
0
        downsample->pub.need_context_rows = TRUE;
512
0
      } else
513
115k
#endif
514
115k
        downsample->methods[ci] = fullsize_downsample;
515
115k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
516
20.7k
               compptr->v_samp_factor == cinfo->max_v_samp_factor) {
517
10.5k
#ifdef INPUT_SMOOTHING_SUPPORTED
518
10.5k
      smoothok = FALSE;
519
10.5k
#endif
520
#ifdef WITH_SIMD
521
      if (jsimd_set_h2v1_downsample(cinfo))
522
        downsample->methods[ci] = jsimd_h2v1_downsample;
523
      else
524
#endif
525
10.5k
        downsample->methods[ci] = h2v1_downsample;
526
30.8k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
527
10.2k
               compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
528
10.2k
#ifdef INPUT_SMOOTHING_SUPPORTED
529
10.2k
      if (cinfo->smoothing_factor) {
530
0
        downsample->methods[ci] = h2v2_smooth_downsample;
531
0
        downsample->pub.need_context_rows = TRUE;
532
0
      } else
533
10.2k
#endif
534
10.2k
      {
535
#ifdef WITH_SIMD
536
        if (jsimd_set_h2v2_downsample(cinfo))
537
          downsample->methods[ci] = jsimd_h2v2_downsample;
538
        else
539
#endif
540
10.2k
          downsample->methods[ci] = h2v2_downsample;
541
10.2k
      }
542
20.5k
    } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
543
20.5k
               (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
544
20.5k
#ifdef INPUT_SMOOTHING_SUPPORTED
545
20.5k
      smoothok = FALSE;
546
20.5k
#endif
547
20.5k
      downsample->methods[ci] = int_downsample;
548
20.5k
    } else
549
0
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
550
156k
  }
551
552
59.4k
#ifdef INPUT_SMOOTHING_SUPPORTED
553
59.4k
  if (cinfo->smoothing_factor && !smoothok)
554
0
    TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
555
59.4k
#endif
556
59.4k
}
j16init_downsampler
Line
Count
Source
468
21.1k
{
469
21.1k
  my_downsample_ptr downsample;
470
21.1k
  int ci;
471
21.1k
  jpeg_component_info *compptr;
472
21.1k
#ifdef INPUT_SMOOTHING_SUPPORTED
473
21.1k
  boolean smoothok = TRUE;
474
21.1k
#endif
475
476
21.1k
#ifdef C_LOSSLESS_SUPPORTED
477
21.1k
  if (cinfo->master->lossless) {
478
#if BITS_IN_JSAMPLE == 8
479
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
480
#else
481
21.1k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
482
21.1k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
483
0
#endif
484
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
485
21.1k
  } else
486
0
#endif
487
0
  {
488
0
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
489
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
490
0
  }
491
492
21.1k
  downsample = (my_downsample_ptr)
493
21.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
494
21.1k
                                sizeof(my_downsampler));
495
21.1k
  cinfo->downsample = (struct jpeg_downsampler *)downsample;
496
21.1k
  downsample->pub.start_pass = start_pass_downsample;
497
21.1k
  downsample->pub._downsample = sep_downsample;
498
21.1k
  downsample->pub.need_context_rows = FALSE;
499
500
21.1k
  if (cinfo->CCIR601_sampling)
501
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
502
503
  /* Verify we can handle the sampling factors, and set up method pointers */
504
80.2k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
505
59.1k
       ci++, compptr++) {
506
59.1k
    if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
507
59.1k
        compptr->v_samp_factor == cinfo->max_v_samp_factor) {
508
59.1k
#ifdef INPUT_SMOOTHING_SUPPORTED
509
59.1k
      if (cinfo->smoothing_factor) {
510
0
        downsample->methods[ci] = fullsize_smooth_downsample;
511
0
        downsample->pub.need_context_rows = TRUE;
512
0
      } else
513
59.1k
#endif
514
59.1k
        downsample->methods[ci] = fullsize_downsample;
515
59.1k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
516
0
               compptr->v_samp_factor == cinfo->max_v_samp_factor) {
517
0
#ifdef INPUT_SMOOTHING_SUPPORTED
518
0
      smoothok = FALSE;
519
0
#endif
520
#ifdef WITH_SIMD
521
      if (jsimd_set_h2v1_downsample(cinfo))
522
        downsample->methods[ci] = jsimd_h2v1_downsample;
523
      else
524
#endif
525
0
        downsample->methods[ci] = h2v1_downsample;
526
0
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
527
0
               compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
528
0
#ifdef INPUT_SMOOTHING_SUPPORTED
529
0
      if (cinfo->smoothing_factor) {
530
0
        downsample->methods[ci] = h2v2_smooth_downsample;
531
0
        downsample->pub.need_context_rows = TRUE;
532
0
      } else
533
0
#endif
534
0
      {
535
#ifdef WITH_SIMD
536
        if (jsimd_set_h2v2_downsample(cinfo))
537
          downsample->methods[ci] = jsimd_h2v2_downsample;
538
        else
539
#endif
540
0
          downsample->methods[ci] = h2v2_downsample;
541
0
      }
542
0
    } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
543
0
               (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
544
0
#ifdef INPUT_SMOOTHING_SUPPORTED
545
0
      smoothok = FALSE;
546
0
#endif
547
0
      downsample->methods[ci] = int_downsample;
548
0
    } else
549
0
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
550
59.1k
  }
551
552
21.1k
#ifdef INPUT_SMOOTHING_SUPPORTED
553
21.1k
  if (cinfo->smoothing_factor && !smoothok)
554
0
    TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
555
21.1k
#endif
556
21.1k
}
557
558
#endif /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */