Overview
Package color implements a basic color library.
Index
- func CMYKToRGB(c, m, y, k uint8) (uint8, uint8, uint8)
- func RGBToYCbCr(r, g, b uint8) (uint8, uint8, uint8)
- type Alpha
- type Alpha16
- type CMYK
- type Color
- type RGBA
- type RGBA64
- type YCbCr
Variables
Standard colors.
func
¶
CMYKToRGB converts a CMYK quadruple to an RGB triple.
func
¶
RGBToCMYK converts an RGB triple to a CMYK quadruple.
func RGBToYCbCr
RGBToYCbCr converts an RGB triple to a Y’CbCr triple.
YCbCrToRGB converts a Y’CbCr triple to an RGB triple.
type Alpha
- type Alpha struct {
- A uint8
- }
Alpha represents an 8-bit alpha color.
func (Alpha)
¶
- func (c ) RGBA() (r, g, b, a uint32)
type
¶
- type Alpha16 struct {
- A
- }
Alpha16 represents a 16-bit alpha color.
func (Alpha16) RGBA
- func (c Alpha16) RGBA() (r, g, b, a )
type CMYK
- type CMYK struct {
- C, M, Y, K uint8
- }
CMYK represents a fully opaque CMYK color, having 8 bits for each of cyan,
magenta, yellow and black.
It is not associated with any particular color profile.
func (CMYK)
¶
type Color
- type Color interface {
- // RGBA returns the alpha-premultiplied red, green, blue and alpha values
- // for the color. Each value ranges within [0, 0xffff], but is represented
- // by a uint32 so that multiplying by a blend factor up to 0xffff will not
- // overflow.
- //
- // An alpha-premultiplied color component c has been scaled by alpha (a),
- // so has valid values 0 <= c <= a.
- RGBA() (r, g, b, a uint32)
- }
Color can convert itself to alpha-premultiplied 16-bits per channel RGBA. The
conversion may be lossy.
type
¶
Gray represents an 8-bit grayscale color.
func (Gray)
¶
- func (c ) RGBA() (r, g, b, a uint32)
type
¶
- type Gray16 struct {
- Y
- }
Gray16 represents a 16-bit grayscale color.
- func (c Gray16) RGBA() (r, g, b, a )
- type Model interface {
- Convert(c Color)
- }
Model can convert any Color to one from its own color model. The conversion may
be lossy.
Models for the standard color types.
- var CMYKModel Model = (cmykModel)
CMYKModel is the Model for CMYK colors.
- var NYCbCrAModel Model = (nYCbCrAModel)
NYCbCrAModel is the Model for non-alpha-premultiplied Y’CbCr-with-alpha colors.
- var YCbCrModel Model = (yCbCrModel)
YCbCrModel is the Model for Y’CbCr colors.
func ModelFunc
ModelFunc returns a Model that invokes f to implement the conversion.
type
¶
- type NRGBA struct {
- R, G, B, A
- }
NRGBA represents a non-alpha-premultiplied 32-bit color.
func (NRGBA) RGBA
- func (c NRGBA) RGBA() (r, g, b, a )
type NRGBA64
NRGBA64 represents a non-alpha-premultiplied 64-bit color, having 16 bits for
each of red, green, blue and alpha.
func (NRGBA64) RGBA
- func (c NRGBA64) RGBA() (r, g, b, a )
type NYCbCrA
- type NYCbCrA struct {
- YCbCr
- A
- }
NYCbCrA represents a non-alpha-premultiplied Y’CbCr-with-alpha color, having 8
bits each for one luma, two chroma and one alpha component.
func (NYCbCrA) RGBA
type
¶
- type Palette []
Palette is a palette of colors.
Convert returns the palette color closest to c in Euclidean R,G,B space.
func (Palette)
¶
- func (p ) Index(c Color)
Index returns the index of the palette color closest to c in Euclidean R,G,B,A
space.
type RGBA
- type RGBA struct {
- R, G, B, A uint8
- }
RGBA represents a traditional 32-bit alpha-premultiplied color, having 8 bits
for each of red, green, blue and alpha.
An alpha-premultiplied color component C has been scaled by alpha (A), so has
valid values 0 <= C <= A.
func (RGBA)
¶
- func (c ) RGBA() (r, g, b, a uint32)
type
¶
- type RGBA64 struct {
- R, G, B, A
- }
RGBA64 represents a 64-bit alpha-premultiplied color, having 16 bits for each of
red, green, blue and alpha.
An alpha-premultiplied color component C has been scaled by alpha (A), so has
valid values 0 <= C <= A.
func (RGBA64) RGBA
- func (c RGBA64) RGBA() (r, g, b, a )
- type YCbCr struct {
- Y, Cb, Cr uint8
- }
YCbCr represents a fully opaque 24-bit Y’CbCr color, having 8 bits each for one
luma and two chroma components.
JPEG, VP8, the MPEG family and other codecs use this color model. Such codecs
often use the terms YUV and Y’CbCr interchangeably, but strictly speaking, the
term YUV applies only to analog video signals, and Y’ (luma) is Y (luminance)
after applying gamma correction.
Conversion between RGB and Y’CbCr is lossy and there are multiple, slightly
different formulae for converting between the two. This package follows the JFIF
specification at .