Coverage Report

Created: 2026-04-12 06:05

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
141k
{
90
  /* no work for now */
91
141k
}
jcsample-8.c:start_pass_downsample
Line
Count
Source
89
68.7k
{
90
  /* no work for now */
91
68.7k
}
jcsample-12.c:start_pass_downsample
Line
Count
Source
89
52.6k
{
90
  /* no work for now */
91
52.6k
}
jcsample-16.c:start_pass_downsample
Line
Count
Source
89
20.1k
{
90
  /* no work for now */
91
20.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
519M
{
103
519M
  register _JSAMPROW ptr;
104
519M
  register _JSAMPLE pixval;
105
519M
  register int count;
106
519M
  int row;
107
519M
  int numcols = (int)(output_cols - input_cols);
108
109
519M
  if (numcols > 0) {
110
728M
    for (row = 0; row < num_rows; row++) {
111
402M
      ptr = image_data[row] + input_cols;
112
402M
      pixval = ptr[-1];
113
4.75G
      for (count = numcols; count > 0; count--)
114
4.34G
        *ptr++ = pixval;
115
402M
    }
116
325M
  }
117
519M
}
jcsample-8.c:expand_right_edge
Line
Count
Source
102
278M
{
103
278M
  register _JSAMPROW ptr;
104
278M
  register _JSAMPLE pixval;
105
278M
  register int count;
106
278M
  int row;
107
278M
  int numcols = (int)(output_cols - input_cols);
108
109
278M
  if (numcols > 0) {
110
467M
    for (row = 0; row < num_rows; row++) {
111
258M
      ptr = image_data[row] + input_cols;
112
258M
      pixval = ptr[-1];
113
3.02G
      for (count = numcols; count > 0; count--)
114
2.76G
        *ptr++ = pixval;
115
258M
    }
116
209M
  }
117
278M
}
jcsample-12.c:expand_right_edge
Line
Count
Source
102
181M
{
103
181M
  register _JSAMPROW ptr;
104
181M
  register _JSAMPLE pixval;
105
181M
  register int count;
106
181M
  int row;
107
181M
  int numcols = (int)(output_cols - input_cols);
108
109
181M
  if (numcols > 0) {
110
260M
    for (row = 0; row < num_rows; row++) {
111
144M
      ptr = image_data[row] + input_cols;
112
144M
      pixval = ptr[-1];
113
1.72G
      for (count = numcols; count > 0; count--)
114
1.58G
        *ptr++ = pixval;
115
144M
    }
116
116M
  }
117
181M
}
jcsample-16.c:expand_right_edge
Line
Count
Source
102
59.6M
{
103
59.6M
  register _JSAMPROW ptr;
104
59.6M
  register _JSAMPLE pixval;
105
59.6M
  register int count;
106
59.6M
  int row;
107
59.6M
  int numcols = (int)(output_cols - input_cols);
108
109
59.6M
  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
59.6M
}
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
225M
{
131
225M
  my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample;
132
225M
  int ci;
133
225M
  jpeg_component_info *compptr;
134
225M
  _JSAMPARRAY in_ptr, out_ptr;
135
136
806M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
137
580M
       ci++, compptr++) {
138
580M
    in_ptr = input_buf[ci] + in_row_index;
139
580M
    out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
140
580M
    (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
141
580M
  }
142
225M
}
jcsample-8.c:sep_downsample
Line
Count
Source
130
134M
{
131
134M
  my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample;
132
134M
  int ci;
133
134M
  jpeg_component_info *compptr;
134
134M
  _JSAMPARRAY in_ptr, out_ptr;
135
136
473M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
137
339M
       ci++, compptr++) {
138
339M
    in_ptr = input_buf[ci] + in_row_index;
139
339M
    out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
140
339M
    (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
141
339M
  }
142
134M
}
jcsample-12.c:sep_downsample
Line
Count
Source
130
70.3M
{
131
70.3M
  my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample;
132
70.3M
  int ci;
133
70.3M
  jpeg_component_info *compptr;
134
70.3M
  _JSAMPARRAY in_ptr, out_ptr;
135
136
251M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
137
181M
       ci++, compptr++) {
138
181M
    in_ptr = input_buf[ci] + in_row_index;
139
181M
    out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
140
181M
    (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
141
181M
  }
142
70.3M
}
jcsample-16.c:sep_downsample
Line
Count
Source
130
20.8M
{
131
20.8M
  my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample;
132
20.8M
  int ci;
133
20.8M
  jpeg_component_info *compptr;
134
20.8M
  _JSAMPARRAY in_ptr, out_ptr;
135
136
80.4M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
137
59.6M
       ci++, compptr++) {
138
59.6M
    in_ptr = input_buf[ci] + in_row_index;
139
59.6M
    out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
140
59.6M
    (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
141
59.6M
  }
142
20.8M
}
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
77.6M
{
156
77.6M
  int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
157
77.6M
  JDIMENSION outcol, outcol_h;  /* outcol_h == outcol*h_expand */
158
77.6M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
159
77.6M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
160
77.6M
  _JSAMPROW inptr, outptr;
161
77.6M
  JLONG outvalue;
162
163
77.6M
  h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
164
77.6M
  v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
165
77.6M
  numpix = h_expand * v_expand;
166
77.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
77.6M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
173
77.6M
                    output_cols * h_expand);
174
175
77.6M
  inrow = 0;
176
157M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
177
79.4M
    outptr = output_data[outrow];
178
887M
    for (outcol = 0, outcol_h = 0; outcol < output_cols;
179
808M
         outcol++, outcol_h += h_expand) {
180
808M
      outvalue = 0;
181
1.89G
      for (v = 0; v < v_expand; v++) {
182
1.08G
        inptr = input_data[inrow + v] + outcol_h;
183
3.76G
        for (h = 0; h < h_expand; h++) {
184
2.67G
          outvalue += (JLONG)(*inptr++);
185
2.67G
        }
186
1.08G
      }
187
808M
      *outptr++ = (_JSAMPLE)((outvalue + numpix2) / numpix);
188
808M
    }
189
79.4M
    inrow += v_expand;
190
79.4M
  }
