Bug fix: image can't draw itself (#45)

This commit is contained in:
Hajime Hoshi 2015-01-06 23:50:02 +09:00
parent 0ab90197a3
commit 4eaba93c73
2 changed files with 17 additions and 2 deletions

View File

@ -15,6 +15,7 @@
package ebiten
import (
"errors"
"github.com/hajimehoshi/ebiten/internal"
"github.com/hajimehoshi/ebiten/internal/graphics"
"github.com/hajimehoshi/ebiten/internal/opengl"
@ -177,6 +178,9 @@ func (i *Image) Fill(clr color.Color) (err error) {
// Be careful that this method is potentially slow.
// It would be better if you could call this method fewer times.
func (i *Image) DrawImage(image *Image, options *DrawImageOptions) (err error) {
if i == image {
return errors.New("Image.DrawImage: image should be different from the receiver")
}
return i.drawImage(image.inner, options)
}

View File

@ -49,7 +49,7 @@ func diff(x, y uint8) uint8 {
return x - y
}
func TestPixels(t *testing.T) {
func TestImagePixels(t *testing.T) {
eimg, img, err := openImage("testdata/ebiten.png")
if err != nil {
t.Fatal(err)
@ -71,7 +71,7 @@ func TestPixels(t *testing.T) {
}
}
func TestComposition(t *testing.T) {
func TestImageComposition(t *testing.T) {
img2Color := color.NRGBA{0x24, 0x3f, 0x6a, 0x88}
img3Color := color.NRGBA{0x85, 0xa3, 0x08, 0xd3}
@ -134,4 +134,15 @@ func TestComposition(t *testing.T) {
}
}
func TestImageSelf(t *testing.T) {
img, _, err := openImage("testdata/ebiten.png")
if err != nil {
t.Fatal(err)
return
}
if err := img.DrawImage(img, nil); err == nil {
t.Fatalf("img.DrawImage(img, nil) doesn't return error; an error should be return")
}
}
// TODO: Add more tests (e.g. DrawImage with color matrix)