graphicsutil: Add tests

This commit is contained in:
Hajime Hoshi 2018-03-09 00:19:10 +09:00
parent 36b249b320
commit 4c7025a05f
2 changed files with 14 additions and 0 deletions

View File

@ -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++ {

View File

@ -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)