Blender  V2.93
BLI_color.hh
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 
17 #pragma once
18 
19 #include <iostream>
20 
21 #include "BLI_math_color.h"
22 
23 namespace blender {
24 
25 struct Color4f {
26  float r, g, b, a;
27 
28  Color4f() = default;
29 
30  Color4f(const float *rgba) : r(rgba[0]), g(rgba[1]), b(rgba[2]), a(rgba[3])
31  {
32  }
33 
34  Color4f(float r, float g, float b, float a) : r(r), g(g), b(b), a(a)
35  {
36  }
37 
38  operator float *()
39  {
40  return &r;
41  }
42 
43  operator const float *() const
44  {
45  return &r;
46  }
47 
48  friend std::ostream &operator<<(std::ostream &stream, Color4f c)
49  {
50  stream << "(" << c.r << ", " << c.g << ", " << c.b << ", " << c.a << ")";
51  return stream;
52  }
53 
54  friend bool operator==(const Color4f &a, const Color4f &b)
55  {
56  return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
57  }
58 
59  friend bool operator!=(const Color4f &a, const Color4f &b)
60  {
61  return !(a == b);
62  }
63 
64  uint64_t hash() const
65  {
66  uint64_t x1 = *reinterpret_cast<const uint32_t *>(&r);
67  uint64_t x2 = *reinterpret_cast<const uint32_t *>(&g);
68  uint64_t x3 = *reinterpret_cast<const uint32_t *>(&b);
69  uint64_t x4 = *reinterpret_cast<const uint32_t *>(&a);
70  return (x1 * 1283591) ^ (x2 * 850177) ^ (x3 * 735391) ^ (x4 * 442319);
71  }
72 };
73 
74 struct Color4b {
75  uint8_t r, g, b, a;
76 
77  Color4b() = default;
78 
80  {
81  }
82 
84  {
85  rgba_float_to_uchar(*this, other);
86  }
87 
88  operator Color4f() const
89  {
92  return result;
93  }
94 
95  operator uint8_t *()
96  {
97  return &r;
98  }
99 
100  operator const uint8_t *() const
101  {
102  return &r;
103  }
104 
105  friend std::ostream &operator<<(std::ostream &stream, Color4b c)
106  {
107  stream << "(" << c.r << ", " << c.g << ", " << c.b << ", " << c.a << ")";
108  return stream;
109  }
110 
111  friend bool operator==(const Color4b &a, const Color4b &b)
112  {
113  return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
114  }
115 
116  friend bool operator!=(const Color4b &a, const Color4b &b)
117  {
118  return !(a == b);
119  }
120 
121  uint64_t hash() const
122  {
123  return static_cast<uint64_t>(r * 1283591) ^ static_cast<uint64_t>(g * 850177) ^
124  static_cast<uint64_t>(b * 735391) ^ static_cast<uint64_t>(a * 442319);
125  }
126 };
127 
128 } // namespace blender
void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
Definition: math_color.c:414
void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
Definition: math_color.c:427
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble x2
static unsigned c
Definition: RandGen.cpp:97
unsigned int uint32_t
Definition: stdint.h:83
unsigned char uint8_t
Definition: stdint.h:81
unsigned __int64 uint64_t
Definition: stdint.h:93
Color4b(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Definition: BLI_color.hh:79
friend bool operator==(const Color4b &a, const Color4b &b)
Definition: BLI_color.hh:111
Color4b(Color4f other)
Definition: BLI_color.hh:83
friend std::ostream & operator<<(std::ostream &stream, Color4b c)
Definition: BLI_color.hh:105
uint64_t hash() const
Definition: BLI_color.hh:121
Color4b()=default
friend bool operator!=(const Color4b &a, const Color4b &b)
Definition: BLI_color.hh:116
Color4f()=default
friend bool operator!=(const Color4f &a, const Color4f &b)
Definition: BLI_color.hh:59
uint64_t hash() const
Definition: BLI_color.hh:64
friend std::ostream & operator<<(std::ostream &stream, Color4f c)
Definition: BLI_color.hh:48
Color4f(float r, float g, float b, float a)
Definition: BLI_color.hh:34
friend bool operator==(const Color4f &a, const Color4f &b)
Definition: BLI_color.hh:54
Color4f(const float *rgba)
Definition: BLI_color.hh:30