From 146dcf3e22216705d3b3caf140b4f76521e63a52 Mon Sep 17 00:00:00 2001 From: Mattia Barbon Date: Tue, 21 Jun 2005 20:17:42 +0000 Subject: [PATCH] Implemented loading 256-color bitmaps. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34726 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/dib.cpp | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/msw/dib.cpp b/src/msw/dib.cpp index 1a57decc31..5d2ef8e621 100644 --- a/src/msw/dib.cpp +++ b/src/msw/dib.cpp @@ -394,7 +394,31 @@ HBITMAP wxDIB::CreateDDB(HDC hdc) const return 0; } - return ConvertToBitmap((BITMAPINFO *)&ds.dsBmih, hdc, ds.dsBm.bmBits); + // how many colours are we going to have in the palette? + DWORD biClrUsed = ds.dsBmih.biClrUsed; + if ( !biClrUsed ) + { + // biClrUsed field might not be set + biClrUsed = GetNumberOfColours(ds.dsBmih.biBitCount); + } + + if ( !biClrUsed ) + { + return ConvertToBitmap((BITMAPINFO *)&ds.dsBmih, hdc, ds.dsBm.bmBits); + } + else + { + // fake a BITMAPINFO w/o bits, just the palette info + wxCharBuffer bmi(sizeof(BITMAPINFO) + (biClrUsed - 1)*sizeof(RGBQUAD)); + BITMAPINFO *pBmi = (BITMAPINFO *)bmi.data(); + MemoryHDC hDC; + // get the colour table + SelectInHDC sDC(hDC, m_handle); + ::GetDIBColorTable(hDC, 0, biClrUsed, pBmi->bmiColors); + memcpy(&pBmi->bmiHeader, &ds.dsBmih, ds.dsBmih.biSize); + + return ConvertToBitmap(pBmi, hdc, ds.dsBm.bmBits); + } } /* static */ @@ -591,6 +615,8 @@ wxPalette *wxDIB::CreatePalette() const return NULL; } + MemoryHDC hDC; + // LOGPALETTE struct has only 1 element in palPalEntry array, we're // going to have biClrUsed of them so add necessary space LOGPALETTE *pPalette = (LOGPALETTE *) @@ -601,8 +627,11 @@ wxPalette *wxDIB::CreatePalette() const pPalette->palVersion = 0x300; // magic number, not in docs but works pPalette->palNumEntries = (WORD)biClrUsed; - // and the colour table (it starts right after the end of the header) - const RGBQUAD *pRGB = (RGBQUAD *)((char *)&ds.dsBmih + ds.dsBmih.biSize); + // and the colour table + wxCharBuffer rgb(sizeof(RGBQUAD) * biClrUsed); + RGBQUAD *pRGB = (RGBQUAD*)rgb.data(); + SelectInHDC(hDC, m_handle); + ::GetDIBColorTable(hDC, 0, biClrUsed, pRGB); for ( DWORD i = 0; i < biClrUsed; i++, pRGB++ ) { pPalette->palPalEntry[i].peRed = pRGB->rgbRed; -- 2.45.2