sincerely Singaporean

If you have not done so, read this full tutorial on how to use SGEXTN to build an application.

SGXColourRGBA

see header file

see source file

class SGXColourRGBA;

part of SGEXTN module SG_Core

8bit RGBA colour

detailed description

list of all including inherited members

implementation details

preprocessor file inclusion directive: #include ‹SGXColourRGBA.h›

CMake target for BuildLah: SGEXTN::SG_Core

see this link for more information about BuildLah

parent class: (none)

children classes: (none)

instance member functions

SGXColourRGBA(int r, int g, int b, int a);

SGXColourRGBA(int r, int g, int b);

SGXColourRGBA(float r, float g, float b);

SGXColourRGBA(float r, float g, float b, float a);

SGXColourRGBA& applyTint(SGXColourRGBA x);

SGXColourRGBA& applyTintNoGammaCorrection(SGXColourRGBA x);

SGXColourRGBA& applyTintNoGammaCorrectionSeparateTransparency(SGXColourRGBA x, int a);

SGXColourRGBA& applyTintNoGammaCorrectionSeparateTransparencyUsingFloat(SGXColourRGBA x, float a);

SGXColourRGBA& applyTintSeparateTransparency(SGXColourRGBA x, int a);

SGXColourRGBA& applyTintSeparateTransparencyUsingFloat(SGXColourRGBA x, float a);

void gammaCorrectBegin(float& r, float& g, float& b) const;

void gammaCorrectEnd(float r, float g, float b);

[[nodiscard]] int getBlue() const;

[[nodiscard]] float getBlueAsFloat() const;

[[nodiscard]] int getGreen() const;

[[nodiscard]] float getGreenAsFloat() const;

[[nodiscard]] int getRed() const;

[[nodiscard]] float getRedAsFloat() const;

[[nodiscard]] SGXString getStringForPrintingRGBAFloatHTML() const;

[[nodiscard]] SGXString getStringForPrintingRGBAHTML() const;

[[nodiscard]] SGXString getStringForPrintingRGBAHex() const;

[[nodiscard]] SGXString getStringForPrintingRGBFloatHTML() const;

[[nodiscard]] SGXString getStringForPrintingRGBHTML() const;

[[nodiscard]] SGXString getStringForPrintingRGBHex() const;

[[nodiscard]] int getTransparency() const;

[[nodiscard]] float getTransparencyAsFloat() const;

[[nodiscard]] int hash() const;

[[nodiscard]] SGXColourRGBA linearInterpolate(SGXColourRGBA x, float f) const;

[[nodiscard]] SGXColourRGBA linearInterpolateGammaCorrection(SGXColourRGBA x, float f) const;

SGXColourRGBA& linearTransformBlue(float m, float c);

SGXColourRGBA& linearTransformBlueWithGamma(float m, float c);

SGXColourRGBA& linearTransformGreen(float m, float c);

SGXColourRGBA& linearTransformGreenWithGamma(float m, float c);

SGXColourRGBA& linearTransformRed(float m, float c);

SGXColourRGBA& linearTransformRedWithGamma(float m, float c);

SGXColourRGBA& linearTransformTransparency(float m, float c);

[[nodiscard]] bool operator!=(SGXColourRGBA x) const;

[[nodiscard]] bool operator‹(SGXColourRGBA x) const;

[[nodiscard]] bool operator==(SGXColourRGBA x) const;

[[nodiscard]] bool operator›(SGXColourRGBA x) const;

[[nodiscard]] float relativeContrast() const;

SGXColourRGBA& setBlue(int b);

SGXColourRGBA& setBlueUsingFloat(float b);

SGXColourRGBA& setGreen(int g);

SGXColourRGBA& setGreenUsingFloat(float g);

SGXColourRGBA& setRed(int r);

SGXColourRGBA& setRedUsingFloat(float r);

SGXColourRGBA& setTransparency(int a);

SGXColourRGBA& setTransparencyUsingFloat(float a);

SGXColourRGBA& toComplementColour();

Detailed Description

SGXColourRGBA represents a colour in RGBA format with 8 bits per channel. Each of the red, green, blue, and transparency channels can range between 0 to 255 inclusive. Features such as colour transformation and gamma correction are included also.

Implementation Details

SGXColourRGBA packs all 4 channels into 1 unsigned int.

SGXColourRGBA(int r, int g, int b, int a);

