Core 1.0
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Friends | List of all members
Color Class Reference

Color with alpha channel in RGB space. More...

#include <color.h>

Public Member Functions

 Color (const double &=0.0)
 Creates a greyscale color. More...
 
 Color (unsigned long)
 Creates a color given a compact color representation. More...
 
 Color (const double &, const double &, const double &, const double &=1.0)
 Creates a color given each of these components. More...
 
 Color (int, int, int, int=255)
 Create a color given integer components. More...
 
 Color (const QColor &)
 Create a color from Qt representation. More...
 
 Color (const QRgb &)
 Create a color from Qt representation. More...
 
 ~Color ()
 Empty.
 
Color Pow (const double &=2.2)
 Apply gamma correction. More...
 
Coloroperator+= (const Color &)
 Overloaded operator.
 
Color Scale (const Color &) const
 Scale. More...
 
Coloroperator*= (const double &)
 Destructive scalar multiply.
 
Color Clamp (const Color &=Color::Black, const Color &=Color::White) const
 Clamp a color between two bounds. More...
 
double Luminance () const
 Compute the luminance.
 
unsigned long Cast () const
 Returns a compact color format of the RGB-alpha system value of the color.
 
constexpr double & operator[] (int)
 Returns the ith channel of the spectrum. More...
 
constexpr double operator[] (int) const
 Returns a copy of the ith channel of the spectrum. More...
 
QColor GetQt () const
 Create a Qt color from a color. More...
 

Static Public Member Functions

static Color Min (const Color &, const Color &)
 Returns the minimum value of each component. More...
 
static Color Max (const Color &, const Color &)
 Returns the maximum value of each component. More...
 
static Color Lerp (const double &, const Color &, const Color &)
 Linear interpolation between two colors. More...
 
static Color Get (const QVector< Color > &, const double &t)
 Compute a color in a discretized array of colors. More...
 
static QColor LerpQt (const QColor &, const QColor &, const double &, int)
 Interpolate two Qt colors in the prescribed space. More...
 
static Color BiCubic (const double &, const double &, const Color &, const Color &, const Color &, const Color &, const Color &, const Color &, const Color &, const Color &, const Color &, const Color &, const Color &, const Color &, const Color &=Color::Black, const Color &=Color::Black, const Color &=Color::Black, const Color &=Color::Black)
 Bi-cubic interpolation between four values, given partial derivatives. More...
 
static Color Bilinear (const Color &, const Color &, const Color &, const Color &, const double &, const double &)
 Bi-linear interpolation between four colors. More...
 
static const Color Grey (const double &)
 Grey. More...
 

Static Public Attributes

static const Color Black
 Black.
 
static const Color White
 White.
 
static const Color Red
 Red.
 
static const Color Blue
 Blue.
 
static const Color Transparent
 Transparent.
 

Protected Attributes

double c [4]
 Array of color components; includes an alpha channel.
 

Friends

Color operator+ (const Color &, const Color &)
 Overloaded sum operator.
 
Color operator- (const Color &, const Color &)
 Overloaded difference operator.
 
Color operator* (const Color &, const double &)
 Overloaded product by a scalar operator.
 
Color operator* (const double &, const Color &)
 Overloaded product by a scalar operator. More...
 
Color operator/ (const Color &, const double &)
 Overloaded division by a scalar operator. More...
 
std::ostream & operator<< (std::ostream &, const Color &)
 Overloaded output-stream operator. More...
 

Detailed Description

Color with alpha channel in RGB space.

Colors are represented using double.

Several constructors exist, two of them may be confusing:

Color c(127,24,216); // Use constructor with integer parameters in [0,255] range.
Color c(0.5,0.1,0.84); // Use double parameters, in [0.0,1.0] range.
Color with alpha channel in RGB space.
Definition: color.h:14
double c[4]
Array of color components; includes an alpha channel.
Definition: color.h:16

Constructor & Destructor Documentation

◆ Color() [1/6]

Color::Color ( const double &  v = 0.0)
inlineexplicit

Creates a greyscale color.

Initializes all the components to the given value except the opacity coefficient wich is set to 1.0.

Parameters
vGrey value.

◆ Color() [2/6]

Color::Color ( unsigned long  x)
inlineexplicit

Creates a color given a compact color representation.

Parameters
xColor compacted into an unsigned long.

◆ Color() [3/6]

Color::Color ( const double &  r,
const double &  g,
const double &  b,
const double &  a = 1.0 
)
inlineexplicit

Creates a color given each of these components.

Parameters
r,g,bRed, green and blue components.
aAlpha channel, set to 1.0 (opaque) as default.

◆ Color() [4/6]

