Skip to content

Commit a052db1

Browse files
add rgbau2rgba and rgbu2rgb
1 parent 9778108 commit a052db1

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

inmath/color.d

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ vec4 hex2rgba(const(char)[] input) {
137137
/**
138138
Parses a hex string to a RGBA color
139139
140-
Returns the color as 8 bit RGB(A)
140+
Returns the color as a static 8 bit RGB(A) array.
141141
*/
142142
ubyte[4] hex2rgbau(const(char)[] input) {
143143
import core.stdc.stdio : printf;
@@ -199,4 +199,27 @@ unittest {
199199
string col6 = "#FF";
200200
ubyte[4] col6u = [255, 0, 0, 0];
201201
assert(hex2rgbau(col6) == col6u);
202+
}
203+
204+
/**
205+
Returns RGBA color from 0..1 from colors in range 0..255
206+
*/
207+
vec4 rgbau2rgba(ubyte[4] colors) {
208+
return vec4(
209+
cast(float)colors[0]/255.0,
210+
cast(float)colors[1]/255.0,
211+
cast(float)colors[2]/255.0,
212+
cast(float)colors[3]/255.0,
213+
);
214+
}
215+
216+
/**
217+
Returns RGB color from 0..1 from colors in range 0..255
218+
*/
219+
vec3 rgbu2rgb(ubyte[3] colors) {
220+
return vec3(
221+
cast(float)colors[0]/255.0,
222+
cast(float)colors[1]/255.0,
223+
cast(float)colors[2]/255.0,
224+
);
202225
}

0 commit comments

Comments
 (0)