From ff75b2d8243f18b92dea12ec46be808d0223c3fe Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Wed, 18 Mar 2015 14:50:27 +1100 Subject: [PATCH] draw: have TestSrcTranslationInvariance work on smaller images. Before/after: $ go test PASS ok golang.org/x/image/draw 1.173s $ go test PASS ok golang.org/x/image/draw 0.225s Change-Id: I5b4742f045870db9353da1d85b0677be992cb347 Reviewed-on: https://go-review.googlesource.com/7712 Reviewed-by: Rob Pike --- draw/scale_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/draw/scale_test.go b/draw/scale_test.go index 4ed60d6..b112643 100644 --- a/draw/scale_test.go +++ b/draw/scale_test.go @@ -196,6 +196,10 @@ func TestSrcTranslationInvariance(t *testing.T) { if err != nil { t.Fatalf("Decode: %v", err) } + sr := image.Rect(2, 3, 16, 12) + if !sr.In(src.Bounds()) { + t.Fatalf("src bounds too small: got %v", src.Bounds()) + } qs := []Interpolator{ NearestNeighbor, ApproxBiLinear, @@ -216,23 +220,23 @@ func TestSrcTranslationInvariance(t *testing.T) { for _, transform := range []bool{false, true} { for _, q := range qs { - want := image.NewRGBA(image.Rect(0, 0, 200, 200)) + want := image.NewRGBA(image.Rect(0, 0, 20, 20)) if transform { - q.Transform(want, m00, src, src.Bounds(), nil) + q.Transform(want, m00, src, sr, nil) } else { - q.Scale(want, want.Bounds(), src, src.Bounds(), nil) + q.Scale(want, want.Bounds(), src, sr, nil) } for _, delta := range deltas { tsrc := &translatedImage{src, delta} - got := image.NewRGBA(image.Rect(0, 0, 200, 200)) + got := image.NewRGBA(image.Rect(0, 0, 20, 20)) if transform { m := matMul(m00, &f64.Aff3{ 1, 0, -float64(delta.X), 0, 1, -float64(delta.Y), }) - q.Transform(got, &m, tsrc, tsrc.Bounds(), nil) + q.Transform(got, &m, tsrc, sr.Add(delta), nil) } else { - q.Scale(got, got.Bounds(), tsrc, tsrc.Bounds(), nil) + q.Scale(got, got.Bounds(), tsrc, sr.Add(delta), nil) } if !bytes.Equal(got.Pix, want.Pix) { t.Errorf("pix differ for delta=%v, transform=%t, q=%T", delta, transform, q)