Fixed bug with negative pitch.
This commit is contained in:
parent
14a0614ced
commit
5559f34621
19
bitmap.go
19
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
|
||||
|
Loading…
Reference in New Issue
Block a user