- BITMAPFILEHEADER hdr;
- LPBITMAPINFOHEADER lpbi;
- int fh;
- OFSTRUCT of;
-
- if (!hdib)
- return FALSE;
-
- fh = OpenFile(wxConvertWX2MB(szFile), &of, OF_CREATE | OF_READWRITE);
- if (fh == -1)
- return FALSE;
-
-#ifdef __WINDOWS_386__
- lpbi = (LPBITMAPINFOHEADER) MK_FP32(GlobalLock(hdib));
-#else
- lpbi = (LPBITMAPINFOHEADER) GlobalLock(hdib);
-#endif
- /* Fill in the fields of the file header */
- hdr.bfType = BFT_BITMAP;
- hdr.bfSize = GlobalSize(hdib) + sizeof(BITMAPFILEHEADER);
- hdr.bfReserved1 = 0;
- hdr.bfReserved2 = 0;
- hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + lpbi->biSize +
- wxPaletteSize(lpbi);
-
- /* Write the file header */
- _lwrite(fh, (LPSTR) &hdr, sizeof(BITMAPFILEHEADER));
-
- /* Write the DIB header and the bits */
- lwrite(fh, (LPSTR) lpbi, GlobalSize(hdib));
-
- GlobalUnlock(hdib);
- _lclose(fh);
- return TRUE;
-}
-
-/****************************************************************************
- * *
- * FUNCTION : wxPaletteSize(VOID FAR * pv) *
- * *
- * PURPOSE : Calculates the palette size in bytes. If the info. block *
- * is of the BITMAPCOREHEADER type, the number of colors is *
- * multiplied by 3 to give the palette size, otherwise the *
- * number of colors is multiplied by 4. *
- * *
- * RETURNS : Palette size in number of bytes. *
- * *
- ****************************************************************************/
-
-WORD wxPaletteSize(VOID FAR * pv)
-{
- LPBITMAPINFOHEADER lpbi;
- WORD NumColors;
-
- lpbi = (LPBITMAPINFOHEADER) pv;
- NumColors = DibNumColors(lpbi);
-
- if (lpbi->biSize == sizeof(BITMAPCOREHEADER))
- return (WORD)(NumColors * sizeof(RGBTRIPLE));
- else
- return (WORD)(NumColors * sizeof(RGBQUAD));
-}
-
-/****************************************************************************
- * *
- * FUNCTION : DibNumColors(VOID FAR * pv) *
- * *
- * PURPOSE : Determines the number of colors in the DIB by looking at *
- * the BitCount filed in the info block. *
- * *
- * RETURNS : The number of colors in the DIB. *
- * *
- ****************************************************************************/
-
-static WORD DibNumColors(VOID FAR *pv)
-{
- int bits;
- BITMAPINFOHEADER *lpbi;
- BITMAPCOREHEADER *lpbc;
-
- lpbi = ((BITMAPINFOHEADER*) pv);
- lpbc = ((BITMAPCOREHEADER*) pv);
-
- /* With the BITMAPINFO format headers, the size of the palette
- * is in biClrUsed, whereas in the BITMAPCORE - style headers, it
- * is dependent on the bits per pixel ( = 2 raised to the power of
- * bits/pixel).
- */
- if (lpbi->biSize != sizeof(BITMAPCOREHEADER)) {
- if (lpbi->biClrUsed != 0)
- return (WORD) lpbi->biClrUsed;
- bits = lpbi->biBitCount;
- }
- else
- bits = lpbc->bcBitCount;
-
- switch (bits) {
- case 1:
- return 2;
- case 4:
- return 16;
- case 8:
- return 256;
- default:
- /* A 24 bitcount DIB has no color table */
- return 0;
- }
-}
-
-/****************************************************************************
- * *
- * FUNCTION : DibFromBitmap() *
- * *
- * PURPOSE : Will create a global memory block in DIB format that *
- * represents the Device-dependent bitmap (DDB) passed in. *
- * *
- * RETURNS : A handle to the DIB *
- * *
- ****************************************************************************/
-
-#if NOTHING
-static HANDLE DibFromBitmap(HBITMAP hbm, DWORD biStyle, WORD biBits, HPALETTE hpal)
-{
- BITMAP bm;
- BITMAPINFOHEADER bi;
- BITMAPINFOHEADER FAR *lpbi;
- DWORD dwLen;
- HANDLE hdib;
- HANDLE h;
- HDC hdc;
-
- if (!hbm)
- return NULL;
-
- if (hpal == NULL)
- hpal = GetStockObject(DEFAULT_PALETTE);
-
- GetObject(hbm, sizeof (bm), (LPSTR) &bm);
-
- if (biBits == 0)
- biBits = bm.bmPlanes * bm.bmBitsPixel;
-
- bi.biSize = sizeof(BITMAPINFOHEADER);
- bi.biWidth = bm.bmWidth;
- bi.biHeight = bm.bmHeight;
- bi.biPlanes = 1;
- bi.biBitCount = biBits;
- bi.biCompression = biStyle;
- bi.biSizeImage = 0;
- bi.biXPelsPerMeter = 0;
- bi.biYPelsPerMeter = 0;
- bi.biClrUsed = 0;
- bi.biClrImportant = 0;
-
- dwLen = bi.biSize + wxPaletteSize(&bi);
-
- hdc = GetDC((HWND) NULL);
- hpal = SelectPalette(hdc, hpal, FALSE);
- RealizePalette(hdc);
-
- hdib = GlobalAlloc(GHND, dwLen);
-
- if (!hdib) {
- SelectPalette(hdc, hpal, FALSE);
- ReleaseDC(NULL, hdc);
- return NULL;
- }