2014-04-10 10:53:35 -07:00
|
|
|
|
|
|
|
#ifndef COLOR_H
|
|
|
|
#define COLOR_H
|
|
|
|
|
2014-04-24 06:59:41 -07:00
|
|
|
#include <string>
|
|
|
|
|
2014-04-10 10:53:35 -07:00
|
|
|
struct Color {
|
2014-05-04 05:32:57 -07:00
|
|
|
Color(): r(0), g(0), b(0), a(0) {};
|
2014-04-24 06:59:41 -07:00
|
|
|
Color(uint32_t c): r((c >> 16) & 0xff), g((c >> 8) & 0xff), b((c >> 0) & 0xff ), a((c >> 24) & 0xff) {};
|
|
|
|
Color(uint8_t r, uint8_t g, uint8_t b): r(r), g(g), b(b), a(0xff) {};
|
2014-04-10 10:53:35 -07:00
|
|
|
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a): r(r), g(g), b(b), a(a) {};
|
2015-02-14 23:44:44 -08:00
|
|
|
Color(std::string s, int alpha = 1);
|
2014-04-12 16:18:34 -07:00
|
|
|
Color &operator=(const Color &c);
|
|
|
|
unsigned to_uint() const { return (unsigned(a) << 24) + (unsigned(r) << 16) + (unsigned(g) << 8) + unsigned(b); }
|
2014-05-08 05:21:58 -07:00
|
|
|
//libgd treats 127 as transparent, and 0 as opaque ...
|
|
|
|
int to_libgd() const { return (((0xff - int(a)) >> 1) << 24) + (int(r) << 16) + (int(g) << 8) + int(b); }
|
2014-04-10 10:53:35 -07:00
|
|
|
uint8_t r;
|
|
|
|
uint8_t g;
|
|
|
|
uint8_t b;
|
|
|
|
uint8_t a;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ColorEntry {
|
2016-01-05 03:16:19 -08:00
|
|
|
enum flags {
|
|
|
|
FlagNone = 0x00,
|
2016-01-05 03:16:29 -08:00
|
|
|
FlagIgnore = 0x01,
|
2016-01-05 03:16:33 -08:00
|
|
|
FlagAir = 0x02,
|
2016-01-05 03:16:19 -08:00
|
|
|
};
|
|
|
|
ColorEntry(): r(0), g(0), b(0), a(0), t(0), f(0) {};
|
|
|
|
ColorEntry(uint8_t r, uint8_t g, uint8_t b, uint8_t a, uint8_t t, uint8_t f): r(r), g(g), b(b), a(a), t(t), f(f) {};
|
2014-04-10 10:53:35 -07:00
|
|
|
inline Color to_color() const { return Color(r, g, b, a); }
|
|
|
|
uint8_t r;
|
|
|
|
uint8_t g;
|
|
|
|
uint8_t b;
|
|
|
|
uint8_t a;
|
|
|
|
uint8_t t;
|
2016-01-05 03:16:19 -08:00
|
|
|
uint8_t f;
|
2014-04-10 10:53:35 -07:00
|
|
|
};
|
|
|
|
|
2014-04-12 16:18:34 -07:00
|
|
|
inline Color &Color::operator=(const Color &c)
|
2014-04-10 10:53:35 -07:00
|
|
|
{
|
2014-04-12 16:18:34 -07:00
|
|
|
r = c.r;
|
|
|
|
g = c.g;
|
|
|
|
b = c.b;
|
|
|
|
a = c.a;
|
|
|
|
return *this;
|
2014-04-10 10:53:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // COLOR_H
|