ebiten: Bug fix: Fill on a sub-image didn't work correctly

Closes #1691
This commit is contained in:
Hajime Hoshi 2021-07-02 22:40:19 +09:00
parent 6b95dd0d4d
commit 66be53804d
2 changed files with 40 additions and 1 deletions

View File

@ -89,7 +89,13 @@ func init() {
//
// When the image is disposed, Fill does nothing.
func (i *Image) Fill(clr color.Color) {
w, h := i.Size()
// Use the original size to cover the entire region (#1691).
// DrawImage automatically clips the rendering region.
orig := i
if i.isSubImage() {
orig = i.original
}
w, h := orig.Size()
op := &DrawImageOptions{}
op.GeoM.Scale(float64(w), float64(h))

View File

@ -2207,3 +2207,36 @@ func TestImageClip(t *testing.T) {
}
}
}
// Issue #1691
func TestImageSubImageFill(t *testing.T) {
dst := NewImage(3, 3).SubImage(image.Rect(1, 1, 2, 2)).(*Image)
dst.Fill(color.White)
for j := 0; j < 3; j++ {
for i := 0; i < 3; i++ {
got := dst.At(i, j)
var want color.RGBA
if i == 1 && j == 1 {
want = color.RGBA{0xff, 0xff, 0xff, 0xff}
}
if got != want {
t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want)
}
}
}
dst = NewImage(17, 31).SubImage(image.Rect(3, 4, 8, 10)).(*Image)
dst.Fill(color.White)
for j := 0; j < 31; j++ {
for i := 0; i < 17; i++ {
got := dst.At(i, j)
var want color.RGBA
if 3 <= i && i < 8 && 4 <= j && j < 10 {
want = color.RGBA{0xff, 0xff, 0xff, 0xff}
}
if got != want {
t.Errorf("dst.At(%d, %d): got: %v, want: %v", i, j, got, want)
}
}
}
}