68 : myRed(0), myGreen(0), myBlue(0), myAlpha(0) {}
83 RGBColor::set(
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a) {
93 if (col == RGBColor::RED) {
96 if (col == RGBColor::GREEN) {
99 if (col == RGBColor::BLUE) {
102 if (col == RGBColor::YELLOW) {
103 return os <<
"yellow";
105 if (col == RGBColor::CYAN) {
108 if (col == RGBColor::MAGENTA) {
109 return os <<
"magenta";
111 if (col == RGBColor::ORANGE) {
112 return os <<
"orange";
114 if (col == RGBColor::WHITE) {
115 return os <<
"white";
117 if (col == RGBColor::BLACK) {
118 return os <<
"black";
120 if (col == RGBColor::GREY) {
123 os << static_cast<int>(col.
myRed) <<
"," 124 << static_cast<int>(col.
myGreen) <<
"," 125 <<
static_cast<int>(col.
myBlue);
127 os <<
"," <<
static_cast<int>(col.
myAlpha);
148 const unsigned char r = (
unsigned char)(255 - (
int)
myRed);
149 const unsigned char g = (
unsigned char)(255 - (
int)
myGreen);
150 const unsigned char b = (
unsigned char)(255 - (
int)
myBlue);
158 const unsigned char red = (
unsigned char)(
MIN2(
MAX2(
myRed + change, 0), 255));
161 int changed = ((int)red - (
int)
myRed) + ((
int)blue - (int)
myBlue) + ((int)green - (
int)
myGreen);
163 if (changed == toChange * change) {
165 }
else if (changed == 0) {
168 const int maxedColors = (red !=
myRed + change ? 1 : 0) + (blue != myBlue + change ? 1 : 0) + (green !=
myGreen + change ? 1 : 0);
169 if (maxedColors == 3) {
172 const int toChangeNext = 3 - maxedColors;
173 return result.
changedBrightness((
int)((toChange * change - changed) / toChangeNext), toChangeNext);
181 std::transform(coldef.begin(), coldef.end(), coldef.begin(), tolower);
182 if (coldef ==
"red") {
185 if (coldef ==
"green") {
188 if (coldef ==
"blue") {
191 if (coldef ==
"yellow") {
194 if (coldef ==
"cyan") {
197 if (coldef ==
"magenta") {
200 if (coldef ==
"orange") {
203 if (coldef ==
"white") {
206 if (coldef ==
"black") {
209 if (coldef ==
"grey" || coldef ==
"gray") {
215 unsigned char a = 255;
216 if (coldef[0] ==
'#') {
218 if (coldef.length() == 7) {
219 r =
static_cast<unsigned char>((coldesc & 0xFF0000) >> 16);
220 g =
static_cast<unsigned char>((coldesc & 0x00FF00) >> 8);
222 }
else if (coldef.length() == 9) {
223 r =
static_cast<unsigned char>((coldesc & 0xFF000000) >> 24);
224 g =
static_cast<unsigned char>((coldesc & 0x00FF0000) >> 16);
225 b =
static_cast<unsigned char>((coldesc & 0x0000FF00) >> 8);
232 if (st.size() == 3 || st.size() == 4) {
237 if (st.size() == 4) {
240 if (r <= 1 && g <= 1 && b <= 1 && (st.size() == 3 || a <= 1)) {
247 if (st.size() == 4) {
261 const std::string& coldef,
const std::string& objecttype,
262 const char* objectid,
bool report,
bool& ok) {
270 std::ostringstream oss;
271 oss <<
"Attribute 'color' in definition of ";
277 oss <<
" '" << objectid <<
"'";
279 oss <<
" is not a valid color.";
293 const unsigned char r = (
unsigned char)((
int)minColor.
myRed + (((int)maxColor.
myRed - (
int)minColor.
myRed) * weight));
294 const unsigned char g = (
unsigned char)((
int)minColor.
myGreen + (((int)maxColor.
myGreen - (
int)minColor.
myGreen) * weight));
295 const unsigned char b = (
unsigned char)((
int)minColor.
myBlue + (((int)maxColor.
myBlue - (
int)minColor.
myBlue) * weight));
296 const unsigned char a = (
unsigned char)((
int)minColor.
myAlpha + (((int)maxColor.
myAlpha - (
int)minColor.
myAlpha) * weight));
315 const unsigned char m =
static_cast<unsigned char>(v * (1 - s) * 255. + 0.5);
316 const unsigned char n =
static_cast<unsigned char>(v * (1 - s * f) * 255. + 0.5);
317 const unsigned char vv =
static_cast<unsigned char>(v * 255. + 0.5);
333 return RGBColor(255, 255, 255, 255);
static int _hex2int(const E *const data)
converts a char-type array with a hex value into the integer value described by it ...
static const RGBColor BLUE
static RGBColor parseColor(std::string coldef)
Parses a color information.
static RGBColor fromHSV(double h, double s, double v)
Converts the given hsv-triplet to rgb.
static const RGBColor WHITE
static RGBColor parseColorReporting(const std::string &coldef, const std::string &objecttype, const char *objectid, bool report, bool &ok)
Parses a color information.
bool operator==(const RGBColor &c) const
static const RGBColor ORANGE
friend std::ostream & operator<<(std::ostream &os, const RGBColor &col)
Writes the color to the given stream.
static const RGBColor BLACK
#define UNUSED_PARAMETER(x)
unsigned char blue() const
Returns the blue-amount of the color.
bool operator!=(const RGBColor &c) const
static const RGBColor GREEN
static const RGBColor GREY
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
unsigned char myRed
The color amounts.
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
assigns new values
RGBColor invertedColor() const
obtain inverted of current RGBColor
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
unsigned char alpha() const
Returns the alpha-amount of the color.
static const RGBColor MAGENTA
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
std::vector< std::string > getVector()
static const RGBColor YELLOW
static int _2int(const E *const data)
converts a char-type array into the integer value described by it
static const RGBColor RED
named colors
static const RGBColor CYAN
static double _2double(const E *const data)
converts a char-type array into the double value described by it
unsigned char green() const
Returns the green-amount of the color.
unsigned char red() const
Returns the red-amount of the color.
static RGBColor interpolate(const RGBColor &minColor, const RGBColor &maxColor, double weight)
Interpolates between two colors.
static const std::string DEFAULT_COLOR_STRING
The string description of the default color.