#endif
m_isDIB =
- m_hasAlpha = FALSE;
+ m_hasAlpha = false;
}
wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData& data)
wxASSERT_MSG( !data.m_isDIB,
_T("can't copy bitmap locked for raw access!") );
- m_isDIB = FALSE;
+ m_isDIB = false;
m_hasAlpha = data.m_hasAlpha;
}
UnRef();
if ( !cursor.Ok() )
- return FALSE;
+ return false;
return CopyFromIconOrCursor(cursor);
}
UnRef();
if ( !icon.Ok() )
- return FALSE;
+ return false;
return CopyFromIconOrCursor(icon);
}
bool wxBitmap::CopyFromDIB(const wxDIB& dib)
{
- wxCHECK_MSG( dib.IsOk(), FALSE, _T("invalid DIB in CopyFromDIB") );
+ wxCHECK_MSG( dib.IsOk(), false, _T("invalid DIB in CopyFromDIB") );
#ifdef SOMETIMES_USE_DIB
HBITMAP hbitmap = dib.CreateDDB();
if ( !hbitmap )
- return FALSE;
+ return false;
#else // ALWAYS_USE_DIB
HBITMAP hbitmap = ((wxDIB &)dib).Detach(); // const_cast
#endif // SOMETIMES_USE_DIB/ALWAYS_USE_DIB
delete palette;
#endif // wxUSE_PALETTE
- return TRUE;
+ return true;
}
#endif // NEVER_USE_DIB
for ( int bits = 0; bits < 8; bits++)
{
reversed <<= 1;
- reversed |= (val & 0x01);
+ reversed |= (unsigned char)(val & 0x01);
val >>= 1;
}
*dst++ = reversed;
}
// Create from XPM data
-#if wxUSE_IMAGE && wxUSE_XPM
bool wxBitmap::CreateFromXpm(const char **data)
-#else
-bool wxBitmap::CreateFromXpm(const char **WXUNUSED(data))
-#endif
{
#if wxUSE_IMAGE && wxUSE_XPM
Init();
- wxCHECK_MSG( data != NULL, FALSE, wxT("invalid bitmap data") )
+ wxCHECK_MSG( data != NULL, false, wxT("invalid bitmap data") )
wxXPMDecoder decoder;
wxImage img = decoder.ReadData(data);
- wxCHECK_MSG( img.Ok(), FALSE, wxT("invalid bitmap data") )
+ wxCHECK_MSG( img.Ok(), false, wxT("invalid bitmap data") )
*this = wxBitmap(img);
- return TRUE;
+ return true;
#else
- return FALSE;
+ wxUnusedVar(data);
+ return false;
#endif
}
bool wxBitmap::Create(int width, int height, const wxDC& dc)
{
- wxCHECK_MSG( dc.Ok(), FALSE, _T("invalid HDC in wxBitmap::Create()") );
+ wxCHECK_MSG( dc.Ok(), false, _T("invalid HDC in wxBitmap::Create()") );
return DoCreate(width, height, -1, dc.GetHDC());
}
wxDIB dib(w, h, d);
if ( !dib.IsOk() )
- return FALSE;
+ return false;
// don't delete the DIB section in dib object dtor
hbmp = dib.Detach();
- GetBitmapData()->m_isDIB = TRUE;
+ GetBitmapData()->m_isDIB = true;
GetBitmapData()->m_depth = d;
}
else // create a DDB
if (hBitmap == NULL)
{
::ReleaseDC(NULL, hScreenDC);
- return FALSE;
+ return false;
}
HDC hMemDC = ::CreateCompatibleDC(hScreenDC);
if (!hMaskBitmap)
{
- hasMask = FALSE;
+ hasMask = false;
}
else
{
hOldMaskBitmap = ::SelectObject( hMaskDC, hMaskBitmap);
}
#else
- hasMask = FALSE;
+ hasMask = false;
#endif
}
SetPalette(image.GetPalette());
#endif // wxUSE_PALETTE
- return TRUE;
+ return true;
}
wxImage wxBitmap::ConvertToImage() const
bool wxBitmap::CreateFromImage(const wxImage& image, const wxDC& dc)
{
- wxCHECK_MSG( dc.Ok(), FALSE,
+ wxCHECK_MSG( dc.Ok(), false,
_T("invalid HDC in wxBitmap::CreateFromImage()") );
return CreateFromImage(image, -1, dc.GetHDC());
bool wxBitmap::CreateFromImage(const wxImage& image, int depth, WXHDC hdc)
{
- wxCHECK_MSG( image.Ok(), FALSE, wxT("invalid image") );
+ wxCHECK_MSG( image.Ok(), false, wxT("invalid image") );
UnRef();
wxDIB dib(image);
if ( !dib.IsOk() )
- return FALSE;
+ return false;
// store the bitmap parameters
// don't delete the DIB section in dib object dtor
hbitmap = dib.Detach();
- refData->m_isDIB = TRUE;
+ refData->m_isDIB = true;
refData->m_depth = dib.GetDepth();
}
#ifndef ALWAYS_USE_DIB
// finally also set the mask if we have one
if ( image.HasMask() )
{
- SetMask(new wxMask(*this, wxColour(image.GetMaskRed(),
- image.GetMaskGreen(),
- image.GetMaskBlue())));
+ const size_t len = 2*((w+15)/16);
+ BYTE *src = image.GetData();
+ BYTE *data = new BYTE[h*len];
+ memset(data, 0, h*len);
+ BYTE r = image.GetMaskRed(),
+ g = image.GetMaskGreen(),
+ b = image.GetMaskBlue();
+ BYTE *dst = data;
+ for ( int y = 0; y < h; y++, dst += len )
+ {
+ BYTE *dstLine = dst;
+ BYTE mask = 0x80;
+ for ( int x = 0; x < w; x++, src += 3 )
+ {
+ if (src[0] != r || src[1] != g || src[2] != b)
+ *dstLine |= mask;
+
+ if ( (mask >>= 1) == 0 )
+ {
+ dstLine++;
+ mask = 0x80;
+ }
+ }
+ }
+
+ hbitmap = ::CreateBitmap(w, h, 1, 1, data);
+ if ( !hbitmap )
+ {
+ wxLogLastError(_T("CreateBitmap(mask)"));
+ }
+ else
+ {
+ SetMask(new wxMask((WXHBITMAP)hbitmap));
+ }
+
+ delete data;
}
- return TRUE;
+ return true;
}
wxImage wxBitmap::ConvertToImage() const
{
*this = wxBitmap(image);
- return TRUE;
+ return true;
}
}
#endif // wxUSE_IMAGE
- return FALSE;
+ return false;
}
bool wxBitmap::Create(void *data, long type, int width, int height, int depth)
{
wxLogDebug(wxT("Failed to create bitmap: no bitmap handler for type %ld defined."), type);
- return FALSE;
+ return false;
}
m_refData = new wxBitmapRefData;
}
#endif // wxUSE_IMAGE
- return FALSE;
+ return false;
}
// ----------------------------------------------------------------------------
(rect.y+rect.height <= GetHeight()),
wxNullBitmap, wxT("Invalid bitmap or bitmap region") );
- wxBitmap ret( rect.width, rect.height );
+ wxBitmap ret( rect.width, rect.height, GetDepth() );
wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") );
#ifndef __WXMICROWIN__
- // TODO: copy alpha channel data if any
+ // handle alpha channel, if any
+ if (HasAlpha())
+ ret.UseAlpha();
// copy bitmap data
MemoryHDC dcSrc,
data.m_height = h;
// remember that DIBs are stored in top to bottom order!
- const LONG bytesPerRow = ds.dsBm.bmWidthBytes;
+ // (We can't just use ds.dsBm.bmWidthBytes here, because it isn't always a
+ // multiple of 2, as required by the documentation. So we use the official
+ // formula, which we already use elsewhere.)
+ const LONG bytesPerRow =
+ wxDIB::GetLineSize(ds.dsBm.bmWidth, ds.dsBm.bmBitsPixel);
data.m_stride = -bytesPerRow;
char *bits = (char *)ds.dsBm.bmBits;
if ( !Ok() )
return;
- // the cast is ugly but we can't do without it and without making this
- // function template (and hence inline) unfortunately
- typedef wxPixelData<wxBitmap, wxAlphaPixelFormat> PixelData;
- PixelData& data = (PixelData &)dataBase;
-
- if ( !data )
+ if ( !&dataBase )
{
// invalid data, don't crash -- but don't assert neither as we're
// called automatically from wxPixelDataBase dtor and so there is no
return;
}
- if ( GetBitmapData()->m_hasAlpha )
- {
- // AlphaBlend() wants to have premultiplied source alpha but
- // wxRawBitmap API uses normal, not premultiplied, colours, so adjust
- // them here now
- PixelData::Iterator p(data);
-
- const int w = data.GetWidth();
- const int h = data.GetHeight();
-
- for ( int y = 0; y < h; y++ )
- {
- PixelData::Iterator rowStart = p;
-
- for ( int x = 0; x < w; x++ )
- {
- const unsigned alpha = p.Alpha();
-
- p.Red() = (p.Red() * alpha + 127) / 255;
- p.Blue() = (p.Blue() * alpha + 127) / 255;
- p.Green() = (p.Green() * alpha + 127) / 255;
-
- ++p;
- }
-
- p = rowStart;
- p.OffsetY(data, 1);
- }
- }
-
// if we're a DDB we need to convert DIB back to DDB now to make the
// changes made via raw bitmap access effective
if ( !GetBitmapData()->m_isDIB )
bool wxMask::Create(const wxBitmap& bitmap)
{
#ifndef __WXMICROWIN__
- wxCHECK_MSG( bitmap.Ok() && bitmap.GetDepth() == 1, FALSE,
+ wxCHECK_MSG( bitmap.Ok() && bitmap.GetDepth() == 1, false,
_T("can't create mask from invalid or not monochrome bitmap") );
if ( m_maskBitmap )
DeleteDC(srcDC);
SelectObject(destDC, 0);
DeleteDC(destDC);
- return TRUE;
+ return true;
#else
- return FALSE;
+ wxUnusedVar(bitmap);
+ return false;
#endif
}
}
#endif // wxUSE_PALETTE
- return FALSE;
+ return false;
}
// Create a mask from a bitmap and a colour indicating
bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
{
#ifndef __WXMICROWIN__
- wxCHECK_MSG( bitmap.Ok(), FALSE, _T("invalid bitmap in wxMask::Create") );
+ wxCHECK_MSG( bitmap.Ok(), false, _T("invalid bitmap in wxMask::Create") );
if ( m_maskBitmap )
{
wxLogLastError(wxT("CreateCompatibleDC"));
}
- bool ok = TRUE;
+ bool ok = true;
// SelectObject() will fail
wxASSERT_MSG( !bitmap.GetSelectedInto(),
{
wxLogLastError(wxT("SelectObject"));
- ok = FALSE;
+ ok = false;
}
HGDIOBJ hbmpDstOld = ::SelectObject(destDC, (HBITMAP)m_maskBitmap);
{
wxLogLastError(wxT("SelectObject"));
- ok = FALSE;
+ ok = false;
}
if ( ok )
return ok;
#else // __WXMICROWIN__
- return FALSE;
+ wxUnusedVar(bitmap);
+ wxUnusedVar(colour);
+ return false;
#endif // __WXMICROWIN__/!__WXMICROWIN__
}
{
wxBitmap *bitmap = wxDynamicCast(image, wxBitmap);
- return bitmap ? Create(bitmap, data, flags, width, height, depth) : FALSE;
+ return bitmap ? Create(bitmap, data, flags, width, height, depth) : false;
}
bool wxBitmapHandler::Load(wxGDIImage *image,
{
wxBitmap *bitmap = wxDynamicCast(image, wxBitmap);
- return bitmap ? LoadFile(bitmap, name, flags, width, height) : FALSE;
+ return bitmap ? LoadFile(bitmap, name, flags, width, height) : false;
}
bool wxBitmapHandler::Save(wxGDIImage *image,
{
wxBitmap *bitmap = wxDynamicCast(image, wxBitmap);
- return bitmap ? SaveFile(bitmap, name, type) : FALSE;
+ return bitmap ? SaveFile(bitmap, name, type) : false;
}
bool wxBitmapHandler::Create(wxBitmap *WXUNUSED(bitmap),
int WXUNUSED(height),
int WXUNUSED(depth))
{
- return FALSE;
+ return false;
}
bool wxBitmapHandler::LoadFile(wxBitmap *WXUNUSED(bitmap),
int WXUNUSED(desiredWidth),
int WXUNUSED(desiredHeight))
{
- return FALSE;
+ return false;
}
bool wxBitmapHandler::SaveFile(wxBitmap *WXUNUSED(bitmap),
int WXUNUSED(type),
const wxPalette *WXUNUSED(palette))
{
- return FALSE;
+ return false;
}
// ----------------------------------------------------------------------------
*lpDIBHeader = lpDIBheader;
- return TRUE;
+ return true;
}
void wxFreeDIB(LPBITMAPINFO lpDIBHeader)
HICON wxBitmapToHICON(const wxBitmap& bmp)
{
- return wxBitmapToIconOrCursor(bmp, TRUE, 0, 0);
+ return wxBitmapToIconOrCursor(bmp, true, 0, 0);
}
HCURSOR wxBitmapToHCURSOR(const wxBitmap& bmp, int hotSpotX, int hotSpotY)
{
- return (HCURSOR)wxBitmapToIconOrCursor(bmp, FALSE, hotSpotX, hotSpotY);
+ return (HCURSOR)wxBitmapToIconOrCursor(bmp, false, hotSpotX, hotSpotY);
}
HBITMAP wxInvertMask(HBITMAP hbmpMask, int w, int h)
// Deselect objects
SelectObject(hdcSrc,srcTmp);
SelectObject(hdcDst,dstTmp);
-
+
::DeleteDC(hdcSrc);
::DeleteDC(hdcDst);