X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/fd3f686c274a264e89ea97505350a82c1134f307..e702ff0f08a54622a6b0f1e2ec39537b082c3a8e:/src/msw/dib.cpp diff --git a/src/msw/dib.cpp b/src/msw/dib.cpp index 4694f6b261..871197195c 100644 --- a/src/msw/dib.cpp +++ b/src/msw/dib.cpp @@ -35,18 +35,24 @@ #ifndef WX_PRECOMP #include "wx/setup.h" #include "wx/defs.h" +#include "wx/bitmap.h" #endif #include #include #include + +#if !defined(__MWERKS__) && !defined(__SALFORDC__) #include +#endif #include "wx/msw/dib.h" +#ifndef __TWIN32__ #ifdef __GNUWIN32__ #include "wx/msw/gnuwin32/extra.h" #endif +#endif #ifndef SEEK_CUR /* flags for _lseek */ @@ -121,7 +127,7 @@ BOOL WriteDIB(LPSTR szFile, HANDLE hdib) hdr.bfSize = GlobalSize(hdib) + sizeof(BITMAPFILEHEADER); hdr.bfReserved1 = 0; hdr.bfReserved2 = 0; - hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + lpbi->biSize + + hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) + lpbi->biSize + PaletteSize(lpbi); /* Write the file header */ @@ -158,7 +164,7 @@ WORD PaletteSize(VOID FAR * pv) if (lpbi->biSize == sizeof(BITMAPCOREHEADER)) return NumColors * sizeof(RGBTRIPLE); - else + else return NumColors * sizeof(RGBQUAD); } @@ -192,7 +198,7 @@ WORD DibNumColors(VOID FAR *pv) return (WORD) lpbi->biClrUsed; bits = lpbi->biBitCount; } - else + else bits = lpbc->bcBitCount; switch (bits) { @@ -255,7 +261,7 @@ HANDLE DibFromBitmap(HBITMAP hbm, DWORD biStyle, WORD biBits, HPALETTE hpal) dwLen = bi.biSize + PaletteSize(&bi); - hdc = GetDC(NULL); + hdc = GetDC((HWND) NULL); hpal = SelectPalette(hdc, hpal, FALSE); RealizePalette(hdc); @@ -323,7 +329,7 @@ HANDLE DibFromBitmap(HBITMAP hbm, DWORD biStyle, WORD biBits, HPALETTE hpal) GlobalUnlock(hdib); hdib = NULL; SelectPalette(hdc, hpal, FALSE); - ReleaseDC(NULL, hdc); + ReleaseDC((HWND) NULL, hdc); return NULL; } @@ -406,7 +412,7 @@ DWORD PASCAL lwrite(int fh, VOID FAR *pv, DWORD ul) * is loaded, the function also creates a bitmap and * palette out of the DIB for a device-dependent form. * - * RETURNS : TRUE - DIB loaded and bitmap/palette created + * RETURNS : TRUE - DIB loaded and bitmap/palette created * The DIBINIT structure pointed to by pInfo is * filled with the appropriate handles. * FALSE - otherwise @@ -430,12 +436,12 @@ BOOL ReadDIB(LPSTR lpFileName, HBITMAP *bitmap, HPALETTE *palette) fh = OpenFile (lpFileName, &of, OF_READ); if (fh == -1) { - wsprintf(str,"Can't open file '%ls'", (LPSTR)lpFileName); + wsprintf(str,"Can't open file '%s'", lpFileName); MessageBox(NULL, str, "Error", MB_ICONSTOP | MB_OK); return (0); } - - hDIB = GlobalAlloc(GHND, (DWORD)(sizeof(BITMAPINFOHEADER) + + + hDIB = GlobalAlloc(GHND, (DWORD)(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD))); if (!hDIB) return(0); @@ -491,7 +497,7 @@ BOOL ReadDIB(LPSTR lpFileName, HBITMAP *bitmap, HPALETTE *palette) * lpbi->biHeight; } - /* get a proper-sized buffer for header, color table and bits */ + /* get a proper-sized buffer for header, color table and bits */ GlobalUnlock(hDIB); hDIB = GlobalReAlloc(hDIB, lpbi->biSize + nNumColors * sizeof(RGBQUAD) + @@ -573,7 +579,7 @@ ErrExit2: * to be used for a device-dependent representation of * of the image. * - * RETURNS : TRUE --> success. phPal and phBitmap are filled with + * RETURNS : TRUE --> success. phPal and phBitmap are filled with * appropriate handles. Caller is responsible * for freeing objects. * FALSE --> unable to create objects. both pointer are @@ -602,9 +608,9 @@ BOOL PASCAL MakeBitmapAndPalette(HDC hDC, HANDLE hDIB, hOldPal = SelectPalette(hDC, hPalette, TRUE); RealizePalette(hDC); - lpBits = (LPSTR)lpInfo + (WORD)lpInfo->biSize + + lpBits = (LPSTR)lpInfo + (WORD)lpInfo->biSize + (WORD)lpInfo->biClrUsed * sizeof(RGBQUAD); - hBitmap = CreateDIBitmap(hDC, lpInfo, CBM_INIT, lpBits, + hBitmap = CreateDIBitmap(hDC, lpInfo, CBM_INIT, lpBits, (LPBITMAPINFO)lpInfo, DIB_RGB_COLORS); SelectPalette(hDC, hOldPal, TRUE); @@ -626,11 +632,11 @@ BOOL PASCAL MakeBitmapAndPalette(HDC hDC, HANDLE hDIB, * * * FUNCTION : MakeDIBPalette(lpInfo) * * * - * PURPOSE : Given a BITMAPINFOHEADER, create a palette based on + * PURPOSE : Given a BITMAPINFOHEADER, create a palette based on * the color table. - * + * * * - * RETURNS : non-zero - handle of a corresponding palette + * RETURNS : non-zero - handle of a corresponding palette * zero - unable to create palette * * ****************************************************************************/ @@ -638,7 +644,7 @@ HPALETTE MakeDIBPalette(LPBITMAPINFOHEADER lpInfo) { NPLOGPALETTE npPal; RGBQUAD far *lpRGB; - HPALETTE hLogPal; + HPALETTE hLogPal; WORD i; /* since biClrUsed field was filled during the loading of the DIB, @@ -647,10 +653,10 @@ HPALETTE MakeDIBPalette(LPBITMAPINFOHEADER lpInfo) if (lpInfo->biClrUsed) { /* - npPal = (NPLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) + + npPal = (NPLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) + (WORD)lpInfo->biClrUsed * sizeof(PALETTEENTRY)); */ - npPal = (NPLOGPALETTE)malloc(sizeof(LOGPALETTE) + + npPal = (NPLOGPALETTE)malloc(sizeof(LOGPALETTE) + (WORD)lpInfo->biClrUsed * sizeof(PALETTEENTRY)); if (!npPal) @@ -674,7 +680,7 @@ HPALETTE MakeDIBPalette(LPBITMAPINFOHEADER lpInfo) hLogPal = CreatePalette((LPLOGPALETTE)npPal); // LocalFree((HANDLE)npPal); free(npPal); - + return(hLogPal); } @@ -686,7 +692,7 @@ HPALETTE MakeDIBPalette(LPBITMAPINFOHEADER lpInfo) return((HPALETTE) GetStockObject(DEFAULT_PALETTE)); } -bool wxLoadIntoBitmap(char *filename, wxBitmap *bitmap, wxColourMap **pal) +bool wxLoadIntoBitmap(char *filename, wxBitmap *bitmap, wxPalette **pal) { HBITMAP hBitmap; HPALETTE hPalette; @@ -703,7 +709,7 @@ bool wxLoadIntoBitmap(char *filename, wxBitmap *bitmap, wxColourMap **pal) { if (pal) { - *pal = new wxColourMap; + *pal = new wxPalette; (*pal)->SetHPALETTE((WXHPALETTE) hPalette); } else @@ -727,7 +733,7 @@ bool wxLoadIntoBitmap(char *filename, wxBitmap *bitmap, wxColourMap **pal) else return FALSE; } -wxBitmap *wxLoadBitmap(char *filename, wxColourMap **pal) +wxBitmap *wxLoadBitmap(char *filename, wxPalette **pal) { wxBitmap *bitmap = new wxBitmap; if (wxLoadIntoBitmap(filename, bitmap, pal)) @@ -767,7 +773,7 @@ wxBitmap *wxLoadBitmap(char *filename, wxColourMap **pal) // // History: Date Reason // 11/07/91 Created -// +// //--------------------------------------------------------------------- void InitBitmapInfoHeader (LPBITMAPINFOHEADER lpBmInfoHdr, @@ -825,7 +831,7 @@ LPSTR FindDIBBits (LPSTR lpbi) // // History: Date Reason // 6/01/91 Created -// +// //--------------------------------------------------------------------- HANDLE BitmapToDIB (HBITMAP hBitmap, HPALETTE hPal) @@ -848,16 +854,16 @@ HANDLE BitmapToDIB (HBITMAP hBitmap, HPALETTE hPal) if (!GetObject (hBitmap, sizeof (Bitmap), (LPSTR) &Bitmap)) return NULL; - InitBitmapInfoHeader (&bmInfoHdr, - Bitmap.bmWidth, - Bitmap.bmHeight, + InitBitmapInfoHeader (&bmInfoHdr, + Bitmap.bmWidth, + Bitmap.bmHeight, Bitmap.bmPlanes * Bitmap.bmBitsPixel); // Now allocate memory for the DIB. Then, set the BITMAPINFOHEADER // into this memory, and find out where the bitmap bits go. - hDIB = GlobalAlloc (GHND, sizeof (BITMAPINFOHEADER) + + hDIB = GlobalAlloc (GHND, sizeof (BITMAPINFOHEADER) + PaletteSize ((LPSTR) &bmInfoHdr) + bmInfoHdr.biSizeImage); if (!hDIB) @@ -890,12 +896,12 @@ HANDLE BitmapToDIB (HBITMAP hBitmap, HPALETTE hPal) // it party on our bitmap. It will fill in the color table, // and bitmap bits of our global memory block. - if (!GetDIBits (hMemDC, - hBitmap, - 0, - Bitmap.bmHeight, - lpBits, - (LPBITMAPINFO) lpbmInfoHdr, + if (!GetDIBits (hMemDC, + hBitmap, + 0, + Bitmap.bmHeight, + lpBits, + (LPBITMAPINFO) lpbmInfoHdr, DIB_RGB_COLORS)) { GlobalUnlock (hDIB); @@ -916,7 +922,7 @@ HANDLE BitmapToDIB (HBITMAP hBitmap, HPALETTE hPal) return hDIB; } -bool wxSaveBitmap(char *filename, wxBitmap *bitmap, wxColourMap *colourmap) +bool wxSaveBitmap(char *filename, wxBitmap *bitmap, wxPalette *colourmap) { HPALETTE hPalette = 0; if (colourmap)