191
77.6M
}
jcsample-8.c:int_downsample
Line
Count
Source
155
53.4M
{
156
53.4M
  int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
157
53.4M
  JDIMENSION outcol, outcol_h;  /* outcol_h == outcol*h_expand */
158
53.4M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
159
53.4M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
160
53.4M
  _JSAMPROW inptr, outptr;
161
53.4M
  JLONG outvalue;
162
163
53.4M
  h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
164
53.4M
  v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
165
53.4M
  numpix = h_expand * v_expand;
166
53.4M
  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
53.4M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
173
53.4M
                    output_cols * h_expand);
174
175
53.4M
  inrow = 0;
176
108M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
177
55.1M
    outptr = output_data[outrow];
178
604M
    for (outcol = 0, outcol_h = 0; outcol < output_cols;
179
549M
         outcol++, outcol_h += h_expand) {
180
549M
      outvalue = 0;
181
1.27G
      for (v = 0; v < v_expand; v++) {
182
721M
        inptr = input_data[inrow + v] + outcol_h;
183
2.57G
        for (h = 0; h < h_expand; h++) {
184
1.85G
          outvalue += (JLONG)(*inptr++);
185
1.85G
        }
186
721M
      }
187
549M
      *outptr++ = (_JSAMPLE)((outvalue + numpix2) / numpix);
188
549M
    }
189
55.1M
    inrow += v_expand;
190
55.1M
  }
191
53.4M
}
jcsample-12.c:int_downsample
Line
Count
Source
155
24.2M
{
156
24.2M
  int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
157
24.2M
  JDIMENSION outcol, outcol_h;  /* outcol_h == outcol*h_expand */
158
24.2M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
159
24.2M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
160
24.2M
  _JSAMPROW inptr, outptr;
161
24.2M
  JLONG outvalue;
162
163
24.2M
  h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
164
24.2M
  v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
165
24.2M
  numpix = h_expand * v_expand;
166
24.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
24.2M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
173
24.2M
                    output_cols * h_expand);
174
175
24.2M
  inrow = 0;
176
48.5M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
177
24.2M
    outptr = output_data[outrow];
178
282M
    for (outcol = 0, outcol_h = 0; outcol < output_cols;
179
258M
         outcol++, outcol_h += h_expand) {
180
258M
      outvalue = 0;
181
625M
      for (v = 0; v < v_expand; v++) {
182
367M
        inptr = input_data[inrow + v] + outcol_h;
183
1.18G
        for (h = 0; h < h_expand; h++) {
184
815M
          outvalue += (JLONG)(*inptr++);
185
815M
        }
186
367M
      }
187
258M
      *outptr++ = (_JSAMPLE)((outvalue + numpix2) / numpix);
188
258M
    }
189
24.2M
    inrow += v_expand;
190
24.2M
  }
191
24.2M
}
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
412M
{
204
412M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
205
206
  /* Copy the data */
207
412M
  _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
208
412M
                     cinfo->image_width);
209
  /* Edge-expand */
210
412M
  expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
211
412M
                    compptr->width_in_blocks * data_unit);
212
412M
}
jcsample-8.c:fullsize_downsample
Line
Count
Source
203
219M
{
204
219M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
205
206
  /* Copy the data */
207
219M
  _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
208
219M
                     cinfo->image_width);
