mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-01 05:57:09 -06:00
Clamp negative signals to zero in hlg_decode
Found while testing crates/color/src/transfer.rs:52 Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
38f8d25087
commit
89e08db8b8
@@ -49,6 +49,7 @@ pub fn hlg_encode(e: f64) -> f64 {
|
||||
}
|
||||
|
||||
pub fn hlg_decode(s: f64) -> f64 {
|
||||
let s = s.max(0.0);
|
||||
if s <= 0.5 { s * s / 3.0 } else { (((s - HLG_C) / HLG_A).exp() + HLG_B) / 12.0 }
|
||||
}
|
||||
|
||||
@@ -112,6 +113,11 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hlg_decode_clamps_negative() {
|
||||
assert_eq!(hlg_decode(-0.5), 0.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pq_hlg_roundtrip() {
|
||||
for i in 0..=50 {
|
||||
|
||||
Reference in New Issue
Block a user