import std.algorithm.mutation;
string intToHex(int i, int format = 0){
case 1: result ~='1'; break;
case 2: result ~='2'; break;
case 3: result ~='3'; break;
case 4: result ~='4'; break;
case 5: result ~='5'; break;
case 6: result ~='6'; break;
case 7: result ~='7'; break;
case 8: result ~='8'; break;
case 9: result ~='9'; break;
case 10: result ~='A'; break;
case 11: result ~='B'; break;
case 12: result ~='C'; break;
case 13: result ~='D'; break;
case 14: result ~='E'; break;
case 15: result ~='F'; break;
default: result ~='0'; break;
if(result.length < format){
for(size_t j = result.length ; j < format ; j++){
reverse(cast(char[])result);
public @nogc @property ubyte alpha(){ return colors[0]; }
public @nogc @property ubyte red(){ return colors[1]; }
public @nogc @property ubyte green(){ return colors[2]; }
public @nogc @property ubyte blue(){ return colors[3]; }
public @nogc @property ubyte alpha(ubyte value){ return colors[0] = value; }
public @nogc @property ubyte red(ubyte value){ return colors[1] = value; }
public @nogc @property ubyte green(ubyte value){ return colors[2] = value; }
public @nogc @property ubyte blue(ubyte value){ return colors[3] = value; }
public @nogc @property ubyte alpha(){ return colors[3]; }
public @nogc @property ubyte red(){ return colors[2]; }
public @nogc @property ubyte green(){ return colors[1]; }
public @nogc @property ubyte blue(){ return colors[0]; }
public @nogc @property ubyte alpha(ubyte value){ return colors[3] = value; }
public @nogc @property ubyte red(ubyte value){ return colors[2] = value; }
public @nogc @property ubyte green(ubyte value){ return colors[1] = value; }
public @nogc @property ubyte blue(ubyte value){ return colors[0] = value; }
public @nogc this(ubyte alpha, ubyte red, ubyte green, ubyte blue){
public @nogc this(uint val){
public Color opBinary(string op)(Color rhs){
int r = red + rhs.red, g = green + rhs.green, b = blue + rhs.blue, a = alpha + rhs.alpha;
return Color(a > 255 ? 255 : cast(ubyte)a, r > 255 ? 255 : cast(ubyte)r, g > 255 ? 255 : cast(ubyte)g, b > 255 ? 255 : cast(ubyte)b);
}else static if(op == "-"){
int r = red - rhs.red, g = green - rhs.green, b = blue - rhs.blue, a = alpha - rhs.alpha;
return Color(a < 0 ? 0 : cast(ubyte)a, r < 0 ? 0 : cast(ubyte)r, g < 0 ? 0 : cast(ubyte)g, b < 0 ? 0 : cast(ubyte)b);
}else static if(op == "^"){
return Color(alpha ^ rhs.alpha, red ^ rhs.red, green ^ rhs.green, blue ^ rhs.blue);
}else static if(op == "&"){
return rhs.alpha ? rhs : this;
}else static if(op == "*"){
return Color(alpha, cast(ubyte)( ( (rhs.red * (1 + rhs.alpha)) + (red * (256 - rhs.alpha)) )>>8 ),
cast(ubyte)( ( (rhs.green * (1 + rhs.alpha)) + (green * (256 - rhs.alpha)) )>>8 ),
cast(ubyte)( ( (rhs.blue * (1 + rhs.alpha)) + (blue * (256 - rhs.alpha)) )>>8 ));
}else static assert(0, "Operator '" ~ op ~ "' not supported!");
public string toString() const
return "0x" ~ intToHex(raw, 8);
static immutable immutable(Color)[] clrs;
clrs = [Color(0, 255, 0, 0),
enum ct_clrs = [Color(0, 255, 0, 0),
writefln("0x%08X", clrs[1].raw);
Color[] clrs2 = clrs.dup;
assert(clrs2[1].green == 255);