209
  /* Edge-expand */
210
219M
  expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
211
219M
                    compptr->width_in_blocks * data_unit);
212
219M
}
jcsample-12.c:fullsize_downsample
Line
Count
Source
203
132M
{
204
132M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
205
206
  /* Copy the data */
207
132M
  _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
208
132M
                     cinfo->image_width);
209
  /* Edge-expand */
210
132M
  expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
211
132M
                    compptr->width_in_blocks * data_unit);
212
132M
}
jcsample-16.c:fullsize_downsample
Line
Count
Source
203
59.6M
{
204
59.6M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
205
206
  /* Copy the data */
207
59.6M
  _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
208
59.6M
                     cinfo->image_width);
209
  /* Edge-expand */
210
59.6M
  expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
211
59.6M
                    compptr->width_in_blocks * data_unit);
212
59.6M
}
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
16.1M
{
231
16.1M
  int outrow;
232
16.1M
  JDIMENSION outcol;
233
16.1M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
234
16.1M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
235
16.1M
  register _JSAMPROW inptr, outptr;
236
16.1M
  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
16.1M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
243
16.1M
                    output_cols * 2);
244
245
32.3M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
246
16.1M
    outptr = output_data[outrow];
247
16.1M
    inptr = input_data[outrow];
248
16.1M
    bias = 0;                   /* bias = 0,1,0,1,... for successive samples */
249
185M
    for (outcol = 0; outcol < output_cols; outcol++) {
250
169M
      *outptr++ = (_JSAMPLE)((inptr[0] + inptr[1] + bias) >> 1);
251
169M
      bias ^= 1;                /* 0=>1, 1=>0 */
252
169M
      inptr += 2;
253
169M
    }
254
16.1M
  }
255
16.1M
}
Unexecuted instantiation: jcsample-8.c:h2v1_downsample
jcsample-12.c:h2v1_downsample
Line
Count
Source
230
16.1M
{
231
16.1M
  int outrow;
232
16.1M
  JDIMENSION outcol;
233
16.1M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
234
16.1M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
235
16.1M
  register _JSAMPROW inptr, outptr;
236
16.1M
  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
16.1M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
243
16.1M
                    output_cols * 2);
244
245
32.3M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
246
16.1M
    outptr = output_data[outrow];
247
16.1M
    inptr = input_data[outrow];
248
16.1M
    bias = 0;                   /* bias = 0,1,0,1,... for successive samples */
249
185M
    for (outcol = 0; outcol < output_cols; outcol++) {
250
169M
      *outptr++ = (_JSAMPLE)((inptr[0] + inptr[1] + bias) >> 1);
251
169M
      bias ^= 1;                /* 0=>1, 1=>0 */
252
169M
      inptr += 2;
253
169M
    }
254
16.1M
  }
255
16.1M
}
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
8.09M
{
268
8.09M
  int inrow, outrow;
269
8.09M
  JDIMENSION outcol;
270
8.09M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
271
8.09M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
272
8.09M
  register _JSAMPROW inptr0, inptr1, outptr;
273
8.09M
  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
8.09M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
280
8.09M
                    output_cols * 2);
281
282
8.09M
  inrow = 0;
283
16.1M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
284
8.09M
    outptr = output_data[outrow];
285
8.09M
    inptr0 = input_data[inrow];
286
8.09M
    inptr1 = input_data[inrow + 1];
287
8.09M
    bias = 1;                   /* bias = 1,2,1,2,... for successive samples */
288
94.9M
    for (outcol = 0; outcol < output_cols; outcol++) {
289
86.8M
      *outptr++ = (_JSAMPLE)
290
86.8M
        ((inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1] + bias) >> 2);
291
86.8M
      bias ^= 3;                /* 1=>2, 2=>1 */
292
86.8M
      inptr0 += 2;  inptr1 += 2;
293
86.8M
    }
294
8.09M
    inrow += 2;
295
8.09M
  }
296
8.09M
}
Unexecuted instantiation: jcsample-8.c:h2v2_downsample
jcsample-12.c:h2v2_downsample
Line
Count
Source
267
8.09M
{
268
8.09M
  int inrow, outrow;
269
8.09M
  JDIMENSION outcol;
270
8.09M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
271
8.09M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
272
8.09M
  register _JSAMPROW inptr0, inptr1, outptr;
273
8.09M
  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
8.09M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
280
8.09M
                    output_cols * 2);
281
282
8.09M
  inrow = 0;
283
16.1M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
284
8.09M
    outptr = output_data[outrow];
285
8.09M
    inptr0 = input_data[inrow];
