fix mutating *image.RGBA when converting PictureDataFromImage

This commit is contained in:
faiface 2018-03-29 16:18:37 +02:00
parent 81ecf115f0
commit f6ed7c9db5
1 changed files with 2 additions and 7 deletions

View File

@ -165,13 +165,8 @@ func verticalFlip(rgba *image.RGBA) {
// //
// The resulting PictureData's Bounds will be the equivalent of the supplied image.Image's Bounds. // The resulting PictureData's Bounds will be the equivalent of the supplied image.Image's Bounds.
func PictureDataFromImage(img image.Image) *PictureData { func PictureDataFromImage(img image.Image) *PictureData {
var rgba *image.RGBA rgba := image.NewRGBA(img.Bounds())
if rgbaImg, ok := img.(*image.RGBA); ok { draw.Draw(rgba, rgba.Bounds(), img, img.Bounds().Min, draw.Src)
rgba = rgbaImg
} else {
rgba = image.NewRGBA(img.Bounds())
draw.Draw(rgba, rgba.Bounds(), img, img.Bounds().Min, draw.Src)
}
verticalFlip(rgba) verticalFlip(rgba)