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)
commitdf20c28265935fe18fc843ea8e5e7493aa6a76be (patch)
treec95bfcb0f17783a66f7d2613c8962ecbd1a63748 /xlib
parentf6f9740cb0d68f61cdfc5c4c8c3aabc06ceb8bfb (diff)
parentac8934a59330e0c285c4a5c89d4e6f985dc499d5 (diff)
downloadtk-df20c28265935fe18fc843ea8e5e7493aa6a76be.zip
tk-df20c28265935fe18fc843ea8e5e7493aa6a76be.tar.gz
tk-df20c28265935fe18fc843ea8e5e7493aa6a76be.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;