diff --git a/bitmap.go b/bitmap.go index 9a3e024..093539f 100644 --- a/bitmap.go +++ b/bitmap.go @@ -231,12 +231,23 @@ func (b *Bitmap) Image() image.Image { return nil } defer C.al_unlock_bitmap(b.bitmap) - src := (*[1 << 30]uint8)(region.data) - dst := im.Pix + + pitch := int(region.pitch) + length := b.height * pitch + data := uintptr(region.data) var srcOff, dstOff int + if pitch < 0 { + srcOff = (b.height - 1) * -pitch + length *= -1 + data = data - uintptr(srcOff) + } + + rowLength := b.width * 4 + src := (*[1 << 28]uint8)(unsafe.Pointer(data))[:length:length] + dst := im.Pix for y := 0; y < b.height; y++ { - copy(dst[dstOff:], src[srcOff:srcOff+b.width*4]) - srcOff += int(region.pitch) + copy(dst[dstOff:], src[srcOff:srcOff+rowLength]) + srcOff += pitch dstOff += im.Stride } return im