Coverage Report

Created: 2026-02-26 07:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libjpeg-turbo.dev/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
93.5k
{
90
  /* no work for now */
91
93.5k
}
jcsample-8.c:start_pass_downsample
Line
Count
Source
89
44.8k
{
90
  /* no work for now */
91
44.8k
}
jcsample-12.c:start_pass_downsample
Line
Count
Source
89
37.4k
{
90
  /* no work for now */
91
37.4k
}
jcsample-16.c:start_pass_downsample
Line
Count
Source
89
11.2k
{
90
  /* no work for now */
91
11.2k
}
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
708M
{
103
708M
  register _JSAMPROW ptr;
104
708M
  register _JSAMPLE pixval;
105
708M
  register int count;
106
708M
  int row;
107
708M
  int numcols = (int)(output_cols - input_cols);
108
109
708M
  if (numcols > 0) {
110
991M
    for (row = 0; row < num_rows; row++) {
111
544M
      ptr = image_data[row] + input_cols;
112
544M
      pixval = ptr[-1];
113
6.37G
      for (count = numcols; count > 0; count--)
114
5.83G
        *ptr++ = pixval;
115
544M
    }
116
446M
  }
117
708M
}
jcsample-8.c:expand_right_edge
Line
Count
Source
102
344M
{
103
344M
  register _JSAMPROW ptr;
104
344M
  register _JSAMPLE pixval;
105
344M
  register int count;
106
344M
  int row;
107
344M
  int numcols = (int)(output_cols - input_cols);
108
109
344M
  if (numcols > 0) {
110
559M
    for (row = 0; row < num_rows; row++) {
111
305M
      ptr = image_data[row] + input_cols;
112
305M
      pixval = ptr[-1];
113
3.54G
      for (count = numcols; count > 0; count--)
114
3.23G
        *ptr++ = pixval;
115
305M
    }
116
254M
  }
117
344M
}
jcsample-12.c:expand_right_edge
Line
Count
Source
102
277M
{
103
277M
  register _JSAMPROW ptr;
104
277M
  register _JSAMPLE pixval;
105
277M
  register int count;
106
277M
  int row;
107
277M
  int numcols = (int)(output_cols - input_cols);
108
109
277M
  if (numcols > 0) {
110
431M
    for (row = 0; row < num_rows; row++) {
111
239M
      ptr = image_data[row] + input_cols;
112
239M
      pixval = ptr[-1];
113
2.83G
      for (count = numcols; count > 0; count--)
114
2.59G
        *ptr++ = pixval;
115
239M
    }
116
192M
  }
117
277M
}
jcsample-16.c:expand_right_edge
Line
Count
Source
102
86.0M
{
103
86.0M
  register _JSAMPROW ptr;
104
86.0M
  register _JSAMPLE pixval;
105
86.0M
  register int count;
106
86.0M
  int row;
107
86.0M
  int numcols = (int)(output_cols - input_cols);
108
109
86.0M
  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
86.0M
}
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
307M
{
131
307M
  my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample;
132
307M
  int ci;
133
307M
  jpeg_component_info *compptr;
134
307M
  _JSAMPARRAY in_ptr, out_ptr;
135
136
1.08G
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
137
782M
       ci++, compptr++) {
138
782M
    in_ptr = input_buf[ci] + in_row_index;
139
782M
    out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
140
782M
    (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
141
782M
  }
142
307M
}
jcsample-8.c:sep_downsample
Line
Count
Source
130
168M
{
131
168M
  my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample;
132
168M
  int ci;
133
168M
  jpeg_component_info *compptr;
134
168M
  _JSAMPARRAY in_ptr, out_ptr;
135
136
587M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
137
419M
       ci++, compptr++) {
138
419M
    in_ptr = input_buf[ci] + in_row_index;
139
419M
    out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
140
419M
    (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
141
419M
  }
142
168M
}
jcsample-12.c:sep_downsample
Line
Count
Source
130
108M
{
131
108M
  my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample;
132
108M
  int ci;
133
108M
  jpeg_component_info *compptr;
134
108M
  _JSAMPARRAY in_ptr, out_ptr;
135
136
386M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
137
277M
       ci++, compptr++) {
138
277M
    in_ptr = input_buf[ci] + in_row_index;
139
277M
    out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
140
277M
    (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
141
277M
  }
142
108M
}
jcsample-16.c:sep_downsample
Line
Count
Source
130
30.1M
{
131
30.1M
  my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample;
132
30.1M
  int ci;
133
30.1M
  jpeg_component_info *compptr;
134
30.1M
  _JSAMPARRAY in_ptr, out_ptr;
135
136
116M
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
137
86.0M
       ci++, compptr++) {
138
86.0M
    in_ptr = input_buf[ci] + in_row_index;
139
86.0M
    out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
140
86.0M
    (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
141
86.0M
  }
142
30.1M
}
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
102M
{
156
102M
  int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
157
102M
  JDIMENSION outcol, outcol_h;  /* outcol_h == outcol*h_expand */
158
102M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
159
102M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
160
102M
  _JSAMPROW inptr, outptr;
161
102M
  JLONG outvalue;
162
163
102M
  h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
164
102M
  v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
165
102M
  numpix = h_expand * v_expand;
166
102M
  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
102M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
173
102M
                    output_cols * h_expand);
