Skip to content

Commit 2be72e0

Browse files
committed
color split into 3 components
1 parent dd54bbc commit 2be72e0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

color.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ func ColorFromRGBA(r, g, b, a uint8) Color {
2626

2727
// ColorFromHex just cast uint32 (hex) to color type
2828
// is alias for cast:
29-
// c := glx.Color(0xff0000ff)
30-
// c := glx.ColorFromHex(0xff0000ff)
29+
//
30+
// c := glx.Color(0xff0000ff)
31+
// c := glx.ColorFromHex(0xff0000ff)
3132
func ColorFromHex(hex uint32) Color {
3233
return Color(hex)
3334
}
@@ -61,3 +62,12 @@ func (c Color) Split() (r uint8, g uint8, b uint8, a uint8) {
6162
binary.LittleEndian.PutUint32(bytes, uint32(c))
6263
return bytes[3], bytes[2], bytes[1], bytes[0]
6364
}
65+
66+
// SplitRGB will decode hex to 3 color components
67+
// each component is uint8 values (0 .. 255)
68+
// alpha component is just ignored
69+
func (c Color) SplitRGB() (r uint8, g uint8, b uint8) {
70+
bytes := make([]byte, 4)
71+
binary.LittleEndian.PutUint32(bytes, uint32(c))
72+
return bytes[3], bytes[2], bytes[1]
73+
}

0 commit comments

Comments
 (0)