API Documentation
Loading...
Searching...
No Matches
HSLColor.h
Go to the documentation of this file.
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;
42 /**----------------------------------------------------------------------------
43 \brief The HSL (Hue, Saturation, Luminosity) color model defines a color space in
44 terms of three constituent components hue, brightness and luminosity
45 // ----------------------------------------------------------------------------*/
46 class HSLColor : public Color
47 {
48 public:
53 public:
60 constexpr HSLColor(const HSLColor& color) = default;
61 constexpr HSLColor(const Angle<HSLAngleType>& h, uint01 s, uint01 b, uint01 a = 255)
62 : hue(h)
63 , saturation(s)
64 , brightness(b)
65 , alpha(a)
66 {}
67
68 constexpr HSLColor(const Angle<HSLAngleType>& h, fltp08 s, fltp08 b, fltp08 a = 1.0)
69 : hue(h)
70 , saturation(cast<uint01>((s > 1) ? 1 : ((s < 0) ? 0 : s) * 255))
71 , brightness(cast<uint01>((b > 1) ? 1 : ((b < 0) ? 0 : b) * 255))
72 , alpha(cast<uint01>(a *255))
73 {}
74
75 constexpr HSLColor(const Angle<HSLAngleType>& h, fltp04 s, fltp04 b, fltp04 a = 1.0f)
76 : hue(h)
77 , saturation(cast<uint01>((s > 1) ? 1 : ((s < 0) ? 0 : s) * 255))
78 , brightness(cast<uint01>((b > 1) ? 1 : ((b < 0) ? 0 : b) * 255))
79 , alpha(cast<uint01>(a * 255))
80 {}
81
82 constexpr HSLColor(fltp08 h, fltp08 s, fltp08 b, fltp08 a = 1.0f)
83 : hue(DEGREES, cast<fltp04>(h))
84 , saturation(cast<uint01>((s > 1) ? 1 : ((s < 0) ? 0 : s) * 255))
85 , brightness(cast<uint01>((b > 1) ? 1 : ((b < 0) ? 0 : b) * 255))
86 , alpha(cast<uint01>(a * 255))
87 {}
88
89 constexpr HSLColor(fltp04 h, fltp04 s, fltp04 b, fltp04 a = 1.0f)
90 : hue(DEGREES, h)
91 , saturation(cast<uint01>((s > 1) ? 1 : ((s < 0) ? 0 : s) * 255))
92 , brightness(cast<uint01>((b > 1) ? 1 : ((b < 0) ? 0 : b) * 255))
93 , alpha(cast<uint01>(a * 255))
94 {}
95 constexpr HSLColor(const Vector<4, fltp04>& color)
96 : hue(Angle<HSLAngleType>(DEGREES, color[X]))
97 , saturation(cast<uint01>((color[Y] > 1) ? 1 : ((color[Y] < 0) ? 0 : color[Y]) * 255))
98 , brightness(cast<uint01>((color[Z] > 1) ? 1 : ((color[Z] < 0) ? 0 : color[Z]) * 255))
99 , alpha(cast<uint01>(color[W] * 255))
100 {}
104 fltp04 getBF() const
105 {
106 return cast<fltp04>(brightness) / 255.0f;
107 }
108 fltp04 getSF() const
109 {
110 return cast<fltp04>(saturation) / 255.0f;
111 }
112 fltp04 getAF() const
113 {
114 return cast<fltp04>(alpha) / 255.0f;
115 }
116
117 };
119 template<> constexpr HSLColor Constant<HSLColor>::Max = HSLColor(Constant<Angle<HSLAngleType>>::Max, 1.0f, 1.0f, 1.0f);
120 template<> constexpr HSLColor Constant<HSLColor>::Min = HSLColor(Constant<Angle<HSLAngleType>>::Max, 0.0f, 0.0f, 0.0f);
121}
122
123
#define NDEVR_BASE_API
Definition DLLInfo.h:78
ACI colors are the standard colors used in AutoCAD-based products. Each color is identified by an ACI...
Definition ACIColor.h:58
The primary angle storage class for this API. Stores an angle in an optimized format.
Definition StringStream.h:408
Definition Color.h:36
The HSL (Hue, Saturation, Luminosity) color model defines a color space in.
Definition HSLColor.h:47
uint01 alpha
Definition HSLColor.h:52
uint01 brightness
Definition HSLColor.h:51
uint01 saturation
Definition HSLColor.h:50
Angle< HSLAngleType > hue
Definition HSLColor.h:49
fltp04 getBF() const
Definition HSLColor.h:104
fltp04 getAF() const
Definition HSLColor.h:112
constexpr HSLColor(const Angle< HSLAngleType > &h, fltp04 s, fltp04 b, fltp04 a=1.0f)
Definition HSLColor.h:75
constexpr HSLColor(const Angle< HSLAngleType > &h, uint01 s, uint01 b, uint01 a=255)
Definition HSLColor.h:61
NDEVR_BASE_API HSLColor(const RGBColor &)
NDEVR_BASE_API HSLColor(const XYZColor &)
fltp04 getSF() const
Definition HSLColor.h:108
constexpr HSLColor(const Vector< 4, fltp04 > &color)
Definition HSLColor.h:95
constexpr HSLColor(fltp08 h, fltp08 s, fltp08 b, fltp08 a=1.0f)
Definition HSLColor.h:82
constexpr HSLColor()
Definition HSLColor.h:54
constexpr HSLColor(const HSLColor &color)=default
constexpr HSLColor(fltp04 h, fltp04 s, fltp04 b, fltp04 a=1.0f)
Definition HSLColor.h:89
constexpr HSLColor(const Angle< HSLAngleType > &h, fltp08 s, fltp08 b, fltp08 a=1.0)
Definition HSLColor.h:68
NDEVR_BASE_API HSLColor(const ACIColor &)
Represents a color in the RGB space with optional alpha transparency.
Definition RGBColor.h:53
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
In opposition to the previous models, the CIE XYZ model defines an absolute color space....
Definition XYZColor.h:50
Definition ACIColor.h:37
int32_t sint04
-Defines an alias representing a 4 byte, signed integer. -Can represent exact integer values -2147483...
Definition BaseValues.hpp:62
sint04 HSLAngleType
Definition HSLColor.h:41
float fltp04
Defines an alias representing a 4 byte floating-point number.
Definition BaseValues.hpp:125
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:78
@ DEGREES
Definition Angle.h:62
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:379
@ Y
Definition BaseValues.hpp:165
@ X
Definition BaseValues.hpp:163
@ Z
Definition BaseValues.hpp:167
@ W
Definition BaseValues.hpp:169
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:146
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved.
Definition BaseValues.hpp:230