flip image in Picture to make it correct

This commit is contained in:
faiface 2017-01-22 02:49:45 +01:00
parent ca9b2716a8
commit 8e1359b45d
1 changed files with 10 additions and 0 deletions

View File

@ -25,6 +25,16 @@ func NewPicture(img image.Image, smooth bool) *Picture {
nrgba := image.NewNRGBA(image.Rect(0, 0, bounds.Dx(), bounds.Dy()))
draw.Draw(nrgba, nrgba.Bounds(), img, bounds.Min, draw.Src)
// flip the image vertically
tmp := make([]byte, nrgba.Stride)
for i, j := 0, bounds.Dy()-1; i < j; i, j = i+1, j-1 {
iSlice := nrgba.Pix[i*nrgba.Stride : (i+1)*nrgba.Stride]
jSlice := nrgba.Pix[j*nrgba.Stride : (j+1)*nrgba.Stride]
copy(tmp, iSlice)
copy(iSlice, jSlice)
copy(jSlice, tmp)
}
var texture *pixelgl.Texture
mainthread.Call(func() {
texture = pixelgl.NewTexture(