23#ifndef VCL_SPACE_CORE_COLOR_H
24#define VCL_SPACE_CORE_COLOR_H
77 enum class Format { ABGR, ARGB, RGBA, BGRA };
86 DarkGray = 0xff404040,
88 LightGray = 0xffc0c0c0,
99 LightRed = 0xff8080ff,
100 LightGreen = 0xff80ff80,
101 LightBlue = 0xffff8080,
103 LightCyan = 0xffffff80,
104 LightYellow = 0xff80ffff,
105 LightMagenta = 0xffff80ff,
107 DarkRed = 0xff000040,
108 DarkGreen = 0xff004000,
109 DarkBlue = 0xff400000,
111 DarkCyan = 0xff404000,
112 DarkYellow = 0xff004040,
113 DarkMagenta = 0xff400040,
115 LightBrown = 0xff4080b0,
116 DarkBrown = 0xff002040,
123 enum class ColorMap { RedBlue, Parula, GreyShade };
133 Color(uint32_t cc,
Format format) { set(cc, format); }
201 float redF()
const {
return (
float)
x() / 255; }
207 float greenF()
const {
return (
float)
y() / 255; }
213 float blueF()
const {
return (
float)
z() / 255; }
219 float alphaF()
const {
return (
float)
w() / 255; }
283 return *
reinterpret_cast<const uint32_t*
>(Point::data());
286 uint32_t argb()
const
291 uint32_t rgba()
const
296 uint32_t bgra()
const
311 unsigned short r =
x() / 8;
312 unsigned short g =
y() / 8;
313 unsigned short b =
z() / 8;
314 unsigned short res =
r +
g * 32 +
b * 1024;
328 unsigned short r =
x() / 8;
329 unsigned short g =
y() / 8;
330 unsigned short b =
z() / 8;
331 unsigned short res =
b +
g * 32 +
r * 1024;
380 case Format::ARGB: setArgb(
cc);
break;
381 case Format::ABGR: setAbgr(
cc);
break;
382 case Format::RGBA: setRgba(
cc);
break;
383 case Format::BGRA: setBgra(
cc);
break;
387 void setAbgr(uint32_t val)
389 *
reinterpret_cast<uint32_t*
>(Point::data()) = val;
392 void setArgb(uint32_t val)
394 x() = (val >> 16) % 256;
395 y() = (val >> 8) % 256;
397 w() = (val >> 24) % 256;
400 void setRgba(uint32_t val)
402 x() = (val >> 24) % 256;
403 y() = (val >> 16) % 256;
404 z() = (val >> 8) % 256;
408 void setBgra(uint32_t val)
410 x() = (val >> 8) % 256;
411 y() = (val >> 16) % 256;
412 z() = (val >> 24) % 256;
432 y() = ((
val / 32) % 32) * 8;
433 z() = ((
val / 1024) % 32) * 8;
453 y() = ((
val / 32) % 32) * 8;
454 x() = ((
val / 1024) % 32) * 8;
477 h = (
h / 360.0) * 255;
482 p = (v * (255 - s)) >> 8;
483 q = (v * (255 - ((s *
remainder) >> 8))) >> 8;
484 t = (v * (255 - ((s * (255 -
remainder)) >> 8))) >> 8;
668 for (uint
i = 0;
i < 4;
i++)
669 c(
i) =
c1(
i) * value +
c0(
i) * (1 - value);
684inline Color colorFromIntervalRedBlue(
float value)
693 c.
setHsv(value * 240, 255, 255);
714inline Color colorFromIntervalRedBlue(
float min,
float max,
float value)
721 value = std::abs((value -
min) / (
max -
min));
722 return colorFromIntervalRedBlue(value);
737inline Color colorFromIntervalParula(
float value)
744 static uint paruVal[9] = {
755 int ind = int(floor(value * 8.0f));
756 float div = (value * 8.0f - ind);
786inline Color colorFromIntervalParula(
float min,
float max,
float value)
793 value = std::abs((value -
min) / (
max -
min));
794 return colorFromIntervalParula(value);
809inline Color colorFromIntervalGreyShade(
float value)
815 return Color(value * 255, value * 255, value * 255, 255);
835inline Color colorFromIntervalGreyShade(
float min,
float max,
float value)
842 value = std::abs((value -
min) / (
max -
min));
843 return colorFromIntervalGreyShade(value);
859 case RedBlue:
return colorFromIntervalRedBlue(value);
860 case Parula:
return colorFromIntervalParula(value);
861 case GreyShade:
return colorFromIntervalGreyShade(value);
862 default: assert(0);
return Color::Gray;
885inline Color colorFromInterval(
895 value = std::abs((value -
min) / (
max -
min));
896 return colorFromInterval(value, cm);
908inline std::vector<Color> colorScattering(
913 std::vector<Color> scattering;
914 scattering.reserve(n);
916 for (uint v = 0; v < n; ++v) {
917 uint value = v, m = n;
920 for (uint k = 1; k < n; k <<= 1) {
921 if (value << 1 >= m) {
923 value -= (m + 1) >> 1;
932 rc.setHsvF(
float(b) / float(n), sat, val);
933 scattering.push_back(rc);
The Color class represents a 32 bit color.
Definition color.h:48
ColorABGR
ABGR enum with some standard colors.
Definition color.h:84
uint8_t green() const
Returns the green component of this color [0-255].
Definition color.h:159
bool operator==(const Color &otherColor) const
Returns true if this color has the same RGB and alpha values as otherColor; otherwise returns false.
Definition color.h:590
float greenF() const
Returns the float green component of this color [0-1].
Definition color.h:207
uint8_t & blue()
Returns the blue component of this color [0-255].
Definition color.h:189
void setBlue(uint8_t blue)
Sets the blue of this color [0-255].
Definition color.h:357
unsigned short bgr5() const
Converts the color to an unsigned short in bgr5 format.
Definition color.h:309
uint8_t & green()
Returns the green component of this color [0-255].
Definition color.h:183
void setHsvF(float hf, float sf, float vf, float alpha=1.0)
Sets the HSV values of this color.
Definition color.h:578
ColorMap
List of Color Maps supported by the vcl::Color.
Definition color.h:123
Color(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha=255)
Color constructor.
Definition color.h:142
uint8_t hsvHue() const
Returns the hue color component of this color [0-359].
Definition color.h:225
void setRgbF(float red, float green, float blue, float alpha=1.0)
Sets the RGB values of this color.
Definition color.h:559
Format
Color format enumeration.
Definition color.h:77
void setBgr5(unsigned short val)
Definition color.h:429
uint8_t red() const
Returns the red component of this color [0-255].
Definition color.h:153
Representation
Color representation enumeration.
Definition color.h:64
void setHsv(uint8_t h, uint8_t s, uint8_t v, uint8_t alpha=255)
Sets the HSV values of this color.
Definition color.h:468
float blueF() const
Returns the float blue component of this color [0-1].
Definition color.h:213
float alphaF() const
Returns the float alpha component of this color [0-1].
Definition color.h:219
bool operator!=(const Color &otherColor) const
Returns false if this color has the same RGB and alpha values as otherColor; otherwise returns true.
Definition color.h:604
uint8_t & red()
Returns the red component of this color [0-255].
Definition color.h:177
bool operator<(const Color &otherColor) const
Returns true if this color is less than otherColor follwing the RGBA order; otherwise returns false.
Definition color.h:616
void setRedF(float red)
Sets the red of this color [0-1].
Definition color.h:531
uint8_t & alpha()
Returns the alpha component of this color [0-255].
Definition color.h:195
void setRed(uint8_t red)
Sets the red of this color [0-255].
Definition color.h:345
float hsvSaturationF() const
Returns the float saturation color component of this color [0-1].
Definition color.h:279
void setAlpha(uint8_t alpha)
Sets the alpha of this color [0-255].
Definition color.h:339
float redF() const
Returns the float red component of this color [0-1].
Definition color.h:201
void setAlphaF(float alpha)
Sets the alpha of this color [0-1].
Definition color.h:525
Color()
Default constructor. Initializes a black color (with alpha 255).
Definition color.h:129
uint8_t hsvSaturation() const
Returns the saturation color component of this color [0-255].
Definition color.h:255
unsigned short rgb5() const
Converts the color to an unsigned short in rgb5 format.
Definition color.h:326
void setBlueF(float blue)
Sets the blue of this color [0-1].
Definition color.h:543
void setRgb5(unsigned short val)
Definition color.h:450
void setGreen(uint8_t green)
Sets the green of this color [0-255].
Definition color.h:351
uint8_t alpha() const
Returns the alpha component of this color [0-255].
Definition color.h:171
float hsvHueF() const
Returns the float saturation color component of this color [0-1].
Definition color.h:273
void setRgb(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha=255)
Sets the RGB values of this color.
Definition color.h:369
friend std::ostream & operator<<(std::ostream &out, const Color &c)
Overload of stream operator to allow a pretty print of a vcl::Color.
Definition color.h:642
uint8_t blue() const
Returns the blue component of this color [0-255].
Definition color.h:165
void setGreenF(float green)
Sets the green of this color [0-1].
Definition color.h:537
The Point class represents an N-dimensional point containing N scalar values.
Definition point.h:58
auto cast() const
Casts the Point object to a different scalar type.
Definition point.h:226
ScalarType & z()
Returns a reference to the z-component of the Point object.
Definition point.h:175
ScalarType & x()
Returns a reference to the x-component of the Point object.
Definition point.h:131
ScalarType & w()
Returns a reference to the w-component of the Point object.
Definition point.h:197
ScalarType & y()
Returns a reference to the y-component of the Point object.
Definition point.h:153
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:43
constexpr auto max(const T &p1, const T &p2)
Returns the maximum between the two parameters.
Definition min_max.h:83
constexpr auto min(const T &p1, const T &p2)
Returns the minimum between the two parameters.
Definition min_max.h:42