286
8.09M
    inptr1 = input_data[inrow + 1];
287
8.09M
    bias = 1;                   /* bias = 1,2,1,2,... for successive samples */
288
94.9M
    for (outcol = 0; outcol < output_cols; outcol++) {
289
86.8M
      *outptr++ = (_JSAMPLE)
290
86.8M
        ((inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1] + bias) >> 2);
291
86.8M
      bias ^= 3;                /* 1=>2, 2=>1 */
292
86.8M
      inptr0 += 2;  inptr1 += 2;
293
86.8M
    }
294
8.09M
    inrow += 2;
295
8.09M
  }
296
8.09M
}
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
3.45M
{
311
3.45M
  int inrow, outrow;
312
3.45M
  JDIMENSION colctr;
313
3.45M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
314
3.45M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
315
3.45M
  register _JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
316
3.45M
  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
3.45M
  expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
323
3.45M
                    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
3.45M
  memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
339
3.45M
  neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
340
341
3.45M
  inrow = 0;
342
6.90M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
343
3.45M
    outptr = output_data[outrow];
344
3.45M
    inptr0 = input_data[inrow];
345
3.45M
    inptr1 = input_data[inrow + 1];
346
3.45M
    above_ptr = input_data[inrow - 1];
347
3.45M
    below_ptr = input_data[inrow + 2];
348
349
    /* Special case for first column: pretend column -1 is same as column 0 */
350
3.45M
    membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1];
351
3.45M
    neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] +
352
3.45M
               inptr0[0] + inptr0[2] + inptr1[0] + inptr1[2];
353
3.45M
    neighsum += neighsum;
354
3.45M
    neighsum += above_ptr[0] + above_ptr[2] + below_ptr[0] + below_ptr[2];
355
3.45M
    membersum = membersum * memberscale + neighsum * neighscale;
356
3.45M
    *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
357
3.45M
    inptr0 += 2;  inptr1 += 2;  above_ptr += 2;  below_ptr += 2;
358
359
70.4M
    for (colctr = output_cols - 2; colctr > 0; colctr--) {
360
      /* sum of components directly mapped to this output element */
361
67.0M
      membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1];
362
      /* sum of edge-neighbor components */
363
67.0M
      neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] +
364
67.0M
                 inptr0[-1] + inptr0[2] + inptr1[-1] + inptr1[2];
365
      /* The edge-neighbors count twice as much as corner-neighbors */
366
67.0M
      neighsum += neighsum;
367
      /* Add in the corner-neighbors */
368
67.0M
      neighsum += above_ptr[-1] + above_ptr[2] + below_ptr[-1] + below_ptr[2];
369
      /* form final output scaled up by 2^16 */
370
67.0M
      membersum = membersum * memberscale + neighsum * neighscale;
371
      /* round, descale and output it */
372
67.0M
      *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
373
67.0M
      inptr0 += 2;  inptr1 += 2;  above_ptr += 2;  below_ptr += 2;
374
67.0M
    }
375
376
    /* Special case for last column */
377
3.45M
    membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1];
378
3.45M
    neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] +
379
3.45M
               inptr0[-1] + inptr0[1] + inptr1[-1] + inptr1[1];
380
3.45M
    neighsum += neighsum;
381
3.45M
    neighsum += above_ptr[-1] + above_ptr[1] + below_ptr[-1] + below_ptr[1];
382
3.45M
    membersum = membersum * memberscale + neighsum * neighscale;
383
3.45M
    *outptr = (_JSAMPLE)((membersum + 32768) >> 16);
384
385
3.45M
    inrow += 2;
386
3.45M
  }
387
3.45M
}
jcsample-8.c:h2v2_smooth_downsample
Line
Count
Source
310
3.45M
{
311
3.45M
  int inrow, outrow;
312
3.45M
  JDIMENSION colctr;
313
3.45M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
314
3.45M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
315
3.45M
  register _JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
316
3.45M
  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
3.45M
  expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
323
3.45M
                    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
3.45M
  memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
339
3.45M
  neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
340
341
3.45M
  inrow = 0;
342
6.90M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
343
3.45M
    outptr = output_data[outrow];
344
3.45M
    inptr0 = input_data[inrow];
345
3.45M
    inptr1 = input_data[inrow + 1];
346
3.45M
    above_ptr = input_data[inrow - 1];
347
3.45M
    below_ptr = input_data[inrow + 2];
348
349
    /* Special case for first column: pretend column -1 is same as column 0 */
350
3.45M
    membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1];
351
3.45M
    neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] +
352
3.45M
               inptr0[0] + inptr0[2] + inptr1[0] + inptr1[2];
353
3.45M
    neighsum += neighsum;
