From f175b58d1b93123b2c022888e9a848eb4564b60f Mon Sep 17 00:00:00 2001
From: faiface <faiface@ksp.sk>
Date: Thu, 5 Jan 2017 15:02:31 +0100
Subject: [PATCH] optimize picture constructor for RGBA images

---
 picture.go | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/picture.go b/picture.go
index 49b79bb..4ac181c 100644
--- a/picture.go
+++ b/picture.go
@@ -21,8 +21,13 @@ type Picture struct {
 // NewPicture creates a new picture from an image.Image.
 func NewPicture(img image.Image, smooth bool) *Picture {
 	// convert the image to RGBA format
-	rgba := image.NewRGBA(image.Rect(0, 0, img.Bounds().Dx(), img.Bounds().Dy()))
-	draw.Draw(rgba, rgba.Bounds(), img, img.Bounds().Min, draw.Src)
+	var rgba *image.RGBA
+	if img, ok := img.(*image.RGBA); ok {
+		rgba = img
+	} else {
+		rgba = image.NewRGBA(image.Rect(0, 0, img.Bounds().Dx(), img.Bounds().Dy()))
+		draw.Draw(rgba, rgba.Bounds(), img, img.Bounds().Min, draw.Src)
+	}
 
 	var texture *pixelgl.Texture
 	pixelgl.Do(func() {
-- 
GitLab