- XImage *ximage;
- unsigned char *result, *o;
- char *bits = (char *) malloc (sizeof(bob_bits));
- int x, y;
- int scale = ((width > bob_width * 11) ? 2 : 1);
-
- memcpy (bits, bob_bits, sizeof(bob_bits));
- ximage = XCreateImage (display, visual, 1, XYBitmap, 0, bits,
- bob_width, bob_height, 8, 0);
- ximage->byte_order = LSBFirst;
- ximage->bitmap_bit_order = LSBFirst;
- *w = ximage->width * scale;
- *h = ximage->height * scale;
- o = result = (unsigned char *) malloc ((*w * scale) * (*h * scale));
- for (y = 0; y < *h; y++)
- for (x = 0; x < *w; x++)
- *o++ = (XGetPixel(ximage, x/scale, y/scale) ? 255 : 0);
-
- return result;
- }
- else /* load a bitmap file */
- {
- Pixmap pixmap =
- xpm_file_to_pixmap (display, window, bitmap_name, &width, &height, 0);
- XImage *image;
- int x, y;
- unsigned char *result, *o;
-
- image = XGetImage (display, pixmap, 0, 0, width, height, ~0L, ZPixmap);
- XFreePixmap(display, pixmap);
-
- result = (unsigned char *) malloc (width * height);
- o = result;
- for (y = 0; y < height; y++)
- for (x = 0; x < width; x++)
- {
- int rgba = XGetPixel (image, x, y);
- /* This is *so* not handling all the cases... */
- int gray = (image->depth > 16
- ? ((((rgba >> 24) & 0xFF) +
- ((rgba >> 16) & 0xFF) +
- ((rgba >> 8) & 0xFF) +
- ((rgba ) & 0xFF)) >> 2)
- : ((((rgba >> 12) & 0x0F) +
- ((rgba >> 8) & 0x0F) +
- ((rgba >> 4) & 0x0F) +
- ((rgba ) & 0x0F)) >> 1));
- *o++ = 255 - gray;
- }
-
- XFree (image->data);
- image->data = 0;
- XDestroyImage (image);
-
- *w = width;
- *h = height;
- return result;