Gorgon Game Engine
RGBA Class Reference

This class represents a color information. More...

Public Types

typedef Byte ChannelType
 Data type for each channel. More...
 

Public Member Functions

 RGBA ()
 Default constructor does not perform initialization. More...
 
 RGBA (Byte lum, Byte a=255)
 Constructs a grayscale color from the given luminance. More...
 
 RGBA (Byte r, Byte g, Byte b, Byte a=255)
 Filling constructor. More...
 
 RGBA (const RGBA &)=default
 Copy constructor. More...
 
 RGBA (const RGBA &first, const RGBA &second, double alpha)
 Blending constructor. More...
 
 RGBA (const RGBA &first, const RGBA &second, float alpha=1.0f)
 Blending constructor. More...
 
 RGBA (const RGBA &first, const RGBA &second, int alpha)
 Blending constructor. More...
 
 RGBA (const RGBA &other, Byte newalpha)
 Copy constructor with new alpha value. More...
 
 RGBA (const RGBA &other, double newalpha)
 Copy constructor with new alpha value. More...
 
 RGBA (const RGBA &other, float newalpha)
 Copy constructor with new alpha value. More...
 
 RGBA (const RGBA &other, int newalpha)
 Copy constructor with new alpha value. More...
 
 RGBA (double lum)
 Conversion from float. Assumes the given float value is a 0 to 1 luminance. Sets alpha to 255. More...
 
 RGBA (float lum)
 Conversion from float. Assumes the given float value is a 0 to 1 luminance. Sets alpha to 255. More...
 
constexpr RGBA (int color)
 Conversion from integer. More...
 
 RGBA (int lum, int a)
 Constructs a grayscale color from the given luminance. More...
 
constexpr RGBA (uint32_t color)
 Conversion from uint32_t. More...
 
float AccurateLuminance () const
 Returns the luminance of this color as a floating point value between 0 and 1. More...
 
void Blend (const RGBA &color)
 Blends the given color into this one. More...
 
void Blend (const RGBA &color, float alpha)
 Blends the given color into this one. More...
 
RGBA BlendWith (const RGBA &color) const
 Blends the current color with the given color and returns the result. More...
 
RGBA BlendWith (const RGBA &color, float alpha) const
 Blends the current color with the given color and returns the result. More...
 
std::string HTMLColor () const
 Returns a six nibble HTML color. More...
 
Byte Luminance () const
 Returns the luminance of this color as a single byte number. More...
 
 operator int () const
 Conversion to integer. More...
 
 operator std::string () const
 Converts this color to a hex representation of this color. More...
 
 operator uint32_t () const
 Conversion to integer. More...
 
bool operator!= (const RGBA &other) const
 Compares two colors. More...
 
RGBAoperator= (const int &color)
 From integer assignment. More...
 
RGBAoperator= (const RGBA &)=default
 Copy assignment. More...
 
RGBAoperator= (const uint32_t &color)
 From integer assignment. More...
 
RGBAoperator= (float lum)
 From float assignment. Assumes the given float value is a 0 to 1 luminance. Sets alpha to 255. More...
 
bool operator== (const RGBA &other) const
 Compares two colors. More...
 

Public Attributes

Byte A
 Alpha channel. More...
 
Byte B
 Blue channel. More...
 
Byte G
 Green channel. More...
 
Byte R
 Red channel. More...
 

Detailed Description

This class represents a color information.

Contains 4 channels, 8 bits each. Red is the lowest bit while alpha is the highest. Please note that conversion from/to integer will work in reverse of the HTML notation. 0xff800000 is dark blue not dark red.

Member Typedef Documentation

◆ ChannelType

typedef Byte ChannelType

Data type for each channel.

Constructor & Destructor Documentation

◆ RGBA() [1/16]

RGBA ( )

Default constructor does not perform initialization.

◆ RGBA() [2/16]

RGBA ( const RGBA )
default

Copy constructor.

◆ RGBA() [3/16]

RGBA ( const RGBA other,
Byte  newalpha 
)

Copy constructor with new alpha value.

◆ RGBA() [4/16]

RGBA ( const RGBA other,
int  newalpha 
)

Copy constructor with new alpha value.

◆ RGBA() [5/16]

RGBA ( const RGBA other,
double  newalpha 
)

Copy constructor with new alpha value.

◆ RGBA() [6/16]

RGBA ( const RGBA other,
float  newalpha 
)