174
175
102M
  inrow = 0;
176
206M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
177
104M
    outptr = output_data[outrow];
178
1.09G
    for (outcol = 0, outcol_h = 0; outcol < output_cols;
179
987M
         outcol++, outcol_h += h_expand) {
180
987M
      outvalue = 0;
181
2.28G
      for (v = 0; v < v_expand; v++) {
182
1.30G
        inptr = input_data[inrow + v] + outcol_h;
183
4.62G
        for (h = 0; h < h_expand; h++) {
184
3.32G
          outvalue += (JLONG)(*inptr++);
185
3.32G
        }
186
1.30G
      }
187
987M
      *outptr++ = (_JSAMPLE)((outvalue + numpix2) / numpix);
188
987M
    }
189
104M
    inrow += v_expand;
190
104M
  }
191
102M
}
jcsample-8.c:int_downsample
Line
Count
Source
155
62.2M
{
156
62.2M
  int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
157
62.2M
  JDIMENSION outcol, outcol_h;  /* outcol_h == outcol*h_expand */
158
62.2M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
159
62.2M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
160
62.2M
  _JSAMPROW inptr, outptr;
161
62.2M
  JLONG outvalue;
162
163
62.2M
  h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
164
62.2M
  v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
165
62.2M
  numpix = h_expand * v_expand;
166
62.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
62.2M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
173
62.2M
                    output_cols * h_expand);
174
175
62.2M
  inrow = 0;
176
126M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
177
63.9M
    outptr = output_data[outrow];
178
681M
    for (outcol = 0, outcol_h = 0; outcol < output_cols;
179
617M
         outcol++, outcol_h += h_expand) {
180
617M
      outvalue = 0;
181
1.40G
      for (v = 0; v < v_expand; v++) {
182
789M
        inptr = input_data[inrow + v] + outcol_h;
183
2.91G
        for (h = 0; h < h_expand; h++) {
184
2.12G
          outvalue += (JLONG)(*inptr++);
185
2.12G
        }
186
789M
      }
187
617M
      *outptr++ = (_JSAMPLE)((outvalue + numpix2) / numpix);
188
617M
    }
189
63.9M
    inrow += v_expand;
190
63.9M
  }
191
62.2M
}
jcsample-12.c:int_downsample
Line
Count
Source
155
40.0M
{
156
40.0M
  int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
157
40.0M
  JDIMENSION outcol, outcol_h;  /* outcol_h == outcol*h_expand */
158
40.0M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
159
40.0M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
160
40.0M
  _JSAMPROW inptr, outptr;
161
40.0M
  JLONG outvalue;
162
163
40.0M
  h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
164
40.0M
  v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
165
40.0M
  numpix = h_expand * v_expand;
166
40.0M
  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
40.0M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
173
40.0M
                    output_cols * h_expand);
174
175
40.0M
  inrow = 0;
176
80.1M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
177
40.0M
    outptr = output_data[outrow];
178
409M
    for (outcol = 0, outcol_h = 0; outcol < output_cols;
179
369M
         outcol++, outcol_h += h_expand) {
180
369M
      outvalue = 0;
181
880M
      for (v = 0; v < v_expand; v++) {
182
511M
        inptr = input_data[inrow + v] + outcol_h;
183
1.70G
        for (h = 0; h < h_expand; h++) {
184
1.19G
          outvalue += (JLONG)(*inptr++);
185
1.19G
        }
186
511M
      }
187
369M
      *outptr++ = (_JSAMPLE)((outvalue + numpix2) / numpix);
188
369M
    }
