graphics: Bug fix: Too small mipmap

Bug: #839
This commit is contained in:
Hajime Hoshi 2019-04-07 05:29:19 +09:00
parent 6cdcd1ee62
commit 3cb9d18fc4
2 changed files with 29 additions and 0 deletions

View File

@ -325,6 +325,17 @@ func (i *Image) drawImage(img *Image, options *DrawImageOptions) {
if level < 0 { if level < 0 {
panic(fmt.Sprintf("ebiten: level must be >= 0 but %d", level)) panic(fmt.Sprintf("ebiten: level must be >= 0 but %d", level))
} }
// If the image can be scaled into 0 size, adjust the level. (#839)
w, h := bounds.Dx(), bounds.Dy()
for level >= 0 {
s := 1 << uint(level)
if w/s == 0 || h/s == 0 {
level--
continue
}
break
}
} }
if level > 6 { if level > 6 {
level = 6 level = 6

View File

@ -1652,3 +1652,21 @@ func TestImageSubImageSubImage(t *testing.T) {
} }
} }
} }
// Issue 839
func TestImageTooSmallMipmap(t *testing.T) {
const w, h = 16, 16
src, _ := NewImage(w, h, FilterDefault)
dst, _ := NewImage(w, h, FilterDefault)
src.Fill(color.White)
op := &DrawImageOptions{}
op.GeoM.Scale(1, 0.24)
op.Filter = FilterLinear
dst.DrawImage(src.SubImage(image.Rect(5, 0, 6, 16)).(*Image), op)
got := dst.At(0, 0).(color.RGBA)
want := color.RGBA{0xff, 0xff, 0xff, 0xff}
if got != want {
t.Errorf("got: %v, want: %v", got, want)
}
}