CUGL
Cornell University Game Library
CUColor4.h
1 //
2 // CUColor4.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides support for a standard colors. It provides both a
6 // float based color solution and a byte-based color solution. The former
7 // is better for blending and calculations. The later is better for storage.
8 //
9 // Because math objects are intended to be on the stack, we do not provide
10 // any shared pointer support in this class.
11 //
12 // This module is based on an original file from GamePlay3D: http://gameplay3d.org.
13 // It has been modified to support the CUGL framework.
14 //
15 // CUGL zlib License:
16 // This software is provided 'as-is', without any express or implied
17 // warranty. In no event will the authors be held liable for any damages
18 // arising from the use of this software.
19 //
20 // Permission is granted to anyone to use this software for any purpose,
21 // including commercial applications, and to alter it and redistribute it
22 // freely, subject to the following restrictions:
23 //
24 // 1. The origin of this software must not be misrepresented; you must not
25 // claim that you wrote the original software. If you use this software
26 // in a product, an acknowledgment in the product documentation would be
27 // appreciated but is not required.
28 //
29 // 2. Altered source versions must be plainly marked as such, and must not
30 // be misrepresented as being the original software.
31 //
32 // 3. This notice may not be removed or altered from any source distribution.
33 //
34 // Author: Walker White
35 // Version: 5/30/16
36 #ifndef __CU_COLOR4_H__
37 #define __CU_COLOR4_H__
38 
39 #include <math.h>
40 #include <functional>
41 #include "CUMathBase.h"
42 #include "../base/CUEndian.h"
43 
45 #define COLOR_BYTE_TO_FLOAT(x) ( static_cast<float>(x)/255.0f )
46 
47 #define COLOR_FLOAT_TO_BYTE(x) ( static_cast<int>(roundf(x*255.0f)) )
48 
49 namespace cugl {
50 
51 // Forward references to the classes we convert to
52 class Color4;
53 class Vec3;
54 class Vec4;
55 
56 #pragma mark -
57 #pragma mark Color with Float Attributes
58 
73 class Color4f {
74 
75 #pragma mark Values
76 public:
78  GLfloat r;
80  GLfloat g;
82  GLfloat b;
84  GLfloat a;
85 
87  static const Color4f CLEAR;
89  static const Color4f WHITE;
91  static const Color4f BLACK;
93  static const Color4f YELLOW;
95  static const Color4f BLUE;
97  static const Color4f GREEN;
99  static const Color4f RED;
101  static const Color4f MAGENTA;
103  static const Color4f CYAN;
105  static const Color4f ORANGE;
107  static const Color4f GRAY;
109  static const Color4f CORNFLOWER;
111  static const Color4f PAPYRUS;
112 
113 #pragma mark Constructors
114 public:
118  Color4f() : r(0), g(0), b(0), a(0) {}
119 
130  Color4f(float r, float g, float b, float a = 1);
131 
140  Color4f(GLuint color);
141 
147  Color4f(const Color4f& copy) {
148  r = copy.r; g = copy.g; b = copy.b; a = copy.a;
149  }
150 
158  Color4f(const float* array);
159 
163  ~Color4f() {}
164 
165 
166 #pragma mark Setters
167 
174  Color4f& operator=(const Color4f& c) {
175  return set(c);
176  }
177 
188  Color4f& operator=(unsigned int color) {
189  return set(color);
190  }
191 
201  Color4f& operator=(const float* array) {
202  return set(array);
203  }
204 
217  Color4f& set(float r, float g, float b, float a = 1);
218 
228  Color4f& set(const float* array);
229 
240  Color4f& set(GLuint color);
241 
249  Color4f& set(const Color4f& c) {
250  r = c.r; g = c.g; b = c.b; a = c.a;
251  return *this;
252  }
253 
254 
255 #pragma mark Arithmetic
256 
264  Color4f& clamp(const Color4f& min, const Color4f& max);
265 
276  Color4f getClamp(const Color4f& min, const Color4f& max) const {
277  return Color4f(clampf(r,min.r,max.r), clampf(g,min.g,max.g),
278  clampf(b,min.b,max.b), clampf(a,min.a,max.a));
279  }
280 
292  Color4f& add(const Color4f& c, bool alpha = false) {
293  r = clampf(r+c.r,0.0,1.0);
294  g = clampf(g+c.g,0.0,1.0);
295  b = clampf(b+c.b,0.0,1.0);
296  a = (alpha ? clampf(a+c.a,0.0,1.0) : a);
297  return *this;
298  }
299 
312  Color4f& add(float r, float g, float b, float a = 0) {
313  this->r = clampf(this->r+r,0.0,1.0);
314  this->g = clampf(this->g+g,0.0,1.0);
315  this->b = clampf(this->b+b,0.0,1.0);
316  this->a = clampf(this->a+a,0.0,1.0);
317  return *this;
318  }
319 
331  Color4f& subtract(const Color4f& c, bool alpha = false) {
332  r = clampf(r-c.r,0.0,1.0);
333  g = clampf(g-c.g,0.0,1.0);
334  b = clampf(b-c.b,0.0,1.0);
335  a = (alpha ? clampf(a-c.a,0.0,1.0) : a);
336  return *this;
337  }
338 
351  Color4f& subtract(float r, float g, float b, float a = 0) {
352  this->r = clampf(this->r-r,0.0,1.0);
353  this->g = clampf(this->g-g,0.0,1.0);
354  this->b = clampf(this->b-b,0.0,1.0);
355  this->a = clampf(this->a-a,0.0,1.0);
356  return *this;
357  }
358 
369  Color4f& scale(float s, bool alpha = false) {
370  r = clampf(r*s,0.0,1.0);
371  g = clampf(g*s,0.0,1.0);
372  b = clampf(b*s,0.0,1.0);
373  a = (alpha ? clampf(a*s,0.0,1.0) : a);
374  return *this;
375  }
376 
389  Color4f& scale(float sr, float sg, float sb, float sa = 1) {
390  r = clampf(r*sr,0.0,1.0);
391  g = clampf(g*sg,0.0,1.0);
392  b = clampf(b*sb,0.0,1.0);
393  a = clampf(a*sa,0.0,1.0);
394  return *this;
395  }
396 
407  Color4f& scale(const Color4f& c, bool alpha = false) {
408  r *= c.r; g *= c.g; b *= c.b;
409  a = (alpha ? a*c.a : a);
410  return *this;
411  }
412 
425  Color4f& map(std::function<float(float)> func, bool alpha = false) {
426  r = clampf(func(r),0,1); g = clampf(func(g),0,1); b = clampf(func(b),0,1);
427  a = (alpha ? clampf(func(a),0,1) : a);
428  return *this;
429  }
430 
442  Color4f getMap(std::function<float(float)> func, bool alpha = false) const {
443  return Color4f(clampf(func(r),0,1), clampf(func(g),0,1),
444  clampf(func(b),0,1), (alpha ? clampf(func(a),0,1) : a));
445  }
446 
447 
448 #pragma mark Color Operations
449 
458  Color4f& complement(bool alpha = false) {
459  r = 1-r; g = 1-g; b = 1-b; a = (alpha ? 1-a : a);
460  return *this;
461  }
462 
474  Color4f getComplement(bool alpha = false) const {
475  return Color4f(1-r, 1-g, 1-b, (alpha ? 1-a : a));
476  }
477 
493  Color4f& lerp(const Color4f& other, float alpha) {
494  float x = clampf(alpha,0,1);
495  *this *= (1.f - x);
496  return *this += other * x;
497  }
498 
509  Color4f& blend(const Color4f& other) {
510  float a1 = a*(1-other.a);
511  float a2 = other.a+a1;
512  r = (other.r*other.a+r*a1)/a2;
513  g = (other.g*other.a+g*a1)/a2;
514  b = (other.b*other.a+b*a1)/a2;
515  a = a2;
516  return *this;
517  }
518 
529  Color4f& blendPre(const Color4f& other) {
530  a = other.a+a*(1-other.a);
531  r = other.r+r*(1-other.a);
532  g = other.g+g*(1-other.a);
533  b = other.b+b*(1-other.a);
534  return *this;
535  }
536 
547  r *= a; g *= a; b *= a;
548  return *this;
549  }
550 
563  if (a > 0) {
564  r /= a; g /= a; b /= a;
565  }
566  return *this;
567  }
568 
586  Color4f getLerp(const Color4f& other, float alpha) const {
587  float x = clampf(alpha,0,1);
588  return *this * (1.f - x) + other * x;
589  }
590 
603  Color4f getBlend(const Color4f& other) const {
604  float a1 = a*(1-other.a);
605  float a2 = other.a+a1;
606  return Color4f((other.r*other.a+r*a1)/a2,
607  (other.g*other.a+g*a1)/a2,
608  (other.b*other.a+b*a1)/a2,
609  a2);
610  }
611 
624  Color4f getBlendPre(const Color4f& other) const {
625  float oa = other.a+a*(1-other.a);
626  return Color4f((other.r+r*(1-other.a)), (other.g+g*(1-other.a)),
627  (other.b+b*(1-other.a)), oa);
628  }
629 
642  return Color4f(r*a,g*a,b*a,a);
643  }
644 
659  if (a > 0) {
660  return Color4f(r/a,g/a,b/a,a);
661  }
662  return *this;
663  }
664 
682  static Color4f* lerp(const Color4f& c1, const Color4f& c2, float alpha, Color4f* dst);
683 
697  static Color4f* blend(const Color4f& c1, const Color4f& c2, Color4f* dst);
698 
712  static Color4f* blendPre(const Color4f& c1, const Color4f& c2, Color4f* dst);
713 
725  GLuint getRGBA() const;
726 
727 #pragma mark Operators
728 
741  r = clampf(r+c.r,0.0,1.0);
742  g = clampf(g+c.g,0.0,1.0);
743  b = clampf(b+c.b,0.0,1.0);
744  a = clampf(a+c.a,0.0,1.0);
745  return *this;
746  }
747 
761  r = clampf(r-c.r,0.0,1.0);
762  g = clampf(g-c.g,0.0,1.0);
763  b = clampf(b-c.b,0.0,1.0);
764  a = clampf(a-c.a,0.0,1.0);
765  return *this;
766  }
767 
779  Color4f& operator*=(float s) {
780  r = clampf(r*s,0.0,1.0);
781  g = clampf(g*s,0.0,1.0);
782  b = clampf(b*s,0.0,1.0);
783  a = clampf(a*s,0.0,1.0);
784  return *this;
785  }
786 
797  r *= c.r; g *= c.g; b *= c.b; a *= c.a;
798  return *this;
799  }
800 
815  const Color4f operator+(const Color4f& c) const {
816  Color4f result(*this);
817  return result += c;
818  }
819 
834  const Color4f operator-(const Color4f& c) const {
835  Color4f result(*this);
836  return result -= c;
837  }
838 
850  const Color4f operator*(float s) const {
851  Color4f result(*this);
852  return result *= s;
853  }
854 
866  const Color4f operator*(const Color4f& c) const {
867  Color4f result(*this);
868  return result *= c;
869  }
870 
871 
872 #pragma mark Comparisons
873 
884  bool operator<(const Color4f& c) const;
885 
897  bool operator<=(const Color4f& c) const {
898  return *this < c || *this == c;
899  }
900 
912  bool operator>(const Color4f& c) const;
913 
925  bool operator>=(const Color4f& c) const {
926  return *this > c || *this == c;
927  }
928 
939  bool operator==(const Color4f& c) const {
940  return r == c.r && g == c.g && b == c.b && a == c.a;
941  }
942 
953  bool operator!=(const Color4f& c) const {
954  return r != c.r || g != c.g || b != c.b || a != c.a;
955  }
956 
968  bool darkerThan(const Color4f& c) const {
969  return r <= c.r && g <= c.g && b <= c.b && c.a <= a;
970  }
971 
984  bool lighterThan(const Color4f& c) const {
985  return r >= c.r && g >= c.g && b >= c.b && c.a >= a;
986  }
987 
998  bool equals(const Color4f& color, float variance=CU_MATH_EPSILON) const {
999  return (fabsf(r-color.r) < variance && fabsf(g-color.g) < variance &&
1000  fabsf(b-color.b) < variance && fabsf(a-color.a) < variance);
1001  }
1002 
1003 
1004 #pragma mark Conversion Methods
1005 public:
1016  std::string toString(bool verbose = false) const;
1017 
1019  operator std::string() const { return toString(); }
1020 
1022  operator Vec4() const;
1023 
1031  explicit Color4f(const Vec4& vector);
1032 
1042  Color4f& operator= (const Vec4& vector);
1043 
1045  operator Vec3() const;
1046 
1054  explicit Color4f(const Vec3& vector);
1055 
1065  Color4f& operator= (const Vec3& vector);
1066 
1068  operator Color4() const;
1069 
1078  explicit Color4f(Color4 color);
1079 
1090  Color4f& operator= (Color4 color);
1091 };
1092 
1093 
1094 #pragma mark -
1095 #pragma mark Color with Byte Attributes
1096 
1104 class Color4 {
1105 
1106 #pragma mark Values
1107 public:
1108 union {
1109  struct {
1111  GLubyte r;
1113  GLubyte g;
1115  GLubyte b;
1117  GLubyte a;
1118  };
1120  Uint32 rgba;
1121 };
1122 
1124  static const Color4 CLEAR;
1126  static const Color4 WHITE;
1128  static const Color4 BLACK;
1130  static const Color4 YELLOW;
1132  static const Color4 BLUE;
1134  static const Color4 GREEN;
1136  static const Color4 RED;
1138  static const Color4 MAGENTA;
1140  static const Color4 CYAN;
1142  static const Color4 ORANGE;
1144  static const Color4 GRAY;
1146  static const Color4 CORNFLOWER;
1148  static const Color4 PAPYRUS;
1149 
1150 
1151 #pragma mark Constructors
1152 public:
1156  Color4() : rgba(0) {}
1157 
1166  Color4(GLubyte r, GLubyte g, GLubyte b, GLubyte a = 255) {
1167  this->r = r; this->g = g; this->b = b; this->a = a;
1168  }
1169 
1179  Color4(GLuint color) { set(color); }
1180 
1189  Color4(const float* array);
1190 
1194  ~Color4() {}
1195 
1196 
1197 #pragma mark Setters
1198 
1209  Color4& operator=(GLuint color) {
1210  return set(color);
1211  }
1212 
1223  Color4& operator=(const float* array) {
1224  return set(array);
1225  }
1226 
1237  Color4& set(GLubyte r, GLubyte g, GLubyte b, GLubyte a = 255) {
1238  this->r = r; this->g = g; this->b = b; this->a = a;
1239  return *this;
1240  }
1241 
1252  Color4& set(const float* array);
1253 
1264  Color4& set(GLuint color) {
1265  rgba = marshall(color);
1266  return *this;
1267  }
1268 
1276  Color4& set(const Color4& c) {
1277  rgba = c.rgba;
1278  return *this;
1279  }
1280 
1281 
1282 #pragma mark Arithmetic
1283 
1291  Color4& clamp(Color4 min, Color4 max);
1292 
1303  Color4 getClamp(Color4 min, Color4 max) const {
1304  return Color4(clampb(r,min.r,max.r), clampb(g,min.g,max.g),
1305  clampb(b,min.b,max.b), clampb(a,min.a,max.a));
1306  }
1307 
1308 
1320  Color4& add(Color4 c, bool alpha = false) {
1321  r = clampb(r+c.r,0,255);
1322  g = clampb(g+c.g,0,255);
1323  b = clampb(b+c.b,0,255);
1324  a = (alpha ? clampb(a+c.a,0,255) : a);
1325  return *this;
1326  }
1327 
1340  Color4& add(GLubyte r, GLubyte g, GLubyte b, GLubyte a = 0) {
1341  this->r = clampb(this->r+r,0,255);
1342  this->g = clampb(this->g+g,0,255);
1343  this->b = clampb(this->b+b,0,255);
1344  this->a = clampb(this->a+a,0,255);
1345  return *this;
1346  }
1347 
1359  Color4& subtract(Color4 c, bool alpha = false) {
1360  r = clampb(r-c.r,0,255);
1361  g = clampb(g-c.g,0,255);
1362  b = clampb(b-c.b,0,255);
1363  a = (alpha ? clampb(a-c.a,0,255) : a);
1364  return *this;
1365  }
1366 
1379  Color4& subtract(GLubyte r, GLubyte g, GLubyte b, GLubyte a = 0) {
1380  this->r = clampb(this->r-r,0,255);
1381  this->g = clampb(this->g-g,0,255);
1382  this->b = clampb(this->b-b,0,255);
1383  this->a = clampb(this->a-a,0,255);
1384  return *this;
1385  }
1386 
1397  Color4& scale(float s, bool alpha = false) {
1398  r = clampb(static_cast<GLubyte>(r*s),0,255);
1399  g = clampb(static_cast<GLubyte>(g*s),0,255);
1400  b = clampb(static_cast<GLubyte>(b*s),0,255);
1401  a = (alpha ? clampb(static_cast<GLubyte>(a*s),0,255) : a);
1402  return *this;
1403  }
1404 
1417  Color4& scale(float sr, float sg, float sb, float sa = 1) {
1418  r = clampb(static_cast<GLuint>(r*sr),0,255);
1419  g = clampb(static_cast<GLuint>(g*sg),0,255);
1420  b = clampb(static_cast<GLuint>(b*sb),0,255);
1421  a = clampb(static_cast<GLuint>(a*sa),0,255);
1422  return *this;
1423  }
1424 
1435  Color4& scale(Color4 c, bool alpha = false) {
1436  r = clampb(static_cast<GLuint>(COLOR_BYTE_TO_FLOAT(c.r)*r),0,255);
1437  g = clampb(static_cast<GLuint>(COLOR_BYTE_TO_FLOAT(c.g)*g),0,255);
1438  b = clampb(static_cast<GLuint>(COLOR_BYTE_TO_FLOAT(c.b)*b),0,255);
1439  a = (alpha ? clampb(static_cast<GLuint>(COLOR_BYTE_TO_FLOAT(c.a)*a),0,255) : a);
1440  return *this;
1441  }
1442 
1455  Color4& map(std::function<GLubyte(GLubyte)> func, bool alpha = false) {
1456  r = func(r); g = func(g); b = func(b);
1457  a = (alpha ? func(a) : a);
1458  return *this;
1459  }
1460 
1473  Color4 getMap(std::function<GLubyte(GLubyte)> func, bool alpha = false) const {
1474  return Color4(func(r),func(g),func(b),(alpha ? func(a) : a));
1475  }
1476 
1477 
1478 #pragma mark Color4 Operations
1479 
1488  Color4& complement(bool alpha = false) {
1489  r = 255-r; g = 255-g; b = 255-b; a = (alpha ? 255-a : a);
1490  return *this;
1491  }
1492 
1504  Color4 getComplement(bool alpha = false) const {
1505  return Color4(255-r, 255-g, 255-b, (alpha ? 255-a : a));
1506  }
1507 
1523  Color4& lerp(const Color4f& other, float alpha) {
1524  float x = clampf(alpha,0,1);
1525  *this *= (1.f - x);
1526  return *this += other * x;
1527  }
1528 
1539  Color4& blend(Color4 other) {
1540  float srca = COLOR_BYTE_TO_FLOAT(other.a);
1541  float a1 = COLOR_BYTE_TO_FLOAT(a)*(1-srca);
1542  float a2 = srca+a1;
1543  r = clampb((GLubyte)((other.r*srca+r*a1)/a2),0,255);
1544  g = clampb((GLubyte)((other.g*srca+g*a1)/a2),0,255);
1545  b = clampb((GLubyte)((other.b*srca+b*a1)/a2),0,255);
1546  a = COLOR_FLOAT_TO_BYTE(a2);
1547  return *this;
1548  }
1549 
1561  float srca = COLOR_BYTE_TO_FLOAT(other.a);
1562  float a1 = srca+COLOR_BYTE_TO_FLOAT(a)*(1-srca);
1563  r = clampb((GLubyte)(other.r+r*(1-srca)),0,255);
1564  g = clampb((GLubyte)(other.g+g*(1-srca)),0,255);
1565  b = clampb((GLubyte)(other.b+b*(1-srca)),0,255);
1566  a = COLOR_FLOAT_TO_BYTE(a1);
1567  return *this;
1568  }
1569 
1580  scale(COLOR_BYTE_TO_FLOAT(a),false);
1581  return *this;
1582  }
1583 
1596  if (a > 0) {
1597  float a1 = 1/COLOR_BYTE_TO_FLOAT(a);
1598  scale(a1,false);
1599  }
1600  return *this;
1601  }
1602 
1620  Color4 getLerp(Color4 other, float alpha) const {
1621  float x = clampf(alpha,0,1);
1622  return *this * (1.f - x) + other * x;
1623  }
1624 
1637  Color4 getBlend(Color4 other) const {
1638  float srca = COLOR_BYTE_TO_FLOAT(other.a);
1639  float a1 = COLOR_BYTE_TO_FLOAT(a)*(1-srca);
1640  float a2 = srca+a1;
1641  return Color4(clampb((GLubyte)((other.r*srca+r*a1)/a2), 0, 255),
1642  clampb((GLubyte)((other.g*srca+g*a1)/a2), 0, 255),
1643  clampb((GLubyte)((other.b*srca+b*a1)/a2), 0, 255),
1644  COLOR_FLOAT_TO_BYTE(a2));
1645  }
1646 
1659  Color4f getBlendPre(Color4 other) const {
1660  float srca = COLOR_BYTE_TO_FLOAT(other.a);
1661  float dsta = COLOR_BYTE_TO_FLOAT(a);
1662  float a1 = srca+dsta*(1-srca);
1663  return Color4(clampb((GLubyte)(other.r+r*(1-srca)),0,255),
1664  clampb((GLubyte)(other.g+g*(1-srca)),0,255),
1665  clampb((GLubyte)(other.b+b*(1-srca)),0,255),
1666  COLOR_FLOAT_TO_BYTE(a1));
1667  }
1668 
1681  Color4 result(r,g,b,255);
1682  result *= COLOR_BYTE_TO_FLOAT(a);
1683  return result;
1684  }
1685 
1700  if (a > 0) {
1701  float a1 = 1/COLOR_BYTE_TO_FLOAT(a);
1702  Color4 result(*this);
1703  return result.scale(a1,false);
1704  }
1705  return *this;
1706  }
1707 
1725  static Color4* lerp(Color4 c1, Color4 c2, float alpha, Color4* dst);
1726 
1740  static Color4* blend(Color4 c1, Color4 c2, Color4* dst);
1741 
1755  static Color4* blendPre(Color4 c1, Color4 c2, Color4* dst);
1756 
1769  GLuint getRGBA() const {
1770  return marshall(rgba);
1771  }
1772 
1773 #pragma mark Operators
1774 
1787  r = clampb(r+c.r,0,255);
1788  g = clampb(g+c.g,0,255);
1789  b = clampb(b+c.b,0,255);
1790  a = clampb(a+c.a,0,255);
1791  return *this;
1792  }
1793 
1807  r = clampb(r-c.r,0,255);
1808  g = clampb(g-c.g,0,255);
1809  b = clampb(b-c.b,0,255);
1810  a = clampb(a-c.a,0,255);
1811  return *this;
1812  }
1813 
1825  Color4& operator*=(float s) {
1826  r = clampb(static_cast<GLubyte>(r*s),0,255);
1827  g = clampb(static_cast<GLubyte>(g*s),0,255);
1828  b = clampb(static_cast<GLubyte>(b*s),0,255);
1829  a = clampb(static_cast<GLubyte>(a*s),0,255);
1830  return *this;
1831  }
1832 
1843  r = clampb(static_cast<GLuint>(COLOR_BYTE_TO_FLOAT(c.r)*r),0,255);
1844  g = clampb(static_cast<GLuint>(COLOR_BYTE_TO_FLOAT(c.g)*g),0,255);
1845  b = clampb(static_cast<GLuint>(COLOR_BYTE_TO_FLOAT(c.b)*b),0,255);
1846  a = clampb(static_cast<GLuint>(COLOR_BYTE_TO_FLOAT(c.a)*a),0,255);
1847  return *this;
1848  }
1849 
1864  const Color4 operator+(Color4 c) const {
1865  Color4 result(*this);
1866  return result += c;
1867  }
1868 
1883  const Color4 operator-(Color4 c) const {
1884  Color4 result(*this);
1885  return result -= c;
1886  }
1887 
1901  const Color4 operator*(float s) const {
1902  Color4 result(*this);
1903  return result *= s;
1904  }
1905 
1917  const Color4 operator*(Color4 c) const {
1918  Color4 result(*this);
1919  return result *= c;
1920  }
1921 
1922 
1923 #pragma mark Comparisons
1924 
1935  bool operator<(Color4 c) const;
1936 
1948  bool operator<=(Color4 c) const {
1949  return *this < c || rgba == c.rgba;
1950  }
1951 
1963  bool operator>(Color4 c) const;
1964 
1976  bool operator>=(Color4 c) const {
1977  return *this > c || rgba == c.rgba;
1978  }
1979 
1987  bool operator==(Color4 c) const {
1988  return rgba == c.rgba;
1989  }
1990 
2001  bool operator!=(Color4 c) const {
2002  return rgba != c.rgba;
2003  }
2004 
2016  bool darkerThan(Color4 c) const {
2017  return r <= c.r && g <= c.g && b <= c.b && c.a <= a;
2018  }
2019 
2032  bool lighterThan(Color4 c) const {
2033  return r >= c.r && g >= c.g && b >= c.b && c.a >= a;
2034  }
2035 
2036 #pragma mark Conversion Methods
2037 public:
2048  std::string toString(bool verbose = false) const;
2049 
2051  operator std::string() const { return toString(); }
2052 
2058  operator Vec4() const;
2059 
2068  explicit Color4(const Vec4& vector);
2069 
2080  Color4& operator= (const Vec4& vector);
2081 
2087  operator Vec3() const;
2088 
2097  explicit Color4(const Vec3& vector);
2098 
2109  Color4& operator= (const Vec3& vector);
2110 
2112  operator Color4f() const;
2113 
2122  explicit Color4(const Color4f& color);
2123 
2134  Color4& operator= (const Color4f& color);
2135 };
2136 
2137 #pragma mark -
2138 #pragma mark Friend Operations
2139 
2152 inline const Color4f operator*(float s, const Color4f& c) {
2153  Color4f result(c);
2154  return result *= s;
2155 }
2156 
2169 inline const Color4 operator*(float s, Color4 c) {
2170  Color4 result(c);
2171  return result *= s;
2172 }
2173 
2174 }
2175 
2176 #endif /* __CU_COLOR4_H__ */
static const Color4 CORNFLOWER
Definition: CUColor4.h:1146
Color4f & clamp(const Color4f &min, const Color4f &max)
static const Color4f BLACK
Definition: CUColor4.h:91
Color4 & subtract(GLubyte r, GLubyte g, GLubyte b, GLubyte a=0)
Definition: CUColor4.h:1379
Color4f getPremultiplied() const
Definition: CUColor4.h:641
Color4 & set(GLuint color)
Definition: CUColor4.h:1264
Color4f getClamp(const Color4f &min, const Color4f &max) const
Definition: CUColor4.h:276
Color4 getBlend(Color4 other) const
Definition: CUColor4.h:1637
Color4f & blendPre(const Color4f &other)
Definition: CUColor4.h:529
static const Color4 YELLOW
Definition: CUColor4.h:1130
Color4f getBlend(const Color4f &other) const
Definition: CUColor4.h:603
Color4 getUnpremultiplied() const
Definition: CUColor4.h:1699
Color4 & add(Color4 c, bool alpha=false)
Definition: CUColor4.h:1320
bool lighterThan(const Color4f &c) const
Definition: CUColor4.h:984
~Color4()
Definition: CUColor4.h:1194
Color4f & lerp(const Color4f &other, float alpha)
Definition: CUColor4.h:493
Color4 & set(const Color4 &c)
Definition: CUColor4.h:1276
bool operator==(Color4 c) const
Definition: CUColor4.h:1987
bool darkerThan(const Color4f &c) const
Definition: CUColor4.h:968
Color4(GLubyte r, GLubyte g, GLubyte b, GLubyte a=255)
Definition: CUColor4.h:1166
~Color4f()
Definition: CUColor4.h:163
const Color4f operator+(const Color4f &c) const
Definition: CUColor4.h:815
Color4f getMap(std::function< float(float)> func, bool alpha=false) const
Definition: CUColor4.h:442
const Color4f operator-(const Color4f &c) const
Definition: CUColor4.h:834
GLfloat g
Definition: CUColor4.h:80
static const Color4f ORANGE
Definition: CUColor4.h:105
Color4f & operator*=(const Color4f &c)
Definition: CUColor4.h:796
Color4f getBlendPre(const Color4f &other) const
Definition: CUColor4.h:624
GLfloat a
Definition: CUColor4.h:84
bool equals(const Color4f &color, float variance=CU_MATH_EPSILON) const
Definition: CUColor4.h:998
Color4f & map(std::function< float(float)> func, bool alpha=false)
Definition: CUColor4.h:425
static const Color4 BLACK
Definition: CUColor4.h:1128
GLuint getRGBA() const
Color4 & map(std::function< GLubyte(GLubyte)> func, bool alpha=false)
Definition: CUColor4.h:1455
GLubyte r
Definition: CUColor4.h:1111
Color4 & scale(Color4 c, bool alpha=false)
Definition: CUColor4.h:1435
bool operator==(const Color4f &c) const
Definition: CUColor4.h:939
SDL_FORCE_INLINE Uint16 marshall(Sint16 value)
Definition: CUEndian.h:53
bool darkerThan(Color4 c) const
Definition: CUColor4.h:2016
GLuint getRGBA() const
Definition: CUColor4.h:1769
bool operator!=(Color4 c) const
Definition: CUColor4.h:2001
Color4 & operator+=(Color4 c)
Definition: CUColor4.h:1786
Color4 & subtract(Color4 c, bool alpha=false)
Definition: CUColor4.h:1359
const Color4 operator*(float s) const
Definition: CUColor4.h:1901
Color4 & scale(float s, bool alpha=false)
Definition: CUColor4.h:1397
static const Color4f CYAN
Definition: CUColor4.h:103
Color4f getLerp(const Color4f &other, float alpha) const
Definition: CUColor4.h:586
const Color4 operator-(Color4 c) const
Definition: CUColor4.h:1883
Definition: CUColor4.h:73
Color4 & scale(float sr, float sg, float sb, float sa=1)
Definition: CUColor4.h:1417
Color4 & premultiply()
Definition: CUColor4.h:1579
static const Color4f GRAY
Definition: CUColor4.h:107
Color4(GLuint color)
Definition: CUColor4.h:1179
Color4f & operator=(const float *array)
Definition: CUColor4.h:201
static const Color4 RED
Definition: CUColor4.h:1136
static const Color4 WHITE
Definition: CUColor4.h:1126
bool operator>=(const Color4f &c) const
Definition: CUColor4.h:925
Color4f & complement(bool alpha=false)
Definition: CUColor4.h:458
Color4 & unpremultiply()
Definition: CUColor4.h:1595
Color4f(const Color4f &copy)
Definition: CUColor4.h:147
Color4 & operator*=(Color4 c)
Definition: CUColor4.h:1842
Color4 & blendPre(Color4 other)
Definition: CUColor4.h:1560
Color4f & add(float r, float g, float b, float a=0)
Definition: CUColor4.h:312
static const Color4 CLEAR
Definition: CUColor4.h:1124
Color4f & unpremultiply()
Definition: CUColor4.h:562
Color4 & operator=(const float *array)
Definition: CUColor4.h:1223
Color4f & subtract(float r, float g, float b, float a=0)
Definition: CUColor4.h:351
static const Color4f GREEN
Definition: CUColor4.h:97
Color4 & operator-=(Color4 c)
Definition: CUColor4.h:1806
Color4 & operator=(GLuint color)
Definition: CUColor4.h:1209
Color4()
Definition: CUColor4.h:1156
std::string toString(bool verbose=false) const
Color4 & operator*=(float s)
Definition: CUColor4.h:1825
Color4f & premultiply()
Definition: CUColor4.h:546
Color4f & add(const Color4f &c, bool alpha=false)
Definition: CUColor4.h:292
Color4 getMap(std::function< GLubyte(GLubyte)> func, bool alpha=false) const
Definition: CUColor4.h:1473
Definition: CUVec4.h:73
Color4f & operator=(unsigned int color)
Definition: CUColor4.h:188
bool operator>=(Color4 c) const
Definition: CUColor4.h:1976
Color4f & operator-=(const Color4f &c)
Definition: CUColor4.h:760
bool operator<=(const Color4f &c) const
Definition: CUColor4.h:897
bool operator>(Color4 c) const
Color4 getLerp(Color4 other, float alpha) const
Definition: CUColor4.h:1620
Color4 getComplement(bool alpha=false) const
Definition: CUColor4.h:1504
std::string toString(bool verbose=false) const
static const Color4 GRAY
Definition: CUColor4.h:1144
Color4f & operator=(const Color4f &c)
Definition: CUColor4.h:174
static const Color4 CYAN
Definition: CUColor4.h:1140
Color4 & add(GLubyte r, GLubyte g, GLubyte b, GLubyte a=0)
Definition: CUColor4.h:1340
Color4 & complement(bool alpha=false)
Definition: CUColor4.h:1488
bool lighterThan(Color4 c) const
Definition: CUColor4.h:2032
static const Color4f CLEAR
Definition: CUColor4.h:87
GLubyte b
Definition: CUColor4.h:1115
Color4f & subtract(const Color4f &c, bool alpha=false)
Definition: CUColor4.h:331
Color4 & blend(Color4 other)
Definition: CUColor4.h:1539
static const Color4f BLUE
Definition: CUColor4.h:95
Color4f getComplement(bool alpha=false) const
Definition: CUColor4.h:474
Color4 getClamp(Color4 min, Color4 max) const
Definition: CUColor4.h:1303
Color4f & set(const Color4f &c)
Definition: CUColor4.h:249
static const Color4f CORNFLOWER
Definition: CUColor4.h:109
Color4f & operator+=(const Color4f &c)
Definition: CUColor4.h:740
GLfloat r
Definition: CUColor4.h:78
GLubyte g
Definition: CUColor4.h:1113
const Color4f operator*(const Color4f &c) const
Definition: CUColor4.h:866
Color4f & blend(const Color4f &other)
Definition: CUColor4.h:509
static const Color4 BLUE
Definition: CUColor4.h:1132
Color4f & operator*=(float s)
Definition: CUColor4.h:779
Color4f & scale(float sr, float sg, float sb, float sa=1)
Definition: CUColor4.h:389
int operator*(Font::Style value)
Definition: CUFont.h:1503
static const Color4f RED
Definition: CUColor4.h:99
Uint32 rgba
Definition: CUColor4.h:1120
Color4f getBlendPre(Color4 other) const
Definition: CUColor4.h:1659
Definition: CUVec3.h:61
Color4f & scale(const Color4f &c, bool alpha=false)
Definition: CUColor4.h:407
const Color4 operator+(Color4 c) const
Definition: CUColor4.h:1864
static const Color4f WHITE
Definition: CUColor4.h:89
bool operator<=(Color4 c) const
Definition: CUColor4.h:1948
Definition: CUColor4.h:1104
const Color4f operator*(float s) const
Definition: CUColor4.h:850
static const Color4 PAPYRUS
Definition: CUColor4.h:1148
Definition: CUAnimationNode.h:52
GLfloat b
Definition: CUColor4.h:82
Color4 & clamp(Color4 min, Color4 max)
const Color4 operator*(Color4 c) const
Definition: CUColor4.h:1917
Color4f()
Definition: CUColor4.h:118
bool operator!=(const Color4f &c) const
Definition: CUColor4.h:953
Color4f & scale(float s, bool alpha=false)
Definition: CUColor4.h:369
bool operator<(const Color4f &c) const
Color4 getPremultiplied() const
Definition: CUColor4.h:1680
Color4f getUnpremultiplied() const
Definition: CUColor4.h:658
bool operator>(const Color4f &c) const
Color4 & lerp(const Color4f &other, float alpha)
Definition: CUColor4.h:1523
static const Color4 MAGENTA
Definition: CUColor4.h:1138
static const Color4f YELLOW
Definition: CUColor4.h:93
GLubyte a
Definition: CUColor4.h:1117
static const Color4 ORANGE
Definition: CUColor4.h:1142
static const Color4 GREEN
Definition: CUColor4.h:1134
Color4f & set(float r, float g, float b, float a=1)
static const Color4f MAGENTA
Definition: CUColor4.h:101
static const Color4f PAPYRUS
Definition: CUColor4.h:111
Color4 & set(GLubyte r, GLubyte g, GLubyte b, GLubyte a=255)
Definition: CUColor4.h:1237
bool operator<(Color4 c) const