colour

package
v0.0.0-...-7a819e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2019 License: BSD-2-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package colour provides types and functions to manipulate colors.

It is compatible with the standard library "image/color" package, but is designed to work well with GPUs.

The first difference is that it is based on float32 (instead of uint32), which can be used directly in shaders and graphics API such as OpenGL.

It also makes an explicit distinction between linear and sRGB color spaces, in addition to the distinction between alpha-premultiplied and alpha-postmultiplied.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Colour

type Colour interface {
	// Linear returns the alpha-premultiplied red, green, blue and alpha
	// values for the color, in 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.
	Linear() (r, g, b, a float32)
}

type RGB

type RGB struct {
	R float32
	G float32
	B float32
}

RGB represents a color in linear color space. Each value ranges within [0, 1], and can be used directly by GPU shaders.

func RGBOf

func RGBOf(c Colour) RGB

RGBOf converts any color to linear color space with no alpha.

func (RGB) Linear

func (c RGB) Linear() (r, g, b, a float32)

Linear implements the Colour interface.

func (RGB) RGBA

func (c RGB) RGBA() (r, g, b, a uint32)

RGBA implements the image.Color interface: it returns the four components scaled by 0xFFFF.

type RGBA

type RGBA struct {
	R float32
	G float32
	B float32
	A float32
}

RGBA 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.

func RGBAOf

func RGBAOf(c Colour) RGBA

RGBAOf converts any color to alpha-premultiplied, linear color space.

func (RGBA) Linear

func (c RGBA) Linear() (r, g, b, a float32)

Linear implements the Colour interface.

func (RGBA) RGBA

func (c RGBA) RGBA() (r, g, b, a uint32)

RGBA implements the image.Color interface: it returns the four components scaled by 0xFFFF.

type RGBnA

type RGBnA struct {
	R float32
	G float32
	B float32
	A float32
}

RGBnA 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.

func RGBnAOf

func RGBnAOf(c Colour) RGBnA

RGBnAOf converts any color to non alpha-premultiplied linear color space.

func (RGBnA) Linear

func (c RGBnA) Linear() (r, g, b, a float32)

Linear implements the Colour interface.

func (RGBnA) RGBA

func (c RGBnA) RGBA() (r, g, b, a uint32)

RGBA implements the image.Color interface: it returns the four components scaled by 0xFFFF.

type SRGB

type SRGB struct {
	R float32
	G float32
	B float32
}

SRGB represents a color in sRGB color space. Each value ranges within [0, 1], and can be used directly by GPU shaders.

func SRGBOf

func SRGBOf(c Colour) SRGB

SRGBOf converts any color to sRGB color space with no alpha.

func (SRGB) Linear

func (c SRGB) Linear() (r, g, b, a uint32)

Linear implements the image.Color interface: it returns the four components scaled by 0xFFFF.

func (SRGB) RGBA

func (c SRGB) RGBA() (r, g, b, a float32)

RGBA implements the Colour interface.

type SRGB8

type SRGB8 struct {
	R uint8
	G uint8
	B uint8
}

SRGB8 represents a 24-bit color in sRGB color space. There is 8 bits for each components.

func SRGB8Of

func SRGB8Of(c Colour) SRGB8

SRGB8Of converts any color to sRGB color space.

func (SRGB8) Linear

func (c SRGB8) Linear() (r, g, b, a float32)

Linear implements the Colour interface.

func (SRGB8) RGBA

func (c SRGB8) RGBA() (r, g, b, a uint32)

RGBA implements the image.Color interface.

type SRGBA

type SRGBA struct {
	R float32
	G float32
	B float32
	A float32
}

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 SRGBAOf

func SRGBAOf(c Colour) SRGBA

SRGBAOf converts any color to sRGB alpha-premultiplied color space.

func (SRGBA) Linear

func (c SRGBA) Linear() (r, g, b, a float32)

Linear implements the Colour interface: it returns the color converted to linear color space.

func (SRGBA) RGBA

func (c SRGBA) RGBA() (r, g, b, a uint32)

RGBA implements the image.Color interface: it returns the four components scaled by 0xFFFF.

type SRGBA8

type SRGBA8 struct {
	R uint8
	G uint8
	B uint8
	A uint8
}

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.

func SRGBA8Of

func SRGBA8Of(c Colour) SRGBA8

SRGBA8Of converts any color to alpha-premultiplied sRGB color space.

func (SRGBA8) Linear

func (c SRGBA8) Linear() (r, g, b, a float32)

Linear implements the Colour interface.

func (SRGBA8) RGBA

func (c SRGBA8) RGBA() (r, g, b, a uint32)

RGBA implements the image.Color interface.

type SRGBnA

type SRGBnA struct {
	R float32
	G float32
	B float32
	A float32
}

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 SRGBnAOf

func SRGBnAOf(c Colour) SRGBnA

SRGBnAOf converts any color to sRGB non alpha-premultiplied sRGB color space.

func (SRGBnA) Linear

func (c SRGBnA) Linear() (r, g, b, a float32)

Linear implements the Colour interface: it returns the color converted to alpha-premultipled linear color space.

func (SRGBnA) RGBA

func (c SRGBnA) RGBA() (r, g, b, a uint32)

RGBA implements the image.Color interface: it returns the four components scaled by 0xFFFF.

type SRGBnA8

type SRGBnA8 struct {
	R uint8
	G uint8
	B uint8
	A uint8
}

SRGBnA8 represents a 32-bit color in *non* alpha-premultiplied sRGB color space. There is 8 bits for each compnent.

func SRGBnA8Of

func SRGBnA8Of(c Colour) SRGBnA8

SRGBnA8Of converts any color to non alpha-premultiplied sRGB color space.

func (SRGBnA8) Linear

func (c SRGBnA8) Linear() (r, g, b, a float32)

Linear implements the Colour interface.

func (SRGBnA8) RGBA

func (c SRGBnA8) RGBA() (r, g, b, a uint32)

RGBA implements the image.Color interface: it returns the four components scaled by 0xFFFF.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL