Moved the 16-bit pointer to the DIB bits out of the driver-specific
structure and into the main bitmap structure. Removed
CreateDIBSection16 from the driver interface.

diff --git a/dlls/gdi/wing.c b/dlls/gdi/wing.c
index 0eb84e1..d382b84 100644
--- a/dlls/gdi/wing.c
+++ b/dlls/gdi/wing.c
@@ -6,10 +6,6 @@
 
 #include "config.h"
 
-#ifndef X_DISPLAY_MISSING
-#include "x11drv.h"
-#endif /* !defined(X_DISPLAY_MISSING) */
-
 #include "wine/winuser16.h"
 #include "bitmap.h"
 #include "debugtools.h"
@@ -89,19 +85,15 @@
  */
 SEGPTR WINAPI WinGGetDIBPointer16(HBITMAP16 hWinGBitmap, BITMAPINFO* bmpi)
 {
-  BITMAPOBJ*	bmp = (BITMAPOBJ *) GDI_GetObjPtr( hWinGBitmap, BITMAP_MAGIC );
+    BITMAPOBJ* bmp = (BITMAPOBJ *) GDI_GetObjPtr( hWinGBitmap, BITMAP_MAGIC );
     SEGPTR res = 0;
 
     TRACE("(%d,%p)\n", hWinGBitmap, bmpi);
-    if (!bmp) return (SEGPTR)NULL;
+    if (!bmp) return 0;
 
-    if (bmpi)
-	FIXME(": Todo - implement setting BITMAPINFO\n");
+    if (bmpi) FIXME(": Todo - implement setting BITMAPINFO\n");
 
-#ifndef X_DISPLAY_MISSING
-    res = MAKESEGPTR(((X11DRV_DIBSECTION *) bmp->dib)->selector, 0);
-#endif /* !defined(X_DISPLAY_MISSING) */
-    
+    res = bmp->segptr_bits;
     GDI_ReleaseObj( hWinGBitmap );
     return res;
 }
diff --git a/dlls/ttydrv/bitmap.c b/dlls/ttydrv/bitmap.c
index 6cd581b..6c5df15 100644
--- a/dlls/ttydrv/bitmap.c
+++ b/dlls/ttydrv/bitmap.c
@@ -184,19 +184,6 @@
   return (HBITMAP) NULL;
 }
 
-/**********************************************************************
- *		TTYDRV_BITMAP_CreateDIBSection16
- */
-HBITMAP16 TTYDRV_DIB_CreateDIBSection16(
-  DC *dc, BITMAPINFO *bmi, UINT16 usage,
-  SEGPTR *bits, HANDLE section, DWORD offset)
-{
-  FIXME("(%p, %p, %u, %p, 0x%04x, %ld): stub\n",
-	dc, bmi, usage, bits, section, offset);
-
-  return (HBITMAP16) NULL;
-}
-
 /***********************************************************************
  *		TTYDRV_BITMAP_DeleteDIBSection
  */
diff --git a/dlls/ttydrv/dc.c b/dlls/ttydrv/dc.c
index 1dc83d8..30de623 100644
--- a/dlls/ttydrv/dc.c
+++ b/dlls/ttydrv/dc.c
@@ -33,7 +33,6 @@
   TTYDRV_DC_CreateBitmap, /* pCreateBitmap */
   TTYDRV_DC_CreateDC,  /* pCreateDC */
   NULL,                /* pCreateDIBSection */
-  NULL,                /* pCreateDIBSection16 */
   TTYDRV_DC_DeleteDC,  /* pDeleteDC */
   TTYDRV_DC_DeleteObject, /* pDeleteObject */
   NULL,                /* pDescribePixelFormat */
diff --git a/dlls/ttydrv/ttydrv.h b/dlls/ttydrv/ttydrv.h
index 1b77028..91bcdcb 100644
--- a/dlls/ttydrv/ttydrv.h
+++ b/dlls/ttydrv/ttydrv.h
@@ -45,8 +45,6 @@
 /* TTY GDI bitmap driver */
 
 extern HBITMAP TTYDRV_BITMAP_CreateDIBSection(struct tagDC *dc, BITMAPINFO *bmi, UINT usage, LPVOID *bits, HANDLE section, DWORD offset);
