raSystem  1.0 bata
raColor.h
Go to the documentation of this file.
1 #pragma once
2 
3 #define raCOLORCON (0.003921568627450980392156862745098f)
4 
5  class RAPI raColor
6  {
7  public:
8  union
9  {
10  struct
11  {
12  float r;
13  float g;
14  float b;
15  float a;
16  };
17  struct
18  {
19  float red;
20  float green;
21  float blue;
22  float alpa;
23  };
24  float c[4];
25  //D3DCOLORVALUE D3DColorValue;
26  };
27  raColor(void) {}
28  raColor(float _r, float _g, float _b, float _a) : r(_r), g(_g), b(_b), a(_a) {}
29  raColor(float _r, float _g, float _b) : r(_r), g(_g), b(_b), a(1.0f) {}
30  raColor(float f) : r(f), g(f), b(f), a(f) {}
31  raColor(float *com) : r(com[0]), g(com[1]), b(com[2]), a(com[3]) {}
32  raColor(const int _r, const int _g, const int _b) : r((float)(_r) * raCOLORCON), g((float)(_g) * raCOLORCON), b((float)(_b) * raCOLORCON), a(1.0f) {}
33  raColor(const int _r, const int _g, const int _b, const int _a) : r((float)(_r) * raCOLORCON), g((float)(_g) * raCOLORCON), b((float)(_b) * raCOLORCON), a((float)(_a) * raCOLORCON) {}
34  raColor(const int* pComponent) : r((float)(pComponent[0]) * raCOLORCON), g((float)(pComponent[1]) * raCOLORCON), b((float)(pComponent[2]) * raCOLORCON), a((float)(pComponent[3]) * raCOLORCON) {}
35  raColor(const int c) : r(raCOLORCON * (float)(int)(c >> 16)), g(raCOLORCON * (float)(int)(c >> 8)), b(raCOLORCON * (float)(int)(c)), a(raCOLORCON * (float)(int)(c >> 24)) {}
36 
37  operator unsigned long () const
38  {
39  return ((a >= 1.0f ? 255 : a <= 0.0f ? 0 : (DWORD)(a * 255.0f)) << 24) |
40  ((r >= 1.0f ? 255 : r <= 0.0f ? 0 : (DWORD)(r * 255.0f)) << 16) |
41  ((g >= 1.0f ? 255 : g <= 0.0f ? 0 : (DWORD)(g * 255.0f)) << 8) |
42  (b >= 1.0f ? 255 : b <= 0.0f ? 0 : (DWORD)(b * 255.0f));
43  }
44  operator float* () {return (float*)(c);}
45  //operator D3DCOLORVALUE& () {return D3DColorValue;}
46 
47  raColor& operator = (const raColor& c) {a = c.a; b = c.b; g = c.g; r = c.r; return *this;}
48  raColor& operator += (const raColor& c) {r += c.r; g += c.g; b += c.b; a += c.a; return *this;}
49  raColor& operator -= (const raColor& c) {r -= c.r; g -= c.g; b -= c.b; a -= c.a; return *this;}
50  raColor& operator *= (const raColor& c) {r *= c.r; g *= c.g; b *= c.b; a *= c.a; return *this;}
51  raColor& operator *= (const float f) {r *= f; g *= f; b *= f; a *= f; return *this;}
52  raColor& operator /= (const raColor& c) {r /= c.r; g /= c.g; b /= c.b; a /= c.a; return *this;}
53  raColor& operator /= (const float f) {r /= f; g /= f; b /= f; a /= f; return *this;}
54  };
55  inline raColor operator + (const raColor& a, const raColor& b) {return raColor(a.r + b.r, a.g + b.g, a.b + b.b, a.a + b.a);}
56  inline raColor operator - (const raColor& a, const raColor& b) {return raColor(a.r - b.r, a.g - b.g, a.b - b.b, a.a - b.a);}
57  inline raColor operator - (const raColor& c) {return raColor(-c.r, -c.g, -c.b, c.a);}
58  inline raColor operator * (const raColor& a, const raColor& b) {return raColor(a.r * b.r, a.g * b.g, a.b * b.b, a.a * b.a);}
59  inline raColor operator * (const raColor& c, const float f) {return raColor(c.r * f, c.g * f, c.b * f, c.a * f);}
60  inline raColor operator * (const float f, const raColor& c) {return raColor(c.r * f, c.g * f, c.b * f, c.a * f);}
61  inline raColor operator / (const raColor& a, const raColor& b) {return raColor(a.r / b.r, a.g / b.g, a.b / b.b, a.a / b.a);}
62  inline raColor operator / (const raColor& c, const float f) {return raColor(c.r / f, c.g / f, c.b / f, c.a / f);}
63 
64  // Vergleichsoperatoren
65  inline bool operator == (const raColor& a, const raColor& b) {if(a.r != b.r) return false; if(a.g != b.g) return false; if(a.b != b.b) return false; return a.a == b.a;}
66  inline bool operator != (const raColor& a, const raColor& b) {if(a.r != b.r) return true; if(a.g != b.g) return true; if(a.b != b.b) return true; return a.a != b.a;}
67 
68  // ******************************************************************
69  // Funktionen deklarieren
70  inline raColor raColorNegate(const raColor& c) {return raColor(1.0f - c.r, 1.0f - c.g, 1.0f - c.b, 1.0f - c.a);}
71  inline float raColorBrightness(const raColor& c) {return c.r * 0.299f + c.g * 0.587f + c.b * 0.114f;}
72  inline raColor raColorInterpolate(const raColor& c1, const raColor& c2, const float p) {return c1 + p * (c2 - c1);}
73  inline raColor raColorMin(const raColor& c1, const raColor& c2) {return raColor(RAMIN(c1.r, c2.r), RAMIN(c1.g, c2.g), RAMIN(c1.b, c2.b), RAMIN(c1.a, c2.a));}
74  inline raColor raColorMax(const raColor& c1, const raColor& c2) {return raColor(RAMAX(c1.r, c2.r), RAMAX(c1.g, c2.g), RAMAX(c1.b, c2.b), RAMAX(c1.a, c2.a));}
75 
76  RAPI raColor raColorFromYUV(float y, float u, float v);
77  RAPI raColor raColorFromHSV(float h, float s, float v);
78  RAPI raColor raColorFromCMY(float c, float m, float y);
float alpa
Definition: raColor.h:22
bool operator==(const raColor &a, const raColor &b)
Definition: raColor.h:65
raColor(float _r, float _g, float _b, float _a)
Definition: raColor.h:28
#define RAPI
Definition: raMain.h:11
RAPI raColor raColorFromCMY(float c, float m, float y)
Definition: raColor.cpp:14
raColor operator-(const raColor &a, const raColor &b)
Definition: raColor.h:56
RAPI raColor raColorFromHSV(float h, float s, float v)
Definition: raColor.cpp:19
float green
Definition: raColor.h:20
Definition: raColor.h:5
float g
Definition: raColor.h:13
float red
Definition: raColor.h:19
raColor operator/(const raColor &a, const raColor &b)
Definition: raColor.h:61
float b
Definition: raColor.h:14
raColor operator*(const raColor &a, const raColor &b)
Definition: raColor.h:58
raColor(const int _r, const int _g, const int _b)
Definition: raColor.h:32
#define raCOLORCON
Definition: raColor.h:3
raColor(const int _r, const int _g, const int _b, const int _a)
Definition: raColor.h:33
bool operator!=(const raColor &a, const raColor &b)
Definition: raColor.h:66
raColor(float *com)
Definition: raColor.h:31
float a
Definition: raColor.h:15
raColor(float _r, float _g, float _b)
Definition: raColor.h:29
raColor(void)
Definition: raColor.h:27
raColor raColorInterpolate(const raColor &c1, const raColor &c2, const float p)
Definition: raColor.h:72
float raColorBrightness(const raColor &c)
Definition: raColor.h:71
#define RAMAX(a, b)
Definition: raMain.h:128
raColor raColorNegate(const raColor &c)
Definition: raColor.h:70
#define RAMIN(a, b)
Definition: raMain.h:127
raColor raColorMax(const raColor &c1, const raColor &c2)
Definition: raColor.h:74
raColor(const int *pComponent)
Definition: raColor.h:34
raColor(const int c)
Definition: raColor.h:35
raColor(float f)
Definition: raColor.h:30
float blue
Definition: raColor.h:21
raColor raColorMin(const raColor &c1, const raColor &c2)
Definition: raColor.h:73
raColor operator+(const raColor &a, const raColor &b)
Definition: raColor.h:55
float r
Definition: raColor.h:12
RAPI raColor raColorFromYUV(float y, float u, float v)
Definition: raColor.cpp:5