Documentation ¶
Overview ¶
Package color provides types and functions to manipulate colors.
The types defined here are compatible with the standard library package "image/color", but are designed to work well with the GPU.
The first difference with the standard library is that most of them are based on float32 (instead of uint32), so they can be directly passed to GPU shaders.
The second difference is that they make an explicit distinction between linear and standard (sRGB) color spaces, while the standard library only makes distinction between alpha-premultiplied and alpha-postmultiplied. Both distinction are equally important for correct color handling.
Linear and sRGB ¶
Structs prefixed by "L" are in linear color space, while structs prefixed by "S" are in standard (sRGB) color space.
For the importance of this distinction, see:
http://blog.johnnovak.net/2016/09/21/what-every-coder-should-know-about-gamma/
Alpha Pre-Multipled and Post-Multiplied ¶
Structs ending with "nA" are alpha post-multplied; all others are alpha pre-multiplied.
In an alpha-premultiplied color, the three RGB component have been scaled by alpha; valid values are therefore within [0, alpha]. This is the most useful choice for alpha-blending.
For the importance of alpha pre-multipled, see:
https://blogs.msdn.microsoft.com/shawnhar/2009/11/06/premultiplied-alpha/
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Color ¶
type Color interface { // Linear returns the red, green, blue and alpha values in linear color space. // The red, gren and blue values have been alpha-premultiplied in linear // space. Each value ranges within [0, 1] and can be used directly by GPU // shaders. Linear() (r, g, b, a float32) // Standard returns the red, green, blue and alpha values in standard (sRGB) // color space. The red, gren and blue values have been alpha-premultiplied in // linear space. Each value ranges within [0, 1]. Standard() (r, g, b, a float32) }
Color can convert itself to alpha-premultipled RGBA as 32 bit floats, in both linear and standard (sRGB) color spaces.
type LRGB ¶
LRGB represents a color in linear color space. Each value ranges within [0, 1], and can be used directly by GPU shaders.
type LRGBA ¶
LRGBA represents a color in alpha-premultiplied linear color space. Each value ranges within [0, 1], and can be used directly by GPU shaders.
An alpha-premultiplied color component c has been scaled by alpha (a), so has valid values 0 <= c <= a.
Note that additive blending can also be achieved when alpha is set to 0 while the color components are non-null.
type LRGBnA ¶
LRGBnA represents a color in *non* alpha-premultiplied linear color space. Each value ranges within [0, 1], and can be used directly by GPU shaders.
Note: prefer RGBA for use in shaders.
type Palette ¶
A Palette is an ordered list of colors (defined by their LRGBA values), and a name-to-index dictionary.
func PaletteFrom ¶
PaletteFrom returns a new Palette created from the file at the specified path.
type SRGB ¶
SRGB represents a color in sRGB color space. Each value ranges within [0, 1], and can be used directly by GPU shaders.
type SRGB8 ¶
SRGB8 represents a 24-bit color in sRGB color space. There is 8 bits for each components.
type SRGBA ¶
SRGBA represents a color in alpha-premultiplied sRGB color space. Each value ranges within [0, 1].
An alpha-premultiplied color component c has been scaled by alpha (a), so has valid values 0 <= c <= a.
Note that additive blending can also be achieved when alpha is set to 0 while the color components are non-null.
func (SRGBA) Linear ¶
Linear implements the Colour interface: it returns the color converted to linear color space.
type SRGBA8 ¶
SRGBA8 represents a 32-bit color in alpha-premultiplied sRGB color space. There is 8 bits for each components.
An alpha-premultiplied color component c has been scaled by alpha (a), so has valid values 0 <= c <= a.
Note that additive blending can also be achieved when alpha is set to 0 while the color components are non-null.
type SRGBnA ¶
SRGBnA represents a color in *non* alpha-premultiplied sRGB color space. Each value ranges within [0, 1].
An alpha-premultiplied color component c has been scaled by alpha (a), so has valid values 0 <= c <= a.
Note that additive blending can also be achieved when alpha is set to 0 while the color components are non-null.
func (SRGBnA) Linear ¶
Linear implements the Colour interface: it returns the color converted to alpha-premultipled linear color space.
type SRGBnA8 ¶
SRGBnA8 represents a 32-bit color in *non* alpha-premultiplied sRGB color space. There is 8 bits for each compnent.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package c64 provides the color palette of C64 microcomputers.
|
Package c64 provides the color palette of C64 microcomputers. |
Package cpc provides the color palette of CPC microcomputers.
|
Package cpc provides the color palette of CPC microcomputers. |
Package msx provides the color palette of MSX1 microcomputers.
|
Package msx provides the color palette of MSX1 microcomputers. |
Package msx2 provides the color palette of MSX2 microcomputers.
|
Package msx2 provides the color palette of MSX2 microcomputers. |
Package pico8 provides the color palette of the PICO-8 fantasy console.
|
Package pico8 provides the color palette of the PICO-8 fantasy console. |