@@ -17,6 +17,13 @@ use core::ops::{Add, Div, Mul, Neg, Rem, Sub};
17
17
18
18
// DType {{{
19
19
20
+ /// 3 channels, or 4 with alpha. Alpha ignored.
21
+ pub struct Channels < const N : usize > ;
22
+ /// 3 channels, or 4 with alpha. Alpha ignored.
23
+ pub trait ValidChannels { }
24
+ impl ValidChannels for Channels < 3 > { }
25
+ impl ValidChannels for Channels < 4 > { }
26
+
20
27
#[ allow( missing_docs) ]
21
28
/// Convert an F32 ito any supported DType
22
29
pub trait FromF32 : Sized {
@@ -754,9 +761,10 @@ macro_rules! op_chunk {
754
761
755
762
macro_rules! op_inter {
756
763
( $func: ident, $data: expr) => {
757
- $data
758
- . chunks_exact_mut( 3 )
759
- . for_each( |pixel| $func( pixel. try_into( ) . unwrap( ) ) )
764
+ $data. chunks_exact_mut( 3 ) . for_each( |pixel| {
765
+ let pixel: & mut [ T ; 3 ] = unsafe { pixel. try_into( ) . unwrap_unchecked( ) } ;
766
+ $func( pixel) ;
767
+ } )
760
768
} ;
761
769
}
762
770
@@ -1037,8 +1045,11 @@ pub fn srgb_to_hsv<T: DType>(pixel: &mut [T; 3]) {
1037
1045
/// Convert from sRGB to Linear RGB by applying the sRGB EOTF
1038
1046
///
1039
1047
/// <https://www.color.org/chardata/rgb/srgb.xalter>
1040
- pub fn srgb_to_lrgb < T : DType > ( pixel : & mut [ T ; 3 ] ) {
1041
- pixel. iter_mut ( ) . for_each ( |c| * c = srgb_eotf ( * c) ) ;
1048
+ pub fn srgb_to_lrgb < T : DType , const N : usize > ( pixel : & mut [ T ; N ] )
1049
+ where
1050
+ Channels < N > : ValidChannels ,
1051
+ {
1052
+ pixel. iter_mut ( ) . take ( 3 ) . for_each ( |c| * c = srgb_eotf ( * c) ) ;
1042
1053
}
1043
1054
1044
1055
/// Convert from Linear Light RGB to CIE XYZ, D65 standard illuminant
0 commit comments