graphics: Bug fix: start pixel must start at 0 (#303)

This commit is contained in:
Hajime Hoshi 2017-01-19 10:10:57 +09:00
parent 333b0956ff
commit 3331f17723
2 changed files with 13 additions and 1 deletions

View File

@ -43,7 +43,7 @@ func CopyImage(origImg image.Image) *image.RGBA {
palette[4*i+2] = rgba.B
palette[4*i+3] = rgba.A
}
index0 := y0*origImg.Stride + x0
index0 := 0
index1 := 0
d0 := origImg.Stride - (x1 - x0)
d1 := newImg.Stride - (x1-x0)*4

View File

@ -24,6 +24,10 @@ import (
)
func TestCopyImage(t *testing.T) {
pal := make(color.Palette, 256)
for i := range pal {
pal[i] = color.White
}
cases := []struct {
In image.Image
Out *image.RGBA
@ -43,6 +47,14 @@ func TestCopyImage(t *testing.T) {
Rect: image.Rect(0, 0, 2, 2),
},
},
{
In: image.NewPaletted(image.Rect(0, 0, 240, 160), pal).SubImage(image.Rect(238, 158, 240, 160)),
Out: &image.RGBA{
Pix: []uint8{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
Stride: 8,
Rect: image.Rect(0, 0, 2, 2),
},
},
{
In: &image.RGBA{
Pix: []uint8{0, 0, 0, 0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0, 0, 0},