X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f288c87b3df1e24c5e1b3727c539744e0710c4c1..9b7835a516d1acdeb007bed0c5bb80cae1643416:/src/mac/carbon/bitmap.cpp?ds=sidebyside diff --git a/src/mac/carbon/bitmap.cpp b/src/mac/carbon/bitmap.cpp index 5abc83eb77..c1106bdfb0 100644 --- a/src/mac/carbon/bitmap.cpp +++ b/src/mac/carbon/bitmap.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: bitmap.cpp +// Name: src/mac/carbon/bitmap.cpp // Purpose: wxBitmap // Author: Stefan Csomor // Modified by: @@ -12,9 +12,14 @@ #include "wx/wxprec.h" #include "wx/bitmap.h" -#include "wx/icon.h" -#include "wx/log.h" -#include "wx/image.h" + +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/dcmemory.h" + #include "wx/icon.h" + #include "wx/image.h" +#endif + #include "wx/metafile.h" #include "wx/xpmdecod.h" @@ -22,7 +27,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) -IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject) #ifdef __DARWIN__ #include @@ -31,7 +35,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject) #endif #include "wx/mac/uma.h" -#include "wx/dcmemory.h" // Implementation Notes // -------------------- @@ -90,8 +93,10 @@ void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bi #endif else { +#ifndef __LP64__ info->contentType = kControlContentPictHandle ; info->u.picture = bmap->GetPictHandle() ; +#endif } } } @@ -148,6 +153,28 @@ void wxBitmapRefData::Init() m_hasAlpha = false; } +wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData &tocopy) +{ + Init(); + Create(tocopy.m_width, tocopy.m_height, tocopy.m_depth); + + if (tocopy.m_bitmapMask) + m_bitmapMask = new wxMask(*tocopy.m_bitmapMask); + + unsigned char* dest = (unsigned char*)GetRawAccess(); + unsigned char* source = (unsigned char*)tocopy.GetRawAccess(); + size_t numbytes = tocopy.m_width * tocopy.m_height * 4; + + for (size_t i=0; i MAC_OS_X_VERSION_10_2 + // cleaner version existing from 10.3 upwards + HLock((Handle) iconFamily); + OSStatus err = GetIconRefFromIconFamilyPtr( *iconFamily, GetHandleSize((Handle) iconFamily), &m_iconRef ); + HUnlock((Handle) iconFamily); + wxASSERT_MSG( err == noErr , wxT("Error when constructing icon ref") ); +#else static int iconCounter = 2 ; OSStatus err = RegisterIconRefFromIconFamily( 'WXNG' , (OSType) iconCounter, iconFamily, &m_iconRef ) ; @@ -403,8 +440,9 @@ IconRef wxBitmapRefData::GetIconRef() // we have to retain a reference, as Unregister will decrement it AcquireIconRef( m_iconRef ) ; UnregisterIconRef( 'WXNG' , (OSType) iconCounter ) ; - DisposeHandle( (Handle) iconFamily ) ; ++iconCounter ; +#endif + DisposeHandle( (Handle) iconFamily ) ; } return m_iconRef ; @@ -414,6 +452,7 @@ PicHandle wxBitmapRefData::GetPictHandle() { if ( m_pictHandle == NULL ) { +#ifndef __LP64__ CGrafPtr origPort = NULL ; GDHandle origDev = NULL ; GWorldPtr wp = NULL ; @@ -483,6 +522,7 @@ PicHandle wxBitmapRefData::GetPictHandle() SetGWorld( origPort , origDev ) ; if ( clipRgn ) DisposeRgn( clipRgn ) ; +#endif } return m_pictHandle ; @@ -542,16 +582,38 @@ CGImageRef wxBitmapRefData::CGImageCreate() const membuf = new wxMemoryBuffer( m_memBuf ) ; } - - CGColorSpaceRef colorSpace = wxMacGetGenericRGBColorSpace(); - CGDataProviderRef dataProvider = - CGDataProviderCreateWithData( - membuf , (const void *)membuf->GetData() , imageSize, - wxMacMemoryBufferReleaseProc ); - image = + + CGDataProviderRef dataProvider = NULL ; + if ( m_depth == 1 ) + { + wxMemoryBuffer* maskBuf = new wxMemoryBuffer( m_width * m_height ); + unsigned char * maskBufData = (unsigned char *) maskBuf->GetData(); + unsigned char * bufData = (unsigned char *) membuf->GetData() ; + // copy one color component + for( int i = 0 ; i < m_width * m_height ; ++i ) + maskBufData[i] = bufData[i*4+3]; + dataProvider = + CGDataProviderCreateWithData( + maskBuf , (const void *) maskBufData , m_width * m_height, + wxMacMemoryBufferReleaseProc ); + // as we are now passing the mask buffer to the data provider, we have + // to release the membuf ourselves + delete membuf ; + + image = ::CGImageMaskCreate( w, h, 8, 8, m_width , dataProvider, NULL, false ); + } + else + { + CGColorSpaceRef colorSpace = wxMacGetGenericRGBColorSpace(); + dataProvider = + CGDataProviderCreateWithData( + membuf , (const void *)membuf->GetData() , imageSize, + wxMacMemoryBufferReleaseProc ); + image = ::CGImageCreate( w, h, 8 , 32 , 4 * m_width , colorSpace, alphaInfo , dataProvider, NULL , false , kCGRenderingIntentDefault ); + } CGDataProviderRelease( dataProvider); } else @@ -643,6 +705,7 @@ void wxBitmapRefData::Free() m_iconRef = NULL ; } +#ifndef __LP64__ if ( m_pictHandle ) { KillPicture( m_pictHandle ) ; @@ -660,7 +723,7 @@ void wxBitmapRefData::Free() DisposeGWorld( MAC_WXHBITMAP(m_hMaskBitmap) ) ; m_hMaskBitmap = NULL ; } - +#endif if (m_bitmapMask) { delete m_bitmapMask; @@ -802,7 +865,7 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits bit = x % 8 ; mask = 1 << bit ; - if ( !(linestart[index] & mask ) ) + if ( linestart[index] & mask ) { *destination++ = 0xFF ; *destination++ = 0 ; @@ -832,7 +895,7 @@ wxBitmap::wxBitmap(int w, int h, int d) (void)Create(w, h, d); } -wxBitmap::wxBitmap(void *data, wxBitmapType type, int width, int height, int depth) +wxBitmap::wxBitmap(const void* data, wxBitmapType type, int width, int height, int depth) { (void) Create(data, type, width, height, depth); } @@ -842,14 +905,14 @@ wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type) LoadFile(filename, type); } -wxBitmap::wxBitmap(const char **bits) +wxObjectRefData* wxBitmap::CreateRefData() const { - (void) CreateFromXpm(bits); + return new wxBitmapRefData; } -wxBitmap::wxBitmap(char **bits) +wxObjectRefData* wxBitmap::CloneRefData(const wxObjectRefData* data) const { - (void) CreateFromXpm((const char **)bits); + return new wxBitmapRefData(*wx_static_cast(const wxBitmapRefData *, data)); } void * wxBitmap::GetRawAccess() const @@ -873,24 +936,6 @@ void wxBitmap::EndRawAccess() M_BITMAPDATA->EndRawAccess() ; } -bool wxBitmap::CreateFromXpm(const char **bits) -{ -#if wxUSE_IMAGE - wxCHECK_MSG( bits != NULL, false, wxT("invalid bitmap data") ) - - wxXPMDecoder decoder; - wxImage img = decoder.ReadData(bits); - wxCHECK_MSG( img.Ok(), false, wxT("invalid bitmap data") ) - - *this = wxBitmap(img); - - return true; -#else - - return false; -#endif -} - #ifdef __WXMAC_OSX__ WXCGIMAGEREF wxBitmap::CGImageCreate() const { @@ -1005,7 +1050,7 @@ bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type) return false; } -bool wxBitmap::Create(void *data, wxBitmapType type, int width, int height, int depth) +bool wxBitmap::Create(const void* data, wxBitmapType type, int width, int height, int depth) { UnRef(); @@ -1027,7 +1072,7 @@ 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( image.Ok(), wxT("invalid image") ); // width and height of the device-dependent bitmap int width = image.GetWidth(); @@ -1215,7 +1260,7 @@ bool wxBitmap::SaveFile( const wxString& filename, return success; } -bool wxBitmap::Ok() const +bool wxBitmap::IsOk() const { return (M_BITMAPDATA && M_BITMAPDATA->Ok()); } @@ -1241,17 +1286,6 @@ int wxBitmap::GetDepth() const return M_BITMAPDATA->GetDepth(); } -#if WXWIN_COMPATIBILITY_2_4 -int wxBitmap::GetQuality() const -{ - return 0; -} - -void wxBitmap::SetQuality(int WXUNUSED(quality)) -{ -} -#endif - wxMask *wxBitmap::GetMask() const { wxCHECK_MSG( Ok(), (wxMask *) NULL, wxT("invalid bitmap") ); @@ -1268,33 +1302,25 @@ bool wxBitmap::HasAlpha() const void wxBitmap::SetWidth(int w) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - + AllocExclusive(); M_BITMAPDATA->SetWidth(w); } void wxBitmap::SetHeight(int h) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - + AllocExclusive(); M_BITMAPDATA->SetHeight(h); } void wxBitmap::SetDepth(int d) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - + AllocExclusive(); M_BITMAPDATA->SetDepth(d); } void wxBitmap::SetOk(bool isOk) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - + AllocExclusive(); M_BITMAPDATA->SetOk(isOk); } @@ -1308,18 +1334,14 @@ wxPalette *wxBitmap::GetPalette() const void wxBitmap::SetPalette(const wxPalette& palette) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - + AllocExclusive(); M_BITMAPDATA->m_bitmapPalette = palette ; } #endif // wxUSE_PALETTE void wxBitmap::SetMask(wxMask *mask) { - if (!M_BITMAPDATA) - m_refData = new wxBitmapRefData; - + AllocExclusive(); // Remove existing mask if there is one. delete M_BITMAPDATA->m_bitmapMask; @@ -1340,6 +1362,26 @@ wxMask::wxMask() Init() ; } +wxMask::wxMask(const wxMask &tocopy) +{ + Init(); + + m_bytesPerRow = tocopy.m_bytesPerRow; + m_width = tocopy.m_width; + m_height = tocopy.m_height; + + size_t size = m_bytesPerRow * m_height; + unsigned char* dest = (unsigned char*)m_memBuf.GetWriteBuf( size ); + unsigned char* source = (unsigned char*)tocopy.m_memBuf.GetData(); + for (size_t i=0; iHasAlpha() ) - return; - - wxAlphaPixelData& data = (wxAlphaPixelData&)dataBase; - int w = data.GetWidth(); - int 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; - wxAlphaPixelData::Iterator 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 ) ); + EndRawAccess() ; } void wxBitmap::UseAlpha()