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 <r@golang.org>
This commit is contained in:
parent
a71fdfe7d1
commit
ff75b2d824
|
@ -196,6 +196,10 @@ func TestSrcTranslationInvariance(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Decode: %v", err)
|
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{
|
qs := []Interpolator{
|
||||||
NearestNeighbor,
|
NearestNeighbor,
|
||||||
ApproxBiLinear,
|
ApproxBiLinear,
|
||||||
|
@ -216,23 +220,23 @@ func TestSrcTranslationInvariance(t *testing.T) {
|
||||||
|
|
||||||
for _, transform := range []bool{false, true} {
|
for _, transform := range []bool{false, true} {
|
||||||
for _, q := range qs {
|
for _, q := range qs {
|
||||||
want := image.NewRGBA(image.Rect(0, 0, 200, 200))
|
want := image.NewRGBA(image.Rect(0, 0, 20, 20))
|
||||||
if transform {
|
if transform {
|
||||||
q.Transform(want, m00, src, src.Bounds(), nil)
|
q.Transform(want, m00, src, sr, nil)
|
||||||
} else {
|
} else {
|
||||||
q.Scale(want, want.Bounds(), src, src.Bounds(), nil)
|
q.Scale(want, want.Bounds(), src, sr, nil)
|
||||||
}
|
}
|
||||||
for _, delta := range deltas {
|
for _, delta := range deltas {
|
||||||
tsrc := &translatedImage{src, delta}
|
tsrc := &translatedImage{src, delta}
|
||||||
got := image.NewRGBA(image.Rect(0, 0, 200, 200))
|
got := image.NewRGBA(image.Rect(0, 0, 20, 20))
|
||||||
if transform {
|
if transform {
|
||||||
m := matMul(m00, &f64.Aff3{
|
m := matMul(m00, &f64.Aff3{
|
||||||
1, 0, -float64(delta.X),
|
1, 0, -float64(delta.X),
|
||||||
0, 1, -float64(delta.Y),
|
0, 1, -float64(delta.Y),
|
||||||
})
|
})
|
||||||
q.Transform(got, &m, tsrc, tsrc.Bounds(), nil)
|
q.Transform(got, &m, tsrc, sr.Add(delta), nil)
|
||||||
} else {
|
} 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) {
|
if !bytes.Equal(got.Pix, want.Pix) {
|
||||||
t.Errorf("pix differ for delta=%v, transform=%t, q=%T", delta, transform, q)
|
t.Errorf("pix differ for delta=%v, transform=%t, q=%T", delta, transform, q)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user