changeset 23453:3e18bed9618a

Make gmplayer show right colors if X server does not use native byteorder.
author reimar
date Tue, 05 Jun 2007 11:37:16 +0000
parents 3e676c9e1e35
children 2d5b7c795a60
files gui/wm/ws.c
diffstat 1 files changed, 30 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/gui/wm/ws.c	Tue Jun 05 11:13:32 2007 +0000
+++ b/gui/wm/ws.c	Tue Jun 05 11:37:16 2007 +0000
@@ -30,6 +30,7 @@
 #include "../mp_msg.h"
 #include "../help_mp.h"
 #include "../mplayer.h"
+#include "../mpbswap.h"
 
 #include <X11/extensions/XShm.h>
 #ifdef HAVE_XSHAPE
@@ -84,6 +85,7 @@
 int                  wsGreenMask = 0;
 int                  wsBlueMask = 0;
 int                  wsOutMask = 0;
+int                  wsNonNativeOrder = 0;
 
 int                  wsTrue    = True;
 
@@ -845,7 +847,29 @@
 //    Put 'Image' to window.
 // ----------------------------------------------------------------------------------------------
 void wsConvert( wsTWindow * win,unsigned char * Image,unsigned int Size )
-{ if ( wsConvFunc ) wsConvFunc( Image,win->ImageData,win->xImage->width * win->xImage->height * 4 ); }
+{
+  int i;
+  if ( wsConvFunc )
+    wsConvFunc( Image,win->ImageData,win->xImage->width * win->xImage->height * 4 );
+  if (!wsNonNativeOrder) return;
+  switch (win->xImage->bits_per_pixel) {
+    case 32:
+    {
+      uint32_t *d = win->ImageData;
+      for (i = 0; i < win->xImage->width * win->xImage->height; i++)
+        d[i] = bswap_32(d[i]);
+      break;
+    }
+    case 16:
+    case 15:
+    {
+      uint16_t *d = win->ImageData;
+      for (i = 0; i < win->xImage->width * win->xImage->height; i++)
+        d[i] = bswap_16(d[i]);
+      break;
+    }
+  }
+}
 
 void wsPutImage( wsTWindow * win )
 {
@@ -1048,6 +1072,11 @@
    wsRedMask=mXImage->red_mask;
    wsGreenMask=mXImage->green_mask;
    wsBlueMask=mXImage->blue_mask;
+#ifdef WORDS_BIGENDIAN
+   wsNonNativeOrder = mXImage->byte_order == LSBFirst;
+#else
+   wsNonNativeOrder = mXImage->byte_order == MSBFirst;
+#endif
    XDestroyImage( mXImage );
   }
  else