/rust/registry/src/index.crates.io-1949cf8c6b5b557f/pic-scale-safe-0.1.10/src/handler_provider.rs
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) Radzivon Bartoshyk, 10/2024. All rights reserved. |
3 | | * |
4 | | * Redistribution and use in source and binary forms, with or without modification, |
5 | | * are permitted provided that the following conditions are met: |
6 | | * |
7 | | * 1. Redistributions of source code must retain the above copyright notice, this |
8 | | * list of conditions and the following disclaimer. |
9 | | * |
10 | | * 2. Redistributions in binary form must reproduce the above copyright notice, |
11 | | * this list of conditions and the following disclaimer in the documentation |
12 | | * and/or other materials provided with the distribution. |
13 | | * |
14 | | * 3. Neither the name of the copyright holder nor the names of its |
15 | | * contributors may be used to endorse or promote products derived from |
16 | | * this software without specific prior written permission. |
17 | | * |
18 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
21 | | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
22 | | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
23 | | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
24 | | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
25 | | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
26 | | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
27 | | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | | */ |
29 | | use crate::filter_weights::{FilterBounds, FilterWeights}; |
30 | | use crate::fixed_point_horizontal::{ |
31 | | convolve_row_handler_fixed_point, convolve_row_handler_fixed_point_4, |
32 | | }; |
33 | | use crate::fixed_point_vertical::column_handler_fixed_point; |
34 | | use crate::floating_point_horizontal::{ |
35 | | convolve_row_handler_floating_point, convolve_row_handler_floating_point_4, |
36 | | }; |
37 | | use crate::floating_point_vertical::column_handler_floating_point; |
38 | | use crate::mixed_storage::MixedStorage; |
39 | | use crate::saturate_narrow::SaturateNarrow; |
40 | | use num_traits::{AsPrimitive, Float, MulAdd}; |
41 | | use std::ops::{Add, AddAssign, Mul}; |
42 | | |
43 | | pub(crate) trait ColumnHandlerFixedPoint<T, J> |
44 | | where |
45 | | T: Copy + 'static + AsPrimitive<J> + Default, |
46 | | J: Copy + 'static + AsPrimitive<T> + Mul<Output = J> + AddAssign + SaturateNarrow<T> + Default, |
47 | | i32: AsPrimitive<J>, |
48 | | i16: AsPrimitive<J>, |
49 | | { |
50 | | fn handle_column( |
51 | | bounds: &FilterBounds, |
52 | | src: &[T], |
53 | | dst: &mut [T], |
54 | | src_stride: usize, |
55 | | weight: &[i16], |
56 | | bit_depth: u32, |
57 | | ); |
58 | | } |
59 | | |
60 | | pub(crate) trait RowHandlerFixedPoint<T, J> |
61 | | where |
62 | | T: Copy + 'static + AsPrimitive<J> + Default, |
63 | | J: Copy + 'static + AsPrimitive<T> + Mul<Output = J> + AddAssign + SaturateNarrow<T> + Default, |
64 | | i32: AsPrimitive<J>, |
65 | | i16: AsPrimitive<J>, |
66 | | { |
67 | | fn handle_row_4<const COMPONENTS: usize>( |
68 | | src: &[T], |
69 | | src_stride: usize, |
70 | | dst: &mut [T], |
71 | | dst_stride: usize, |
72 | | filter_weights: &FilterWeights<i16>, |
73 | | bit_depth: u32, |
74 | | ); |
75 | | |
76 | | fn handle_row<const COMPONENTS: usize>( |
77 | | src: &[T], |
78 | | dst: &mut [T], |
79 | | filter_weights: &FilterWeights<i16>, |
80 | | bit_depth: u32, |
81 | | ); |
82 | | } |
83 | | |
84 | | impl<J> RowHandlerFixedPoint<u8, J> for u8 |
85 | | where |
86 | | J: Copy |
87 | | + 'static |
88 | | + AsPrimitive<u8> |
89 | | + Mul<Output = J> |
90 | | + AddAssign |
91 | | + SaturateNarrow<u8> |
92 | | + Add<J, Output = J> |
93 | | + Default, |
94 | | i32: AsPrimitive<J>, |
95 | | u8: AsPrimitive<J>, |
96 | | i16: AsPrimitive<J>, |
97 | | { |
98 | 0 | fn handle_row_4<const COMPONENTS: usize>( |
99 | 0 | src: &[u8], |
100 | 0 | src_stride: usize, |
101 | 0 | dst: &mut [u8], |
102 | 0 | dst_stride: usize, |
103 | 0 | filter_weights: &FilterWeights<i16>, |
104 | 0 | bit_depth: u32, |
105 | 0 | ) { |
106 | 0 | convolve_row_handler_fixed_point_4::<u8, J, COMPONENTS>( |
107 | 0 | src, |
108 | 0 | src_stride, |
109 | 0 | dst, |
110 | 0 | dst_stride, |
111 | 0 | filter_weights, |
112 | 0 | bit_depth, |
113 | | ) |
114 | 0 | } Unexecuted instantiation: <u8 as pic_scale_safe::handler_provider::RowHandlerFixedPoint<u8, i32>>::handle_row_4::<1> Unexecuted instantiation: <u8 as pic_scale_safe::handler_provider::RowHandlerFixedPoint<u8, i32>>::handle_row_4::<2> Unexecuted instantiation: <u8 as pic_scale_safe::handler_provider::RowHandlerFixedPoint<u8, i32>>::handle_row_4::<3> Unexecuted instantiation: <u8 as pic_scale_safe::handler_provider::RowHandlerFixedPoint<u8, i32>>::handle_row_4::<4> |
115 | | |
116 | 0 | fn handle_row<const COMPONENTS: usize>( |
117 | 0 | src: &[u8], |
118 | 0 | dst: &mut [u8], |
119 | 0 | filter_weights: &FilterWeights<i16>, |
120 | 0 | bit_depth: u32, |
121 | 0 | ) { |
122 | 0 | convolve_row_handler_fixed_point::<u8, J, COMPONENTS>(src, dst, filter_weights, bit_depth) |
123 | 0 | } Unexecuted instantiation: <u8 as pic_scale_safe::handler_provider::RowHandlerFixedPoint<u8, i32>>::handle_row::<1> Unexecuted instantiation: <u8 as pic_scale_safe::handler_provider::RowHandlerFixedPoint<u8, i32>>::handle_row::<2> Unexecuted instantiation: <u8 as pic_scale_safe::handler_provider::RowHandlerFixedPoint<u8, i32>>::handle_row::<3> Unexecuted instantiation: <u8 as pic_scale_safe::handler_provider::RowHandlerFixedPoint<u8, i32>>::handle_row::<4> |
124 | | } |
125 | | |
126 | | impl<J> RowHandlerFixedPoint<u16, J> for u16 |
127 | | where |
128 | | J: Copy |
129 | | + 'static |
130 | | + AsPrimitive<u16> |
131 | | + Mul<Output = J> |
132 | | + AddAssign |
133 | | + SaturateNarrow<u16> |
134 | | + Add<J, Output = J> |
135 | | + Default, |
136 | | i32: AsPrimitive<J>, |
137 | | u16: AsPrimitive<J>, |
138 | | i16: AsPrimitive<J>, |
139 | | { |
140 | 0 | fn handle_row_4<const COMPONENTS: usize>( |
141 | 0 | src: &[u16], |
142 | 0 | src_stride: usize, |
143 | 0 | dst: &mut [u16], |
144 | 0 | dst_stride: usize, |
145 | 0 | filter_weights: &FilterWeights<i16>, |
146 | 0 | bit_depth: u32, |
147 | 0 | ) { |
148 | 0 | convolve_row_handler_fixed_point_4::<u16, J, COMPONENTS>( |
149 | 0 | src, |
150 | 0 | src_stride, |
151 | 0 | dst, |
152 | 0 | dst_stride, |
153 | 0 | filter_weights, |
154 | 0 | bit_depth, |
155 | | ) |
156 | 0 | } Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::RowHandlerFixedPoint<u16, i32>>::handle_row_4::<1> Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::RowHandlerFixedPoint<u16, i32>>::handle_row_4::<2> Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::RowHandlerFixedPoint<u16, i32>>::handle_row_4::<3> Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::RowHandlerFixedPoint<u16, i32>>::handle_row_4::<4> |
157 | | |
158 | 0 | fn handle_row<const COMPONENTS: usize>( |
159 | 0 | src: &[u16], |
160 | 0 | dst: &mut [u16], |
161 | 0 | filter_weights: &FilterWeights<i16>, |
162 | 0 | bit_depth: u32, |
163 | 0 | ) { |
164 | 0 | convolve_row_handler_fixed_point::<u16, J, COMPONENTS>(src, dst, filter_weights, bit_depth) |
165 | 0 | } Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::RowHandlerFixedPoint<u16, i32>>::handle_row::<1> Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::RowHandlerFixedPoint<u16, i32>>::handle_row::<2> Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::RowHandlerFixedPoint<u16, i32>>::handle_row::<3> Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::RowHandlerFixedPoint<u16, i32>>::handle_row::<4> |
166 | | } |
167 | | |
168 | | impl<J> ColumnHandlerFixedPoint<u8, J> for u8 |
169 | | where |
170 | | J: Copy |
171 | | + 'static |
172 | | + AsPrimitive<u8> |
173 | | + Mul<Output = J> |
174 | | + AddAssign |
175 | | + SaturateNarrow<u8> |
176 | | + Default, |
177 | | i32: AsPrimitive<J>, |
178 | | i16: AsPrimitive<J>, |
179 | | u8: AsPrimitive<J>, |
180 | | { |
181 | 0 | fn handle_column( |
182 | 0 | bounds: &FilterBounds, |
183 | 0 | src: &[u8], |
184 | 0 | dst: &mut [u8], |
185 | 0 | src_stride: usize, |
186 | 0 | weight: &[i16], |
187 | 0 | bit_depth: u32, |
188 | 0 | ) { |
189 | 0 | column_handler_fixed_point::<u8, J>(bounds, src, dst, src_stride, weight, bit_depth); |
190 | 0 | } |
191 | | } |
192 | | |
193 | | impl<J> ColumnHandlerFixedPoint<u16, J> for u16 |
194 | | where |
195 | | J: Copy |
196 | | + 'static |
197 | | + AsPrimitive<u16> |
198 | | + Mul<Output = J> |
199 | | + AddAssign |
200 | | + SaturateNarrow<u16> |
201 | | + Default, |
202 | | i32: AsPrimitive<J>, |
203 | | i16: AsPrimitive<J>, |
204 | | u16: AsPrimitive<J>, |
205 | | { |
206 | 0 | fn handle_column( |
207 | 0 | bounds: &FilterBounds, |
208 | 0 | src: &[u16], |
209 | 0 | dst: &mut [u16], |
210 | 0 | src_stride: usize, |
211 | 0 | weight: &[i16], |
212 | 0 | bit_depth: u32, |
213 | 0 | ) { |
214 | 0 | column_handler_fixed_point::<u16, J>(bounds, src, dst, src_stride, weight, bit_depth); |
215 | 0 | } |
216 | | } |
217 | | |
218 | | pub(crate) trait ColumnHandlerFloatingPoint<T, J, F> |
219 | | where |
220 | | T: Copy + 'static + AsPrimitive<J> + Default, |
221 | | J: Copy + 'static + AsPrimitive<T> + MulAdd<J, Output = J> + Default + MixedStorage<T>, |
222 | | F: Copy + 'static + AsPrimitive<J>, |
223 | | i32: AsPrimitive<J>, |
224 | | f32: AsPrimitive<J>, |
225 | | { |
226 | | fn handle_column( |
227 | | bounds: &FilterBounds, |
228 | | src: &[T], |
229 | | dst: &mut [T], |
230 | | src_stride: usize, |
231 | | weight: &[F], |
232 | | bit_depth: u32, |
233 | | ); |
234 | | } |
235 | | |
236 | | macro_rules! default_floating_column_handler { |
237 | | ($column_type:ty) => { |
238 | | impl<J, F> ColumnHandlerFloatingPoint<$column_type, J, F> for $column_type |
239 | | where |
240 | | J: Copy |
241 | | + 'static |
242 | | + AsPrimitive<$column_type> |
243 | | + MulAdd<J, Output = J> |
244 | | + MixedStorage<$column_type> |
245 | | + Default |
246 | | + Mul<J, Output = J> |
247 | | + Add<J, Output = J>, |
248 | | F: Copy + 'static + Float + AsPrimitive<J>, |
249 | | i32: AsPrimitive<J>, |
250 | | $column_type: AsPrimitive<J>, |
251 | | f32: AsPrimitive<J>, |
252 | | { |
253 | 0 | fn handle_column( |
254 | 0 | bounds: &FilterBounds, |
255 | 0 | src: &[$column_type], |
256 | 0 | dst: &mut [$column_type], |
257 | 0 | src_stride: usize, |
258 | 0 | weight: &[F], |
259 | 0 | bit_depth: u32, |
260 | 0 | ) { |
261 | 0 | column_handler_floating_point::<$column_type, J, F>( |
262 | 0 | bounds, src, dst, src_stride, weight, bit_depth, |
263 | | ) |
264 | 0 | } Unexecuted instantiation: <u8 as pic_scale_safe::handler_provider::ColumnHandlerFloatingPoint<u8, _, _>>::handle_column Unexecuted instantiation: <u32 as pic_scale_safe::handler_provider::ColumnHandlerFloatingPoint<u32, _, _>>::handle_column Unexecuted instantiation: <f64 as pic_scale_safe::handler_provider::ColumnHandlerFloatingPoint<f64, _, _>>::handle_column Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::ColumnHandlerFloatingPoint<u16, f32, f32>>::handle_column Unexecuted instantiation: <f32 as pic_scale_safe::handler_provider::ColumnHandlerFloatingPoint<f32, f32, f32>>::handle_column |
265 | | } |
266 | | }; |
267 | | } |
268 | | |
269 | | default_floating_column_handler!(u8); |
270 | | default_floating_column_handler!(u16); |
271 | | default_floating_column_handler!(u32); |
272 | | default_floating_column_handler!(f32); |
273 | | default_floating_column_handler!(f64); |
274 | | |
275 | | pub(crate) trait RowHandlerFloatingPoint<T, J, F> |
276 | | where |
277 | | T: Copy + 'static + AsPrimitive<J> + Default, |
278 | | J: Copy + 'static + AsPrimitive<T> + MulAdd<J, Output = J> + Default + MixedStorage<T>, |
279 | | F: Copy + 'static + AsPrimitive<J>, |
280 | | i32: AsPrimitive<J>, |
281 | | f32: AsPrimitive<J>, |
282 | | { |
283 | | fn handle_row_4<const COMPONENTS: usize>( |
284 | | src: &[T], |
285 | | src_stride: usize, |
286 | | dst: &mut [T], |
287 | | dst_stride: usize, |
288 | | filter_weights: &FilterWeights<F>, |
289 | | bit_depth: u32, |
290 | | ); |
291 | | |
292 | | fn handle_row<const COMPONENTS: usize>( |
293 | | src: &[T], |
294 | | dst: &mut [T], |
295 | | filter_weights: &FilterWeights<F>, |
296 | | bit_depth: u32, |
297 | | ); |
298 | | } |
299 | | |
300 | | macro_rules! default_floating_column_handler { |
301 | | ($row_type:ty) => { |
302 | | impl<J, F> RowHandlerFloatingPoint<$row_type, J, F> for $row_type |
303 | | where |
304 | | J: Copy |
305 | | + 'static |
306 | | + AsPrimitive<$row_type> |
307 | | + MulAdd<J, Output = J> |
308 | | + Default |
309 | | + MixedStorage<$row_type> |
310 | | + Mul<J, Output = J> |
311 | | + Add<J, Output = J>, |
312 | | F: Copy + 'static + AsPrimitive<J> + Float, |
313 | | i32: AsPrimitive<J>, |
314 | | f32: AsPrimitive<J>, |
315 | | $row_type: AsPrimitive<J>, |
316 | | { |
317 | 0 | fn handle_row_4<const COMPONENTS: usize>( |
318 | 0 | src: &[$row_type], |
319 | 0 | src_stride: usize, |
320 | 0 | dst: &mut [$row_type], |
321 | 0 | dst_stride: usize, |
322 | 0 | filter_weights: &FilterWeights<F>, |
323 | 0 | bit_depth: u32, |
324 | 0 | ) { |
325 | 0 | convolve_row_handler_floating_point_4::<$row_type, J, F, COMPONENTS>( |
326 | 0 | src, |
327 | 0 | src_stride, |
328 | 0 | dst, |
329 | 0 | dst_stride, |
330 | 0 | filter_weights, |
331 | 0 | bit_depth, |
332 | | ) |
333 | 0 | } Unexecuted instantiation: <f64 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<f64, _, _>>::handle_row_4::<_> Unexecuted instantiation: <u8 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<u8, _, _>>::handle_row_4::<_> Unexecuted instantiation: <f32 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<f32, f32, f32>>::handle_row_4::<1> Unexecuted instantiation: <f32 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<f32, f32, f32>>::handle_row_4::<2> Unexecuted instantiation: <f32 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<f32, f32, f32>>::handle_row_4::<3> Unexecuted instantiation: <f32 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<f32, f32, f32>>::handle_row_4::<4> Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<u16, f32, f32>>::handle_row_4::<1> Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<u16, f32, f32>>::handle_row_4::<2> Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<u16, f32, f32>>::handle_row_4::<3> Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<u16, f32, f32>>::handle_row_4::<4> |
334 | | |
335 | 0 | fn handle_row<const COMPONENTS: usize>( |
336 | 0 | src: &[$row_type], |
337 | 0 | dst: &mut [$row_type], |
338 | 0 | filter_weights: &FilterWeights<F>, |
339 | 0 | bit_depth: u32, |
340 | 0 | ) { |
341 | 0 | convolve_row_handler_floating_point::<$row_type, J, F, COMPONENTS>( |
342 | 0 | src, |
343 | 0 | dst, |
344 | 0 | filter_weights, |
345 | 0 | bit_depth, |
346 | | ) |
347 | 0 | } Unexecuted instantiation: <f64 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<f64, _, _>>::handle_row::<_> Unexecuted instantiation: <u8 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<u8, _, _>>::handle_row::<_> Unexecuted instantiation: <f32 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<f32, f32, f32>>::handle_row::<1> Unexecuted instantiation: <f32 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<f32, f32, f32>>::handle_row::<2> Unexecuted instantiation: <f32 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<f32, f32, f32>>::handle_row::<3> Unexecuted instantiation: <f32 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<f32, f32, f32>>::handle_row::<4> Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<u16, f32, f32>>::handle_row::<1> Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<u16, f32, f32>>::handle_row::<2> Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<u16, f32, f32>>::handle_row::<3> Unexecuted instantiation: <u16 as pic_scale_safe::handler_provider::RowHandlerFloatingPoint<u16, f32, f32>>::handle_row::<4> |
348 | | } |
349 | | }; |
350 | | } |
351 | | |
352 | | default_floating_column_handler!(f32); |
353 | | default_floating_column_handler!(f64); |
354 | | default_floating_column_handler!(u8); |
355 | | default_floating_column_handler!(u16); |