189
40.0M
    inrow += v_expand;
190
40.0M
  }
191
40.0M
}
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
560M
{
204
560M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
205
206
  /* Copy the data */
207
560M
  _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
208
560M
                     cinfo->image_width);
209
  /* Edge-expand */
210
560M
  expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
211
560M
                    compptr->width_in_blocks * data_unit);
212
560M
}
jcsample-8.c:fullsize_downsample
Line
Count
Source
203
277M
{
204
277M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
205
206
  /* Copy the data */
207
277M
  _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
208
277M
                     cinfo->image_width);
209
  /* Edge-expand */
210
277M
  expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
211
277M
                    compptr->width_in_blocks * data_unit);
212
277M
}
jcsample-12.c:fullsize_downsample
Line
Count
Source
203
197M
{
204
197M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
205
206
  /* Copy the data */
207
197M
  _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
208
197M
                     cinfo->image_width);
209
  /* Edge-expand */
210
197M
  expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
211
197M
                    compptr->width_in_blocks * data_unit);
212
197M
}
jcsample-16.c:fullsize_downsample
Line
Count
Source
203
86.0M
{
204
86.0M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
205
206
  /* Copy the data */
207
86.0M
  _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor,
208
86.0M
                     cinfo->image_width);
209
  /* Edge-expand */
210
86.0M
  expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,
211
86.0M
                    compptr->width_in_blocks * data_unit);
212
86.0M
}
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
26.7M
{
231
26.7M
  int outrow;
232
26.7M
  JDIMENSION outcol;
233
26.7M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
234
26.7M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
235
26.7M
  register _JSAMPROW inptr, outptr;
236
26.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
26.7M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
243
26.7M
                    output_cols * 2);
244
245
53.4M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
246
26.7M
    outptr = output_data[outrow];
247
26.7M
    inptr = input_data[outrow];
248
26.7M
    bias = 0;                   /* bias = 0,1,0,1,... for successive samples */
249
267M
    for (outcol = 0; outcol < output_cols; outcol++) {
250
241M
      *outptr++ = (_JSAMPLE)((inptr[0] + inptr[1] + bias) >> 1);
251
241M
      bias ^= 1;                /* 0=>1, 1=>0 */
252
241M
      inptr += 2;
253
241M
    }
254
26.7M
  }
255
26.7M
}
Unexecuted instantiation: jcsample-8.c:h2v1_downsample
jcsample-12.c:h2v1_downsample
Line
Count
Source
230
26.7M
{
231
26.7M
  int outrow;
232
26.7M
  JDIMENSION outcol;
233
26.7M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
234
26.7M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
235
26.7M
  register _JSAMPROW inptr, outptr;
236
26.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
26.7M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
243
26.7M
                    output_cols * 2);
244
245
53.4M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
246
26.7M
    outptr = output_data[outrow];
247
26.7M
    inptr = input_data[outrow];
248
26.7M
    bias = 0;                   /* bias = 0,1,0,1,... for successive samples */
249
267M
    for (outcol = 0; outcol < output_cols; outcol++) {
250
241M
      *outptr++ = (_JSAMPLE)((inptr[0] + inptr[1] + bias) >> 1);
251
241M
      bias ^= 1;                /* 0=>1, 1=>0 */
252
241M
      inptr += 2;
253
241M
    }
254
26.7M
  }
255
26.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
13.3M
{
268
13.3M
  int inrow, outrow;
269
13.3M
  JDIMENSION outcol;
270
13.3M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
271
13.3M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
272
13.3M
  register _JSAMPROW inptr0, inptr1, outptr;
273
13.3M
  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
13.3M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
280
13.3M
                    output_cols * 2);
281
282
13.3M
  inrow = 0;
283
26.7M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
284
13.3M
    outptr = output_data[outrow];
285
13.3M
    inptr0 = input_data[inrow];
286
13.3M
    inptr1 = input_data[inrow + 1];
287
13.3M
    bias = 1;                   /* bias = 1,2,1,2,... for successive samples */
288
137M
    for (outcol = 0; outcol < output_cols; outcol++) {
289
124M
      *outptr++ = (_JSAMPLE)
290
124M
        ((inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1] + bias) >> 2);
291
124M
      bias ^= 3;                /* 1=>2, 2=>1 */
