X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fxpm-ximage.c;h=640ebf75d841575487d576d1568528054e0004e6;hb=d6b0217f2417bd19187f0ebc389d6c5c2233b11c;hp=cf600bc7312ed9b618d8f079c01eaef761dba26d;hpb=4ade52359b6eba3621566dac79793a33aa4c915f;p=xscreensaver diff --git a/hacks/glx/xpm-ximage.c b/hacks/glx/xpm-ximage.c index cf600bc7..640ebf75 100644 --- a/hacks/glx/xpm-ximage.c +++ b/hacks/glx/xpm-ximage.c @@ -1,5 +1,5 @@ /* xpm-ximage.c --- converts XPM data to an XImage for use with OpenGL. - * xscreensaver, Copyright (c) 1998-2013 Jamie Zawinski + * xscreensaver, Copyright (c) 1998-2016 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -19,7 +19,7 @@ #include #include -#ifdef HAVE_COCOA +#ifdef HAVE_JWXYZ # include "jwxyz.h" #else # include @@ -27,6 +27,10 @@ #include "xpm-ximage.h" +#ifdef HAVE_COCOA +# include "grabscreen.h" /* for osx_load_image_file() */ +#endif + extern char *progname; @@ -78,7 +82,9 @@ xpm_to_ximage_1 (Display *dpy, Visual *visual, Colormap cmap, if (!initted) { #ifdef HAVE_GTK2 +#if !GLIB_CHECK_VERSION(2, 36 ,0) g_type_init (); +#endif #endif gdk_pixbuf_xlib_init (dpy, DefaultScreen (dpy)); xlib_rgb_init (dpy, DefaultScreenOfDisplay (dpy)); @@ -334,7 +340,8 @@ xpm_to_ximage_1 (Display *dpy, Visual *visual, Colormap cmap, /* Given a bitmask, returns the position and width of the field. */ static void -decode_mask (unsigned int mask, unsigned int *pos_ret, unsigned int *size_ret) +decode_mask (unsigned long mask, unsigned long *pos_ret, + unsigned long *size_ret) { int i; for (i = 0; i < 32; i++) @@ -358,7 +365,7 @@ xpm_to_ximage_1 (Display *dpy, Visual *visual, Colormap cmap, const char *filename, char **xpm_data) { int iw, ih, w8, x, y; - XImage *ximage; + XImage *ximage = 0; char *data; unsigned char *mask = 0; int depth = 32; @@ -368,22 +375,62 @@ xpm_to_ximage_1 (Display *dpy, Visual *visual, Colormap cmap, int npixels = 0; int bpl; - unsigned int rpos=0, gpos=0, bpos=0, apos=0; - unsigned int rmsk=0, gmsk=0, bmsk=0, amsk=0; - unsigned int rsiz=0, gsiz=0, bsiz=0, asiz=0; + unsigned long rpos=0, gpos=0, bpos=0, apos=0; + unsigned long rmsk=0, gmsk=0, bmsk=0, amsk=0; + unsigned long rsiz=0, gsiz=0, bsiz=0, asiz=0; + +# ifdef HAVE_COCOA + if (filename) { + XRectangle geom; + Screen *screen = DefaultScreenOfDisplay (dpy); + Window window = RootWindowOfScreen (screen); + XWindowAttributes xgwa; + XGetWindowAttributes (dpy, window, &xgwa); + Pixmap pixmap = + XCreatePixmap (dpy, window, xgwa.width, xgwa.height, xgwa.depth); + + if (osx_load_image_file (screen, window, pixmap, filename, &geom)) { + ximage = XGetImage (dpy, pixmap, geom.x, geom.y, geom.width, geom.height, + ~0L, ZPixmap); + + /* Have to convert BGRA to ARGB */ + if (ximage) { + int x, y; + for (y = 0; y < ximage->height; y++) + for (x = 0; x < ximage->width; x++) { + unsigned long p = XGetPixel (ximage, x, y); + unsigned long b = (p >> 24) & 0xFF; + unsigned long g = (p >> 16) & 0xFF; + unsigned long r = (p >> 8) & 0xFF; + unsigned long a = (p >> 0) & 0xFF; + p = (a << 24) | (r << 16) | (g << 8) | (b << 0); + XPutPixel (ximage, x, y, p); + } + } + + } + + XFreePixmap (dpy, pixmap); + + if (! ximage) + fprintf (stderr, "%s: %s failed\n", progname, filename); + return ximage; + } +# endif /* HAVE_COCOA */ if (filename) { fprintf(stderr, - "%s: no files: not compiled with XPM or Pixbuf support.\n", - progname); - exit (1); + "%s: can't load %s: not compiled with XPM or Pixbuf support.\n", + progname, filename); + return 0; } if (! xpm_data) abort(); ximage = minixpm_to_ximage (dpy, visual, cmap, depth, background_color, (const char * const *) xpm_data, &iw, &ih, &pixels, &npixels, &mask); + if (!ximage) abort(); if (pixels) free (pixels); bpl = ximage->bytes_per_line; @@ -414,7 +461,7 @@ xpm_to_ximage_1 (Display *dpy, Visual *visual, Colormap cmap, for (x = 0; x < ximage->width; x++) { - unsigned long pixel = iline[x]; + unsigned int pixel = iline[x]; unsigned char r = (pixel & rmsk) >> rpos; unsigned char g = (pixel & gmsk) >> gpos; unsigned char b = (pixel & bmsk) >> bpos;