@@ -13,7 +13,7 @@ mod tests;
13
13
14
14
use core:: cmp:: PartialOrd ;
15
15
use core:: ffi:: { c_char, CStr } ;
16
- use core:: ops:: { Add , Div , Mul , Rem , Sub } ;
16
+ use core:: ops:: { Add , Div , Mul , Neg , Rem , Sub } ;
17
17
18
18
// DType {{{
19
19
@@ -56,8 +56,9 @@ pub trait DType:
56
56
+ Add < Output = Self >
57
57
+ Div < Output = Self >
58
58
+ Mul < Output = Self >
59
- + Sub < Output = Self >
59
+ + Neg < Output = Self >
60
60
+ Rem < Output = Self >
61
+ + Sub < Output = Self >
61
62
+ PartialOrd
62
63
+ FromF32
63
64
{
@@ -356,7 +357,7 @@ fn pq_eotf_common<T: DType>(e: T, m2: T) -> T {
356
357
let ep_pow_1divm2 = e. spowf ( T :: ff32 ( 1.0 ) / m2) ;
357
358
358
359
let numerator: T = ( ep_pow_1divm2 - PQEOTF_C1 . to_dt ( ) ) . max ( 0.0 . to_dt ( ) ) ;
359
- let denominator: T = T :: ff32 ( PQEOTF_C2 ) - T :: ff32 ( PQEOTF_C3 ) * ep_pow_1divm2 ;
360
+ let denominator: T = ep_pow_1divm2 . fma ( T :: ff32 ( - PQEOTF_C3 ) , PQEOTF_C2 . to_dt ( ) ) ;
360
361
361
362
let y = ( numerator / denominator) . spowf ( ( 1.0 / PQEOTF_M1 ) . to_dt ( ) ) ;
362
363
@@ -1018,9 +1019,7 @@ pub fn srgb_to_hsv<T: DType>(pixel: &mut [T; 3]) {
1018
1019
} else {
1019
1020
let s = dmax / vmax;
1020
1021
1021
- let dr = ( ( ( vmax - pixel[ 0 ] ) / 6.0 . to_dt ( ) ) + ( dmax / 2.0 . to_dt ( ) ) ) / dmax;
1022
- let dg = ( ( ( vmax - pixel[ 1 ] ) / 6.0 . to_dt ( ) ) + ( dmax / 2.0 . to_dt ( ) ) ) / dmax;
1023
- let db = ( ( ( vmax - pixel[ 2 ] ) / 6.0 . to_dt ( ) ) + ( dmax / 2.0 . to_dt ( ) ) ) / dmax;
1022
+ let [ dr, dg, db] = pixel. map ( |c| ( ( ( vmax - c) / 6.0 . to_dt ( ) ) + ( dmax / 2.0 . to_dt ( ) ) ) / dmax) ;
1024
1023
1025
1024
let h = if pixel[ 0 ] == vmax {
1026
1025
db - dg
@@ -1065,7 +1064,7 @@ pub fn xyz_to_cielab<T: DType>(pixel: &mut [T; 3]) {
1065
1064
} ) ;
1066
1065
1067
1066
* pixel = [
1068
- ( T :: ff32 ( 116.0 ) * pixel[ 1 ] ) - 16.0 . to_dt ( ) ,
1067
+ T :: ff32 ( 116.0 ) . fma ( pixel[ 1 ] , T :: ff32 ( - 16.0 ) ) ,
1069
1068
T :: ff32 ( 500.0 ) * ( pixel[ 0 ] - pixel[ 1 ] ) ,
1070
1069
T :: ff32 ( 200.0 ) * ( pixel[ 1 ] - pixel[ 2 ] ) ,
1071
1070
]
@@ -1087,8 +1086,8 @@ pub fn xyz_to_jzazbz<T: DType>(pixel: &mut [T; 3]) {
1087
1086
let mut lms = matmul3 (
1088
1087
JZAZBZ_M1 ,
1089
1088
[
1090
- pixel[ 0 ] * JZAZBZ_B . to_dt ( ) - T :: ff32 ( JZAZBZ_B - 1.0 ) * pixel[ 2 ] ,
1091
- pixel[ 1 ] * JZAZBZ_G . to_dt ( ) - T :: ff32 ( JZAZBZ_G - 1.0 ) * pixel[ 0 ] ,
1089
+ pixel[ 0 ] . fma ( JZAZBZ_B . to_dt ( ) , T :: ff32 ( - JZAZBZ_B + 1.0 ) * pixel[ 2 ] ) ,
1090
+ pixel[ 1 ] . fma ( JZAZBZ_G . to_dt ( ) , T :: ff32 ( - JZAZBZ_G + 1.0 ) * pixel[ 0 ] ) ,
1092
1091
pixel[ 2 ] ,
1093
1092
] ,
1094
1093
) ;
@@ -1198,8 +1197,8 @@ pub fn hsv_to_srgb<T: DType>(pixel: &mut [T; 3]) {
1198
1197
}
1199
1198
let var_i = var_h. trunc ( ) ;
1200
1199
let var_1 = pixel[ 2 ] * ( T :: ff32 ( 1.0 ) - pixel[ 1 ] ) ;
1201
- let var_2 = pixel[ 2 ] * ( T :: ff32 ( 1.0 ) - pixel[ 1 ] * ( var_h - var_i ) ) ;
1202
- let var_3 = pixel[ 2 ] * ( T :: ff32 ( 1.0 ) - pixel[ 1 ] * ( T :: ff32 ( 1.0 ) - ( var_h - var_i ) ) ) ;
1200
+ let var_2 = pixel[ 2 ] * ( -var_h + var_i ) . fma ( pixel[ 1 ] , 1.0 . to_dt ( ) ) ;
1201
+ let var_3 = pixel[ 2 ] * ( T :: ff32 ( - 1.0 ) + ( var_h - var_i ) ) . fma ( pixel[ 1 ] , T :: ff32 ( 1.0 ) ) ;
1203
1202
1204
1203
* pixel = if var_i == 0.0 . to_dt ( ) {
1205
1204
[ pixel[ 2 ] , var_3, var_1]
@@ -1269,7 +1268,7 @@ pub fn jzazbz_to_xyz<T: DType>(pixel: &mut [T; 3]) {
1269
1268
JZAZBZ_M2_INV ,
1270
1269
[
1271
1270
( pixel[ 0 ] + JZAZBZ_D0 . to_dt ( ) )
1272
- / ( T :: ff32 ( 1.0 + JZAZBZ_D ) - T :: ff32 ( JZAZBZ_D ) * ( pixel [ 0 ] + JZAZBZ_D0 . to_dt ( ) ) ) ,
1271
+ / ( pixel [ 0 ] + JZAZBZ_D0 . to_dt ( ) ) . fma ( T :: ff32 ( - JZAZBZ_D ) , T :: ff32 ( 1.0 + JZAZBZ_D ) ) ,
1273
1272
pixel[ 1 ] ,
1274
1273
pixel[ 2 ] ,
1275
1274
] ,
0 commit comments