graphics: Check isDisposed at (*Image).Clear and Fill

This commit is contained in:
Hajime Hoshi 2018-04-08 01:39:06 +09:00
parent ce2168c0d6
commit 008ed26276

View File

@ -61,6 +61,10 @@ func (i *Image) Size() (width, height int) {
return i.shareableImage.Size() return i.shareableImage.Size()
} }
func (i *Image) isDisposed() bool {
return i.shareableImage == nil
}
// Clear resets the pixels of the image into 0. // Clear resets the pixels of the image into 0.
// //
// When the image is disposed, Clear does nothing. // When the image is disposed, Clear does nothing.
@ -68,6 +72,9 @@ func (i *Image) Size() (width, height int) {
// Clear always returns nil as of 1.5.0-alpha. // Clear always returns nil as of 1.5.0-alpha.
func (i *Image) Clear() error { func (i *Image) Clear() error {
i.copyCheck() i.copyCheck()
if i.isDisposed() {
return nil
}
i.fill(0, 0, 0, 0) i.fill(0, 0, 0, 0)
return nil return nil
} }
@ -79,6 +86,9 @@ func (i *Image) Clear() error {
// Fill always returns nil as of 1.5.0-alpha. // Fill always returns nil as of 1.5.0-alpha.
func (i *Image) Fill(clr color.Color) error { func (i *Image) Fill(clr color.Color) error {
i.copyCheck() i.copyCheck()
if i.isDisposed() {
return nil
}
r, g, b, a := clr.RGBA() r, g, b, a := clr.RGBA()
i.fill(uint8(r>>8), uint8(g>>8), uint8(b>>8), uint8(a>>8)) i.fill(uint8(r>>8), uint8(g>>8), uint8(b>>8), uint8(a>>8))
return nil return nil
@ -103,10 +113,6 @@ func (i *Image) fill(r, g, b, a uint8) {
_ = i.DrawImage(emptyImage, op) _ = i.DrawImage(emptyImage, op)
} }
func (i *Image) isDisposed() bool {
return i.shareableImage == nil
}
// DrawImage draws the given image on the image i. // DrawImage draws the given image on the image i.
// //
// DrawImage accepts the options. For details, see the document of DrawImageOptions. // DrawImage accepts the options. For details, see the document of DrawImageOptions.