Skip to content

Commit

Permalink
Added test of ToU8ForWriting. Found a bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
zond committed Sep 19, 2024
1 parent b56d3f5 commit 772b64d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion jxl/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pub mod debug_tools {

impl ToU8ForWriting for u16 {
fn to_u8_for_writing(self) -> u8 {
(self as u32 * 255 / 65535) as u8
(self as u32 >> 8) as u8
}
}

Expand Down Expand Up @@ -255,4 +255,14 @@ mod test {
assert!(image.as_rect().to_pgm().starts_with(b"P5\n32 32\n255\n"));
Ok(())
}

#[cfg(feature = "debug_tools")]
#[test]
fn to_u8() {
use super::debug_tools::ToU8ForWriting;
assert!(0xd7a0u16.to_u8_for_writing() == 0xd7);
assert!(0.5f32.to_u8_for_writing() == 0x80);
assert!(0xd7a02953u32.to_u8_for_writing() == 0xd7);
assert!((half::f16::from_f32(0.5)).to_u8_for_writing() == 0x80);
}
}

0 comments on commit 772b64d

Please sign in to comment.