mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
image: Add test
This commit is contained in:
parent
afe4c76b50
commit
2ab7c2eb9b
1
image.go
1
image.go
@ -171,6 +171,7 @@ func (i *Image) At(x, y int) color.Color {
|
|||||||
//
|
//
|
||||||
// This function may be slow (as for implementation, this calls glTexSubImage2D).
|
// This function may be slow (as for implementation, this calls glTexSubImage2D).
|
||||||
func (i *Image) ReplacePixels(p []uint8) error {
|
func (i *Image) ReplacePixels(p []uint8) error {
|
||||||
|
// TODO: Can we set p to pixels?
|
||||||
i.pixels = nil
|
i.pixels = nil
|
||||||
w, h := i.Size()
|
w, h := i.Size()
|
||||||
l := 4 * w * h
|
l := 4 * w * h
|
||||||
|
@ -203,8 +203,23 @@ func TestReplacePixels(t *testing.T) {
|
|||||||
img0.ReplacePixels(img.Pix)
|
img0.ReplacePixels(img.Pix)
|
||||||
for j := 0; j < img0.Bounds().Size().Y; j++ {
|
for j := 0; j < img0.Bounds().Size().Y; j++ {
|
||||||
for i := 0; i < img0.Bounds().Size().X; i++ {
|
for i := 0; i < img0.Bounds().Size().X; i++ {
|
||||||
got := img.At(i, j)
|
got := img0.At(i, j)
|
||||||
want := img0.At(i, j)
|
want := img.At(i, j)
|
||||||
|
if got != want {
|
||||||
|
t.Errorf("img0 At(%d, %d): got %#v; want %#v", i, j, got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p := make([]uint8, 4*size.X*size.Y)
|
||||||
|
for i, _ := range p {
|
||||||
|
p[i] = 0x80
|
||||||
|
}
|
||||||
|
img0.ReplacePixels(p)
|
||||||
|
for j := 0; j < img0.Bounds().Size().Y; j++ {
|
||||||
|
for i := 0; i < img0.Bounds().Size().X; i++ {
|
||||||
|
got := img0.At(i, j)
|
||||||
|
want := color.RGBA{p[4*i], p[4*i+1], p[4*i+2], p[4*i+3]}
|
||||||
if got != want {
|
if got != want {
|
||||||
t.Errorf("img0 At(%d, %d): got %#v; want %#v", i, j, got, want)
|
t.Errorf("img0 At(%d, %d): got %#v; want %#v", i, j, got, want)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user