Skip to main content

singe_npp/image/
color_twist_batch.rs

1use super::*;
2
3impl_color_twist_batch!(
4    color_twist_batch_u8_c1,
5    C1,
6    nppiColorTwistBatch32f_8u_C1R_Ctx
7);
8impl_color_twist_batch!(
9    color_twist_batch_u8_c3,
10    C3,
11    nppiColorTwistBatch32f_8u_C3R_Ctx
12);
13impl_color_twist_batch!(
14    color_twist_batch_u8_c4,
15    C4,
16    nppiColorTwistBatch32f_8u_C4R_Ctx
17);
18impl_color_twist_batch!(
19    color_twist_batch_u8_ac4,
20    AC4,
21    nppiColorTwistBatch32f_8u_AC4R_Ctx
22);
23impl_color_twist_batch_in_place!(
24    color_twist_batch_u8_c1_in_place,
25    C1,
26    nppiColorTwistBatch32f_8u_C1IR_Ctx
27);
28impl_color_twist_batch_in_place!(
29    color_twist_batch_u8_c3_in_place,
30    C3,
31    nppiColorTwistBatch32f_8u_C3IR_Ctx
32);
33impl_color_twist_batch_in_place!(
34    color_twist_batch_u8_c4_in_place,
35    C4,
36    nppiColorTwistBatch32f_8u_C4IR_Ctx
37);
38impl_color_twist_batch_in_place!(
39    color_twist_batch_u8_ac4_in_place,
40    AC4,
41    nppiColorTwistBatch32f_8u_AC4IR_Ctx
42);
43impl_color_twist_batch_typed!(
44    color_twist_batch_f32_c1,
45    f32,
46    C1,
47    nppiColorTwistBatch_32f_C1R_Ctx
48);
49impl_color_twist_batch_typed!(
50    color_twist_batch_f32_c3,
51    f32,
52    C3,
53    nppiColorTwistBatch_32f_C3R_Ctx
54);
55impl_color_twist_batch_typed!(
56    color_twist_batch_f32_c4,
57    f32,
58    C4,
59    nppiColorTwistBatch_32f_C4R_Ctx
60);
61impl_color_twist_batch_typed!(
62    color_twist_batch_f32_ac4,
63    f32,
64    AC4,
65    nppiColorTwistBatch_32f_AC4R_Ctx
66);
67impl_color_twist_batch_in_place_typed!(
68    color_twist_batch_f32_c1_in_place,
69    f32,
70    C1,
71    nppiColorTwistBatch_32f_C1IR_Ctx
72);
73impl_color_twist_batch_in_place_typed!(
74    color_twist_batch_f32_c3_in_place,
75    f32,
76    C3,
77    nppiColorTwistBatch_32f_C3IR_Ctx
78);
79impl_color_twist_batch_in_place_typed!(
80    color_twist_batch_f32_c4_in_place,
81    f32,
82    C4,
83    nppiColorTwistBatch_32f_C4IR_Ctx
84);
85impl_color_twist_batch_in_place_typed!(
86    color_twist_batch_f32_ac4_in_place,
87    f32,
88    AC4,
89    nppiColorTwistBatch_32f_AC4IR_Ctx
90);
91impl_color_twist_batch_typed!(
92    color_twist_batch_f16_c1,
93    f16,
94    C1,
95    nppiColorTwistBatch32f_16f_C1R_Ctx
96);
97impl_color_twist_batch_typed!(
98    color_twist_batch_f16_c3,
99    f16,
100    C3,
101    nppiColorTwistBatch32f_16f_C3R_Ctx
102);
103impl_color_twist_batch_typed!(
104    color_twist_batch_f16_c4,
105    f16,
106    C4,
107    nppiColorTwistBatch32f_16f_C4R_Ctx
108);
109impl_color_twist_batch_in_place_typed!(
110    color_twist_batch_f16_c1_in_place,
111    f16,
112    C1,
113    nppiColorTwistBatch32f_16f_C1IR_Ctx
114);
115impl_color_twist_batch_in_place_typed!(
116    color_twist_batch_f16_c3_in_place,
117    f16,
118    C3,
119    nppiColorTwistBatch32f_16f_C3IR_Ctx
120);
121impl_color_twist_batch_in_place_typed!(
122    color_twist_batch_f16_c4_in_place,
123    f16,
124    C4,
125    nppiColorTwistBatch32f_16f_C4IR_Ctx
126);
127impl_color_twist_batch_with_constants_typed!(
128    color_twist_batch_u8_c4_with_constants,
129    u8,
130    nppiColorTwistBatch32fC_8u_C4R_Ctx
131);
132impl_color_twist_batch_with_constants_in_place_typed!(
133    color_twist_batch_u8_c4_with_constants_in_place,
134    u8,
135    nppiColorTwistBatch32fC_8u_C4IR_Ctx
136);
137impl_color_twist_batch_with_constants_typed!(
138    color_twist_batch_f16_c4_with_constants,
139    f16,
140    nppiColorTwistBatch32fC_16f_C4R_Ctx
141);
142impl_color_twist_batch_with_constants_in_place_typed!(
143    color_twist_batch_f16_c4_with_constants_in_place,
144    f16,
145    nppiColorTwistBatch32fC_16f_C4IR_Ctx
146);
147impl_color_twist_batch_with_constants_typed!(
148    color_twist_batch_f32_c4_with_constants,
149    f32,
150    nppiColorTwistBatch_32fC_C4R_Ctx
151);
152impl_color_twist_batch_with_constants_in_place_typed!(
153    color_twist_batch_f32_c4_with_constants_in_place,
154    f32,
155    nppiColorTwistBatch_32fC_C4IR_Ctx
156);
157
158pub trait ColorTwistBatch<L: ChannelLayout>: DataTypeLike {
159    fn color_twist_batch(
160        stream_context: &StreamContext,
161        sources: &[ImageView<'_, Self, L>],
162        twists: &[ColorTwistMatrix],
163        destinations: &mut [ImageViewMut<'_, Self, L>],
164        min: f32,
165        max: f32,
166    ) -> Result<()>;
167}
168
169macro_rules! impl_color_twist_batch_dispatch {
170    ($ty:ty, $layout:ty, $function:ident) => {
171        impl ColorTwistBatch<$layout> for $ty {
172            fn color_twist_batch(
173                stream_context: &StreamContext,
174                sources: &[ImageView<'_, Self, $layout>],
175                twists: &[ColorTwistMatrix],
176                destinations: &mut [ImageViewMut<'_, Self, $layout>],
177                min: f32,
178                max: f32,
179            ) -> Result<()> {
180                $function(stream_context, sources, twists, destinations, min, max)
181            }
182        }
183    };
184}
185
186impl_color_twist_batch_dispatch!(u8, C1, color_twist_batch_u8_c1);
187impl_color_twist_batch_dispatch!(u8, C3, color_twist_batch_u8_c3);
188impl_color_twist_batch_dispatch!(u8, C4, color_twist_batch_u8_c4);
189impl_color_twist_batch_dispatch!(u8, AC4, color_twist_batch_u8_ac4);
190impl_color_twist_batch_dispatch!(f16, C1, color_twist_batch_f16_c1);
191impl_color_twist_batch_dispatch!(f16, C3, color_twist_batch_f16_c3);
192impl_color_twist_batch_dispatch!(f16, C4, color_twist_batch_f16_c4);
193impl_color_twist_batch_dispatch!(f32, C1, color_twist_batch_f32_c1);
194impl_color_twist_batch_dispatch!(f32, C3, color_twist_batch_f32_c3);
195impl_color_twist_batch_dispatch!(f32, C4, color_twist_batch_f32_c4);
196impl_color_twist_batch_dispatch!(f32, AC4, color_twist_batch_f32_ac4);
197
198pub fn color_twist_batch<T, L>(
199    stream_context: &StreamContext,
200    sources: &[ImageView<'_, T, L>],
201    twists: &[ColorTwistMatrix],
202    destinations: &mut [ImageViewMut<'_, T, L>],
203    min: f32,
204    max: f32,
205) -> Result<()>
206where
207    T: ColorTwistBatch<L>,
208    L: ChannelLayout,
209{
210    T::color_twist_batch(stream_context, sources, twists, destinations, min, max)
211}
212
213pub trait ColorTwistBatchInPlace<L: ChannelLayout>: DataTypeLike {
214    fn color_twist_batch_in_place(
215        stream_context: &StreamContext,
216        images: &mut [ImageViewMut<'_, Self, L>],
217        twists: &[ColorTwistMatrix],
218        min: f32,
219        max: f32,
220    ) -> Result<()>;
221}
222
223macro_rules! impl_color_twist_batch_in_place_dispatch {
224    ($ty:ty, $layout:ty, $function:ident) => {
225        impl ColorTwistBatchInPlace<$layout> for $ty {
226            fn color_twist_batch_in_place(
227                stream_context: &StreamContext,
228                images: &mut [ImageViewMut<'_, Self, $layout>],
229                twists: &[ColorTwistMatrix],
230                min: f32,
231                max: f32,
232            ) -> Result<()> {
233                $function(stream_context, images, twists, min, max)
234            }
235        }
236    };
237}
238
239impl_color_twist_batch_in_place_dispatch!(u8, C1, color_twist_batch_u8_c1_in_place);
240impl_color_twist_batch_in_place_dispatch!(u8, C3, color_twist_batch_u8_c3_in_place);
241impl_color_twist_batch_in_place_dispatch!(u8, C4, color_twist_batch_u8_c4_in_place);
242impl_color_twist_batch_in_place_dispatch!(u8, AC4, color_twist_batch_u8_ac4_in_place);
243impl_color_twist_batch_in_place_dispatch!(f16, C1, color_twist_batch_f16_c1_in_place);
244impl_color_twist_batch_in_place_dispatch!(f16, C3, color_twist_batch_f16_c3_in_place);
245impl_color_twist_batch_in_place_dispatch!(f16, C4, color_twist_batch_f16_c4_in_place);
246impl_color_twist_batch_in_place_dispatch!(f32, C1, color_twist_batch_f32_c1_in_place);
247impl_color_twist_batch_in_place_dispatch!(f32, C3, color_twist_batch_f32_c3_in_place);
248impl_color_twist_batch_in_place_dispatch!(f32, C4, color_twist_batch_f32_c4_in_place);
249impl_color_twist_batch_in_place_dispatch!(f32, AC4, color_twist_batch_f32_ac4_in_place);
250
251pub fn color_twist_batch_in_place<T, L>(
252    stream_context: &StreamContext,
253    images: &mut [ImageViewMut<'_, T, L>],
254    twists: &[ColorTwistMatrix],
255    min: f32,
256    max: f32,
257) -> Result<()>
258where
259    T: ColorTwistBatchInPlace<L>,
260    L: ChannelLayout,
261{
262    T::color_twist_batch_in_place(stream_context, images, twists, min, max)
263}
264
265pub trait ColorTwistBatchWithConstantsC4: DataTypeLike {
266    fn color_twist_batch_with_constants_c4(
267        stream_context: &StreamContext,
268        sources: &[ImageView<'_, Self, C4>],
269        twists: &[ColorTwistBatchConstantsMatrix4],
270        destinations: &mut [ImageViewMut<'_, Self, C4>],
271        min: f32,
272        max: f32,
273    ) -> Result<()>;
274}
275
276macro_rules! impl_color_twist_batch_with_constants_c4_dispatch {
277    ($ty:ty, $function:ident) => {
278        impl ColorTwistBatchWithConstantsC4 for $ty {
279            fn color_twist_batch_with_constants_c4(
280                stream_context: &StreamContext,
281                sources: &[ImageView<'_, Self, C4>],
282                twists: &[ColorTwistBatchConstantsMatrix4],
283                destinations: &mut [ImageViewMut<'_, Self, C4>],
284                min: f32,
285                max: f32,
286            ) -> Result<()> {
287                $function(stream_context, sources, twists, destinations, min, max)
288            }
289        }
290    };
291}
292
293impl_color_twist_batch_with_constants_c4_dispatch!(u8, color_twist_batch_u8_c4_with_constants);
294impl_color_twist_batch_with_constants_c4_dispatch!(f16, color_twist_batch_f16_c4_with_constants);
295impl_color_twist_batch_with_constants_c4_dispatch!(f32, color_twist_batch_f32_c4_with_constants);
296
297pub fn color_twist_batch_c4_with_constants<T>(
298    stream_context: &StreamContext,
299    sources: &[ImageView<'_, T, C4>],
300    twists: &[ColorTwistBatchConstantsMatrix4],
301    destinations: &mut [ImageViewMut<'_, T, C4>],
302    min: f32,
303    max: f32,
304) -> Result<()>
305where
306    T: ColorTwistBatchWithConstantsC4,
307{
308    T::color_twist_batch_with_constants_c4(stream_context, sources, twists, destinations, min, max)
309}
310
311pub trait ColorTwistBatchWithConstantsC4InPlace: DataTypeLike {
312    fn color_twist_batch_with_constants_c4_in_place(
313        stream_context: &StreamContext,
314        images: &mut [ImageViewMut<'_, Self, C4>],
315        twists: &[ColorTwistBatchConstantsMatrix4],
316        min: f32,
317        max: f32,
318    ) -> Result<()>;
319}
320
321macro_rules! impl_color_twist_batch_with_constants_c4_in_place_dispatch {
322    ($ty:ty, $function:ident) => {
323        impl ColorTwistBatchWithConstantsC4InPlace for $ty {
324            fn color_twist_batch_with_constants_c4_in_place(
325                stream_context: &StreamContext,
326                images: &mut [ImageViewMut<'_, Self, C4>],
327                twists: &[ColorTwistBatchConstantsMatrix4],
328                min: f32,
329                max: f32,
330            ) -> Result<()> {
331                $function(stream_context, images, twists, min, max)
332            }
333        }
334    };
335}
336
337impl_color_twist_batch_with_constants_c4_in_place_dispatch!(
338    u8,
339    color_twist_batch_u8_c4_with_constants_in_place
340);
341impl_color_twist_batch_with_constants_c4_in_place_dispatch!(
342    f16,
343    color_twist_batch_f16_c4_with_constants_in_place
344);
345impl_color_twist_batch_with_constants_c4_in_place_dispatch!(
346    f32,
347    color_twist_batch_f32_c4_with_constants_in_place
348);
349
350pub fn color_twist_batch_c4_with_constants_in_place<T>(
351    stream_context: &StreamContext,
352    images: &mut [ImageViewMut<'_, T, C4>],
353    twists: &[ColorTwistBatchConstantsMatrix4],
354    min: f32,
355    max: f32,
356) -> Result<()>
357where
358    T: ColorTwistBatchWithConstantsC4InPlace,
359{
360    T::color_twist_batch_with_constants_c4_in_place(stream_context, images, twists, min, max)
361}