67 : myRed(0), myGreen(0), myBlue(0), myAlpha(0) {}
82 RGBColor::set(
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a) {
92 if (col == RGBColor::RED) {
95 if (col == RGBColor::GREEN) {
98 if (col == RGBColor::BLUE) {
101 if (col == RGBColor::YELLOW) {
102 return os <<
"yellow";
104 if (col == RGBColor::CYAN) {
107 if (col == RGBColor::MAGENTA) {
108 return os <<
"magenta";
110 if (col == RGBColor::ORANGE) {
111 return os <<
"orange";
113 if (col == RGBColor::WHITE) {
114 return os <<
"white";
116 if (col == RGBColor::BLACK) {
117 return os <<
"black";
119 if (col == RGBColor::GREY) {
122 os << static_cast<int>(col.
myRed) <<
"," 123 << static_cast<int>(col.
myGreen) <<
"," 124 <<
static_cast<int>(col.
myBlue);
126 os <<
"," <<
static_cast<int>(col.
myAlpha);
147 const unsigned char r = (
unsigned char)(255 - (
int)
myRed);
148 const unsigned char g = (
unsigned char)(255 - (
int)
myGreen);
149 const unsigned char b = (
unsigned char)(255 - (
int)
myBlue);
157 const unsigned char red = (
unsigned char)(
MIN2(
MAX2(
myRed + change, 0), 255));
160 int changed = ((int)red - (
int)
myRed) + ((
int)blue - (int)
myBlue) + ((int)green - (
int)
myGreen);
162 if (changed == toChange * change) {
164 }
else if (changed == 0) {
167 const int maxedColors = (red !=
myRed + change ? 1 : 0) + (blue != myBlue + change ? 1 : 0) + (green !=
myGreen + change ? 1 : 0);
168 if (maxedColors == 3) {
171 const int toChangeNext = 3 - maxedColors;
172 return result.
changedBrightness((
int)((toChange * change - changed) / toChangeNext), toChangeNext);
180 std::transform(coldef.begin(), coldef.end(), coldef.begin(), tolower);
181 if (coldef ==
"red") {
184 if (coldef ==
"green") {
187 if (coldef ==
"blue") {
190 if (coldef ==
"yellow") {
193 if (coldef ==
"cyan") {
196 if (coldef ==
"magenta") {
199 if (coldef ==
"orange") {
202 if (coldef ==
"white") {
205 if (coldef ==
"black") {
208 if (coldef ==
"grey" || coldef ==
"gray") {
214 unsigned char a = 255;
215 if (coldef[0] ==
'#') {
217 if (coldef.length() == 7) {
218 r =
static_cast<unsigned char>((coldesc & 0xFF0000) >> 16);
219 g =
static_cast<unsigned char>((coldesc & 0x00FF00) >> 8);
221 }
else if (coldef.length() == 9) {
222 r =
static_cast<unsigned char>((coldesc & 0xFF000000) >> 24);
223 g =
static_cast<unsigned char>((coldesc & 0x00FF0000) >> 16);
224 b =
static_cast<unsigned char>((coldesc & 0x0000FF00) >> 8);
231 if (st.size() == 3 || st.size() == 4) {
236 if (st.size() == 4) {
239 if (r <= 1 && g <= 1 && b <= 1 && (st.size() == 3 || a <= 1)) {
246 if (st.size() == 4) {
260 const std::string& coldef,
const std::string& objecttype,
261 const char* objectid,
bool report,
bool& ok) {
269 std::ostringstream oss;
270 oss <<
"Attribute 'color' in definition of ";
276 oss <<
" '" << objectid <<
"'";
278 oss <<
" is not a valid color.";
292 const unsigned char r = (
unsigned char)((
int)minColor.
myRed + (((int)maxColor.
myRed - (
int)minColor.
myRed) * weight));
293 const unsigned char g = (
unsigned char)((
int)minColor.
myGreen + (((int)maxColor.
myGreen - (
int)minColor.
myGreen) * weight));
294 const unsigned char b = (
unsigned char)((
int)minColor.
myBlue + (((int)maxColor.
myBlue - (
int)minColor.
myBlue) * weight));
295 const unsigned char a = (
unsigned char)((
int)minColor.
myAlpha + (((int)maxColor.
myAlpha - (
int)minColor.
myAlpha) * weight));
314 const unsigned char m =
static_cast<unsigned char>(v * (1 - s) * 255. + 0.5);
315 const unsigned char n =
static_cast<unsigned char>(v * (1 - s * f) * 255. + 0.5);
316 const unsigned char vv =
static_cast<unsigned char>(v * 255. + 0.5);
332 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.
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 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.
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
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
unsigned char green() const
Returns the green-amount of the color.
static double _2double(const E *const data)
converts a char-type array into the double value described by it
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.