From 5559f346214687b075f05fc797f7936ad30162f3 Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Tue, 12 May 2020 21:03:50 +0200 Subject: [PATCH] Fixed bug with negative pitch. --- bitmap.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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