restorable: Bug fix: PutQuadVertices should take the source image

Fixes #898
This commit is contained in:
Hajime Hoshi 2019-07-15 03:09:00 +09:00
parent aee26eec1e
commit a7e7e007ca
2 changed files with 36 additions and 2 deletions

View File

@ -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)
}
}
}
}

View File

@ -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()