354
3.45M
    neighsum += above_ptr[0] + above_ptr[2] + below_ptr[0] + below_ptr[2];
355
3.45M
    membersum = membersum * memberscale + neighsum * neighscale;
356
3.45M
    *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
357
3.45M
    inptr0 += 2;  inptr1 += 2;  above_ptr += 2;  below_ptr += 2;
358
359
70.4M
    for (colctr = output_cols - 2; colctr > 0; colctr--) {
360
      /* sum of components directly mapped to this output element */
361
67.0M
      membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1];
362
      /* sum of edge-neighbor components */
363
67.0M
      neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] +
364
67.0M
                 inptr0[-1] + inptr0[2] + inptr1[-1] + inptr1[2];
365
      /* The edge-neighbors count twice as much as corner-neighbors */
366
67.0M
      neighsum += neighsum;
367
      /* Add in the corner-neighbors */
368
67.0M
      neighsum += above_ptr[-1] + above_ptr[2] + below_ptr[-1] + below_ptr[2];
369
      /* form final output scaled up by 2^16 */
370
67.0M
      membersum = membersum * memberscale + neighsum * neighscale;
371
      /* round, descale and output it */
372
67.0M
      *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
373
67.0M
      inptr0 += 2;  inptr1 += 2;  above_ptr += 2;  below_ptr += 2;
374
67.0M
    }
375
376
    /* Special case for last column */
377
3.45M
    membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1];
378
3.45M
    neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] +
379
3.45M
               inptr0[-1] + inptr0[1] + inptr1[-1] + inptr1[1];
380
3.45M
    neighsum += neighsum;
381
3.45M
    neighsum += above_ptr[-1] + above_ptr[1] + below_ptr[-1] + below_ptr[1];
382
3.45M
    membersum = membersum * memberscale + neighsum * neighscale;
383
3.45M
    *outptr = (_JSAMPLE)((membersum + 32768) >> 16);
384
385
3.45M
    inrow += 2;
386
3.45M
  }
387
3.45M
}
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.10M
{
400
2.10M
  int outrow;
401
2.10M
  JDIMENSION colctr;
402
2.10M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
403
2.10M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
404
2.10M
  register _JSAMPROW inptr, above_ptr, below_ptr, outptr;
405
2.10M
  JLONG membersum, neighsum, memberscale, neighscale;
406
2.10M
  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.10M
  expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
413
2.10M
                    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.10M
  memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
422
2.10M
  neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
423
424
5.94M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
425
3.83M
    outptr = output_data[outrow];
426
3.83M
    inptr = input_data[outrow];
427
3.83M
    above_ptr = input_data[outrow - 1];
428
3.83M
    below_ptr = input_data[outrow + 1];
429
430
    /* Special case for first column */
431
3.83M
    colsum = (*above_ptr++) + (*below_ptr++) + inptr[0];
432
3.83M
    membersum = *inptr++;
433
3.83M
    nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0];
434
3.83M
    neighsum = colsum + (colsum - membersum) + nextcolsum;
435
3.83M
    membersum = membersum * memberscale + neighsum * neighscale;
436
3.83M
    *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
437
3.83M
    lastcolsum = colsum;  colsum = nextcolsum;
438
439
150M
    for (colctr = output_cols - 2; colctr > 0; colctr--) {
440
146M
      membersum = *inptr++;
441
146M
      above_ptr++;  below_ptr++;
442
146M
      nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0];
443
146M
      neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
444
146M
      membersum = membersum * memberscale + neighsum * neighscale;
445
146M
      *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
446
146M
      lastcolsum = colsum;  colsum = nextcolsum;
447
146M
    }
448
449
    /* Special case for last column */
450
3.83M
    membersum = *inptr;
451
3.83M
    neighsum = lastcolsum + (colsum - membersum) + colsum;
452
3.83M
    membersum = membersum * memberscale + neighsum * neighscale;
453
3.83M
    *outptr = (_JSAMPLE)((membersum + 32768) >> 16);
454
455
3.83M
  }
456
2.10M
}
jcsample-8.c:fullsize_smooth_downsample
Line
Count
Source
399
2.10M
{
400
2.10M
  int outrow;
401
2.10M
  JDIMENSION colctr;
402
2.10M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
403
2.10M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
404
2.10M
  register _JSAMPROW inptr, above_ptr, below_ptr, outptr;
405
2.10M
  JLONG membersum, neighsum, memberscale, neighscale;
406
2.10M
  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.10M
  expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
413
2.10M
                    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.10M
  memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
422
2.10M
  neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
423
424
5.94M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
425
3.83M
    outptr = output_data[outrow];
426
3.83M
    inptr = input_data[outrow];
427
3.83M
    above_ptr = input_data[outrow - 1];
428
3.83M
    below_ptr = input_data[outrow + 1];
429
430
    /* Special case for first column */
431
3.83M
    colsum = (*above_ptr++) + (*below_ptr++) + inptr[0];
432
3.83M
    membersum = *inptr++;
433
3.83M
    nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0];