Creates a SGXColourRGBA from its components (red r, green g, blue b, transparency a).

Each channel should range from 0 to 255 inclusive. Out of bounds channels are corrected automatically.

Ensure that all arguments passed have a type of int, otherwise it may trigger the wrong constructor.

SGXColourRGBA(int r, int g, int b);

Creates a SGXColourRGBA from its components (red r, green g, blue b) with transparency assumed to be 255.

Each channel should range from 0 to 255 inclusive. Out of bounds channels are corrected automatically.

Ensure that all arguments passed have a type of int, otherwise it may trigger the wrong constructor.

SGXColourRGBA(float r, float g, float b);

Creates a SGXColourRGBA from its components (red r, green g, blue b) with transparency assumed to be 1.

Each channel should range from 0 to 1 inclusive. Out of bounds channels are corrected automatically.

Ensure that all arguments passed have a type of float, otherwise it may trigger the wrong constructor.

SGXColourRGBA(float r, float g, float b, float a);

Creates a SGXColourRGBA from its components (red r, green g, blue b, transparency a).

Each channel should range from 0 to 1 inclusive. Out of bounds channels are corrected automatically.

Ensure that all arguments passed have a type of float, otherwise it may trigger the wrong constructor.

SGXColourRGBA& applyTint(SGXColourRGBA x);

Sets this SGXColourRGBA to the resulting colour if this SGXColourRGBA is viewed behind a screen with colour x, with computation done in linear colour space and returns a reference to this SGXColourRGBA to allow operation chaining.

This does not change the transparency of this SGXColourRGBA.

SGXColourRGBA& applyTintNoGammaCorrection(SGXColourRGBA x);

Sets this SGXColourRGBA to the resulting colour if this SGXColourRGBA is viewed behind a screen with colour x and returns a reference to this SGXColourRGBA to allow operation chaining.

This does not change the transparency of this SGXColourRGBA.

SGXColourRGBA& applyTintNoGammaCorrectionSeparateTransparency(SGXColourRGBA x, int a);

Sets this SGXColourRGBA to the resulting colour if this SGXColourRGBA is viewed behind a screen with colour c, where c has equal RGB channels as x but a transparency of a between 0 and 255 inclusive and returns a reference to this SGXColourRGBA to allow operation chaining.

The computation proceeds anyways if a is out of bounds. This can be useful for effects that remove a certain colour.

This does not change the transparency of this SGXColourRGBA.

SGXColourRGBA& applyTintNoGammaCorrectionSeparateTransparencyUsingFloat(SGXColourRGBA x, float a);

Sets this SGXColourRGBA to the resulting colour if this SGXColourRGBA is viewed behind a screen with colour c, where c has equal RGB channels as x but a transparency of a between 0 and 1 inclusive and returns a reference to this SGXColourRGBA to allow operation chaining.

The computation proceeds anyways if a is out of bounds. This can be useful for effects that remove a certain colour.

This does not change the transparency of this SGXColourRGBA.

SGXColourRGBA& applyTintSeparateTransparency(SGXColourRGBA x, int a);

Sets this SGXColourRGBA to the resulting colour if this SGXColourRGBA is viewed behind a screen with colour c, where c has equal RGB channels as x but a transparency of a between 0 and 255 inclusive, with computation done in linear colour space and returns a reference to this SGXColourRGBA to allow operation chaining.

The computation proceeds anyways if a is out of bounds. This can be useful for effects that remove a certain colour.

This does not change the transparency of this SGXColourRGBA.

SGXColourRGBA& applyTintSeparateTransparencyUsingFloat(SGXColourRGBA x, float a);

Sets this SGXColourRGBA to the resulting colour if this SGXColourRGBA is viewed behind a screen with colour c, where c has equal RGB channels as x but a transparency of a between 0 and 1 inclusive, with computation done in linear colour space and returns a reference to this SGXColourRGBA to allow operation chaining.

The computation proceeds anyways if a is out of bounds. This can be useful for effects that remove a certain colour.

This does not change the transparency of this SGXColourRGBA.

void gammaCorrectBegin(float& r, float& g, float& b) const;

Converts the SGXColourRGBA to linear colour space for physically accurate colour mixing. The linear colour space RGB values are output in r, g, and b as floating point numbers between 0 and 1 inclusive.

Putting linear colour space values into a SGXColourRGBA is not recommended, instead use SGXColourRGBA::gammaCorrectEnd to convert it back.

