Skip to content

Colour Pixel API

Sam Lane edited this page May 31, 2018 · 4 revisions

All Built-In functions and APIs accept all of the below standards transparently.

Colour Storage Types

The listed types are available, and each have their own use cases for the colours/patterns they are best suited to storing.

  • u_int32_t -> 24-bits of 32-bits are used to store 8-bit RGB values for colours. Eg 0xFFFFFF is white, 0xFF0000 is Red etc.
  • RGBPixel -> 3 Fields, (R,G,B) all of which are u_int8_t (0-255)
  • HSLPixel -> 3 Fields, (H,S,L) all of which are float_t (0-1)
  • HSVPixel -> 3 Fields, (H,S,V) all of which are float_t (0-1)

Converting Between Types

Use of ColourConverter to convert between types has been built to be as transparent as possible, taking 1 or 2 arguments (Source) or (Source & Destination) then determining which is the most appropriate function to call. This happens at compile time by function overloading, so there is no overhead in this.

Functions are as follows:

Return Value Function Name Arg 1 Arg 2
RGBPixel ToRGB u_int32_t,HSLPixel,HSVPixel N/A
N/A ToRGB u_int32_t,HSLPixel,HSVPixel RGBPixel
HSLPixel ToHSL u_int32_t,RGBPixel,HSVPixel N/A
N/A ToHSL u_int32_t,RGBPixel,HSVPixel HSLPixel
HSVPixel ToHSV u_int32_t,HSLPixel,RGBPixel N/A
N/A ToHSV u_int32_t,HSLPixel,RGBPixel HSVPixel
u_int32_t ToRaw RGBPixel,HSLPixel,HSVPixel N/A
N/A ToRaw RGBPixel,HSLPixel,HSVPixel u_int32_t
  • It is highly recommended that, in a loop context, a single Pixel is created and then edited in place by the N/A return value functions. This will save the overhead of copying.

  • Conversion between RGB<->HSL/HSV is much slower than Raw<->RGB due to the transition between floating and integer numbers. HSL<->HSV is the slowest of all, requiring a =n intermediate conversion to RGB first. If possible use RGB values or Raw in a loop.

Clone this wiki locally