From db1030a6d4ddbc8e05853fa3f110bfc568a56c72 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Tue, 30 Jul 2019 14:10:37 +0900 Subject: [PATCH] graphics: Add TestImageMipmapNegativeDet --- image_test.go | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/image_test.go b/image_test.go index 796a378b6..9aa3ca2bc 100644 --- a/image_test.go +++ b/image_test.go @@ -1047,6 +1047,60 @@ func TestImageMipmap(t *testing.T) { } } +func TestImageMipmapNegativeDet(t *testing.T) { + src, _, err := openEbitenImage() + if err != nil { + t.Fatal(err) + return + } + w, h := src.Size() + + l1, _ := NewImage(w/2, h/2, FilterDefault) + op := &DrawImageOptions{} + op.GeoM.Scale(1/2.0, 1/2.0) + op.Filter = FilterLinear + l1.DrawImage(src, op) + + l1w, l1h := l1.Size() + l2, _ := NewImage(l1w/2, l1h/2, FilterDefault) + op = &DrawImageOptions{} + op.GeoM.Scale(1/2.0, 1/2.0) + op.Filter = FilterLinear + l2.DrawImage(l1, op) + + gotDst, _ := NewImage(w, h, FilterDefault) + op = &DrawImageOptions{} + op.GeoM.Scale(-1/5.0, -1/5.0) + op.GeoM.Translate(float64(w), float64(h)) + op.Filter = FilterLinear + gotDst.DrawImage(src, op) + + wantDst, _ := NewImage(w, h, FilterDefault) + op = &DrawImageOptions{} + op.GeoM.Scale(-4.0/5.0, -4.0/5.0) + op.GeoM.Translate(float64(w), float64(h)) + op.Filter = FilterLinear + wantDst.DrawImage(l2, op) + + allZero := true + for j := 0; j < h; j++ { + for i := 0; i < h; i++ { + got := gotDst.At(i, j).(color.RGBA) + want := wantDst.At(i, j).(color.RGBA) + if !sameColors(got, want, 1) { + t.Errorf("At(%d, %d): got: %#v, want: %#v", i, j, got, want) + } + if got.A > 0 { + allZero = false + } + } + } + + if allZero { + t.Errorf("the image must include non-zero values but not") + } +} + // Issue #710 func TestImageMipmapColor(t *testing.T) { img0, _ := NewImage(256, 256, FilterDefault)