More bitmap fixes.

diff --git a/graphics/x11drv/bitmap.c b/graphics/x11drv/bitmap.c
index 6c46061..8ea1f26 100644
--- a/graphics/x11drv/bitmap.c
+++ b/graphics/x11drv/bitmap.c
@@ -17,13 +17,6 @@
 #include "xmalloc.h"
 #include "x11drv.h"
 
-#ifdef PRELIMINARY_WING16_SUPPORT
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#endif
-
-
   /* GCs used for B&W and color bitmap operations */
 GC BITMAP_monoGC = 0, BITMAP_colorGC = 0;
 
@@ -186,11 +179,14 @@
       /* Check parameters */
     if (bmp->bitmap.bmPlanes != 1) return 0;
     if ((bmp->bitmap.bmBitsPixel != 1) && 
-       (bmp->bitmap.bmBitsPixel != screenDepth)) {
+	(bmp->bitmap.bmBitsPixel != screenDepth)) {
         GDI_HEAP_UNLOCK( hbitmap );
 	return FALSE;
     }
 
+    TRACE(x11drv, "(%08x) %dx%d %d bpp\n", hbitmap, bmp->bitmap.bmWidth,
+	  bmp->bitmap.bmHeight, bmp->bitmap.bmBitsPixel);
+
     pbitmap = X11DRV_AllocBitmap( bmp );
     if(!pbitmap) return FALSE;
 
@@ -243,7 +239,9 @@
     LPBYTE tbuf;
     int	h, w, pad;
 
-    pad = BITMAP_GetBitsPadding(bmp->bitmap.bmWidth, bmp->bitmap.bmBitsPixel);
+    TRACE(x11drv, "(bmp=%p, buffer=%p, count=%lx)\n", bmp, buffer, count);
+
+    pad = BITMAP_GetPadding(bmp->bitmap.bmWidth, bmp->bitmap.bmBitsPixel);
 
     if (pad == -1)
         return 0;
@@ -364,30 +362,25 @@
     struct XPutImage_descr descr;
     LONG height;
     XImage *image;
-    LPBYTE sbuf, tmpbuffer;
-    int	w, h, pad, widthbytes;
+    LPBYTE sbuf;
+    int	w, h, pad;
 
     TRACE(x11drv, "(bmp=%p, bits=%p, count=%lx)\n", bmp, bits, count);
     
-    pad = BITMAP_GetBitsPadding(bmp->bitmap.bmWidth, bmp->bitmap.bmBitsPixel);
+    pad = BITMAP_GetPadding(bmp->bitmap.bmWidth, bmp->bitmap.bmBitsPixel);
 
     if (pad == -1) 
         return 0;
 	
     sbuf = (LPBYTE)bits;
 
-    widthbytes	= (((bmp->bitmap.bmWidth * bmp->bitmap.bmBitsPixel) + 31) /
-		   32) * 4;
-    height      = count / bmp->bitmap.bmWidthBytes;
-    tmpbuffer	= (LPBYTE)xmalloc(widthbytes*height);
-
-    TRACE(x11drv, "h=%ld, w=%d, wb=%d\n", height, bmp->bitmap.bmWidth, 
-	  widthbytes);
+    height = count / bmp->bitmap.bmWidthBytes;
 
     EnterCriticalSection( &X11DRV_CritSection );
     image = XCreateImage( display, DefaultVisualOfScreen(screen),
-                          bmp->bitmap.bmBitsPixel, ZPixmap, 0, tmpbuffer,
-                          bmp->bitmap.bmWidth,height,32,widthbytes );
+                          bmp->bitmap.bmBitsPixel, ZPixmap, 0, NULL,
+                          bmp->bitmap.bmWidth, height, 32, 0 );
+    image->data = (LPBYTE)xmalloc(image->bytes_per_line * height);
     
     /* copy 16 bit padded image buffer with real bitsperpixel to XImage */
     sbuf = (LPBYTE)bits;
@@ -466,8 +459,9 @@
     descr.image  = image;
     descr.width  = bmp->bitmap.bmWidth;
     descr.height = height;
+
     CALL_LARGE_STACK( XPutImage_wrapper, &descr );
