graphics: Bug fix: Wrong palette usage when the palette is big

This commit is contained in:
Hajime Hoshi 2017-02-19 02:56:07 +09:00
parent 5466ac504f
commit acc488b980
2 changed files with 23 additions and 1 deletions

View File

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

View File

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