Coverage Report

Created: 2026-04-28 06:57

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