diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2012-02-15 20:57:48 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2012-02-15 20:57:48 (GMT) |
commit | 3db9fce4a20b8969cd5c73671c76dd4918d048f9 (patch) | |
tree | b69a457a0eaaa41f3bf3c89239cd80372fd4b53e /xlib/xcolors.c | |
parent | 751529e39515a7968bd597326de78c0f9f220f44 (diff) | |
parent | 05750b46ee02ad06be61476b42f8a1a8d8a87597 (diff) | |
download | tk-3db9fce4a20b8969cd5c73671c76dd4918d048f9.zip tk-3db9fce4a20b8969cd5c73671c76dd4918d048f9.tar.gz tk-3db9fce4a20b8969cd5c73671c76dd4918d048f9.tar.bz2 |
[Bug 3486474]: Inconsistent color scaling
Diffstat (limited to 'xlib/xcolors.c')
-rw-r--r-- | xlib/xcolors.c | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/xlib/xcolors.c b/xlib/xcolors.c index ad33b7b..b1d1f27 100644 --- a/xlib/xcolors.c +++ b/xlib/xcolors.c @@ -879,24 +879,33 @@ XParseColor( XColor *colorPtr) { if (spec[0] == '#') { - char fmt[16]; - int i, red, green, blue; + char *p; + Tcl_WideInt value = _strtoi64(++spec, &p, 16); - if ((i = (int) strlen(spec+1))%3) { - return 0; - } - i /= 3; - - sprintf(fmt, "%%%dx%%%dx%%%dx", i, i, i); - if (sscanf(spec+1, fmt, &red, &green, &blue) != 3) { + switch ((int)(p-spec)) { + case 3: + colorPtr->red = (unsigned short) (((value >> 8) & 0xf) * 0x1111); + colorPtr->green = (unsigned short) (((value >> 4) & 0xf) * 0x1111); + colorPtr->blue = (unsigned short) ((value & 0xf) * 0x1111); + break; + case 6: + colorPtr->red = (unsigned short) (((value >> 16) & 0xff) | ((value >> 8) & 0xff00)); + colorPtr->green = (unsigned short) (((value >> 8) & 0xff) | (value & 0xff00)); + colorPtr->blue = (unsigned short) ((value & 0xff) | (value << 8)); + break; + case 9: + colorPtr->red = (unsigned short) (((value >> 32) & 0xf) | ((value >> 20) & 0xfff0)); + colorPtr->green = (unsigned short) (((value >> 20) & 0xf) | ((value >> 8) & 0xfff0)); + colorPtr->blue = (unsigned short) (((value >> 8) & 0xf) | (value << 4)); + break; + case 12: + colorPtr->red = (unsigned short) (value >> 32); + colorPtr->green = (unsigned short) (value >> 16); + colorPtr->blue = (unsigned short) value; + break; + default: return 0; } - colorPtr->red = (((unsigned short) red) << (4 * (4 - i))) - | ((unsigned short) red); - colorPtr->green = (((unsigned short) green) << (4 * (4 - i))) - | ((unsigned short) green); - colorPtr->blue = (((unsigned short) blue) << (4 * (4 - i))) - | ((unsigned short) blue); } else { if (!FindColor(spec, colorPtr)) { return 0; |