From aeef5f147d7ab869dba2889ca3555fc307689e91 Mon Sep 17 00:00:00 2001 From: John Wang Date: Sat, 18 Jan 2025 13:34:26 -0800 Subject: [PATCH] feat: `image/colors`: add `ConvertBits8To24()` --- image/colors/convert.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/image/colors/convert.go b/image/colors/convert.go index 9246aaf..ecca9cb 100644 --- a/image/colors/convert.go +++ b/image/colors/convert.go @@ -149,6 +149,16 @@ func ColorString(c color.Color) string { }, ".") } +// ConvertBits8To24 converts a 8 bit color (`color.RGBA`) to a 24 bit color. +// `a` is the alphachannel. +func ConvertBits8To24(c, a uint8) int { + if a < 255 { + return int(uint16(c) * uint16(a) / 255) + } else { + return int(c) + } +} + func ColorAverageImage(i image.Image) color.Color { var r, g, b uint64