From 3dcdc36c067aaba6c716aa4de77dbe0e82a4ab03 Mon Sep 17 00:00:00 2001 From: Atreya Bain Date: Mon, 19 Feb 2024 09:07:28 +0530 Subject: [PATCH] [col] Refactor color constants --- src/graphics/color.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/graphics/color.rs b/src/graphics/color.rs index 00d9ccc..7f6e61c 100644 --- a/src/graphics/color.rs +++ b/src/graphics/color.rs @@ -4,10 +4,12 @@ use crate::misc::result::EmulatorResult; #[derive(Debug, Copy, Clone)] pub struct Color(u8); -const RED_MULT: u8 = 36; -const GREEN_MULT: u8 = 6; impl Color { + /// Red color offset in the colour byte + const RED_MULT: u8 = 36; + /// green color offset in the colour byte + const GREEN_MULT: u8 = 6; /// Only first 216 color indices are used. const COLOR_MAX: u8 = 215; const COLOR_FACTOR_8_BIT: u8 = 0x33; @@ -16,7 +18,7 @@ impl Color { let red = red / Self::COLOR_FACTOR_8_BIT; let green = green / Self::COLOR_FACTOR_8_BIT; let blue = blue / Self::COLOR_FACTOR_8_BIT; - Color(red * RED_MULT + green * GREEN_MULT + blue) + Color(red * Self::RED_MULT + green * Self::GREEN_MULT + blue) } pub fn try_new(in_mem_color: u8) -> EmulatorResult { if in_mem_color > Self::COLOR_MAX { @@ -29,10 +31,10 @@ impl Color { } /// This fetches the rgb triplet pub fn get_rgb(self) -> [u8; 3] { - let r = self.0 / RED_MULT; - let gb_byte_remainder = self.0 % RED_MULT; - let g = gb_byte_remainder / GREEN_MULT; - let b = gb_byte_remainder % GREEN_MULT; + let r = self.0 / Self::RED_MULT; + let gb_byte_remainder = self.0 % Self::RED_MULT; + let g = gb_byte_remainder / Self::GREEN_MULT; + let b = gb_byte_remainder % Self::GREEN_MULT; [r * Self::COLOR_FACTOR_8_BIT, g * Self::COLOR_FACTOR_8_BIT, b * Self::COLOR_FACTOR_8_BIT] } }