434
3.83M
    neighsum = colsum + (colsum - membersum) + nextcolsum;
435
3.83M
    membersum = membersum * memberscale + neighsum * neighscale;
436
3.83M
    *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
437
3.83M
    lastcolsum = colsum;  colsum = nextcolsum;
438
439
150M
    for (colctr = output_cols - 2; colctr > 0; colctr--) {
440
146M
      membersum = *inptr++;
441
146M
      above_ptr++;  below_ptr++;
442
146M
      nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0];
443
146M
      neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
444
146M
      membersum = membersum * memberscale + neighsum * neighscale;
445
146M
      *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
446
146M
      lastcolsum = colsum;  colsum = nextcolsum;
447
146M
    }
448
449
    /* Special case for last column */
450
3.83M
    membersum = *inptr;
451
3.83M
    neighsum = lastcolsum + (colsum - membersum) + colsum;
452
3.83M
    membersum = membersum * memberscale + neighsum * neighscale;
453
3.83M
    *outptr = (_JSAMPLE)((membersum + 32768) >> 16);
454
455
3.83M
  }
456
2.10M
}
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
166k
{
469
166k
  my_downsample_ptr downsample;
470
166k
  int ci;
471
166k
  jpeg_component_info *compptr;
472
166k
#ifdef INPUT_SMOOTHING_SUPPORTED
473
166k
  boolean smoothok = TRUE;
474
166k
#endif
475
476
166k
#ifdef C_LOSSLESS_SUPPORTED
477
166k
  if (cinfo->master->lossless) {
478
#if BITS_IN_JSAMPLE == 8
479
24.6k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
480
#else
481
40.1k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
482
40.1k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
483
0
#endif
484
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
485
64.8k
  } else
486
101k
#endif
487
101k
  {
488
101k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
489
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
490
101k
  }
491
492
166k
  downsample = (my_downsample_ptr)
493
166k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
494
166k
                                sizeof(my_downsampler));
495
166k
  cinfo->downsample = (struct jpeg_downsampler *)downsample;
496
166k
  downsample->pub.start_pass = start_pass_downsample;
497
166k
  downsample->pub._downsample = sep_downsample;
498
166k
  downsample->pub.need_context_rows = FALSE;
499
500
166k
  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
597k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
505
430k
       ci++, compptr++) {
506
430k
    if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
507
339k
        compptr->v_samp_factor == cinfo->max_v_samp_factor) {
508
317k
#ifdef INPUT_SMOOTHING_SUPPORTED
509
317k
      if (cinfo->smoothing_factor) {
510
3.15k
        downsample->methods[ci] = fullsize_smooth_downsample;
511
3.15k
        downsample->pub.need_context_rows = TRUE;
512
3.15k
      } else
513
314k
#endif
514
314k
        downsample->methods[ci] = fullsize_downsample;
515
317k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
516
61.9k
               compptr->v_samp_factor == cinfo->max_v_samp_factor) {
517
30.3k
#ifdef INPUT_SMOOTHING_SUPPORTED
518
30.3k
      smoothok = FALSE;
519
30.3k
#endif
520
#ifdef WITH_SIMD
521
20.9k
      if (jsimd_set_h2v1_downsample(cinfo))
522
20.9k
        downsample->methods[ci] = jsimd_h2v1_downsample;
523
0
      else
524
0
#endif
525
0
        downsample->methods[ci] = h2v1_downsample;
526
82.6k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
527
31.5k
               compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
528
31.5k
#ifdef INPUT_SMOOTHING_SUPPORTED
529
31.5k
      if (cinfo->smoothing_factor) {
530
3.92k
        downsample->methods[ci] = h2v2_smooth_downsample;
531
3.92k
        downsample->pub.need_context_rows = TRUE;
532
3.92k
      } else
533
27.6k
#endif
534
27.6k
      {
535
#ifdef WITH_SIMD
536
18.5k
        if (jsimd_set_h2v2_downsample(cinfo))
537
18.5k
          downsample->methods[ci] = jsimd_h2v2_downsample;
538
0
        else
539
0
#endif
540
0
          downsample->methods[ci] = h2v2_downsample;
541
27.6k
      }
542
51.0k
    } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
543
51.0k
               (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
544
51.0k
#ifdef INPUT_SMOOTHING_SUPPORTED
545
51.0k
      smoothok = FALSE;
546
51.0k
#endif
547
51.0k
      downsample->methods[ci] = int_downsample;
548
51.0k
    } else
