From cec32d4f722ce115166d788c0b9c895cb20a78d4 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 3 Jul 2020 03:25:45 +0900 Subject: [PATCH] ebiten: Add tests to modify pixels after ReplacePixels Updates #1222 --- image_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/image_test.go b/image_test.go index 065bd0051..c15eb0198 100644 --- a/image_test.go +++ b/image_test.go @@ -2161,3 +2161,47 @@ func TestImageColorMCopy(t *testing.T) { } } } + +// TODO: Do we have to guarantee this behavior? See #1222 +func TestImageReplacePixelsAndModifyPixels(t *testing.T) { + const w, h = 16, 16 + dst, _ := NewImage(w, h, FilterDefault) + src, _ := NewImage(w, h, FilterDefault) + + pix := make([]byte, 4*w*h) + for j := 0; j < h; j++ { + for i := 0; i < w; i++ { + idx := 4 * (i + j*w) + pix[idx] = 0xff + pix[idx+1] = 0 + pix[idx+2] = 0 + pix[idx+3] = 0xff + } + } + + src.ReplacePixels(pix) + + // Modify pix after ReplacePixels + for j := 0; j < h; j++ { + for i := 0; i < w; i++ { + idx := 4 * (i + j*w) + pix[idx] = 0 + pix[idx+1] = 0xff + pix[idx+2] = 0 + pix[idx+3] = 0xff + } + } + + // Ensure that src's pixels are actually used + dst.DrawImage(src, nil) + + for j := 0; j < h; j++ { + for i := 0; i < w; i++ { + got := src.At(i, j).(color.RGBA) + want := color.RGBA{0xff, 0, 0, 0xff} + if got != want { + t.Errorf("src.At(%d, %d): got: %v, want: %v", i, j, got, want) + } + } + } +}