292
124M
      inptr0 += 2;  inptr1 += 2;
293
124M
    }
294
13.3M
    inrow += 2;
295
13.3M
  }
296
13.3M
}
Unexecuted instantiation: jcsample-8.c:h2v2_downsample
jcsample-12.c:h2v2_downsample
Line
Count
Source
267
13.3M
{
268
13.3M
  int inrow, outrow;
269
13.3M
  JDIMENSION outcol;
270
13.3M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
271
13.3M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
272
13.3M
  register _JSAMPROW inptr0, inptr1, outptr;
273
13.3M
  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
13.3M
  expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width,
280
13.3M
                    output_cols * 2);
281
282
13.3M
  inrow = 0;
283
26.7M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
284
13.3M
    outptr = output_data[outrow];
285
13.3M
    inptr0 = input_data[inrow];
286
13.3M
    inptr1 = input_data[inrow + 1];
287
13.3M
    bias = 1;                   /* bias = 1,2,1,2,... for successive samples */
288
137M
    for (outcol = 0; outcol < output_cols; outcol++) {
289
124M
      *outptr++ = (_JSAMPLE)
290
124M
        ((inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1] + bias) >> 2);
291
124M
      bias ^= 3;                /* 1=>2, 2=>1 */
292
124M
      inptr0 += 2;  inptr1 += 2;
293
124M
    }
294
13.3M
    inrow += 2;
295
13.3M
  }
296
13.3M
}
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
67.5M
    for (colctr = output_cols - 2; colctr > 0; colctr--) {
360
      /* sum of components directly mapped to this output element */
361
64.0M
      membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1];
362
      /* sum of edge-neighbor components */
363
64.0M
      neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] +
364
64.0M
                 inptr0[-1] + inptr0[2] + inptr1[-1] + inptr1[2];
365
      /* The edge-neighbors count twice as much as corner-neighbors */
366
64.0M
      neighsum += neighsum;
367
      /* Add in the corner-neighbors */
368
64.0M
      neighsum += above_ptr[-1] + above_ptr[2] + below_ptr[-1] + below_ptr[2];
369
      /* form final output scaled up by 2^16 */
370
64.0M
      membersum = membersum * memberscale + neighsum * neighscale;
371
      /* round, descale and output it */
372
64.0M
      *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
373
64.0M
      inptr0 += 2;  inptr1 += 2;  above_ptr += 2;  below_ptr += 2;
374
64.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
67.5M
    for (colctr = output_cols - 2; colctr > 0; colctr--) {
360
      /* sum of components directly mapped to this output element */
361
64.0M
      membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1];
362
      /* sum of edge-neighbor components */
363
64.0M
      neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] +
364
64.0M
                 inptr0[-1] + inptr0[2] + inptr1[-1] + inptr1[2];
365
      /* The edge-neighbors count twice as much as corner-neighbors */
366
64.0M
      neighsum += neighsum;
367
      /* Add in the corner-neighbors */
368
64.0M
      neighsum += above_ptr[-1] + above_ptr[2] + below_ptr[-1] + below_ptr[2];
369
      /* form final output scaled up by 2^16 */
370
64.0M
      membersum = membersum * memberscale + neighsum * neighscale;
371
      /* round, descale and output it */
372
64.0M
      *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
373
64.0M
      inptr0 += 2;  inptr1 += 2;  above_ptr += 2;  below_ptr += 2;
374
64.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.01M
{
400
2.01M
  int outrow;
401
2.01M
  JDIMENSION colctr;
402
2.01M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
403
2.01M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
404
2.01M
  register _JSAMPROW inptr, above_ptr, below_ptr, outptr;
405
2.01M
  JLONG membersum, neighsum, memberscale, neighscale;
406
2.01M
  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.01M
  expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
413
2.01M
                    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.01M
  memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
422
2.01M
  neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
423
424
5.76M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
425
3.74M
    outptr = output_data[outrow];
426
3.74M
    inptr = input_data[outrow];
427
3.74M
    above_ptr = input_data[outrow - 1];
428
3.74M
    below_ptr = input_data[outrow + 1];
429
430
    /* Special case for first column */
431
3.74M
    colsum = (*above_ptr++) + (*below_ptr++) + inptr[0];
432
3.74M
    membersum = *inptr++;
433
3.74M
    nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0];
434
3.74M
    neighsum = colsum + (colsum - membersum) + nextcolsum;
