2018-09-06 01:53:11 +00:00
|
|
|
#ifndef COLOR_H
|
|
|
|
|
2018-09-06 02:26:54 +00:00
|
|
|
#include "util.h"
|
2018-09-06 01:53:11 +00:00
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
|
|
|
|
struct ColorU32
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2018-09-06 02:26:54 +00:00
|
|
|
uint8_t b, g, r, a;
|
2018-09-06 01:53:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t u32;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-09-06 02:26:54 +00:00
|
|
|
struct ColorF32
|
|
|
|
{
|
|
|
|
float b, g, r, a;
|
|
|
|
|
|
|
|
static inline ColorU32 ConvertToU32(ColorF32 c)
|
|
|
|
{
|
|
|
|
ColorU32 result;
|
|
|
|
|
|
|
|
result.b = (uint8_t)(c.b * 255);
|
|
|
|
result.g = (uint8_t)(c.g * 255);
|
|
|
|
result.r = (uint8_t)(c.r * 255);
|
|
|
|
result.a = (uint8_t)(c.a * 255);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// OPERATORS
|
|
|
|
// c1 + c2
|
|
|
|
inline ColorF32 operator+(ColorF32 c1, ColorF32 c2)
|
|
|
|
{
|
|
|
|
ColorF32 result;
|
|
|
|
|
|
|
|
result.b = MIN((c1.b + c2.b), 1.0f);
|
|
|
|
result.g = MIN((c1.g + c2.g), 1.0f);
|
|
|
|
result.r = MIN((c1.r + c2.r), 1.0f);
|
|
|
|
result.a = MIN((c1.a + c2.a), 1.0f);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// c1 += c2
|
|
|
|
inline ColorF32 &operator+=(ColorF32 &c1, ColorF32 c2)
|
|
|
|
{
|
|
|
|
c1 = c1 + c2;
|
|
|
|
|
|
|
|
return(c1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// c * f
|
|
|
|
inline ColorF32 operator*(ColorF32 c, float f)
|
|
|
|
{
|
|
|
|
ColorF32 result;
|
|
|
|
|
|
|
|
result.b = MIN((f * c.b), 1.0f);
|
|
|
|
result.g = MIN((f * c.g), 1.0f);
|
|
|
|
result.r = MIN((f * c.r), 1.0f);
|
|
|
|
result.a = MIN((f * c.a), 1.0f);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2018-09-06 01:53:11 +00:00
|
|
|
|
2018-09-11 02:51:59 +00:00
|
|
|
// f * c
|
|
|
|
inline ColorF32 operator*(float f, ColorF32 c)
|
|
|
|
{
|
|
|
|
ColorF32 result;
|
|
|
|
|
|
|
|
result = c * f;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-09-06 01:53:11 +00:00
|
|
|
#define COLOR_H
|
|
|
|
#endif
|
|
|
|
|