X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=otk%2Ftruerendercontrol.cc;h=42589dd3e5f8adb2fd8e6f77337ab72826570545;hb=0c2f95674f56e25e2b74cce506d9d89ec41252a4;hp=ffe5b181388685a33493bd499aecd2dafd05013c;hpb=72ff846dbb56ec36231fb761b864da09885d3690;p=chaz%2Fopenbox diff --git a/otk/truerendercontrol.cc b/otk/truerendercontrol.cc index ffe5b181..42589dd3 100644 --- a/otk/truerendercontrol.cc +++ b/otk/truerendercontrol.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 { TrueRenderControl::TrueRenderControl(int screen) @@ -25,10 +23,11 @@ TrueRenderControl::TrueRenderControl(int screen) _green_offset(0), _blue_offset(0) { + printf("Initializing TrueColor RenderControl\n"); + const ScreenInfo *info = display->screenInfo(_screen); XImage *timage = XCreateImage(**display, info->visual(), info->depth(), ZPixmap, 0, NULL, 1, 1, 32, 0); - printf("Initializing TrueColor RenderControl\n"); unsigned long red_mask, green_mask, blue_mask; @@ -55,11 +54,12 @@ TrueRenderControl::~TrueRenderControl() void TrueRenderControl::reduceDepth(Surface &sf, XImage *im) const { -// since pixel32 is the largest possible pixel size, we can share the array + // since pixel32 is the largest possible pixel size, we can share the array int r, g, b; int x,y; pixel32 *data = sf.pixelData(); - pixel16 *p = (pixel16*) data; + pixel32 *ret = (pixel32*)malloc(im->width * im->height * 4); + pixel16 *p = (pixel16*) ret; switch (im->bits_per_pixel) { case 32: if ((_red_offset != default_red_shift) || @@ -71,13 +71,15 @@ void TrueRenderControl::reduceDepth(Surface &sf, XImage *im) const r = (data[x] >> default_red_shift) & 0xFF; g = (data[x] >> default_green_shift) & 0xFF; b = (data[x] >> default_blue_shift) & 0xFF; - data[x] = (r << _red_offset) + (g << _green_offset) + + ret[x] = (r << _red_offset) + (g << _green_offset) + (b << _blue_offset); } data += im->width; } - } - return; + } else { + memcpy(ret, data, im->width * im->height * 4); + } + break; case 16: for (y = 0; y < im->height; y++) { for (x = 0; x < im->width; x++) { @@ -96,6 +98,17 @@ void TrueRenderControl::reduceDepth(Surface &sf, XImage *im) const default: printf("your bit depth is currently unhandled\n"); } + im->data = (char*)ret; +} + +void TrueRenderControl::allocateColor(XColor *color) const +{ + const ScreenInfo *info = display->screenInfo(_screen); + if (!XAllocColor(**display, info->colormap(), color)) { + fprintf(stderr, "TrueRenderControl: color alloc error: rgb:%x/%x/%x\n", + color->red & 0xff, color->green & 0xff, color->blue & 0xff); + color->pixel = 0; + } } }