-extern HBITMAP16 TTYDRV_BITMAP_CreateDIBSection16(struct tagDC *dc, BITMAPINFO *bmi, UINT16 usage, SEGPTR *bits, HANDLE section, DWORD offset);
-
 extern INT TTYDRV_BITMAP_SetDIBits(struct tagBITMAPOBJ *bmp, struct tagDC *dc, UINT startscan, UINT lines, LPCVOID bits, const BITMAPINFO *info, UINT coloruse, HBITMAP hbitmap);
 extern INT TTYDRV_BITMAP_GetDIBits(struct tagBITMAPOBJ *bmp, struct tagDC *dc, UINT startscan, UINT lines, LPVOID bits, BITMAPINFO *info, UINT coloruse, HBITMAP hbitmap);
 extern void TTYDRV_BITMAP_DeleteDIBSection(struct tagBITMAPOBJ *bmp);
diff --git a/dlls/wineps/init.c b/dlls/wineps/init.c
index f908ee2..819d1b0 100644
--- a/dlls/wineps/init.c
+++ b/dlls/wineps/init.c
@@ -45,7 +45,6 @@
     NULL,                            /* pCreateBitmap */
     PSDRV_CreateDC,                  /* pCreateDC */
     NULL,                            /* pCreateDIBSection */
-    NULL,                            /* pCreateDIBSection16 */
     PSDRV_DeleteDC,                  /* pDeleteDC */
     NULL,                            /* pDeleteObject */
     NULL,                            /* pDescribePixelFormat */
diff --git a/graphics/enhmetafiledrv/init.c b/graphics/enhmetafiledrv/init.c
index b807b3a..7e8892a 100644
--- a/graphics/enhmetafiledrv/init.c
+++ b/graphics/enhmetafiledrv/init.c
@@ -32,7 +32,6 @@
     NULL,                            /* pCreateBitmap */
     NULL, /* no implementation */    /* pCreateDC */
     NULL,                            /* pCreateDIBSection */
-    NULL,                            /* pCreateDIBSection16 */
     NULL, /* no implementation */    /* pDeleteDC */
     NULL,                            /* pDeleteObject */
     NULL,                            /* pDescribePixelFormat */
diff --git a/graphics/metafiledrv/init.c b/graphics/metafiledrv/init.c
index 7dbe5a1..758ba1e 100644
--- a/graphics/metafiledrv/init.c
+++ b/graphics/metafiledrv/init.c
@@ -32,7 +32,6 @@
     NULL,                            /* pCreateBitmap */
     NULL, /* no implementation */    /* pCreateDC */
     NULL,                            /* pCreateDIBSection */
-    NULL,                            /* pCreateDIBSection16 */
     NULL, /* no implementation */    /* pDeleteDC */
     NULL,                            /* pDeleteObject */
     NULL,                            /* pDescribePixelFormat */
diff --git a/graphics/win16drv/init.c b/graphics/win16drv/init.c
index dfd4b66..510a16e 100644
--- a/graphics/win16drv/init.c
+++ b/graphics/win16drv/init.c
@@ -58,7 +58,6 @@
     NULL,                            /* pCreateBitmap */
     WIN16DRV_CreateDC,               /* pCreateDC */
     NULL,                            /* pCreateDIBSection */
-    NULL,                            /* pCreateDIBSection16 */
     NULL,                            /* pDeleteDC */
     NULL,                            /* pDeleteObject */
     NULL,                            /* pDescribePixelFormat */
diff --git a/graphics/x11drv/dib.c b/graphics/x11drv/dib.c
index 2c9b4ca..789ba03 100644
--- a/graphics/x11drv/dib.c
+++ b/graphics/x11drv/dib.c
@@ -25,8 +25,7 @@
 #include "x11drv.h"
 #include "debugtools.h"
 #include "gdi.h"
-#include "color.h"
-#include "selectors.h"
+#include "palette.h"
 #include "global.h"
 
 DEFAULT_DEBUG_CHANNEL(bitmap);
@@ -3732,46 +3731,6 @@
   X11DRV_UnlockDIBSection2( dc->hBitmap, commit );
 }
 
