Deluge Firmware 1.3.0
Build date: 2025.04.16
Loading...
Searching...
No Matches
RGB Class Reference

This class represents the colour format most used by the Deluge globally. More...

#include <rgb.h>

Public Types

using channel_type = uint8_t
 The size of each colour channel.
 

Public Member Functions

constexpr RGBoperator= (const RGB &other)=default
 Copies RGB values from a colour.
 
template<typename UnaryOp>
requires std::convertible_to<UnaryOp, std::function<channel_type(channel_type)>>
constexpr RGB transform (UnaryOp transformFn) const
 Create a new colour by transforming each channel of a colour.
 
constexpr RGB forTail () const
 Create a derived colour for tails (used by views)
 
constexpr RGB forBlur () const
 Create a derived colour for blurs (used by views)
 
constexpr RGB dim (uint8_t level=1) const
 Dim a colour.
 
constexpr RGB dull () const
 Dull a colour, clamping it to [5, 50].
 
constexpr RGB greyOut (int32_t proportion)
 Grey out a colour.
 
bool operator== (RGB const &) const =default
 Compare two colours to determine if they're the same.
 
constexpr channel_typeoperator[] (size_t idx)
 Legacy access to the colour internals for ease of use.
 
constexpr channel_typebegin ()
 Iterator constructor pointing to the beginning of this structure.
 
constexpr channel_typeend ()
 Iterator constructor for the end sentinel of this structure.
 
constexpr RGB adjust (uint8_t intensity, uint8_t brightnessDivider) const
 Adjust a colour by altering its intensity and brightness.
 
constexpr RGB adjustFractional (uint16_t numerator, uint16_t divisor) const
 Adjust a colour by altering its intensity and brightness. Intensity/brightnessDivider must be less than 1.
 
constexpr RGB rotate ()
 

Static Public Member Functions

static constexpr RGB monochrome (uint8_t brightness)
 Construct a monochrome (white) shade.
 
static RGB fromHue (int32_t hue)
 Construct a colour from a hue.
 
static RGB fromHuePastel (int32_t hue)
 Construct a colour from a hue.
 
static constexpr RGB average (RGB colourA, RGB colourB)
 Average two colours together.
 
static constexpr RGB blend (RGB sourceA, RGB sourceB, uint16_t index)
 Generate a new colour made from blending two source colours.
 
static constexpr RGB blend2 (RGB sourceA, RGB sourceB, uint16_t indexA, uint16_t indexB)
 Generate a new colour made from blending two source colours with individual proportions.
 
static constexpr size_t size ()
 Used in combination with operator[] and begin end.
 
template<typename BinaryOp>
requires std::convertible_to<BinaryOp, std::function<channel_type(channel_type, channel_type)>>
static constexpr RGB transform2 (RGB colourA, RGB colourB, BinaryOp transformFn)
 Create a new colour by transforming the channels of two colours.
 

Public Attributes

channel_type r = 0
 Red channel.
 
channel_type g = 0
 Green channel.
 
channel_type b = 0
 Blue channel.
 

Static Public Attributes

static constexpr auto channel_min = std::numeric_limits<channel_type>::min()
 
static constexpr auto channel_max = std::numeric_limits<channel_type>::max()
 

Private Member Functions

constexpr RGB xform (const uint32_t mat[4][4])
 

Static Private Member Functions

static constexpr channel_type blendChannel (uint32_t channelA, uint32_t channelB, uint16_t index)
 Blend a channel in equal proportions.
 
static constexpr channel_type blendChannel2 (uint32_t channelA, uint32_t channelB, uint16_t indexA, uint16_t indexB)
 Blend two channels in differing proportions.
 

Static Private Attributes

static constexpr uint32_t IMat [4][4]
 
static constexpr float c = 0.5403f
 
static constexpr float s = 0.8414f
 
static constexpr uint32_t RMat [4][4]
 

Detailed Description

This class represents the colour format most used by the Deluge globally.

Member Function Documentation

◆ adjust()

RGB RGB::adjust ( uint8_t intensity,
uint8_t brightnessDivider ) const
inlinenodiscardconstexpr

Adjust a colour by altering its intensity and brightness.

Returns
RGB The new colour

◆ adjustFractional()

RGB RGB::adjustFractional ( uint16_t numerator,
uint16_t divisor ) const
inlinenodiscardconstexpr

Adjust a colour by altering its intensity and brightness. Intensity/brightnessDivider must be less than 1.

Returns
RGB The new colour

◆ average()

static constexpr RGB RGB::average ( RGB colourA,
RGB colourB )
inlinestaticconstexpr

Average two colours together.

Parameters
colourAThe first colour
colourBThe second colour
Returns
RGB A composite average of the channel values of the component colours

◆ begin()

channel_type * RGB::begin ( )
inlineconstexpr

Iterator constructor pointing to the beginning of this structure.

Warning
Strongly relies on both the sizeof() and byte layout of this object (i.e. that it is a POD and 3 bytes)
Returns
constexpr channel_type* The first channel

◆ blend()

static constexpr RGB RGB::blend ( RGB sourceA,
RGB sourceB,
uint16_t index )
inlinestaticnodiscardconstexpr

Generate a new colour made from blending two source colours.

Parameters
sourceAThe first colour
sourceBThe second colour
indexThe blend amount. You can think of this as a slider from one RGB to the other
Returns
RGB The new blended colour

◆ blend2()

static constexpr RGB RGB::blend2 ( RGB sourceA,
RGB sourceB,
uint16_t indexA,
uint16_t indexB )
inlinestaticnodiscardconstexpr

Generate a new colour made from blending two source colours with individual proportions.

Parameters
sourceAThe first colour
sourceBThe second colour
indexAThe blend amount for sourceA
indexBThe blend amount for sourceB
Returns
RGB The new blended colour

