@@ -29,28 +29,16 @@ enum Cmp {
29
29
Le ,
30
30
}
31
31
32
- trait DType :
33
- Sized
34
- + Copy
35
- + Add < Output = Self >
36
- + Div < Output = Self >
37
- + Mul < Output = Self >
38
- + Sub < Output = Self >
39
- + Rem < Output = Self >
32
+ trait DT :
33
+ Sized + Copy + Add < Output = Self > + Div < Output = Self > + Mul < Output = Self > + Sub < Output = Self > + Rem < Output = Self >
40
34
{
41
35
fn f32 ( b : f32 ) -> Self ;
42
36
fn fma ( self , mul : Self , add : Self ) -> Self ;
43
37
fn powf ( self , b : Self ) -> Self ;
44
- fn branch < F : FnOnce ( ) -> Self , G : FnOnce ( ) -> Self > (
45
- self ,
46
- b : Self ,
47
- cmp : Cmp ,
48
- x : F ,
49
- y : G ,
50
- ) -> Self ;
38
+ fn branch < F : FnOnce ( ) -> Self , G : FnOnce ( ) -> Self > ( self , b : Self , cmp : Cmp , x : F , y : G ) -> Self ;
51
39
}
52
40
53
- impl DType for f32 {
41
+ impl DT for f32 {
54
42
fn f32 ( b : f32 ) -> Self {
55
43
b
56
44
}
@@ -63,13 +51,7 @@ impl DType for f32 {
63
51
self . powf ( b)
64
52
}
65
53
66
- fn branch < F : FnOnce ( ) -> Self , G : FnOnce ( ) -> Self > (
67
- self ,
68
- b : Self ,
69
- cmp : Cmp ,
70
- x : F ,
71
- y : G ,
72
- ) -> Self {
54
+ fn branch < F : FnOnce ( ) -> Self , G : FnOnce ( ) -> Self > ( self , b : Self , cmp : Cmp , x : F , y : G ) -> Self {
73
55
if match cmp {
74
56
Cmp :: Gt => self > b,
75
57
Cmp :: Lt => self < b,
@@ -83,7 +65,7 @@ impl DType for f32 {
83
65
}
84
66
}
85
67
86
- impl DType for f64 {
68
+ impl DT for f64 {
87
69
fn f32 ( b : f32 ) -> Self {
88
70
b. into ( )
89
71
}
@@ -96,13 +78,7 @@ impl DType for f64 {
96
78
self . powf ( b)
97
79
}
98
80
99
- fn branch < F : FnOnce ( ) -> Self , G : FnOnce ( ) -> Self > (
100
- self ,
101
- b : Self ,
102
- cmp : Cmp ,
103
- x : F ,
104
- y : G ,
105
- ) -> Self {
81
+ fn branch < F : FnOnce ( ) -> Self , G : FnOnce ( ) -> Self > ( self , b : Self , cmp : Cmp , x : F , y : G ) -> Self {
106
82
if match cmp {
107
83
Cmp :: Gt => self > b,
108
84
Cmp :: Lt => self < b,
@@ -117,7 +93,7 @@ impl DType for f64 {
117
93
}
118
94
119
95
#[ cfg( feature = "nightly" ) ]
120
- impl < const N : usize > DType for Simd < f32 , N >
96
+ impl < const N : usize > DT for Simd < f32 , N >
121
97
where
122
98
LaneCount < N > : SupportedLaneCount ,
123
99
{
@@ -137,13 +113,7 @@ where
137
113
self
138
114
}
139
115
140
- fn branch < F : FnOnce ( ) -> Self , G : FnOnce ( ) -> Self > (
141
- self ,
142
- b : Self ,
143
- cmp : Cmp ,
144
- x : F ,
145
- y : G ,
146
- ) -> Self {
116
+ fn branch < F : FnOnce ( ) -> Self , G : FnOnce ( ) -> Self > ( self , b : Self , cmp : Cmp , x : F , y : G ) -> Self {
147
117
match cmp {
148
118
Cmp :: Gt => self . simd_gt ( b) ,
149
119
Cmp :: Lt => self . simd_lt ( b) ,
@@ -152,6 +122,7 @@ where
152
122
}
153
123
. select ( x ( ) , y ( ) )
154
124
}
125
+ }
155
126
156
127
/// Create an array of separate channel buffers from a single interwoven buffer.
157
128
/// Copies the data.
@@ -307,6 +278,7 @@ const ICTCP_M2_INV: [[f32; 3]; 3] = [
307
278
[ 1. , -0.008609037 , -0.111029625 ] ,
308
279
[ 1. , 0.5600313357 , -0.320627175 ] ,
309
280
] ;
281
+
310
282
/// 3 * 3x3 Matrix multiply with vector transposed, ie pixel @ matrix
311
283
fn matmul3t ( pixel : [ f32 ; 3 ] , matrix : [ [ f32 ; 3 ] ; 3 ] ) -> [ f32 ; 3 ] {
312
284
[
@@ -317,11 +289,11 @@ fn matmul3t(pixel: [f32; 3], matrix: [[f32; 3]; 3]) -> [f32; 3] {
317
289
}
318
290
319
291
/// Transposed 3 * 3x3 matrix multiply, ie matrix @ pixel
320
- fn matmul3 < T : DType > ( matrix : [ [ f32 ; 3 ] ; 3 ] , pixel : [ T ; 3 ] ) -> [ T ; 3 ] {
292
+ fn matmul3 < T : DT > ( m : [ [ f32 ; 3 ] ; 3 ] , p : [ T ; 3 ] ) -> [ T ; 3 ] {
321
293
[
322
- pixel [ 0 ] . fma ( DType :: f32 ( matrix [ 0 ] [ 0 ] ) , pixel [ 1 ] . fma ( DType :: f32 ( matrix [ 0 ] [ 1 ] ) , pixel [ 2 ] * DType :: f32 ( matrix [ 0 ] [ 2 ] ) ) ) ,
323
- pixel [ 0 ] . fma ( DType :: f32 ( matrix [ 1 ] [ 0 ] ) , pixel [ 1 ] . fma ( DType :: f32 ( matrix [ 1 ] [ 1 ] ) , pixel [ 2 ] * DType :: f32 ( matrix [ 1 ] [ 2 ] ) ) ) ,
324
- pixel [ 0 ] . fma ( DType :: f32 ( matrix [ 2 ] [ 0 ] ) , pixel [ 1 ] . fma ( DType :: f32 ( matrix [ 2 ] [ 1 ] ) , pixel [ 2 ] * DType :: f32 ( matrix [ 2 ] [ 2 ] ) ) ) ,
294
+ p [ 0 ] . fma ( DT :: f32 ( m [ 0 ] [ 0 ] ) , p [ 1 ] . fma ( DT :: f32 ( m [ 0 ] [ 1 ] ) , p [ 2 ] * DT :: f32 ( m [ 0 ] [ 2 ] ) ) ) ,
295
+ p [ 0 ] . fma ( DT :: f32 ( m [ 1 ] [ 0 ] ) , p [ 1 ] . fma ( DT :: f32 ( m [ 1 ] [ 1 ] ) , p [ 2 ] * DT :: f32 ( m [ 1 ] [ 2 ] ) ) ) ,
296
+ p [ 0 ] . fma ( DT :: f32 ( m [ 2 ] [ 0 ] ) , p [ 1 ] . fma ( DT :: f32 ( m [ 2 ] [ 1 ] ) , p [ 2 ] * DT :: f32 ( m [ 2 ] [ 2 ] ) ) ) ,
325
297
]
326
298
}
327
299
// ### MATRICES ### }}}
@@ -340,15 +312,12 @@ fn matmul3<T: DType>(matrix: [[f32; 3]; 3], pixel: [T; 3]) -> [T; 3] {
340
312
// }
341
313
//}
342
314
343
- pub fn srgb_eotf < T : DType > ( n : T ) -> T {
315
+ pub fn srgb_eotf < T : DT > ( n : T ) -> T {
344
316
n. branch (
345
- DType :: f32 ( SRGBEOTF_CHI ) ,
317
+ DT :: f32 ( SRGBEOTF_CHI ) ,
346
318
Cmp :: Le ,
347
- || n / DType :: f32 ( SRGBEOTF_PHI ) ,
348
- || {
349
- ( ( n + DType :: f32 ( SRGBEOTF_ALPHA ) ) / DType :: f32 ( SRGBEOTF_ALPHA + 1.0 ) )
350
- . powf ( DType :: f32 ( SRGBEOTF_GAMMA ) )
351
- } ,
319
+ || n / DT :: f32 ( SRGBEOTF_PHI ) ,
320
+ || ( ( n + DT :: f32 ( SRGBEOTF_ALPHA ) ) / DT :: f32 ( SRGBEOTF_ALPHA + 1.0 ) ) . powf ( DT :: f32 ( SRGBEOTF_GAMMA ) ) ,
352
321
)
353
322
}
354
323
@@ -1062,7 +1031,7 @@ pub extern "C" fn srgb_to_lrgb(pixel: &mut [f32; 3]) {
1062
1031
/// Convert from Linear Light RGB to CIE XYZ, D65 standard illuminant
1063
1032
///
1064
1033
/// <https://en.wikipedia.org/wiki/SRGB#From_sRGB_to_CIE_XYZ>
1065
- pub fn lrgb_to_xyz < T : DType > ( pixel : & mut [ T ; 3 ] ) {
1034
+ pub fn lrgb_to_xyz < T : DT > ( pixel : & mut [ T ; 3 ] ) {
1066
1035
* pixel = matmul3 ( XYZ65_MAT , * pixel)
1067
1036
}
1068
1037
0 commit comments