Skip to content

Commit 5158488

Browse files
committed
srgb_to_hsv 50% faster
Iterators OP
1 parent 37f7d61 commit 5158488

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/lib.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -1074,16 +1074,18 @@ where
10741074
} else {
10751075
let s = dmax / vmax;
10761076

1077-
let dr = (((vmax - pixel[0]) / 6.0.to_dt()) + (dmax / 2.0.to_dt())) / dmax;
1078-
let dg = (((vmax - pixel[1]) / 6.0.to_dt()) + (dmax / 2.0.to_dt())) / dmax;
1079-
let db = (((vmax - pixel[2]) / 6.0.to_dt()) + (dmax / 2.0.to_dt())) / dmax;
1080-
1081-
let h = if pixel[0] == vmax {
1082-
db - dg
1083-
} else if pixel[1] == vmax {
1084-
T::ff32(1.0 / 3.0) + dr - db
1077+
let [branch_0, branch_1] = [pixel[0] == vmax, pixel[1] == vmax];
1078+
1079+
pixel.iter_mut().take(3).for_each(|c| {
1080+
*c = (((vmax - *c) / 6.0.to_dt()) + (dmax / 2.0.to_dt())) / dmax;
1081+
});
1082+
1083+
let h = if branch_0 {
1084+
pixel[2] - pixel[1]
1085+
} else if branch_1 {
1086+
T::ff32(1.0 / 3.0) + pixel[0] - pixel[2]
10851087
} else {
1086-
T::ff32(2.0 / 3.0) + dg - dr
1088+
T::ff32(2.0 / 3.0) + pixel[1] - pixel[0]
10871089
}
10881090
.rem_euclid(1.0.to_dt());
10891091
(h, s)

0 commit comments

Comments
 (0)