From f272d02fffaeb57d70d95c17d1ca22f88983c73a Mon Sep 17 00:00:00 2001 From: Adrian Robert Date: Tue, 25 Nov 2008 04:39:29 +0000 Subject: [PATCH] * nsterm.m (ns_get_color): Handle long hex strings (fixes bug #1044). --- src/nsterm.m | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/nsterm.m b/src/nsterm.m index a82937a6ccf..83cc18184ba 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -1411,13 +1411,22 @@ ns_get_color (const char *name, NSColor **col) /* Direct colors (hex values) */ if (hex) { - unsigned int color = 0; + unsigned long color = 0; if (sscanf (hex, "%x", &color)) { - float f1 = ((color >> 24) & 0xff) / 255.0; - float f2 = ((color >> 16) & 0xff) / 255.0; - float f3 = ((color >> 8) & 0xff) / 255.0; - float f4 = ((color ) & 0xff) / 255.0; + float f1, f2, f3, f4; + /* Assume it's either 1 byte or 2 per channel... */ + if (strlen(hex) > 8) { + f1 = ((color >> 48) & 0xffff) / 65535.0; + f2 = ((color >> 32) & 0xffff) / 65535.0; + f3 = ((color >> 16) & 0xffff) / 65535.0; + f4 = ((color ) & 0xffff) / 65535.0; + } else { + f1 = ((color >> 24) & 0xff) / 255.0; + f2 = ((color >> 16) & 0xff) / 255.0; + f3 = ((color >> 8) & 0xff) / 255.0; + f4 = ((color ) & 0xff) / 255.0; + } switch (color_space) { -- 2.39.2