00001
00002
00003
00004
00005
00006 #ifndef COLOR4_H
00007 #define COLOR4_H
00008
00009 #include<Color3.h>
00010
00011 #include<stream.h>
00012
00013 class ObjectFile;
00014
00017 class Color4 : public Color3
00018 {
00019 friend ostream &operator<<(ostream &stream, Color4 &c);
00020 friend ObjectFile &operator>>(ObjectFile &f, Color4 &c);
00021 public:
00022
00023 Color4() {};
00024 Color4(float rr, float gg, float bb)
00025 : Color3(rr, gg, bb), a(1.0) {}
00026 Color4(float rr, float gg, float bb, float aa);
00027 Color4(const Color3 &c, float aa);
00028 Color4(const Color4 &c) : Color3(c), a(c.a) {}
00029
00030
00031 float &operator [](unsigned int i) {
00032 return ((float*)(this))[i];
00033 }
00034
00035
00036 Color4 &clamp() {
00037 r = ::clamp(r);
00038 g = ::clamp(g);
00039 b = ::clamp(b);
00040 a = ::clamp(a);
00041 return *this;
00042 }
00043 Color4 &lerp(Color4 &from, Color4 &to, float t);
00044
00045
00046 Color4 &operator =(const Color3 &c);
00047 Color4 &operator =(const Color4 &c) {
00048 r = c.r;
00049 g = c.g;
00050 b = c.b;
00051 a = c.a;
00052 return *this;
00053 }
00054 void operator -=(const Color4 &c) {
00055 r -= c.r;
00056 g -= c.g;
00057 b -= c.b;
00058 a -= c.a;
00059 ::clamp(a);
00060 }
00061 void operator += (const Color4 &c) {
00062 r += c.r;
00063 g += c.g;
00064 b += c.b;
00065 a += c.a;
00066 a = ::clamp(a);
00067 }
00068 void operator *=(float s) {
00069 r *= s;
00070 g *= s;
00071 b *= s;
00072 }
00073 void operator *=(const Color4 &c) {
00074 r *= c.r;
00075 g *= c.g;
00076 b *= c.b;
00077 a *= c.a;
00078 }
00079 void operator /=(float s) {
00080 r /= s;
00081 g /= s;
00082 b /= s;
00083 }
00084
00085
00086 Color4 operator -(const Color4 &c) const {
00087 Color4 cc(r - c.r, g - c.g, b - c.b, ::clamp(a - c.a) );
00088 return cc;
00089 }
00090 Color4 operator +(const Color4 &c) const {
00091 Color4 cc(r + c.r, g + c.g, b + c.b, ::clamp(a + c.a));
00092 return cc;
00093 }
00094 Color4 operator *(float s) const {
00095 Color4 cc(r * s, g * s, b * s, a);
00096 return cc;
00097 }
00098 Color4 operator *(const Color4 &c) const {
00099 Color4 cc(r * c.r, g * c.g, b * c.b, a * c.a);
00100 return cc;
00101 }
00102 Color4 operator /(float s) const {
00103 Color4 cc(r / s, g / s, b / s, a);
00104 return cc;
00105 }
00106 float gray() const;
00107
00108
00109 Color4 blend(float d, float s, const Color4 &src);
00110 Color4 over(const Color4 &c) {
00111 return blend(1.0, 1.0-a, c);
00112 }
00113 Color4 in(const Color4 &c) {
00114 return blend(c.a, 0.0, c);
00115 }
00116 Color4 heldout(const Color4 &c) {
00117 return blend(1.0-c.a, 0.0, c);
00118 }
00119 Color4 atop(const Color4 &c) {
00120 return blend(c.a, 1.0-a, c);
00121 }
00122 Color4 xor(const Color4 &c) {
00123 return blend(1.0-c.a, 1.0-a, c);
00124 }
00125
00126 float a;
00127 };
00128 #endif