limage - 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
14 return color.NRGBA64{
15 R: uint16(r),
16 G: uint16(g),
17 B: uint16(b),
18 A: uint16(a),
19 }
20 }
21
22 // Index returns the palette index of the nearest color.
23 func (ap AlphaPalette) Index(c color.Color) int {
24 return color.Palette(ap).Index(c)
25 }
26
27 // IndexedAlpha is the combination of a palette index and an Alpha channel.
28 type IndexedAlpha struct {
29 I, A uint8
30 }
31