limage - lcolor/indexed.go
1 package lcolor
2
3 import "image/color"
4
5 // AlphaPalette is an extension to the normal color.Palette type
6 type AlphaPalette color.Palette
7
8 // Convert converts the given color to the nearest color in the palette, but
9 // preserves the alpha channel
10 func (ap AlphaPalette) Convert(c color.Color) color.Color {
11 r, g, b, _ := color.Palette(ap).Convert(c).RGBA()
12 _, _, _, a := c.RGBA()
13 return color.NRGBA64{
14 R: uint16(r),
15 G: uint16(g),
16 B: uint16(b),
17 A: uint16(a),
18 }
19 }
20
21 // Index returns the palette index of the nearest color
22 func (ap AlphaPalette) Index(c color.Color) int {
23 return color.Palette(ap).Index(c)
24 }
25
26 // IndexedAlpha is the combination of a palette index and an Alpha channel
27 type IndexedAlpha struct {
28 I, A uint8
29 }
30