// under Quartz then content is transformed into a CGImageRef representing the same data
// which can be transferred to the GPU by the OS for fast rendering
+class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
+{
+ friend class WXDLLIMPEXP_FWD_CORE wxIcon;
+ friend class WXDLLIMPEXP_FWD_CORE wxCursor;
+public:
+ wxBitmapRefData(int width , int height , int depth);
+ wxBitmapRefData();
+ wxBitmapRefData(const wxBitmapRefData &tocopy);
+
+ virtual ~wxBitmapRefData();
+
+ void Free();
+ bool Ok() const { return IsOk(); }
+ bool IsOk() const { return m_ok; }
+ void SetOk( bool isOk) { m_ok = isOk; }
+
+ void SetWidth( int width ) { m_width = width; }
+ void SetHeight( int height ) { m_height = height; }
+ void SetDepth( int depth ) { m_depth = depth; }
+
+ int GetWidth() const { return m_width; }
+ int GetHeight() const { return m_height; }
+ int GetDepth() const { return m_depth; }
+
+ void *GetRawAccess() const;
+ void *BeginRawAccess();
+ void EndRawAccess();
+
+ bool HasAlpha() const { return m_hasAlpha; }
+ void UseAlpha( bool useAlpha );
+
+public:
+#if wxUSE_PALETTE
+ wxPalette m_bitmapPalette;
+#endif // wxUSE_PALETTE
+
+ wxMask * m_bitmapMask; // Optional mask
+ CGImageRef CreateCGImage() const;
+
+ // returns true if the bitmap has a size that
+ // can be natively transferred into a true icon
+ // if no is returned GetIconRef will still produce
+ // an icon but it will be generated via a PICT and
+ // rescaled to 16 x 16
+ bool HasNativeSize();
+
+ // caller should increase ref count if needed longer
+ // than the bitmap exists
+ IconRef GetIconRef();
+
+ // returns a Pict from the bitmap content
+ PicHandle GetPictHandle();
+
+ CGContextRef GetBitmapContext() const;
+
+ int GetBytesPerRow() const { return m_bytesPerRow; }
+ private :
+ bool Create(int width , int height , int depth);
+ void Init();
+
+ int m_width;
+ int m_height;
+ int m_bytesPerRow;
+ int m_depth;
+ bool m_hasAlpha;
+ wxMemoryBuffer m_memBuf;
+ int m_rawAccessCount;
+ bool m_ok;
+ mutable CGImageRef m_cgImageRef;
+
+ IconRef m_iconRef;
+ PicHandle m_pictHandle;
+
+ CGContextRef m_hBitmap;
+};
+
+
#define wxMAC_USE_PREMULTIPLIED_ALPHA 1
static const int kBestByteAlignement = 16;
static const int kMaskBytesPerPixel = 1;
return (((rawBytes)+kBestByteAlignement-1) & ~(kBestByteAlignement-1) );
}
-#if wxUSE_BMPBUTTON
+#if wxUSE_GUI
+
+// this is used for more controls than just the wxBitmap button, also for notebooks etc
void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType )
{
else if ( forceType == kControlContentCGImageRef )
{
info->contentType = kControlContentCGImageRef ;
- info->u.imageRef = (CGImageRef) bmap->CGImageCreate() ;
+ info->u.imageRef = (CGImageRef) bmap->CreateCGImage() ;
}
else
{
wxBitmapRefData * bmap = bitmap.GetBitmapData() ;
if ( bmap == NULL )
return NULL ;
- return (CGImageRef) bmap->CGImageCreate();
+ return (CGImageRef) bmap->CreateCGImage();
}
void wxMacReleaseBitmapButton( ControlButtonContentInfo*info )
{
// QT does not correctly export the mask
// TODO if we get around to it create a synthetic PICT with the CopyBits and Mask commands
- CGImageRef imageRef = CGImageCreate();
+ CGImageRef imageRef = CreateCGImage();
err = GraphicsExportSetInputCGImage( exporter, imageRef );
err = GraphicsExportSetOutputHandle(exporter, (Handle)m_pictHandle);
err = GraphicsExportDoExport(exporter, NULL);
return m_pictHandle ;
}
-void wxMacMemoryBufferReleaseProc(void *info, const void *data, size_t WXUNUSED(size))
-{
- wxMemoryBuffer* membuf = (wxMemoryBuffer*) info ;
-
- wxASSERT( data == membuf->GetData() ) ;
-
- delete membuf ;
-}
-
-CGImageRef wxBitmapRefData::CGImageCreate() const
+CGImageRef wxBitmapRefData::CreateCGImage() const
{
wxASSERT( m_ok ) ;
wxASSERT( m_rawAccessCount >= 0 ) ;
int w = m_width ;
int h = m_height ;
CGImageAlphaInfo alphaInfo = kCGImageAlphaNoneSkipFirst ;
- wxMemoryBuffer* membuf = NULL ;
+ wxMemoryBuffer membuf;
if ( m_bitmapMask )
{
alphaInfo = kCGImageAlphaFirst ;
- membuf = new wxMemoryBuffer( imageSize ) ;
- memcpy( membuf->GetData() , dataBuffer , imageSize ) ;
+ unsigned char *destalphastart = (unsigned char*) membuf.GetWriteBuf( imageSize ) ;
+ memcpy( destalphastart , dataBuffer , imageSize ) ;
unsigned char *sourcemaskstart = (unsigned char *) m_bitmapMask->GetRawAccess() ;
int maskrowbytes = m_bitmapMask->GetBytesPerRow() ;
- unsigned char *destalphastart = (unsigned char *) membuf->GetData() ;
for ( int y = 0 ; y < h ; ++y , destalphastart += m_bytesPerRow, sourcemaskstart += maskrowbytes)
{
unsigned char *sourcemask = sourcemaskstart ;
*destalpha = 0xFF - *sourcemask ;
}
}
+ membuf.UngetWriteBuf( imageSize );
}
else
{
#endif
}
- membuf = new wxMemoryBuffer( m_memBuf ) ;
+ membuf = m_memBuf;
}
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() ;
+ // TODO CHECK ALIGNMENT
+ wxMemoryBuffer maskBuf;
+ unsigned char * maskBufData = (unsigned char*) maskBuf.GetWriteBuf( m_width * m_height );
+ 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];
+ size_t i = 0;
+ for( int y = 0 ; y < m_height ; bufData+= m_bytesPerRow, ++y )
+ {
+ unsigned char *bufDataIter = bufData+3;
+ for ( int x = 0 ; x < m_width ; bufDataIter += 4, ++x, ++i )
+ {
+ maskBufData[i] = *bufDataIter;
+ }
+ }
+ maskBuf.UngetWriteBuf( m_width * m_height );
+
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 ;
+ wxMacCGDataProviderCreateWithMemoryBuffer( maskBuf );
image = ::CGImageMaskCreate( w, h, 8, 8, m_width , dataProvider, NULL, false );
}
else
{
CGColorSpaceRef colorSpace = wxMacGetGenericRGBColorSpace();
- dataProvider =
- CGDataProviderCreateWithData(
- membuf , (const void *)membuf->GetData() , imageSize,
- wxMacMemoryBufferReleaseProc );
+ dataProvider = wxMacCGDataProviderCreateWithMemoryBuffer( membuf );
image =
::CGImageCreate(
w, h, 8 , 32 , m_bytesPerRow , colorSpace, alphaInfo ,
M_BITMAPDATA->EndRawAccess() ;
}
-WXCGIMAGEREF wxBitmap::CGImageCreate() const
+CGImageRef wxBitmap::CreateCGImage() const
+{
+ wxCHECK_MSG( Ok(), NULL , wxT("invalid bitmap") ) ;
+
+ return M_BITMAPDATA->CreateCGImage() ;
+}
+
+IconRef wxBitmap::GetIconRef() const
{
wxCHECK_MSG( Ok(), NULL , wxT("invalid bitmap") ) ;
+
+ return M_BITMAPDATA->GetIconRef() ;
+}
- return M_BITMAPDATA->CGImageCreate() ;
+IconRef wxBitmap::CreateIconRef() const
+{
+ IconRef icon = GetIconRef();
+ verify_noerr( AcquireIconRef(icon) );
+ return icon;
}
wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
// Standard Handlers
// ----------------------------------------------------------------------------
+#ifndef __LP64__
+
class WXDLLEXPORT wxPICTResourceHandler: public wxBitmapHandler
{
DECLARE_DYNAMIC_CLASS(wxPICTResourceHandler)
return false ;
}
+#endif
void wxBitmap::InitStandardHandlers()
{
+#ifndef __LP64__
AddHandler( new wxPICTResourceHandler ) ;
+#endif
AddHandler( new wxICONResourceHandler ) ;
}