From a3bd24ae53ea4e1d1c77dfc5a1171a05b5d9ca18 Mon Sep 17 00:00:00 2001 From: bptato Date: Sat, 11 Nov 2023 22:27:26 +0100 Subject: color: fix 3/6-digit hex color parsing --- src/types/color.nim | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/types/color.nim b/src/types/color.nim index 48f9d9e7..155a22ad 100644 --- a/src/types/color.nim +++ b/src/types/color.nim @@ -428,7 +428,8 @@ func parseHexColor*(s: string): Option[RGBAColor] = if hexValue(c) == -1: return none(RGBAColor) case s.len of 6: - let c = (hexValue(s[0]) shl 20) or (hexValue(s[1]) shl 16) or + let c = 0xFF000000 or + (hexValue(s[0]) shl 20) or (hexValue(s[1]) shl 16) or (hexValue(s[2]) shl 12) or (hexValue(s[3]) shl 8) or (hexValue(s[4]) shl 4) or hexValue(s[5]) return some(RGBAColor(c)) @@ -439,7 +440,8 @@ func parseHexColor*(s: string): Option[RGBAColor] = (hexValue(s[4]) shl 4) or hexValue(s[5]) return some(RGBAColor(c)) of 3: - let c = (hexValue(s[0]) shl 20) or (hexValue(s[0]) shl 16) or + let c = 0xFF000000 or + (hexValue(s[0]) shl 20) or (hexValue(s[0]) shl 16) or (hexValue(s[1]) shl 12) or (hexValue(s[1]) shl 8) or (hexValue(s[2]) shl 4) or hexValue(s[2]) return some(RGBAColor(c)) -- cgit 1.4.1-2-gfad0