/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-2025, 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 |
17 | | * is defined to be max_v_samp_factor pixel rows of each component, |
18 | | * from which the downsampler produces v_samp_factor sample rows. |
19 | | * A single row group is processed in each 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 |
29 | | * one row group's worth of pixels above and below the passed-in data; |
30 | | * the caller will create dummy rows at image top and bottom by replicating |
31 | | * the first or last real pixel row. |
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 | | * pixels covered by the output pixel. 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, but for the specific cases we normally use (1:1 |
41 | | * and 2:1 ratios) the box is equivalent to a "triangle filter" which is not |
42 | | * nearly so bad. If you intend to use other sampling ratios, you'd be well |
43 | | * 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 pixel P is replaced by a weighted sum of itself and its |
49 | | * eight neighbors. P's weight is 1-8*SF and each neighbor's weight is SF, |
50 | | * 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 | 81.6k | { |
90 | | /* no work for now */ |
91 | 81.6k | } jcsample-8.c:start_pass_downsample Line | Count | Source | 89 | 37.8k | { | 90 | | /* no work for now */ | 91 | 37.8k | } |
jcsample-12.c:start_pass_downsample Line | Count | Source | 89 | 33.0k | { | 90 | | /* no work for now */ | 91 | 33.0k | } |
jcsample-16.c:start_pass_downsample Line | Count | Source | 89 | 10.7k | { | 90 | | /* no work for now */ | 91 | 10.7k | } |
|
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 | 614M | { |
103 | 614M | register _JSAMPROW ptr; |
104 | 614M | register _JSAMPLE pixval; |
105 | 614M | register int count; |
106 | 614M | int row; |
107 | 614M | int numcols = (int)(output_cols - input_cols); |
108 | | |
109 | 614M | if (numcols > 0) { |
110 | 827M | for (row = 0; row < num_rows; row++) { |
111 | 448M | ptr = image_data[row] + input_cols; |
112 | 448M | pixval = ptr[-1]; |
113 | 5.19G | for (count = numcols; count > 0; count--) |
114 | 4.75G | *ptr++ = pixval; |
115 | 448M | } |
116 | 378M | } |
117 | 614M | } jcsample-8.c:expand_right_edge Line | Count | Source | 102 | 310M | { | 103 | 310M | register _JSAMPROW ptr; | 104 | 310M | register _JSAMPLE pixval; | 105 | 310M | register int count; | 106 | 310M | int row; | 107 | 310M | int numcols = (int)(output_cols - input_cols); | 108 | | | 109 | 310M | if (numcols > 0) { | 110 | 474M | for (row = 0; row < num_rows; row++) { | 111 | 253M | ptr = image_data[row] + input_cols; | 112 | 253M | pixval = ptr[-1]; | 113 | 2.85G | for (count = numcols; count > 0; count--) | 114 | 2.59G | *ptr++ = pixval; | 115 | 253M | } | 116 | 221M | } | 117 | 310M | } |
jcsample-12.c:expand_right_edge Line | Count | Source | 102 | 221M | { | 103 | 221M | register _JSAMPROW ptr; | 104 | 221M | register _JSAMPLE pixval; | 105 | 221M | register int count; | 106 | 221M | int row; | 107 | 221M | int numcols = (int)(output_cols - input_cols); | 108 | | | 109 | 221M | if (numcols > 0) { | 110 | 352M | for (row = 0; row < num_rows; row++) { | 111 | 195M | ptr = image_data[row] + input_cols; | 112 | 195M | pixval = ptr[-1]; | 113 | 2.34G | for (count = numcols; count > 0; count--) | 114 | 2.15G | *ptr++ = pixval; | 115 | 195M | } | 116 | 157M | } | 117 | 221M | } |
jcsample-16.c:expand_right_edge Line | Count | Source | 102 | 82.6M | { | 103 | 82.6M | register _JSAMPROW ptr; | 104 | 82.6M | register _JSAMPLE pixval; | 105 | 82.6M | register int count; | 106 | 82.6M | int row; | 107 | 82.6M | int numcols = (int)(output_cols - input_cols); | 108 | | | 109 | 82.6M | if (numcols > 0) { | 110 | 0 | for (row = 0; row < num_rows; row++) { | 111 | 0 | ptr = image_data[row] + input_cols; | 112 | 0 | pixval = ptr[-1]; | 113 | 0 | for (count = numcols; count > 0; count--) | 114 | 0 | *ptr++ = pixval; | 115 | 0 | } | 116 | 0 | } | 117 | 82.6M | } |
|
118 | | |
119 | | |
120 | | /* |
121 | | * Do downsampling for a whole row group (all components). |
122 | | * |
123 | | * In this version we simply downsample each component independently. |
124 | | */ |
125 | | |
126 | | METHODDEF(void) |
127 | | sep_downsample(j_compress_ptr cinfo, _JSAMPIMAGE input_buf, |
128 | | JDIMENSION in_row_index, _JSAMPIMAGE output_buf, |
129 | | JDIMENSION out_row_group_index) |
130 | 265M | { |
131 | 265M | my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample; |
132 | 265M | int ci; |
133 | 265M | jpeg_component_info *compptr; |
134 | 265M | _JSAMPARRAY in_ptr, out_ptr; |
135 | | |
136 | 944M | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
137 | 678M | ci++, compptr++) { |
138 | 678M | in_ptr = input_buf[ci] + in_row_index; |
139 | 678M | out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor); |
140 | 678M | (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr); |
141 | 678M | } |
142 | 265M | } jcsample-8.c:sep_downsample Line | Count | Source | 130 | 149M | { | 131 | 149M | my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample; | 132 | 149M | int ci; | 133 | 149M | jpeg_component_info *compptr; | 134 | 149M | _JSAMPARRAY in_ptr, out_ptr; | 135 | | | 136 | 524M | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 137 | 375M | ci++, compptr++) { | 138 | 375M | in_ptr = input_buf[ci] + in_row_index; | 139 | 375M | out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor); | 140 | 375M | (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr); | 141 | 375M | } | 142 | 149M | } |
jcsample-12.c:sep_downsample Line | Count | Source | 130 | 86.6M | { | 131 | 86.6M | my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample; | 132 | 86.6M | int ci; | 133 | 86.6M | jpeg_component_info *compptr; | 134 | 86.6M | _JSAMPARRAY in_ptr, out_ptr; | 135 | | | 136 | 307M | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 137 | 221M | ci++, compptr++) { | 138 | 221M | in_ptr = input_buf[ci] + in_row_index; | 139 | 221M | out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor); | 140 | 221M | (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr); | 141 | 221M | } | 142 | 86.6M | } |
jcsample-16.c:sep_downsample Line | Count | Source | 130 | 28.9M | { | 131 | 28.9M | my_downsample_ptr downsample = (my_downsample_ptr)cinfo->downsample; | 132 | 28.9M | int ci; | 133 | 28.9M | jpeg_component_info *compptr; | 134 | 28.9M | _JSAMPARRAY in_ptr, out_ptr; | 135 | | | 136 | 111M | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 137 | 82.6M | ci++, compptr++) { | 138 | 82.6M | in_ptr = input_buf[ci] + in_row_index; | 139 | 82.6M | out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor); | 140 | 82.6M | (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr); | 141 | 82.6M | } | 142 | 28.9M | } |
|
143 | | |
144 | | |
145 | | /* |
146 | | * Downsample pixel values of a single component. |
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 | 86.6M | { |
156 | 86.6M | int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v; |
157 | 86.6M | JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */ |
158 | 86.6M | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
159 | 86.6M | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; |
160 | 86.6M | _JSAMPROW inptr, outptr; |
161 | 86.6M | JLONG outvalue; |
162 | | |
163 | 86.6M | h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor; |
164 | 86.6M | v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor; |
165 | 86.6M | numpix = h_expand * v_expand; |
166 | 86.6M | numpix2 = numpix / 2; |
167 | | |
168 | | /* Expand input data enough to let all the output samples be generated |
169 | | * by the standard loop. Special-casing padded output would be more |
170 | | * efficient. |
171 | | */ |
172 | 86.6M | expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width, |
173 | 86.6M | output_cols * h_expand); |
174 | | |
175 | 86.6M | inrow = 0; |
176 | 173M | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { |
177 | 86.6M | outptr = output_data[outrow]; |
178 | 902M | for (outcol = 0, outcol_h = 0; outcol < output_cols; |
179 | 815M | outcol++, outcol_h += h_expand) { |
180 | 815M | outvalue = 0; |
181 | 1.88G | for (v = 0; v < v_expand; v++) { |
182 | 1.07G | inptr = input_data[inrow + v] + outcol_h; |
183 | 3.81G | for (h = 0; h < h_expand; h++) { |
184 | 2.74G | outvalue += (JLONG)(*inptr++); |
185 | 2.74G | } |
186 | 1.07G | } |
187 | 815M | *outptr++ = (_JSAMPLE)((outvalue + numpix2) / numpix); |
188 | 815M | } |
189 | 86.6M | inrow += v_expand; |
190 | 86.6M | } |
191 | 86.6M | } jcsample-8.c:int_downsample Line | Count | Source | 155 | 53.8M | { | 156 | 53.8M | int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v; | 157 | 53.8M | JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */ | 158 | 53.8M | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; | 159 | 53.8M | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; | 160 | 53.8M | _JSAMPROW inptr, outptr; | 161 | 53.8M | JLONG outvalue; | 162 | | | 163 | 53.8M | h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor; | 164 | 53.8M | v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor; | 165 | 53.8M | numpix = h_expand * v_expand; | 166 | 53.8M | numpix2 = numpix / 2; | 167 | | | 168 | | /* Expand input data enough to let all the output samples be generated | 169 | | * by the standard loop. Special-casing padded output would be more | 170 | | * efficient. | 171 | | */ | 172 | 53.8M | expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width, | 173 | 53.8M | output_cols * h_expand); | 174 | | | 175 | 53.8M | inrow = 0; | 176 | 107M | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { | 177 | 53.8M | outptr = output_data[outrow]; | 178 | 553M | for (outcol = 0, outcol_h = 0; outcol < output_cols; | 179 | 499M | outcol++, outcol_h += h_expand) { | 180 | 499M | outvalue = 0; | 181 | 1.13G | for (v = 0; v < v_expand; v++) { | 182 | 632M | inptr = input_data[inrow + v] + outcol_h; | 183 | 2.36G | for (h = 0; h < h_expand; h++) { | 184 | 1.73G | outvalue += (JLONG)(*inptr++); | 185 | 1.73G | } | 186 | 632M | } | 187 | 499M | *outptr++ = (_JSAMPLE)((outvalue + numpix2) / numpix); | 188 | 499M | } | 189 | 53.8M | inrow += v_expand; | 190 | 53.8M | } | 191 | 53.8M | } |
jcsample-12.c:int_downsample Line | Count | Source | 155 | 32.8M | { | 156 | 32.8M | int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v; | 157 | 32.8M | JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */ | 158 | 32.8M | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; | 159 | 32.8M | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; | 160 | 32.8M | _JSAMPROW inptr, outptr; | 161 | 32.8M | JLONG outvalue; | 162 | | | 163 | 32.8M | h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor; | 164 | 32.8M | v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor; | 165 | 32.8M | numpix = h_expand * v_expand; | 166 | 32.8M | numpix2 = numpix / 2; | 167 | | | 168 | | /* Expand input data enough to let all the output samples be generated | 169 | | * by the standard loop. Special-casing padded output would be more | 170 | | * efficient. | 171 | | */ | 172 | 32.8M | expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width, | 173 | 32.8M | output_cols * h_expand); | 174 | | | 175 | 32.8M | inrow = 0; | 176 | 65.6M | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { | 177 | 32.8M | outptr = output_data[outrow]; | 178 | 348M | for (outcol = 0, outcol_h = 0; outcol < output_cols; | 179 | 315M | outcol++, outcol_h += h_expand) { | 180 | 315M | outvalue = 0; | 181 | 757M | for (v = 0; v < v_expand; v++) { | 182 | 441M | inptr = input_data[inrow + v] + outcol_h; | 183 | 1.45G | for (h = 0; h < h_expand; h++) { | 184 | 1.01G | outvalue += (JLONG)(*inptr++); | 185 | 1.01G | } | 186 | 441M | } | 187 | 315M | *outptr++ = (_JSAMPLE)((outvalue + numpix2) / numpix); | 188 | 315M | } | 189 | 32.8M | inrow += v_expand; | 190 | 32.8M | } | 191 | 32.8M | } |
Unexecuted instantiation: jcsample-16.c:int_downsample |
192 | | |
193 | | |
194 | | /* |
195 | | * Downsample pixel values of a single component. |
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 | 494M | { |
204 | 494M | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
205 | | |
206 | | /* Copy the data */ |
207 | 494M | _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor, |
208 | 494M | cinfo->image_width); |
209 | | /* Edge-expand */ |
210 | 494M | expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width, |
211 | 494M | compptr->width_in_blocks * data_unit); |
212 | 494M | } jcsample-8.c:fullsize_downsample Line | Count | Source | 203 | 256M | { | 204 | 256M | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; | 205 | | | 206 | | /* Copy the data */ | 207 | 256M | _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor, | 208 | 256M | cinfo->image_width); | 209 | | /* Edge-expand */ | 210 | 256M | expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width, | 211 | 256M | compptr->width_in_blocks * data_unit); | 212 | 256M | } |
jcsample-12.c:fullsize_downsample Line | Count | Source | 203 | 155M | { | 204 | 155M | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; | 205 | | | 206 | | /* Copy the data */ | 207 | 155M | _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor, | 208 | 155M | cinfo->image_width); | 209 | | /* Edge-expand */ | 210 | 155M | expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width, | 211 | 155M | compptr->width_in_blocks * data_unit); | 212 | 155M | } |
jcsample-16.c:fullsize_downsample Line | Count | Source | 203 | 82.6M | { | 204 | 82.6M | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; | 205 | | | 206 | | /* Copy the data */ | 207 | 82.6M | _jcopy_sample_rows(input_data, 0, output_data, 0, cinfo->max_v_samp_factor, | 208 | 82.6M | cinfo->image_width); | 209 | | /* Edge-expand */ | 210 | 82.6M | expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width, | 211 | 82.6M | compptr->width_in_blocks * data_unit); | 212 | 82.6M | } |
|
213 | | |
214 | | |
215 | | /* |
216 | | * Downsample pixel values of a single component. |
217 | | * This version handles the common case of 2:1 horizontal and 1:1 vertical, |
218 | | * without smoothing. |
219 | | * |
220 | | * A note about the "bias" calculations: when rounding fractional values to |
221 | | * integer, we do not want to always round 0.5 up to the next integer. |
222 | | * If we did that, we'd introduce a noticeable bias towards larger values. |
223 | | * Instead, this code is arranged so that 0.5 will be rounded up or down at |
224 | | * alternate pixel locations (a simple ordered dither pattern). |
225 | | */ |
226 | | |
227 | | METHODDEF(void) |
228 | | h2v1_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, |
229 | | _JSAMPARRAY input_data, _JSAMPARRAY output_data) |
230 | 21.8M | { |
231 | 21.8M | int outrow; |
232 | 21.8M | JDIMENSION outcol; |
233 | 21.8M | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
234 | 21.8M | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; |
235 | 21.8M | register _JSAMPROW inptr, outptr; |
236 | 21.8M | register int bias; |
237 | | |
238 | | /* Expand input data enough to let all the output samples be generated |
239 | | * by the standard loop. Special-casing padded output would be more |
240 | | * efficient. |
241 | | */ |
242 | 21.8M | expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width, |
243 | 21.8M | output_cols * 2); |
244 | | |
245 | 43.7M | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { |
246 | 21.8M | outptr = output_data[outrow]; |
247 | 21.8M | inptr = input_data[outrow]; |
248 | 21.8M | bias = 0; /* bias = 0,1,0,1,... for successive samples */ |
249 | 227M | for (outcol = 0; outcol < output_cols; outcol++) { |
250 | 205M | *outptr++ = (_JSAMPLE)((inptr[0] + inptr[1] + bias) >> 1); |
251 | 205M | bias ^= 1; /* 0=>1, 1=>0 */ |
252 | 205M | inptr += 2; |
253 | 205M | } |
254 | 21.8M | } |
255 | 21.8M | } Unexecuted instantiation: jcsample-8.c:h2v1_downsample jcsample-12.c:h2v1_downsample Line | Count | Source | 230 | 21.8M | { | 231 | 21.8M | int outrow; | 232 | 21.8M | JDIMENSION outcol; | 233 | 21.8M | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; | 234 | 21.8M | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; | 235 | 21.8M | register _JSAMPROW inptr, outptr; | 236 | 21.8M | register int bias; | 237 | | | 238 | | /* Expand input data enough to let all the output samples be generated | 239 | | * by the standard loop. Special-casing padded output would be more | 240 | | * efficient. | 241 | | */ | 242 | 21.8M | expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width, | 243 | 21.8M | output_cols * 2); | 244 | | | 245 | 43.7M | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { | 246 | 21.8M | outptr = output_data[outrow]; | 247 | 21.8M | inptr = input_data[outrow]; | 248 | 21.8M | bias = 0; /* bias = 0,1,0,1,... for successive samples */ | 249 | 227M | for (outcol = 0; outcol < output_cols; outcol++) { | 250 | 205M | *outptr++ = (_JSAMPLE)((inptr[0] + inptr[1] + bias) >> 1); | 251 | 205M | bias ^= 1; /* 0=>1, 1=>0 */ | 252 | 205M | inptr += 2; | 253 | 205M | } | 254 | 21.8M | } | 255 | 21.8M | } |
Unexecuted instantiation: jcsample-16.c:h2v1_downsample |
256 | | |
257 | | |
258 | | /* |
259 | | * Downsample pixel values of a single component. |
260 | | * This version handles the standard case of 2:1 horizontal and 2:1 vertical, |
261 | | * without smoothing. |
262 | | */ |
263 | | |
264 | | METHODDEF(void) |
265 | | h2v2_downsample(j_compress_ptr cinfo, jpeg_component_info *compptr, |
266 | | _JSAMPARRAY input_data, _JSAMPARRAY output_data) |
267 | 10.9M | { |
268 | 10.9M | int inrow, outrow; |
269 | 10.9M | JDIMENSION outcol; |
270 | 10.9M | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
271 | 10.9M | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; |
272 | 10.9M | register _JSAMPROW inptr0, inptr1, outptr; |
273 | 10.9M | register int bias; |
274 | | |
275 | | /* Expand input data enough to let all the output samples be generated |
276 | | * by the standard loop. Special-casing padded output would be more |
277 | | * efficient. |
278 | | */ |
279 | 10.9M | expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width, |
280 | 10.9M | output_cols * 2); |
281 | | |
282 | 10.9M | inrow = 0; |
283 | 21.8M | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { |
284 | 10.9M | outptr = output_data[outrow]; |
285 | 10.9M | inptr0 = input_data[inrow]; |
286 | 10.9M | inptr1 = input_data[inrow + 1]; |
287 | 10.9M | bias = 1; /* bias = 1,2,1,2,... for successive samples */ |
288 | 117M | for (outcol = 0; outcol < output_cols; outcol++) { |
289 | 106M | *outptr++ = (_JSAMPLE) |
290 | 106M | ((inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1] + bias) >> 2); |
291 | 106M | bias ^= 3; /* 1=>2, 2=>1 */ |
292 | 106M | inptr0 += 2; inptr1 += 2; |
293 | 106M | } |
294 | 10.9M | inrow += 2; |
295 | 10.9M | } |
296 | 10.9M | } Unexecuted instantiation: jcsample-8.c:h2v2_downsample jcsample-12.c:h2v2_downsample Line | Count | Source | 267 | 10.9M | { | 268 | 10.9M | int inrow, outrow; | 269 | 10.9M | JDIMENSION outcol; | 270 | 10.9M | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; | 271 | 10.9M | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; | 272 | 10.9M | register _JSAMPROW inptr0, inptr1, outptr; | 273 | 10.9M | register int bias; | 274 | | | 275 | | /* Expand input data enough to let all the output samples be generated | 276 | | * by the standard loop. Special-casing padded output would be more | 277 | | * efficient. | 278 | | */ | 279 | 10.9M | expand_right_edge(input_data, cinfo->max_v_samp_factor, cinfo->image_width, | 280 | 10.9M | output_cols * 2); | 281 | | | 282 | 10.9M | inrow = 0; | 283 | 21.8M | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { | 284 | 10.9M | outptr = output_data[outrow]; | 285 | 10.9M | inptr0 = input_data[inrow]; | 286 | 10.9M | inptr1 = input_data[inrow + 1]; | 287 | 10.9M | bias = 1; /* bias = 1,2,1,2,... for successive samples */ | 288 | 117M | for (outcol = 0; outcol < output_cols; outcol++) { | 289 | 106M | *outptr++ = (_JSAMPLE) | 290 | 106M | ((inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1] + bias) >> 2); | 291 | 106M | bias ^= 3; /* 1=>2, 2=>1 */ | 292 | 106M | inptr0 += 2; inptr1 += 2; | 293 | 106M | } | 294 | 10.9M | inrow += 2; | 295 | 10.9M | } | 296 | 10.9M | } |
Unexecuted instantiation: jcsample-16.c:h2v2_downsample |
297 | | |
298 | | |
299 | | #ifdef INPUT_SMOOTHING_SUPPORTED |
300 | | |
301 | | /* |
302 | | * Downsample pixel values of a single component. |
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 | 0 | { |
311 | 0 | int inrow, outrow; |
312 | 0 | JDIMENSION colctr; |
313 | 0 | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
314 | 0 | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; |
315 | 0 | register _JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr; |
316 | 0 | 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 | 0 | expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, |
323 | 0 | cinfo->image_width, output_cols * 2); |
324 | | |
325 | | /* We don't bother to form the individual "smoothed" input pixel values; |
326 | | * we can directly compute the output which is the average of the four |
327 | | * smoothed values. Each of the four member pixels contributes a fraction |
328 | | * (1-8*SF) to its own smoothed image and a fraction SF to each of the three |
329 | | * other smoothed pixels, therefore a total fraction (1-5*SF)/4 to the final |
330 | | * output. The four corner-adjacent neighbor pixels contribute a fraction |
331 | | * SF to just one smoothed pixel, or SF/4 to the final output; while the |
332 | | * eight edge-adjacent neighbors contribute SF to each of two smoothed |
333 | | * pixels, or SF/2 overall. In order to use integer arithmetic, these |
334 | | * factors are scaled by 2^16 = 65536. |
335 | | * Also recall that SF = smoothing_factor / 1024. |
336 | | */ |
337 | |
|
338 | 0 | memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */ |
339 | 0 | neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */ |
340 | |
|
341 | 0 | inrow = 0; |
342 | 0 | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { |
343 | 0 | outptr = output_data[outrow]; |
344 | 0 | inptr0 = input_data[inrow]; |
345 | 0 | inptr1 = input_data[inrow + 1]; |
346 | 0 | above_ptr = input_data[inrow - 1]; |
347 | 0 | below_ptr = input_data[inrow + 2]; |
348 | | |
349 | | /* Special case for first column: pretend column -1 is same as column 0 */ |
350 | 0 | membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1]; |
351 | 0 | neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] + |
352 | 0 | inptr0[0] + inptr0[2] + inptr1[0] + inptr1[2]; |
353 | 0 | neighsum += neighsum; |
354 | 0 | neighsum += above_ptr[0] + above_ptr[2] + below_ptr[0] + below_ptr[2]; |
355 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
356 | 0 | *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16); |
357 | 0 | inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; |
358 | |
|
359 | 0 | for (colctr = output_cols - 2; colctr > 0; colctr--) { |
360 | | /* sum of pixels directly mapped to this output element */ |
361 | 0 | membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1]; |
362 | | /* sum of edge-neighbor pixels */ |
363 | 0 | neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] + |
364 | 0 | inptr0[-1] + inptr0[2] + inptr1[-1] + inptr1[2]; |
365 | | /* The edge-neighbors count twice as much as corner-neighbors */ |
366 | 0 | neighsum += neighsum; |
367 | | /* Add in the corner-neighbors */ |
368 | 0 | neighsum += above_ptr[-1] + above_ptr[2] + below_ptr[-1] + below_ptr[2]; |
369 | | /* form final output scaled up by 2^16 */ |
370 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
371 | | /* round, descale and output it */ |
372 | 0 | *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16); |
373 | 0 | inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2; |
374 | 0 | } |
375 | | |
376 | | /* Special case for last column */ |
377 | 0 | membersum = inptr0[0] + inptr0[1] + inptr1[0] + inptr1[1]; |
378 | 0 | neighsum = above_ptr[0] + above_ptr[1] + below_ptr[0] + below_ptr[1] + |
379 | 0 | inptr0[-1] + inptr0[1] + inptr1[-1] + inptr1[1]; |
380 | 0 | neighsum += neighsum; |
381 | 0 | neighsum += above_ptr[-1] + above_ptr[1] + below_ptr[-1] + below_ptr[1]; |
382 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
383 | 0 | *outptr = (_JSAMPLE)((membersum + 32768) >> 16); |
384 | |
|
385 | 0 | inrow += 2; |
386 | 0 | } |
387 | 0 | } Unexecuted instantiation: jcsample-8.c:h2v2_smooth_downsample Unexecuted instantiation: jcsample-12.c:h2v2_smooth_downsample Unexecuted instantiation: jcsample-16.c:h2v2_smooth_downsample |
388 | | |
389 | | |
390 | | /* |
391 | | * Downsample pixel values of a single component. |
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 | 0 | { |
400 | 0 | int outrow; |
401 | 0 | JDIMENSION colctr; |
402 | 0 | int data_unit = cinfo->master->lossless ? 1 : DCTSIZE; |
403 | 0 | JDIMENSION output_cols = compptr->width_in_blocks * data_unit; |
404 | 0 | register _JSAMPROW inptr, above_ptr, below_ptr, outptr; |
405 | 0 | JLONG membersum, neighsum, memberscale, neighscale; |
406 | 0 | 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 | 0 | expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2, |
413 | 0 | cinfo->image_width, output_cols); |
414 | | |
415 | | /* Each of the eight neighbor pixels contributes a fraction SF to the |
416 | | * smoothed pixel, while the main pixel contributes (1-8*SF). In order |
417 | | * to use integer arithmetic, these factors are multiplied by 2^16 = 65536. |
418 | | * Also recall that SF = smoothing_factor / 1024. |
419 | | */ |
420 | |
|
421 | 0 | memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */ |
422 | 0 | neighscale = cinfo->smoothing_factor * 64; /* scaled SF */ |
423 | |
|
424 | 0 | for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) { |
425 | 0 | outptr = output_data[outrow]; |
426 | 0 | inptr = input_data[outrow]; |
427 | 0 | above_ptr = input_data[outrow - 1]; |
428 | 0 | below_ptr = input_data[outrow + 1]; |
429 | | |
430 | | /* Special case for first column */ |
431 | 0 | colsum = (*above_ptr++) + (*below_ptr++) + inptr[0]; |
432 | 0 | membersum = *inptr++; |
433 | 0 | nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0]; |
434 | 0 | neighsum = colsum + (colsum - membersum) + nextcolsum; |
435 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
436 | 0 | *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16); |
437 | 0 | lastcolsum = colsum; colsum = nextcolsum; |
438 | |
|
439 | 0 | for (colctr = output_cols - 2; colctr > 0; colctr--) { |
440 | 0 | membersum = *inptr++; |
441 | 0 | above_ptr++; below_ptr++; |
442 | 0 | nextcolsum = above_ptr[0] + below_ptr[0] + inptr[0]; |
443 | 0 | neighsum = lastcolsum + (colsum - membersum) + nextcolsum; |
444 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
445 | 0 | *outptr++ = (_JSAMPLE)((membersum + 32768) >> 16); |
446 | 0 | lastcolsum = colsum; colsum = nextcolsum; |
447 | 0 | } |
448 | | |
449 | | /* Special case for last column */ |
450 | 0 | membersum = *inptr; |
451 | 0 | neighsum = lastcolsum + (colsum - membersum) + colsum; |
452 | 0 | membersum = membersum * memberscale + neighsum * neighscale; |
453 | 0 | *outptr = (_JSAMPLE)((membersum + 32768) >> 16); |
454 | |
|
455 | 0 | } |
456 | 0 | } Unexecuted instantiation: jcsample-8.c:fullsize_smooth_downsample 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 | 98.0k | { |
469 | 98.0k | my_downsample_ptr downsample; |
470 | 98.0k | int ci; |
471 | 98.0k | jpeg_component_info *compptr; |
472 | 98.0k | boolean smoothok = TRUE; |
473 | | |
474 | 98.0k | #ifdef C_LOSSLESS_SUPPORTED |
475 | 98.0k | if (cinfo->master->lossless) { |
476 | | #if BITS_IN_JSAMPLE == 8 |
477 | 12.6k | if (cinfo->data_precision > BITS_IN_JSAMPLE || cinfo->data_precision < 2) |
478 | | #else |
479 | 20.5k | if (cinfo->data_precision > BITS_IN_JSAMPLE || |
480 | 20.5k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) |
481 | 0 | #endif |
482 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
483 | 33.2k | } else |
484 | 64.7k | #endif |
485 | 64.7k | { |
486 | 64.7k | if (cinfo->data_precision != BITS_IN_JSAMPLE) |
487 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); |
488 | 64.7k | } |
489 | | |
490 | 98.0k | downsample = (my_downsample_ptr) |
491 | 98.0k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, |
492 | 98.0k | sizeof(my_downsampler)); |
493 | 98.0k | cinfo->downsample = (struct jpeg_downsampler *)downsample; |
494 | 98.0k | downsample->pub.start_pass = start_pass_downsample; |
495 | 98.0k | downsample->pub._downsample = sep_downsample; |
496 | 98.0k | downsample->pub.need_context_rows = FALSE; |
497 | | |
498 | 98.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 | 354k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; |
503 | 255k | ci++, compptr++) { |
504 | 255k | if (compptr->h_samp_factor == cinfo->max_h_samp_factor && |
505 | 198k | compptr->v_samp_factor == cinfo->max_v_samp_factor) { |
506 | 184k | #ifdef INPUT_SMOOTHING_SUPPORTED |
507 | 184k | if (cinfo->smoothing_factor) { |
508 | 0 | downsample->methods[ci] = fullsize_smooth_downsample; |
509 | 0 | downsample->pub.need_context_rows = TRUE; |
510 | 0 | } else |
511 | 184k | #endif |
512 | 184k | downsample->methods[ci] = fullsize_downsample; |
513 | 184k | } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && |
514 | 38.4k | compptr->v_samp_factor == cinfo->max_v_samp_factor) { |
515 | 19.3k | smoothok = FALSE; |
516 | | #ifdef WITH_SIMD |
517 | 12.7k | if (jsimd_set_h2v1_downsample(cinfo)) |
518 | 12.7k | downsample->methods[ci] = jsimd_h2v1_downsample; |
519 | 0 | else |
520 | 0 | #endif |
521 | 0 | downsample->methods[ci] = h2v1_downsample; |
522 | 51.8k | } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && |
523 | 19.1k | compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) { |
524 | 19.1k | #ifdef INPUT_SMOOTHING_SUPPORTED |
525 | 19.1k | if (cinfo->smoothing_factor) { |
526 | 0 | downsample->methods[ci] = h2v2_smooth_downsample; |
527 | 0 | downsample->pub.need_context_rows = TRUE; |
528 | 0 | } else |
529 | 19.1k | #endif |
530 | 19.1k | { |
531 | | #ifdef WITH_SIMD |
532 | 12.5k | if (jsimd_set_h2v2_downsample(cinfo)) |
533 | 12.5k | downsample->methods[ci] = jsimd_h2v2_downsample; |
534 | 0 | else |
535 | 0 | #endif |
536 | 0 | downsample->methods[ci] = h2v2_downsample; |
537 | 19.1k | } |
538 | 32.7k | } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 && |
539 | 32.7k | (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) { |
540 | 32.7k | smoothok = FALSE; |
541 | 32.7k | downsample->methods[ci] = int_downsample; |
542 | 32.7k | } else |
543 | 0 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); |
544 | 255k | } |
545 | | |
546 | 98.0k | #ifdef INPUT_SMOOTHING_SUPPORTED |
547 | 98.0k | if (cinfo->smoothing_factor && !smoothok) |
548 | 0 | TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL); |
549 | 98.0k | #endif |
550 | 98.0k | } Line | Count | Source | 468 | 54.2k | { | 469 | 54.2k | my_downsample_ptr downsample; | 470 | 54.2k | int ci; | 471 | 54.2k | jpeg_component_info *compptr; | 472 | 54.2k | boolean smoothok = TRUE; | 473 | | | 474 | 54.2k | #ifdef C_LOSSLESS_SUPPORTED | 475 | 54.2k | if (cinfo->master->lossless) { | 476 | 12.6k | #if BITS_IN_JSAMPLE == 8 | 477 | 12.6k | 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.6k | } else | 484 | 41.5k | #endif | 485 | 41.5k | { | 486 | 41.5k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 487 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 488 | 41.5k | } | 489 | | | 490 | 54.2k | downsample = (my_downsample_ptr) | 491 | 54.2k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 492 | 54.2k | sizeof(my_downsampler)); | 493 | 54.2k | cinfo->downsample = (struct jpeg_downsampler *)downsample; | 494 | 54.2k | downsample->pub.start_pass = start_pass_downsample; | 495 | 54.2k | downsample->pub._downsample = sep_downsample; | 496 | 54.2k | downsample->pub.need_context_rows = FALSE; | 497 | | | 498 | 54.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 | 192k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 503 | 138k | ci++, compptr++) { | 504 | 138k | if (compptr->h_samp_factor == cinfo->max_h_samp_factor && | 505 | 100k | compptr->v_samp_factor == cinfo->max_v_samp_factor) { | 506 | 93.2k | #ifdef INPUT_SMOOTHING_SUPPORTED | 507 | 93.2k | if (cinfo->smoothing_factor) { | 508 | 0 | downsample->methods[ci] = fullsize_smooth_downsample; | 509 | 0 | downsample->pub.need_context_rows = TRUE; | 510 | 0 | } else | 511 | 93.2k | #endif | 512 | 93.2k | downsample->methods[ci] = fullsize_downsample; | 513 | 93.2k | } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && | 514 | 25.2k | compptr->v_samp_factor == cinfo->max_v_samp_factor) { | 515 | 12.7k | smoothok = FALSE; | 516 | 12.7k | #ifdef WITH_SIMD | 517 | 12.7k | if (jsimd_set_h2v1_downsample(cinfo)) | 518 | 12.7k | downsample->methods[ci] = jsimd_h2v1_downsample; | 519 | 0 | else | 520 | 0 | #endif | 521 | 0 | downsample->methods[ci] = h2v1_downsample; | 522 | 32.0k | } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && | 523 | 12.5k | compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) { | 524 | 12.5k | #ifdef INPUT_SMOOTHING_SUPPORTED | 525 | 12.5k | if (cinfo->smoothing_factor) { | 526 | 0 | downsample->methods[ci] = h2v2_smooth_downsample; | 527 | 0 | downsample->pub.need_context_rows = TRUE; | 528 | 0 | } else | 529 | 12.5k | #endif | 530 | 12.5k | { | 531 | 12.5k | #ifdef WITH_SIMD | 532 | 12.5k | if (jsimd_set_h2v2_downsample(cinfo)) | 533 | 12.5k | downsample->methods[ci] = jsimd_h2v2_downsample; | 534 | 0 | else | 535 | 0 | #endif | 536 | 0 | downsample->methods[ci] = h2v2_downsample; | 537 | 12.5k | } | 538 | 19.5k | } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 && | 539 | 19.5k | (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) { | 540 | 19.5k | smoothok = FALSE; | 541 | 19.5k | downsample->methods[ci] = int_downsample; | 542 | 19.5k | } else | 543 | 0 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); | 544 | 138k | } | 545 | | | 546 | 54.2k | #ifdef INPUT_SMOOTHING_SUPPORTED | 547 | 54.2k | if (cinfo->smoothing_factor && !smoothok) | 548 | 0 | TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL); | 549 | 54.2k | #endif | 550 | 54.2k | } |
Line | Count | Source | 468 | 33.0k | { | 469 | 33.0k | my_downsample_ptr downsample; | 470 | 33.0k | int ci; | 471 | 33.0k | jpeg_component_info *compptr; | 472 | 33.0k | boolean smoothok = TRUE; | 473 | | | 474 | 33.0k | #ifdef C_LOSSLESS_SUPPORTED | 475 | 33.0k | 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 | 9.85k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 480 | 9.85k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 481 | 0 | #endif | 482 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 483 | 9.85k | } else | 484 | 23.2k | #endif | 485 | 23.2k | { | 486 | 23.2k | if (cinfo->data_precision != BITS_IN_JSAMPLE) | 487 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 488 | 23.2k | } | 489 | | | 490 | 33.0k | downsample = (my_downsample_ptr) | 491 | 33.0k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 492 | 33.0k | sizeof(my_downsampler)); | 493 | 33.0k | cinfo->downsample = (struct jpeg_downsampler *)downsample; | 494 | 33.0k | downsample->pub.start_pass = start_pass_downsample; | 495 | 33.0k | downsample->pub._downsample = sep_downsample; | 496 | 33.0k | downsample->pub.need_context_rows = FALSE; | 497 | | | 498 | 33.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 | 120k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 503 | 87.5k | ci++, compptr++) { | 504 | 87.5k | if (compptr->h_samp_factor == cinfo->max_h_samp_factor && | 505 | 67.6k | compptr->v_samp_factor == cinfo->max_v_samp_factor) { | 506 | 61.0k | #ifdef INPUT_SMOOTHING_SUPPORTED | 507 | 61.0k | if (cinfo->smoothing_factor) { | 508 | 0 | downsample->methods[ci] = fullsize_smooth_downsample; | 509 | 0 | downsample->pub.need_context_rows = TRUE; | 510 | 0 | } else | 511 | 61.0k | #endif | 512 | 61.0k | downsample->methods[ci] = fullsize_downsample; | 513 | 61.0k | } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && | 514 | 13.2k | compptr->v_samp_factor == cinfo->max_v_samp_factor) { | 515 | 6.68k | 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 | 6.68k | downsample->methods[ci] = h2v1_downsample; | 522 | 19.7k | } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor && | 523 | 6.58k | compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) { | 524 | 6.58k | #ifdef INPUT_SMOOTHING_SUPPORTED | 525 | 6.58k | if (cinfo->smoothing_factor) { | 526 | 0 | downsample->methods[ci] = h2v2_smooth_downsample; | 527 | 0 | downsample->pub.need_context_rows = TRUE; | 528 | 0 | } else | 529 | 6.58k | #endif | 530 | 6.58k | { | 531 | | #ifdef WITH_SIMD | 532 | | if (jsimd_set_h2v2_downsample(cinfo)) | 533 | | downsample->methods[ci] = jsimd_h2v2_downsample; | 534 | | else | 535 | | #endif | 536 | 6.58k | downsample->methods[ci] = h2v2_downsample; | 537 | 6.58k | } | 538 | 13.1k | } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 && | 539 | 13.1k | (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) { | 540 | 13.1k | smoothok = FALSE; | 541 | 13.1k | downsample->methods[ci] = int_downsample; | 542 | 13.1k | } else | 543 | 0 | ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL); | 544 | 87.5k | } | 545 | | | 546 | 33.0k | #ifdef INPUT_SMOOTHING_SUPPORTED | 547 | 33.0k | if (cinfo->smoothing_factor && !smoothok) | 548 | 0 | TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL); | 549 | 33.0k | #endif | 550 | 33.0k | } |
Line | Count | Source | 468 | 10.7k | { | 469 | 10.7k | my_downsample_ptr downsample; | 470 | 10.7k | int ci; | 471 | 10.7k | jpeg_component_info *compptr; | 472 | 10.7k | boolean smoothok = TRUE; | 473 | | | 474 | 10.7k | #ifdef C_LOSSLESS_SUPPORTED | 475 | 10.7k | 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.7k | if (cinfo->data_precision > BITS_IN_JSAMPLE || | 480 | 10.7k | cinfo->data_precision < BITS_IN_JSAMPLE - 3) | 481 | 0 | #endif | 482 | 0 | ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision); | 483 | 10.7k | } 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 | 10.7k | downsample = (my_downsample_ptr) | 491 | 10.7k | (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE, | 492 | 10.7k | sizeof(my_downsampler)); | 493 | 10.7k | cinfo->downsample = (struct jpeg_downsampler *)downsample; | 494 | 10.7k | downsample->pub.start_pass = start_pass_downsample; | 495 | 10.7k | downsample->pub._downsample = sep_downsample; | 496 | 10.7k | downsample->pub.need_context_rows = FALSE; | 497 | | | 498 | 10.7k | 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 | 41.1k | for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components; | 503 | 30.4k | ci++, compptr++) { | 504 | 30.4k | if (compptr->h_samp_factor == cinfo->max_h_samp_factor && | 505 | 30.4k | compptr->v_samp_factor == cinfo->max_v_samp_factor) { | 506 | 30.4k | #ifdef INPUT_SMOOTHING_SUPPORTED | 507 | 30.4k | if (cinfo->smoothing_factor) { | 508 | 0 | downsample->methods[ci] = fullsize_smooth_downsample; | 509 | 0 | downsample->pub.need_context_rows = TRUE; | 510 | 0 | } else | 511 | 30.4k | #endif | 512 | 30.4k | downsample->methods[ci] = fullsize_downsample; | 513 | 30.4k | } 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 | 30.4k | } | 545 | | | 546 | 10.7k | #ifdef INPUT_SMOOTHING_SUPPORTED | 547 | 10.7k | if (cinfo->smoothing_factor && !smoothok) | 548 | 0 | TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL); | 549 | 10.7k | #endif | 550 | 10.7k | } |
|
551 | | |
552 | | #endif /* BITS_IN_JSAMPLE != 16 || defined(C_LOSSLESS_SUPPORTED) */ |