graphics: Bug fix: a sub image's Size was wrong

Fixes #732
This commit is contained in:
Hajime Hoshi 2018-11-08 04:22:19 +09:00
parent 859cfa14ac
commit 76ac850f6b
2 changed files with 14 additions and 2 deletions

View File

@ -150,7 +150,8 @@ func (i *Image) copyCheck() {
// Size returns the size of the image.
func (i *Image) Size() (width, height int) {
return i.mipmap.original().Size()
s := i.Bounds().Size()
return s.X, s.Y
}
func (i *Image) isDisposed() bool {
@ -569,7 +570,7 @@ func (i *Image) SubImage(r image.Rectangle) image.Image {
// Bounds returns the bounds of the image.
func (i *Image) Bounds() image.Rectangle {
if i.bounds == nil {
w, h := i.Size()
w, h := i.mipmap.original().Size()
return image.Rect(0, 0, w, h)
}
return *i.bounds

View File

@ -1034,3 +1034,14 @@ func TestImageSubImageAt(t *testing.T) {
t.Errorf("got: %v, want: %v", got, want)
}
}
func TestImageSubImageSize(t *testing.T) {
img, _ := NewImage(16, 16, FilterDefault)
img.Fill(color.RGBA{0xff, 0, 0, 0xff})
got, _ := img.SubImage(image.Rect(1, 1, 16, 16)).(*Image).Size()
want := 15
if got != want {
t.Errorf("got: %v, want: %v", got, want)
}
}