NDEVR
API Documentation
HSBColor.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: HSBColor
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Angle.h>
34#include <NDEVR/Vector.h>
35#include <NDEVR/Buffer.h>
36namespace NDEVR
37{
38 class RGBColor;
39 class ACIColor;
40 class LABColor;
41 class XYZColor;
62 {
63 public:
68 public:
73 {}
74
81 constexpr HSBColor(const Angle<HSBAngleType>& h, uint01 s, uint01 b, uint01 a = 255)
82 : hue(h)
83 , saturation(s)
84 , brightness(b)
85 , alpha(a)
86 {}
87
95 constexpr HSBColor(const Angle<HSBAngleType>& h, fltp08 s, fltp08 b, fltp08 a = 1.0)
96 : hue(h)
97 , saturation(cast<uint01>((s > 1) ? 1 : ((s < 0) ? 0 : s) * 255))
98 , brightness(cast<uint01>((b > 1) ? 1 : ((b < 0) ? 0 : b) * 255))
99 , alpha(cast<uint01>(a *255))
100 {}
101
109 constexpr HSBColor(const Angle<HSBAngleType>& h, fltp04 s, fltp04 b, fltp04 a = 1.0f)
110 : hue(h)
111 , saturation(cast<uint01>((s > 1) ? 1 : ((s < 0) ? 0 : s) * 255))
112 , brightness(cast<uint01>((b > 1) ? 1 : ((b < 0) ? 0 : b) * 255))
113 , alpha(cast<uint01>(a * 255))
114 {}
115
123 constexpr HSBColor(fltp08 h, fltp08 s, fltp08 b, fltp08 a = 1.0f)
125 , saturation(cast<uint01>((s > 1) ? 1 : ((s < 0) ? 0 : s) * 255))
126 , brightness(cast<uint01>((b > 1) ? 1 : ((b < 0) ? 0 : b) * 255))
127 , alpha(cast<uint01>(a * 255))
128 {}
129
137 constexpr HSBColor(fltp04 h, fltp04 s, fltp04 b, fltp04 a = 1.0f)
138 : hue(Angle<sint01>(DEGREES, h))
139 , saturation(cast<uint01>((s > 1) ? 1 : ((s < 0) ? 0 : s) * 255))
140 , brightness(cast<uint01>((b > 1) ? 1 : ((b < 0) ? 0 : b) * 255))
141 , alpha(cast<uint01>(a * 255))
142 {}
143
147 NDEVR_BASE_API explicit HSBColor(const Vector<4, fltp04>& color);
152 NDEVR_BASE_API explicit HSBColor(const ACIColor&);
157 NDEVR_BASE_API explicit HSBColor(const RGBColor&);
162 NDEVR_BASE_API explicit HSBColor(const XYZColor&);
167 template<class t_type>
168 t_type getHDeg() const
169 {
170 return cast<t_type>(hue.as<DEGREES>());
171 }
172
176 template<class t_type>
177 void setHDeg(const t_type& val)
178 {
180 }
181
185 fltp04 getBF() const
186 {
187 return cast<fltp04>(brightness) / 255.0f;
188 }
189
193 fltp04 getBS() const
194 {
195 return cast<fltp04>(saturation) / 255.0f;
196 }
197
201 fltp04 getAF() const
202 {
203 return cast<fltp04>(alpha) / 255.0f;
204 }
205
210 bool operator==(const HSBColor& color) const
211 {
212 return hue == color.hue
213 && brightness == color.brightness
214 && saturation == color.saturation
215 && alpha == color.alpha;
216 }
217
222 bool operator!=(const HSBColor& color) const
223 {
224 return hue != color.hue
225 || brightness != color.brightness
226 || saturation != color.saturation
227 || alpha != color.alpha;
228 }
229
237 NDEVR_BASE_API static HSBColor ConvertColor(const LABColor& current_color, const PrimitiveAlignedBuffer<std::pair<LABColor, LABColor>, 32>& pairs, bool preserve_brightness, bool preserve_alpha);
238 };
239 template<>
240 constexpr HSBColor Constant<HSBColor>::Invalid = HSBColor(Constant<Angle<HSBAngleType>>::Invalid, Constant<uint01>::Invalid, Constant<uint01>::Invalid, Constant<uint01>::Invalid);
241 template<>
242 constexpr HSBColor Constant<HSBColor>::Max = HSBColor(Constant<Angle<HSBAngleType>>::Max, Constant<uint01>::Max, Constant<uint01>::Max, Constant<uint01>::Max);
243 template<>
244 constexpr HSBColor Constant<HSBColor>::Min = HSBColor(Constant<Angle<HSBAngleType>>::Min, Constant<uint01>::Min, Constant<uint01>::Min, Constant<uint01>::Min);
245}
246
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
A color defined by hue, saturation, and brightness components.
Definition HSBColor.h:62
static HSBColor ConvertColor(const LABColor &current_color, const PrimitiveAlignedBuffer< std::pair< LABColor, LABColor >, 32 > &pairs, bool preserve_brightness, bool preserve_alpha)
Converts a LABColor to an HSBColor using a set of LAB color mapping pairs.
uint01 saturation
The saturation component, ranging from 0 to 255.
Definition HSBColor.h:65
bool operator!=(const HSBColor &color) const
Checks inequality between two HSBColor instances.
Definition HSBColor.h:222
HSBColor()
Default constructor.
Definition HSBColor.h:72
HSBColor(const ACIColor &)
Constructs an HSBColor by converting from an ACIColor.
void setHDeg(const t_type &val)
Sets the hue component from a value in degrees.
Definition HSBColor.h:177
fltp04 getBF() const
Gets the brightness as a normalized float (0.0-1.0).
Definition HSBColor.h:185
HSBColor(const XYZColor &)
Constructs an HSBColor by converting from an XYZColor.
fltp04 getBS() const
Gets the saturation as a normalized float (0.0-1.0).
Definition HSBColor.h:193
Angle< HSBAngleType > hue
The hue component as an angle, ranging from 0 to 360 degrees.
Definition HSBColor.h:64
HSBColor(const Vector< 4, fltp04 > &color)
Constructs an HSBColor from a 4-component floating-point vector.
constexpr HSBColor(fltp04 h, fltp04 s, fltp04 b, fltp04 a=1.0f)
Constructs an HSBColor from raw single-precision values with hue in degrees.
Definition HSBColor.h:137
constexpr HSBColor(const Angle< HSBAngleType > &h, fltp08 s, fltp08 b, fltp08 a=1.0)
Constructs an HSBColor from double-precision floating-point values.
Definition HSBColor.h:95
uint01 brightness
The brightness component, ranging from 0 to 255.
Definition HSBColor.h:66
constexpr HSBColor(const Angle< HSBAngleType > &h, uint01 s, uint01 b, uint01 a=255)
Constructs an HSBColor from integer component values.
Definition HSBColor.h:81
constexpr HSBColor(fltp08 h, fltp08 s, fltp08 b, fltp08 a=1.0f)
Constructs an HSBColor from raw double-precision values with hue in degrees.
Definition HSBColor.h:123
fltp04 getAF() const
Gets the alpha as a normalized float (0.0-1.0).
Definition HSBColor.h:201
uint01 alpha
The alpha (opacity) component, ranging from 0 (transparent) to 255 (opaque).
Definition HSBColor.h:67
constexpr HSBColor(const Angle< HSBAngleType > &h, fltp04 s, fltp04 b, fltp04 a=1.0f)
Constructs an HSBColor from single-precision floating-point values.
Definition HSBColor.h:109
HSBColor(const RGBColor &)
Constructs an HSBColor by converting from an RGBColor.
t_type getHDeg() const
Gets the hue component in degrees, cast to the requested type.
Definition HSBColor.h:168
bool operator==(const HSBColor &color) const
Checks equality between two HSBColor instances.
Definition HSBColor.h:210
Forward declaration of the NDEVR translated string class.
Definition LABColor.h:65
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
sint04 HSBAngleType
Integer type used for storing HSB hue angle values.
Definition HSBColor.h:43
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
int8_t sint01
-Defines an alias representing a 1 byte, signed integer.
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...