]> git.draconx.ca Git - rrace.git/blobdiff - src/ewmhicon.c
Separate EWMH colour conversion from icon generation.
[rrace.git] / src / ewmhicon.c
index 7e69ec883f5c36317c900abff0a947e03b149d8c..8b731a35d52dece292079b576d5d9f7758c689ee 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdint.h>
 
 #if !X_DISPLAY_MISSING
 #  include <X11/Intrinsic.h>
 
 enum { ICON_16x16, ICON_24x24, ICON_32x32, ICON_48x48, ICON_MAX };
 
-static unsigned long scale16to8(unsigned x)
+static unsigned long scale16to8(uint_least32_t x)
 {
-       return x*0xfful / 0xffff;
+       return x*0xff / 0xffff;
 }
 
 static unsigned long wm_pixel(const XColor *c)
 {
-       return 0xff000000
-            | scale16to8(c->red) << 16
-            | scale16to8(c->green) << 8
-            | scale16to8(c->blue);
+       uint_least32_t t = -1;
+
+       t = (t << 8) + scale16to8(c->red);
+       t = (t << 8) + scale16to8(c->green);
+       t = (t << 8) + scale16to8(c->blue);
+
+       return t & 0xffffffff;
+}
+
+void ewmh_icon_prepare_cmap(XColor *map, unsigned n)
+{
+       unsigned i;
+
+       for (i = 0; i < n; i++) {
+               map[i].pixel = wm_pixel(&map[i]);
+       }
 }
 
 static void do_remap(void *icon, unsigned area, const XColor *map)
@@ -53,7 +66,7 @@ static void do_remap(void *icon, unsigned area, const XColor *map)
 
        area--;
        for (i = 0; i <= area; i++) {
-               argb[area-i] = wm_pixel(map + index[area-i]);
+               argb[area-i] = (map + index[area-i])->pixel;
        }
 }