From 090a2172da3957cc9f59f9ef132ddb1d5c1734b9 Mon Sep 17 00:00:00 2001 From: Franco Colmenarez Date: Mon, 4 Nov 2024 15:54:32 -0500 Subject: [PATCH] rgb555 to rgb888 converter --- snes-core/src/utils/color.rs | 29 +++++++++++++++++++++++++++++ snes-core/src/utils/mod.rs | 1 + 2 files changed, 30 insertions(+) create mode 100644 snes-core/src/utils/color.rs diff --git a/snes-core/src/utils/color.rs b/snes-core/src/utils/color.rs new file mode 100644 index 0000000..b45d52a --- /dev/null +++ b/snes-core/src/utils/color.rs @@ -0,0 +1,29 @@ +pub fn rbg555_to_rgb888(rgb555: (u8, u8, u8)) -> (u8, u8, u8) { + let red = rgb555.0 & 0b11111; + let green = rgb555.1 & 0b11111; + let blue = rgb555.2 & 0b11111; + ( + (red << 3) | (red >> 2), + (green << 3) | (green >> 2), + (blue << 3) | (blue >> 2), + ) +} + + +#[cfg(test)] +mod color_tests { + use super::*; + + #[test] + fn test_rbg555_to_rgb888() { + assert_eq!(rbg555_to_rgb888((0x00, 0x00, 0x00)), (0x00, 0x00, 0x00)); + assert_eq!( + rbg555_to_rgb888((0b0001_1111, 0b0001_1111, 0b0001_1111)), + (0xFF, 0xFF, 0xFF) + ); + assert_eq!( + rbg555_to_rgb888((0b10101, 0b01010, 0b11011)), + (0xAD, 0x52, 0xDE) + ); + } +} \ No newline at end of file diff --git a/snes-core/src/utils/mod.rs b/snes-core/src/utils/mod.rs index 6112635..fa36a3d 100644 --- a/snes-core/src/utils/mod.rs +++ b/snes-core/src/utils/mod.rs @@ -1,3 +1,4 @@ pub mod alu; pub mod addressing; pub mod num_trait; +pub mod color;