65 : myRed(0), myGreen(0), myBlue(0), myAlpha(0) {}
80 RGBColor::set(
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a) {
90 if (col == RGBColor::RED) {
93 if (col == RGBColor::GREEN) {
96 if (col == RGBColor::BLUE) {
99 if (col == RGBColor::YELLOW) {
100 return os <<
"yellow";
102 if (col == RGBColor::CYAN) {
105 if (col == RGBColor::MAGENTA) {
106 return os <<
"magenta";
108 if (col == RGBColor::ORANGE) {
109 return os <<
"orange";
111 if (col == RGBColor::WHITE) {
112 return os <<
"white";
114 if (col == RGBColor::BLACK) {
115 return os <<
"black";
117 if (col == RGBColor::GREY) {
120 os << static_cast<int>(col.
myRed) <<
"," 121 << static_cast<int>(col.
myGreen) <<
"," 122 <<
static_cast<int>(col.
myBlue);
124 os <<
"," <<
static_cast<int>(col.
myAlpha);
145 const unsigned char r = (
unsigned char)(255 - (
int)
myRed);
146 const unsigned char g = (
unsigned char)(255 - (
int)
myGreen);
147 const unsigned char b = (
unsigned char)(255 - (
int)
myBlue);
155 const unsigned char red = (
unsigned char)(
MIN2(
MAX2(
myRed + change, 0), 255));
158 int changed = ((int)red - (
int)
myRed) + ((
int)blue - (int)
myBlue) + ((int)green - (
int)
myGreen);
160 if (changed == toChange * change) {
162 }
else if (changed == 0) {
165 const int maxedColors = (red !=
myRed + change ? 1 : 0) + (blue != myBlue + change ? 1 : 0) + (green !=
myGreen + change ? 1 : 0);
166 if (maxedColors == 3) {
169 const int toChangeNext = 3 - maxedColors;
170 return result.
changedBrightness((
int)((toChange * change - changed) / toChangeNext), toChangeNext);
178 std::transform(coldef.begin(), coldef.end(), coldef.begin(), tolower);
179 if (coldef ==
"red") {
182 if (coldef ==
"green") {
185 if (coldef ==
"blue") {
188 if (coldef ==
"yellow") {
191 if (coldef ==
"cyan") {
194 if (coldef ==
"magenta") {
197 if (coldef ==
"orange") {
200 if (coldef ==
"white") {
203 if (coldef ==
"black") {
206 if (coldef ==
"grey" || coldef ==
"gray") {
212 unsigned char a = 255;
213 if (coldef[0] ==
'#') {
215 if (coldef.length() == 7) {
216 r =
static_cast<unsigned char>((coldesc & 0xFF0000) >> 16);
217 g =
static_cast<unsigned char>((coldesc & 0x00FF00) >> 8);
219 }
else if (coldef.length() == 9) {
220 r =
static_cast<unsigned char>((coldesc & 0xFF000000) >> 24);
221 g =
static_cast<unsigned char>((coldesc & 0x00FF0000) >> 16);
222 b =
static_cast<unsigned char>((coldesc & 0x0000FF00) >> 8);
229 if (st.size() == 3 || st.size() == 4) {
234 if (st.size() == 4) {
237 if (r <= 1 && g <= 1 && b <= 1 && (st.size() == 3 || a <= 1)) {
244 if (st.size() == 4) {
258 const std::string& coldef,
const std::string& objecttype,
259 const char* objectid,
bool report,
bool& ok) {
267 std::ostringstream oss;
268 oss <<
"Attribute 'color' in definition of ";
269 if (objectid ==
nullptr) {
273 if (objectid !=
nullptr) {
274 oss <<
" '" << objectid <<
"'";
276 oss <<
" is not a valid color.";
290 const unsigned char r = (
unsigned char)((
int)minColor.
myRed + (((int)maxColor.
myRed - (
int)minColor.
myRed) * weight));
291 const unsigned char g = (
unsigned char)((
int)minColor.
myGreen + (((int)maxColor.
myGreen - (
int)minColor.
myGreen) * weight));
292 const unsigned char b = (
unsigned char)((
int)minColor.
myBlue + (((int)maxColor.
myBlue - (
int)minColor.
myBlue) * weight));
293 const unsigned char a = (
unsigned char)((
int)minColor.
myAlpha + (((int)maxColor.
myAlpha - (
int)minColor.
myAlpha) * weight));
312 const unsigned char m =
static_cast<unsigned char>(v * (1 - s) * 255. + 0.5);
313 const unsigned char n =
static_cast<unsigned char>(v * (1 - s * f) * 255. + 0.5);
314 const unsigned char vv =
static_cast<unsigned char>(v * 255. + 0.5);
330 return RGBColor(255, 255, 255, 255);
static const RGBColor BLUE
static RGBColor randomHue(double s=1, double v=1)
Return color with random hue.
static RGBColor parseColor(std::string coldef)
Parses a color information.
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
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.
unsigned char alpha() const
Returns the alpha-amount of the color.
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
static const RGBColor ORANGE
unsigned char blue() const
Returns the blue-amount of the color.
friend std::ostream & operator<<(std::ostream &os, const RGBColor &col)
Writes the color to the given stream.
static const RGBColor BLACK
bool operator==(const RGBColor &c) const
RGBColor invertedColor() const
obtain inverted of current RGBColor
#define UNUSED_PARAMETER(x)
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.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter ...
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
assigns new values
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
static const RGBColor MAGENTA
static int toInt(const std::string &sData)
converts a string into the integer value described by it by calling the char-type converter...
static std::mt19937 myRNG
A random number generator to generate random colors independent of other randomness.
std::vector< std::string > getVector()
static const RGBColor YELLOW
static const RGBColor RED
named colors
static const RGBColor CYAN
unsigned char green() const
Returns the green-amount of the color.
unsigned char red() const
Returns the red-amount of the color.
static const RGBColor INVISIBLE
static int hexToInt(const std::string &sData)
converts a string with a hex value into the integer value described by it by calling the char-type co...
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.