-    XDestroyImage( image ); /* frees tmpbuffer too */
+    XDestroyImage( image ); /* frees image->data too */
     LeaveCriticalSection( &X11DRV_CritSection );
     
     return count;
@@ -505,28 +499,8 @@
 {
     X11DRV_PHYSBITMAP *pbitmap = bmp->DDBitmap->physBitmap;
 
-#ifdef PRELIMINARY_WING16_SUPPORT
-    if( bmp->bitmap.bmBits )
- 	TSXShmDetach( display, (XShmSegmentInfo*)bmp->bitmap.bmBits );
-#endif
-
     TSXFreePixmap( display, pbitmap->pixmap );
 
-
-#ifdef PRELIMINARY_WING16_SUPPORT
-    if( bmp->bitmap.bmBits )
-    {
-    __ShmBitmapCtl* p = (__ShmBitmapCtl*)bmp->bitmap.bmBits;
-      WORD          sel = HIWORD(p->bits);
-      unsigned long l, limit = GetSelectorLimit(sel);
-
-      for( l = 0; l < limit; l += 0x10000, sel += __AHINCR )
-	   FreeSelector(sel);
-      shmctl(p->si.shmid, IPC_RMID, NULL); 
-      shmdt(p->si.shmaddr);  /* already marked for destruction */
-    }
-#endif
-
     HeapFree( GetProcessHeap(), 0, bmp->DDBitmap->physBitmap );
     HeapFree( GetProcessHeap(), 0, bmp->DDBitmap );
     bmp->DDBitmap = NULL;
diff --git a/include/bitmap.h b/include/bitmap.h
index aa07e66..64765ef 100644
--- a/include/bitmap.h
+++ b/include/bitmap.h
@@ -53,16 +53,12 @@
 
 } BITMAPOBJ;
 
-#define BITMAP_WIDTH_BYTES(width,bpp) \
-    (((bpp) == 24) ? (width) * 4 : ( ((bpp) == 15) ? (width) * 2 : \
-				    ((width) * (bpp) + 15) / 16 * 2 ))
-
   /* objects/bitmap.c */
 extern INT16   BITMAP_GetObject16( BITMAPOBJ * bmp, INT16 count, LPVOID buffer );
 extern INT32   BITMAP_GetObject32( BITMAPOBJ * bmp, INT32 count, LPVOID buffer );
 extern BOOL32  BITMAP_DeleteObject( HBITMAP16 hbitmap, BITMAPOBJ * bitmap );
-extern INT32   BITMAP_GetBitsPadding( int width, int depth );
-extern INT32   BITMAP_GetBitsWidth( int width, int depth );
+extern INT32   BITMAP_GetPadding( INT32 width, INT32 depth );
+extern INT32   BITMAP_GetWidthBytes( INT32 width, INT32 depth );
 extern HBITMAP32 BITMAP_LoadBitmap32W(HINSTANCE32 instance,LPCWSTR name,
   UINT32 loadflags);
 extern HBITMAP32 BITMAP_CopyBitmap( HBITMAP32 hbitmap );
diff --git a/objects/bitmap.c b/objects/bitmap.c
index 2aa3b3f..c08193b 100644
--- a/objects/bitmap.c
+++ b/objects/bitmap.c
@@ -19,19 +19,18 @@
 
 
 /***********************************************************************
- *           BITMAP_GetBitsPadding
+ *           BITMAP_GetPadding
  *
  * Return number of bytes to pad a scanline of 16-bit aligned Windows DDB data.
  */
-INT32 BITMAP_GetBitsPadding( int bmWidth, int bpp )
+INT32 BITMAP_GetPadding( int bmWidth, int bpp )
 {
     INT32 pad;
 
     switch (bpp) 
     {
     case 1:
-	if (!(bmWidth & 15)) pad = 0;
-	else pad = ((16 - (bmWidth & 15)) + 7) / 8;
+        pad = ((bmWidth-1) & 8) ? 0 : 1;
 	break;
 
     case 8:
@@ -61,11 +60,12 @@
 }
 
 /***********************************************************************
- *           BITMAP_GetBitsWidth
+ *           BITMAP_GetWidthBytes
  *
- * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB data.
+ * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB
+ * data.
  */
-INT32 BITMAP_GetBitsWidth( int bmWidth, int bpp )
+INT32 BITMAP_GetWidthBytes( INT32 bmWidth, INT32 bpp )
 {
     switch(bpp)
     {
@@ -167,11 +167,11 @@
     bmp->size.cx = 0;
     bmp->size.cy = 0;
     bmp->bitmap.bmType = 0;
-    bmp->bitmap.bmWidth = (INT16)width;
-    bmp->bitmap.bmHeight = (INT16)height;
-    bmp->bitmap.bmPlanes = (BYTE)planes;
-    bmp->bitmap.bmBitsPixel = (BYTE)bpp;
-    bmp->bitmap.bmWidthBytes = (INT16)BITMAP_WIDTH_BYTES( width, bpp );
+    bmp->bitmap.bmWidth = width;
+    bmp->bitmap.bmHeight = height;
+    bmp->bitmap.bmPlanes = planes;
+    bmp->bitmap.bmBitsPixel = bpp;
+    bmp->bitmap.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
     bmp->bitmap.bmBits = NULL;
 
     bmp->DDBitmap = NULL;
@@ -594,8 +594,11 @@
 }
 
 
-HBITMAP32 BITMAP_LoadBitmap32W(HINSTANCE32 instance,LPCWSTR name,
-  UINT32 loadflags)
+/**********************************************************************
+ *       BITMAP_LoadBitmap32W
+ */
+HBITMAP32 BITMAP_LoadBitmap32W(HINSTANCE32 instance,LPCWSTR name, 
+			       UINT32 loadflags)
 {
     HBITMAP32 hbitmap = 0;
     HDC32 hdc;
@@ -647,6 +650,8 @@
     if (loadflags & LR_LOADFROMFILE) UnmapViewOfFile( ptr );
     return hbitmap;
 }
+
+
 /******************************************************************************
  * LoadBitmap32W [USER32.358]  Loads bitmap from the executable file
  *
diff --git a/objects/cursoricon.c b/objects/cursoricon.c
index 9dfac0c..57e0738 100644
--- a/objects/cursoricon.c
+++ b/objects/cursoricon.c
@@ -754,8 +754,8 @@
 	   TRACE(icon, "[%04x] %ix%i %ibpp (bogus %ibps)\n", 
 		hIcon, pIcon->nWidth, pIcon->nHeight, pIcon->bBitsPerPixel, pIcon->nWidthBytes );
 
-	   xor_width = BITMAP_GetBitsWidth( pIcon->nWidth, bpp );
-	   and_width =  BITMAP_GetBitsWidth( pIcon->nWidth, 1 );
+	   xor_width = BITMAP_GetWidthBytes( pIcon->nWidth, bpp );
+	   and_width = BITMAP_GetWidthBytes( pIcon->nWidth, 1 );
 	   psPtr = (BYTE *)(pIcon + 1) + pIcon->nHeight * and_width;
 
            memset(pXorBits, 0, 128);
@@ -923,9 +923,9 @@
 
     hInstance = GetExePtr( hInstance );  /* Make it a module handle */
     if (!lpXORbits || !lpANDbits || info->bPlanes != 1) return 0;
-    info->nWidthBytes = BITMAP_WIDTH_BYTES(info->nWidth,info->bBitsPerPixel);
+    info->nWidthBytes = BITMAP_GetWidthBytes(info->nWidth,info->bBitsPerPixel);
     sizeXor = info->nHeight * info->nWidthBytes;
-    sizeAnd = info->nHeight * BITMAP_WIDTH_BYTES( info->nWidth, 1 );
+    sizeAnd = info->nHeight * BITMAP_GetWidthBytes( info->nWidth, 1 );
     if (!(handle = GlobalAlloc16( GMEM_MOVEABLE,
                                   sizeof(CURSORICONINFO) + sizeXor + sizeAnd)))
         return 0;
@@ -1057,7 +1057,7 @@
                                (char *)(ptr+1) );
     hXorBits = CreateBitmap32( ptr->nWidth, ptr->nHeight, ptr->bPlanes,
                                ptr->bBitsPerPixel, (char *)(ptr + 1)
-                         + ptr->nHeight * BITMAP_WIDTH_BYTES(ptr->nWidth,1) );
+                        + ptr->nHeight * BITMAP_GetWidthBytes(ptr->nWidth,1) );
     oldFg = SetTextColor32( hdc, RGB(0,0,0) );
     oldBg = SetBkColor32( hdc, RGB(255,255,255) );
 
