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