1 #ifndef SDK_COLOR_BASE_TYPES_HELPERS_H_
11 #define SDK_COLOR_BASE_TYPES_HELPERS_H_
28 r = src_clr.
r,
g = src_clr.
g,
b = src_clr.
b,
a = src_clr.
a;
32 r = src_clr.
r,
g = src_clr.
g,
b = src_clr.
b,
a = src_clr.
a;
35 explicit ColorF(
float init_r,
float init_g,
float init_b,
36 float init_a) noexcept {
37 r = init_r,
g = init_g,
b = init_b,
a = init_a;
40 explicit ColorF(
double init_r,
double init_g,
double init_b,
41 double init_a) noexcept {
42 r =
static_cast<float>(init_r),
g =
static_cast<float>(init_g);
43 b =
static_cast<float>(init_b),
a =
static_cast<float>(init_a);
46 explicit ColorF(SDKUInt32 argb) noexcept {
47 a =
static_cast<float>((argb & 0xFF000000)>> 24) / 255.f;
48 r =
static_cast<float>((argb & 0x00FF0000)>> 16) / 255.f;
49 g =
static_cast<float>((argb & 0x0000FF00)>> 8) / 255.f;
50 b =
static_cast<float>(argb & 0x000000FF) / 255.f;
53 inline bool is_valid()
const
55 return a >= 0.0f &&
a <= 1.0f &&
r >= 0.0f &&
r <= 1.0f
56 &&
g >= 0.0f &&
g <= 1.0f &&
b >= 0.0f &&
b <= 1.0f;
60 const ColorF& operator=(
const ColorF& src_clr) noexcept {
61 r = src_clr.
r,
g = src_clr.
g,
b = src_clr.
b,
a = src_clr.
a;
65 r = src_clr.
r,
g = src_clr.
g,
b = src_clr.
b,
a = src_clr.
a;
72 return *
static_cast<const SDKColorF*
>(
this);
74 SDKUInt32 get_argb()
const noexcept {
75 SDKUInt8 r8 =
static_cast<SDKUInt8
>(
r * 255.0);
76 SDKUInt8 g8 =
static_cast<SDKUInt8
>(
g * 255.0);
77 SDKUInt8 b8 =
static_cast<SDKUInt8
>(
b * 255.0);
78 SDKUInt8 a8 =
static_cast<SDKUInt8
>(
a * 255.0);
83 void get_argb(SDKUInt8* r8, SDKUInt8* g8, SDKUInt8* b8,
84 SDKUInt8* a8)
const noexcept {
86 *r8 =
static_cast<SDKUInt8
>(
r * 255.0);
88 *g8 =
static_cast<SDKUInt8
>(
g * 255.0);
90 *b8 =
static_cast<SDKUInt8
>(
b * 255.0);
92 *a8 =
static_cast<SDKUInt8
>(
a * 255.0);
95 bool operator!=(
const ColorF& clr)
const noexcept {
96 return !operator==(clr);
98 bool operator!=(
const SDKColorF& clr)
const noexcept {
99 return !operator==(clr);
101 bool operator==(
const ColorF& clr)
const noexcept {
102 return operator==(clr.get());
104 bool operator==(
const SDKColorF& clr)
const noexcept {
105 if (fabs(
r - clr.
r) <= FLT_EPSILON && fabs(
g - clr.
g) <= FLT_EPSILON &&
106 fabs(
b - clr.
b) <= FLT_EPSILON && fabs(
a - clr.
a) <= FLT_EPSILON)
111 static SDKUInt32
ARGB(SDKUInt8 _r, SDKUInt8 _g, SDKUInt8 _b, SDKUInt8 _a) {
112 return ((_a << 24) | (_r << 16) | (_g << 8) | _b);
115 static SDKUInt32
RGBA(SDKUInt8 _r, SDKUInt8 _g, SDKUInt8 _b, SDKUInt8 _a) {
116 return ((_r << 24) | (_g << 16) | (_b << 8) | _a);
119 static SDKUInt32
ABGR(SDKUInt8 _r, SDKUInt8 _g, SDKUInt8 _b, SDKUInt8 _a) {
120 return ((_a << 24) | (_b << 16) | (_g << 8) | _r);
123 static void FromABGR(SDKUInt32 argb, SDKUInt8* _r, SDKUInt8* _g, SDKUInt8* _b,
126 *_r =
static_cast<SDKUInt8
>(argb & 0x000000FF);
128 *_g =
static_cast<SDKUInt8
>((argb & 0x0000FF00) >> 8);
130 *_b =
static_cast<SDKUInt8
>((argb & 0x00FF0000) >> 16);
132 *_a =
static_cast<SDKUInt8
>((argb & 0x00FF0000) >> 24);
136 return ColorF(-1.0, -1.0, -1.0, -1.0);
142 #endif // SDK_COLOR_BASE_TYPES_HELPERS_H_