restorable: Fix clearing logic

Fixes #740
This commit is contained in:
Hajime Hoshi 2018-11-28 23:00:22 +01:00
parent 1a54ff34e6
commit 962a11468b
2 changed files with 35 additions and 3 deletions

View File

@ -524,6 +524,36 @@ func TestImageFill(t *testing.T) {
}
}
// Issue #740
func TestImageClear(t *testing.T) {
const w, h = 128, 256
img, err := NewImage(w, h, FilterNearest)
if err != nil {
t.Fatal(err)
return
}
img.Fill(color.White)
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
got := img.At(i, j)
want := color.RGBA{0xff, 0xff, 0xff, 0xff}
if got != want {
t.Errorf("img At(%d, %d): got %#v; want %#v", i, j, got, want)
}
}
}
img.Clear()
for j := 0; j < h; j++ {
for i := 0; i < w; i++ {
got := img.At(i, j)
want := color.RGBA{}
if got != want {
t.Errorf("img At(%d, %d): got %#v; want %#v", i, j, got, want)
}
}
}
}
// Issue #317, #558, #724
func TestImageEdge(t *testing.T) {
const (

View File

@ -157,9 +157,11 @@ func (i *Image) ReplacePixels(pixels []byte, x, y, width, height int) {
// This means dummyImage might not be restored yet when this image is restored.
// However, that's ok since this image will be stale or have updated pixel data
// and this image can be restored without dummyImage.
w, h := dummyImage.Size()
vs := graphics.QuadVertices(w, h, 0, 0, w, h,
float32(width)/float32(w), 0, 0, float32(height)/float32(h),
dw, dh := dummyImage.Size()
w2 := graphics.NextPowerOf2Int(w)
h2 := graphics.NextPowerOf2Int(h)
vs := graphics.QuadVertices(w2, h2, 0, 0, dw, dh,
float32(width)/float32(dw), 0, 0, float32(height)/float32(dh),
float32(x), float32(y),
0, 0, 0, 0)
is := graphics.QuadIndices()