]> Dogcows Code - chaz/openbox/blobdiff - otk/truerendercontrol.cc
make reduceDepth set the im->data member, with newly allocated data, so the pixelData...
[chaz/openbox] / otk / truerendercontrol.cc
index ffe5b181388685a33493bd499aecd2dafd05013c..2ce771ebcc32180627513ffaef776f5b4a1439d0 100644 (file)
@@ -25,10 +25,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 +56,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 +73,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 +100,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.024553 seconds and 4 git commands to generate.