http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.14.tar.gz
[xscreensaver] / hacks / glx / grab-ximage.c
index d1e920794a0acdbdfeeee93153378274fadbdaf4..99e92317487e25373e5a456a86d94eb356e74a89 100644 (file)
@@ -85,13 +85,22 @@ spread_bits (unsigned char value, unsigned char width)
 }
 
 
+static Bool
+bigendian (void)
+{
+  union { int i; char c[sizeof(int)]; } u;
+  u.i = 1;
+  return !u.c[0];
+}
+
+
 /* Returns an XImage structure containing an image of the desktop.
    (As a side-effect, that image *may* be painted onto the given Window.)
    This XImage will be 32 bits per pixel, 8 each per R, G, and B, with the
    extra byte set to 0xFF.
  */
 XImage *
-screen_to_ximage (Screen *screen, Window window)
+screen_to_ximage (Screen *screen, Window window, char **filename_return)
 {
   Display *dpy = DisplayOfScreen (screen);
   Pixmap pixmap = 0;
@@ -104,7 +113,7 @@ screen_to_ximage (Screen *screen, Window window)
   win_height = xgwa.height;
 
   pixmap = XCreatePixmap(dpy, window, xgwa.width, xgwa.height, xgwa.depth);
-  load_random_image (screen, window, pixmap);
+  load_random_image (screen, window, pixmap, filename_return);
 
   /* GL texture sizes must be powers of two. */
   tex_width  = to_pow2(win_width);
@@ -146,10 +155,10 @@ screen_to_ximage (Screen *screen, Window window)
      */
     {
       int x, y;
-      int crpos, cgpos, cbpos, capos;  /* bitfield positions */
-      int srpos, sgpos, sbpos;
-      int srmsk, sgmsk, sbmsk;
-      int srsiz, sgsiz, sbsiz;
+      unsigned int crpos=0, cgpos=0, cbpos=0, capos=0; /* bitfield positions */
+      unsigned int srpos=0, sgpos=0, sbpos=0;
+      unsigned int srmsk=0, sgmsk=0, sbmsk=0;
+      unsigned int srsiz=0, sgsiz=0, sbsiz=0;
       int i;
 
       unsigned char spread_map[3][256];
@@ -171,7 +180,10 @@ screen_to_ximage (Screen *screen, Window window)
          we need to pack things in "RGBA" order on the client machine,
          regardless of its endianness.
        */
-      crpos =  0, cgpos =  8, cbpos = 16, capos = 24;
+      if (bigendian())
+        crpos = 24, cgpos = 16, cbpos =  8, capos =  0;
+      else
+        crpos =  0, cgpos =  8, cbpos = 16, capos = 24;
 
       if (colors == 0)  /* truecolor */
         {