diff --git a/image_test.go b/image_test.go index d48cadc83..34f73fc0f 100644 --- a/image_test.go +++ b/image_test.go @@ -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 ( diff --git a/internal/restorable/image.go b/internal/restorable/image.go index ce591d24f..78011ca75 100644 --- a/internal/restorable/image.go +++ b/internal/restorable/image.go @@ -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()