]> Dogcows Code - chaz/openbox/commitdiff
Fix reduce color depth to not use original data
authorDerek Foreman <manmower@gmail.com>
Sun, 6 Apr 2003 18:03:59 +0000 (18:03 +0000)
committerDerek Foreman <manmower@gmail.com>
Sun, 6 Apr 2003 18:03:59 +0000 (18:03 +0000)
(and break parentrel)

render/color.c
render/render.c

index d5821c87b5fe65949b27e1fd569b1e9a89d0a485..c25707205256a69e027dd8175e81a4a1c6d99248 100644 (file)
@@ -65,12 +65,11 @@ void color_free(color_rgb *c)
 
 void reduce_depth(pixel32 *data, XImage *im)
 {
-    /* since pixel32 is the largest possible pixel size, we can share the
-       array*/
     int r, g, b;
     int x,y;
-    pixel16 *p16 = (pixel16*) data;
-    unsigned char *p8 = (unsigned char *)data;
+    pixel32 *p32 = (pixel32 *) im->data;
+    pixel16 *p16 = (pixel16 *) im->data;
+    unsigned char *p8 = (unsigned char *)im->data;
     switch (im->bits_per_pixel) {
     case 32:
         if ((render_red_offset != default_red_shift) ||
@@ -81,12 +80,14 @@ void reduce_depth(pixel32 *data, XImage *im)
                     r = (data[x] >> default_red_shift) & 0xFF;
                     g = (data[x] >> default_green_shift) & 0xFF;
                     b = (data[x] >> default_blue_shift) & 0xFF;
-                    data[x] = (r << render_red_offset) + (g << render_green_offset) +
-                        (b << render_blue_offset);
+                    p32[x] = (r << render_red_offset)
+                           + (g << render_green_offset)
+                           + (b << render_blue_offset);
                 }
                 data += im->width;
+                p32 += im->width;
             } 
-        }
+        } else im->data = data;
         break;
     case 16:
         for (y = 0; y < im->height; y++) {
index be2b83100a4aa4ebbc2672049516629c8800d360..42fdebe8787866e2f5a4d092a2eb4ba14ae12c55 100644 (file)
@@ -377,17 +377,23 @@ void appearance_free(Appearance *a)
 
 void pixel32_to_pixmap(pixel32 *in, Pixmap out, int x, int y, int w, int h)
 {
+    unsigned char *scratch;
     XImage *im = NULL;
     im = XCreateImage(ob_display, render_visual, render_depth,
                       ZPixmap, 0, NULL, w, h, 32, 0);
     g_assert(im != NULL);
     im->byte_order = endian;
-    im->data = (char *)in;
-    reduce_depth((pixel32*)im->data, im);
+/* this malloc is a complete waste of time on normal 32bpp
+   as reduce_depth just sets im->data = data and returns
+*/
+    scratch = malloc(im->width * im->height * sizeof(pixel32));
+    im->data = scratch;
+    reduce_depth(in, im);
     XPutImage(ob_display, out, DefaultGC(ob_display, ob_screen),
               im, 0, 0, x, y, w, h);
     im->data = NULL;
     XDestroyImage(im);
+    free(scratch);
 }
 
 void appearance_minsize(Appearance *l, Size *s)
This page took 0.025152 seconds and 4 git commands to generate.