NDEVR
API Documentation
HSLColor.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: HSLColor
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Color.h>
34#include <NDEVR/Angle.h>
35#include <NDEVR/Vector.h>
36namespace NDEVR
37{
38 class RGBColor;
39 class ACIColor;
40 class XYZColor;
50 class HSLColor : public Color
51 {
52 public:
57 public:
61 constexpr HSLColor()
62 : hue(Constant<Angle<HSLAngleType>>::Invalid)
63 , saturation(Constant<uint01>::Invalid)
64 , brightness(Constant<uint01>::Invalid)
65 , alpha(Constant<uint01>::Invalid)
66 {}
67
71 constexpr HSLColor(const HSLColor& color) = default;
79 constexpr HSLColor(const Angle<HSLAngleType>& h, uint01 s, uint01 b, uint01 a = 255)
80 : hue(h)
81 , saturation(s)
82 , brightness(b)
83 , alpha(a)
84 {}
85
92 constexpr HSLColor(uint01 h, uint01 s, uint01 b, uint01 a = 255)
93 : hue(Angle<HSLAngleType>(DEGREES, 360.0 * cast<fltp08>(h) / 256.0))
94 , saturation(s)
95 , brightness(b)
96 , alpha(a)
97 {
98 }
99
106 constexpr HSLColor(const Angle<HSLAngleType>& h, fltp08 s, fltp08 b, fltp08 a = 1.0)
107 : hue(h)
108 , saturation(cast<uint01>((s > 1) ? 1 : ((s < 0) ? 0 : s) * 255))
109 , brightness(cast<uint01>((b > 1) ? 1 : ((b < 0) ? 0 : b) * 255))
110 , alpha(cast<uint01>(a *255))
111 {}
112
120 constexpr HSLColor(const Angle<HSLAngleType>& h, fltp04 s, fltp04 b, fltp04 a = 1.0f)
121 : hue(h)
122 , saturation(cast<uint01>((s > 1) ? 1 : ((s < 0) ? 0 : s) * 255))
123 , brightness(cast<uint01>((b > 1) ? 1 : ((b < 0) ? 0 : b) * 255))
124 , alpha(cast<uint01>(a * 255))
125 {}
126
134 constexpr HSLColor(fltp08 h, fltp08 s, fltp08 b, fltp08 a = 1.0f)
135 : hue(DEGREES, cast<fltp04>(h))
136 , saturation(cast<uint01>((s > 1) ? 1 : ((s < 0) ? 0 : s) * 255))
137 , brightness(cast<uint01>((b > 1) ? 1 : ((b < 0) ? 0 : b) * 255))
138 , alpha(cast<uint01>(a * 255))
139 {}
140
148 constexpr HSLColor(fltp04 h, fltp04 s, fltp04 b, fltp04 a = 1.0f)
149 : hue(DEGREES, h)
150 , saturation(cast<uint01>((s > 1) ? 1 : ((s < 0) ? 0 : s) * 255))
151 , brightness(cast<uint01>((b > 1) ? 1 : ((b < 0) ? 0 : b) * 255))
152 , alpha(cast<uint01>(a * 255))
153 {}
154
158 constexpr HSLColor(const Vector<4, fltp04>& color)
159 : hue(Angle<HSLAngleType>(DEGREES, color[X]))
160 , saturation(cast<uint01>((color[Y] > 1) ? 1 : ((color[Y] < 0) ? 0 : color[Y]) * 255))
161 , brightness(cast<uint01>((color[Z] > 1) ? 1 : ((color[Z] < 0) ? 0 : color[Z]) * 255))
162 , alpha(cast<uint01>(color[W] * 255))
163 {}
164
168 NDEVR_BASE_API explicit HSLColor(const ACIColor&);
173 NDEVR_BASE_API explicit HSLColor(const RGBColor&);
178 NDEVR_BASE_API explicit HSLColor(const XYZColor&);
183 template<class t_type>
184 t_type getHDeg() const
185 {
186 return cast<t_type>(hue.as<DEGREES>());
187 }
188
192 template<class t_type>
193 void setHDeg(const t_type& val)
194 {
196 }
197
201 uint01 getHI() const
202 {
203 constexpr HSLAngleType den = ((2 * Angle<HSLAngleType>::INDEX_PI) / 256);
204 return cast<uint01>(hue.internal<false>() / den);
205 }
206
210 void setHI(uint01 val)
211 {
212 constexpr HSLAngleType den = ((2 * Angle<HSLAngleType>::INDEX_PI) / 256);
214 }
215
219 fltp04 getBF() const
220 {
221 return cast<fltp04>(brightness) / 255.0f;
222 }
223
227 fltp04 getSF() const
228 {
229 return cast<fltp04>(saturation) / 255.0f;
230 }
231
235 fltp04 getAF() const
236 {
237 return cast<fltp04>(alpha) / 255.0f;
238 }
239
244 bool operator==(const HSLColor& color) const
245 {
246 return hue == color.hue
247 && brightness == color.brightness
248 && saturation == color.saturation
249 && alpha == color.alpha;
250 }
251
256 bool operator!=(const HSLColor& color) const
257 {
258 return hue != color.hue
259 || brightness != color.brightness
260 || saturation != color.saturation
261 || alpha != color.alpha;
262 }
263 };
264 template<> constexpr HSLColor Constant<HSLColor>::Invalid = HSLColor();
265 template<> constexpr HSLColor Constant<HSLColor>::Max = HSLColor(Constant<Angle<HSLAngleType>>::Max, 1.0f, 1.0f, 1.0f);
266 template<> constexpr HSLColor Constant<HSLColor>::Min = HSLColor(Constant<Angle<HSLAngleType>>::Max, 0.0f, 0.0f, 0.0f);
267}
268
269
A color identified by an AutoCAD Color Index (ACI) number from 1 through 255.
Definition ACIColor.h:59
Stores an angle in an optimized internal format with support for efficient trigonometric operations.
Definition Angle.h:83
static constexpr sint04 INDEX_PI
Optimized angle constant representing PI; allows integers to store angles to some degree of accuracy.
Definition Angle.h:305
The core Color class in the NDEVR API.
Definition Color.h:42
A color defined by hue, saturation, and luminosity components.
Definition HSLColor.h:51
constexpr HSLColor(const Angle< HSLAngleType > &h, uint01 s, uint01 b, uint01 a=255)
Constructs an HSLColor from an angle and integer components.
Definition HSLColor.h:79
Angle< HSLAngleType > hue
The hue component, representing the color angle on the color wheel.
Definition HSLColor.h:53
constexpr HSLColor(const Vector< 4, fltp04 > &color)
Constructs an HSLColor from a 4-component float vector (hue degrees, saturation, brightness,...
Definition HSLColor.h:158
constexpr HSLColor()
Constructs a default HSLColor with all components set to invalid.
Definition HSLColor.h:61
void setHI(uint01 val)
Sets the hue component from a uint01 index in the range 0-255.
Definition HSLColor.h:210
fltp04 getAF() const
Gets the alpha component as a normalized float (0.0-1.0).
Definition HSLColor.h:235
constexpr HSLColor(const Angle< HSLAngleType > &h, fltp08 s, fltp08 b, fltp08 a=1.0)
Constructs an HSLColor from an angle and double-precision floating-point components.
Definition HSLColor.h:106
HSLColor(const XYZColor &)
Constructs an HSLColor by converting from an XYZColor.
uint01 brightness
The brightness (luminosity) component, stored as 0-255.
Definition HSLColor.h:55
constexpr HSLColor(fltp04 h, fltp04 s, fltp04 b, fltp04 a=1.0f)
Constructs an HSLColor from single-precision hue in degrees and normalized components.
Definition HSLColor.h:148
constexpr HSLColor(const Angle< HSLAngleType > &h, fltp04 s, fltp04 b, fltp04 a=1.0f)
Constructs an HSLColor from an angle and single-precision floating-point components.
Definition HSLColor.h:120
void setHDeg(const t_type &val)
Sets the hue component from a value in degrees.
Definition HSLColor.h:193
HSLColor(const ACIColor &)
Constructs an HSLColor by converting from an ACIColor.
uint01 getHI() const
Gets the hue component as a uint01 index in the range 0-255.
Definition HSLColor.h:201
uint01 saturation
The saturation component, stored as 0-255.
Definition HSLColor.h:54
constexpr HSLColor(const HSLColor &color)=default
Copy constructor.
constexpr HSLColor(uint01 h, uint01 s, uint01 b, uint01 a=255)
Constructs an HSLColor from integer components, converting hue from a 0-255 range to degrees.
Definition HSLColor.h:92
uint01 alpha
The alpha (opacity) component, stored as 0-255.
Definition HSLColor.h:56
t_type getHDeg() const
Gets the hue component in degrees, converted to the specified type.
Definition HSLColor.h:184
constexpr HSLColor(fltp08 h, fltp08 s, fltp08 b, fltp08 a=1.0f)
Constructs an HSLColor from double-precision hue in degrees and normalized components.
Definition HSLColor.h:134
HSLColor(const RGBColor &)
Constructs an HSLColor by converting from an RGBColor.
bool operator!=(const HSLColor &color) const
Checks inequality between two HSLColor values.
Definition HSLColor.h:256
fltp04 getBF() const
Gets the brightness component as a normalized float (0.0-1.0).
Definition HSLColor.h:219
bool operator==(const HSLColor &color) const
Checks equality between two HSLColor values.
Definition HSLColor.h:244
fltp04 getSF() const
Gets the saturation component as a normalized float (0.0-1.0).
Definition HSLColor.h:227
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:57
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
Forward declaration of HSLColor.
Definition XYZColor.h:55
The primary namespace for the NDEVR SDK.
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
double fltp08
Defines an alias representing an 8 byte floating-point number.
int32_t sint04
-Defines an alias representing a 4 byte, signed integer.
@ DEGREES
Angle measured in degrees (0 to 360 for a full circle).
Definition Angle.h:58
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
sint04 HSLAngleType
The integer type used for HSL hue angle representation.
Definition HSLColor.h:41
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...