435
3.74M
    membersum = membersum * memberscale + neighsum * neighscale;
436
3.74M
    *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
437
3.74M
    lastcolsum = colsum;  colsum = nextcolsum;
438
439
147M
    for (colctr = output_cols - 2; colctr > 0; colctr--) {
440
143M
      membersum = *inptr++;
441
143M
      above_ptr++;  below_ptr++;
442
143M
      nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0];
443
143M
      neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
444
143M
      membersum = membersum * memberscale + neighsum * neighscale;
445
143M
      *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
446
143M
      lastcolsum = colsum;  colsum = nextcolsum;
447
143M
    }
448
449
    /* Special case for last column */
450
3.74M
    membersum = *inptr;
451
3.74M
    neighsum = lastcolsum + (colsum - membersum) + colsum;
452
3.74M
    membersum = membersum * memberscale + neighsum * neighscale;
453
3.74M
    *outptr = (_JSAMPLE)((membersum + 32768) >> 16);
454
455
3.74M
  }
456
2.01M
}
jcsample-8.c:fullsize_smooth_downsample
Line
Count
Source
399
2.01M
{
400
2.01M
  int outrow;
401
2.01M
  JDIMENSION colctr;
402
2.01M
  int data_unit = cinfo->master->lossless ? 1 : DCTSIZE;
403
2.01M
  JDIMENSION output_cols = compptr->width_in_blocks * data_unit;
404
2.01M
  register _JSAMPROW inptr, above_ptr, below_ptr, outptr;
405
2.01M
  JLONG membersum, neighsum, memberscale, neighscale;
406
2.01M
  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.01M
  expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
413
2.01M
                    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.01M
  memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
422
2.01M
  neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
423
424
5.76M
  for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
425
3.74M
    outptr = output_data[outrow];
426
3.74M
    inptr = input_data[outrow];
427
3.74M
    above_ptr = input_data[outrow - 1];
428
3.74M
    below_ptr = input_data[outrow + 1];
429
430
    /* Special case for first column */
431
3.74M
    colsum = (*above_ptr++) + (*below_ptr++) + inptr[0];
432
3.74M
    membersum = *inptr++;
433
3.74M
    nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0];
434
3.74M
    neighsum = colsum + (colsum - membersum) + nextcolsum;
435
3.74M
    membersum = membersum * memberscale + neighsum * neighscale;
436
3.74M
    *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
437
3.74M
    lastcolsum = colsum;  colsum = nextcolsum;
438
439
147M
    for (colctr = output_cols - 2; colctr > 0; colctr--) {
440
143M
      membersum = *inptr++;
441
143M
      above_ptr++;  below_ptr++;
442
143M
      nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0];
443
143M
      neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
444
143M
      membersum = membersum * memberscale + neighsum * neighscale;
445
143M
      *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16);
446
143M
      lastcolsum = colsum;  colsum = nextcolsum;
447
143M
    }
448
449
    /* Special case for last column */
450
3.74M
    membersum = *inptr;
451
3.74M
    neighsum = lastcolsum + (colsum - membersum) + colsum;
452
3.74M
    membersum = membersum * memberscale + neighsum * neighscale;
453
3.74M
    *outptr = (_JSAMPLE)((membersum + 32768) >> 16);
454
455
3.74M
  }
456
2.01M
}
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
113k
{
469
113k
  my_downsample_ptr downsample;
470
113k
  int ci;
471
113k
  jpeg_component_info *compptr;
472
113k
  boolean smoothok = TRUE;
473
474
113k
#ifdef C_LOSSLESS_SUPPORTED
475
113k
  if (cinfo->master->lossless) {
476
#if BITS_IN_JSAMPLE == 8
477
12.9k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
478
#else
479
22.1k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
480
22.1k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
481
0
#endif
482
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
483
35.1k
  } else
484
78.5k
#endif
485
78.5k
  {
486
78.5k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
487
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
488
78.5k
  }
489
490
113k
  downsample = (my_downsample_ptr)
491
113k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
492
113k
                                sizeof(my_downsampler));
493
113k
  cinfo->downsample = (struct jpeg_downsampler *)downsample;
494
113k
  downsample->pub.start_pass = start_pass_downsample;
495
113k
  downsample->pub._downsample = sep_downsample;
496
113k
  downsample->pub.need_context_rows = FALSE;
