Cumulia Illustrator Rendering Engine v2.1.0
A Rendering engine for industrial CAD/CAE model and optimized for greatest performance
 
Loading...
Searching...
No Matches
color.h
1//##################################################################################################
2//
3// Copyright (c) 2024 Beijing Qiongqi Tech Co.,Ltd. All rights reserved.
4
5// This source code is confidential and proprietary to Beijing Qiongqi Tech Co.,Ltd(The Holder).
6// Any unauthorized use, copying, modification, or distribution of the code is strictly prohibited.
7// Any user shall obtain authorizaition from the Holder before modifying the source code. And the user shall not
8// sublicense, sell, distribute, or transfer the source code, whether in original or modified form, to any third party
9// without the prior written consent of the Holder.
10
11// This copyright notice and permission grant shall be included in all copies or substantial portions of the source code.
12
13// Author Cumulia Illustrator
14// Date 2025-08-05
15// Version V2.1.0
16//##################################################################################################
17
18#pragma once
19
20#include "tuple.h"
21
22namespace cil
23{
24 class Color3f;
25 class Color3ub;
26 class Color4f;
27 class Color4ub;
28
30 template<typename T>
31 class Color : public Tuple<T>
32 {
33 public:
37 : Tuple<T>(size)
38 {
39 }
41 const T& operator[](int index) const
42 {
43 return this->m_data[index];
44 }
46 T& operator[](int index)
47 {
48 return this->m_data[index];
49 }
53 const T& operator[](char key) const
54 {
55 if (key == 'r')
56 return this->m_data[0];
57 if (key == 'g')
58 return this->m_data[1];
59 if (key == 'b')
60 return this->m_data[2];
61 if (key == 'a' && this->m_size == 4)
62 return this->m_data[3];
63
64 return this->m_data[0];
65 }
69 T& operator[](char key)
70 {
71 if (key == 'r')
72 return this->m_data[0];
73 if (key == 'g')
74 return this->m_data[1];
75 if (key == 'b')
76 return this->m_data[2];
77 if (key == 'a' && this->m_size == 4)
78 return this->m_data[3];
79
80 return this->m_data[0];
81 }
82 };
83
85 template<typename T>
86 class Color3 : public Color<T>
87 {
88 public:
91 : Color<T>(3)
92 {
93 }
95 void set(T r, T g, T b)
96 {
97 this->m_data[0] = r;
98 this->m_data[1] = g;
99 this->m_data[2] = b;
100 }
101 };
102
104 class Color3f final : public Color3<float>
105 {
106 public:
108 Color3f(float r, float g, float b);
109 Color3f(const Color3f& other);
110 Color3f(const Color3ub& other);
111 Color3f(const Color4f& other);
112 Color3f(const Color4ub& other);
113 };
115 class Color3ub final : public Color3<unsigned char>
116 {
117 public:
119 Color3ub(unsigned char r, unsigned char g, unsigned char b);
120 Color3ub(const Color3ub& other);
121 Color3ub(const Color3f& other);
122 Color3ub(const Color4ub& other);
123 Color3ub(const Color4f& other);
124 };
126 template<typename T>
127 class Color4 : public Color<T>
128 {
129 public:
132 : Color<T>(4)
133 {
134 }
136 void set(T r, T g, T b, T a)
137 {
138 this->m_data[0] = r;
139 this->m_data[1] = g;
140 this->m_data[2] = b;
141 this->m_data[3] = a;
142 }
143 };
145 class Color4f final : public Color4<float>
146 {
147 public:
149 Color4f(float r, float g, float b, float a);
150 Color4f(const Color4f& other);
151 Color4f(const Color3f& other);
152 Color4f(const Color4ub& other);
153 Color4f(const Color3ub& other);
154 };
156 class Color4ub final : public Color4<unsigned char>
157 {
158 public:
160 Color4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a);
161 Color4ub(const Color4ub& other);
162 Color4ub(const Color4f& other);
163 Color4ub(const Color3ub& other);
164 Color4ub(const Color3f& other);
165 };
166
167 using clr3 = Color3f;
169 using clr4 = Color4f;
171}
The class Color3 is a templated class inheriting from the Color class. A Color3 object holds 3 elemen...
Definition color.h:87
void set(T r, T g, T b)
Sets the (r,g,b) values of current Color3 object.
Definition color.h:95
Color3()
Contructs a Color3 object with 3 elements.
Definition color.h:90
The Color3f class inherits from Color3, specilizing the template parameters to float for element type...
Definition color.h:105
Color3f(const Color4f &other)
Color3f(const Color4ub &other)
Color3f(const Color3ub &other)
Constructs a Color3f of (r, g, b) by copying the values of another Color3ub object and dividing these...
Color3f(float r, float g, float b)
Constructs a Color3f object, and set its elements to parameters (r, g, b).
Color3f()
Constructs a Color3f object, and initializes it to (1.0f, 1.0f, 1.0f).
Color3f(const Color3f &other)
The Color3ub class inherits from Color3, specilizing the template parameters to unsigned char for ele...
Definition color.h:116
Color3ub(const Color4ub &other)
Color3ub(unsigned char r, unsigned char g, unsigned char b)
Constructs a Color3ub object, and set its elements to parameters (r, g, b).
Color3ub()
Constructs a Color3ub object, and initializes it to (255, 255, 255).
Color3ub(const Color3ub &other)
Color3ub(const Color3f &other)
Constructs a Color3f of (r, g, b) by copying the values of another Color3ub object and multiplying th...
Color3ub(const Color4f &other)
The class Color4 is a templated class inheriting from the Color class. A Color4 object holds 4 elemen...
Definition color.h:128
Color4()
Contructs a Color4 object with 4 elements.
Definition color.h:131
void set(T r, T g, T b, T a)
Sets the (r, g, b, a) values of current Color4 object.
Definition color.h:136
The Color4f class inherits from Color4, specilizing the template parameters to float for element type...
Definition color.h:146
Color4f(const Color4ub &other)
Constructs a Color4f of (r, g, b, a) by copying the values of another Color4ub object and dividing th...
Color4f()
Constructs a Color4f object, and initializes it to (1.0f, 1.0f, 1.0f, 1.0f).
Color4f(const Color4f &other)
Color4f(const Color3f &other)
Constructs a Color4f of (r, g, b, a) by copying the (r, g, b) of another Color3ub object and setting ...
Color4f(float r, float g, float b, float a)
Constructs a Color4f object, and set its elements to parameters (r, g, b, a).
Color4f(const Color3ub &other)
The Color4ub class inherits from Color4, specilizing the template parameters to unsigned char for ele...
Definition color.h:157
Color4ub(const Color3ub &other)
Color4ub(const Color4ub &other)
Color4ub(const Color3f &other)
Constructs a Color4ub of (r, g, b, a) by copying the (r, g, b) of another Color3ub object and setting...
Color4ub(const Color4f &other)
Constructs a Color4ub of (r, g, b, a) by copying the values of another Color4f object and multiplying...
Color4ub()
Constructs a Color4ub object, and initializes it to (255, 255, 255, 255).
Color4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Constructs a Color4ub object, and set its elements to paramters (r, g, b, a).
The Color is a templated class that inherits publicly from a class named Tuple<T>.
Definition color.h:32
Color(int size)
Constructs a Color object with a specified number of elements.
Definition color.h:36
T & operator[](int index)
Provides read-write access to the element at a specific index(position) within the Color object.
Definition color.h:46
const T & operator[](char key) const
Provides read-only access to a element within the Color object using a character key.
Definition color.h:53
const T & operator[](int index) const
Provides read-only access to the element at a specific index(position) within the Color object.
Definition color.h:41
T & operator[](char key)
Provides read-write access to a element within the Color object using a character key.
Definition color.h:69
The Tuple is a templated class inheriting from the most basic class Variant.
Definition tuple.h:27
int m_size
The number of elements that the data array of the Tuple holds.
Definition tuple.h:36
T * m_data
The data array of the Tuple.
Definition tuple.h:35
int size() const
Gets the number of elements of the Tuple.
Definition tuple.h:54
Definition decal.h:23