v4/utils/colors.go
2025-04-05 22:02:17 -07:00

21 lines
408 B
Go

package utils
import "math"
func IsDarkColor(r, g, b uint8) bool {
rC := 0.299 * math.Pow(float64(r), 2)
gC := 0.587 * math.Pow(float64(g), 2)
bC := 0.114 * math.Pow(float64(b), 2)
lum := math.Sqrt(rC + gC + bC)
return lum <= 130
}
func IntToRgb(color uint32) (uint8, uint8, uint8) {
b := color % 256
g := color / 256 % 256
r := color / (256 * 256) % 256
return uint8(r), uint8(g), uint8(b)
}