From 4c7025a05f41b77c3eb4c7950b73986596e6503f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 9 Mar 2018 00:19:10 +0900 Subject: [PATCH] graphicsutil: Add tests --- internal/graphicsutil/copy.go | 1 + internal/graphicsutil/copy_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/internal/graphicsutil/copy.go b/internal/graphicsutil/copy.go index c6f657f2c..c4cfc1a9a 100644 --- a/internal/graphicsutil/copy.go +++ b/internal/graphicsutil/copy.go @@ -51,6 +51,7 @@ func CopyImage(origImg image.Image) *image.RGBA { index1 := 0 d0 := origImg.Stride - (x1 - x0) d1 := newImg.Stride - (x1-x0)*4 + // Even origImg is a subimage of another image, Pix starts with 0-th index. pix0 := origImg.Pix pix1 := newImg.Pix for j := 0; j < y1-y0; j++ { diff --git a/internal/graphicsutil/copy_test.go b/internal/graphicsutil/copy_test.go index ec6de78bd..6b13dbf5f 100644 --- a/internal/graphicsutil/copy_test.go +++ b/internal/graphicsutil/copy_test.go @@ -89,6 +89,19 @@ func TestCopyImage(t *testing.T) { Rect: image.Rect(0, 0, 2, 2), }, }, + { + In: (&image.Paletted{ + Pix: []uint8{0, 64, 0, 0}, + Stride: 2, + Rect: image.Rect(0, 0, 2, 2), + Palette: bigPalette, + }).SubImage(image.Rect(1, 0, 2, 1)), + Out: &image.RGBA{ + Pix: []uint8{0xff, 0xff, 0xff, 0xff}, + Stride: 4, + Rect: image.Rect(0, 0, 1, 1), + }, + }, } for _, c := range cases { got := CopyImage(c.In)