Main Page   Class Hierarchy   Alphabetical List   Compound List   Compound Members  

prapi::Color< T, comps > Class Template Reference

#include <Color.h>

List of all members.


Detailed Description

template<class T, int comps>
class prapi::Color< T, comps >

A universal representation of a color.

A color may have any number of components that can be stored as any data types. It is advisable not to use class types as color components because color copies are implemented as raw memory transfers. Constructors are thus not called.


Public Methods

 Color ()
 The default constructor.

 Color (T value)
 Construct a new color whose components are reset to the given value.

 Color (const Color &other)
 The copy constructor.

template<class U>  Color (const Color< U, comps > &other)
 Create a typecasted copy of another color.

getComponent (int index)
 Get a color component.

void setComponent (int index, T value)
 Set the value of a color channel.

T * getComponents (void)
 Get the color components as an array.

void setComponents (T *array)
 Set the color components all at once.

Color & operator= (const Color &other)
 Copy a color.

Color & operator= (T value)
 Set all color channels to the same value.

T & operator[] (int index)
 Get a given color channel.

operator[] (int index) const
 Get a given color channel.

void operator+= (Color other)
 Add the corresponding color channels together.

void operator-= (Color other)
 Subract the corresponding color channels from each other.

void operator *= (Color other)
 Multiply corresponding color channels by each other.

void operator/= (Color other)
 Divide corresponding color channels by each other.

void operator *= (double value)
 Multiply all channels by a value.

void operator/= (double value)
 Divide all channels by a value.

void operator+= (double value)
 Add a value to all color channels.

void operator-= (double value)
 Subtract a value from all color channels.

template<class U>  operator Color ()
 Cast a color to a different type of color.

template<class U> Color & operator= (const Color< U, comps > &other)
 Make a typecasted copy of a color.


Protected Attributes

_aComponents [comps]
 The component array.


Friends

class ColorTransform
template<class U, int nc> bool operator== (const Color< U, nc > &clr1, const Color< U, nc > &clr2)
 Compare two colors.

template<class U, int nc> bool operator!= (const Color< U, nc > &clr1, const Color< U, nc > &clr2)
 Compare two colors.

template<class U, int nc> Color< U, nc > operator * (const Color< U, nc > &clr, double value)
 Multiply all channes by a value.

template<class U, int nc> Color< U, nc > operator/ (const Color< U, nc > &clr, double value)
 Divide all channes by a value.

template<class U, int nc> Color< U, nc > operator+ (const Color< U, nc > &clr, double value)
 Add a value to all channes.

template<class U, int nc> Color< U, nc > operator- (const Color< U, nc > &clr, double value)
 Subtract a value from all channes.

template<class U, int nc> Color< U, nc > operator+ (const Color< U, nc > &clr1, const Color< U, nc > &clr2)
 Sum corresponding channels together.

template<class U, int nc> Color< U, nc > operator- (const Color< U, nc > &clr1, const Color< U, nc > &clr2)
 Subtract corresponding channels from each other.

template<class U, int nc> Color< U, nc > operator * (const Color< U, nc > &clr1, const Color< U, nc > &clr2)
 Multiply corresponding channels by each other.

template<class U, int nc> Color< U, nc > operator/ (const Color< U, nc > &clr1, const Color< U, nc > &clr2)
 Divide corresponding channels by each other.

template<class U, int nc> std::ostream & operator<< (std::ostream &sout, const Color< U, nc > &c)
 Write to a stream.

template<class U, int nc> std::istream & operator>> (std::istream &sin, Color< U, nc > &c)
 Read from a stream.

template<class U, class V, int nc> Color< double, nc > operator * (const util::Matrix< V > &mat, const Color< U, nc > &clr) throw (util::MatrixException&)
 Transform this a color by a comps-by-comps transformation matrix.


Constructor & Destructor Documentation

template<class T, int comps>
prapi::Color< T, comps >::Color   [inline]
 

The default constructor.

Initializes the component array by filling it with zero bytes. Using floating point component values may result in weird initial values and you may want to use the Color(value) constructor instead.

template<class T, int comps>
prapi::Color< T, comps >::Color   value [inline]
 

Construct a new color whose components are reset to the given value.

Parameters:
value  the initial value for all of the color components


Member Function Documentation

template<class T, int comps>
T prapi::Color< T, comps >::getComponent int    index [inline]
 

Get a color component.

For example, in an RGB color, index 0 represents the green channel and index 2 represents the blue channel.

Parameters:
index  the channel index

template<class T, int comps>
T* prapi::Color< T, comps >::getComponents void    [inline]
 

Get the color components as an array.

Returns:
a pointer to the internal color component array

template<class T, int comps>
T prapi::Color< T, comps >::operator[] int    index const [inline]
 

Get a given color channel.

See also:
getComponent(int)

template<class T, int comps>
T& prapi::Color< T, comps >::operator[] int    index [inline]
 

Get a given color channel.

See also:
getComponent(int)

template<class T, int comps>
void prapi::Color< T, comps >::setComponent int    index,
  value
[inline]
 

Set the value of a color channel.

Parameters:
index  the channel index
value  the new value for this channel

template<class T, int comps>
void prapi::Color< T, comps >::setComponents T *    array [inline]
 

Set the color components all at once.

Parameters:
array  an array with an entry for each color channel.


Friends And Related Function Documentation

template<class T, int comps>
template<class U, int nc>
bool operator!= const Color< U, nc > &    clr1,
const Color< U, nc > &    clr2
[friend]
 

Compare two colors.

Colors are different if any of their corresponding components are different.

template<class T, int comps>
template<class U, int nc>
bool operator== const Color< U, nc > &    clr1,
const Color< U, nc > &    clr2
[friend]
 

Compare two colors.

Colors are equal if all of their corresponding components are equal.


The documentation for this class was generated from the following file:
Documentation generated on 11.09.2003 with Doxygen.
The documentation is copyrighted material.
Copyright © Topi Mäenpää 2003. All rights reserved.