limage - lcolor/rgb.go
1 package lcolor // import "vimagination.zapto.org/limage/lcolor"
2
3 import "image/color"
4
5 // RGB is a standard colour type whose Alpha channel is always full
6 type RGB struct {
7 R, G, B uint8
8 }
9
10 // RGBA implements the color.Color interface
11 func (rgb RGB) RGBA() (r, g, b, a uint32) {
12 r = uint32(rgb.R)
13 r |= r << 8
14 g = uint32(rgb.G)
15 g |= g << 8
16 b = uint32(rgb.B)
17 b |= b << 8
18 return r, g, b, 0xFFFF
19 }
20
21 // ToNRGBA returns itself as a non-alpha-premultiplied value
22 // As the alpha is always full, this only returns the normal values
23 func (rgb RGB) ToNRGBA() color.NRGBA64 {
24 r := uint16(rgb.R)
25 r |= r << 8
26 g := uint16(rgb.G)
27 g |= g << 8
28 b := uint16(rgb.B)
29 b |= b << 8
30 return color.NRGBA64{r, g, b, 0xffff}
31 }
32
33 func rgbColourModel(c color.Color) color.Color {
34 r, g, b, _ := c.RGBA()
35 return RGB{
36 R: uint8(r >> 8),
37 G: uint8(g >> 8),
38 B: uint8(b >> 8),
39 }
40 }
41