Copy constructor with new alpha value.

◆ RGBA() [7/16]

RGBA ( const RGBA first,
const RGBA second,
float  alpha = 1.0f 
)

Blending constructor.

References RGBA::Blend().

◆ RGBA() [8/16]

RGBA ( const RGBA first,
const RGBA second,
double  alpha 
)

Blending constructor.

References RGBA::Blend().

◆ RGBA() [9/16]

RGBA ( const RGBA first,
const RGBA second,
int  alpha 
)

Blending constructor.

◆ RGBA() [10/16]

RGBA ( Byte  r,
Byte  g,
Byte  b,
Byte  a = 255 
)

Filling constructor.

◆ RGBA() [11/16]

RGBA ( Byte  lum,
Byte  a = 255 
)
explicit

Constructs a grayscale color from the given luminance.

◆ RGBA() [12/16]

RGBA ( int  lum,
int  a 
)
explicit

Constructs a grayscale color from the given luminance.

◆ RGBA() [13/16]

constexpr RGBA ( int  color)
constexpr

Conversion from integer.

◆ RGBA() [14/16]

constexpr RGBA ( uint32_t  color)
constexpr

Conversion from uint32_t.

◆ RGBA() [15/16]

RGBA ( float  lum)
explicit

Conversion from float. Assumes the given float value is a 0 to 1 luminance. Sets alpha to 255.

References RGBA::B, RGBA::G, and RGBA::R.

◆ RGBA() [16/16]

RGBA ( double  lum)
explicit

Conversion from float. Assumes the given float value is a 0 to 1 luminance. Sets alpha to 255.

References RGBA::B, RGBA::G, and RGBA::R.

Member Function Documentation

◆ AccurateLuminance()

float AccurateLuminance ( ) const

Returns the luminance of this color as a floating point value between 0 and 1.

The conversion is done to preserve perceived luminance.

References RGBA::B, RGBA::G, and RGBA::R.

◆ Blend() [1/2]

void Blend ( const RGBA color)

Blends the given color into this one.

This operation performs regular alpha blending with the current color being blended over.

◆ Blend() [2/2]

void Blend ( const RGBA color,
float  alpha 
)

Blends the given color into this one.

This operation performs regular alpha blending with the current color being blended over.

References RGBA::A, RGBA::B, RGBA::G, and RGBA::R.

◆ BlendWith() [1/2]

RGBA BlendWith ( const RGBA color) const

Blends the current color with the given color and returns the result.

References RGBA::Blend().

◆ BlendWith() [2/2]

RGBA BlendWith ( const RGBA color,
float  alpha 
) const

Blends the current color with the given color and returns the result.

References RGBA::Blend().

◆ HTMLColor()

std::string HTMLColor ( ) const

Returns a six nibble HTML color.

References RGBA::B, RGBA::G, and RGBA::R.

◆ Luminance()

Byte Luminance ( ) const

Returns the luminance of this color as a single byte number.

The returned number could be supplied to a new color to create grayscale representation of this color. This function performs lots of shifts to calculate a luminance close to perceived grayscale value. Probably works even slower than accurate luminance, however, the value returned is directly a byte.

References RGBA::B, RGBA::G, and RGBA::R.

◆ operator int()

operator int ( ) const

Conversion to integer.

◆ operator std::string()

operator std::string ( ) const

Converts this color to a hex representation of this color.

◆ operator uint32_t()

operator uint32_t ( ) const

Conversion to integer.

◆ operator!=()

bool operator!= ( const RGBA other) const

Compares two colors.

◆ operator=() [1/4]

RGBA& operator= ( const int &  color)

From integer assignment.

◆ operator=() [2/4]

RGBA& operator= ( const RGBA )
default

Copy assignment.

◆ operator=() [3/4]

RGBA& operator= ( const uint32_t &  color)

From integer assignment.

◆ operator=() [4/4]

RGBA& operator= ( float  lum)

From float assignment. Assumes the given float value is a 0 to 1 luminance. Sets alpha to 255.

References RGBA::A, RGBA::B, RGBA::G, and RGBA::R.

◆ operator==()

bool operator== ( const RGBA other) const

Compares two colors.

Member Data Documentation

◆ A

Byte A

Alpha channel.

◆ B

Byte B

Blue channel.

◆ G

Byte G

Green channel.

◆ R

Byte R

Red channel.


The documentation for this class was generated from the following file: