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 */
return NULL;
}
- if ( !ConvertFromBitmap((BITMAPINFO *)(void *)GlobalPtr(hDIB), hbmp) )
+ if ( !ConvertFromBitmap((BITMAPINFO *)(void *)GlobalPtrLock(hDIB), hbmp) )
{
// this really shouldn't happen... it worked the first time, why not
// now?
wxPalette *wxDIB::CreatePalette() const
{
+ // GetDIBColorTable not available in eVC3
+#if defined(_WIN32_WCE) && _WIN32_WCE < 400
+ return NULL;
+#else
wxCHECK_MSG( m_handle, NULL, _T("wxDIB::CreatePalette(): invalid object") );
DIBSECTION ds;
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 *)
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 selectHandle(hDC, m_handle);
+ ::GetDIBColorTable(hDC, 0, biClrUsed, pRGB);
for ( DWORD i = 0; i < biClrUsed; i++, pRGB++ )
{
pPalette->palPalEntry[i].peRed = pRGB->rgbRed;
palette->SetHPALETTE((WXHPALETTE)hPalette);
return palette;
+#endif
}
#endif // wxUSE_PALETTE