mirror of
https://github.com/storytold/effectcraft.git
synced 2026-12-02 15:01:26 -05:00
Make premultiplied RGB zero deterministic across platforms
This commit is contained in:
@@ -72,7 +72,13 @@ impl AlphaOp {
|
||||
// premultiplied against a matte colour m: c = s·a + m·(1−a) → s·a = c − m·(1−a)
|
||||
let k = 1.0 - a;
|
||||
let m = self.matte;
|
||||
[(c[0] - m[0] * k).max(0.0), (c[1] - m[1] * k).max(0.0), (c[2] - m[2] * k).max(0.0), a]
|
||||
let unmatte = |value: f32, matte: f32| {
|
||||
let value = value - matte * k;
|
||||
// `max` may retain negative zero depending on the platform. Keep
|
||||
// clamped premultiplied samples bit-identical, including transparent RGB.
|
||||
if value > 0.0 { value } else { 0.0 }
|
||||
};
|
||||
[unmatte(c[0], m[0]), unmatte(c[1], m[1]), unmatte(c[2], m[2]), a]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user