00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef COLOR_3C_H_
00026 #define COLOR_3C_H_
00027
00028 #include <Core/System/Math.h>
00029
00030 namespace Lamp{
00031
00032 class Color4c;
00033 class Color3f;
00034 class Color4f;
00035
00036
00037
00038
00039
00040
00041
00042 class Color3c{
00043 public:
00044
00045
00046
00047
00048 union{
00049
00050 struct{
00051
00052 u_char r;
00053
00054 u_char g;
00055
00056 u_char b;
00057 };
00058
00059
00060 u_char array[3];
00061 };
00062
00063
00064
00065
00066
00067 static const Color3c white;
00068
00069
00070 static const Color3c gray;
00071
00072
00073 static const Color3c black;
00074
00075
00076 static const Color3c red;
00077
00078
00079 static const Color3c green;
00080
00081
00082 static const Color3c blue;
00083
00084
00085 static const Color3c yellow;
00086
00087
00088 static const Color3c cyan;
00089
00090
00091 static const Color3c magenta;
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 Color3c(){}
00102
00103
00104
00105
00106
00107
00108
00109 inline Color3c(u_char sourceR, u_char sourceG, u_char sourceB) :
00110 r(sourceR), g(sourceG), b(sourceB){
00111 }
00112
00113
00114
00115
00116
00117 explicit Color3c(const Color4c& source);
00118
00119
00120
00121
00122
00123 explicit Color3c(const Color3f& source);
00124
00125
00126
00127
00128
00129 explicit Color3c(const Color4f& source);
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 inline void set(u_char sourceR, u_char sourceG, u_char sourceB){
00141 r = sourceR;
00142 g = sourceG;
00143 b = sourceB;
00144 }
00145
00146
00147
00148
00149
00150 void set(const Color4c& source);
00151
00152
00153
00154
00155
00156 void set(const Color3f& source);
00157
00158
00159
00160
00161
00162 void set(const Color4f& source);
00163
00164
00165
00166
00167
00168 void setARGB(u_int source){
00169 r = (u_char)((source & 0xff0000) >> 16);
00170 g = (u_char)((source & 0xff00) >> 8);
00171 b = (u_char)(source & 0xff);
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181 u_int getARGB() const{
00182 return (0xff000000 | ((u_int)r << 16) | ((u_int)g << 8) | ((u_int)b));
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 inline Color3c operator +(const Color3c& addColor) const{
00194 int addR = (int)r + addColor.r;
00195 if(addR > 255){ addR = 255; }
00196 int addG = (int)g + addColor.g;
00197 if(addG > 255){ addG = 255; }
00198 int addB = (int)b + addColor.b;
00199 if(addB > 255){ addB = 255; }
00200 return Color3c(addR, addG, addB);
00201 }
00202
00203
00204
00205
00206
00207
00208 inline Color3c operator -(const Color3c& subColor) const{
00209 int subR = (int)r - subColor.r;
00210 if(subR < 0){ subR = 0; }
00211 int subG = (int)g - subColor.g;
00212 if(subG < 0){ subG = 0; }
00213 int subB = (int)b - subColor.b;
00214 if(subB < 0){ subB = 0; }
00215 return Color3c(subR, subG, subB);
00216 }
00217
00218
00219
00220
00221
00222
00223 inline Color3c operator *(const Color3c& mulColor) const{
00224 int mulR = ((int)r * mulColor.r) / 255;
00225 int mulG = ((int)g * mulColor.g) / 255;
00226 int mulB = ((int)b * mulColor.b) / 255;
00227 return Color3c(mulR, mulG, mulB);
00228 }
00229
00230
00231
00232
00233
00234
00235 inline Color3c operator *(float mulValue) const{
00236 int mulR = (int)(r * mulValue);
00237 if(mulR > 255){
00238 mulR = 255;
00239 }else if(mulR < 0){
00240 mulR = 0;
00241 }
00242 int mulG = (int)(g * mulValue);
00243 if(mulG > 255){
00244 mulG = 255;
00245 } else if(mulG < 0){
00246 mulG = 0;
00247 }
00248 int mulB = (int)(b * mulValue);
00249 if(mulB > 255){
00250 mulB = 255;
00251 }else if(mulB < 0){
00252 mulB = 0;
00253 }
00254 return Color3c(mulR, mulG, mulB);
00255 }
00256
00257
00258
00259
00260
00261
00262
00263 inline friend Color3c operator *(float mulValue, const Color3c& mulColor){
00264 int mulR = (int)(mulColor.r * mulValue);
00265 if(mulR > 255){
00266 mulR = 255;
00267 }else if(mulR < 0){
00268 mulR = 0;
00269 }
00270 int mulG = (int)(mulColor.g * mulValue);
00271 if(mulG > 255){
00272 mulG = 255;
00273 } else if(mulG < 0){
00274 mulG = 0;
00275 }
00276 int mulB = (int)(mulColor.b * mulValue);
00277 if(mulB > 255){
00278 mulB = 255;
00279 }else if(mulB < 0){
00280 mulB = 0;
00281 }
00282 return Color3c(mulR, mulG, mulB);
00283 }
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 inline Color3c& operator +=(const Color3c& addColor){
00294 int addR = (int)r + addColor.r;
00295 if(addR > 255){ addR = 255; }
00296 int addG = (int)g + addColor.g;
00297 if(addG > 255){ addG = 255; }
00298 int addB = (int)b + addColor.b;
00299 if(addB > 255){ addB = 255; }
00300 set(addR, addG, addB);
00301 return (*this);
00302 }
00303
00304
00305
00306
00307
00308
00309 inline Color3c& operator -=(const Color3c& subColor){
00310 int subR = (int)r - subColor.r;
00311 if(subR < 0){ subR = 0; }
00312 int subG = (int)g - subColor.g;
00313 if(subG < 0){ subG = 0; }
00314 int subB = (int)b - subColor.b;
00315 if(subB < 0){ subB = 0; }
00316 set(subR, subG, subB);
00317 return (*this);
00318 }
00319
00320
00321
00322
00323
00324
00325 inline Color3c& operator *=(const Color3c& mulColor){
00326 int mulR = ((int)r * mulColor.r) / 255;
00327 int mulG = ((int)g * mulColor.g) / 255;
00328 int mulB = ((int)b * mulColor.b) / 255;
00329 set(mulR, mulG, mulB);
00330 return (*this);
00331 }
00332
00333
00334
00335
00336
00337
00338 inline Color3c& operator *=(float mulValue){
00339 int mulR = (int)(r * mulValue);
00340 if(mulR > 255){
00341 mulR = 255;
00342 }else if(mulR < 0){
00343 mulR = 0;
00344 }
00345 int mulG = (int)(g * mulValue);
00346 if(mulG > 255){
00347 mulG = 255;
00348 } else if(mulG < 0){
00349 mulG = 0;
00350 }
00351 int mulB = (int)(b * mulValue);
00352 if(mulB > 255){
00353 mulB = 255;
00354 }else if(mulB < 0){
00355 mulB = 0;
00356 }
00357 set(mulR, mulG, mulB);
00358 return (*this);
00359 }
00360
00361
00362
00363
00364
00365
00366
00367
00368 inline Color3c& negative(){
00369 set(255 - r, 255 - g, 255 - b);
00370 return (*this);
00371 }
00372
00373
00374
00375
00376
00377
00378
00379
00380 inline static Color3c lerp(
00381 const Color3c& source, const Color3c& target, float alpha){
00382 float beta = 1.f - alpha;
00383 Color3c result;
00384 result.r = (u_char)(source.r * beta + target.r * alpha);
00385 result.g = (u_char)(source.g * beta + target.g * alpha);
00386 result.b = (u_char)(source.b * beta + target.b * alpha);
00387 return result;
00388 }
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398 inline bool operator ==(const Color3c& target) const{
00399 return ((r == target.r) && (g == target.g) && (b == target.b));
00400 }
00401
00402
00403
00404
00405
00406
00407 inline bool operator !=(const Color3c& target) const{
00408 return ((r != target.r) || (g != target.g) || (b != target.b));
00409 }
00410
00411
00412
00413
00414
00415
00416
00417
00418 inline String toString() const{
00419 String returnString;
00420 returnString.format("( %d, %d, %d )", r, g, b);
00421 return returnString;
00422 }
00423
00424
00425 private:
00426
00427 };
00428
00429
00430 }
00431 #endif // End of COLOR_3C_H_
00432