Debian Codegraph @

src/upsampler.rs

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 * Copyright (c) 2023.
3 *
4 * This software is free software;
5 *
6 * You can redistribute it or modify it under terms of the MIT, Apache License or Zlib license
7 */
8
9 //! Up-sampling routines
10 //!
11 //! The main upsampling method is a bi-linear interpolation or a "triangle
12 //! filter " or libjpeg turbo `fancy_upsampling` which is a good compromise
13 //! between speed and visual quality
14 //!
15 //! # The filter
16 //! Each output pixel is made from `(3*A+B)/4` where A is the original
17 //! pixel closer to the output and B is the one further.
18 //!
19 //! ```text
20 //!+---+---+
21 //! | A | B |
22 //! +---+---+
23 //! +-+-+-+-+
24 //! | |P| | |
25 //! +-+-+-+-+
26 //! ```
27 //!
28 //! # Horizontal Bi-linear filter
29 //! ```text
30 //! |---+-----------+---+
31 //! | | | |
32 //! | A | |p1 | p2| | B |
33 //! | | | |
34 //! |---+-----------+---+
35 //!
36 //! ```
37 //! For a horizontal bi-linear it's trivial to implement,
38 //!
39 //! `A` becomes the input closest to the output.
40 //!
41 //! `B` varies depending on output.
42 //! - For odd positions, input is the `next` pixel after A
43 //! - For even positions, input is the `previous` value before A.
44 //!
45 //! We iterate in a classic 1-D sliding window with a window of 3.
46 //! For our sliding window approach, `A` is the 1st and `B` is either the 0th term or 2nd term
47 //! depending on position we are writing.(see scalar code).
48 //!
49 //! For vector code see module sse for explanation.
50 //!
51 //! # Vertical bi-linear.
52 //! Vertical up-sampling is a bit trickier.
53 //!
54 //! ```text
55 //! +----+----+
56 //! | A1 | A2 |
57 //! +----+----+
58 //! +----+----+
59 //! | p1 | p2 |
60 //! +----+-+--+
61 //! +----+-+--+
62 //! | p3 | p4 |
63 //! +----+-+--+
64 //! +----+----+
65 //! | B1 | B2 |
66 //! +----+----+
67 //! ```
68 //!
69 //! For `p1`
70 //! - `A1` is given a weight of `3` and `B1` is given a weight of 1.
71 //!
72 //! For `p3`
73 //! - `B1` is given a weight of `3` and `A1` is given a weight of 1
74 //!
75 //! # Horizontal vertical downsampling/chroma quartering.
76 //!
77 //! Carry out a vertical filter in the first pass, then a horizontal filter in the second pass.
78 #![allow(unreachable_code)]
79 use zune_corerust-analyzer cargo zune-core 0.5.1 crate/::optionsrust-analyzer cargo zune-core 0.5.1 options/::DecoderOptionsrust-analyzer cargo zune-core 0.5.1 options/decoder/DecoderOptions#;
80
81 use craterust-analyzer cargo zune-jpeg 0.5.15 crate/::componentsrust-analyzer cargo zune-jpeg 0.5.15 components/::UpSamplerrust-analyzer cargo zune-jpeg 0.5.15 components/UpSampler#;
82
83 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
84 #[cfg(feature = "x86")]
85 mod avx2rust-analyzer cargo zune-jpeg 0.5.15 upsampler/avx2/;
86 #[cfg(target_arch = "aarch64")]
87 #[cfg(feature = "neon")]
88 mod neon;
89 #[cfg(feature = "portable_simd")]
90 mod portable_simdrust-analyzer cargo zune-jpeg 0.5.15 upsampler/portable_simd/;
91 mod scalarrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/;
92
93 // choose the best possible implementation for this platform
94 #[allow(unused_variables)]
95 pub fn choose_horizontal_samp_functionrust-analyzer cargo zune-jpeg 0.5.15 upsampler/choose_horizontal_samp_function().(options: &DecoderOptionsrust-analyzer cargo zune-core 0.5.1 options/decoder/DecoderOptions#) -> UpSamplerrust-analyzer cargo zune-jpeg 0.5.15 components/UpSampler# {
96 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
97 #[cfg(feature = "x86")]
98 if options.use_avx2rust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]use_avx2().() {
99 return |a: &[i16], b: &[i16], c: &[i16], d: &mut [i16], e: &mut [i16]| {
100 // SAFETY: `options.use_avx2()` only returns true if avx2 is supported.
101 unsafe { avx2rust-analyzer cargo zune-jpeg 0.5.15 upsampler/avx2/::upsample_horizontal_avx2rust-analyzer cargo zune-jpeg 0.5.15 upsampler/avx2/upsample_horizontal_avx2().(a, b, c, d, e) }
102 };
103 }
104 #[cfg(target_arch = "aarch64")]
105 #[cfg(feature = "neon")]
106 if options.use_neon() {
107 return |a: &[i16], b: &[i16], c: &[i16], d: &mut [i16], e: &mut [i16]| {
108 // SAFETY: `options.use_neon()` only returns true if neon is supported.
109 unsafe { neon::upsample_horizontal_neon(a, b, c, d, e) }
110 };
111 }
112 #[cfg(feature = "portable_simd")]
113 return portable_simdrust-analyzer cargo zune-jpeg 0.5.15 upsampler/portable_simd/::upsample_horizontal_simdrust-analyzer cargo zune-jpeg 0.5.15 upsampler/portable_simd/upsample_horizontal_simd().;
114 return scalarrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/::upsample_horizontalrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/upsample_horizontal().;
115 }
116
117 #[allow(unused_variables)]
118 pub fn choose_hv_samp_functionrust-analyzer cargo zune-jpeg 0.5.15 upsampler/choose_hv_samp_function().(options: &DecoderOptionsrust-analyzer cargo zune-core 0.5.1 options/decoder/DecoderOptions#) -> UpSamplerrust-analyzer cargo zune-jpeg 0.5.15 components/UpSampler# {
119 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
120 #[cfg(feature = "x86")]
121 if options.use_avx2rust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]use_avx2().() {
122 return |a: &[i16], b: &[i16], c: &[i16], d: &mut [i16], e: &mut [i16]| {
123 // SAFETY: `options.use_avx2()` only returns true if avx2 is supported.
124 unsafe { avx2rust-analyzer cargo zune-jpeg 0.5.15 upsampler/avx2/::upsample_hv_avx2rust-analyzer cargo zune-jpeg 0.5.15 upsampler/avx2/upsample_hv_avx2().(a, b, c, d, e) }
125 };
126 }
127 #[cfg(target_arch = "aarch64")]
128 #[cfg(feature = "neon")]
129 if options.use_neon() {
130 return |a: &[i16], b: &[i16], c: &[i16], d: &mut [i16], e: &mut [i16]| {
131 // SAFETY: `options.use_neon()` only returns true if neon is supported.
132 unsafe { neon::upsample_hv_neon(a, b, c, d, e) }
133 };
134 }
135 #[cfg(feature = "portable_simd")]
136 return portable_simdrust-analyzer cargo zune-jpeg 0.5.15 upsampler/portable_simd/::upsample_hv_simdrust-analyzer cargo zune-jpeg 0.5.15 upsampler/portable_simd/upsample_hv_simd().;
137 return scalarrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/::upsample_hvrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/upsample_hv().;
138 }
139
140 #[allow(unused_variables)]
141 pub fn choose_v_samp_functionrust-analyzer cargo zune-jpeg 0.5.15 upsampler/choose_v_samp_function().(options: &DecoderOptionsrust-analyzer cargo zune-core 0.5.1 options/decoder/DecoderOptions#) -> UpSamplerrust-analyzer cargo zune-jpeg 0.5.15 components/UpSampler# {
142 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
143 #[cfg(feature = "x86")]
144 if options.use_avx2rust-analyzer cargo zune-core 0.5.1 options/decoder/impl#[DecoderOptions]use_avx2().() {
145 return |a: &[i16], b: &[i16], c: &[i16], d: &mut [i16], e: &mut [i16]| {
146 // SAFETY: `options.use_avx2()` only returns true if avx2 is supported.
147 unsafe { avx2rust-analyzer cargo zune-jpeg 0.5.15 upsampler/avx2/::upsample_vertical_avx2rust-analyzer cargo zune-jpeg 0.5.15 upsampler/avx2/upsample_vertical_avx2().(a, b, c, d, e) }
148 };
149 }
150 #[cfg(target_arch = "aarch64")]
151 #[cfg(feature = "neon")]
152 if options.use_neon() {
153 return |a: &[i16], b: &[i16], c: &[i16], d: &mut [i16], e: &mut [i16]| {
154 // SAFETY: `options.use_neon()` only returns true if neon is supported.
155 unsafe { neon::upsample_vertical_neon(a, b, c, d, e) }
156 };
157 }
158 #[cfg(feature = "portable_simd")]
159 return portable_simdrust-analyzer cargo zune-jpeg 0.5.15 upsampler/portable_simd/::upsample_vertical_simdrust-analyzer cargo zune-jpeg 0.5.15 upsampler/portable_simd/upsample_vertical_simd().;
160 return scalarrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/::upsample_verticalrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/upsample_vertical().;
161 }
162
163 /// Upsample nothing
164
165 pub fn upsample_no_oprust-analyzer cargo zune-jpeg 0.5.15 upsampler/upsample_no_op().(
166 _input: &[i16],
167 _in_ref: &[i16],
168 _in_near: &[i16],
169 _scratch_space: &mut [i16],
170 _output: &mut [i16],
171 ) {
172 }
173
174 pub fn generic_samplerrust-analyzer cargo zune-jpeg 0.5.15 upsampler/generic_sampler().() -> UpSamplerrust-analyzer cargo zune-jpeg 0.5.15 components/UpSampler# {
175 scalarrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/::upsample_genericrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/upsample_generic().
176 }
177
178 #[cfg(test)]
179 mod testsrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/ {
180 use superrust-analyzer cargo zune-jpeg 0.5.15 upsampler/::*;
•181 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#;
182 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/;
183
184 #[cfg(feature = "portable_simd")]
185 mod portable_simd_implrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/portable_simd_impl/ {
186 use superrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/::*;
187
188 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
189 fn portable_simd_verticalrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/portable_simd_impl/portable_simd_vertical().() {
190 _test_verticalrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/_test_vertical().(portable_simdrust-analyzer cargo zune-jpeg 0.5.15 upsampler/portable_simd/::upsample_vertical_simdrust-analyzer cargo zune-jpeg 0.5.15 upsampler/portable_simd/upsample_vertical_simd().)
191 }
192
193 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
194 fn portable_simd_horizontalrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/portable_simd_impl/portable_simd_horizontal().() {
195 _test_horizontalrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/_test_horizontal().(portable_simdrust-analyzer cargo zune-jpeg 0.5.15 upsampler/portable_simd/::upsample_horizontal_simdrust-analyzer cargo zune-jpeg 0.5.15 upsampler/portable_simd/upsample_horizontal_simd().)
196 }
197
198 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
199 fn portable_simd_hvrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/portable_simd_impl/portable_simd_hv().() {
200 _test_hvrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/_test_hv().(portable_simdrust-analyzer cargo zune-jpeg 0.5.15 upsampler/portable_simd/::upsample_hv_simdrust-analyzer cargo zune-jpeg 0.5.15 upsampler/portable_simd/upsample_hv_simd().)
201 }
202 }
203
204 #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
205 #[cfg(feature = "x86")]
206 #[cfg(target_feature = "avx2")]
207 mod avx2_impl {
208 use superrust-analyzer cargo zune-jpeg 0.5.15 upsampler/::*;
209
210 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
211 fn avx2_vertical() {
212 _test_verticalrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/_test_vertical().(|a: &[i16], b: &[i16], c: &[i16], d: &mut [i16], e: &mut [i16]| {
213 // SAFETY: Test guarded behind `target_feature`
214 unsafe { avx2rust-analyzer cargo zune-jpeg 0.5.15 upsampler/avx2/::upsample_vertical_avx2rust-analyzer cargo zune-jpeg 0.5.15 upsampler/avx2/upsample_vertical_avx2().(a, b, c, d, e) }
215 })
216 }
217
218 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
219 fn avx2_horizontal() {
220 _test_horizontalrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/_test_horizontal().(|a: &[i16], b: &[i16], c: &[i16], d: &mut [i16], e: &mut [i16]| {
221 // SAFETY: Test guarded behind `target_feature`
222 unsafe { avx2rust-analyzer cargo zune-jpeg 0.5.15 upsampler/avx2/::upsample_horizontal_avx2rust-analyzer cargo zune-jpeg 0.5.15 upsampler/avx2/upsample_horizontal_avx2().(a, b, c, d, e) }
223 })
224 }
225
226 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
227 fn avx2_hv() {
228 _test_hvrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/_test_hv().(|a: &[i16], b: &[i16], c: &[i16], d: &mut [i16], e: &mut [i16]| {
229 // SAFETY: Test guarded behind `target_feature`
230 unsafe { avx2rust-analyzer cargo zune-jpeg 0.5.15 upsampler/avx2/::upsample_hv_avx2rust-analyzer cargo zune-jpeg 0.5.15 upsampler/avx2/upsample_hv_avx2().(a, b, c, d, e) }
231 })
232 }
233 }
234
235 #[cfg(target_arch = "aarch64")]
236 #[cfg(feature = "neon")]
237 #[cfg(target_feature = "neon")]
238 mod neon_impl {
239 use superrust-analyzer cargo zune-jpeg 0.5.15 upsampler/::*;
240
241 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
242 fn neon_vertical() {
243 _test_verticalrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/_test_vertical().(|a: &[i16], b: &[i16], c: &[i16], d: &mut [i16], e: &mut [i16]| {
244 // SAFETY: Test guarded behind `target_feature`
245 unsafe { neon::upsample_vertical_neon(a, b, c, d, e) }
246 })
247 }
248
249 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
250 fn neon_horizontal() {
251 _test_horizontalrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/_test_horizontal().(|a: &[i16], b: &[i16], c: &[i16], d: &mut [i16], e: &mut [i16]| {
252 // SAFETY: Test guarded behind `target_feature`
253 unsafe { neon::upsample_horizontal_neon(a, b, c, d, e) }
254 })
255 }
256
257 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
258 fn neon_hv() {
259 _test_hvrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/_test_hv().(|a: &[i16], b: &[i16], c: &[i16], d: &mut [i16], e: &mut [i16]| {
260 // SAFETY: Test guarded behind `target_feature`
261 unsafe { neon::upsample_hv_neon(a, b, c, d, e) }
262 })
263 }
264 }
265
266 fn _test_verticalrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/_test_vertical().(upsampler: UpSamplerrust-analyzer cargo zune-jpeg 0.5.15 components/UpSampler#) {
267 let width = 1024;
268 let input: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i16> = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#width).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| ((x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().10) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().256) as i16).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
269 let in_near: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i16> = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#width).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| ((x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().20) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().256) as i16).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
270 let in_far: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i16> = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#width).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| ((x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().30) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().256) as i16).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
271 let mut scratch = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0i16; width];
272
273 let mut output_scalar = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0i16; width *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). 2];
274 let mut output_fast = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0i16; width *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). 2];
275
276 scalarrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/::upsample_verticalrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/upsample_vertical().(&input, &in_near, &in_far, &mut scratch, &mut output_scalar);
277 upsampler(&input, &in_near, &in_far, &mut scratch, &mut output_fast);
278
279 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output_scalar, output_fast);
280 }
281
282 fn _test_horizontalrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/_test_horizontal().(upsampler: UpSamplerrust-analyzer cargo zune-jpeg 0.5.15 components/UpSampler#) {
283 _test_horizontal_even_widthrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/_test_horizontal_even_width().(upsampler);
284 _test_horizontal_odd_widthrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/_test_horizontal_odd_width().(upsampler);
285 }
286
287 fn _test_horizontal_even_widthrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/_test_horizontal_even_width().(upsampler: UpSamplerrust-analyzer cargo zune-jpeg 0.5.15 components/UpSampler#) {
288 let width = 1024;
289 let input: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i16> = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#width).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| ((x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().10) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().256) as i16).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
290
291 let mut scratch = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0i16; width];
292
293 let mut output_scalar = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0i16; width *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). 2];
294 let mut output_fast = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0i16; width *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). 2];
295
296 scalarrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/::upsample_horizontalrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/upsample_horizontal().(&input, &[], &[], &mut scratch, &mut output_scalar);
297 upsampler(&input, &[], &[], &mut scratch, &mut output_fast);
298
299 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output_scalar, output_fast);
300 }
301
302 fn _test_horizontal_odd_widthrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/_test_horizontal_odd_width().(upsampler: UpSamplerrust-analyzer cargo zune-jpeg 0.5.15 components/UpSampler#) {
303 let width = 33;
304 let input: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i16> = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#width).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| ((x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().10) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().256) as i16).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
305 let mut scratch = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0i16; width];
306 let mut output_scalar = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0i16; width *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). 2];
307 let mut output_fast = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0i16; width *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). 2];
308
309 scalarrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/::upsample_horizontalrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/upsample_horizontal().(&input, &[], &[], &mut scratch, &mut output_scalar);
310 upsampler(&input, &[], &[], &mut scratch, &mut output_fast);
311
312 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output_scalar, output_fast);
313 }
314
315 fn _test_hvrust-analyzer cargo zune-jpeg 0.5.15 upsampler/tests/_test_hv().(upsampler: UpSamplerrust-analyzer cargo zune-jpeg 0.5.15 components/UpSampler#) {
316 let width = 512;
317 let input: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i16> = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#width).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| ((x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().10) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().256) as i16).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
318 let in_near: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i16> = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#width).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| ((x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().20) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().256) as i16).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
319 let in_far: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<i16> = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#width).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|x| ((x rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().30) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Rem<Self>`]rem().256) as i16).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
320
321 // Output len is width * 4 for HV (vertical * 2, then horizontal * 2 for each row)
322 // scratch is width * 2
323 let mut scratch_scalar = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0i16; width *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). 2];
324 let mut scratch_fast = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0i16; width *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). 2];
325 let mut output_scalar = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0i16; width *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). 4];
326 let mut output_fast = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0i16; width *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Mul<Self>`]mul(). 4];
327
328 scalarrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/::upsample_hvrust-analyzer cargo zune-jpeg 0.5.15 upsampler/scalar/upsample_hv().(
329 &input,
330 &in_near,
331 &in_far,
332 &mut scratch_scalar,
333 &mut output_scalar,
334 );
335 upsampler(
336 &input,
337 &in_near,
338 &in_far,
339 &mut scratch_fast,
340 &mut output_fast,
341 );
342
343 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(output_scalar, output_fast);
344 }
345 }