◆ blendChannel()

static constexpr channel_type RGB::blendChannel ( uint32_t channelA,
uint32_t channelB,
uint16_t index )
inlinestaticconstexprprivate

Blend a channel in equal proportions.

Returns
The blended channel value

◆ blendChannel2()

static constexpr channel_type RGB::blendChannel2 ( uint32_t channelA,
uint32_t channelB,
uint16_t indexA,
uint16_t indexB )
inlinestaticconstexprprivate

Blend two channels in differing proportions.

Returns
The blended channel value

◆ dim()

RGB RGB::dim ( uint8_t level = 1) const
inlinenodiscardconstexpr

Dim a colour.

Parameters
levelHow much to dim (up to 8)
Returns
RGB The dimmed colour

◆ dull()

RGB RGB::dull ( ) const
inlinenodiscardconstexpr

Dull a colour, clamping it to [5, 50].

This is only used by the ArrangerView and its parent, View

See also
ArrangerView#drawMuteSquare
View::getClipMuteSquareColour
Returns
RGB the dulled colour

◆ end()

channel_type * RGB::end ( )
inlineconstexpr

Iterator constructor for the end sentinel of this structure.

Warning
Strongly relies on both the sizeof() and byte layout of this object (i.e. that it is a POD and 3 bytes)
Returns
constexpr channel_type* One byte past the last channel

◆ forBlur()

RGB RGB::forBlur ( ) const
inlinenodiscardconstexpr

Create a derived colour for blurs (used by views)

Returns
RGB The derived colour

◆ forTail()

RGB RGB::forTail ( ) const
inlinenodiscardconstexpr

Create a derived colour for tails (used by views)

Returns
RGB The derived colour

◆ fromHue()

RGB RGB::fromHue ( int32_t hue)
static

Construct a colour from a hue.

Parameters
hueThe hue value
Returns
RGB The colour

◆ fromHuePastel()

RGB RGB::fromHuePastel ( int32_t hue)
static

Construct a colour from a hue.

Parameters
hueThe hue value
Returns
RGB A pastel colour

◆ greyOut()

RGB RGB::greyOut ( int32_t proportion)
inlinenodiscardconstexpr

Grey out a colour.

Parameters
proportionThe amount to grey out
Returns
RGB The resulting colour

◆ monochrome()

static constexpr RGB RGB::monochrome ( uint8_t brightness)
inlinestaticconstexpr

Construct a monochrome (white) shade.

Parameters
brightnessThe brightness level
Returns
RGB The constructed colour

◆ operator==()

bool RGB::operator== ( RGB const & ) const
default

Compare two colours to determine if they're the same.

Returns
bool The true / false result if they're the equal

◆ operator[]()

channel_type & RGB::operator[] ( size_t idx)
inlineconstexpr

Legacy access to the colour internals for ease of use.

Parameters
idxThe channel to access (order R G B)
Returns
channel_type& The channel

◆ rotate()

RGB RGB::rotate ( )
inlineconstexpr

This rotates the colour in fromRgb by 1 radian and places it in rgb This is useful to generate a complementary colour with the same brightness

◆ size()

static constexpr size_t RGB::size ( )
inlinestaticconstexpr

Used in combination with operator[] and begin end.

Returns
constexpr size_t The size of this 'container'

◆ transform()

template<typename UnaryOp>
requires std::convertible_to<UnaryOp, std::function<channel_type(channel_type)>>
RGB RGB::transform ( UnaryOp transformFn) const
inlinenodiscardconstexpr

Create a new colour by transforming each channel of a colour.

Template Parameters
UnaryOpThe function type (should be equivalent to std::function<channel_type(channel_type)>)
Parameters
transformFnThe function to apply to each channel, taking a channel_type value and returning a channel_type value
Returns
RGB The new colour

◆ transform2()

template<typename BinaryOp>
requires std::convertible_to<BinaryOp, std::function<channel_type(channel_type, channel_type)>>
static constexpr RGB RGB::transform2 ( RGB colourA,
RGB colourB,
BinaryOp transformFn )
inlinestaticconstexpr

Create a new colour by transforming the channels of two colours.

Template Parameters
BinaryOpThe function type (should be equivalent to std::function<channel_type(channel_type, channel_type)>)
Parameters
colourAThe first colour
colourBThe second colour
transformFnThe transformer function, taking two channel_type values and returning a channel_type value
Returns
RGB The new colour

Member Data Documentation

◆ channel_max

auto RGB::channel_max = std::numeric_limits<channel_type>::max()
staticconstexpr

The maximum value each channel can hold. Useful for std::clamp<>(val, RGB::channel_min, RGB::channel_max)

◆ channel_min

auto RGB::channel_min = std::numeric_limits<channel_type>::min()
staticconstexpr

The maximum value each channel can hold. Useful for std::clamp<>(val, RGB::channel_min, RGB::channel_max)

◆ IMat

uint32_t RGB::IMat[4][4]
staticconstexprprivate
Initial value:
= {
{ONE_Q16, 0, 0, 0},
{0, ONE_Q16, 0, 0},
{0, 0, ONE_Q16, 0},
{0, 0, 0, ONE_Q16},
}

◆ RMat

uint32_t RGB::RMat[4][4]
staticconstexprprivate
Initial value:
= {
{(uint32_t)(c * ONE_Q16), 0, (uint32_t)(s* ONE_Q16), 0},
{(uint32_t)(s * ONE_Q16), (uint32_t)(c* ONE_Q16), 0, 0},
{0, (uint32_t)(s* ONE_Q16), (uint32_t)(c* ONE_Q16), 0},
{0, 0, 0, ONE_Q16},
}

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