NAP
Public Types | Public Member Functions | Public Attributes | List of all members
Color< T, CHANNELS > Class Template Reference

#include <color.h>

Public Types

using value_type = T
 
- Public Types inherited from BaseColor
using Converter = std::function< void(const BaseColor &, BaseColor &, int)>
 

Public Member Functions

 Color ()
 
 Color (const std::array< T, CHANNELS > &colors)
 
 Color (const nap::BaseColor &source)
 
rtti::TypeInfo getValueType () const override
 
bool isPointer () const override
 
getValue (EColorChannel channel) const
 
T & getValue (EColorChannel channel)
 
void setValue (EColorChannel channel, T value)
 
const std::array< T, CHANNELS > & getValues () const
 
T * getData ()
 
const T * getData () const
 
void setData (const T *data)
 
float getDistance (const Color< T, CHANNELS > &other) const
 
bool operator== (const Color< T, CHANNELS > &rhs) const
 
bool operator!= (const Color< T, CHANNELS > &rhs) const
 
bool operator< (const Color< T, CHANNELS > &rhs) const
 
bool operator> (const Color< T, CHANNELS > &rhs) const
 
bool operator<= (const Color< T, CHANNELS > &rhs) const
 
bool operator>= (const Color< T, CHANNELS > &rhs) const
 
T & operator[] (std::size_t index)
 
const T & operator[] (std::size_t index) const
 
- Public Member Functions inherited from BaseColor
 BaseColor (int channels, int size)
 
virtual ~BaseColor ()=default
 
bool operator== (const BaseColor &rhs)=delete
 
bool operator!= (const BaseColor &rhs)=delete
 
int getNumberOfChannels () const
 
int valueSize () const
 
void convert (BaseColor &target) const
 
Converter getConverter (const BaseColor &target) const
 
template<typename T >
convert () const
 
int size () const
 

Public Attributes

std::array< T, CHANNELS > mValues
 

Additional Inherited Members

- Static Public Member Functions inherited from BaseColor
static void convertColor (const BaseColor &source, BaseColor &target)
 
static void convertColor (const BaseColor &source, BaseColor &target, const Converter &converter)
 
static Converter getConverter (const BaseColor &source, const BaseColor &target)
 

Description

template<typename T, int CHANNELS>
class nap::Color< T, CHANNELS >

Specific type of color where T defines the value type of the color. Every color has at least 1 or more channels. Colors are always packed in the following order RGBA. This class can also be used to store pointers to colors and can therefore act as a convenient wrapper around bitmap color values. All color types can be hashed for convenience. This makes most sense for 8 and 16 bit color types. For float colors a simple x/or is used. In order to hash colors you should use one of the explicitly defined successive color types, ie: RGBA8, R8, RGBFloat etc.

Inheritance diagram for Color< T, CHANNELS >:
[legend]
Collaboration diagram for Color< T, CHANNELS >:
[legend]

Member Typedef Documentation

◆ value_type

using value_type = T

Constructor & Destructor Documentation

◆ Color() [1/3]

Color ( )

Constructor that simply creates a 0 initialized color

◆ Color() [2/3]

Color ( const std::array< T, CHANNELS > &  colors)

Constructor that creates a color based on a list of values. Note that the number of values in the array must match the number of channels. The order is important: RGBA.

// Create 8 bit RGBA color
RGBAColor8 eight_bit_color = { 0xC8, 0x69, 0x69, 0xFF };

◆ Color() [3/3]

Color ( const nap::BaseColor< T, CHANNELS > &  source)

Initializes this color using a different type of color. Colors are converted automatically. The source color must have an equal or higher amount of channels.

Parameters
sourcethe color to initialize this color with.

Member Function Documentation

◆ getData() [1/2]

T* getData ( )
Returns
pointer to the beginning of the data

◆ getData() [2/2]

const T* getData ( ) const
Returns
pointer to the begging of the data

◆ getDistance()

float getDistance ( const Color< T, CHANNELS > &  other) const

Computes the distance between this and another color in Euclidean space. The result is not squared

Parameters
otherthe color to compare against
Returns
the non squared distance between this and another color

◆ getValue() [1/2]

T & getValue ( EColorChannel  channel)
Parameters
channelthe channel to get the value for
Returns
reference to the color value associated with the specified channel This call asserts when the channel is not available

◆ getValue() [2/2]

T getValue ( EColorChannel  channel) const

Returns the color value associated with a given channel. This call asserts when the channel is not available.

Parameters
channelthe channel to get the value for
Returns
the color value associated with the specified channel

◆ getValues()

const std::array<T, CHANNELS>& getValues ( ) const
Returns
all the values associated with this color

◆ getValueType()

rtti::TypeInfo getValueType ( ) const
overridevirtual
Returns
the type of the value

Implements BaseColor.

◆ isPointer()

bool isPointer
overridevirtual
Returns
if this color points to values in memory

Implements BaseColor.

◆ operator!=()

bool operator!= ( const Color< T, CHANNELS > &  rhs) const
Returns
if two color values are not similar

◆ operator<()

bool operator< ( const Color< T, CHANNELS > &  rhs) const
Returns
if the color value is less than another color Won't work when the color is a pointer

◆ operator<=()

bool operator<= ( const Color< T, CHANNELS > &  rhs) const
Returns
if the color value is less or equal to another color Won't work when the color is a pointer

◆ operator==()

bool operator== ( const Color< T, CHANNELS > &  rhs) const
Returns
if two color values are similar. Performs a value comparison when the color is not a pointer. Otherwise a pointer comparison.

◆ operator>()

bool operator> ( const Color< T, CHANNELS > &  rhs) const
Returns
if the color value higher than another color Won't work when the color is a pointer

◆ operator>=()

bool operator>= ( const Color< T, CHANNELS > &  rhs) const
Returns
if the color value is higher or equal to another color Won't work when the color is a pointer

◆ operator[]() [1/2]

T& operator[] ( std::size_t  index)

Array subscript overload. Does not perform a bounds check!

Returns
the color at index

◆ operator[]() [2/2]

const T& operator[] ( std::size_t  index) const

Array subscript overload. Does not perform a bounds check!

Returns
the color at index

◆ setData()

void setData ( const T *  data)

Set the color data associated with this color. This call assumes the data is of the right size and length. When this color points to a location in memory, that memory location is copied. Otherwise the actual values are copied over.

Parameters
datathe color data to copy, behind the scenes a memcopy is performed

◆ setValue()

void setValue ( EColorChannel  channel,
value 
)

Sets the color value for the incoming channel. This call asserts when the channel is not available.

Parameters
channelthe color channel to set
valuethe new color value

Member Data Documentation

◆ mValues

std::array<T, CHANNELS> mValues

Color values associated with this color

nap::RGBAColor8
RGBAColor< uint8 > RGBAColor8
Definition: color.h:578