예제 #1
0
func TestConvolve(t *testing.T) {
	kernFull, err := NewKernel([]float64{
		0, 0, 0,
		1, 1, 1,
		0, 0, 0,
	})
	if err != nil {
		t.Fatal(err)
	}

	kernSep := &SeparableKernel{
		X: []float64{1, 1, 1},
		Y: []float64{0, 1, 0},
	}

	src, err := graphicstest.LoadImage("../../testdata/gopher.png")
	if err != nil {
		t.Fatal(err)
	}
	b := src.Bounds()

	sep := image.NewRGBA(b)
	if err = Convolve(sep, src, kernSep); err != nil {
		t.Fatal(err)
	}

	full := image.NewRGBA(b)
	Convolve(full, src, kernFull)

	err = graphicstest.ImageWithinTolerance(sep, full, 0x101)
	if err != nil {
		t.Fatal(err)
	}
}
예제 #2
0
func TestScaleGopher(t *testing.T) {
	dst := image.NewRGBA(image.Rect(0, 0, 100, 150))

	src, err := graphicstest.LoadImage("../testdata/gopher.png")
	if err != nil {
		t.Error(err)
		return
	}

	// Down-sample.
	if err := Scale(dst, src); err != nil {
		t.Fatal(err)
	}
	cmp, err := graphicstest.LoadImage("../testdata/gopher-100x150.png")
	if err != nil {
		t.Error(err)
		return
	}
	err = graphicstest.ImageWithinTolerance(dst, cmp, 0)
	if err != nil {
		t.Error(err)
		return
	}

	// Up-sample.
	dst = image.NewRGBA(image.Rect(0, 0, 500, 750))
	if err := Scale(dst, src); err != nil {
		t.Fatal(err)
	}
	cmp, err = graphicstest.LoadImage("../testdata/gopher-500x750.png")
	if err != nil {
		t.Error(err)
		return
	}
	err = graphicstest.ImageWithinTolerance(dst, cmp, 0)
	if err != nil {
		t.Error(err)
		return
	}
}
예제 #3
0
func TestThumbnailLongGopher(t *testing.T) {
	dst := image.NewRGBA(image.Rect(0, 0, 50, 150))

	src, err := graphicstest.LoadImage("../testdata/gopher.png")
	if err != nil {
		t.Fatal(err)
	}
	if err := Thumbnail(dst, src); err != nil {
		t.Fatal(err)
	}
	cmp, err := graphicstest.LoadImage("../testdata/gopher-thumb-50x150.png")
	if err != nil {
		t.Fatal(err)
	}
	err = graphicstest.ImageWithinTolerance(dst, cmp, 0)
	if err != nil {
		t.Error(err)
	}
}
예제 #4
0
func TestBlurGopher(t *testing.T) {
	src, err := graphicstest.LoadImage("../testdata/gopher.png")
	if err != nil {
		t.Fatal(err)
	}

	dst := image.NewRGBA(src.Bounds())
	if err = Blur(dst, src, &BlurOptions{StdDev: 1.1}); err != nil {
		t.Fatal(err)
	}

	cmp, err := graphicstest.LoadImage("../testdata/gopher-blur.png")
	if err != nil {
		t.Fatal(err)
	}
	err = graphicstest.ImageWithinTolerance(dst, cmp, 0x101)
	if err != nil {
		t.Fatal(err)
	}
}
예제 #5
0
func TestRotateGopherPartial(t *testing.T) {
	src, err := graphicstest.LoadImage("../testdata/gopher.png")
	if err != nil {
		t.Fatal(err)
	}

	srcb := src.Bounds()
	dst := image.NewRGBA(image.Rect(0, 0, srcb.Dx(), srcb.Dy()))
	if err := Rotate(dst, src, &RotateOptions{math.Pi / 3.0}); err != nil {
		t.Fatal(err)
	}

	cmp, err := graphicstest.LoadImage("../testdata/gopher-rotate-partial.png")
	if err != nil {
		t.Fatal(err)
	}
	err = graphicstest.ImageWithinTolerance(dst, cmp, 0x101)
	if err != nil {
		t.Fatal(err)
	}
}