549
0
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
550
430k
  }
551
552
166k
#ifdef INPUT_SMOOTHING_SUPPORTED
553
166k
  if (cinfo->smoothing_factor && !smoothok)
554
0
    TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
555
166k
#endif
556
166k
}
jinit_downsampler
Line
Count
Source
468
93.4k
{
469
93.4k
  my_downsample_ptr downsample;
470
93.4k
  int ci;
471
93.4k
  jpeg_component_info *compptr;
472
93.4k
#ifdef INPUT_SMOOTHING_SUPPORTED
473
93.4k
  boolean smoothok = TRUE;
474
93.4k
#endif
475
476
93.4k
#ifdef C_LOSSLESS_SUPPORTED
477
93.4k
  if (cinfo->master->lossless) {
478
24.6k
#if BITS_IN_JSAMPLE == 8
479
24.6k
    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
24.6k
  } else
486
68.7k
#endif
487
68.7k
  {
488
68.7k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
489
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
490
68.7k
  }
491
492
93.4k
  downsample = (my_downsample_ptr)
493
93.4k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
494
93.4k
                                sizeof(my_downsampler));
495
93.4k
  cinfo->downsample = (struct jpeg_downsampler *)downsample;
496
93.4k
  downsample->pub.start_pass = start_pass_downsample;
497
93.4k
  downsample->pub._downsample = sep_downsample;
498
93.4k
  downsample->pub.need_context_rows = FALSE;
499
500
93.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
328k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
505
234k
       ci++, compptr++) {
506
234k
    if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
507
171k
        compptr->v_samp_factor == cinfo->max_v_samp_factor) {
508
158k
#ifdef INPUT_SMOOTHING_SUPPORTED
509
158k
      if (cinfo->smoothing_factor) {
510
3.15k
        downsample->methods[ci] = fullsize_smooth_downsample;
511
3.15k
        downsample->pub.need_context_rows = TRUE;
512
3.15k
      } else
513
155k
#endif
514
155k
        downsample->methods[ci] = fullsize_downsample;
515
158k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
516
43.4k
               compptr->v_samp_factor == cinfo->max_v_samp_factor) {
517
20.9k
#ifdef INPUT_SMOOTHING_SUPPORTED
518
20.9k
      smoothok = FALSE;
519
20.9k
#endif
520
20.9k
#ifdef WITH_SIMD
521
20.9k
      if (jsimd_set_h2v1_downsample(cinfo))
522
20.9k
        downsample->methods[ci] = jsimd_h2v1_downsample;
523
0
      else
524
0
#endif
525
0
        downsample->methods[ci] = h2v1_downsample;
526
55.1k
    } 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
3.92k
        downsample->methods[ci] = h2v2_smooth_downsample;
531
3.92k
        downsample->pub.need_context_rows = TRUE;
532
3.92k
      } else
533
18.5k
#endif
534
18.5k
      {
535
18.5k
#ifdef WITH_SIMD
536
18.5k
        if (jsimd_set_h2v2_downsample(cinfo))
537
18.5k
          downsample->methods[ci] = jsimd_h2v2_downsample;
538
0
        else
539
0
#endif
540
0
          downsample->methods[ci] = h2v2_downsample;
541
18.5k
      }
542
32.7k
    } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
543
32.7k
               (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
544
32.7k
#ifdef INPUT_SMOOTHING_SUPPORTED
545
32.7k
      smoothok = FALSE;
546
32.7k
#endif
547
32.7k
      downsample->methods[ci] = int_downsample;
548
32.7k
    } else
549
0
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
550
234k
  }
551
552
93.4k
#ifdef INPUT_SMOOTHING_SUPPORTED
553
93.4k
  if (cinfo->smoothing_factor && !smoothok)
554
0
    TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
555
93.4k
#endif
556
93.4k
}
j12init_downsampler
Line
Count
Source
468
52.6k
{
469
52.6k
  my_downsample_ptr downsample;
470
52.6k
  int ci;
471
52.6k
  jpeg_component_info *compptr;
472
52.6k
#ifdef INPUT_SMOOTHING_SUPPORTED
473
52.6k
  boolean smoothok = TRUE;
474
52.6k
#endif
475
476
52.6k
#ifdef C_LOSSLESS_SUPPORTED
477
52.6k
  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
19.9k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
482
19.9k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
483
0
#endif
484
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
485
19.9k
  } else
486
32.6k
#endif
487
32.6k
  {
488
32.6k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
489
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
490
32.6k
  }
491
492
52.6k
  downsample = (my_downsample_ptr)
