]> Dogcows Code - chaz/openbox/blobdiff - otk/truerendercontrol.cc
set the log domain for each plugin properly
[chaz/openbox] / otk / truerendercontrol.cc
index ffe5b181388685a33493bd499aecd2dafd05013c..42589dd3e5f8adb2fd8e6f77337ab72826570545 100644 (file)
@@ -9,14 +9,12 @@
 #include "rendertexture.hh"
 
 extern "C" {
-#ifdef    HAVE_STDLIB_H
-#  include <stdlib.h>
-#endif // HAVE_STDLIB_H
-
 #include "../src/gettext.h"
 #define _(str) gettext(str)
 }
 
+#include <cstdlib>
+
 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;
+  }
 }
 
 }
This page took 0.025302 seconds and 4 git commands to generate.