-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdither_test.go
More file actions
46 lines (38 loc) · 1.05 KB
/
dither_test.go
File metadata and controls
46 lines (38 loc) · 1.05 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
package xtx_test
import (
"image"
"image/color"
"testing"
"github.com/phrozen/xtx"
)
func TestDitherParse(t *testing.T) {
tests := []struct {
name string
want xtx.DitherAlgorithm
}{
{"floyd-steinberg", xtx.DitherFloydSteinberg},
{"atkinson", xtx.DitherAtkinson},
{"sierra", xtx.DitherSierra},
{"stucki", xtx.DitherStucki},
{"unknown-xyz", xtx.DitherFloydSteinberg}, // fallbacks
}
for _, tt := range tests {
algo, _ := xtx.ParseDitherAlgorithm(tt.name)
if algo.Name != tt.want.Name {
t.Errorf("ParseDitherAlgorithm(%q).Name = %q, want %q", tt.name, algo.Name, tt.want.Name)
}
}
}
func TestDither_Bounds(t *testing.T) {
// 4x4 grayscale image
src := image.NewGray(image.Rect(0, 0, 4, 4))
for y := 0; y < 4; y++ {
for x := 0; x < 4; x++ {
src.SetGray(x, y, color.Gray{Y: uint8(x*64 + y*64)})
}
}
dst := xtx.NewMonochrome(image.Rect(0, 0, 4, 4))
ditherer := xtx.Dither{Algo: xtx.DitherAtkinson}
ditherer.Draw(dst, dst.Bounds(), src, image.Point{0, 0})
// If it doesn't panic out of bounds on the error buffer, we're good.
}