diff options
| author | Dana Jansens <danakj@orodu.net> | 2003-02-14 08:01:44 +0000 |
|---|---|---|
| committer | Dana Jansens <danakj@orodu.net> | 2003-02-14 08:01:44 +0000 |
| commit | 01a37dfe1888f1ac6da7ab12c6e4d59ce104d12c (patch) | |
| tree | 63fa5cbb7476634aea8f8e4f0b7108023d83e102 /otk/pseudorendercontrol.cc | |
| parent | 49974f6916c98a23189daefa19dd79986629fe8f (diff) | |
allocate colors in pseudocolor from the map we allocate in the rendercontrol
Diffstat (limited to 'otk/pseudorendercontrol.cc')
| -rw-r--r-- | otk/pseudorendercontrol.cc | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/otk/pseudorendercontrol.cc b/otk/pseudorendercontrol.cc index 89e95ab6..29636ee9 100644 --- a/otk/pseudorendercontrol.cc +++ b/otk/pseudorendercontrol.cc @@ -93,9 +93,8 @@ int tr, tg, tb; _colors[i].pixel = icolors[close].pixel; // try alloc this closest color, it had better succeed! - if (XAllocColor(**display, info->colormap(), &_colors[i])) { + if (XAllocColor(**display, info->colormap(), &_colors[i])) _colors[i].flags = DoRed|DoGreen|DoBlue; // mark as alloced - } else assert(false); // wtf has gone wrong, its already alloced for chissake! } @@ -135,4 +134,44 @@ void PseudoRenderControl::reduceDepth(Surface &sf, XImage *im) const } +void PseudoRenderControl::allocateColor(XColor *color) const +{ + const ScreenInfo *info = display->screenInfo(_screen); + int depth = info->depth(); + + // get the allocated values from the X server (only the first 256 XXX why!?) + XColor icolors[256]; + int incolors = (((1 << depth) > 256) ? 256 : (1 << depth)); + for (int i = 0; i < incolors; i++) + icolors[i].pixel = i; + XQueryColors(**display, info->colormap(), icolors, incolors); + + unsigned long closest = 0xffffffff, close = 0; + for (int ii = 0; ii < incolors; ii++) { + // find deviations + int r = (color->red - icolors[ii].red) & 0xff; + int g = (color->green - icolors[ii].green) & 0xff; + int b = (color->blue - icolors[ii].blue) & 0xff; + // find a weighted absolute deviation + unsigned long dev = (r * r) + (g * g) + (b * b); + + if (dev < closest) { + closest = dev; + close = ii; + } + } + + color->red = icolors[close].red; + color->green = icolors[close].green; + color->blue = icolors[close].blue; + color->pixel = icolors[close].pixel; + + // try alloc this closest color, it had better succeed! + if (XAllocColor(**display, info->colormap(), color)) { + color->flags = DoRed|DoGreen|DoBlue; // mark as alloced + } + else + assert(false); // wtf has gone wrong, its already alloced for chissake! +} + } |
