1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/core/bitmap.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/bitmap.h"
18 #include "wx/dcmemory.h"
23 #include "wx/metafile.h"
24 #include "wx/xpmdecod.h"
26 #include "wx/rawbmp.h"
28 IMPLEMENT_DYNAMIC_CLASS(wxBitmap
, wxGDIObject
)
29 IMPLEMENT_DYNAMIC_CLASS(wxMask
, wxObject
)
32 #include "wx/osx/uma.h"
34 #include "wx/osx/private.h"
37 #ifndef __WXOSX_IPHONE__
38 #include <QuickTime/QuickTime.h>
41 CGColorSpaceRef
wxMacGetGenericRGBColorSpace();
42 CGDataProviderRef
wxMacCGDataProviderCreateWithMemoryBuffer( const wxMemoryBuffer
& buf
);
44 // Implementation Notes
45 // --------------------
47 // we are always working with a 32 bit deep pixel buffer
48 // under QuickDraw its alpha parts are going to be ignored in the GWorld,
49 // therefore we have a separate GWorld there for blitting the mask in
51 // under Quartz then content is transformed into a CGImageRef representing the same data
52 // which can be transferred to the GPU by the OS for fast rendering
54 class WXDLLEXPORT wxBitmapRefData
: public wxGDIRefData
56 friend class WXDLLIMPEXP_FWD_CORE wxIcon
;
57 friend class WXDLLIMPEXP_FWD_CORE wxCursor
;
59 wxBitmapRefData(int width
, int height
, int depth
);
60 wxBitmapRefData(CGImageRef image
);
62 wxBitmapRefData(const wxBitmapRefData
&tocopy
);
64 virtual ~wxBitmapRefData();
66 virtual bool IsOk() const { return m_ok
; }
69 void SetOk( bool isOk
) { m_ok
= isOk
; }
71 void SetWidth( int width
) { m_width
= width
; }
72 void SetHeight( int height
) { m_height
= height
; }
73 void SetDepth( int depth
) { m_depth
= depth
; }
75 int GetWidth() const { return m_width
; }
76 int GetHeight() const { return m_height
; }
77 int GetDepth() const { return m_depth
; }
79 void *GetRawAccess() const;
80 void *BeginRawAccess();
83 bool HasAlpha() const { return m_hasAlpha
; }
84 void UseAlpha( bool useAlpha
);
88 wxPalette m_bitmapPalette
;
89 #endif // wxUSE_PALETTE
91 wxMask
* m_bitmapMask
; // Optional mask
92 CGImageRef
CreateCGImage() const;
94 // returns true if the bitmap has a size that
95 // can be natively transferred into a true icon
96 // if no is returned GetIconRef will still produce
97 // an icon but it will be generated via a PICT and
98 // rescaled to 16 x 16
101 // caller should increase ref count if needed longer
102 // than the bitmap exists
103 IconRef
GetIconRef();
105 #ifndef __WXOSX_IPHONE__
106 // returns a Pict from the bitmap content
107 PicHandle
GetPictHandle();
110 CGContextRef
GetBitmapContext() const;
112 int GetBytesPerRow() const { return m_bytesPerRow
; }
114 bool Create(int width
, int height
, int depth
);
115 bool Create( CGImageRef image
);
123 wxMemoryBuffer m_memBuf
;
124 int m_rawAccessCount
;
126 mutable CGImageRef m_cgImageRef
;
129 #ifndef __WXOSX_IPHONE__
130 PicHandle m_pictHandle
;
132 CGContextRef m_hBitmap
;
136 #define wxOSX_USE_PREMULTIPLIED_ALPHA 1
137 static const int kBestByteAlignement
= 16;
138 static const int kMaskBytesPerPixel
= 1;
140 static int GetBestBytesPerRow( int rawBytes
)
142 return (((rawBytes
)+kBestByteAlignement
-1) & ~(kBestByteAlignement
-1) );
145 #if wxUSE_GUI && !defined(__WXOSX_IPHONE__)
147 // this is used for more controls than just the wxBitmap button, also for notebooks etc
149 void wxMacCreateBitmapButton( ControlButtonContentInfo
*info
, const wxBitmap
& bitmap
, int forceType
)
151 memset( info
, 0 , sizeof(ControlButtonContentInfo
) ) ;
154 wxBitmapRefData
* bmap
= bitmap
.GetBitmapData() ;
158 if ( forceType
== 0 )
160 forceType
= kControlContentCGImageRef
;
163 if ( forceType
== kControlContentIconRef
)
166 wxBitmapRefData
* bmp
= bmap
;
168 if ( !bmap
->HasNativeSize() )
170 // as PICT conversion will only result in a 16x16 icon, let's attempt
171 // a few scales for better results
173 int w
= bitmap
.GetWidth() ;
174 int h
= bitmap
.GetHeight() ;
175 int sz
= wxMax( w
, h
) ;
176 if ( sz
== 24 || sz
== 64 )
178 scaleBmp
= wxBitmap( bitmap
.ConvertToImage().Scale( w
* 2 , h
* 2 ) ) ;
179 bmp
= scaleBmp
.GetBitmapData() ;
183 info
->contentType
= kControlContentIconRef
;
184 info
->u
.iconRef
= bmp
->GetIconRef() ;
185 AcquireIconRef( info
->u
.iconRef
) ;
187 else if ( forceType
== kControlContentCGImageRef
)
189 info
->contentType
= kControlContentCGImageRef
;
190 info
->u
.imageRef
= (CGImageRef
) bmap
->CreateCGImage() ;
195 info
->contentType
= kControlContentPictHandle
;
196 info
->u
.picture
= bmap
->GetPictHandle() ;
202 CGImageRef
wxMacCreateCGImageFromBitmap( const wxBitmap
& bitmap
)
204 wxBitmapRefData
* bmap
= bitmap
.GetBitmapData() ;
207 return (CGImageRef
) bmap
->CreateCGImage();
210 void wxMacReleaseBitmapButton( ControlButtonContentInfo
*info
)
212 if ( info
->contentType
== kControlContentIconRef
)
214 ReleaseIconRef( info
->u
.iconRef
) ;
216 else if ( info
->contentType
== kControlNoContent
)
218 // there's no bitmap at all, fall through silently
220 else if ( info
->contentType
== kControlContentPictHandle
)
222 // owned by the bitmap, no release here
224 else if ( info
->contentType
== kControlContentCGImageRef
)
226 CGImageRelease( info
->u
.imageRef
) ;
230 wxFAIL_MSG(wxT("Unexpected bitmap type") ) ;
234 #endif //wxUSE_BMPBUTTON
236 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
238 void wxBitmapRefData::Init()
245 m_bitmapMask
= NULL
;
246 m_cgImageRef
= NULL
;
248 #ifndef __WXOSX_IPHONE__
250 m_pictHandle
= NULL
;
254 m_rawAccessCount
= 0 ;
258 wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData
&tocopy
) : wxGDIRefData()
261 Create(tocopy
.m_width
, tocopy
.m_height
, tocopy
.m_depth
);
263 if (tocopy
.m_bitmapMask
)
264 m_bitmapMask
= new wxMask(*tocopy
.m_bitmapMask
);
265 else if (tocopy
.m_hasAlpha
)
268 unsigned char* dest
= (unsigned char*)GetRawAccess();
269 unsigned char* source
= (unsigned char*)tocopy
.GetRawAccess();
270 size_t numbytes
= m_bytesPerRow
* m_height
;
271 memcpy( dest
, source
, numbytes
);
274 wxBitmapRefData::wxBitmapRefData()
279 wxBitmapRefData::wxBitmapRefData( int w
, int h
, int d
)
282 Create( w
, h
, d
) ;
285 wxBitmapRefData::wxBitmapRefData(CGImageRef image
)
290 // code from Technical Q&A QA1509
292 bool wxBitmapRefData::Create(CGImageRef image
)
296 m_width
= CGImageGetWidth(image
);
297 m_height
= CGImageGetHeight(image
);
301 m_bytesPerRow
= GetBestBytesPerRow( m_width
* 4 ) ;
302 size_t size
= m_bytesPerRow
* m_height
;
303 void* data
= m_memBuf
.GetWriteBuf( size
) ;
306 memset( data
, 0 , size
) ;
307 m_memBuf
.UngetWriteBuf( size
) ;
308 CGImageAlphaInfo alpha
= CGImageGetAlphaInfo(image
);
309 if ( alpha
== kCGImageAlphaNone
|| alpha
== kCGImageAlphaNoneSkipFirst
|| alpha
== kCGImageAlphaNoneSkipLast
)
311 m_hBitmap
= CGBitmapContextCreate((char*) data
, m_width
, m_height
, 8, m_bytesPerRow
, wxMacGetGenericRGBColorSpace(), kCGImageAlphaNoneSkipFirst
);
316 m_hBitmap
= CGBitmapContextCreate((char*) data
, m_width
, m_height
, 8, m_bytesPerRow
, wxMacGetGenericRGBColorSpace(), kCGImageAlphaPremultipliedFirst
);
318 CGRect rect
= CGRectMake(0,0,m_width
,m_height
);
319 CGContextDrawImage(m_hBitmap
, rect
, image
);
321 wxASSERT_MSG( m_hBitmap
, wxT("Unable to create CGBitmapContext context") ) ;
322 CGContextTranslateCTM( m_hBitmap
, 0, m_height
);
323 CGContextScaleCTM( m_hBitmap
, 1, -1 );
326 m_ok
= ( m_hBitmap
!= NULL
) ;
332 bool wxBitmapRefData::Create( int w
, int h
, int d
)
334 m_width
= wxMax(1, w
);
335 m_height
= wxMax(1, h
);
339 m_bytesPerRow
= GetBestBytesPerRow( m_width
* 4 ) ;
340 size_t size
= m_bytesPerRow
* m_height
;
341 void* data
= m_memBuf
.GetWriteBuf( size
) ;
344 memset( data
, 0 , size
) ;
345 m_memBuf
.UngetWriteBuf( size
) ;
347 m_hBitmap
= CGBitmapContextCreate((char*) data
, m_width
, m_height
, 8, m_bytesPerRow
, wxMacGetGenericRGBColorSpace(), kCGImageAlphaNoneSkipFirst
);
348 wxASSERT_MSG( m_hBitmap
, wxT("Unable to create CGBitmapContext context") ) ;
349 CGContextTranslateCTM( m_hBitmap
, 0, m_height
);
350 CGContextScaleCTM( m_hBitmap
, 1, -1 );
352 m_ok
= ( m_hBitmap
!= NULL
) ;
357 void wxBitmapRefData::UseAlpha( bool use
)
359 if ( m_hasAlpha
== use
)
364 CGContextRelease( m_hBitmap
);
365 m_hBitmap
= CGBitmapContextCreate((char*) m_memBuf
.GetData(), m_width
, m_height
, 8, m_bytesPerRow
, wxMacGetGenericRGBColorSpace(), m_hasAlpha
? kCGImageAlphaPremultipliedFirst
: kCGImageAlphaNoneSkipFirst
);
366 wxASSERT_MSG( m_hBitmap
, wxT("Unable to create CGBitmapContext context") ) ;
367 CGContextTranslateCTM( m_hBitmap
, 0, m_height
);
368 CGContextScaleCTM( m_hBitmap
, 1, -1 );
371 void *wxBitmapRefData::GetRawAccess() const
373 wxCHECK_MSG( IsOk(), NULL
, wxT("invalid bitmap") ) ;
374 return m_memBuf
.GetData() ;
377 void *wxBitmapRefData::BeginRawAccess()
379 wxCHECK_MSG( IsOk(), NULL
, wxT("invalid bitmap") ) ;
380 wxASSERT( m_rawAccessCount
== 0 ) ;
381 #ifndef __WXOSX_IPHONE__
382 wxASSERT_MSG( m_pictHandle
== NULL
&& m_iconRef
== NULL
,
383 wxT("Currently, modifing bitmaps that are used in controls already is not supported") ) ;
387 // we must destroy an existing cached image, as
388 // the bitmap data may change now
391 CGImageRelease( m_cgImageRef
) ;
392 m_cgImageRef
= NULL
;
395 return m_memBuf
.GetData() ;
398 void wxBitmapRefData::EndRawAccess()
400 wxCHECK_RET( IsOk() , wxT("invalid bitmap") ) ;
401 wxASSERT( m_rawAccessCount
== 1 ) ;
406 bool wxBitmapRefData::HasNativeSize()
409 int h
= GetHeight() ;
410 int sz
= wxMax( w
, h
) ;
412 return ( sz
== 128 || sz
== 48 || sz
== 32 || sz
== 16 );
415 #ifndef __WXOSX_IPHONE__
416 IconRef
wxBitmapRefData::GetIconRef()
418 if ( m_iconRef
== NULL
)
420 // Create Icon Family Handle
422 IconFamilyHandle iconFamily
= (IconFamilyHandle
) NewHandle( 0 );
425 int h
= GetHeight() ;
426 int sz
= wxMax( w
, h
) ;
428 OSType dataType
= 0 ;
429 OSType maskType
= 0 ;
434 dataType
= kIconServices128PixelDataARGB
;
438 dataType
= kIconServices48PixelDataARGB
;
442 dataType
= kIconServices32PixelDataARGB
;
446 dataType
= kIconServices16PixelDataARGB
;
457 size_t datasize
= sz
* sz
* 4 ;
458 Handle data
= NewHandle( datasize
) ;
460 unsigned char* ptr
= (unsigned char*) *data
;
461 memset( ptr
, 0, datasize
);
462 bool hasAlpha
= HasAlpha() ;
463 wxMask
*mask
= m_bitmapMask
;
464 unsigned char * sourcePtr
= (unsigned char*) GetRawAccess() ;
465 unsigned char * masksourcePtr
= mask
? (unsigned char*) mask
->GetRawAccess() : NULL
;
467 for ( int y
= 0 ; y
< h
; ++y
, sourcePtr
+= m_bytesPerRow
, masksourcePtr
+= mask
? mask
->GetBytesPerRow() : 0 )
469 unsigned char * source
= sourcePtr
;
470 unsigned char * masksource
= masksourcePtr
;
471 unsigned char * dest
= ptr
+ y
* sz
* 4 ;
472 unsigned char a
, r
, g
, b
;
474 for ( int x
= 0 ; x
< w
; ++x
)
483 a
= 0xFF - *masksource
++ ;
485 else if ( !hasAlpha
)
489 #if wxOSX_USE_PREMULTIPLIED_ALPHA
490 // this must be non-premultiplied data
491 if ( a
!= 0xFF && a
!= 0 )
508 OSStatus err
= SetIconFamilyData( iconFamily
, dataType
, data
);
511 wxFAIL_MSG("Error when adding bitmap");
514 DisposeHandle( data
);
518 // setup the header properly
521 Handle maskdata
= NULL
;
522 unsigned char * maskptr
= NULL
;
523 unsigned char * ptr
= NULL
;
524 size_t datasize
, masksize
;
526 datasize
= sz
* sz
* 4 ;
527 data
= NewHandle( datasize
) ;
529 ptr
= (unsigned char*) *data
;
530 memset( ptr
, 0, datasize
) ;
533 maskdata
= NewHandle( masksize
) ;
535 maskptr
= (unsigned char*) *maskdata
;
536 memset( maskptr
, 0 , masksize
) ;
538 bool hasAlpha
= HasAlpha() ;
539 wxMask
*mask
= m_bitmapMask
;
540 unsigned char * sourcePtr
= (unsigned char*) GetRawAccess() ;
541 unsigned char * masksourcePtr
= mask
? (unsigned char*) mask
->GetRawAccess() : NULL
;
543 for ( int y
= 0 ; y
< h
; ++y
, sourcePtr
+= m_bytesPerRow
, masksourcePtr
+= mask
? mask
->GetBytesPerRow() : 0 )
545 unsigned char * source
= sourcePtr
;
546 unsigned char * masksource
= masksourcePtr
;
547 unsigned char * dest
= ptr
+ y
* sz
* 4 ;
548 unsigned char * maskdest
= maskptr
+ y
* sz
;
549 unsigned char a
, r
, g
, b
;
551 for ( int x
= 0 ; x
< w
; ++x
)
564 *maskdest
++ = 0xFF - *masksource
++ ;
572 OSStatus err
= SetIconFamilyData( iconFamily
, dataType
, data
) ;
573 wxASSERT_MSG( err
== noErr
, wxT("Error when adding bitmap") ) ;
575 err
= SetIconFamilyData( iconFamily
, maskType
, maskdata
) ;
576 wxASSERT_MSG( err
== noErr
, wxT("Error when adding mask") ) ;
579 HUnlock( maskdata
) ;
580 DisposeHandle( data
) ;
581 DisposeHandle( maskdata
) ;
586 PicHandle pic
= GetPictHandle() ;
587 SetIconFamilyData( iconFamily
, 'PICT' , (Handle
) pic
) ;
589 // transform into IconRef
591 // cleaner version existing from 10.3 upwards
592 HLock((Handle
) iconFamily
);
593 OSStatus err
= GetIconRefFromIconFamilyPtr( *iconFamily
, GetHandleSize((Handle
) iconFamily
), &m_iconRef
);
594 HUnlock((Handle
) iconFamily
);
595 DisposeHandle( (Handle
) iconFamily
) ;
597 wxCHECK_MSG( err
== noErr
, NULL
, wxT("Error when constructing icon ref") );
603 PicHandle
wxBitmapRefData::GetPictHandle()
605 return m_pictHandle
;
609 CGImageRef
wxBitmapRefData::CreateCGImage() const
612 wxASSERT( m_rawAccessCount
>= 0 ) ;
614 if ( m_rawAccessCount
> 0 || m_cgImageRef
== NULL
)
616 if ( m_depth
!= 1 && m_bitmapMask
== NULL
)
619 // in order for this code to work properly, wxMask would have to invert black and white
620 // in the native bitmap
623 CGImageRef tempImage
= CGBitmapContextCreateImage( m_hBitmap
);
624 CGImageRef tempMask
= CGBitmapContextCreateImage((CGContextRef
) m_bitmapMask
->GetHBITMAP() );
625 image
= CGImageCreateWithMask( tempImage
, tempMask
);
626 CGImageRelease(tempMask
);
627 CGImageRelease(tempImage
);
631 image
= CGBitmapContextCreateImage( m_hBitmap
);
635 size_t imageSize
= m_height
* m_bytesPerRow
;
636 void * dataBuffer
= m_memBuf
.GetData() ;
639 CGImageAlphaInfo alphaInfo
= kCGImageAlphaNoneSkipFirst
;
640 wxMemoryBuffer membuf
;
644 alphaInfo
= kCGImageAlphaFirst
;
645 unsigned char *destalphastart
= (unsigned char*) membuf
.GetWriteBuf( imageSize
) ;
646 memcpy( destalphastart
, dataBuffer
, imageSize
) ;
647 unsigned char *sourcemaskstart
= (unsigned char *) m_bitmapMask
->GetRawAccess() ;
648 int maskrowbytes
= m_bitmapMask
->GetBytesPerRow() ;
649 for ( int y
= 0 ; y
< h
; ++y
, destalphastart
+= m_bytesPerRow
, sourcemaskstart
+= maskrowbytes
)
651 unsigned char *sourcemask
= sourcemaskstart
;
652 unsigned char *destalpha
= destalphastart
;
653 for ( int x
= 0 ; x
< w
; ++x
, sourcemask
+= kMaskBytesPerPixel
, destalpha
+= 4 )
655 *destalpha
= 0xFF - *sourcemask
;
658 membuf
.UngetWriteBuf( imageSize
);
664 #if wxOSX_USE_PREMULTIPLIED_ALPHA
665 alphaInfo
= kCGImageAlphaPremultipliedFirst
;
667 alphaInfo
= kCGImageAlphaFirst
;
674 CGDataProviderRef dataProvider
= NULL
;
677 // TODO CHECK ALIGNMENT
678 wxMemoryBuffer maskBuf
;
679 unsigned char * maskBufData
= (unsigned char*) maskBuf
.GetWriteBuf( m_width
* m_height
);
680 unsigned char * bufData
= (unsigned char *) membuf
.GetData() ;
681 // copy one color component
683 for( int y
= 0 ; y
< m_height
; bufData
+= m_bytesPerRow
, ++y
)
685 unsigned char *bufDataIter
= bufData
+3;
686 for ( int x
= 0 ; x
< m_width
; bufDataIter
+= 4, ++x
, ++i
)
688 maskBufData
[i
] = *bufDataIter
;
691 maskBuf
.UngetWriteBuf( m_width
* m_height
);
694 wxMacCGDataProviderCreateWithMemoryBuffer( maskBuf
);
696 image
= ::CGImageMaskCreate( w
, h
, 8, 8, m_width
, dataProvider
, NULL
, false );
700 CGColorSpaceRef colorSpace
= wxMacGetGenericRGBColorSpace();
701 dataProvider
= wxMacCGDataProviderCreateWithMemoryBuffer( membuf
);
704 w
, h
, 8 , 32 , m_bytesPerRow
, colorSpace
, alphaInfo
,
705 dataProvider
, NULL
, false , kCGRenderingIntentDefault
);
707 CGDataProviderRelease( dataProvider
);
712 image
= m_cgImageRef
;
713 CGImageRetain( image
) ;
716 if ( m_rawAccessCount
== 0 && m_cgImageRef
== NULL
)
718 // we keep it for later use
719 m_cgImageRef
= image
;
720 CGImageRetain( image
) ;
726 CGContextRef
wxBitmapRefData::GetBitmapContext() const
731 void wxBitmapRefData::Free()
733 wxASSERT_MSG( m_rawAccessCount
== 0 , wxT("Bitmap still selected when destroyed") ) ;
737 CGImageRelease( m_cgImageRef
) ;
738 m_cgImageRef
= NULL
;
740 #ifndef __WXOSX_IPHONE__
743 ReleaseIconRef( m_iconRef
) ;
750 m_pictHandle
= NULL
;
756 CGContextRelease(m_hBitmap
);
760 wxDELETE(m_bitmapMask
);
763 wxBitmapRefData::~wxBitmapRefData()
770 // ----------------------------------------------------------------------------
772 // ----------------------------------------------------------------------------
774 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
776 bool created
= false ;
777 int w
= icon
.GetWidth() ;
778 int h
= icon
.GetHeight() ;
781 #ifdef __WXOSX_CARBON__
782 if ( w
== h
&& ( w
== 16 || w
== 32 || w
== 48 || w
== 128 ) )
784 IconFamilyHandle iconFamily
= NULL
;
785 Handle imagehandle
= NewHandle( 0 ) ;
786 Handle maskhandle
= NewHandle( 0 ) ;
790 IconSelectorValue selector
= 0 ;
795 dataType
= kThumbnail32BitData
;
796 maskType
= kThumbnail8BitMask
;
797 selector
= kSelectorAllAvailableData
;
801 dataType
= kHuge32BitData
;
802 maskType
= kHuge8BitMask
;
803 selector
= kSelectorHuge32Bit
| kSelectorHuge8BitMask
;
807 dataType
= kLarge32BitData
;
808 maskType
= kLarge8BitMask
;
809 selector
= kSelectorLarge32Bit
| kSelectorLarge8BitMask
;
813 dataType
= kSmall32BitData
;
814 maskType
= kSmall8BitMask
;
815 selector
= kSelectorSmall32Bit
| kSelectorSmall8BitMask
;
822 OSStatus err
= IconRefToIconFamily( MAC_WXHICON(icon
.GetHICON()) , selector
, &iconFamily
) ;
824 err
= GetIconFamilyData( iconFamily
, dataType
, imagehandle
) ;
825 err
= GetIconFamilyData( iconFamily
, maskType
, maskhandle
) ;
826 size_t imagehandlesize
= GetHandleSize( imagehandle
) ;
827 size_t maskhandlesize
= GetHandleSize( maskhandle
) ;
829 if ( imagehandlesize
!= 0 && maskhandlesize
!= 0 )
831 wxASSERT( GetHandleSize( imagehandle
) == w
* 4 * h
) ;
832 wxASSERT( GetHandleSize( maskhandle
) == w
* h
) ;
836 unsigned char *source
= (unsigned char *) *imagehandle
;
837 unsigned char *sourcemask
= (unsigned char *) *maskhandle
;
838 unsigned char* destination
= (unsigned char*) BeginRawAccess() ;
840 for ( int y
= 0 ; y
< h
; ++y
)
842 for ( int x
= 0 ; x
< w
; ++x
)
844 unsigned char a
= *sourcemask
++;
847 #if wxOSX_USE_PREMULTIPLIED_ALPHA
848 *destination
++ = ( (*source
++) * a
+ 127 ) / 255;
849 *destination
++ = ( (*source
++) * a
+ 127 ) / 255;
850 *destination
++ = ( (*source
++) * a
+ 127 ) / 255;
852 *destination
++ = *source
++ ;
853 *destination
++ = *source
++ ;
854 *destination
++ = *source
++ ;
860 DisposeHandle( imagehandle
) ;
861 DisposeHandle( maskhandle
) ;
865 DisposeHandle( (Handle
) iconFamily
) ;
871 dc
.SelectObject( *this ) ;
872 dc
.DrawIcon( icon
, 0 , 0 ) ;
873 dc
.SelectObject( wxNullBitmap
) ;
879 wxBitmap::wxBitmap(const char bits
[], int the_width
, int the_height
, int no_bits
)
881 wxBitmapRefData
* bitmapRefData
;
883 m_refData
= bitmapRefData
= new wxBitmapRefData( the_width
, the_height
, no_bits
) ;
885 if (bitmapRefData
->IsOk())
889 int linesize
= ( the_width
/ (sizeof(unsigned char) * 8)) ;
890 if ( the_width
% (sizeof(unsigned char) * 8) )
891 linesize
+= sizeof(unsigned char);
893 unsigned char* linestart
= (unsigned char*) bits
;
894 unsigned char* destptr
= (unsigned char*) BeginRawAccess() ;
896 for ( int y
= 0 ; y
< the_height
; ++y
, linestart
+= linesize
, destptr
+= M_BITMAPDATA
->GetBytesPerRow() )
898 unsigned char* destination
= destptr
;
899 int index
, bit
, mask
;
901 for ( int x
= 0 ; x
< the_width
; ++x
)
907 if ( linestart
[index
] & mask
)
909 *destination
++ = 0xFF ;
916 *destination
++ = 0xFF ;
917 *destination
++ = 0xFF ;
918 *destination
++ = 0xFF ;
919 *destination
++ = 0xFF ;
928 wxFAIL_MSG(wxT("multicolor BITMAPs not yet implemented"));
930 } /* bitmapRefData->IsOk() */
933 wxBitmap::wxBitmap(const void* data
, wxBitmapType type
, int width
, int height
, int depth
)
935 (void) Create(data
, type
, width
, height
, depth
);
938 wxBitmap::wxBitmap(const wxString
& filename
, wxBitmapType type
)
940 LoadFile(filename
, type
);
943 wxBitmap::wxBitmap(CGImageRef image
)
945 (void) Create(image
);
948 wxGDIRefData
* wxBitmap::CreateGDIRefData() const
950 return new wxBitmapRefData
;
953 wxGDIRefData
* wxBitmap::CloneGDIRefData(const wxGDIRefData
* data
) const
955 return new wxBitmapRefData(*static_cast<const wxBitmapRefData
*>(data
));
958 void * wxBitmap::GetRawAccess() const
960 wxCHECK_MSG( IsOk() , NULL
, wxT("invalid bitmap") ) ;
962 return M_BITMAPDATA
->GetRawAccess() ;
965 void * wxBitmap::BeginRawAccess()
967 wxCHECK_MSG( IsOk() , NULL
, wxT("invalid bitmap") ) ;
969 return M_BITMAPDATA
->BeginRawAccess() ;
972 void wxBitmap::EndRawAccess()
974 wxCHECK_RET( IsOk() , wxT("invalid bitmap") ) ;
976 M_BITMAPDATA
->EndRawAccess() ;
979 CGImageRef
wxBitmap::CreateCGImage() const
981 wxCHECK_MSG( IsOk(), NULL
, wxT("invalid bitmap") ) ;
983 return M_BITMAPDATA
->CreateCGImage() ;
986 #ifndef __WXOSX_IPHONE__
987 IconRef
wxBitmap::GetIconRef() const
989 wxCHECK_MSG( IsOk(), NULL
, wxT("invalid bitmap") ) ;
991 return M_BITMAPDATA
->GetIconRef() ;
994 IconRef
wxBitmap::CreateIconRef() const
996 IconRef icon
= GetIconRef();
997 verify_noerr( AcquireIconRef(icon
) );
1004 WX_NSImage
wxBitmap::GetNSImage() const
1006 wxCFRef
< CGImageRef
> cgimage(CreateCGImage());
1007 return wxOSXGetNSImageFromCGImage( cgimage
);
1012 #if wxOSX_USE_IPHONE
1014 WX_UIImage
wxBitmap::GetUIImage() const
1016 wxCFRef
< CGImageRef
> cgimage(CreateCGImage());
1017 return wxOSXGetUIImageFromCGImage( cgimage
);
1021 wxBitmap
wxBitmap::GetSubBitmap(const wxRect
&rect
) const
1023 wxCHECK_MSG( IsOk() &&
1024 (rect
.x
>= 0) && (rect
.y
>= 0) &&
1025 (rect
.x
+rect
.width
<= GetWidth()) &&
1026 (rect
.y
+rect
.height
<= GetHeight()),
1027 wxNullBitmap
, wxT("invalid bitmap or bitmap region") );
1029 wxBitmap
ret( rect
.width
, rect
.height
, GetDepth() );
1030 wxASSERT_MSG( ret
.IsOk(), wxT("GetSubBitmap error") );
1032 int destwidth
= rect
.width
;
1033 int destheight
= rect
.height
;
1036 unsigned char *sourcedata
= (unsigned char*) GetRawAccess() ;
1037 unsigned char *destdata
= (unsigned char*) ret
.BeginRawAccess() ;
1038 wxASSERT((sourcedata
!= NULL
) && (destdata
!= NULL
));
1040 if ( (sourcedata
!= NULL
) && (destdata
!= NULL
) )
1042 int sourcelinesize
= GetBitmapData()->GetBytesPerRow() ;
1043 int destlinesize
= ret
.GetBitmapData()->GetBytesPerRow() ;
1044 unsigned char *source
= sourcedata
+ rect
.x
* 4 + rect
.y
* sourcelinesize
;
1045 unsigned char *dest
= destdata
;
1047 for (int yy
= 0; yy
< destheight
; ++yy
, source
+= sourcelinesize
, dest
+= destlinesize
)
1049 memcpy( dest
, source
, destlinesize
) ;
1052 ret
.EndRawAccess() ;
1056 if ( M_BITMAPDATA
->m_bitmapMask
)
1058 wxMemoryBuffer maskbuf
;
1059 int rowBytes
= GetBestBytesPerRow( destwidth
* kMaskBytesPerPixel
);
1060 size_t maskbufsize
= rowBytes
* destheight
;
1062 int sourcelinesize
= M_BITMAPDATA
->m_bitmapMask
->GetBytesPerRow() ;
1063 int destlinesize
= rowBytes
;
1065 unsigned char *source
= (unsigned char *) M_BITMAPDATA
->m_bitmapMask
->GetRawAccess() ;
1066 unsigned char *destdata
= (unsigned char * ) maskbuf
.GetWriteBuf( maskbufsize
) ;
1067 wxASSERT( (source
!= NULL
) && (destdata
!= NULL
) ) ;
1069 if ( (source
!= NULL
) && (destdata
!= NULL
) )
1071 source
+= rect
.x
* kMaskBytesPerPixel
+ rect
.y
* sourcelinesize
;
1072 unsigned char *dest
= destdata
;
1074 for (int yy
= 0; yy
< destheight
; ++yy
, source
+= sourcelinesize
, dest
+= destlinesize
)
1076 memcpy( dest
, source
, destlinesize
) ;
1079 maskbuf
.UngetWriteBuf( maskbufsize
) ;
1081 ret
.SetMask( new wxMask( maskbuf
, destwidth
, destheight
, rowBytes
) ) ;
1083 else if ( HasAlpha() )
1089 bool wxBitmap::Create(int w
, int h
, int d
)
1094 d
= wxDisplayDepth() ;
1096 m_refData
= new wxBitmapRefData( w
, h
, d
);
1098 return M_BITMAPDATA
->IsOk() ;
1102 bool wxBitmap::Create(CGImageRef image
)
1106 m_refData
= new wxBitmapRefData( image
);
1108 return M_BITMAPDATA
->IsOk() ;
1111 bool wxBitmap::LoadFile(const wxString
& filename
, wxBitmapType type
)
1115 wxBitmapHandler
*handler
= FindHandler(type
);
1119 m_refData
= new wxBitmapRefData
;
1121 return handler
->LoadFile(this, filename
, type
, -1, -1);
1126 wxImage
loadimage(filename
, type
);
1127 if (loadimage
.IsOk())
1136 wxLogWarning(wxT("no bitmap handler for type %d defined."), type
);
1141 bool wxBitmap::Create(const void* data
, wxBitmapType type
, int width
, int height
, int depth
)
1145 m_refData
= new wxBitmapRefData
;
1147 wxBitmapHandler
*handler
= FindHandler(type
);
1149 if ( handler
== NULL
)
1151 wxLogWarning(wxT("no bitmap handler for type %d defined."), type
);
1156 return handler
->Create(this, data
, type
, width
, height
, depth
);
1161 wxBitmap::wxBitmap(const wxImage
& image
, int depth
)
1163 wxCHECK_RET( image
.IsOk(), wxT("invalid image") );
1165 // width and height of the device-dependent bitmap
1166 int width
= image
.GetWidth();
1167 int height
= image
.GetHeight();
1169 wxBitmapRefData
* bitmapRefData
;
1171 m_refData
= bitmapRefData
= new wxBitmapRefData( width
, height
, depth
) ;
1173 if ( bitmapRefData
->IsOk())
1177 bool hasAlpha
= false ;
1179 if ( image
.HasMask() )
1181 // takes precedence, don't mix with alpha info
1185 hasAlpha
= image
.HasAlpha() ;
1191 unsigned char* destinationstart
= (unsigned char*) BeginRawAccess() ;
1192 register unsigned char* data
= image
.GetData();
1193 if ( destinationstart
!= NULL
&& data
!= NULL
)
1195 const unsigned char *alpha
= hasAlpha
? image
.GetAlpha() : NULL
;
1196 for (int y
= 0; y
< height
; destinationstart
+= M_BITMAPDATA
->GetBytesPerRow(), y
++)
1198 unsigned char * destination
= destinationstart
;
1199 for (int x
= 0; x
< width
; x
++)
1203 const unsigned char a
= *alpha
++;
1204 *destination
++ = a
;
1206 #if wxOSX_USE_PREMULTIPLIED_ALPHA
1207 *destination
++ = ((*data
++) * a
+ 127) / 255 ;
1208 *destination
++ = ((*data
++) * a
+ 127) / 255 ;
1209 *destination
++ = ((*data
++) * a
+ 127) / 255 ;
1211 *destination
++ = *data
++ ;
1212 *destination
++ = *data
++ ;
1213 *destination
++ = *data
++ ;
1218 *destination
++ = 0xFF ;
1219 *destination
++ = *data
++ ;
1220 *destination
++ = *data
++ ;
1221 *destination
++ = *data
++ ;
1228 if ( image
.HasMask() )
1229 SetMask( new wxMask( *this , wxColour( image
.GetMaskRed() , image
.GetMaskGreen() , image
.GetMaskBlue() ) ) ) ;
1230 } /* bitmapRefData->IsOk() */
1233 wxImage
wxBitmap::ConvertToImage() const
1237 wxCHECK_MSG( IsOk(), wxNullImage
, wxT("invalid bitmap") );
1239 // create an wxImage object
1240 int width
= GetWidth();
1241 int height
= GetHeight();
1242 image
.Create( width
, height
);
1244 unsigned char *data
= image
.GetData();
1245 wxCHECK_MSG( data
, wxNullImage
, wxT("Could not allocate data for image") );
1247 unsigned char* sourcestart
= (unsigned char*) GetRawAccess() ;
1249 bool hasAlpha
= false ;
1250 bool hasMask
= false ;
1251 int maskBytesPerRow
= 0 ;
1252 unsigned char *alpha
= NULL
;
1253 unsigned char *mask
= NULL
;
1261 mask
= (unsigned char*) GetMask()->GetRawAccess() ;
1262 maskBytesPerRow
= GetMask()->GetBytesPerRow() ;
1268 alpha
= image
.GetAlpha() ;
1273 // The following masking algorithm is the same as well in msw/gtk:
1274 // the colour used as transparent one in wxImage and the one it is
1275 // replaced with when it actually occurs in the bitmap
1276 static const int MASK_RED
= 1;
1277 static const int MASK_GREEN
= 2;
1278 static const int MASK_BLUE
= 3;
1279 static const int MASK_BLUE_REPLACEMENT
= 2;
1281 for (int yy
= 0; yy
< height
; yy
++ , sourcestart
+= M_BITMAPDATA
->GetBytesPerRow() , mask
+= maskBytesPerRow
)
1283 unsigned char * maskp
= mask
;
1284 unsigned char * source
= sourcestart
;
1285 unsigned char a
, r
, g
, b
;
1288 for (int xx
= 0; xx
< width
; xx
++)
1290 color
= *((long*) source
) ;
1291 #ifdef WORDS_BIGENDIAN
1292 a
= ((color
&0xFF000000) >> 24) ;
1293 r
= ((color
&0x00FF0000) >> 16) ;
1294 g
= ((color
&0x0000FF00) >> 8) ;
1295 b
= (color
&0x000000FF);
1297 b
= ((color
&0xFF000000) >> 24) ;
1298 g
= ((color
&0x00FF0000) >> 16) ;
1299 r
= ((color
&0x0000FF00) >> 8) ;
1300 a
= (color
&0x000000FF);
1304 if ( *maskp
++ == 0xFF )
1310 else if ( r
== MASK_RED
&& g
== MASK_GREEN
&& b
== MASK_BLUE
)
1311 b
= MASK_BLUE_REPLACEMENT
;
1313 else if ( hasAlpha
)
1316 #if wxOSX_USE_PREMULTIPLIED_ALPHA
1317 // this must be non-premultiplied data
1318 if ( a
!= 0xFF && a
!= 0 )
1328 data
[index
+ 1] = g
;
1329 data
[index
+ 2] = b
;
1337 image
.SetMaskColour( MASK_RED
, MASK_GREEN
, MASK_BLUE
);
1342 #endif //wxUSE_IMAGE
1344 bool wxBitmap::SaveFile( const wxString
& filename
,
1345 wxBitmapType type
, const wxPalette
*palette
) const
1347 bool success
= false;
1348 wxBitmapHandler
*handler
= FindHandler(type
);
1352 success
= handler
->SaveFile(this, filename
, type
, palette
);
1357 wxImage image
= ConvertToImage();
1358 success
= image
.SaveFile(filename
, type
);
1360 wxLogWarning(wxT("no bitmap handler for type %d defined."), type
);
1367 int wxBitmap::GetHeight() const
1369 wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") );
1371 return M_BITMAPDATA
->GetHeight();
1374 int wxBitmap::GetWidth() const
1376 wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") );
1378 return M_BITMAPDATA
->GetWidth() ;
1381 int wxBitmap::GetDepth() const
1383 wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") );
1385 return M_BITMAPDATA
->GetDepth();
1388 wxMask
*wxBitmap::GetMask() const
1390 wxCHECK_MSG( IsOk(), NULL
, wxT("invalid bitmap") );
1392 return M_BITMAPDATA
->m_bitmapMask
;
1395 bool wxBitmap::HasAlpha() const
1397 wxCHECK_MSG( IsOk(), false , wxT("invalid bitmap") );
1399 return M_BITMAPDATA
->HasAlpha() ;
1402 void wxBitmap::SetWidth(int w
)
1405 M_BITMAPDATA
->SetWidth(w
);
1408 void wxBitmap::SetHeight(int h
)
1411 M_BITMAPDATA
->SetHeight(h
);
1414 void wxBitmap::SetDepth(int d
)
1417 M_BITMAPDATA
->SetDepth(d
);
1420 void wxBitmap::SetOk(bool isOk
)
1423 M_BITMAPDATA
->SetOk(isOk
);
1427 wxPalette
*wxBitmap::GetPalette() const
1429 wxCHECK_MSG( IsOk(), NULL
, wxT("Invalid bitmap GetPalette()") );
1431 return &M_BITMAPDATA
->m_bitmapPalette
;
1434 void wxBitmap::SetPalette(const wxPalette
& palette
)
1437 M_BITMAPDATA
->m_bitmapPalette
= palette
;
1439 #endif // wxUSE_PALETTE
1441 void wxBitmap::SetMask(wxMask
*mask
)
1444 // Remove existing mask if there is one.
1445 delete M_BITMAPDATA
->m_bitmapMask
;
1447 M_BITMAPDATA
->m_bitmapMask
= mask
;
1450 WXHBITMAP
wxBitmap::GetHBITMAP(WXHBITMAP
* mask
) const
1454 return WXHBITMAP(M_BITMAPDATA
->GetBitmapContext());
1457 // ----------------------------------------------------------------------------
1459 // ----------------------------------------------------------------------------
1466 wxMask::wxMask(const wxMask
&tocopy
) : wxObject()
1470 m_bytesPerRow
= tocopy
.m_bytesPerRow
;
1471 m_width
= tocopy
.m_width
;
1472 m_height
= tocopy
.m_height
;
1474 size_t size
= m_bytesPerRow
* m_height
;
1475 unsigned char* dest
= (unsigned char*)m_memBuf
.GetWriteBuf( size
);
1476 unsigned char* source
= (unsigned char*)tocopy
.m_memBuf
.GetData();
1477 memcpy( dest
, source
, size
);
1478 m_memBuf
.UngetWriteBuf( size
) ;
1482 // Construct a mask from a bitmap and a colour indicating
1483 // the transparent area
1484 wxMask::wxMask( const wxBitmap
& bitmap
, const wxColour
& colour
)
1487 Create( bitmap
, colour
);
1490 // Construct a mask from a mono bitmap (copies the bitmap).
1491 wxMask::wxMask( const wxBitmap
& bitmap
)
1497 // Construct a mask from a mono bitmap (copies the bitmap).
1499 wxMask::wxMask( const wxMemoryBuffer
& data
, int width
, int height
, int bytesPerRow
)
1502 Create( data
, width
, height
, bytesPerRow
);
1509 CGContextRelease( (CGContextRef
) m_maskBitmap
);
1510 m_maskBitmap
= NULL
;
1516 m_width
= m_height
= m_bytesPerRow
= 0 ;
1517 m_maskBitmap
= NULL
;
1520 void *wxMask::GetRawAccess() const
1522 return m_memBuf
.GetData() ;
1525 // The default ColorTable for k8IndexedGrayPixelFormat in Intel appears to be broken, so we'll use an non-indexed
1526 // bitmap mask instead; in order to keep the code simple, the change applies to PowerPC implementations as well
1528 void wxMask::RealizeNative()
1532 CGContextRelease( (CGContextRef
) m_maskBitmap
);
1533 m_maskBitmap
= NULL
;
1536 CGColorSpaceRef colorspace
= CGColorSpaceCreateDeviceGray();
1537 // from MouseTracking sample :
1538 // Ironically, due to a bug in CGImageCreateWithMask, you cannot use
1539 // CGColorSpaceCreateWithName(kCGColorSpaceGenericGray) at this point!
1541 m_maskBitmap
= CGBitmapContextCreate((char*) m_memBuf
.GetData(), m_width
, m_height
, 8, m_bytesPerRow
, colorspace
,
1542 kCGImageAlphaNone
);
1543 CGColorSpaceRelease( colorspace
);
1544 wxASSERT_MSG( m_maskBitmap
, wxT("Unable to create CGBitmapContext context") ) ;
1547 // Create a mask from a mono bitmap (copies the bitmap).
1549 bool wxMask::Create(const wxMemoryBuffer
& data
,int width
, int height
, int bytesPerRow
)
1554 m_bytesPerRow
= bytesPerRow
;
1556 wxASSERT( data
.GetDataLen() == (size_t)(height
* bytesPerRow
) ) ;
1563 // Create a mask from a mono bitmap (copies the bitmap).
1564 bool wxMask::Create(const wxBitmap
& bitmap
)
1566 m_width
= bitmap
.GetWidth() ;
1567 m_height
= bitmap
.GetHeight() ;
1568 m_bytesPerRow
= GetBestBytesPerRow( m_width
* kMaskBytesPerPixel
) ;
1570 size_t size
= m_bytesPerRow
* m_height
;
1571 unsigned char * destdatabase
= (unsigned char*) m_memBuf
.GetWriteBuf( size
) ;
1572 wxASSERT( destdatabase
!= NULL
) ;
1576 memset( destdatabase
, 0 , size
) ;
1577 unsigned char * srcdata
= (unsigned char*) bitmap
.GetRawAccess() ;
1579 for ( int y
= 0 ; y
< m_height
; ++y
, destdatabase
+= m_bytesPerRow
)
1581 unsigned char *destdata
= destdatabase
;
1582 unsigned char r
, g
, b
;
1584 for ( int x
= 0 ; x
< m_width
; ++x
)
1591 if ( ( r
+ g
+ b
) > 0x10 )
1592 *destdata
++ = 0xFF ;
1594 *destdata
++ = 0x00 ;
1599 m_memBuf
.UngetWriteBuf( size
) ;
1605 // Create a mask from a bitmap and a colour indicating
1606 // the transparent area
1607 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
1609 m_width
= bitmap
.GetWidth() ;
1610 m_height
= bitmap
.GetHeight() ;
1611 m_bytesPerRow
= GetBestBytesPerRow( m_width
* kMaskBytesPerPixel
) ;
1613 size_t size
= m_bytesPerRow
* m_height
;
1614 unsigned char * destdatabase
= (unsigned char*) m_memBuf
.GetWriteBuf( size
) ;
1615 wxASSERT( destdatabase
!= NULL
) ;
1616 if ( destdatabase
!= NULL
)
1618 memset( destdatabase
, 0 , size
) ;
1619 unsigned char * srcdatabase
= (unsigned char*) bitmap
.GetRawAccess() ;
1620 size_t sourceBytesRow
= bitmap
.GetBitmapData()->GetBytesPerRow();
1622 for ( int y
= 0 ; y
< m_height
; ++y
, srcdatabase
+= sourceBytesRow
, destdatabase
+= m_bytesPerRow
)
1624 unsigned char *srcdata
= srcdatabase
;
1625 unsigned char *destdata
= destdatabase
;
1626 unsigned char r
, g
, b
;
1628 for ( int x
= 0 ; x
< m_width
; ++x
)
1635 if ( colour
== wxColour( r
, g
, b
) )
1636 *destdata
++ = 0xFF ;
1638 *destdata
++ = 0x00 ;
1642 m_memBuf
.UngetWriteBuf( size
) ;
1648 WXHBITMAP
wxMask::GetHBITMAP() const
1650 return m_maskBitmap
;
1653 // ----------------------------------------------------------------------------
1654 // Standard Handlers
1655 // ----------------------------------------------------------------------------
1657 class WXDLLEXPORT wxBundleResourceHandler
: public wxBitmapHandler
1659 DECLARE_ABSTRACT_CLASS(wxBundleResourceHandler
)
1662 inline wxBundleResourceHandler()
1666 virtual bool LoadFile(wxBitmap
*bitmap
,
1667 const wxString
& name
,
1673 IMPLEMENT_ABSTRACT_CLASS(wxBundleResourceHandler
, wxBitmapHandler
);
1675 class WXDLLEXPORT wxPNGResourceHandler
: public wxBundleResourceHandler
1677 DECLARE_DYNAMIC_CLASS(wxPNGResourceHandler
)
1680 inline wxPNGResourceHandler()
1682 SetName(wxT("PNG resource"));
1683 SetExtension("PNG");
1684 SetType(wxBITMAP_TYPE_PNG_RESOURCE
);
1688 IMPLEMENT_DYNAMIC_CLASS(wxPNGResourceHandler
, wxBundleResourceHandler
)
1690 class WXDLLEXPORT wxJPEGResourceHandler
: public wxBundleResourceHandler
1692 DECLARE_DYNAMIC_CLASS(wxPNGResourceHandler
)
1695 inline wxJPEGResourceHandler()
1697 SetName(wxT("JPEG resource"));
1698 SetExtension("JPEG");
1699 SetType(wxBITMAP_TYPE_JPEG_RESOURCE
);
1703 IMPLEMENT_DYNAMIC_CLASS(wxJPEGResourceHandler
, wxBundleResourceHandler
)
1705 bool wxBundleResourceHandler::LoadFile(wxBitmap
*bitmap
,
1706 const wxString
& name
,
1707 wxBitmapType
WXUNUSED(type
),
1708 int WXUNUSED(desiredWidth
),
1709 int WXUNUSED(desiredHeight
))
1711 wxString ext
= GetExtension().Lower();
1712 wxCFStringRef
resname(name
);
1713 wxCFStringRef
restype(ext
);
1715 wxCFRef
<CFURLRef
> imageURL(CFBundleCopyResourceURL(CFBundleGetMainBundle(), resname
, restype
, NULL
));
1717 if ( imageURL
.get() != NULL
)
1719 // Create the data provider object
1720 wxCFRef
<CGDataProviderRef
> provider(CGDataProviderCreateWithURL (imageURL
) );
1721 CGImageRef image
= NULL
;
1723 if ( ext
== "jpeg" )
1724 image
= CGImageCreateWithJPEGDataProvider (provider
, NULL
, true,
1725 kCGRenderingIntentDefault
);
1726 else if ( ext
== "png" )
1727 image
= CGImageCreateWithPNGDataProvider (provider
, NULL
, true,
1728 kCGRenderingIntentDefault
);
1729 if ( image
!= NULL
)
1731 bitmap
->Create(image
);
1732 CGImageRelease(image
);
1739 void wxBitmap::InitStandardHandlers()
1741 #if wxOSX_USE_COCOA_OR_CARBON
1742 AddHandler( new wxICONResourceHandler
) ;
1744 AddHandler( new wxPNGResourceHandler
);
1745 AddHandler( new wxJPEGResourceHandler
);
1748 // ----------------------------------------------------------------------------
1749 // raw bitmap access support
1750 // ----------------------------------------------------------------------------
1752 void *wxBitmap::GetRawData(wxPixelDataBase
& data
, int WXUNUSED(bpp
))
1755 // no bitmap, no data (raw or otherwise)
1758 data
.m_width
= GetWidth() ;
1759 data
.m_height
= GetHeight() ;
1760 data
.m_stride
= GetBitmapData()->GetBytesPerRow() ;
1762 return BeginRawAccess() ;
1765 void wxBitmap::UngetRawData(wxPixelDataBase
& WXUNUSED(dataBase
))
1770 void wxBitmap::UseAlpha()
1772 // remember that we are using alpha channel:
1773 // we'll need to create a proper mask in UngetRawData()
1774 M_BITMAPDATA
->UseAlpha( true );