X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/091c90b7cb1428a4ebd243a409fa52cbec40b8dd..a2fe01c96d43777db58041ec470e8aaa27f1e3b2:/src/mac/carbon/bitmap.cpp diff --git a/src/mac/carbon/bitmap.cpp b/src/mac/carbon/bitmap.cpp index 8918a44ae6..67ec567512 100644 --- a/src/mac/carbon/bitmap.cpp +++ b/src/mac/carbon/bitmap.cpp @@ -366,6 +366,7 @@ wxBitmapRefData::wxBitmapRefData() m_hPict = NULL ; m_hIcon = NULL ; m_bitmapType = kMacBitmapTypeUnknownType ; + m_hasAlpha = false; } // TODO move this to a public function of Bitmap Ref @@ -444,7 +445,7 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits if ( no_bits == 1 ) { M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ; - MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) = wxMacCreateGWorld( the_width , the_height , no_bits ) ; + M_BITMAPDATA->m_hBitmap = wxMacCreateGWorld( the_width , the_height , no_bits ) ; M_BITMAPDATA->m_ok = (MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) != NULL ) ; CGrafPtr origPort ; @@ -550,7 +551,9 @@ wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const wxBitmapRefData *ref = (wxBitmapRefData *)ret.GetRefData(); ref->m_numColors = M_BITMAPDATA->m_numColors; - ref->m_bitmapPalette = M_BITMAPDATA->m_bitmapPalette; +#if wxUSE_PALETTE + ref->m_bitmapPalette = M_BITMAPDATA->m_bitmapPalette; +#endif // wxUSE_PALETTE ref->m_bitmapType = M_BITMAPDATA->m_bitmapType; // Copy sub region of this bitmap @@ -720,7 +723,6 @@ bool wxBitmap::Create(void *data, wxBitmapType type, int width, int height, int wxBitmap::wxBitmap(const wxImage& image, int depth) { wxCHECK_RET( image.Ok(), wxT("invalid image") ) - wxCHECK_RET( depth == -1, wxT("invalid bitmap depth") ) m_refData = new wxBitmapRefData(); @@ -1030,6 +1032,7 @@ void wxBitmap::SetOk(bool isOk) M_BITMAPDATA->m_ok = isOk; } +#if wxUSE_PALETTE wxPalette *wxBitmap::GetPalette() const { wxCHECK_MSG( Ok(), NULL, wxT("Invalid bitmap GetPalette()") ); @@ -1044,6 +1047,7 @@ void wxBitmap::SetPalette(const wxPalette& palette) M_BITMAPDATA->m_bitmapPalette = palette ; } +#endif // wxUSE_PALETTE void wxBitmap::SetMask(wxMask *mask) { @@ -1051,8 +1055,7 @@ void wxBitmap::SetMask(wxMask *mask) m_refData = new wxBitmapRefData; // Remove existing mask if there is one. - if (M_BITMAPDATA->m_bitmapMask) - delete M_BITMAPDATA->m_bitmapMask; + delete M_BITMAPDATA->m_bitmapMask; M_BITMAPDATA->m_bitmapMask = mask ; } @@ -1150,7 +1153,7 @@ bool wxMask::Create(const wxBitmap& bitmap) wxCHECK_MSG( bitmap.Ok(), false, wxT("Invalid bitmap")); - m_depth = bitmap.GetDepth() ; + m_depth = bitmap.GetDepth() ; m_maskBitmap = wxMacCreateGWorld(bitmap.GetWidth(), bitmap.GetHeight(), bitmap.GetDepth() ); Rect rect = { 0,0, bitmap.GetHeight(), bitmap.GetWidth() }; @@ -1349,14 +1352,11 @@ void *wxBitmap::GetRawData(wxPixelDataBase& data, int bpp) GWorldPtr gworld = MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap); PixMapHandle hPixMap = GetGWorldPixMap(gworld); - wxCHECK_MSG( hPixMap, NULL, _T("failed to get PixMap from GWorld?") ); + wxCHECK_MSG( hPixMap && *hPixMap, NULL, + _T("GetRawData(): failed to get PixMap from GWorld?") ); - if ( (*hPixMap)->pixelSize != bpp ) - { - wxFAIL_MSG( _T("bpp mismatch in GetRawData()") ); - - return NULL; - } + wxCHECK_MSG( (*hPixMap)->pixelSize == bpp, NULL, + _T("GetRawData(): pixel format mismatch") ); if ( !LockPixels(hPixMap) ) { @@ -1369,14 +1369,55 @@ void *wxBitmap::GetRawData(wxPixelDataBase& data, int bpp) data.m_height = GetHeight(); data.m_stride = (*hPixMap)->rowBytes & 0x7fff; + M_BITMAPDATA->m_hasAlpha = false; + return GetPixBaseAddr(hPixMap); } -void wxBitmap::UngetRawData(wxPixelDataBase& data) +void wxBitmap::UngetRawData(wxPixelDataBase& dataBase) { if ( !Ok() ) return; + if ( M_BITMAPDATA->m_hasAlpha ) + { + wxAlphaPixelData& data = (wxAlphaPixelData&)dataBase; + + int w = data.GetWidth(), + h = data.GetHeight(); + + wxBitmap bmpMask(GetWidth(), GetHeight(), 32); + wxAlphaPixelData dataMask(bmpMask, data.GetOrigin(), wxSize(w, h)); + wxAlphaPixelData::Iterator pMask(dataMask), + p(data); + for ( int y = 0; y < h; y++ ) + { + wxAlphaPixelData::Iterator rowStartMask = pMask, + rowStart = p; + + for ( int x = 0; x < w; x++ ) + { + const wxAlphaPixelData::Iterator::ChannelType + alpha = p.Alpha(); + + pMask.Red() = alpha; + pMask.Green() = alpha; + pMask.Blue() = alpha; + + ++p; + ++pMask; + } + + p = rowStart; + p.OffsetY(data, 1); + + pMask = rowStartMask; + pMask.OffsetY(dataMask, 1); + } + + SetMask(new wxMask(bmpMask)); + } + GWorldPtr gworld = MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap); PixMapHandle hPixMap = GetGWorldPixMap(gworld); if ( hPixMap ) @@ -1387,6 +1428,8 @@ void wxBitmap::UngetRawData(wxPixelDataBase& data) void wxBitmap::UseAlpha() { - // nothing to do here so far + // remember that we are using alpha channel, we'll need to create a proper + // mask in UngetRawData() + M_BITMAPDATA->m_hasAlpha = true; }