JNR
laColor.h
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
30 
31 
39 
40 #ifndef M_RGB_H
41 #define M_RGB_H
42 
43 #define M_CC unsigned char //< color component type
44 
45 class laColor: public laLoadableObj
46 {
47 protected:
48  //Color components
49  //unsigned char r, g, b, a;
50  M_CC _cc[4];
51 
52 public:
53  // Indexing
54  //
55  inline M_CC& operator[] (unsigned short n) { /*ASSERT(n<4, "%d out of bounds", n);*/ return _cc[n]; }
56  inline const M_CC& operator() (unsigned short n) const{ /*ASSERT(n<4, "%d out of bounds", n);*/ return _cc[n]; }
57 
58  inline const M_CC& r() const{ return _cc[0]; }
59  inline const M_CC& g() const{ return _cc[1]; }
60  inline const M_CC& b() const{ return _cc[2]; }
61  inline const M_CC& a() const{ return _cc[3]; }
62  inline void r(const M_CC &val) { _cc[0] = val; }
63  inline void g(const M_CC &val) { _cc[1] = val; }
64  inline void b(const M_CC &val) { _cc[2] = val; }
65  inline void a(const M_CC &val) { _cc[3] = val; }
66 
67  inline M_CC* data() { return _cc; } // NOTE: This could be operator M_CC*(), but that's harder to debug
68  inline const M_CC* cdata() const{ return _cc; }
69 
70  // Constructors
71  //
72  laColor() { _cc[0] = _cc[1] = _cc[2] = 0; _cc[3] = 255; };
73  laColor(M_CC r, M_CC g, M_CC b, M_CC a=255) { _cc[0] = r; _cc[1] = g; _cc[2] = b; _cc[3] = a; };
74  laColor(M_CC cc) { _cc[0] = _cc[1] = _cc[2] = _cc[3] = cc; };
75  laColor(M_CC *v) { _cc[0] = v[0]; _cc[1] = v[1]; _cc[2] = v[2]; _cc[3] = v[3]; }
76  laColor(const laColor &c) { _cc[0] = c(0); _cc[1] = c(1); _cc[2] = c(2); _cc[3] = c(3); };
77 
78  virtual void load(class laFileParser *fp);
79 
80  // Operators
81  //
82  const laColor operator*(const double &n) { return laColor(r()*n, g()*n, b()*n, a()*n); };
83  const laColor operator/(const double &n) { return laColor(r()/n, g()/n, b()/n, a()/n); };
84  inline const laColor operator*=(const double &n) { _cc[0]*=n; _cc[1]*=n; _cc[2]*=n; _cc[3]*=n; return *this; };
85  inline const laColor operator/=(const double &n) { _cc[0]/=n; _cc[1]/=n; _cc[2]/=n; _cc[3]/=n; return *this; };
86 
87  /*inline const laColor operator*=(const laColor &pt) { r*=pt[0]; g*=pt[1]; b*=pt[2]; a*=pt[3]; return *this; };
88  inline const laColor operator/=(const laColor &pt) { r/=pt[0]; g/=pt[1]; b/=pt[2]; a/=pt[3]; return *this; };*/
89 
90  //A few color filters
91  /*void intensify(double i)
92  {
93  double ar = r+i*255;
94  double ag = g+i*255;
95  double ab = b+i*255;
96  if(ar>255)ar=255;
97  if(ag>255)ag=255;
98  if(ab>255)ab=255;
99  if(ar<0)ar=0;
100  if(ag<0)ag=0;
101  if(ab<0)ab=0;
102  r = (unsigned char)ar;
103  g = (unsigned char)ag;
104  b = (unsigned char)ab;
105  }
106 
107  void brighten(double br)
108  {
109  double ar = r*br;
110  double ag = g*br;
111  double ab = b*br;
112  if(ar>255)ar=255;
113  if(ag>255)ag=255;
114  if(ab>255)ab=255;
115  if(ar<0)ar=0;
116  if(ag<0)ag=0;
117  if(ab<0)ab=0;
118  r = (unsigned char)ar;
119  g = (unsigned char)ag;
120  b = (unsigned char)ab;
121  }*/
122 };
124 #endif
Interface for loadable objects.
Definition: laLoadableObj.h:43
File Parser.
Definition: laFileParser.h:41