From 7b0375eee4a945cc8fbb3c03cfc0657e0f1ee443 Mon Sep 17 00:00:00 2001 From: Rosyid Haryadi Date: Wed, 26 Feb 2025 14:44:11 +0700 Subject: upd: mapping 0-1 to byte --- src/global.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/global.rs') diff --git a/src/global.rs b/src/global.rs index cb616b1..3a1e329 100644 --- a/src/global.rs +++ b/src/global.rs @@ -8,6 +8,16 @@ pub struct Pixel { pub b: u8, } +impl Pixel { + pub fn from_frac(r: f32, g: f32, b: f32) -> Self { + Self { + r: (255.999 * r) as u8, + g: (255.999 * g) as u8, + b: (255.999 * b) as u8, + } + } +} + impl Default for Pixel { fn default() -> Self { Pixel { r:0, g:0, b:0 } -- cgit v1.2.3-70-g09d2