ebiten: bug fix: Fill and Clear doesn't work on an image whose upper-left is not (0, 0)

Closes #2159
This commit is contained in:
Hajime Hoshi 2022-06-24 02:01:58 +09:00
parent 712940cb02
commit ddced3af9f
2 changed files with 66 additions and 1 deletions

View File

@ -82,7 +82,8 @@ func (i *Image) Fill(clr color.Color) {
caf = float32(ca) / 0xffff
}
b := i.Bounds()
i.image.Fill(crf, cgf, cbf, caf, b.Min.X, b.Min.Y, b.Dx(), b.Dy())
x, y := i.adjustPosition(b.Min.X, b.Min.Y)
i.image.Fill(crf, cgf, cbf, caf, x, y, b.Dx(), b.Dy())
}
func canSkipMipmap(geom GeoM, filter graphicsdriver.Filter) bool {

View File

@ -3180,3 +3180,67 @@ func TestImageFromEbitenImageOptions(t *testing.T) {
}
}
}
// Issue #2159
func TestImageOptionsFill(t *testing.T) {
r0 := image.Rect(-2, -3, 4, 5)
img := ebiten.NewImageWithOptions(r0, nil)
img.Fill(color.RGBA{0xff, 0, 0, 0xff})
for j := r0.Min.Y; j < r0.Max.Y; j++ {
for i := r0.Min.X; i < r0.Max.X; i++ {
got := img.At(i, j)
want := color.RGBA{0xff, 0, 0, 0xff}
if got != want {
t.Errorf("img.At(%d, %d): got: %v, want: %v", i, j, got, want)
}
}
}
r1 := image.Rect(-1, -2, 3, 4)
img.SubImage(r1).(*ebiten.Image).Fill(color.RGBA{0, 0xff, 0, 0xff})
for j := r0.Min.Y; j < r0.Max.Y; j++ {
for i := r0.Min.X; i < r0.Max.X; i++ {
got := img.At(i, j)
want := color.RGBA{0xff, 0, 0, 0xff}
if image.Pt(i, j).In(r1) {
want = color.RGBA{0, 0xff, 0, 0xff}
}
if got != want {
t.Errorf("img.At(%d, %d): got: %v, want: %v", i, j, got, want)
}
}
}
}
// Issue #2159
func TestImageOptionsClear(t *testing.T) {
r0 := image.Rect(-2, -3, 4, 5)
img := ebiten.NewImageWithOptions(r0, nil)
img.Fill(color.RGBA{0xff, 0, 0, 0xff})
img.Clear()
for j := r0.Min.Y; j < r0.Max.Y; j++ {
for i := r0.Min.X; i < r0.Max.X; i++ {
got := img.At(i, j)
want := color.RGBA{0, 0, 0, 0}
if got != want {
t.Errorf("img.At(%d, %d): got: %v, want: %v", i, j, got, want)
}
}
}
img.Fill(color.RGBA{0xff, 0, 0, 0xff})
r1 := image.Rect(-1, -2, 3, 4)
img.SubImage(r1).(*ebiten.Image).Clear()
for j := r0.Min.Y; j < r0.Max.Y; j++ {
for i := r0.Min.X; i < r0.Max.X; i++ {
got := img.At(i, j)
want := color.RGBA{0xff, 0, 0, 0xff}
if image.Pt(i, j).In(r1) {
want = color.RGBA{0, 0, 0, 0}
}
if got != want {
t.Errorf("img.At(%d, %d): got: %v, want: %v", i, j, got, want)
}
}
}
}