mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
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:
parent
712940cb02
commit
ddced3af9f
3
image.go
3
image.go
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user