summaryrefslogtreecommitdiffstats
path: root/xlib
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2012-02-15 21:09:27 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2012-02-15 21:09:27 (GMT)
commit41cc9023c9d8ba470b41666d54cfe4db9bbb5020 (patch)
treec95bfcb0f17783a66f7d2613c8962ecbd1a63748 /xlib
parentda13c5e294143c51bdee3d5d9f42c72b1843dc51 (diff)
parent3db9fce4a20b8969cd5c73671c76dd4918d048f9 (diff)
downloadtk-41cc9023c9d8ba470b41666d54cfe4db9bbb5020.zip
tk-41cc9023c9d8ba470b41666d54cfe4db9bbb5020.tar.gz
tk-41cc9023c9d8ba470b41666d54cfe4db9bbb5020.tar.bz2
[Bug 3486474]: Inconsistent color scaling
Diffstat (limited to 'xlib')
-rw-r--r--xlib/xcolors.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/xlib/xcolors.c b/xlib/xcolors.c
index be9e479..0f3085c 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;