44 #ifdef CHECK_MEMORY_LEAKS
46 #endif // CHECK_MEMORY_LEAKS
70 : myRed(0), myGreen(0), myBlue(0), myAlpha(0) {}
73 RGBColor::RGBColor(
unsigned char red,
unsigned char green,
unsigned char blue,
unsigned char alpha)
74 : myRed(red), myGreen(green), myBlue(blue), myAlpha(alpha) {}
78 : myRed(col.myRed), myGreen(col.myGreen), myBlue(col.myBlue), myAlpha(col.myAlpha) {}
85 RGBColor::set(
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a) {
95 if (col == RGBColor::RED) {
98 if (col == RGBColor::GREEN) {
101 if (col == RGBColor::BLUE) {
104 if (col == RGBColor::YELLOW) {
105 return os <<
"yellow";
107 if (col == RGBColor::CYAN) {
110 if (col == RGBColor::MAGENTA) {
111 return os <<
"magenta";
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);
146 const unsigned char red =
static_cast<unsigned char>(
MIN2(
MAX2(
myRed + change, 0), 255));
147 const unsigned char blue =
static_cast<unsigned char>(
MIN2(
MAX2(
myBlue + change, 0), 255));
155 std::transform(coldef.begin(), coldef.end(), coldef.begin(), tolower);
156 if (coldef ==
"red") {
159 if (coldef ==
"green") {
162 if (coldef ==
"blue") {
165 if (coldef ==
"yellow") {
168 if (coldef ==
"cyan") {
171 if (coldef ==
"magenta") {
174 if (coldef ==
"white") {
177 if (coldef ==
"black") {
180 if (coldef ==
"grey" || coldef ==
"gray") {
186 unsigned char a = 255;
187 if (coldef[0] ==
'#') {
189 if (coldef.length() == 7) {
190 r =
static_cast<unsigned char>((coldesc & 0xFF0000) >> 16);
191 g =
static_cast<unsigned char>((coldesc & 0x00FF00) >> 8);
193 }
else if (coldef.length() == 9) {
194 r =
static_cast<unsigned char>((coldesc & 0xFF000000) >> 24);
195 g =
static_cast<unsigned char>((coldesc & 0x00FF0000) >> 16);
196 b =
static_cast<unsigned char>((coldesc & 0x0000FF00) >> 8);
203 if (st.size() == 3 || st.size() == 4) {
208 if (st.size() == 4) {
211 if (r <= 1 && g <= 1 && b <= 1 && (st.size() == 3 || a <= 1)) {
218 if (st.size() == 4) {
232 const std::string& coldef,
const std::string& objecttype,
233 const char* objectid,
bool report,
bool& ok) {
241 std::ostringstream oss;
242 oss <<
"Attribute 'color' in definition of ";
248 oss <<
" '" << objectid <<
"'";
250 oss <<
" is not a valid color.";
264 const unsigned char r = minColor.
myRed +
static_cast<char>((maxColor.
myRed - minColor.
myRed) * weight);
265 const unsigned char g = minColor.
myGreen +
static_cast<char>((maxColor.
myGreen - minColor.
myGreen) * weight);
266 const unsigned char b = minColor.
myBlue +
static_cast<char>((maxColor.
myBlue - minColor.
myBlue) * weight);
267 const unsigned char a = minColor.
myAlpha +
static_cast<char>((maxColor.
myAlpha - minColor.
myAlpha) * weight);
286 const unsigned char m =
static_cast<unsigned char>(v * (1 - s) * 255. + 0.5);
287 const unsigned char n =
static_cast<unsigned char>(v * (1 - s * f) * 255. + 0.5);
288 const unsigned char vv =
static_cast<unsigned char>(v * 255. + 0.5);
304 return RGBColor(255, 255, 255, 255);