Skip to content

Commit f51e096

Browse files
committed
Rustfmt
1 parent bf2c194 commit f51e096

File tree

1 file changed

+20
-51
lines changed

1 file changed

+20
-51
lines changed

src/lib.rs

+20-51
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,16 @@ enum Cmp {
2929
Le,
3030
}
3131

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>
4034
{
4135
fn f32(b: f32) -> Self;
4236
fn fma(self, mul: Self, add: Self) -> Self;
4337
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;
5139
}
5240

53-
impl DType for f32 {
41+
impl DT for f32 {
5442
fn f32(b: f32) -> Self {
5543
b
5644
}
@@ -63,13 +51,7 @@ impl DType for f32 {
6351
self.powf(b)
6452
}
6553

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 {
7355
if match cmp {
7456
Cmp::Gt => self > b,
7557
Cmp::Lt => self < b,
@@ -83,7 +65,7 @@ impl DType for f32 {
8365
}
8466
}
8567

86-
impl DType for f64 {
68+
impl DT for f64 {
8769
fn f32(b: f32) -> Self {
8870
b.into()
8971
}
@@ -96,13 +78,7 @@ impl DType for f64 {
9678
self.powf(b)
9779
}
9880

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 {
10682
if match cmp {
10783
Cmp::Gt => self > b,
10884
Cmp::Lt => self < b,
@@ -117,7 +93,7 @@ impl DType for f64 {
11793
}
11894

11995
#[cfg(feature = "nightly")]
120-
impl<const N: usize> DType for Simd<f32, N>
96+
impl<const N: usize> DT for Simd<f32, N>
12197
where
12298
LaneCount<N>: SupportedLaneCount,
12399
{
@@ -137,13 +113,7 @@ where
137113
self
138114
}
139115

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 {
147117
match cmp {
148118
Cmp::Gt => self.simd_gt(b),
149119
Cmp::Lt => self.simd_lt(b),
@@ -152,6 +122,7 @@ where
152122
}
153123
.select(x(), y())
154124
}
125+
}
155126

156127
/// Create an array of separate channel buffers from a single interwoven buffer.
157128
/// Copies the data.
@@ -307,6 +278,7 @@ const ICTCP_M2_INV: [[f32; 3]; 3] = [
307278
[1., -0.008609037, -0.111029625],
308279
[1., 0.5600313357, -0.320627175],
309280
];
281+
310282
/// 3 * 3x3 Matrix multiply with vector transposed, ie pixel @ matrix
311283
fn matmul3t(pixel: [f32; 3], matrix: [[f32; 3]; 3]) -> [f32; 3] {
312284
[
@@ -317,11 +289,11 @@ fn matmul3t(pixel: [f32; 3], matrix: [[f32; 3]; 3]) -> [f32; 3] {
317289
}
318290

319291
/// 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] {
321293
[
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]))),
325297
]
326298
}
327299
// ### MATRICES ### }}}
@@ -340,15 +312,12 @@ fn matmul3<T: DType>(matrix: [[f32; 3]; 3], pixel: [T; 3]) -> [T; 3] {
340312
// }
341313
//}
342314

343-
pub fn srgb_eotf<T: DType>(n: T) -> T {
315+
pub fn srgb_eotf<T: DT>(n: T) -> T {
344316
n.branch(
345-
DType::f32(SRGBEOTF_CHI),
317+
DT::f32(SRGBEOTF_CHI),
346318
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)),
352321
)
353322
}
354323

@@ -1062,7 +1031,7 @@ pub extern "C" fn srgb_to_lrgb(pixel: &mut [f32; 3]) {
10621031
/// Convert from Linear Light RGB to CIE XYZ, D65 standard illuminant
10631032
///
10641033
/// <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]) {
10661035
*pixel = matmul3(XYZ65_MAT, *pixel)
10671036
}
10681037

0 commit comments

Comments
 (0)