Color::Color ( int  r,
int  g,
int  b,
int  a = 255 
)
inlineexplicit

Create a color given integer components.

Parameters
r,g,bRed, green and blue components.
aAlpha channel, set to 255 (opaque) as default.

◆ Color() [5/6]

Color::Color ( const QColor &  c)
explicit

Create a color from Qt representation.

Parameters
cColor in Qt.

◆ Color() [6/6]

Color::Color ( const QRgb &  c)
explicit

Create a color from Qt representation.

Parameters
cColor in Qt.

Member Function Documentation

◆ BiCubic()

Color Color::BiCubic ( const double &  u,
const double &  v,
const Color a00,
const Color a10,
const Color a11,
const Color a01,
const Color u00,
const Color u10,
const Color u11,
const Color u01,
const Color v00,
const Color v10,
const Color v11,
const Color v01,
const Color x00 = Color::Black,
const Color x10 = Color::Black,
const Color x11 = Color::Black,
const Color x01 = Color::Black 
)
static

Bi-cubic interpolation between four values, given partial derivatives.

The values are given in trigonometric order.

See also
Math::BiCubic
Parameters
u,vInterpolation coefficients.
a00,a10,a11,a01Interpolated values.
u00,u10,u11,u01,v00,v10,v11,v01Partial derivatives with respect to u and v.
x00,x10,x11,x01Cross derivatives.

◆ Bilinear()

Color Color::Bilinear ( const Color a00,
const Color a10,
const Color a11,
const Color a01,
const double &  u,
const double &  v 
)
static

Bi-linear interpolation between four colors.

See also
Math::Bilinear
Parameters
a00,a10,a11,a01Interpolated colors.
u,vInterpolation coefficients.

◆ Clamp()

Color Color::Clamp ( const Color a = Color::Black,
const Color b = Color::White 
) const
inline

Clamp a color between two bounds.

Parameters
a,bColor bounds.

◆ Get()

Color Color::Get ( const QVector< Color > &  c,
const double &  t 
)
static

Compute a color in a discretized array of colors.

Parameters
cArray of colors.
tInterpolation factor.

◆ GetQt()

QColor Color::GetQt ( ) const
inline

Create a Qt color from a color.

Example how to write a pixel with a given color in an image:

QImage image;
image.setPixel(i, j, c.GetQt().rgb());

◆ Grey()

const Color Color::Grey ( const double &  g)
inlinestatic

Grey.

Same as Color(const double&)

Parameters
gGrey level.

◆ Lerp()

Color Color::Lerp ( const double &  t,
const Color a,
const Color b 
)
inlinestatic

Linear interpolation between two colors.

Interpolation is performed in RGB space.

Note that the following lines are equivalent:

Color a,b;
double t;
Color c=(1.0-t)*a+t*b;
Color c=Lerp(t,a,b);
static Color Lerp(const double &, const Color &, const Color &)
Linear interpolation between two colors.
Definition: color.h:120

◆ LerpQt()

QColor Color::LerpQt ( const QColor &  a,
const QColor &  b,
const double &  t,
int  s 
)
static

Interpolate two Qt colors in the prescribed space.

The color space can be QColor::Rgb, QColor::Hsv, QColor::Cmyk or QColor::Hsl.

Parameters
a,bColors.
tInterpolation parameter.
sColor space.

◆ Max()

Color Color::Max ( const Color a,
const Color b 
)
static

Returns the maximum value of each component.

Parameters
a,bArgument colors.

◆ Min()

Color Color::Min ( const Color a,
const Color b 
)
static

Returns the minimum value of each component.

Parameters
a,bArgument colors.

◆ operator[]() [1/2]

constexpr double & Color::operator[] ( int  i)
inlineconstexpr

Returns the ith channel of the spectrum.

Parameters
inummber of the channel queried (default=last)

◆ operator[]() [2/2]

constexpr double Color::operator[] ( int  i) const
inlineconstexpr

Returns a copy of the ith channel of the spectrum.

Parameters
inummber of the channel queried (default=last)

◆ Pow()

Color Color::Pow ( const double &  gamma = 2.2)

Apply gamma correction.

Parameters
gammaExponential coefficient.

◆ Scale()

Color Color::Scale ( const Color v) const
inline

Scale.

Parameters
vColor.

Friends And Related Function Documentation

◆ operator*

Color operator* ( const double &  a,
const Color c 
)
friend

Overloaded product by a scalar operator.

Parameters
cColor.
aScalar.

◆ operator/

Color operator/ ( const Color c,
const double &  a 
)
friend

Overloaded division by a scalar operator.

Parameters
cColor.
aScalar.

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const Color c 
)
friend

Overloaded output-stream operator.

Parameters
cColor.
sStream.