+
+void RrIncreaseDepth(const RrInstance *inst, RrPixel32 *data, XImage *im)
+{
+ int r, g, b;
+ int x,y;
+ RrPixel32 *p32 = (RrPixel32 *) im->data;
+ RrPixel16 *p16 = (RrPixel16 *) im->data;
+ unsigned char *p8 = (unsigned char *)im->data;
+
+ if (im->byte_order != LSBFirst)
+ swap_byte_order(im);
+
+ switch (im->bits_per_pixel) {
+ case 32:
+ for (y = 0; y < im->height; y++) {
+ for (x = 0; x < im->width; x++) {
+ r = (p32[x] >> RrRedOffset(inst)) & 0xff;
+ g = (p32[x] >> RrGreenOffset(inst)) & 0xff;
+ b = (p32[x] >> RrBlueOffset(inst)) & 0xff;
+ data[x] = (r << RrDefaultRedOffset)
+ + (g << RrDefaultGreenOffset)
+ + (b << RrDefaultBlueOffset)
+ + (0xff << RrDefaultAlphaOffset);
+ }
+ data += im->width;
+ p32 += im->bytes_per_line/4;
+ }
+ break;
+ case 16:
+ for (y = 0; y < im->height; y++) {
+ for (x = 0; x < im->width; x++) {
+ r = (p16[x] & RrRedMask(inst)) >>
+ RrRedOffset(inst) <<
+ RrRedShift(inst);
+ g = (p16[x] & RrGreenMask(inst)) >>
+ RrGreenOffset(inst) <<
+ RrGreenShift(inst);
+ b = (p16[x] & RrBlueMask(inst)) >>
+ RrBlueOffset(inst) <<
+ RrBlueShift(inst);
+ data[x] = (r << RrDefaultRedOffset)
+ + (g << RrDefaultGreenOffset)
+ + (b << RrDefaultBlueOffset)
+ + (0xff << RrDefaultAlphaOffset);
+ }
+ data += im->width;
+ p16 += im->bytes_per_line/2;
+ }
+ break;
+ case 8:
+ g_warning("this image bit depth is currently unhandled");
+ break;
+ case 1:
+ for (y = 0; y < im->height; y++) {
+ for (x = 0; x < im->width; x++) {
+ if (!(((p8[x / 8]) >> (x % 8)) & 0x1))
+ data[x] = 0xff << RrDefaultAlphaOffset; /* black */
+ else
+ data[x] = 0xffffffff; /* white */
+ }
+ data += im->width;
+ p8 += im->bytes_per_line;
+ }
+ break;
+ default:
+ g_warning("this image bit depth is currently unhandled");
+ }
+}
+
+int RrColorRed(const RrColor *c)
+{
+ return c->r;
+}
+
+int RrColorGreen(const RrColor *c)
+{
+ return c->g;
+}
+
+int RrColorBlue(const RrColor *c)
+{
+ return c->b;
+}
+
+gulong RrColorPixel(const RrColor *c)
+{
+ return c->pixel;
+}
+
+GC RrColorGC(RrColor *c) /* XXX make this const RrColor* when the GCs are in
+ a cache.. if possible? */