33#include <Pt/Gfx/Api.h>
71 Color(
const Color& color) =
default;
77 explicit Color(
const uint8_t* base)
80 std::memcpy( &_value, base,
sizeof(
uint32_t) );
91 explicit Color(
const ColorF& c);
93 Color& operator=(
const Color& color) =
default;
95 Color& operator=(
const ColorF& c);
110 _value = (_value & 0x00FFFFFF) | (
uint32_t(a) << 24);
115 return (_value & 0x00FF0000) >> 16;
120 _value = (_value & 0xFF00FFFF) | (
uint32_t(r) << 16);
125 return (_value & 0x0000FF00) >> 8;
130 _value = (_value & 0xFFFF00FF) | (
uint32_t(g) << 8);
135 return _value & 0x000000FF;
140 _value = (_value & 0xFFFFFF00) |
uint32_t(b);
148 bool operator==(
const Color& other)
const
149 {
return _value == other._value; }
151 bool operator!=(
const Color& other)
const
152 {
return _value != other._value; }
182 ColorF(
const ColorF&) =
default;
184 explicit ColorF(
const Color& c);
186 ColorF& operator=(
const ColorF&) =
default;
188 ColorF& operator=(
const Color& c);
190 ColorF(
float a,
float r,
float g,
float b)
197 ColorF(
float r,
float g,
float b)
209 void setAlpha(
float c)
229 void setGreen(
float c)
239 void setBlue(
float c)
244 ColorF toGray()
const
246 const float s = 0.299f * _r + 0.587f * _g + 0.114f * _b;
247 return ColorF(_a, s, s, s);
254 return c * (1.f / 255.f);
286inline Color::Color(
const ColorF& c)
287: _value( (
Pt::
uint32_t(ColorF::toChannel8(c.alpha())) << 24) |
288 (
Pt::
uint32_t(ColorF::toChannel8(c.red())) << 16) |
289 (
Pt::
uint32_t(ColorF::toChannel8(c.green())) << 8) |
305inline ColorF::ColorF(
const Color& c)
306: _r(toChannelF(c.red()))
307, _g(toChannelF(c.green()))
308, _b(toChannelF(c.blue()))
309, _a(toChannelF(c.alpha()))
Floating-point RGBA color.
Definition Color.h:173
static float toChannelF(Pt::uint8_t c)
Converts an 8-bit channel to the unit interval.
Definition Color.h:252
static Pt::uint8_t toChannel8(float c)
Converts a unit-interval channel to 8-bit.
Definition Color.h:261
8-bit ARGB color.
Definition Color.h:65
uint_type uint32_t
Unsigned 32-bit integer type.
Definition Api-Types.h:52
uint_type uint8_t
Unsigned 8-bit integer type.
Definition Api-Types.h:24
Graphics and imaging services.
Definition Api-Argb32Image.h:12
Core module.
Definition Allocator.h:33