1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
| // 颜色类型
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.
RGBA() (r, g, b, a uint32)
}
// Colors and Models
// image_draw01_test.go:47: r=>65535, g=>0, b=>0, a=>0
// image_draw01_test.go:55: r=>65535, g=>0, b=>0, a=>0
// image_draw01_test.go:55: r=>0, g=>65535, b=>0, a=>0
// image_draw01_test.go:55: r=>0, g=>0, b=>65535, a=>0
// image_draw01_test.go:55: r=>65535, g=>65535, b=>65535, a=>65535
// image_draw01_test.go:60: convert=>{R:255 G:0 B:0 A:0}, t=>color.RGBA
func TestColorsAndModels(t *testing.T) {
red := color.RGBA{R: 255}
green := color.RGBA{G: 255}
blue := color.RGBA{B: 255}
gray := color.Gray{Y: 255}
// rgba(为[0,0xFFFF]
r, g, b, a := red.RGBA()
t.Logf("r=>%d, g=>%d, b=>%d, a=>%d", r, g, b, a)
// 初始化调色板
plat := color.Palette{
red, green, blue, gray,
}
for _, c := range plat {
r, g, b, a := c.RGBA()
t.Logf("r=>%d, g=>%d, b=>%d, a=>%d", r, g, b, a)
}
// 调色板Convert转换
convert := plat.Convert(red)
t.Logf("convert=>%+v, t=>%[1]T", convert)
}
|