add ToNRGBA function for performance

This commit is contained in:
faiface 2017-03-23 23:03:07 +01:00
parent 3cfa3a5395
commit 6eeff66728
1 changed files with 10 additions and 4 deletions

View File

@ -75,10 +75,9 @@ func clamp(x, low, high float64) float64 {
return x
}
// NRGBAModel converts colors to NRGBA format.
var NRGBAModel = color.ModelFunc(nrgbaModel)
func nrgbaModel(c color.Color) color.Color {
// ToNRGBA converts a color to NRGBA format. Using this function is preferred to using NRGBAModel,
// for performance (using NRGBAModel introduced additional unnecessary allocations).
func ToNRGBA(c color.Color) NRGBA {
if c, ok := c.(NRGBA); ok {
return c
}
@ -101,3 +100,10 @@ func nrgbaModel(c color.Color) color.Color {
float64(a) / 0xffff,
}
}
// NRGBAModel converts colors to NRGBA format.
var NRGBAModel = color.ModelFunc(nrgbaModel)
func nrgbaModel(c color.Color) color.Color {
return ToNRGBA(c)
}