Skip to content

Commit

Permalink
Add f32 to u8 color
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed Jun 8, 2024
1 parent 3211b1b commit f085bbd
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions inmath/color.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit f085bbd

Please sign in to comment.