mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: Fix TestImagePixels to check out-of-range pixels
This commit is contained in:
parent
91681bdc25
commit
0967df7f5e
@ -25,6 +25,7 @@ import (
|
||||
"testing"
|
||||
|
||||
. "github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
@ -87,8 +88,11 @@ func TestImagePixels(t *testing.T) {
|
||||
t.Fatalf("img size: got %d; want %d", got, img.Bounds().Size())
|
||||
}
|
||||
|
||||
for j := 0; j < img0.Bounds().Size().Y; j++ {
|
||||
for i := 0; i < img0.Bounds().Size().X; i++ {
|
||||
w, h := img0.Bounds().Size().X, img0.Bounds().Size().Y
|
||||
// Check out of range part
|
||||
w2, h2 := graphics.NextPowerOf2Int(w), graphics.NextPowerOf2Int(h)
|
||||
for j := -100; j < h2+100; j++ {
|
||||
for i := -100; i < w2+100; i++ {
|
||||
got := img0.At(i, j)
|
||||
want := color.RGBAModel.Convert(img.At(i, j))
|
||||
if got != want {
|
||||
|
@ -170,13 +170,17 @@ func (p *Image) appendDrawImageHistory(image *Image, vertices []float32, colorm
|
||||
// Note that this must not be called until context is available.
|
||||
// This means Pixels members must match with acutal state in VRAM.
|
||||
func (p *Image) At(x, y int, context *opengl.Context) (color.RGBA, error) {
|
||||
w, _ := p.image.Size()
|
||||
w, h := p.image.Size()
|
||||
w2, h2 := graphics.NextPowerOf2Int(w), graphics.NextPowerOf2Int(h)
|
||||
if x < 0 || y < 0 || w2 <= x || h2 <= y {
|
||||
return color.RGBA{}, nil
|
||||
}
|
||||
if p.basePixels == nil || p.drawImageHistory != nil || p.stale {
|
||||
if err := p.readPixelsFromVRAM(p.image, context); err != nil {
|
||||
return color.RGBA{}, err
|
||||
}
|
||||
}
|
||||
idx := 4*x + 4*y*graphics.NextPowerOf2Int(w)
|
||||
idx := 4*x + 4*y*w2
|
||||
r, g, b, a := p.basePixels[idx], p.basePixels[idx+1], p.basePixels[idx+2], p.basePixels[idx+3]
|
||||
return color.RGBA{r, g, b, a}, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user