From f085bbd4b4ca730f71f838828c4c8c64378c2b60 Mon Sep 17 00:00:00 2001 From: LunaTheFoxgirl Date: Sat, 8 Jun 2024 22:35:07 +0200 Subject: [PATCH] Add f32 to u8 color --- inmath/color.d | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/inmath/color.d b/inmath/color.d index 4306e2f..1616cfb 100644 --- a/inmath/color.d +++ b/inmath/color.d @@ -222,4 +222,26 @@ vec3 rgbu2rgb(ubyte[3] colors) { cast(float)colors[1]/255.0, cast(float)colors[2]/255.0, ); +} + +/** + Returns RGBA color from 0..255 from colors in range 0..1 +*/ +ubyte[4] rgba2rgbau(vec4 colors) { + ubyte[4] color; + static foreach(i; 0..4) { + color[i] = cast(ubyte)(colors.vector[i]*255.0); + } + return color; +} + +/** + Returns RGB color from 0..255 from colors in range 0..1 +*/ +ubyte[3] rgb2rgbu(vec3 colors) { + ubyte[3] color; + static foreach(i; 0..3) { + color[i] = cast(ubyte)(colors.vector[i]*255.0); + } + return color; } \ No newline at end of file