zntg/sdlui/image.go

27 lines
469 B
Go

package sdlui
import (
"image"
"image/draw"
)
func NRGBAImage(m image.Image) *image.NRGBA {
nrgba, ok := m.(*image.NRGBA)
if ok {
return nrgba
}
nrgba = image.NewNRGBA(m.Bounds())
draw.Draw(nrgba, nrgba.Bounds(), m, image.ZP, draw.Over)
return nrgba
}
func RGBAImage(m image.Image) *image.RGBA {
rgba, ok := m.(*image.RGBA)
if ok {
return rgba
}
rgba = image.NewRGBA(m.Bounds())
draw.Draw(rgba, rgba.Bounds(), m, image.ZP, draw.Over)
return rgba
}