-/***********************************************************************
- *           X11DRV_DIB_CreateDIBSection16
- */
-HBITMAP16 X11DRV_DIB_CreateDIBSection16(
-  DC *dc, BITMAPINFO *bmi, UINT16 usage,
-  SEGPTR *bits, HANDLE section,
-  DWORD offset, DWORD ovr_pitch)
-{
-  HBITMAP res = X11DRV_DIB_CreateDIBSection(dc, bmi, usage, NULL, 
-					    section, offset, ovr_pitch);
-  if ( res )
-    {
-      BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr(res, BITMAP_MAGIC);
-      if ( bmp && bmp->dib )
-	{
-	  DIBSECTION *dib = bmp->dib;
-	  INT height = dib->dsBm.bmHeight >= 0 ?
-	    dib->dsBm.bmHeight : -dib->dsBm.bmHeight;
-	  /* same as above - only use biSizeImage as the correct size if it a
-	     compressed image and it's currently non-zero.  In other cases, use
-	     width * height as the value. */
-	  INT size = dib->dsBmih.biSizeImage && dib->dsBmih.biCompression != BI_RGB
-	    ? dib->dsBmih.biSizeImage
-	    : dib->dsBm.bmWidthBytes * height;
-	  if ( dib->dsBm.bmBits )
-	    {
-	      ((X11DRV_DIBSECTION *) bmp->dib)->selector = 
-                  SELECTOR_AllocBlock( dib->dsBm.bmBits, size, WINE_LDT_FLAGS_DATA );
-	    }
-	  TRACE("ptr = %p, size =%d, selector = %04x, segptr = %ld\n",
-			 dib->dsBm.bmBits, size, ((X11DRV_DIBSECTION *) bmp->dib)->selector,
-			 MAKESEGPTR(((X11DRV_DIBSECTION *) bmp->dib)->selector, 0));
-      if ( bits ) 
-	*bits = MAKESEGPTR( ((X11DRV_DIBSECTION *) bmp->dib)->selector, 0 );
-    }
-      if (bmp) GDI_ReleaseObj( res );
-    }
-
-    return res;
-}
 
 #ifdef HAVE_LIBXXSHM
 /***********************************************************************
@@ -3945,8 +3904,6 @@
       dib->dibSection.dsOffset = offset;
       
       dib->status    = DIB_Status_None;
-      dib->selector  = 0;
-      
       dib->nColorMap = nColorMap;
       dib->colorMap  = colorMap;
     }
@@ -4055,7 +4012,6 @@
   if (dib->colorMap)
     HeapFree(GetProcessHeap(), 0, dib->colorMap);
 
-  if (dib->selector) SELECTOR_FreeBlock( dib->selector );
   DeleteCriticalSection(&(dib->lock));
 }
 
diff --git a/graphics/x11drv/init.c b/graphics/x11drv/init.c
index 8b5dd5e..58b4f1d 100644
--- a/graphics/x11drv/init.c
+++ b/graphics/x11drv/init.c
@@ -11,7 +11,7 @@
 #include <string.h>
 
 #include "bitmap.h"
-#include "color.h"
+#include "palette.h"
 #include "debugtools.h"
 #include "winnt.h"
 #include "x11drv.h"
@@ -42,7 +42,6 @@
     X11DRV_CreateBitmap,             /* pCreateBitmap */
     X11DRV_CreateDC,                 /* pCreateDC */
     X11DRV_DIB_CreateDIBSection,     /* pCreateDIBSection */
-    X11DRV_DIB_CreateDIBSection16,   /* pCreateDIBSection16 */
     X11DRV_DeleteDC,                 /* pDeleteDC */
     X11DRV_DeleteObject,             /* pDeleteObject */
     X11DRV_DescribePixelFormat,      /* pDescribePixelFormat */
diff --git a/include/bitmap.h b/include/bitmap.h
index 6aa311b..7b9aeb3 100644
--- a/include/bitmap.h
+++ b/include/bitmap.h
@@ -31,6 +31,7 @@
     void	*physBitmap; /* ptr to device specific data */
     /* For device-independent bitmaps: */
     DIBSECTION *dib;
+    SEGPTR      segptr_bits;  /* segptr to DIB bits */
 } BITMAPOBJ;
 
 typedef struct tagBITMAP_DRIVER
diff --git a/include/gdi.h b/include/gdi.h
index 5efd308..3ce380b 100644
--- a/include/gdi.h
+++ b/include/gdi.h
@@ -175,8 +175,6 @@
     BOOL     (*pCreateDC)(DC*,LPCSTR,LPCSTR,LPCSTR,const DEVMODEA*);
     HBITMAP  (*pCreateDIBSection)(DC *,BITMAPINFO *,UINT,LPVOID *,HANDLE,
 				  DWORD,DWORD);
-    HBITMAP16 (*pCreateDIBSection16)(DC *,BITMAPINFO *,UINT16,SEGPTR *,HANDLE,
-				     DWORD,DWORD);
     BOOL     (*pDeleteDC)(DC*);
     BOOL     (*pDeleteObject)(HGDIOBJ);
     INT      (*pDescribePixelFormat)(DC *,INT,UINT,PIXELFORMATDESCRIPTOR *);
