diff --git a/color.go b/color.go index 7345e4a..45d424c 100644 --- a/color.go +++ b/color.go @@ -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) +}