inline DXColor::DXColor( unsigned argb )
{
	const float f = 1.0f / 255.0f;
    r = f * (float) (unsigned char) (argb >> 16);
    g = f * (float) (unsigned char) (argb >>  8);
    b = f * (float) (unsigned char) (argb >>  0);
    a = f * (float) (unsigned char) (argb >> 24);
}

inline DXColor::DXColor( const D3DCOLORVALUE& colval )
{
	r = colval.r;
	g = colval.g;
	b = colval.b;
	a = colval.a;
}

inline DXColor::DXColor( const float* pf)
{    
	r = pf[0];
    g = pf[1];
    b = pf[2];
    a = pf[3];
}

inline DXColor::DXColor( const float fr, const float fg, const float fb, const float fa )
{
	r = fr;
    g = fg;
    b = fb;
    a = fa;
}

// casting
inline DXColor::operator unsigned () const
{
	unsigned dwR = r >= 1.0f ? 0xff : r <= 0.0f ? 0x00 : (unsigned) (r * 255.0f + 0.5f);
    unsigned dwG = g >= 1.0f ? 0xff : g <= 0.0f ? 0x00 : (unsigned) (g * 255.0f + 0.5f);
    unsigned dwB = b >= 1.0f ? 0xff : b <= 0.0f ? 0x00 : (unsigned) (b * 255.0f + 0.5f);
    unsigned dwA = a >= 1.0f ? 0xff : a <= 0.0f ? 0x00 : (unsigned) (a * 255.0f + 0.5f);

    return (dwA << 24) | (dwR << 16) | (dwG << 8) | dwB;
}

inline DXColor::operator float* ()
{
	return (float *) &r;
}

inline DXColor::operator const float* () const
{
	 return (const float *) &r;
}

// assignment operators
inline DXColor& DXColor::operator += ( const DXColor& c )
{
	r += c.r;
    g += c.g;
    b += c.b;
    a += c.a;
    return *this;
}

inline DXColor& DXColor::operator -= ( const DXColor& c )
{
	r -= c.r;
    g -= c.g;
    b -= c.b;
    a -= c.a;
    return *this;
}

inline DXColor& DXColor::operator *= ( const float f )
{
	r *= f;
    g *= f;
    b *= f;
    a *= f;
    return *this;
}

inline DXColor& DXColor::operator /= ( const float f )
{
	FLOAT fInv = 1.0f / f;
    r *= fInv;
    g *= fInv;
    b *= fInv;
    a *= fInv;
    return *this;
}

// unary operators
inline DXColor DXColor::operator + () const
{
	return *this;
}

inline DXColor DXColor::operator - () const
{
	return DXColor(-r, -g, -b, -a);
}

// binary operators
inline DXColor DXColor::operator + ( const DXColor& c) const
{
	return DXColor(r + c.r, g + c.g, b + c.b, a + c.a);
}

inline DXColor DXColor::operator - ( const DXColor& c) const
{
	return DXColor(r - c.r, g - c.g, b - c.b, a - c.a);
}

inline DXColor DXColor::operator * ( const float f ) const
{
	return DXColor(r * f, g * f, b * f, a * f);
}

inline DXColor DXColor::operator / ( const float f ) const
{
	float fInv = 1.0f / f;
    return DXColor(r * fInv, g * fInv, b * fInv, a * fInv);
}

inline DXColor operator * ( const float f, const DXColor& c )
{
	return DXColor(f * c.r, f * c.g, f * c.b, f * c.a);
}

inline bool DXColor::operator == ( const DXColor& c ) const
{
	return r == c.r && g == c.g && b == c.b && a == c.a;
}

inline bool DXColor::operator != ( const DXColor& c ) const
{
	return r != c.r || g != c.g || b != c.b || a != c.a;
}