497
498
113k
  if (cinfo->CCIR601_sampling)
499
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
500
501
  /* Verify we can handle the sampling factors, and set up method pointers */
502
408k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
503
294k
       ci++, compptr++) {
504
294k
    if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
505
222k
        compptr->v_samp_factor == cinfo->max_v_samp_factor) {
506
205k
#ifdef INPUT_SMOOTHING_SUPPORTED
507
205k
      if (cinfo->smoothing_factor) {
508
2.66k
        downsample->methods[ci] = fullsize_smooth_downsample;
509
2.66k
        downsample->pub.need_context_rows = TRUE;
510
2.66k
      } else
511
202k
#endif
512
202k
        downsample->methods[ci] = fullsize_downsample;
513
205k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
514
49.0k
               compptr->v_samp_factor == cinfo->max_v_samp_factor) {
515
23.7k
      smoothok = FALSE;
516
#ifdef WITH_SIMD
517
16.1k
      if (jsimd_set_h2v1_downsample(cinfo))
518
16.1k
        downsample->methods[ci] = jsimd_h2v1_downsample;
519
0
      else
520
0
#endif
521
0
        downsample->methods[ci] = h2v1_downsample;
522
65.4k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
523
25.2k
               compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
524
25.2k
#ifdef INPUT_SMOOTHING_SUPPORTED
525
25.2k
      if (cinfo->smoothing_factor) {
526
3.48k
        downsample->methods[ci] = h2v2_smooth_downsample;
527
3.48k
        downsample->pub.need_context_rows = TRUE;
528
3.48k
      } else
529
21.7k
#endif
530
21.7k
      {
531
#ifdef WITH_SIMD
532
14.2k
        if (jsimd_set_h2v2_downsample(cinfo))
533
14.2k
          downsample->methods[ci] = jsimd_h2v2_downsample;
534
0
        else
535
0
#endif
536
0
          downsample->methods[ci] = h2v2_downsample;
537
21.7k
      }
538
40.2k
    } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
539
40.2k
               (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
540
40.2k
      smoothok = FALSE;
541
40.2k
      downsample->methods[ci] = int_downsample;
542
40.2k
    } else
543
0
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
544
294k
  }
545
546
113k
#ifdef INPUT_SMOOTHING_SUPPORTED
547
113k
  if (cinfo->smoothing_factor && !smoothok)
548
0
    TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
549
113k
#endif
550
113k
}
jinit_downsampler
Line
Count
Source
468
65.0k
{
469
65.0k
  my_downsample_ptr downsample;
470
65.0k
  int ci;
471
65.0k
  jpeg_component_info *compptr;
472
65.0k
  boolean smoothok = TRUE;
473
474
65.0k
#ifdef C_LOSSLESS_SUPPORTED
475
65.0k
  if (cinfo->master->lossless) {
476
12.9k
#if BITS_IN_JSAMPLE == 8
477
12.9k
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
478
#else
479
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
480
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
481
#endif
482
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
483
12.9k
  } else
484
52.0k
#endif
485
52.0k
  {
486
52.0k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
487
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
488
52.0k
  }
489
490
65.0k
  downsample = (my_downsample_ptr)
491
65.0k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
492
65.0k
                                sizeof(my_downsampler));
493
65.0k
  cinfo->downsample = (struct jpeg_downsampler *)downsample;
494
65.0k
  downsample->pub.start_pass = start_pass_downsample;
495
65.0k
  downsample->pub._downsample = sep_downsample;
496
65.0k
  downsample->pub.need_context_rows = FALSE;
497
498
65.0k
  if (cinfo->CCIR601_sampling)
499
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
500
501
  /* Verify we can handle the sampling factors, and set up method pointers */
