47 inline Color(
const unsigned int rgb,
unsigned char alpha = 255);
52 static inline Color gray(
unsigned char grayLevel,
unsigned char alpha = 255);
58 inline Color(
const std::string & htmlColor,
unsigned char alpha);
64 inline Color(
const std::string & htmlColor);
66 inline Color(
const char * htmlColor,
unsigned char alpha = 255);
71 inline Color(std::nullptr_t);
73 inline void red(
unsigned char red);
75 inline void blue(
unsigned char blue);
78 inline unsigned char red()
const;
79 inline unsigned char green()
const;
80 inline unsigned char blue()
const;
81 inline unsigned char alpha()
const;
101 Color &
setHSV(
float hue,
float saturation,
float value,
float alpha = 1.0);
113 std::string
svg()
const;
115 inline bool isNull()
const;
126 std::string
svgAlpha(
const char * prefix)
const;
138 std::string
tikz()
const;
140 void toHSV(
float & hue,
float & saturation,
float & value,
float &
alpha)
const;
144 static Color fromHSV(
float hue,
float saturation,
float value,
float alpha = 1.0f);
152 std::ostream &
flush(std::ostream & out)
const;
186Color &
Color::setRGBi(
const unsigned char red,
const unsigned char green,
const unsigned char blue,
const unsigned char alpha)
197 return _red == -1 && _green == -1 && _blue == -1;
209 _red = _green = _blue = -1;
213Color::Color(
const unsigned int rgb,
unsigned char alpha) : _alpha(alpha)
215 _red = (rgb & 0xFF0000u) >> 16;
216 _green = (rgb & 0xFF00u) >> 8;
220Color::Color(
unsigned char red,
unsigned char green,
unsigned char blue,
unsigned char alpha) : _red(red), _green(green), _blue(blue), _alpha(alpha) {}
222Color::Color(
unsigned char gray,
unsigned char alpha) : _red(gray), _green(gray), _blue(gray), _alpha(alpha) {}
226 return Color(
static_cast<unsigned char>(
red * 255),
static_cast<unsigned char>(
green * 255),
static_cast<unsigned char>(
blue * 255),
static_cast<unsigned char>(
alpha * 255));
231 return Color(grayLevel, grayLevel, grayLevel,
alpha);
235Color::Color(
const std::string & htmlColor,
unsigned char alpha) :
Color(htmlColor.c_str(), alpha) {}
239Color::Color(
const char * htmlColor,
unsigned char alpha) : _alpha(alpha)
241 unsigned int r, g, b, a =
alpha;
242 if (!htmlColor || *htmlColor ==
'\0') {
246 if (strlen(htmlColor) == 7 && sscanf(htmlColor,
"#%2x%2x%2x", &r, &g, &b) == 3) {
251 }
else if (strlen(htmlColor) == 9 && sscanf(htmlColor,
"#%2x%2x%2x%2x", &r, &g, &b, &a) == 4) {
258 Tools::error <<
"Color::Color(htmlcolor): cannot parse color string\n";
284 return static_cast<unsigned char>(_red);
289 return static_cast<unsigned char>(_green);
294 return static_cast<unsigned char>(_blue);
299 return static_cast<unsigned char>(_alpha);
Structure representing an RGB triple.
Definition Color.h:43
static Color fromRGBf(float red, float green, float blue, float alpha=1.0f)
Definition Color.h:224
static Color fromHueColormap(float t)
Definition Color.cpp:229
static const Color DarkGreen
Definition Color.h:163
static const Color Navy
Definition Color.h:172
static const Color Lime
Definition Color.h:164
bool isNull() const
Definition Color.h:195
unsigned char blue() const
Definition Color.h:292
Color & setRGBf(float red, float green, float blue, float alpha=1.0)
Definition Color.cpp:71
static const Color Blue
Definition Color.h:165
bool isValid() const
Definition Color.h:200
unsigned char red() const
Definition Color.h:282
static Color gray(unsigned char grayLevel, unsigned char alpha=255)
Definition Color.h:229
static const Color Null
Definition Color.h:155
std::string postscript() const
Definition Color.cpp:116
static const Color Pink
Definition Color.h:158
static const Color DarkCyan
Definition Color.h:167
static const Color Aqua
Definition Color.h:173
static const Color Purple
Definition Color.h:171
std::string svgAlpha(const char *prefix) const
Definition Color.cpp:132
static Color mixRGB(const Color &a, const Color &b, float t)
Definition Color.cpp:208
static const Color Brown
Definition Color.h:157
static const Color Silver
Definition Color.h:170
static const Color Gray
Definition Color.h:159
unsigned char green() const
Definition Color.h:287
static const Color Black
Definition Color.h:156
std::ostream & flush(std::ostream &out) const
Definition Color.cpp:234
std::string tikz() const
Definition Color.cpp:142
static Color fromHSV(float hue, float saturation, float value, float alpha=1.0f)
Definition Color.cpp:201
static const Color Magenta
Definition Color.h:168
static const Color Cyan
Definition Color.h:166
Color & setRGBi(const unsigned char red, const unsigned char green, const unsigned char blue, const unsigned char alpha=255)
setRGBi
Definition Color.h:186
bool operator!=(const Color &other) const
Definition Color.cpp:89
bool valid() const
Definition Color.h:142
std::string svg() const
Definition Color.cpp:123
void toHSV(float &hue, float &saturation, float &value, float &alpha) const
Definition Color.cpp:172
bool operator==(const Color &other) const
Definition Color.cpp:84
static Color mixHSV(const Color &a, const Color &b, float t)
Definition Color.cpp:217
void flushPostscript(std::ostream &) const
Definition Color.cpp:111
static const Color Yellow
Definition Color.h:169
Color & setHSV(float hue, float saturation, float value, float alpha=1.0)
setHSV
Definition Color.cpp:56
Color()
Definition Color.h:205
static const Color White
Definition Color.h:160
unsigned char alpha() const
Definition Color.h:297
bool operator<(const Color &other) const
Definition Color.cpp:94
static const Color Red
Definition Color.h:161
static const Color Green
Definition Color.h:162
std::ostream & operator<<(std::ostream &out, const Color &color)
Definition Color.cpp:245