From a7e7e007ca4a7a7ca60d5fa8537e7a06aab89d22 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Mon, 15 Jul 2019 03:09:00 +0900 Subject: [PATCH] restorable: Bug fix: PutQuadVertices should take the source image Fixes #898 --- image_test.go | 36 +++++++++++++++++++++++++++++++++++- internal/restorable/image.go | 2 +- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/image_test.go b/image_test.go index 81f97da8e..17c696b37 100644 --- a/image_test.go +++ b/image_test.go @@ -1653,7 +1653,7 @@ func TestImageSubImageSubImage(t *testing.T) { } } -// Issue 839 +// Issue #839 func TestImageTooSmallMipmap(t *testing.T) { const w, h = 16, 16 src, _ := NewImage(w, h, FilterDefault) @@ -1680,3 +1680,37 @@ func TestImageZeroSizedMipmap(t *testing.T) { op.Filter = FilterLinear dst.DrawImage(src.SubImage(image.ZR).(*Image), op) } + +// Issue #898 +func TestImageFillingAndEdges(t *testing.T) { + const ( + srcw, srch = 16, 16 + dstw, dsth = 256, 16 + ) + + println("-- start --") + defer println("-- end --") + src, _ := NewImage(srcw, srch, FilterDefault) + dst, _ := NewImage(dstw, dsth, FilterDefault) + + src.Fill(color.White) + dst.Fill(color.Black) + + op := &DrawImageOptions{} + op.GeoM.Scale(float64(dstw-2)/float64(srcw), float64(dsth-2)/float64(srch)) + op.GeoM.Translate(1, 1) + dst.DrawImage(src, op) + + for j := 0; j < dsth; j++ { + for i := 0; i < dstw; i++ { + got := dst.At(i, j).(color.RGBA) + want := color.RGBA{0xff, 0xff, 0xff, 0xff} + if i == 0 || i == dstw-1 || j == 0 || j == dsth-1 { + want = color.RGBA{0, 0, 0, 0xff} + } + if got != want { + t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want) + } + } + } +} diff --git a/internal/restorable/image.go b/internal/restorable/image.go index 3ffd8c8cc..30fab71ba 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -215,7 +215,7 @@ func (i *Image) fill(r, g, b, a uint8) { dw, dh := i.internalSize() sw, sh := emptyImage.Size() vs := make([]float32, 4*graphics.VertexFloatNum) - graphics.PutQuadVertices(vs, i, 0, 0, sw, sh, + graphics.PutQuadVertices(vs, emptyImage, 0, 0, sw, sh, float32(dw)/float32(sw), 0, 0, float32(dh)/float32(sh), 0, 0, rf, gf, bf, af) is := graphics.QuadIndices()