diff --git a/bent-funny-zone/src/main.rs b/bent-funny-zone/src/main.rs index 1498eb0..acecaba 100644 --- a/bent-funny-zone/src/main.rs +++ b/bent-funny-zone/src/main.rs @@ -28,22 +28,28 @@ fn rgb_to_sample>(pix: Pixel) -> T { fn sample_to_rgb>(sample: T) -> Pixel { let rgb: U24 = sample.to_sample(); - let rg = rgb >> 8.into(); - let r = rg >> 8.into(); + let rgo = ((rgb) >> 8.into()) << 8.into(); + let roo = ((rgo) >> 16.into()) << 16.into(); Pixel::new( - r.inner() as u8, - (rg - r).inner() as u8, - (rgb - rg).inner() as u8, + ((roo) >> 16.into()).inner() as u8, + ((rgo - roo) >> 8.into()).inner() as u8, + (rgb - rgo).inner() as u8, ) } #[cfg(test)] mod tests { use bmp::Pixel; - use dasp_sample::{I24, I48, U24, U48}; + use dasp_sample::{Sample, I24, I48, U24, U48}; use super::{rgb_to_sample, sample_to_rgb}; + #[test] + fn sample_convert_consistency() { + let original = U24::from(42); + assert_eq!(original.clone(), original.to_sample::().to_sample()) + } + #[test] fn rgb2s2rgb_type_consistency() { let pix = Pixel::new(45, 18, 143); @@ -63,7 +69,7 @@ mod tests { #[test] fn rgb2s2rgb() { - let pix = dbg!(Pixel::new(45, 18, 143)); - assert_eq!(pix, dbg!(sample_to_rgb(dbg!(rgb_to_sample::(pix))))); + let pix = Pixel::new(45, 18, 143); + assert_eq!(pix, (sample_to_rgb(rgb_to_sample::(pix)))); } }