ha-rgb-screen/internal/img/image.go
2025-11-12 18:24:46 +01:00

32 lines
552 B
Go

package img
import "image"
type RGB struct {
R float64
G float64
B float64
}
func GetRgbAverage(i *image.RGBA) RGB {
bounds := i.Bounds()
var rSum, gSum, bSum uint64
var count uint64
for y := bounds.Min.Y; y < bounds.Max.Y; y++ {
for x := bounds.Min.X; x < bounds.Max.X; x++ {
r, g, b, _ := i.At(x, y).RGBA()
rSum += uint64(r >> 8)
gSum += uint64(g >> 8)
bSum += uint64(b >> 8)
count++
}
}
return RGB{
R: float64(rSum) / float64(count),
G: float64(gSum) / float64(count),
B: float64(bSum) / float64(count),
}
}