502
228k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
503
163k
       ci++, compptr++) {
504
163k
    if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
505
113k
        compptr->v_samp_factor == cinfo->max_v_samp_factor) {
506
104k
#ifdef INPUT_SMOOTHING_SUPPORTED
507
104k
      if (cinfo->smoothing_factor) {
508
2.66k
        downsample->methods[ci] = fullsize_smooth_downsample;
509
2.66k
        downsample->pub.need_context_rows = TRUE;
510
2.66k
      } else
511
102k
#endif
512
102k
        downsample->methods[ci] = fullsize_downsample;
513
104k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
514
33.8k
               compptr->v_samp_factor == cinfo->max_v_samp_factor) {
515
16.1k
      smoothok = FALSE;
516
16.1k
#ifdef WITH_SIMD
517
16.1k
      if (jsimd_set_h2v1_downsample(cinfo))
518
16.1k
        downsample->methods[ci] = jsimd_h2v1_downsample;
519
0
      else
520
0
#endif
521
0
        downsample->methods[ci] = h2v1_downsample;
522
42.8k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
523
17.6k
               compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
524
17.6k
#ifdef INPUT_SMOOTHING_SUPPORTED
525
17.6k
      if (cinfo->smoothing_factor) {
526
3.48k
        downsample->methods[ci] = h2v2_smooth_downsample;
527
3.48k
        downsample->pub.need_context_rows = TRUE;
528
3.48k
      } else
529
14.2k
#endif
530
14.2k
      {
531
14.2k
#ifdef WITH_SIMD
532
14.2k
        if (jsimd_set_h2v2_downsample(cinfo))
533
14.2k
          downsample->methods[ci] = jsimd_h2v2_downsample;
534
0
        else
535
0
#endif
536
0
          downsample->methods[ci] = h2v2_downsample;
537
14.2k
      }
538
25.1k
    } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
539
25.1k
               (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
540
25.1k
      smoothok = FALSE;
541
25.1k
      downsample->methods[ci] = int_downsample;
542
25.1k
    } else
543
0
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
544
163k
  }
545
546
65.0k
#ifdef INPUT_SMOOTHING_SUPPORTED
547
65.0k
  if (cinfo->smoothing_factor && !smoothok)
548
0
    TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
549
65.0k
#endif
550
65.0k
}
j12init_downsampler
Line
Count
Source
468
37.4k
{
469
37.4k
  my_downsample_ptr downsample;
470
37.4k
  int ci;
471
37.4k
  jpeg_component_info *compptr;
472
37.4k
  boolean smoothok = TRUE;
473
474
37.4k
#ifdef C_LOSSLESS_SUPPORTED
475
37.4k
  if (cinfo->master->lossless) {
476
#if BITS_IN_JSAMPLE == 8
477
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
478
#else
479
10.9k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
480
10.9k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
481
0
#endif
482
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
483
10.9k
  } else
484
26.4k
#endif
485
26.4k
  {
486
26.4k
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
487
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
488
26.4k
  }
489
490
37.4k
  downsample = (my_downsample_ptr)
491
37.4k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
492
37.4k
                                sizeof(my_downsampler));
493
37.4k
  cinfo->downsample = (struct jpeg_downsampler *)downsample;
494
37.4k
  downsample->pub.start_pass = start_pass_downsample;
495
37.4k
  downsample->pub._downsample = sep_downsample;
496
37.4k
  downsample->pub.need_context_rows = FALSE;
497
498
37.4k
  if (cinfo->CCIR601_sampling)
499
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
500
501
  /* Verify we can handle the sampling factors, and set up method pointers */
502
136k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
503
99.2k
       ci++, compptr++) {
504
99.2k
    if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
505
76.5k
        compptr->v_samp_factor == cinfo->max_v_samp_factor) {
506
68.9k
#ifdef INPUT_SMOOTHING_SUPPORTED
507
68.9k
      if (cinfo->smoothing_factor) {
508
0
        downsample->methods[ci] = fullsize_smooth_downsample;
509
0
        downsample->pub.need_context_rows = TRUE;
510
0
      } else
511
68.9k
#endif
512
68.9k
        downsample->methods[ci] = fullsize_downsample;
513
68.9k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
514
15.1k
               compptr->v_samp_factor == cinfo->max_v_samp_factor) {
515
7.63k
      smoothok = FALSE;
516
#ifdef WITH_SIMD
517
      if (jsimd_set_h2v1_downsample(cinfo))
518
        downsample->methods[ci] = jsimd_h2v1_downsample;
519
      else
520
#endif
521
7.63k
        downsample->methods[ci] = h2v1_downsample;
522
22.6k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
523
7.54k
               compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
524
7.54k
#ifdef INPUT_SMOOTHING_SUPPORTED
525
7.54k
      if (cinfo->smoothing_factor) {
526
0
        downsample->methods[ci] = h2v2_smooth_downsample;
527
0
        downsample->pub.need_context_rows = TRUE;
528
0
      } else
529
7.54k
#endif
530
7.54k
      {
531
#ifdef WITH_SIMD
532
        if (jsimd_set_h2v2_downsample(cinfo))
533
          downsample->methods[ci] = jsimd_h2v2_downsample;
534
        else
535
#endif
536
7.54k
          downsample->methods[ci] = h2v2_downsample;
537
7.54k
      }
538
15.0k
    } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
