+#if wxUSE_DIB_FOR_BITMAP
+
+void *wxBitmap::CreateDIB(int width, int height, int depth)
+{
+ void *dibBits;
+ const int infosize = sizeof(BITMAPINFOHEADER);
+
+ BITMAPINFO *info = (BITMAPINFO *)malloc(infosize);
+ if ( info )
+ {
+ memset(info, 0, infosize);
+
+ info->bmiHeader.biSize = infosize;
+ info->bmiHeader.biWidth = width;
+ info->bmiHeader.biHeight = height;
+ info->bmiHeader.biPlanes = 1;
+ info->bmiHeader.biBitCount = depth;
+ info->bmiHeader.biCompression = BI_RGB;
+ info->bmiHeader.biSizeImage =
+ (((width * (depth/8)) + sizeof(DWORD) - 1) /
+ sizeof(DWORD) * sizeof(DWORD)) * height;
+ info->bmiHeader.biXPelsPerMeter = 0;
+ info->bmiHeader.biYPelsPerMeter = 0;
+ info->bmiHeader.biClrUsed = 0;
+ info->bmiHeader.biClrImportant = 0;
+ GetBitmapData()->m_hFileMap = ::CreateFileMapping
+ (
+ INVALID_HANDLE_VALUE,
+ 0,
+ PAGE_READWRITE | SEC_COMMIT,
+ 0,
+ info->bmiHeader.biSizeImage,
+ 0
+ );
+
+ // No need to report an error here. If it fails, we just won't use a
+ // file mapping and CreateDIBSection will just allocate memory for us.
+ GetBitmapData()->m_handle =
+ (WXHANDLE)::CreateDIBSection
+ (
+ 0,
+ info,
+ DIB_RGB_COLORS,
+ &dibBits,
+ GetBitmapData()->m_hFileMap,
+ 0
+ );
+
+ if ( !GetBitmapData()->m_handle )
+ wxLogLastError(wxT("CreateDIBSection"));
+
+ SetWidth(width);
+ SetHeight(height);
+ SetDepth(depth);
+
+ free(info);
+ }
+ else
+ {
+ wxFAIL_MSG( wxT("could not allocate memory for DIB header") );
+
+ dibBits = NULL;
+ }
+
+ return dibBits;
+}
+
+#endif // wxUSE_DIB_FOR_BITMAP
+