Blender  V3.3
Color.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 /*
8  * This file is based on a similar file from the NVIDIA texture tools
9  * (http://nvidia-texture-tools.googlecode.com/)
10  *
11  * Original license from NVIDIA follows.
12  */
13 
14 /* This code is in the public domain -- <castanyo@yahoo.es> */
15 
16 #pragma once
17 
19 class Color32 {
20  public:
22  {
23  }
24  Color32(const Color32 &) = default;
25 
26  Color32(unsigned char R, unsigned char G, unsigned char B)
27  {
28  setRGBA(R, G, B, 0xFF);
29  }
30  Color32(unsigned char R, unsigned char G, unsigned char B, unsigned char A)
31  {
32  setRGBA(R, G, B, A);
33  }
34 #if 0
35  Color32(unsigned char c[4])
36  {
37  setRGBA(c[0], c[1], c[2], c[3]);
38  }
39  Color32(float R, float G, float B)
40  {
41  setRGBA(uint(R * 255), uint(G * 255), uint(B * 255), 0xFF);
42  }
43  Color32(float R, float G, float B, float A)
44  {
45  setRGBA(uint(R * 255), uint(G * 255), uint(B * 255), uint(A * 255));
46  }
47 #endif
48  Color32(unsigned int U) : u(U)
49  {
50  }
51 
52  void setRGBA(unsigned char R, unsigned char G, unsigned char B, unsigned char A)
53  {
54  r = R;
55  g = G;
56  b = B;
57  a = A;
58  }
59 
60  void setBGRA(unsigned char B, unsigned char G, unsigned char R, unsigned char A = 0xFF)
61  {
62  r = R;
63  g = G;
64  b = B;
65  a = A;
66  }
67 
68  operator unsigned int() const
69  {
70  return u;
71  }
72 
73  union {
74  struct {
75  unsigned char b, g, r, a;
76  };
77  unsigned int u;
78  };
79 };
80 
82 class Color16 {
83  public:
85  {
86  }
87  Color16(const Color16 &c) : u(c.u)
88  {
89  }
90  explicit Color16(unsigned short U) : u(U)
91  {
92  }
93 
94  union {
95  struct {
96  unsigned short b : 5;
97  unsigned short g : 6;
98  unsigned short r : 5;
99  };
100  unsigned short u;
101  };
102 };
unsigned int uint
Definition: BLI_sys_types.h:67
#define A
unsigned int U
Definition: btGjkEpa3.h:78
Definition: Color.h:82
unsigned short g
Definition: Color.h:97
unsigned short b
Definition: Color.h:96
Color16(const Color16 &c)
Definition: Color.h:87
unsigned short u
Definition: Color.h:100
Color16()
Definition: Color.h:84
Color16(unsigned short U)
Definition: Color.h:90
unsigned short r
Definition: Color.h:98
Definition: Color.h:19
void setRGBA(unsigned char R, unsigned char G, unsigned char B, unsigned char A)
Definition: Color.h:52
Color32(const Color32 &)=default
void setBGRA(unsigned char B, unsigned char G, unsigned char R, unsigned char A=0xFF)
Definition: Color.h:60
unsigned char g
Definition: Color.h:75
Color32(unsigned char R, unsigned char G, unsigned char B)
Definition: Color.h:26
unsigned char b
Definition: Color.h:75
Color32(unsigned int U)
Definition: Color.h:48
Color32()
Definition: Color.h:21
unsigned int u
Definition: Color.h:77
unsigned char r
Definition: Color.h:75
unsigned char a
Definition: Color.h:75
Color32(unsigned char R, unsigned char G, unsigned char B, unsigned char A)
Definition: Color.h:30
#define B
#define R
#define G(x, y, z)
static unsigned c
Definition: RandGen.cpp:83