539
15.0k
               (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
540
15.0k
      smoothok = FALSE;
541
15.0k
      downsample->methods[ci] = int_downsample;
542
15.0k
    } else
543
0
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
544
99.2k
  }
545
546
37.4k
#ifdef INPUT_SMOOTHING_SUPPORTED
547
37.4k
  if (cinfo->smoothing_factor && !smoothok)
548
0
    TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
549
37.4k
#endif
550
37.4k
}
j16init_downsampler
Line
Count
Source
468
11.2k
{
469
11.2k
  my_downsample_ptr downsample;
470
11.2k
  int ci;
471
11.2k
  jpeg_component_info *compptr;
472
11.2k
  boolean smoothok = TRUE;
473
474
11.2k
#ifdef C_LOSSLESS_SUPPORTED
475
11.2k
  if (cinfo->master->lossless) {
476
#if BITS_IN_JSAMPLE == 8
477
    if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2)
478
#else
479
11.2k
    if (cinfo->data_precision > BITS_IN_JSAMPLE ||
480
11.2k
        cinfo->data_precision < BITS_IN_JSAMPLE - 3)
481
0
#endif
482
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
483
11.2k
  } else
484
0
#endif
485
0
  {
486
0
    if (cinfo->data_precision != BITS_IN_JSAMPLE)
487
0
      ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
488
0
  }
489
490
11.2k
  downsample = (my_downsample_ptr)
491
11.2k
    (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
492
11.2k
                                sizeof(my_downsampler));
493
11.2k
  cinfo->downsample = (struct jpeg_downsampler *)downsample;
494
11.2k
  downsample->pub.start_pass = start_pass_downsample;
495
11.2k
  downsample->pub._downsample = sep_downsample;
496
11.2k
  downsample->pub.need_context_rows = FALSE;
497
498
11.2k
  if (cinfo->CCIR601_sampling)
499
0
    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
500
501
  /* Verify we can handle the sampling factors, and set up method pointers */
502
42.9k
  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
503
31.7k
       ci++, compptr++) {
504
31.7k
    if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
505
31.7k
        compptr->v_samp_factor == cinfo->max_v_samp_factor) {
506
31.7k
#ifdef INPUT_SMOOTHING_SUPPORTED
507
31.7k
      if (cinfo->smoothing_factor) {
508
0
        downsample->methods[ci] = fullsize_smooth_downsample;
509
0
        downsample->pub.need_context_rows = TRUE;
510
0
      } else
511
31.7k
#endif
512
31.7k
        downsample->methods[ci] = fullsize_downsample;
513
31.7k
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
514
0
               compptr->v_samp_factor == cinfo->max_v_samp_factor) {
515
0
      smoothok = FALSE;
516
#ifdef WITH_SIMD
517
      if (jsimd_set_h2v1_downsample(cinfo))
518
        downsample->methods[ci] = jsimd_h2v1_downsample;
519
      else
520
#endif
521
0
        downsample->methods[ci] = h2v1_downsample;
522
0
    } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
523
0
               compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
524
0
#ifdef INPUT_SMOOTHING_SUPPORTED
525
0
      if (cinfo->smoothing_factor) {
526
0
        downsample->methods[ci] = h2v2_smooth_downsample;
527
0
        downsample->pub.need_context_rows = TRUE;
528
0
      } else
529
0
#endif
530
0
      {
531
#ifdef WITH_SIMD
532
        if (jsimd_set_h2v2_downsample(cinfo))
533
          downsample->methods[ci] = jsimd_h2v2_downsample;
534
        else
535
#endif
536
0
          downsample->methods[ci] = h2v2_downsample;
537
0
      }
538
0
    } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
539
0
               (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
540
0
      smoothok = FALSE;
541
0
      downsample->methods[ci] = int_downsample;
542
0
    } else
543
0
      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
544
31.7k
  }
545
546
11.2k
#ifdef INPUT_SMOOTHING_SUPPORTED
547
11.2k
  if (cinfo->smoothing_factor && !smoothok)
548
0
    TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
549
11.2k
#endif
550
11.2k
}
551
552
#endif /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */