dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] pnetlib/Xsharp XsharpSupport.c,1.18,1.19


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] pnetlib/Xsharp XsharpSupport.c,1.18,1.19
Date: Tue, 25 Nov 2003 06:40:35 +0000

Update of /cvsroot/dotgnu-pnet/pnetlib/Xsharp
In directory subversions:/tmp/cvs-serv10109/Xsharp

Modified Files:
        XsharpSupport.c 
Log Message:


Optimize for 16bpp-LSBFirst and 24bpp-MSBFirst screens in
the XImage conversion code.


Index: XsharpSupport.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/Xsharp/XsharpSupport.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** XsharpSupport.c     31 Oct 2003 06:44:35 -0000      1.18
--- XsharpSupport.c     25 Nov 2003 06:40:33 -0000      1.19
***************
*** 718,721 ****
--- 718,775 ----
  
  /*
+  * Write RGB data directly to an XImage, and perform a RGB-BGR byteswap.
+  */
+ static void Write_DirectSwap(Display *dpy, Colormap colormap, XImage *image,
+                                                    int line, unsigned long 
*input, int num)
+ {
+       int column;
+       if(sizeof(unsigned int) == 4)
+       {
+               unsigned int *output = (unsigned int *)
+                       (image->data + line * image->bytes_per_line);
+               for(column = 0; column < num; ++column)
+               {
+                       unsigned int value = (unsigned int)(*input++);
+                       value = ((value & 0x00FF0000) >> 16) |
+                                        (value & 0x0000FF00) |
+                                       ((value & 0x000000FF) << 16);
+                       *output++ = value;
+               }
+       }
+       else
+       {
+               unsigned long *output = (unsigned long *)
+                       (image->data + line * image->bytes_per_line);
+               for(column = 0; column < num; ++column)
+               {
+                       unsigned int value = (unsigned int)(*input++);
+                       value = ((value & 0x00FF0000) >> 16) |
+                                        (value & 0x0000FF00) |
+                                       ((value & 0x000000FF) << 16);
+                       *output++ = (unsigned long)value;
+               }
+       }
+ }
+ 
+ /*
+  * Write RGB data to a 16 bits per pixel XImage structure.
+  */
+ static void Write_16bpp(Display *dpy, Colormap colormap, XImage *image,
+                                           int line, unsigned long *input, int 
num)
+ {
+       int column;
+       unsigned short *output = (unsigned short *)
+               (image->data + line * image->bytes_per_line);
+       for(column = 0; column < num; ++column)
+       {
+               unsigned int value = (unsigned int)(*input++);
+               value = ((value & 0x00F80000) >> 8) |
+                               ((value & 0x0000FC00) >> 5) |
+                               ((value & 0x000000F8) >> 3);
+               *output++ = (unsigned short)value;
+       }
+ }
+ 
+ /*
   * Default writing routine, doing per-pixel color allocations.
   */
***************
*** 747,756 ****
  static WriteFunc GetWriteFunc(XImage *image)
  {
        if(image->depth == 24 && image->red_mask == 0x00FF0000 &&
           image->green_mask == 0x0000FF00 && image->blue_mask == 0x000000FF &&
           image->byte_order == LSBFirst && image->bitmap_bit_order == LSBFirst)
        {
!               return Write_Direct;
        }
        return Write_Default;
  }
--- 801,852 ----
  static WriteFunc GetWriteFunc(XImage *image)
  {
+       /* Determine if the client machine is little-endian or big-endian */
+       union
+       {
+               short volatile value;
+               unsigned char volatile buf[2];
+       } un;
+       int littleEndian;
+       un.value = 0x0102;
+       littleEndian = (un.buf[0] == 0x02);
+ 
+       /* Check for well-known special cases */
        if(image->depth == 24 && image->red_mask == 0x00FF0000 &&
           image->green_mask == 0x0000FF00 && image->blue_mask == 0x000000FF &&
           image->byte_order == LSBFirst && image->bitmap_bit_order == LSBFirst)
        {
!               if(littleEndian)
!               {
!                       return Write_Direct;
!               }
!               else
!               {
!                       return Write_DirectSwap;
!               }
        }
+       if(image->depth == 24 && image->red_mask == 0x00FF0000 &&
+          image->green_mask == 0x0000FF00 && image->blue_mask == 0x000000FF &&
+          image->byte_order == MSBFirst && image->bitmap_bit_order == MSBFirst)
+       {
+               if(littleEndian)
+               {
+                       return Write_DirectSwap;
+               }
+               else
+               {
+                       return Write_Direct;
+               }
+       }
+       if(image->depth == 16 && image->red_mask == 0x0000F800 &&
+          image->green_mask == 0x000007E0 && image->blue_mask == 0x0000001F &&
+          image->byte_order == LSBFirst && image->bitmap_bit_order == LSBFirst)
+       {
+               if(littleEndian)
+               {
+                       return Write_16bpp;
+               }
+       }
+ 
+       /* Fall back to the generic writer, using XPutPixel */
        return Write_Default;
  }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]