17 #ifndef HEADER_SUPERTUX_VIDEO_COLOR_HPP 18 #define HEADER_SUPERTUX_VIDEO_COLOR_HPP 24 #include <SDL_image.h> 41 Color validate()
const {
return Color(r, g, b, a); }
59 static const Color BLACK;
60 static const Color RED;
61 static const Color GREEN;
62 static const Color BLUE;
63 static const Color CYAN;
64 static const Color MAGENTA;
65 static const Color YELLOW;
66 static const Color WHITE;
69 static Color from_rgb888(uint8_t r, uint8_t g, uint8_t b)
71 return Color(static_cast<float>(r) / 255.0f,
72 static_cast<float>(g) / 255.0f,
73 static_cast<float>(b) / 255.0f);
76 static Color from_rgba8888(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255)
78 return Color(static_cast<float>(r) / 255.0f,
79 static_cast<float>(g) / 255.0f,
80 static_cast<float>(b) / 255.0f,
81 static_cast<float>(a) / 255.0f);
84 static Color from_linear(
float r,
float g,
float b,
float a = 1.0f)
86 return Color(add_gamma(r), add_gamma(g), add_gamma(b), a);
90 static float add_gamma(
float x) {
return powf(x, 1.0f / 2.2f); }
91 static float remove_gamma(
float x) {
return powf(x, 2.2f); }
96 Color(
float red_,
float green_,
float blue_,
float alpha_ = 1.0);
98 Color(
const std::vector<float>& vals);
100 bool operator==(
const Color& other)
const;
101 bool operator!=(
const Color& other)
const;
103 float greyscale()
const;
106 Color multiply_linearly(
float v)
const;
108 bool operator < (
const Color& other)
const;
110 std::vector<float> toVector();
112 inline uint8_t r8()
const {
return static_cast<uint8_t
>(255.0f * red); }
113 inline uint8_t g8()
const {
return static_cast<uint8_t
>(255.0f * green); }
114 inline uint8_t b8()
const {
return static_cast<uint8_t
>(255.0f * blue); }
115 inline uint8_t a8()
const {
return static_cast<uint8_t
>(255.0f * alpha); }
117 inline uint32_t rgba()
const 119 return ((static_cast<uint32_t>(a8()) << 24u) |
120 (static_cast<uint32_t>(b8()) << 16u) |
121 (static_cast<uint32_t>(g8()) << 8u) |
122 (static_cast<uint32_t>(r8()) << 0u));
128 return std::to_string(red) +
" " + std::to_string(green) +
" " + std::to_string(blue);
131 SDL_Color to_sdl_color()
const 133 return { r8(), g8(), b8(), a8() };
148 float red, green, blue, alpha;
std::string to_string() const
Return a human-readable string representation for this color.
Definition: color.hpp:126