optimize picture constructor for RGBA images

This commit is contained in:
faiface 2017-01-05 15:02:31 +01:00
parent 5b4cc5f18e
commit f175b58d1b
1 changed files with 7 additions and 2 deletions

View File

@ -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() {