void gammaCorrectEnd(float r, float g, float b);

Converts the RGB values r, g, b in linear colour space back into the SGXColourRGBA colour space and apply them to this SGXColourRGBA.

If the any component is out of bounds, it is corrected automatically.

[[nodiscard]] int getBlue() const;

Returns the blue component of this SGXColourRGBA as a int between 0 and 255 inclusive.

[[nodiscard]] float getBlueAsFloat() const;

Returns the blue component of this SGXColourRGBA as a float between 0 and 1 inclusive.

[[nodiscard]] int getGreen() const;

Returns the green component of this SGXColourRGBA as a int between 0 and 255 inclusive.

[[nodiscard]] float getGreenAsFloat() const;

Returns the green component of this SGXColourRGBA as a float between 0 and 1 inclusive.

[[nodiscard]] int getRed() const;

Returns the red component of this SGXColourRGBA as a int between 0 and 255 inclusive.

[[nodiscard]] float getRedAsFloat() const;

Returns the red component of this SGXColourRGBA as a float between 0 and 1 inclusive.

[[nodiscard]] SGXString getStringForPrintingRGBAFloatHTML() const;

Returns the HTML style string representation of this SGXColourRGBA with colour between 0 and 1 inclusive, this is something like rgb(1.0, 0.0, 0.8, 1.0).

[[nodiscard]] SGXString getStringForPrintingRGBAHTML() const;

Returns the HTML style string representation of this SGXColourRGBA with colour between 0 and 255 inclusive, this is something like rgb(255, 0, 200, 255).

[[nodiscard]] SGXString getStringForPrintingRGBAHex() const;

Returns the hex code string representation of this SGXColourRGBA, this is something like #FF00C8FF.

[[nodiscard]] SGXString getStringForPrintingRGBFloatHTML() const;

Returns the HTML style string representation of this SGXColourRGBA with colour between 0 and 1 inclusive, this is something like rgb(1.0, 0.0, 0.8).

[[nodiscard]] SGXString getStringForPrintingRGBHTML() const;

Returns the HTML style string representation of this SGXColourRGBA with colour between 0 and 255 inclusive, this is something like rgb(255, 0, 200).

[[nodiscard]] SGXString getStringForPrintingRGBHex() const;

Returns the hex code string representation of this SGXColourRGBA, this is something like #FF00C8.

[[nodiscard]] int getTransparency() const;

Returns the transparency component of this SGXColourRGBA as a int between 0 and 255 inclusive.

[[nodiscard]] float getTransparencyAsFloat() const;

Returns the transparency component of this SGXColourRGBA as a float between 0 and 1 inclusive.

[[nodiscard]] int hash() const;

Hash function defined for SGLHash.

[[nodiscard]] SGXColourRGBA linearInterpolate(SGXColourRGBA x, float f) const;

Returns the resulting colour if f of this SGXColourRGBA is mixed with (1 - f) of x, where f is between 0 and 1 inclusive.

The computation proceeds anyways if f is out of bounds. This can be useful for effects that remove a certain colour.

The returned colour has the same transparency as this SGXColourRGBA.

[[nodiscard]] SGXColourRGBA linearInterpolateGammaCorrection(SGXColourRGBA x, float f) const;

Returns the resulting colour if f of this SGXColourRGBA is mixed with (1 - f) of x, where f is between 0 and 1 inclusive, computation done in linear colour space.

The computation proceeds anyways if f is out of bounds. This can be useful for effects that remove a certain colour.

The returned colour has the same transparency as this SGXColourRGBA.

SGXColourRGBA& linearTransformBlue(float m, float c);

Replaces the blue component of this SGXColourRGBA with m * blue + c and returns a reference to this SGXColourRGBA to allow operation chaining.

If the new blue component is out of bounds, it is corrected automatically.

SGXColourRGBA& linearTransformBlueWithGamma(float m, float c);

Replaces the blue component of this SGXColourRGBA with m * blue + c, with computation done in linear colour space and returns a reference to this SGXColourRGBA to allow operation chaining.

If the new blue component is out of bounds, it is corrected automatically.

SGXColourRGBA& linearTransformGreen(float m, float c);

Replaces the green component of this SGXColourRGBA with m * green + c and returns a reference to this SGXColourRGBA to allow operation chaining.

If the new green component is out of bounds, it is corrected automatically.

