X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/42f8298f6f42d5d63bb3caf65682b7d9d9f8b702..19311d4e7c43a3f6243bf805c164fd76cada0386:/src/mac/carbon/bitmap.cpp diff --git a/src/mac/carbon/bitmap.cpp b/src/mac/carbon/bitmap.cpp index 3e1761ba73..3a2d1991b7 100644 --- a/src/mac/carbon/bitmap.cpp +++ b/src/mac/carbon/bitmap.cpp @@ -51,33 +51,54 @@ IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject ) // we don't dare premultiplied alpha yet #define wxMAC_USE_PREMULTIPLIED_ALPHA 0 +#if wxUSE_BMPBUTTON + void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType ) { memset( info , 0 , sizeof(ControlButtonContentInfo) ) ; if ( bitmap.Ok() ) { - wxBitmapRefData * bmap = (wxBitmapRefData*) ( bitmap.GetRefData()) ; + wxBitmapRefData * bmap = bitmap.GetBitmapData() ; if ( bmap == NULL ) return ; - if ( bmap->HasNativeSize() ) + if ( ( bmap->HasNativeSize() && forceType == 0 ) || forceType == kControlContentIconRef ) { + wxBitmap scaleBmp ; + + wxBitmapRefData* bmp = bmap ; + + if ( !bmap->HasNativeSize() ) + { + // as PICT conversion will only result in a 16x16 icon, let's attempt + // a few scales for better results + + int w = bitmap.GetWidth() ; + int h = bitmap.GetHeight() ; + int sz = wxMax( w , h ) ; + if ( sz == 24 || sz == 64) + { + scaleBmp = wxBitmap( bitmap.ConvertToImage().Scale( w * 2 , h * 2 ) ) ; + bmp = scaleBmp.GetBitmapData() ; + } + } + info->contentType = kControlContentIconRef ; - info->u.iconRef = bmap->GetIconRef() ; + info->u.iconRef = bmp->GetIconRef() ; + AcquireIconRef( info->u.iconRef ) ; } +#if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 + else if ( forceType == kControlContentCGImageRef ) + { + info->contentType = kControlContentCGImageRef ; + info->u.imageRef = (CGImageRef) bmap->CGImageCreate() ; + } +#endif else { info->contentType = kControlContentPictHandle ; info->u.picture = bmap->GetPictHandle() ; } -#if wxMAC_USE_CORE_GRAPHICS - /* - // only on 10.4 more controls will accept a CGImage - - info->contentType = kControlContentCGImageRef ; - info->u.imageRef = (CGImageRef) bmap->CGImageCreate() ; - */ -#endif } } @@ -85,11 +106,11 @@ void wxMacReleaseBitmapButton( ControlButtonContentInfo*info ) { if ( info->contentType == kControlContentIconRef ) { - // as the bitmap is now the owner, no need to release here + ReleaseIconRef( info->u.iconRef ) ; } else if ( info->contentType == kControlContentPictHandle ) { - // owned by the bitma, no release here + // owned by the bitmap, no release here } #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 else if ( info->contentType == kControlContentCGImageRef ) @@ -103,6 +124,8 @@ void wxMacReleaseBitmapButton( ControlButtonContentInfo*info ) } } +#endif //wxUSE_BMPBUTTON + #define M_BITMAPDATA ((wxBitmapRefData *)m_refData) void wxBitmapRefData::Init() @@ -350,7 +373,10 @@ IconRef wxBitmapRefData::GetIconRef() // transform into IconRef static int iconCounter = 2 ; - OSStatus err = RegisterIconRefFromIconFamily( 'WXNG' , (OSType) iconCounter, iconFamily, &m_iconRef ) ; +#ifdef __WXDEBUG__ + OSStatus err = +#endif + RegisterIconRefFromIconFamily( 'WXNG' , (OSType) iconCounter, iconFamily, &m_iconRef ) ; wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ; // we have to retain a reference, as Unregister will decrement it AcquireIconRef( m_iconRef ) ; @@ -435,7 +461,7 @@ PicHandle wxBitmapRefData::GetPictHandle() return m_pictHandle ; } -#if wxMAC_USE_CORE_GRAPHICS +#ifdef __WXMAC_OSX__ void wxMacMemoryBufferReleaseProc(void *info, const void *data, size_t size) { wxMemoryBuffer* membuf = (wxMemoryBuffer*) info ; @@ -790,15 +816,19 @@ void wxBitmap::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 } -#if wxMAC_USE_CORE_GRAPHICS +#ifdef __WXMAC_OSX__ WXCGIMAGEREF wxBitmap::CGImageCreate() const { wxCHECK_MSG( Ok(), NULL , wxT("invalid bitmap") ) ; @@ -888,11 +918,13 @@ bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type) } else { +#if wxUSE_IMAGE wxImage loadimage(filename, type); if (loadimage.Ok()) { *this = loadimage; return true; } +#endif } wxLogWarning(wxT("no bitmap handler for type %d defined."), type); return false; @@ -915,6 +947,8 @@ bool wxBitmap::Create(void *data, wxBitmapType type, int width, int height, int return handler->Create(this, data, type, width, height, depth); } +#if wxUSE_IMAGE + wxBitmap::wxBitmap(const wxImage& image, int depth) { wxCHECK_RET( image.Ok(), wxT("invalid image") ) @@ -997,6 +1031,7 @@ wxImage wxBitmap::ConvertToImage() const bool hasAlpha = false ; bool hasMask = false ; + int maskBytesPerRow = 0 ; unsigned char *alpha = NULL ; unsigned char *mask = NULL ; if ( HasAlpha() ) @@ -1008,6 +1043,7 @@ wxImage wxBitmap::ConvertToImage() const { hasMask = true ; mask = (unsigned char*) GetMask()->GetRawAccess() ; + maskBytesPerRow = GetMask()->GetBytesPerRow() ; } if ( hasAlpha ) @@ -1025,8 +1061,9 @@ wxImage wxBitmap::ConvertToImage() const static const int MASK_BLUE = 3; static const int MASK_BLUE_REPLACEMENT = 2; - for (int yy = 0; yy < height; yy++) + for (int yy = 0; yy < height; yy++ , mask += maskBytesPerRow ) { + unsigned char * maskp = mask ; for (int xx = 0; xx < width; xx++) { long color = *((long*) source) ; @@ -1036,7 +1073,7 @@ wxImage wxBitmap::ConvertToImage() const unsigned char b = (color&0x000000FF); if ( hasMask ) { - if ( *mask++ == 0 ) + if ( *maskp++ == 0 ) { if ( r == MASK_RED && g == MASK_GREEN && b == MASK_BLUE ) b = MASK_BLUE_REPLACEMENT ; @@ -1063,6 +1100,7 @@ wxImage wxBitmap::ConvertToImage() const return image; } +#endif //wxUSE_IMAGE bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type, const wxPalette *palette) const @@ -1075,9 +1113,10 @@ bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type, } else { +#if wxUSE_IMAGE wxImage image = ConvertToImage(); - return image.SaveFile(filename, type); +#endif } wxLogWarning(wxT("no bitmap handler for type %d defined."), type);