rgb555 to rgb888 converter

This commit is contained in:
2024-11-04 15:54:32 -05:00
parent e6c57e8046
commit 090a2172da
2 changed files with 30 additions and 0 deletions
+29
View File
@@ -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)
);
}
}
+1
View File
@@ -1,3 +1,4 @@
pub mod alu; pub mod alu;
pub mod addressing; pub mod addressing;
pub mod num_trait; pub mod num_trait;
pub mod color;