- p = image_data_to_pixmap (st->dpy, st->window,
- bob_png, sizeof(bob_png),
- w, h, &mask);
- else /* load a bitmap file */
- p = file_to_pixmap (st->dpy, st->window, bitmap_name,
- &st->width, &st->height, 0);
-
- if (!p) return 0;
- return reformat_pixmap (st, p, mask, w, h);
+ image = image_data_to_ximage (st->dpy, st->visual,
+ bob_png, sizeof(bob_png));
+ else
+ image = file_to_ximage (st->dpy, st->visual, bitmap_name);
+
+ if (! image) return 0;
+
+ while (image->width < st->width / 10 &&
+ image->height < st->height / 10)
+ {
+ image = double_ximage (st->dpy, st->visual, image);
+ blur++;
+ }
+
+ result = (unsigned char *) malloc (image->width * image->height);
+ o = result;
+ for (y = 0; y < image->height; y++)
+ for (x = 0; x < image->width; x++)
+ {
+ unsigned long agbr = XGetPixel (image, x, image->height - y - 1);
+ unsigned long a = (agbr >> 24) & 0xFF;
+ unsigned long gray = (a == 0
+ ? 0xFF
+ : ((((agbr >> 16) & 0xFF) +
+ ((agbr >> 8) & 0xFF) +
+ ((agbr >> 0) & 0xFF))
+ / 3));
+ if (gray < 96) gray /= 2; /* a little more contrast */
+ *o++ = 255 - gray;
+ }
+
+ /* If we enlarged the image, file off the sharp edges. */
+ if (blur > 0)
+ result = gaussian_blur (result, image->width, image->height, blur * 1.7);
+
+ st->theimx = image->width;
+ st->theimy = image->height;
+ XDestroyImage (image);
+ return result;