641
633
else /* load a bitmap file */
644
XpmInfo xpm_info = { 0, };
645
XpmImage xpm_image = { 0, };
647
int result = XpmReadFileToXpmImage (bitmap_name, &xpm_image, &xpm_info);
648
if (result == XpmSuccess)
651
unsigned char *result, *o;
652
unsigned char *grays;
653
XWindowAttributes xgwa;
655
*w = xpm_image.width;
656
*h = xpm_image.height;
657
result = (unsigned char *) malloc ((*w) * (*h));
660
fprintf(stderr, "%s: out of memory loading %s\n",
661
progname, bitmap_name);
665
XGetWindowAttributes (display, window, &xgwa);
667
grays = (unsigned char *) calloc (xpm_image.ncolors+1, 1);
668
for (x = 0; x < xpm_image.ncolors; x++)
671
XpmColor *xpmc = &xpm_image.colorTable[x];
673
if (xpmc->g_color && *xpmc->g_color)
674
cstring = xpmc->g_color;
675
else if (xpmc->g4_color && *xpmc->g4_color)
676
cstring = xpmc->g4_color;
677
else if (xpmc->c_color && *xpmc->c_color)
678
cstring = xpmc->c_color;
680
cstring = xpmc->m_color;
682
memset (&xc, 0, sizeof(xc));
685
!XParseColor (display, xgwa.colormap, cstring, &xc))
688
grays[x] = (int) (((xc.red * 0.299) +
695
for (y = 0; y < *h; y++)
696
for (x = 0; x < *w; x++)
698
int color = xpm_image.data[(y * (*w)) + x];
699
if (color < 0 || color > xpm_image.ncolors) abort();
704
else /* failed to read XPM -- fall through and try XBM */
705
#endif /* HAVE_XPM */
709
int width, height, xh, yh;
711
unsigned char *result, *o;
713
XmuLocateBitmapFile (DefaultScreenOfDisplay (display),
714
bitmap_name, 0, 0, &width, &height, &xh, &yh);
717
fprintf(stderr, "%s: unable to load bitmap file %s\n",
718
progname, bitmap_name);
721
ximage = XGetImage (display, bitmap, 0, 0, width, height,
723
XFreePixmap (display, bitmap);
725
if (ximage->depth != 1) abort();
729
result = (unsigned char *) malloc ((*w) * (*h));
732
fprintf(stderr, "%s: out of memory loading %s\n",
733
progname, bitmap_name);
738
for (y = 0; y < *h; y++)
739
for (x = 0; x < *w; x++)
740
*o++ = (XGetPixel(ximage, x, y) ? 255 : 0);
746
"%s: your vendor doesn't ship the standard Xmu library.\n",
748
fprintf (stderr, "\tWe can't load XBM files without it.\n");
636
xpm_file_to_pixmap (display, window, bitmap_name, &width, &height, 0);
639
unsigned char *result, *o;
641
Bool cmap_p = has_writable_cells (screen, visual);
646
for (i = 0; i < countof (colors); i++)
648
XQueryColors (display, colormap, colors, countof (colors));
651
image = XGetImage (display, pixmap, 0, 0, width, height, ~0L, ZPixmap);
652
XFreePixmap(display, pixmap);
654
result = (unsigned char *) malloc (width * height);
656
for (y = 0; y < height; y++)
657
for (x = 0; x < width; x++)
659
int rgba = XGetPixel (image, x, y);
662
gray = ((200 - ((((colors[rgba].red >> 8) & 0xFF) +
663
((colors[rgba].green >> 8) & 0xFF) +
664
((colors[rgba].blue >> 8) & 0xFF))
668
/* This is *so* not handling all the cases... */
669
gray = (image->depth > 16
670
? ((((rgba >> 24) & 0xFF) +
671
((rgba >> 16) & 0xFF) +
672
((rgba >> 8) & 0xFF) +
673
((rgba ) & 0xFF)) >> 2)
674
: ((((rgba >> 12) & 0x0F) +
675
((rgba >> 8) & 0x0F) +
676
((rgba >> 4) & 0x0F) +
677
((rgba ) & 0x0F)) >> 1));
684
XDestroyImage (image);
783
720
XrmOptionDescRec options [] = {
721
{ "-foreground",".foreground", XrmoptionSepArg, 0 },
722
{ "-fg", ".foreground", XrmoptionSepArg, 0 },
784
723
{ "-delay", ".delay", XrmoptionSepArg, 0 },
785
724
{ "-bitmap", ".bitmap", XrmoptionSepArg, 0 },
786
725
{ "-baseline", ".bitmapBaseline", XrmoptionSepArg, 0 },