diff --git a/internal/graphics/image.go b/internal/graphics/image.go index a6fefaae0..e5b26c5d8 100644 --- a/internal/graphics/image.go +++ b/internal/graphics/image.go @@ -51,7 +51,7 @@ func CopyImage(origImg image.Image) *image.RGBA { pix1 := newImg.Pix for j := 0; j < y1-y0; j++ { for i := 0; i < x1-x0; i++ { - p := pix0[index0] + p := int(pix0[index0]) pix1[index1] = palette[4*p] pix1[index1+1] = palette[4*p+1] pix1[index1+2] = palette[4*p+2] diff --git a/internal/graphics/image_test.go b/internal/graphics/image_test.go index c501d0521..c48f5c1f8 100644 --- a/internal/graphics/image_test.go +++ b/internal/graphics/image_test.go @@ -28,6 +28,15 @@ func TestCopyImage(t *testing.T) { for i := range pal { pal[i] = color.White } + p := make([]color.Color, 255) + for i := range p { + if i == 64 { + p[i] = color.White + } else { + p[i] = color.Transparent + } + } + bigPalette := color.Palette(p) cases := []struct { In image.Image Out *image.RGBA @@ -67,6 +76,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, + }, + Out: &image.RGBA{ + Pix: []uint8{0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0, 0, 0, 0, 0}, + Stride: 8, + Rect: image.Rect(0, 0, 2, 2), + }, + }, } for _, c := range cases { got := CopyImage(c.In)