493
52.6k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
494
52.6k
                                sizeof(my_downsampler));
495
52.6k
  cinfo->downsample = (struct jpeg_downsampler *)downsample;
496
52.6k
  downsample->pub.start_pass = start_pass_downsample;
497
52.6k
  downsample->pub._downsample = sep_downsample;
498
52.6k
  downsample->pub.need_context_rows = FALSE;
499
500
52.6k
  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
191k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
505
139k
       ci++, compptr++) {
506
139k
    if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
507
111k
        compptr->v_samp_factor == cinfo->max_v_samp_factor) {
508
102k
#ifdef INPUT_SMOOTHING_SUPPORTED
509
102k
      if (cinfo->smoothing_factor) {
510
0
        downsample->methods[ci] = fullsize_smooth_downsample;
511
0
        downsample->pub.need_context_rows = TRUE;
512
0
      } else
513
102k
#endif
514
102k
        downsample->methods[ci] = fullsize_downsample;
515
102k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
516
18.5k
               compptr->v_samp_factor == cinfo->max_v_samp_factor) {
517
9.39k
#ifdef INPUT_SMOOTHING_SUPPORTED
518
9.39k
      smoothok = FALSE;
519
9.39k
#endif
520
#ifdef WITH_SIMD
521
      if (jsimd_set_h2v1_downsample(cinfo))
522
        downsample->methods[ci] = jsimd_h2v1_downsample;
523
      else
524
#endif
525
9.39k
        downsample->methods[ci] = h2v1_downsample;
526
27.4k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
527
9.16k
               compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
528
9.16k
#ifdef INPUT_SMOOTHING_SUPPORTED
529
9.16k
      if (cinfo->smoothing_factor) {
530
0
        downsample->methods[ci] = h2v2_smooth_downsample;
531
0
        downsample->pub.need_context_rows = TRUE;
532
0
      } else
533
9.16k
#endif
534
9.16k
      {
535
#ifdef WITH_SIMD
536
        if (jsimd_set_h2v2_downsample(cinfo))
537
          downsample->methods[ci] = jsimd_h2v2_downsample;
538
        else
539
#endif
540
9.16k
          downsample->methods[ci] = h2v2_downsample;
541
9.16k
      }
542
18.3k
    } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
543
18.3k
               (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
544
18.3k
#ifdef INPUT_SMOOTHING_SUPPORTED
545
18.3k
      smoothok = FALSE;
546
18.3k
#endif
547
18.3k
      downsample->methods[ci] = int_downsample;
548
18.3k
    } else
549
0
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
550
139k
  }
551
552
52.6k
#ifdef INPUT_SMOOTHING_SUPPORTED
553
52.6k
  if (cinfo->smoothing_factor && !smoothok)
554
0
    TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
555
52.6k
#endif
556
52.6k
}
j16init_downsampler
Line
Count
Source
468
20.1k
{
469
20.1k
  my_downsample_ptr downsample;
470
20.1k
  int ci;
471
20.1k
  jpeg_component_info *compptr;
472
20.1k
#ifdef INPUT_SMOOTHING_SUPPORTED
473
20.1k
  boolean smoothok = TRUE;
474
20.1k
#endif
475
476
20.1k
#ifdef C_LOSSLESS_SUPPORTED
477
20.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
20.1k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
482
20.1k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
483
0
#endif
484
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
485
20.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
20.1k
  downsample = (my_downsample_ptr)
493
20.1k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
494
20.1k
                                sizeof(my_downsampler));
495
20.1k
  cinfo->downsample = (struct jpeg_downsampler *)downsample;
496
20.1k
  downsample->pub.start_pass = start_pass_downsample;
497
20.1k
  downsample->pub._downsample = sep_downsample;
498
20.1k
  downsample->pub.need_context_rows = FALSE;
499
500
20.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
76.7k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
505
56.6k
       ci++, compptr++) {
506
56.6k
    if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
507
56.6k
        compptr->v_samp_factor == cinfo->max_v_samp_factor) {
508
56.6k
#ifdef INPUT_SMOOTHING_SUPPORTED
509
56.6k
      if (cinfo->smoothing_factor) {
510
0
        downsample->methods[ci] = fullsize_smooth_downsample;
511
0
        downsample->pub.need_context_rows = TRUE;
512
0
      } else
513
56.6k
#endif
514
56.6k
        downsample->methods[ci] = fullsize_downsample;
515
56.6k
    } 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
56.6k
  }
551
552
20.1k
#ifdef INPUT_SMOOTHING_SUPPORTED
553
20.1k
  if (cinfo->smoothing_factor && !smoothok)
554
0
    TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
555
20.1k
#endif
556
20.1k
}
557
558
#endif /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */