mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-05 17:35:36 +00:00
app/headless: compensate for OpenGL's lower left origin
The origin of image.Images is the upper left corner. Convert the ReadPixels result by flipping the image the y-direction. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -111,6 +111,17 @@ func (w *Window) Screenshot() (*image.RGBA, error) {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
// Flip image in y-direction. OpenGL's origin is in the lower
|
||||||
|
// left corner.
|
||||||
|
row := make([]uint8, img.Stride)
|
||||||
|
for y := 0; y < w.size.Y/2; y++ {
|
||||||
|
y1 := w.size.Y - y - 1
|
||||||
|
dest := img.PixOffset(0, y1)
|
||||||
|
src := img.PixOffset(0, y)
|
||||||
|
copy(row, img.Pix[dest:])
|
||||||
|
copy(img.Pix[dest:], img.Pix[src:src+len(row)])
|
||||||
|
copy(img.Pix[src:], row)
|
||||||
|
}
|
||||||
return img, nil
|
return img, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user