mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 09:55:40 +00:00
app/internal/d3d11: tolerate padded row pitches from D3DDeviceContext::Map
Fixes gio#136 (I think) Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -777,13 +777,15 @@ func (f *Framebuffer) ReadPixels(src image.Rectangle, pixels []byte) error {
|
|||||||
return fmt.Errorf("ReadPixels: %v", err)
|
return fmt.Errorf("ReadPixels: %v", err)
|
||||||
}
|
}
|
||||||
defer f.dev.ctx.Unmap(res, 0)
|
defer f.dev.ctx.Unmap(res, 0)
|
||||||
pitch := w * 4
|
srcPitch := w * 4
|
||||||
if int(resMap.RowPitch) != pitch {
|
dstPitch := int(resMap.RowPitch)
|
||||||
return fmt.Errorf("ReadPixels: got row pitch %d, expected %d", resMap.RowPitch, pitch)
|
mapSize := dstPitch * h
|
||||||
|
data := gunsafe.SliceOf(resMap.pData)[:mapSize:mapSize]
|
||||||
|
width := w * 4
|
||||||
|
for r := 0; r < h; r++ {
|
||||||
|
pixels := pixels[r*srcPitch:]
|
||||||
|
copy(pixels[:width], data[r*dstPitch:])
|
||||||
}
|
}
|
||||||
n := pitch * h
|
|
||||||
data := gunsafe.SliceOf(resMap.pData)[:n:n]
|
|
||||||
copy(pixels, data)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user