@@ -1090,7 +1090,7 @@
 
     if (!info) return 0;
     sizeXor = info->nHeight * info->nWidthBytes;
-    sizeAnd = info->nHeight * BITMAP_WIDTH_BYTES( info->nWidth, 1 );
+    sizeAnd = info->nHeight * BITMAP_GetWidthBytes( info->nWidth, 1 );
     if (lpAndBits) *lpAndBits = pInfo + sizeof(CURSORICONINFO);
     if (lpXorBits) *lpXorBits = pInfo + sizeof(CURSORICONINFO) + sizeAnd;
     if (lpLen) *lpLen = sizeof(CURSORICONINFO) + sizeAnd + sizeXor;
@@ -1674,8 +1674,7 @@
                                 ciconinfo->bPlanes, ciconinfo->bBitsPerPixel,
                                 (char *)(ciconinfo + 1)
                                 + ciconinfo->nHeight *
-                                BITMAP_GetBitsWidth (ciconinfo->nWidth,1) );
-//                                BITMAP_WIDTH_BYTES(ciconinfo->nWidth,1) );
+                                BITMAP_GetWidthBytes (ciconinfo->nWidth,1) );
     iconinfo->hbmMask = CreateBitmap32 ( ciconinfo->nWidth, ciconinfo->nHeight,
                                 1, 1, (char *)(ciconinfo + 1));
 
@@ -1819,7 +1818,7 @@
 				    ptr->bPlanes, ptr->bBitsPerPixel,
 				    (char *)(ptr + 1)
 				    + ptr->nHeight *
-				    BITMAP_WIDTH_BYTES(ptr->nWidth,1) );
+				    BITMAP_GetWidthBytes(ptr->nWidth,1) );
 	hAndBits = CreateBitmap32 ( ptr->nWidth, ptr->nHeight,
 				    1, 1, (char *)(ptr+1) );
 	oldFg = SetTextColor32( hdc, RGB(0,0,0) );
diff --git a/objects/oembitmap.c b/objects/oembitmap.c
index d79b60f..c3c45b9 100644
--- a/objects/oembitmap.c
+++ b/objects/oembitmap.c
@@ -332,7 +332,7 @@
     bmpObjPtr->bitmap.bmType       = 0;
     bmpObjPtr->bitmap.bmWidth      = width;
     bmpObjPtr->bitmap.bmHeight     = height;
-    bmpObjPtr->bitmap.bmWidthBytes = BITMAP_WIDTH_BYTES( width, bpp );
+    bmpObjPtr->bitmap.bmWidthBytes = BITMAP_GetWidthBytes( width, bpp );
     bmpObjPtr->bitmap.bmPlanes     = 1;
     bmpObjPtr->bitmap.bmBitsPixel  = bpp;
     bmpObjPtr->bitmap.bmBits       = NULL;
@@ -476,7 +476,8 @@
     bmpXor = (BITMAPOBJ *) GDI_GetObjPtr( descr.bitmap, BITMAP_MAGIC );
     bmpAnd = (BITMAPOBJ *) GDI_GetObjPtr( descr.mask, BITMAP_MAGIC );
     sizeXor = bmpXor->bitmap.bmHeight * bmpXor->bitmap.bmWidthBytes;
-    sizeAnd = bmpXor->bitmap.bmHeight * BITMAP_WIDTH_BYTES( bmpXor->bitmap.bmWidth, 1 );
+    sizeAnd = bmpXor->bitmap.bmHeight * 
+			BITMAP_GetWidthBytes( bmpXor->bitmap.bmWidth, 1 );
 
     if (!(handle = GlobalAlloc16( GMEM_MOVEABLE,
                                   sizeof(CURSORICONINFO) + sizeXor + sizeAnd)))