Rice GLES2 (from mupen64plus-ae) plugin. Compile but doesn't works well on the OpenPa...
[mupen64plus-pandora.git] / source / gles2rice / src / IColor.h
1 /*
2 Copyright (C) 2003 Rice1964
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef _ICOLOR_H_
21 #define _ICOLOR_H_
22
23 #ifndef min
24 #define min(a,b) ((a) < (b) ? (a) : (b))
25 #endif
26 #ifndef max
27 #define max(a,b) ((a) > (b) ? (a) : (b))
28 #endif
29
30 class IColor {
31 public:
32     uint8 r;
33     uint8 g;
34     uint8 b;
35     uint8 a;
36
37     IColor(COLOR rgba)
38     {
39         *((COLOR*)this) = rgba;
40     }
41
42     IColor()
43     {
44         *((COLOR*)this) = 0;
45     }
46
47     IColor(XCOLOR &rgba)
48     {
49         *((COLOR*)this) = (unsigned int) rgba;
50     }
51
52     inline IColor operator = (const IColor &sec) const
53     {
54         *((COLOR*)this) = *((COLOR*)&sec);
55         return *this;
56     }
57
58     inline IColor operator = (COLOR col) const
59     {
60         *((COLOR*)this) = col;
61         return *this;
62     }
63
64     inline IColor operator + (const IColor &sec) const
65     {
66         IColor newc;
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);
71
72         return newc;
73     }
74
75     inline IColor operator - (const IColor &sec) const
76     {
77         IColor newc;
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);
82
83         return newc;
84     }
85     inline IColor operator * (const IColor &sec) const
86     {
87         IColor newc;
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);
92         return newc;
93     }
94
95     inline IColor& operator += (const IColor &sec)
96     {
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));
101         return *this;
102     }
103
104     inline IColor& operator -= (const IColor &sec)
105     {
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));
110         return *this;
111     }
112
113     inline IColor& operator *= (const IColor &sec)
114     {
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));
119         return *this;
120     }
121     
122     inline IColor& operator += (XCOLOR val)
123     {
124         IColor newc(val);
125         return this->operator += (newc);
126     }
127
128     inline IColor& operator -= (XCOLOR val)
129     {
130         IColor newc(val);
131         return this->operator-=(newc);
132     }
133
134     inline IColor& operator *= (XCOLOR val)
135     {
136         IColor newc(val);
137         return this->operator*=(newc);
138     }
139
140     inline IColor operator + (XCOLOR val) const
141     {
142         IColor newc(val);
143         return this->operator+(newc);
144     }
145
146     inline IColor operator - (XCOLOR val) const
147     {
148         IColor newc(val);
149         return this->operator-(newc);
150     }
151
152     inline IColor operator * (XCOLOR val) const
153     {
154         IColor newc(val);
155         return this->operator*(newc);
156     }
157
158     inline operator COLOR() const
159     {
160         return *((COLOR*)this);
161     }
162
163     inline operator XCOLOR() const
164     {
165         XCOLOR rgba;
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;
170
171         return rgba;
172     }
173
174     inline void Complement()
175     {
176         r = 0xFF-r;
177         g = 0xFF-g;
178         b = 0xFF-b;
179         a = 0xFF-a;
180     }
181
182     inline void AlphaReplicate()
183     {
184         r=g=b=a;
185     }
186 };
187
188
189 #endif
190
191