Blender  V2.93
Color.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 /*
22  * This file is based on a similar file from the NVIDIA texture tools
23  * (http://nvidia-texture-tools.googlecode.com/)
24  *
25  * Original license from NVIDIA follows.
26  */
27 
28 /* This code is in the public domain -- <castanyo@yahoo.es> */
29 
30 #pragma once
31 
33 class Color32 {
34  public:
36  {
37  }
38  Color32(const Color32 &c) : u(c.u)
39  {
40  }
41  Color32(unsigned char R, unsigned char G, unsigned char B)
42  {
43  setRGBA(R, G, B, 0xFF);
44  }
45  Color32(unsigned char R, unsigned char G, unsigned char B, unsigned char A)
46  {
47  setRGBA(R, G, B, A);
48  }
49 #if 0
50  Color32(unsigned char c[4])
51  {
52  setRGBA(c[0], c[1], c[2], c[3]);
53  }
54  Color32(float R, float G, float B)
55  {
56  setRGBA(uint(R * 255), uint(G * 255), uint(B * 255), 0xFF);
57  }
58  Color32(float R, float G, float B, float A)
59  {
60  setRGBA(uint(R * 255), uint(G * 255), uint(B * 255), uint(A * 255));
61  }
62 #endif
63  Color32(unsigned int U) : u(U)
64  {
65  }
66 
67  void setRGBA(unsigned char R, unsigned char G, unsigned char B, unsigned char A)
68  {
69  r = R;
70  g = G;
71  b = B;
72  a = A;
73  }
74 
75  void setBGRA(unsigned char B, unsigned char G, unsigned char R, unsigned char A = 0xFF)
76  {
77  r = R;
78  g = G;
79  b = B;
80  a = A;
81  }
82 
83  operator unsigned int() const
84  {
85  return u;
86  }
87 
88  union {
89  struct {
90  unsigned char b, g, r, a;
91  };
92  unsigned int u;
93  };
94 };
95 
97 class Color16 {
98  public:
100  {
101  }
102  Color16(const Color16 &c) : u(c.u)
103  {
104  }
105  explicit Color16(unsigned short U) : u(U)
106  {
107  }
108 
109  union {
110  struct {
111  unsigned short b : 5;
112  unsigned short g : 6;
113  unsigned short r : 5;
114  };
115  unsigned short u;
116  };
117 };
unsigned int uint
Definition: BLI_sys_types.h:83
#define A
unsigned int U
Definition: btGjkEpa3.h:78
Definition: Color.h:97
unsigned short g
Definition: Color.h:112
unsigned short b
Definition: Color.h:111
Color16(const Color16 &c)
Definition: Color.h:102
unsigned short u
Definition: Color.h:115
Color16()
Definition: Color.h:99
Color16(unsigned short U)
Definition: Color.h:105
unsigned short r
Definition: Color.h:113
Definition: Color.h:33
void setRGBA(unsigned char R, unsigned char G, unsigned char B, unsigned char A)
Definition: Color.h:67
void setBGRA(unsigned char B, unsigned char G, unsigned char R, unsigned char A=0xFF)
Definition: Color.h:75
Color32(const Color32 &c)
Definition: Color.h:38
unsigned char g
Definition: Color.h:90
Color32(unsigned char R, unsigned char G, unsigned char B)
Definition: Color.h:41
unsigned char b
Definition: Color.h:90
Color32(unsigned int U)
Definition: Color.h:63
Color32()
Definition: Color.h:35
unsigned int u
Definition: Color.h:92
unsigned char r
Definition: Color.h:90
unsigned char a
Definition: Color.h:90
Color32(unsigned char R, unsigned char G, unsigned char B, unsigned char A)
Definition: Color.h:45
#define B
#define R
static unsigned c
Definition: RandGen.cpp:97
#define G(x, y, z)