-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpaletted_image_test.go
97 lines (71 loc) · 2.15 KB
/
paletted_image_test.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package gfx
import (
"image/color"
"testing"
)
func TestNewPaletted(t *testing.T) {
m := NewPaletted(32, 32, PaletteEN4, PaletteEN4[1])
if got, want := len(m.Pix), 1024; got != want {
t.Fatalf("len(m.Pix) = %d, want %d", got, want)
}
}
func TestNewPalettedImage(t *testing.T) {
m := NewPalettedImage(IR(0, 0, 32, 32), PaletteEN4)
if got, want := len(m.Pix), 1024; got != want {
t.Fatalf("len(m.Pix) = %d, want %d", got, want)
}
}
func TestNewResizedPalettedImage(t *testing.T) {
src := NewPaletted(16, 16, PaletteEN4)
m := NewResizedPalettedImage(src, 32, 32)
if got, want := len(m.Pix), 1024; got != want {
t.Fatalf("len(m.Pix) = %d, want %d", got, want)
}
}
func TestNewScaledPalettedImage(t *testing.T) {
src := NewPaletted(16, 16, PaletteEN4)
m := NewScaledPalettedImage(src, 2)
if got, want := len(m.Pix), 1024; got != want {
t.Fatalf("len(m.Pix) = %d, want %d", got, want)
}
}
func TestPalettedColorModel(t *testing.T) {
m := NewPaletted(16, 16, PaletteEN4)
c := ColorNRGBA(255, 0, 0, 255)
got := m.ColorModel().Convert(c).(color.NRGBA)
want := ColorNRGBA(229, 176, 131, 255)
if got != want {
t.Fatalf("m.ColorModel().Convert(c) = %v, want %v", got, want)
}
}
func TestPalettedPixels(t *testing.T) {
m := NewPaletted(16, 16, PaletteEN4, PaletteEN4[2])
if got, want := len(m.Pixels()), 1024; got != want {
t.Fatalf("len(m.Pixels()) = %d, want %d", got, want)
}
}
func TestPalettedSubImage(t *testing.T) {
m := NewPaletted(16, 16, PaletteEN4)
m.Put(1, 1, 2)
sm := m.SubImage(IR(1, 1, 4, 4)).(*Paletted)
if got, want := sm.Bounds(), IR(1, 1, 4, 4); !got.Eq(want) {
t.Fatalf("sm.Bounds() = %v, want %v", got, want)
}
if got, want := sm.Index(0, 0), uint8(2); got != want {
t.Fatalf("sm.Index(0,0) = %d, want %d", got, want)
}
}
func TestPalettedOpaque(t *testing.T) {
t.Run("Opaque", func(t *testing.T) {
m := NewPaletted(16, 16, PaletteEN4, PaletteEN4[1])
if !m.Opaque() {
t.Fatalf("expected image to be opaque")
}
})
t.Run("Not Opaque", func(t *testing.T) {
m := NewPaletted(16, 16, append(PaletteEN4, ColorTransparent), ColorTransparent)
if m.Opaque() {
t.Fatalf("expected image to not be opaque")
}
})
}