X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Fpseudorendercontrol.cc;h=cf9929248586e4e2c12d0b002eba771bcfb610fe;hb=9c2b06668e349901791fb9fe459cc511e460287e;hp=89e95ab6eec20b327ba4841b66f39eb59d576da4;hpb=1431cd19584e750309561e0054fd013d566965cb;p=chaz%2Fopenbox diff --git a/otk/pseudorendercontrol.cc b/otk/pseudorendercontrol.cc index 89e95ab6..cf992924 100644 --- a/otk/pseudorendercontrol.cc +++ b/otk/pseudorendercontrol.cc @@ -9,14 +9,12 @@ #include "rendertexture.hh" extern "C" { -#ifdef HAVE_STDLIB_H -# include -#endif // HAVE_STDLIB_H - #include "../src/gettext.h" #define _(str) gettext(str) } +#include + namespace otk { PseudoRenderControl::PseudoRenderControl(int screen) @@ -93,9 +91,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! } @@ -114,25 +111,47 @@ PseudoRenderControl::~PseudoRenderControl() delete [] _colors; } +inline const XColor *PseudoRenderControl::pickColor(int r, int g, int b) const +{ + r = (r & 0xff) >> (8-_bpc); + g = (g & 0xff) >> (8-_bpc); + b = (b & 0xff) >> (8-_bpc); + return &_colors[(r << (2*_bpc)) + (g << (1*_bpc)) + b]; +} + void PseudoRenderControl::reduceDepth(Surface &sf, XImage *im) const { pixel32 *data = sf.pixelData(); - char *p = (char *)data; - int x, y, r, g, b; - for (y = 0; y < im->height; y++) { - for (x = 0; x < im->width; x++) { - r = (data[x] >> default_red_shift) & 0xFF; - r = r >> (8-_bpc); - g = (data[x] >> default_green_shift) & 0xFF; - g = g >> (8-_bpc); - b = (data[x] >> default_blue_shift) & 0xFF; - b = b >> (8-_bpc); - p[x] = _colors[(r << (2*_bpc)) + (g << (1*_bpc)) + b].pixel; - } - data += im->width; - p += im->bytes_per_line; + pixel32 *ret = (pixel32*)malloc(im->width * im->height * 4); + char *p = (char *)ret; + int x, y; + for (y = 0; y < im->height; y++) { + for (x = 0; x < im->width; x++) { + p[x] = pickColor(data[x] >> default_red_shift, + data[x] >> default_green_shift, + data[x] >> default_blue_shift)->pixel; } + data += im->width; + p += im->bytes_per_line; + } + im->data = (char*)ret; +} + +void PseudoRenderControl::allocateColor(XColor *color) const +{ + const XColor *c = pickColor(color->red, color->blue, color->green); + + color->red = c->red; + color->green = c->green; + color->blue = c->blue; + color->pixel = c->pixel; + + if (XAllocColor(**display, display->screenInfo(_screen)->colormap(), color)) + color->flags = DoRed|DoGreen|DoBlue; // mark as alloced + else + assert(false); // wtf has gone wrong, its already alloced for chissake! + return; } }