4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 : red(0), green(0), blue(0), alpha(1.0)
33 Color(float red, float green, float blue, float alpha = 1.0)
34 : red(red), green(green), blue(blue), alpha(alpha)
40 Color(const std::vector<float>& vals)
42 assert(vals.size() >= 3);
55 bool operator==(const Color& other) const
57 return red == other.red && green == other.green && blue == other.blue
58 && alpha == other.alpha;
61 void check_color_ranges()
63 if(red < 0 || red > 1.0 || green < 0 || green > 1.0
64 || blue < 0 || blue > 1.0
65 || alpha < 0 || alpha > 1.0)
66 log_warning << "color value out of range: " << red << ", " << green << ", " << blue << ", " << alpha << std::endl;
69 float greyscale() const
71 return red * 0.30 + green * 0.59 + blue * 0.11;
74 bool operator < (const Color& other) const
76 return greyscale() < other.greyscale();
79 float red, green, blue, alpha;
81 static const Color BLACK;
82 static const Color RED;
83 static const Color GREEN;
84 static const Color BLUE;
85 static const Color CYAN;
86 static const Color MAGENTA;
87 static const Color YELLOW;
88 static const Color WHITE;