mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
Bug fix: image can't draw itself (#45)
This commit is contained in:
parent
0ab90197a3
commit
4eaba93c73
4
image.go
4
image.go
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user