4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de> //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include <unison/video/Color.hpp>
32 : red(0), green(0), blue(0), alpha(1.0)
34 Color(float red, float green, float blue, float alpha = 1.0)
35 : red(red), green(green), blue(blue), alpha(alpha)
41 Color(const std::vector<float>& vals)
43 assert(vals.size() >= 3);
56 bool operator==(const Color& other) const
58 return red == other.red && green == other.green && blue == other.blue
59 && alpha == other.alpha;
62 void check_color_ranges()
64 if(red < 0 || red > 1.0 || green < 0 || green > 1.0
65 || blue < 0 || blue > 1.0
66 || alpha < 0 || alpha > 1.0)
67 log_warning << "color value out of range: " << red << ", " << green << ", " << blue << ", " << alpha << std::endl;
70 float greyscale() const
72 return red * 0.30 + green * 0.59 + blue * 0.11;
75 bool operator < (const Color& other) const
77 return greyscale() < other.greyscale();
80 Unison::Video::Color to_unison_color() const
82 Unison::Video::Color color;
83 color.red = (unsigned char) (red * 0xff);
84 color.green = (unsigned char) (green * 0xff);
85 color.blue =(unsigned char) (blue * 0xff);
86 color.alpha = (unsigned char) (alpha * 0xff);
90 float red, green, blue, alpha;
92 static const Color BLACK;
93 static const Color RED;
94 static const Color GREEN;
95 static const Color BLUE;
96 static const Color CYAN;
97 static const Color MAGENTA;
98 static const Color YELLOW;
99 static const Color WHITE;