Add Color struct
This commit is contained in:
parent
e6c943aab4
commit
8170593d56
43
src/fart/color.d
Normal file
43
src/fart/color.d
Normal file
@ -0,0 +1,43 @@
|
||||
module fart.color;
|
||||
|
||||
/**
|
||||
* Structure to represent a RGBA color value.
|
||||
*/
|
||||
struct Color
|
||||
{
|
||||
/** Red color component. */
|
||||
double r;
|
||||
|
||||
/** Green color component. */
|
||||
double g;
|
||||
|
||||
/** Blue color component. */
|
||||
double b;
|
||||
|
||||
/** Alpha color component. */
|
||||
double a;
|
||||
|
||||
/**
|
||||
* Convert color to a 32-bit integer RGBA value.
|
||||
*
|
||||
* Each color component uses one byte.
|
||||
*/
|
||||
public ubyte[] rgba32() const
|
||||
{
|
||||
return [toubyte(r), toubyte(g), toubyte(b), toubyte(a)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Scale a floating point color component value to an unsigned 8-bit byte
|
||||
* value.
|
||||
*
|
||||
* @param v
|
||||
* Floating point color component value.
|
||||
*
|
||||
* @return Unsigned 8-bit byte value for the color component.
|
||||
*/
|
||||
private static ubyte toubyte(double v)
|
||||
{
|
||||
return cast(ubyte)(0xFF * v);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user