Visual Computing Library
|
The Color class represents a 32 bit color. More...
#include <vclib/space/core/color.h>
Public Types | |
enum class | Representation { INT_0_255 , FLOAT_0_1 } |
Color representation enumeration. More... | |
enum class | Format { ABGR , ARGB , RGBA , BGRA } |
Color format enumeration. More... | |
enum | ColorABGR : uint32_t { Black = 0xff000000 , DarkGray = 0xff404040 , Gray = 0xff808080 , LightGray = 0xffc0c0c0 , White = 0xffffffff , Red = 0xff0000ff , Green = 0xff00ff00 , Blue = 0xffff0000 , Yellow = 0xff00ffff , Cyan = 0xffffff00 , Magenta = 0xffff00ff , LightRed = 0xff8080ff , LightGreen = 0xff80ff80 , LightBlue = 0xffff8080 , LightCyan = 0xffffff80 , LightYellow = 0xff80ffff , LightMagenta = 0xffff80ff , DarkRed = 0xff000040 , DarkGreen = 0xff004000 , DarkBlue = 0xff400000 , DarkCyan = 0xff404000 , DarkYellow = 0xff004040 , DarkMagenta = 0xff400040 , LightBrown = 0xff4080b0 , DarkBrown = 0xff002040 , Brown = 0xff004080 } |
ABGR enum with some standard colors. More... | |
enum class | ColorMap { RedBlue , Parula , GreyShade } |
List of Color Maps supported by the vcl::Color. | |
![]() | |
using | BaseMatrixType = Base |
using | ScalarType = Scalar |
The Scalar type of the Point. | |
Public Member Functions | |
Color () | |
Default constructor. Initializes a black color (with alpha 255). | |
Color (ColorABGR cc) | |
Color (uint32_t cc, Format format) | |
Color (uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha=255) | |
Color constructor. | |
Color (const Point4< uint8_t > &p) | |
uint8_t | red () const |
Returns the red component of this color [0-255]. | |
uint8_t | green () const |
Returns the green component of this color [0-255]. | |
uint8_t | blue () const |
Returns the blue component of this color [0-255]. | |
uint8_t | alpha () const |
Returns the alpha component of this color [0-255]. | |
uint8_t & | red () |
Returns the red component of this color [0-255]. | |
uint8_t & | green () |
Returns the green component of this color [0-255]. | |
uint8_t & | blue () |
Returns the blue component of this color [0-255]. | |
uint8_t & | alpha () |
Returns the alpha component of this color [0-255]. | |
float | redF () const |
Returns the float red component of this color [0-1]. | |
float | greenF () const |
Returns the float green component of this color [0-1]. | |
float | blueF () const |
Returns the float blue component of this color [0-1]. | |
float | alphaF () const |
Returns the float alpha component of this color [0-1]. | |
uint8_t | hsvHue () const |
Returns the hue color component of this color [0-359]. | |
uint8_t | hsvSaturation () const |
Returns the saturation color component of this color [0-255]. | |
float | hsvHueF () const |
Returns the float saturation color component of this color [0-1]. | |
float | hsvSaturationF () const |
Returns the float saturation color component of this color [0-1]. | |
uint32_t | abgr () const |
uint32_t | argb () const |
uint32_t | rgba () const |
uint32_t | bgra () const |
unsigned short | bgr5 () const |
Converts the color to an unsigned short in bgr5 format. | |
unsigned short | rgb5 () const |
Converts the color to an unsigned short in rgb5 format. | |
void | setAlpha (uint8_t alpha) |
Sets the alpha of this color [0-255]. | |
void | setRed (uint8_t red) |
Sets the red of this color [0-255]. | |
void | setGreen (uint8_t green) |
Sets the green of this color [0-255]. | |
void | setBlue (uint8_t blue) |
Sets the blue of this color [0-255]. | |
void | setRgb (uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha=255) |
Sets the RGB values of this color. | |
void | set (uint32_t cc, Format fmt=Format::ABGR) |
void | setAbgr (uint32_t val) |
void | setArgb (uint32_t val) |
void | setRgba (uint32_t val) |
void | setBgra (uint32_t val) |
void | setBgr5 (unsigned short val) |
void | setRgb5 (unsigned short val) |
void | setHsv (uint8_t h, uint8_t s, uint8_t v, uint8_t alpha=255) |
Sets the HSV values of this color. | |
void | setAlphaF (float alpha) |
Sets the alpha of this color [0-1]. | |
void | setRedF (float red) |
Sets the red of this color [0-1]. | |
void | setGreenF (float green) |
Sets the green of this color [0-1]. | |
void | setBlueF (float blue) |
Sets the blue of this color [0-1]. | |
void | setRgbF (float red, float green, float blue, float alpha=1.0) |
Sets the RGB values of this color. | |
void | setHsvF (float hf, float sf, float vf, float alpha=1.0) |
Sets the HSV values of this color. | |
bool | operator== (const Color &otherColor) const |
Returns true if this color has the same RGB and alpha values as otherColor; otherwise returns false. | |
bool | operator!= (const Color &otherColor) const |
Returns false if this color has the same RGB and alpha values as otherColor; otherwise returns true. | |
bool | operator< (const Color &otherColor) const |
Returns true if this color is less than otherColor follwing the RGBA order; otherwise returns false. | |
![]() | |
Point () | |
Constructs a Point object with all components set to zero. | |
template<typename OtherDerived > | |
Point (const Eigen::MatrixBase< OtherDerived > &other) | |
Constructs a Point object from an Eigen matrix. | |
template<typename... Scalars> requires (sizeof...(scalars) == N) | |
Point (Scalars... scalars) | |
Constructs a Point object from a set of scalar values. | |
ScalarType & | x () |
Returns a reference to the x-component of the Point object. | |
const ScalarType & | x () const |
Returns a const reference to the x-component of the Point object. | |
ScalarType & | y () |
Returns a reference to the y-component of the Point object. | |
const ScalarType & | y () const |
Returns a const reference to the y-component of the Point object. | |
ScalarType & | z () |
Returns a reference to the z-component of the Point object. | |
const ScalarType & | z () const |
Returns a const reference to the z-component of the Point object. | |
ScalarType & | w () |
Returns a reference to the w-component of the Point object. | |
const ScalarType & | w () const |
Returns a const reference to the w-component of the Point object. | |
ScalarType & | at (uint i) |
const ScalarType & | at (uint i) const |
template<typename S > | |
auto | cast () const |
Casts the Point object to a different scalar type. | |
bool | isDegenerate () const |
Returns true if at least one of its components is NaN or inf. | |
bool | epsilonEquals (const Point &p1, Scalar epsilon=std::numeric_limits< Scalar >::epsilon()) const |
Checks for the equality of two Point objects within a given epsilon tolerance. | |
Scalar | angle (const Point &p1) const |
Computes the angle between two Point objects. | |
Scalar | dist (const Point &p1) const |
Computes the Euclidean distance between two Point objects. | |
Scalar | squaredDist (const Point &p1) const |
Computes the squared Euclidean distance between two Point objects. | |
Point | mul (const Point &p1) const |
Multiplies the components of two Point objects. | |
Point | div (const Point &p1) const |
Divides the components of two Point objects. | |
constexpr uint | size () const |
Returns the size of the Point object. | |
template<typename... Scalars> requires (sizeof...(scalars) == N) | |
void | set (Scalars... scalars) |
Sets all the components of the Point object from a set of scalar values. | |
auto | outerProduct (const Point &p1) const |
Returns the outer product between this point p and p1, which is p * p1^T. | |
void | orthoBase (Point &u, Point &v) const |
Computes an Orthonormal Basis starting from this point n. | |
void | serialize (std::ostream &os) const |
Serializes the point to the given output stream. | |
void | deserialize (std::istream &is) |
Deserializes the point from the given input stream. | |
std::size_t | hash () const |
Computes the hash value of the point. | |
template<typename OtherDerived > | |
Point & | operator= (const Eigen::MatrixBase< OtherDerived > &other) |
Assigns the point to the given Eigen matrix. | |
auto | operator<=> (const Point &p1) const |
Compares the point with another point using the spaceship operator. | |
Point | operator+ (const Scalar &s) const |
Adds a scalar value to each coordinate of the point. | |
Point | operator- (const Scalar &s) const |
Subtracts a scalar value from each coordinate of the point. | |
Scalar | operator* (const Point &p1) const |
Computes the dot product of this point with another point. | |
Point | operator* (const Eigen::Matrix< Scalar, N+1, N+1 > &m) const |
Returns a new 3D point/vector on which has been applied a TRS 4x4 matrix. | |
Point & | operator+= (const Scalar &s) |
Adds a scalar value to this point. | |
Point & | operator-= (const Scalar &s) |
Subtracts a scalar value from this point. | |
Point & | operator*= (const Eigen::Matrix< Scalar, N+1, N+1 > &m) |
Applies a TRS 4x4 matrix transformation to this point. | |
Friends | |
std::ostream & | operator<< (std::ostream &out, const Color &c) |
Overload of stream operator to allow a pretty print of a vcl::Color. | |
Additional Inherited Members | |
![]() | |
static const uint | DIM = N |
DIM: the number of dimensions of the Point. | |
The Color class represents a 32 bit color.
The class is a specialization of the Point4 class, where each component is an unsigned char (0, 1, 2, 3 are respectively the red, green, blue and alpha).
Internally, the class stores four unsigned chars (uint8_t), that can be reinterpreted as a single unsigned integer (uint32_t) that stores a color in the ABGR format.
The class provides some useful methods to convert the color from/to different formats.
enum vcl::Color::ColorABGR : uint32_t |
ABGR enum with some standard colors.
It can be used to initialize a color with an ABGR integer.
|
strong |
Color format enumeration.
The color format enumeration is used to convert the color from/to different 32 bit formats. The notation used tells the order of the components in the integer representation of the color.
For example, the ABGR format means that the first byte of the integer represents the alpha, the second byte represents the blue, the third byte represents the green and the fourth byte represents the red.
|
strong |
Color representation enumeration.
The color representation enumeration is used to convert the color from/to different representations. The notation used tells the range of the components in the representation.
For example, the INT_0_255 format means that the components are integers in the range [0-255], while the FLOAT_0_1 format means that the components are floating points in the range [0-1].
This enumeration is not used directly in this class, but it is useful in conversion functions that ask for the representation of the color.
Color constructor.
[in] | red | red component |
[in] | green | green component |
[in] | blue | blue component |
[in] | alpha | alpha component (default 255) |
|
inline |
Returns the alpha component of this color [0-255].
|
inline |
Returns the alpha component of this color [0-255].
|
inline |
Returns the float alpha component of this color [0-1].
Converts the color to an unsigned short in bgr5 format.
The first (most significant) 5 bits are for blue, the next 5 bits are for green, and the last 5 bits are for red.
|
inline |
Returns the blue component of this color [0-255].
|
inline |
Returns the blue component of this color [0-255].
|
inline |
Returns the float blue component of this color [0-1].
|
inline |
Returns the green component of this color [0-255].
|
inline |
Returns the green component of this color [0-255].
|
inline |
Returns the float green component of this color [0-1].
|
inline |
Returns the hue color component of this color [0-359].
|
inline |
Returns the float saturation color component of this color [0-1].
|
inline |
Returns the saturation color component of this color [0-255].
|
inline |
Returns the float saturation color component of this color [0-1].
Returns false if this color has the same RGB and alpha values as otherColor; otherwise returns true.
otherColor |
Returns true if this color is less than otherColor follwing the RGBA order; otherwise returns false.
otherColor |
Returns true if this color has the same RGB and alpha values as otherColor; otherwise returns false.
otherColor |
|
inline |
Returns the red component of this color [0-255].
|
inline |
Returns the red component of this color [0-255].
|
inline |
Returns the float red component of this color [0-1].
Converts the color to an unsigned short in rgb5 format.
The first (most significant) 5 bits are for red, the next 5 bits are for green, and the last 5 bits are for blue.
Sets the alpha of this color [0-255].
[in] | alpha |
Sets the alpha of this color [0-1].
[in] | alpha |
Set the color values from an unsigned 5-5-5 BGR value.
The input value is interpreted as follows:
Each color component is scaled from 0 to 255 by multiplying the value by 8.
[in] | val | The unsigned 5-5-5 BGR value to set. |
Sets the blue of this color [0-255].
[in] | blue |
Sets the blue of this color [0-1].
[in] | blue |
Sets the green of this color [0-255].
[in] | green |
Sets the green of this color [0-1].
[in] | green |
Sets the HSV values of this color.
All the values must be in the range 0-255.
[in] | h | |
[in] | s | |
[in] | v | |
[in] | alpha |
Sets the HSV values of this color.
All the values must be in the range 0-1. The color will be converted in RGBA and then stored in this color.
[in] | hf | |
[in] | sf | |
[in] | vf | |
[in] | alpha |
Sets the red of this color [0-255].
[in] | red |
Sets the RGB values of this color.
All the values must be in the range 0-255.
[in] | red | |
[in] | green | |
[in] | blue | |
[in] | alpha |
Set the color values from an unsigned 5-5-5 RGB value.
The input value is interpreted as follows:
Each color component is scaled from 0 to 255 by multiplying the value by 8.
[in] | val | The unsigned 5-5-5 RGB value to set. |
Sets the RGB values of this color.
All the values must be in the range 0-1.
[in] | red | red component of the color in as a float value between 0 and 1. |
[in] | green | green component of the color in as a float value between 0 and 1. |
[in] | blue | blue component of the color in as a float value between 0 and 1. |
[in] | alpha | : alpha component of the color in as a float value between 0 and 1. |