12 constexpr Color() noexcept : r{ 0 }, g{ 0 }, b{ 0 }, a{ 255 } {}
13 explicit Color( NoInit )
noexcept {}
14 constexpr Color(
int r,
int g,
int b,
int a ) noexcept : r{uint8_t(r)}, g{uint8_t(g)}, b{uint8_t(b)}, a{uint8_t(a)} {}
15 constexpr Color(
int r,
int g,
int b ) noexcept : r{uint8_t(r)}, g{uint8_t(g)}, b{uint8_t(b)}, a{255} {}
16 constexpr Color(
float r,
float g,
float b,
float a ) noexcept :
17 r{ r > 1 ? uint8_t( 255 ) : ( r < 0 ? uint8_t( 0 ) : uint8_t( r * 255 ) )},
18 g{ g > 1 ? uint8_t( 255 ) : ( g < 0 ? uint8_t( 0 ) : uint8_t( g * 255 ) )},
19 b{ b > 1 ? uint8_t( 255 ) : ( b < 0 ? uint8_t( 0 ) : uint8_t( b * 255 ) )},
20 a{ a > 1 ? uint8_t( 255 ) : ( a < 0 ? uint8_t( 0 ) : uint8_t( a * 255 ) )} {}
21 constexpr Color(
float r,
float g,
float b ) noexcept :
Color( r, g, b, 1.f ) {}
23 constexpr unsigned int getUInt32() const noexcept {
return (
unsigned( r ) ) + ( unsigned( g ) << 8 ) + (
unsigned( b ) << 16 ) + (
unsigned( a ) << 24 ); }
25 static constexpr Color white() noexcept {
return Color( 255,255,255,255 ); }
26 static constexpr Color black() noexcept {
return Color( 0, 0, 0, 255 ); }
27 static constexpr Color gray() noexcept {
return Color( 127, 127, 127, 255 ); }
28 static constexpr Color red() noexcept {
return Color( 255, 0, 0, 255 ); }
29 static constexpr Color green() noexcept {
return Color( 0, 255, 0, 255 ); }
30 static constexpr Color blue() noexcept {
return Color( 0, 0, 255, 255 ); }
31 static constexpr Color yellow() noexcept {
return Color( 255, 255, 0, 255 ); }
32 static constexpr Color brown() noexcept {
return Color( 135, 74, 43, 255 ); }
33 static constexpr Color purple() noexcept {
return Color( 128, 0, 128, 255 ); }
37 static constexpr uint8_t
valToUint8( T val )
noexcept
39 if constexpr ( std::is_same_v<T, uint8_t> )
43 else if constexpr ( std::is_integral_v<T> )
45 return val >= 255 ? uint8_t( 255 ) : ( val <= 0 ? uint8_t( 0 ) : uint8_t( val ) );
49 return val >= T( 1 ) ? uint8_t( 255 ) : ( val <= T( 0 ) ? uint8_t( 0 ) : uint8_t( val * 255 ) );
54 explicit constexpr Color(
const Vector3<T>& vec ) noexcept :
62 explicit constexpr Color(
const Vector4<T>& vec ) noexcept :
70 explicit constexpr operator Vector4<T>() const noexcept
72 if constexpr ( std::is_integral_v<T> )
74 return Vector4<T>( T( r ), T( g ), T( b ), T( a ) );
78 return Vector4<T>( T( r ), T( g ), T( b ), T( a ) ) / T( 255 );
82 const uint8_t& operator [](
int e )
const {
return *( &r + e ); }
83 uint8_t& operator [](
int e ) {
return *( &r + e ); }
85 Color& operator += (
const Color& other ) { *
this =
Color( Vector4i( *
this ) + Vector4i( other ) );
return *
this; }
86 Color& operator -= (
const Color& other ) { *
this =
Color( Vector4i( *
this ) - Vector4i( other ) );
return *
this; }
87 Color& operator *= (
float m ) { *
this =
Color( m * Vector4f( *
this ) );
return *
this; }
88 Color& operator /= (
float m ) {
return *
this *= 1.0f / m; }
92 return Color( r, g, b, uint8_t( std::clamp( m * a, 0.0f , 255.0f ) ) );
98 return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
128 return b * ( 1 / a );
138struct std::hash<
MR::Color>
140 std::uint32_t operator()(
MR::Color c )
const noexcept
143 static_assert(
sizeof( r ) ==
sizeof( c ) );
144 std::memcpy( &r, &c,
sizeof( r ) );
#define MRMESH_API
Definition MRMeshFwd.h:80
Definition MRCameraOrientationPlugin.h:8
bool operator!=(const Color &a, const Color &b)
Definition MRMesh/MRColor.h:101
MRMESH_API Color blend(const Color &front, const Color &back)
Definition MRMesh/MRColor.h:9
static unsafe bool operator==(MR.Color a, MR.Color b)
static MR.Color transparent()
static unsafe MR.Color operator*(float a, MR.Color b)
static byte valToUint8(int val)
static unsafe MR.Color operator-(MR.Color a, in MR.Color b)
readonly unsafe uint getUInt32()
static unsafe MR.Color operator+(MR.Color a, in MR.Color b)
readonly unsafe MR.Color scaledAlpha(float m)
static unsafe MR.Color operator/(MR.Color b, float a)