Ray Tracer Common Project
Image rendering program based on the ray tracing technique.
Public Member Functions | Static Public Attributes | List of all members
rt::color Class Reference

RGBA color representation. More...

#include <color.hpp>

Public Member Functions

 color ()
 
 color (const color &c)
 
 color (double r, double g, double b, double a=1.0)
 
virtual void set_red (double r)
 
virtual void set_green (double g)
 
virtual void set_blue (double b)
 
virtual void set_alpha (double a)
 
double red () const
 
double green () const
 
double blue () const
 
double alpha () const
 
virtual bool operator== (const color &c) const
 
color operator+ (const color &c) const
 Color addition. More...
 
void operator+= (const color &c)
 Color addition See color::operator+ for details.
 
color operator* (const color &c) const
 Color multiplication. More...
 
void operator*= (const color &c)
 Color multiplication. More...
 
void operator*= (double f)
 Double multiplication. More...
 
color operator* (double f) const
 Double multiplication. More...
 
virtual operator uint32 () const
 Cast operator to unsigned 32bits int. More...
 
uint32 map (SDL_PixelFormat *) const
 SDL convertion operator. More...
 

Static Public Attributes

static color WHITE = color(1.0, 1.0, 1.0)
 default white color.
 
static color GRAY = color(0.5, 0.5, 0.5)
 default gray color.
 
static color BLACK = color(0.0, 0.0, 0.0)
 default black color.
 
static color BLUE = color(0.0, 0.0, 1.0)
 default blue color.
 
static color GREEN = color(0.0, 1.0, 0.0)
 default green color.
 
static color RED = color(1.0, 0.0, 0.0)
 default red color.
 

Detailed Description

RGBA color representation.

The color class represents a color through its four components: red, green, blue and alpha (RGBA). All components are normalized into [0, 1].

Constructor & Destructor Documentation

◆ color() [1/3]

rt::color::color ( )

Default constructor. Builds a white color.

◆ color() [2/3]

rt::color::color ( const color c)

Copy constructor.

◆ color() [3/3]

rt::color::color ( double  r,
double  g,
double  b,
double  a = 1.0 
)

Builds a color from its red, green and blue components. Alpha is set to 255.

Member Function Documentation

◆ alpha()

double rt::color::alpha ( ) const
inline

Returns the alpha component.

◆ blue()

double rt::color::blue ( ) const
inline

Returns the blue component.

◆ green()

double rt::color::green ( ) const
inline

Returns the green component.

◆ map()

uint32 rt::color::map ( SDL_PixelFormat *  format) const

SDL convertion operator.

Cast the color into the SDL pixel format representation.

◆ operator uint32()

rt::color::operator uint32 ( ) const
virtual

Cast operator to unsigned 32bits int.

Represents the color as a unsigned 32b int, with red being the most significant byte.

◆ operator*() [1/2]

color rt::color::operator* ( const color c) const

Color multiplication.

Perform a multiplication, or absorbtion, between two colors. The multiplication is defined as follow:

For two colors \(src_{RGBA}\) and \(dst_{RGBA}\) (this color) the destination color will be:

\begin{eqnarray*} out_{RGB} &=& dst_{RGB}src_{RGB}src_A + dst_{RGB}(1-src_A)\\ out_A &=& dst_Asrc_A + dst_A(1-src_A) \end{eqnarray*}

◆ operator*() [2/2]

color rt::color::operator* ( double  f) const

Double multiplication.

Return a new color from this one with all components multiplied by a double value.

◆ operator*=() [1/2]

void rt::color::operator*= ( const color c)

Color multiplication.

See color::operator* for details.

◆ operator*=() [2/2]

void rt::color::operator*= ( double  f)

Double multiplication.

Multiply all components but alpha by a double value.

◆ operator+()

color rt::color::operator+ ( const color c) const

Color addition.

Perfom an additive blending between two colors. The blending is performed as follow:

For two colors \(src_{RGBA}\) and \(dst_{RGBA}\) (this color) the destination color will be:

\[ out_{RGBA} = src_{RGBA} + dst_{RGBA} \]

◆ operator==()

bool rt::color::operator== ( const color c) const
virtual

Comparison operator.

◆ red()

double rt::color::red ( ) const
inline

Returns the red component.

◆ set_alpha()

virtual void rt::color::set_alpha ( double  a)
inlinevirtual

Sets the alpha component.

◆ set_blue()

virtual void rt::color::set_blue ( double  b)
inlinevirtual

Sets the blue component.

◆ set_green()

virtual void rt::color::set_green ( double  g)
inlinevirtual

Sets the green component.

◆ set_red()

virtual void rt::color::set_red ( double  r)
inlinevirtual

Sets the red component.


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