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:
Elias Naur
2019-12-02 13:58:12 +01:00
parent c0beeb5e77
commit 6fbdefa21f
+11
View File
@@ -111,6 +111,17 @@ func (w *Window) Screenshot() (*image.RGBA, error) {
}
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
}