X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f38924e863cd44e2abd49d20d201d72aa773c51e..fb743cab53102c1d2d636acd173112233835f3f7:/src/mac/carbon/bitmap.cpp?ds=sidebyside diff --git a/src/mac/carbon/bitmap.cpp b/src/mac/carbon/bitmap.cpp index c22d1b7821..16d4ea6873 100644 --- a/src/mac/carbon/bitmap.cpp +++ b/src/mac/carbon/bitmap.cpp @@ -16,10 +16,10 @@ #ifndef WX_PRECOMP #include "wx/log.h" #include "wx/dcmemory.h" + #include "wx/icon.h" + #include "wx/image.h" #endif -#include "wx/icon.h" -#include "wx/image.h" #include "wx/metafile.h" #include "wx/xpmdecod.h" @@ -27,7 +27,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject) IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject) -IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject) #ifdef __DARWIN__ #include @@ -165,8 +164,8 @@ wxBitmapRefData::wxBitmapRefData( int w , int h , int d ) bool wxBitmapRefData::Create( int w , int h , int d ) { - m_width = w ; - m_height = h ; + m_width = wxMax(1, w); + m_height = wxMax(1, h); m_depth = d ; m_bytesPerRow = w * 4 ; @@ -397,7 +396,7 @@ IconRef wxBitmapRefData::GetIconRef() SetIconFamilyData( iconFamily, 'PICT' , (Handle) pic ) ; } // transform into IconRef -#ifdef __WXMAC_OSX__ +#if defined( __WXMAC_OSX__ ) && MAC_OS_X_VERSION_MAX_ALLOWED > 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 ); @@ -552,16 +551,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 @@ -812,7 +833,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 ; @@ -842,7 +863,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); } @@ -852,16 +873,6 @@ wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type) LoadFile(filename, type); } -wxBitmap::wxBitmap(const char **bits) -{ - (void) CreateFromXpm(bits); -} - -wxBitmap::wxBitmap(char **bits) -{ - (void) CreateFromXpm((const char **)bits); -} - void * wxBitmap::GetRawAccess() const { wxCHECK_MSG( Ok() , NULL , wxT("invalid bitmap") ) ; @@ -883,24 +894,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 { @@ -1015,7 +1008,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(); @@ -1225,7 +1218,7 @@ bool wxBitmap::SaveFile( const wxString& filename, return success; } -bool wxBitmap::Ok() const +bool wxBitmap::IsOk() const { return (M_BITMAPDATA && M_BITMAPDATA->Ok()); } @@ -1536,25 +1529,7 @@ WXHBITMAP wxMask::GetHBITMAP() const // wxBitmapHandler // ---------------------------------------------------------------------------- -wxBitmapHandler::~wxBitmapHandler() -{ -} - -bool wxBitmapHandler::Create(wxBitmap *bitmap, void *data, long type, int width, int height, int depth) -{ - return false; -} - -bool wxBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags, - int desiredWidth, int desiredHeight) -{ - return false; -} - -bool wxBitmapHandler::SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette) -{ - return false; -} +IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler, wxBitmapHandlerBase) // ---------------------------------------------------------------------------- // Standard Handlers