SGXColourRGBA& linearTransformGreenWithGamma(float m, float c);

Replaces the green component of this SGXColourRGBA with m * green + c, with computation done in linear colour space and returns a reference to this SGXColourRGBA to allow operation chaining.

If the new green component is out of bounds, it is corrected automatically.

SGXColourRGBA& linearTransformRed(float m, float c);

Replaces the red component of this SGXColourRGBA with m * red + c and returns a reference to this SGXColourRGBA to allow operation chaining.

If the new red component is out of bounds, it is corrected automatically.

SGXColourRGBA& linearTransformRedWithGamma(float m, float c);

Replaces the red component of this SGXColourRGBA with m * red + c, with computation done in linear colour space and returns a reference to this SGXColourRGBA to allow operation chaining.

If the new red component is out of bounds, it is corrected automatically.

SGXColourRGBA& linearTransformTransparency(float m, float c);

Replaces the transparency component of this SGXColourRGBA with m * transparency + c and returns a reference to this SGXColourRGBA to allow operation chaining.

If the new transparency component is out of bounds, it is corrected automatically.

[[nodiscard]] bool operator!=(SGXColourRGBA x) const;

Inequality check with x defined for SGLEqualsTo.

[[nodiscard]] bool operator‹(SGXColourRGBA x) const;

Lesser than operator with x defined for SGLLesserThan and SGLMoreThan.

[[nodiscard]] bool operator==(SGXColourRGBA x) const;

Equality check with x defined for SGLEqualsTo.

[[nodiscard]] bool operator›(SGXColourRGBA x) const;

More than operator with x defined for SGLLesserThan and SGLMoreThan.

[[nodiscard]] float relativeContrast() const;

Returns the contrast value of this SGXColourRGBA. Text and background in any UI element must have a contrast difference of at least 1 to be compatible with WCAG AA.

This is not the WCAG contrast ratio.

For WCAG AAA compatibility, a contrast difference of 1.3 is required

SGXColourRGBA& setBlue(int b);

Sets the blue component of this SGXColourRGBA to b and returns a reference to this SGXColourRGBA to allow operation chaining.

b should be between 0 and 255 inclusive. If it is out of bounds, it is corrected automatically.

SGXColourRGBA& setBlueUsingFloat(float b);

Sets the blue component of this SGXColourRGBA to b and returns a reference to this SGXColourRGBA to allow operation chaining.

b should be between 0 and 1 inclusive. If it is out of bounds, it is corrected automatically.

SGXColourRGBA& setGreen(int g);

Sets the green component of this SGXColourRGBA to g and returns a reference to this SGXColourRGBA to allow operation chaining.

g should be between 0 and 255 inclusive. If it is out of bounds, it is corrected automatically.

SGXColourRGBA& setGreenUsingFloat(float g);

Sets the green component of this SGXColourRGBA to g and returns a reference to this SGXColourRGBA to allow operation chaining.

g should be between 0 and 1 inclusive. If it is out of bounds, it is corrected automatically.

SGXColourRGBA& setRed(int r);

Sets the red component of this SGXColourRGBA to r and returns a reference to this SGXColourRGBA to allow operation chaining.

r should be between 0 and 255 inclusive. If it is out of bounds, it is corrected automatically.

SGXColourRGBA& setRedUsingFloat(float r);

Sets the red component of this SGXColourRGBA to r and returns a reference to this SGXColourRGBA to allow operation chaining.

r should be between 0 and 1 inclusive. If it is out of bounds, it is corrected automatically.

SGXColourRGBA& setTransparency(int a);

Sets the transparency component of this SGXColourRGBA to a and returns a reference to this SGXColourRGBA to allow operation chaining.

a should be between 0 and 255 inclusive. If it is out of bounds, it is corrected automatically.

SGXColourRGBA& setTransparencyUsingFloat(float a);

Sets the transparency component of this SGXColourRGBA to a and returns a reference to this SGXColourRGBA to allow operation chaining.

a should be between 0 and 1 inclusive. If it is out of bounds, it is corrected automatically.

SGXColourRGBA& toComplementColour();

Sets this SGXColourRGBA to its complementary colour, with RGB channels inverted and returns a reference to this SGXColourRGBA to allow operation chaining.

©2025 05524F.sg (Singapore)

contact 05524F / report a bug / make a suggestion

about 05524F SINGAPORE values

list of 05524F projects