diff --git a/include/x11drv.h b/include/x11drv.h
index 74150b9..fc88181 100644
--- a/include/x11drv.h
+++ b/include/x11drv.h
@@ -214,9 +214,6 @@
     /* Cached XImage */
     XImage     *image;
 
-    /* Selector for 16-bit access to bits */
-    WORD selector;
-
 #ifdef HAVE_LIBXXSHM
     /* Shared memory segment info */
     XShmSegmentInfo shminfo;
@@ -243,8 +240,6 @@
 
 extern HBITMAP X11DRV_DIB_CreateDIBSection(struct tagDC *dc, BITMAPINFO *bmi, UINT usage,
 					   LPVOID *bits, HANDLE section, DWORD offset, DWORD ovr_pitch);
-extern HBITMAP16 X11DRV_DIB_CreateDIBSection16(struct tagDC *dc, BITMAPINFO *bmi, UINT16 usage,
-					       SEGPTR *bits, HANDLE section, DWORD offset, DWORD ovr_pitch);
 
 extern struct tagBITMAP_DRIVER X11DRV_BITMAP_Driver;
 
diff --git a/objects/bitmap.c b/objects/bitmap.c
index 7ca2f11..ce00d7a 100644
--- a/objects/bitmap.c
+++ b/objects/bitmap.c
@@ -138,6 +138,7 @@
     bmp->funcs = NULL;
     bmp->physBitmap = NULL;
     bmp->dib = NULL;
+    bmp->segptr_bits = 0;
 
     if (bits) /* Set bitmap bits */
 	SetBitmapBits( hbitmap, height * bmp->bitmap.bmWidthBytes,
diff --git a/objects/dib.c b/objects/dib.c
index c588ddf..15514dc 100644
--- a/objects/dib.c
+++ b/objects/dib.c
@@ -11,6 +11,7 @@
 #include "winbase.h"
 #include "bitmap.h"
 #include "callback.h"
+#include "selectors.h"
 #include "gdi.h"
 #include "debugtools.h"
 #include "palette.h"
@@ -853,29 +854,29 @@
  *           CreateDIBSection    (GDI.489)
  */
 HBITMAP16 WINAPI CreateDIBSection16 (HDC16 hdc, BITMAPINFO *bmi, UINT16 usage,
-				     SEGPTR *bits, HANDLE section,
-				     DWORD offset)
+                                     SEGPTR *bits16, HANDLE section, DWORD offset)
 {
-    HBITMAP16 hbitmap = 0;
-    DC *dc;
-    BOOL bDesktopDC = FALSE;
+    LPVOID bits32;
+    HBITMAP hbitmap;
 
-    /* If the reference hdc is null, take the desktop dc */
-    if (hdc == 0)
+    hbitmap = CreateDIBSection( hdc, bmi, usage, &bits32, section, offset );
+    if (hbitmap)
     {
-        hdc = CreateCompatibleDC(0);
-        bDesktopDC = TRUE;
+        BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr(hbitmap, BITMAP_MAGIC);
+        if (bmp && bmp->dib && bits32)
+        {
+            BITMAPINFOHEADER *bi = &bmi->bmiHeader;
+            INT height = bi->biHeight >= 0 ? bi->biHeight : -bi->biHeight;
+            INT width_bytes = DIB_GetDIBWidthBytes(bi->biWidth, bi->biBitCount);
+            INT size  = (bi->biSizeImage && bi->biCompression != BI_RGB) ?
+                         bi->biSizeImage : width_bytes * height;
+
+            WORD sel = SELECTOR_AllocBlock( bits32, size, WINE_LDT_FLAGS_DATA );
+            bmp->segptr_bits = MAKESEGPTR( sel, 0 );
+            if (bits16) *bits16 = bmp->segptr_bits;
+        }
+        if (bmp) GDI_ReleaseObj( hbitmap );
     }
-
-    if ((dc = DC_GetDCPtr( hdc )))
-    {
-        hbitmap = dc->funcs->pCreateDIBSection16(dc, bmi, usage, bits, section, offset, 0);
-        GDI_ReleaseObj(hdc);
-    }
-
-    if (bDesktopDC)
-      DeleteDC(hdc);
-
     return hbitmap;
 }
 
@@ -945,6 +946,7 @@
 
         HeapFree(GetProcessHeap(), 0, dib);
         bmp->dib = NULL;
+        if (bmp->segptr_bits) SELECTOR_FreeBlock( SELECTOROF(bmp->segptr_bits) );
     }
 }