diff --git a/crates/ec-image/src/lib.rs b/crates/ec-image/src/lib.rs index ef163d62..cc8f4ec9 100644 --- a/crates/ec-image/src/lib.rs +++ b/crates/ec-image/src/lib.rs @@ -333,11 +333,6 @@ fn narrow(v: u16) -> u8 { ((u32::from(v) + 128) / 257) as u8 } -/// 8-bit sample widened to 16: `v * 65535 / 255`, exact. -fn widen(v: u8) -> u16 { - u16::from(v) * 257 -} - impl Image { /// `(width, height)`. pub fn dimensions(&self) -> (u32, u32) { @@ -404,34 +399,6 @@ impl Image { out } - /// Packed 16-bit R,G,B — 8-bit sources widened exactly (`v * 257`). - pub fn to_rgb16(&self) -> Vec { - match &self.pixels { - Pixels::Rgb16(d) => d.clone(), - Pixels::Rgba16(d) => d.as_chunks::<4>().0.iter().flat_map(|p| p[..3].to_vec()).collect(), - Pixels::L16(d) => d.iter().flat_map(|&l| [l, l, l]).collect(), - Pixels::La16(d) => d.as_chunks::<2>().0.iter().flat_map(|p| [p[0], p[0], p[0]]).collect(), - _ => self.to_rgb8().into_iter().map(widen).collect(), - } - } - - /// Packed 16-bit R,G,B,A; opaque where the source had no alpha. - pub fn to_rgba16(&self) -> Vec { - match &self.pixels { - Pixels::Rgba16(d) => d.clone(), - Pixels::Rgb16(d) => d - .as_chunks::<3>().0.iter() - .flat_map(|p| [p[0], p[1], p[2], u16::MAX]) - .collect(), - Pixels::L16(d) => d.iter().flat_map(|&l| [l, l, l, u16::MAX]).collect(), - Pixels::La16(d) => d - .as_chunks::<2>().0.iter() - .flat_map(|p| [p[0], p[0], p[0], p[1]]) - .collect(), - _ => self.to_rgba8().into_iter().map(widen).collect(), - } - } - /// The image as an [`ec_core::VideoFrame`], packed RGB8 or RGBA8. /// /// The natural bridge for a caller that composes stills and decoded video @@ -552,12 +519,6 @@ pub fn open(path: impl AsRef) -> Result { decode(&data) } -/// Read the file at `path` and report its header dimensions. -pub fn open_info(path: impl AsRef) -> Result { - let data = std::fs::read(path).map_err(Error::Io)?; - info(&data) -} - #[cfg(test)] mod tests { use super::*; @@ -582,7 +543,7 @@ mod tests { #[test] fn sample_conversion_round_trips_through_eight_bits() { for v in 0..=255u8 { - assert_eq!(narrow(widen(v)), v, "{v}"); + assert_eq!(narrow(u16::from(v) * 257), v, "{v}"); } assert_eq!(narrow(0), 0); assert_eq!(narrow(u16::MAX), 255); diff --git a/crates/ec-image/tests/it/differential.rs b/crates/ec-image/tests/it/differential.rs index caeb8346..7d0ffc00 100644 --- a/crates/ec-image/tests/it/differential.rs +++ b/crates/ec-image/tests/it/differential.rs @@ -85,6 +85,17 @@ fn psnr(a: &[u8], b: &[u8]) -> f64 { } } +fn rgba16(img: &ec_image::Image) -> Vec { + use ec_image::Pixels; + match &img.pixels { + Pixels::L16(d) => d.iter().flat_map(|&l| [l, l, l, u16::MAX]).collect(), + Pixels::La16(d) => d.as_chunks::<2>().0.iter().flat_map(|p| [p[0], p[0], p[0], p[1]]).collect(), + Pixels::Rgb16(d) => d.as_chunks::<3>().0.iter().flat_map(|p| [p[0], p[1], p[2], u16::MAX]).collect(), + Pixels::Rgba16(d) => d.clone(), + _ => unreachable!("only called for 16-bit pictures"), + } +} + #[test] fn png_decodes_pixel_exactly() { let files = corpus("png"); @@ -102,7 +113,7 @@ fn png_decodes_pixel_exactly() { if ours.pixels.bit_depth() == 16 { // Compared at 16 bits so the comparison is not laundered through // two different 16-to-8 rounding conventions. - let a = ours.to_rgba16(); + let a = rgba16(&ours); let b = theirs.to_rgba16().into_raw(); assert_eq!(a, b, "{} (16-bit samples)", path.display()); } else {