add ToNRGBA function for performance
This commit is contained in:
parent
3cfa3a5395
commit
6eeff66728
14
color.go
14
color.go
|
@ -75,10 +75,9 @@ func clamp(x, low, high float64) float64 {
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
|
|
||||||
// NRGBAModel converts colors to NRGBA format.
|
// ToNRGBA converts a color to NRGBA format. Using this function is preferred to using NRGBAModel,
|
||||||
var NRGBAModel = color.ModelFunc(nrgbaModel)
|
// for performance (using NRGBAModel introduced additional unnecessary allocations).
|
||||||
|
func ToNRGBA(c color.Color) NRGBA {
|
||||||
func nrgbaModel(c color.Color) color.Color {
|
|
||||||
if c, ok := c.(NRGBA); ok {
|
if c, ok := c.(NRGBA); ok {
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
@ -101,3 +100,10 @@ func nrgbaModel(c color.Color) color.Color {
|
||||||
float64(a) / 0xffff,
|
float64(a) / 0xffff,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NRGBAModel converts colors to NRGBA format.
|
||||||
|
var NRGBAModel = color.ModelFunc(nrgbaModel)
|
||||||
|
|
||||||
|
func nrgbaModel(c color.Color) color.Color {
|
||||||
|
return ToNRGBA(c)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue