-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathimage_test.go
More file actions
58 lines (48 loc) · 1.32 KB
/
Copy pathimage_test.go
File metadata and controls
58 lines (48 loc) · 1.32 KB
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
package gfx
import (
"image"
"image/color"
"image/draw"
"testing"
)
func TestPt(t *testing.T) {
got, want := Pt(1, 2), image.Point{1, 2}
if got != want {
t.Fatalf("Pt(1,2) = %v, want %v", got, want)
}
}
func TestIR(t *testing.T) {
x0, y0, x1, y1 := 10, 10, 30, 30
got := IR(x0, y0, x1, y1)
want := IR(x0, y0, x1, y1)
if got != want {
t.Fatalf("IR(%d, %d, %d, %d) = %v, want %v", x0, y0, x1, y1, got, want)
}
}
// TestMixMatchesDrawOver verifies that Mix produces the same pixel as
// draw.Draw with draw.Over for a range of source/destination alpha
// combinations, so the inlined blend stays bit-equivalent to the stdlib.
func TestMixMatchesDrawOver(t *testing.T) {
cases := []color.RGBA{
{255, 0, 0, 255},
{0, 255, 0, 128},
{0, 0, 255, 64},
{200, 100, 50, 200},
{12, 34, 56, 1},
{0, 0, 0, 0},
}
for _, dstColor := range cases {
for _, srcColor := range cases {
got := image.NewRGBA(image.Rect(0, 0, 1, 1))
got.SetRGBA(0, 0, dstColor)
Mix(got, 0, 0, srcColor)
want := image.NewRGBA(image.Rect(0, 0, 1, 1))
want.SetRGBA(0, 0, dstColor)
draw.Draw(want, want.Bounds(), image.NewUniform(srcColor), image.Point{}, draw.Over)
if got.RGBAAt(0, 0) != want.RGBAAt(0, 0) {
t.Fatalf("Mix(dst=%v, src=%v) = %v, want %v",
dstColor, srcColor, got.RGBAAt(0, 0), want.RGBAAt(0, 0))
}
}
}
}