summaryrefslogtreecommitdiffstats
path: root/xlib
diff options
context:
space:
mode:
authornijtmans@users.sourceforge.net <jan.nijtmans>2012-02-15 20:57:48 (GMT)
committernijtmans@users.sourceforge.net <jan.nijtmans>2012-02-15 20:57:48 (GMT)
commit2d29beaca054ac2c29f5c7fea5211966ff856914 (patch)
treeb69a457a0eaaa41f3bf3c89239cd80372fd4b53e /xlib
parent7d299c2a9f06b85cca9664a51339aaceb863877e (diff)
parentba59668516533c4b1fbc83bdc4333845c9f49148 (diff)
downloadtk-2d29beaca054ac2c29f5c7fea5211966ff856914.zip
tk-2d29beaca054ac2c29f5c7fea5211966ff856914.tar.gz
tk-2d29beaca054ac2c29f5c7fea5211966ff856914.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 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;