00001 #include "stdafx.h" 00002 #include "color.h" 00003 00004 Color::Color(rgb col) 00005 { 00006 r = (float)col.r; 00007 g = (float)col.g; 00008 b = (float)col.b; 00009 } 00010 00011 Color::Color(float rf, float gf, float bf) 00012 { 00013 if(rf > 255.0) rf = 255.0; 00014 if(gf > 255.0) gf = 255.0; 00015 if(bf > 255.0) bf = 255.0; 00016 if(rf < 0.0) rf = 0.0; 00017 if(gf < 0.0) gf = 0.0; 00018 if(bf < 0.0) bf = 0.0; 00019 r = rf; 00020 b = bf; 00021 g = gf; 00022 } 00024 const Color Color::operator + (const Color& col) const 00025 { 00026 return Color(r + col.r, g + col.g, b + col.b); 00027 } 00028 00029 const Color Color::operator += (const Color& col) 00030 { 00031 r += col.r; 00032 g += col.g; 00033 b += col.b; 00034 return *this; 00035 } 00037 const Color Color::operator * (const float& alpha) const 00038 { 00039 return Color(r * alpha, g * alpha, b * alpha); 00040 } 00041 00043 const Color Color::operator / (const float& scalar) const 00044 { 00045 return Color(r / scalar, g / scalar, b / scalar); 00046 } 00047 00048 const Color Color::operator = (const Color& col) 00049 { 00050 r = col.r; 00051 g = col.g; 00052 b = col.b; 00053 return *this; 00054 } 00055 00056 rgb 00057 Color::toRGB() 00058 { 00059 rgb col; 00060 col.b = (unsigned char) b; 00061 col.g = (unsigned char) g; 00062 col.r = (unsigned char) r; 00063 return col; 00064 }