2 Copyright (C) 2003 Rice1964
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #define min(a,b) ((a) < (b) ? (a) : (b))
27 #define max(a,b) ((a) > (b) ? (a) : (b))
39 *((COLOR*)this) = rgba;
49 *((COLOR*)this) = (unsigned int) rgba;
52 inline IColor operator = (const IColor &sec) const
54 *((COLOR*)this) = *((COLOR*)&sec);
58 inline IColor operator = (COLOR col) const
60 *((COLOR*)this) = col;
64 inline IColor operator + (const IColor &sec) const
67 newc.r = (uint8)min((unsigned int) r + (unsigned int) sec.r, 0xFF);
68 newc.g = (uint8)min((unsigned int) g + (unsigned int) sec.g, 0xFF);
69 newc.b = (uint8)min((unsigned int) b + (unsigned int) sec.b, 0xFF);
70 newc.a = (uint8)min((unsigned int) a + (unsigned int) sec.a, 0xFF);
75 inline IColor operator - (const IColor &sec) const
78 newc.r = max(int(r)-int(sec.r),0);
79 newc.g = max(int(g)-int(sec.g),0);
80 newc.b = max(int(b)-int(sec.b),0);
81 newc.a = max(int(a)-int(sec.a),0);
85 inline IColor operator * (const IColor &sec) const
88 newc.r = (uint8)min((unsigned int) r * (unsigned int) sec.r / 256,255);
89 newc.g = (uint8)min((unsigned int) g * (unsigned int) sec.g / 256,255);
90 newc.b = (uint8)min((unsigned int) b * (unsigned int) sec.b / 256,255);
91 newc.a = (uint8)min((unsigned int) a * (unsigned int) sec.a / 256,255);
95 inline IColor& operator += (const IColor &sec)
97 r = uint8(min((unsigned int) r + (unsigned int) sec.r, 255));
98 g = uint8(min((unsigned int) g + (unsigned int) sec.g, 255));
99 b = uint8(min((unsigned int) b + (unsigned int) sec.b, 255));
100 a = uint8(min((unsigned int) a + (unsigned int) sec.a, 255));
104 inline IColor& operator -= (const IColor &sec)
106 r = uint8(max(int(r)-int(sec.r),0));
107 g = uint8(max(int(g)-int(sec.g),0));
108 b = uint8(max(int(b)-int(sec.b),0));
109 a = uint8(max(int(a)-int(sec.a),0));
113 inline IColor& operator *= (const IColor &sec)
115 r = uint8(min((unsigned int) r * (unsigned int) sec.r / 256,255));
116 g = uint8(min((unsigned int) g * (unsigned int) sec.g / 256,255));
117 b = uint8(min((unsigned int) b * (unsigned int) sec.b / 256,255));
118 a = uint8(min((unsigned int) a * (unsigned int) sec.a / 256,255));
122 inline IColor& operator += (XCOLOR val)
125 return this->operator += (newc);
128 inline IColor& operator -= (XCOLOR val)
131 return this->operator-=(newc);
134 inline IColor& operator *= (XCOLOR val)
137 return this->operator*=(newc);
140 inline IColor operator + (XCOLOR val) const
143 return this->operator+(newc);
146 inline IColor operator - (XCOLOR val) const
149 return this->operator-(newc);
152 inline IColor operator * (XCOLOR val) const
155 return this->operator*(newc);
158 inline operator COLOR() const
160 return *((COLOR*)this);
163 inline operator XCOLOR() const
166 rgba.r = (float)r/256.0f;
167 rgba.g = (float)g/256.0f;
168 rgba.b = (float)b/256.0f;
169 rgba.a = (float)a/256.0f;
174 inline void Complement()
182 inline void AlphaReplicate()