Implemented loading 256-color bitmaps.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34726 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Mattia Barbon
2005-06-21 20:17:42 +00:00
parent 688bdfe9d1
commit 146dcf3e22

View File

@@ -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;