X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fxflame.c;h=b492561a7e55afb7d0c1404c657ec92394cf4016;hb=96a411663168b0ba5432b407a83be55f3df0c802;hp=2e569e07cb959ea3be9ae81dca8dbcd3271d45c7;hpb=0316d74da7982288abddd34e7a62698eb7f79965;p=xscreensaver diff --git a/hacks/xflame.c b/hacks/xflame.c old mode 100644 new mode 100755 index 2e569e07..b492561a --- a/hacks/xflame.c +++ b/hacks/xflame.c @@ -1,4 +1,4 @@ -/* xflame, Copyright (c) 1996-1999 Carsten Haitzler +/* xflame, Copyright (c) 1996-2002 Carsten Haitzler * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -40,6 +40,7 @@ - General cleanup and portability tweaks. * 4-Oct-99, jwz: added support for packed-24bpp (versus 32bpp.) + * 16-Jan-2002, jwz: added gdk_pixbuf support. */ @@ -48,28 +49,17 @@ #include "screenhack.h" +#include "xpm-pixmap.h" #include #include +#undef countof +#define countof(x) (sizeof((x))/sizeof((*x))) + #ifdef HAVE_XSHM_EXTENSION # include "xshm.h" #endif /* HAVE_XSHM_EXTENSION */ -#ifdef HAVE_XPM -# include -# ifndef PIXEL_ALREADY_TYPEDEFED -# define PIXEL_ALREADY_TYPEDEFED /* Sigh, Xmu/Drawing.h needs this... */ -# endif -#endif - -#ifdef HAVE_XMU -# ifndef VMS -# include -# else /* VMS */ -# include -# endif /* VMS */ -#endif /* HAVE_XMU */ - #include "images/bob.xbm" #define MAX_VAL 255 @@ -81,6 +71,7 @@ static int width; static int height; static Colormap colormap; static Visual *visual; +static Screen *screen; static Bool shared; static Bool bloom; static XImage *xim; @@ -117,6 +108,7 @@ GetXInfo(Display *disp, Window win) colormap = xwa.colormap; depth = xwa.depth; visual = xwa.visual; + screen = xwa.screen; width = xwa.width; height = xwa.height; @@ -533,6 +525,13 @@ FlameAdvance(void) if (used) newtop = y - 1; } + + /* clean up the right gutter */ + { + int v1 = (int)*ptr1; + v1 = (v1 * residual) >> 8; + *ptr1 = (unsigned char)v1; + } } top = newtop - 1; @@ -633,115 +632,60 @@ loadBitmap(int *w, int *h) } else /* load a bitmap file */ { -#ifdef HAVE_XPM - XpmInfo xpm_info = { 0, }; - XpmImage xpm_image = { 0, }; + Pixmap pixmap = + xpm_file_to_pixmap (display, window, bitmap_name, &width, &height, 0); + XImage *image; + int x, y; + unsigned char *result, *o; + XColor colors[256]; + Bool cmap_p = has_writable_cells (screen, visual); - int result = XpmReadFileToXpmImage (bitmap_name, &xpm_image, &xpm_info); - if (result == XpmSuccess) + if (cmap_p) { - int x, y; - unsigned char *result, *o; - unsigned char *grays; - XWindowAttributes xgwa; - - *w = xpm_image.width; - *h = xpm_image.height; - result = (unsigned char *) malloc ((*w) * (*h)); - if (!result) - { - fprintf(stderr, "%s: out of memory loading %s\n", - progname, bitmap_name); - exit (1); - } - - XGetWindowAttributes (display, window, &xgwa); - - grays = (unsigned char *) calloc (xpm_image.ncolors+1, 1); - for (x = 0; x < xpm_image.ncolors; x++) - { - XColor xc; - XpmColor *xpmc = &xpm_image.colorTable[x]; - char *cstring = 0; - if (xpmc->g_color && *xpmc->g_color) - cstring = xpmc->g_color; - else if (xpmc->g4_color && *xpmc->g4_color) - cstring = xpmc->g4_color; - else if (xpmc->c_color && *xpmc->c_color) - cstring = xpmc->c_color; - else - cstring = xpmc->m_color; - - memset (&xc, 0, sizeof(xc)); - if (!cstring || - !*cstring || - !XParseColor (display, xgwa.colormap, cstring, &xc)) - grays[x] = 0; - else - grays[x] = (int) (((xc.red * 0.299) + - (xc.green * 0.587) + - (xc.blue * 0.114)) - / 255); - } - - o = result; - for (y = 0; y < *h; y++) - for (x = 0; x < *w; x++) - { - int color = xpm_image.data[(y * (*w)) + x]; - if (color < 0 || color > xpm_image.ncolors) abort(); - *o++ = grays[color]; - } - return result; + int i; + for (i = 0; i < countof (colors); i++) + colors[i].pixel = i; + XQueryColors (display, colormap, colors, countof (colors)); } - else /* failed to read XPM -- fall through and try XBM */ -#endif /* HAVE_XPM */ - { -#ifdef HAVE_XMU - XImage *ximage = 0; - int width, height, xh, yh; - int x, y; - unsigned char *result, *o; - Pixmap bitmap = - XmuLocateBitmapFile (DefaultScreenOfDisplay (display), - bitmap_name, 0, 0, &width, &height, &xh, &yh); - if (!bitmap) - { - fprintf(stderr, "%s: unable to load bitmap file %s\n", - progname, bitmap_name); - exit (1); - } - ximage = XGetImage (display, bitmap, 0, 0, width, height, - 1L, XYPixmap); - XFreePixmap (display, bitmap); - if (ximage->depth != 1) abort(); - - *w = ximage->width; - *h = ximage->height; - result = (unsigned char *) malloc ((*w) * (*h)); - if (!result) - { - fprintf(stderr, "%s: out of memory loading %s\n", - progname, bitmap_name); - exit (1); - } - - o = result; - for (y = 0; y < *h; y++) - for (x = 0; x < *w; x++) - *o++ = (XGetPixel(ximage, x, y) ? 255 : 0); - - return result; - -#else /* !XMU */ - fprintf (stderr, - "%s: your vendor doesn't ship the standard Xmu library.\n", - progname); - fprintf (stderr, "\tWe can't load XBM files without it.\n"); - exit (1); -#endif /* !XMU */ - } + 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); + int gray; + if (cmap_p) + gray = ((200 - ((((colors[rgba].red >> 8) & 0xFF) + + ((colors[rgba].green >> 8) & 0xFF) + + ((colors[rgba].blue >> 8) & 0xFF)) + >> 1)) + & 0xFF); + else + /* This is *so* not handling all the cases... */ + 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; } *w = 0; @@ -774,6 +718,8 @@ char *defaults [] = { }; XrmOptionDescRec options [] = { + { "-foreground",".foreground", XrmoptionSepArg, 0 }, + { "-fg", ".foreground", XrmoptionSepArg, 0 }, { "-delay", ".delay", XrmoptionSepArg, 0 }, { "-bitmap", ".bitmap", XrmoptionSepArg, 0 }, { "-baseline", ".bitmapBaseline", XrmoptionSepArg, 0 },