mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
graphics: Bug fix: Wrong palette usage when the palette is big
This commit is contained in:
parent
5466ac504f
commit
acc488b980
@ -51,7 +51,7 @@ func CopyImage(origImg image.Image) *image.RGBA {
|
|||||||
pix1 := newImg.Pix
|
pix1 := newImg.Pix
|
||||||
for j := 0; j < y1-y0; j++ {
|
for j := 0; j < y1-y0; j++ {
|
||||||
for i := 0; i < x1-x0; i++ {
|
for i := 0; i < x1-x0; i++ {
|
||||||
p := pix0[index0]
|
p := int(pix0[index0])
|
||||||
pix1[index1] = palette[4*p]
|
pix1[index1] = palette[4*p]
|
||||||
pix1[index1+1] = palette[4*p+1]
|
pix1[index1+1] = palette[4*p+1]
|
||||||
pix1[index1+2] = palette[4*p+2]
|
pix1[index1+2] = palette[4*p+2]
|
||||||
|
@ -28,6 +28,15 @@ func TestCopyImage(t *testing.T) {
|
|||||||
for i := range pal {
|
for i := range pal {
|
||||||
pal[i] = color.White
|
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 {
|
cases := []struct {
|
||||||
In image.Image
|
In image.Image
|
||||||
Out *image.RGBA
|
Out *image.RGBA
|
||||||
@ -67,6 +76,19 @@ func TestCopyImage(t *testing.T) {
|
|||||||
Rect: image.Rect(0, 0, 2, 2),
|
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 {
|
for _, c := range cases {
|
||||||
got := CopyImage(c.In)
|
got := CopyImage(c.In)
|
||||||
|
Loading…
Reference in New Issue
Block a user