Skip to content

Commit

Permalink
feat: image/colors: add ConvertBits8To24()
Browse files Browse the repository at this point in the history
  • Loading branch information
grokify committed Jan 18, 2025
1 parent 229630f commit aeef5f1
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions image/colors/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit aeef5f1

Please sign in to comment.