00001 #include "RGBAColor.h" 00002 00003 namespace rcrt 00004 { 00005 00006 RGBAColor::RGBAColor() 00007 { 00008 values[0] = values[1] = values[2] = 0; 00009 values[3] = 1; 00010 } 00011 00012 RGBAColor::RGBAColor(float c, float a) 00013 { 00014 values[0] = values[1] = values[2] = c; 00015 values[3] = a; 00016 } 00017 00018 RGBAColor::RGBAColor(float r, float g, float b, float a) 00019 { 00020 values[0] = r; 00021 values[1] = g; 00022 values[2] = b; 00023 values[3] = a; 00024 } 00025 00026 RGBAColor::RGBAColor(const RGBAColor& col) 00027 { 00028 assign(col); 00029 } 00030 00031 RGBAColor::RGBAColor(const RGBColor& col) 00032 { 00033 values[0] = col.r(); 00034 values[1] = col.g(); 00035 values[2] = col.b(); 00036 values[3] = 1; 00037 } 00038 00039 RGBAColor::~RGBAColor() 00040 { 00041 } 00042 00043 void RGBAColor::assign(const RGBAColor& col) 00044 { 00045 if(&col != this){ 00046 values[0] = col.values[0]; 00047 values[1] = col.values[1]; 00048 values[2] = col.values[2]; 00049 values[3] = col.values[3]; 00050 } 00051 } 00052 00053 const RGBAColor& RGBAColor::operator= (const RGBAColor& col) 00054 { 00055 assign(col); 00056 00057 return *this; 00058 } 00059 00060 RGBAColor RGBAColor::operator+ (const RGBAColor& col) const 00061 { 00062 return RGBAColor(values[0]+col.values[0], 00063 values[1]+col.values[1], 00064 values[2]+col.values[2], 00065 values[3]+col.values[3]); 00066 } 00067 00068 RGBAColor RGBAColor::operator- (const RGBAColor& col) const 00069 { 00070 return RGBAColor(values[0]-col.values[0], 00071 values[1]-col.values[1], 00072 values[2]-col.values[2], 00073 values[3]-col.values[3]); 00074 } 00075 00076 RGBAColor RGBAColor::operator* (float f) const 00077 { 00078 return RGBAColor(values[0]*f,values[1]*f,values[2]*f,values[3]*f); 00079 } 00080 00081 RGBAColor RGBAColor::operator/ (float f) const 00082 { 00083 float g = 1/f; 00084 return RGBAColor(values[0]*g,values[1]*g,values[2]*g,values[3]*g); 00085 } 00086 00087 RGBAColor RGBAColor::blendAssoc(const RGBAColor& col) 00088 { 00089 float apart = (1-values[3])*col.values[3]; 00090 float ao = values[3]+apart; 00091 float aorec = 1/ao; 00092 return RGBAColor((values[3]*values[0]+apart*col.values[0])*aorec, 00093 (values[3]*values[1]+apart*col.values[1])*aorec, 00094 (values[3]*values[2]+apart*col.values[2])*aorec, 00095 ao); 00096 } 00097 00098 RGBAColor RGBAColor::blendOver(const RGBAColor& col) 00099 { 00100 float apart = (1-values[3])*col.values[3]; 00101 float ao = values[3]+apart; 00102 return RGBAColor(values[3]*values[0]+apart*col.values[0], 00103 values[3]*values[1]+apart*col.values[1], 00104 values[3]*values[2]+apart*col.values[2], 00105 ao); 00106 } 00107 00108 float RGBAColor::r() const 00109 { 00110 return values[0]; 00111 } 00112 00113 float RGBAColor::g() const 00114 { 00115 return values[1]; 00116 } 00117 00118 float RGBAColor::b() const 00119 { 00120 return values[2]; 00121 } 00122 00123 float RGBAColor::a() const 00124 { 00125 return values[3]; 00126 } 00127 00128 float RGBAColor::getLuminance() const 00129 { 00130 return (r()+g()+b())/3; 00131 } 00132 00133 RGBColor RGBAColor::getRGB() const 00134 { 00135 return RGBColor(values[0],values[1],values[2]); 00136 } 00137 00138 }