working
This commit is contained in:
parent
d23ba1a238
commit
453dda5111
1 changed files with 14 additions and 8 deletions
|
@ -28,22 +28,28 @@ fn rgb_to_sample<T: Sample + FromSample<U24>>(pix: Pixel) -> T {
|
|||
|
||||
fn sample_to_rgb<T: Sample + ToSample<U24>>(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::<f64>().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::<f64>(pix)))));
|
||||
let pix = Pixel::new(45, 18, 143);
|
||||
assert_eq!(pix, (sample_to_rgb(rgb_to_sample::<f64>(pix))));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue