示例#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 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)
	}
}
示例#3
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)
	}
}
示例#4
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
	}
}