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
= {{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 int sourcelinesize
= GetBitmapData()->GetBytesPerRow() ;
1041 int destlinesize
= ret
.GetBitmapData()->GetBytesPerRow() ;
1042 unsigned char *source
= sourcedata
+ rect
.x
* 4 + rect
.y
* sourcelinesize
;
1043 unsigned char *dest
= destdata
;
1045 for (int yy
= 0; yy
< destheight
; ++yy
, source
+= sourcelinesize
, dest
+= destlinesize
)
1047 memcpy( dest
, source
, destlinesize
) ;
1051 ret
.EndRawAccess() ;
1053 if ( M_BITMAPDATA
->m_bitmapMask
)
1055 wxMemoryBuffer maskbuf
;
1056 int rowBytes
= GetBestBytesPerRow( destwidth
* kMaskBytesPerPixel
);
1057 size_t maskbufsize
= rowBytes
* destheight
;
1059 int sourcelinesize
= M_BITMAPDATA
->m_bitmapMask
->GetBytesPerRow() ;
1060 int destlinesize
= rowBytes
;
1062 unsigned char *source
= (unsigned char *) M_BITMAPDATA
->m_bitmapMask
->GetRawAccess() ;
1063 unsigned char *destdata
= (unsigned char * ) maskbuf
.GetWriteBuf( maskbufsize
) ;
1064 wxASSERT( (source
!= NULL
) && (destdata
!= NULL
) ) ;
1066 source
+= rect
.x
* kMaskBytesPerPixel
+ rect
.y
* sourcelinesize
;
1067 unsigned char *dest
= destdata
;
1069 for (int yy
= 0; yy
< destheight
; ++yy
, source
+= sourcelinesize
, dest
+= destlinesize
)
1071 memcpy( dest
, source
, destlinesize
) ;
1074 maskbuf
.UngetWriteBuf( maskbufsize
) ;
1075 ret
.SetMask( new wxMask( maskbuf
, destwidth
, destheight
, rowBytes
) ) ;
1077 else if ( HasAlpha() )
1083 bool wxBitmap::Create(int w
, int h
, int d
)
1088 d
= wxDisplayDepth() ;
1090 m_refData
= new wxBitmapRefData( w
, h
, d
);
1092 return M_BITMAPDATA
->IsOk() ;
1096 bool wxBitmap::Create(CGImageRef image
)
1100 m_refData
= new wxBitmapRefData( image
);
1102 return M_BITMAPDATA
->IsOk() ;
1105 bool wxBitmap::LoadFile(const wxString
& filename
, wxBitmapType type
)
1109 wxBitmapHandler
*handler
= FindHandler(type
);
1113 m_refData
= new wxBitmapRefData
;
1115 return handler
->LoadFile(this, filename
, type
, -1, -1);
1120 wxImage
loadimage(filename
, type
);
1121 if (loadimage
.IsOk())
1130 wxLogWarning(wxT("no bitmap handler for type %d defined."), type
);
1135 bool wxBitmap::Create(const void* data
, wxBitmapType type
, int width
, int height
, int depth
)
1139 m_refData
= new wxBitmapRefData
;
1141 wxBitmapHandler
*handler
= FindHandler(type
);
1143 if ( handler
== NULL
)
1145 wxLogWarning(wxT("no bitmap handler for type %d defined."), type
);
1150 return handler
->Create(this, data
, type
, width
, height
, depth
);
1155 wxBitmap::wxBitmap(const wxImage
& image
, int depth
)
1157 wxCHECK_RET( image
.IsOk(), wxT("invalid image") );
1159 // width and height of the device-dependent bitmap
1160 int width
= image
.GetWidth();
1161 int height
= image
.GetHeight();
1163 wxBitmapRefData
* bitmapRefData
;
1165 m_refData
= bitmapRefData
= new wxBitmapRefData( width
, height
, depth
) ;
1167 if ( bitmapRefData
->IsOk())
1171 bool hasAlpha
= false ;
1173 if ( image
.HasMask() )
1175 // takes precedence, don't mix with alpha info
1179 hasAlpha
= image
.HasAlpha() ;
1185 unsigned char* destinationstart
= (unsigned char*) BeginRawAccess() ;
1186 register unsigned char* data
= image
.GetData();
1187 if ( destinationstart
!= NULL
&& data
!= NULL
)
1189 const unsigned char *alpha
= hasAlpha
? image
.GetAlpha() : NULL
;
1190 for (int y
= 0; y
< height
; destinationstart
+= M_BITMAPDATA
->GetBytesPerRow(), y
++)
1192 unsigned char * destination
= destinationstart
;
1193 for (int x
= 0; x
< width
; x
++)
1197 const unsigned char a
= *alpha
++;
1198 *destination
++ = a
;
1200 #if wxOSX_USE_PREMULTIPLIED_ALPHA
1201 *destination
++ = ((*data
++) * a
+ 127) / 255 ;
1202 *destination
++ = ((*data
++) * a
+ 127) / 255 ;
1203 *destination
++ = ((*data
++) * a
+ 127) / 255 ;
1205 *destination
++ = *data
++ ;
1206 *destination
++ = *data
++ ;
1207 *destination
++ = *data
++ ;
1212 *destination
++ = 0xFF ;
1213 *destination
++ = *data
++ ;
1214 *destination
++ = *data
++ ;
1215 *destination
++ = *data
++ ;
1222 if ( image
.HasMask() )
1223 SetMask( new wxMask( *this , wxColour( image
.GetMaskRed() , image
.GetMaskGreen() , image
.GetMaskBlue() ) ) ) ;
1224 } /* bitmapRefData->IsOk() */
1227 wxImage
wxBitmap::ConvertToImage() const
1231 wxCHECK_MSG( IsOk(), wxNullImage
, wxT("invalid bitmap") );
1233 // create an wxImage object
1234 int width
= GetWidth();
1235 int height
= GetHeight();
1236 image
.Create( width
, height
);
1238 unsigned char *data
= image
.GetData();
1239 wxCHECK_MSG( data
, wxNullImage
, wxT("Could not allocate data for image") );
1241 unsigned char* sourcestart
= (unsigned char*) GetRawAccess() ;
1243 bool hasAlpha
= false ;
1244 bool hasMask
= false ;
1245 int maskBytesPerRow
= 0 ;
1246 unsigned char *alpha
= NULL
;
1247 unsigned char *mask
= NULL
;
1255 mask
= (unsigned char*) GetMask()->GetRawAccess() ;
1256 maskBytesPerRow
= GetMask()->GetBytesPerRow() ;
1262 alpha
= image
.GetAlpha() ;
1267 // The following masking algorithm is the same as well in msw/gtk:
1268 // the colour used as transparent one in wxImage and the one it is
1269 // replaced with when it actually occurs in the bitmap
1270 static const int MASK_RED
= 1;
1271 static const int MASK_GREEN
= 2;
1272 static const int MASK_BLUE
= 3;
1273 static const int MASK_BLUE_REPLACEMENT
= 2;
1275 for (int yy
= 0; yy
< height
; yy
++ , sourcestart
+= M_BITMAPDATA
->GetBytesPerRow() , mask
+= maskBytesPerRow
)
1277 unsigned char * maskp
= mask
;
1278 unsigned char * source
= sourcestart
;
1279 unsigned char a
, r
, g
, b
;
1282 for (int xx
= 0; xx
< width
; xx
++)
1284 color
= *((long*) source
) ;
1285 #ifdef WORDS_BIGENDIAN
1286 a
= ((color
&0xFF000000) >> 24) ;
1287 r
= ((color
&0x00FF0000) >> 16) ;
1288 g
= ((color
&0x0000FF00) >> 8) ;
1289 b
= (color
&0x000000FF);
1291 b
= ((color
&0xFF000000) >> 24) ;
1292 g
= ((color
&0x00FF0000) >> 16) ;
1293 r
= ((color
&0x0000FF00) >> 8) ;
1294 a
= (color
&0x000000FF);
1298 if ( *maskp
++ == 0xFF )
1304 else if ( r
== MASK_RED
&& g
== MASK_GREEN
&& b
== MASK_BLUE
)
1305 b
= MASK_BLUE_REPLACEMENT
;
1307 else if ( hasAlpha
)
1310 #if wxOSX_USE_PREMULTIPLIED_ALPHA
1311 // this must be non-premultiplied data
1312 if ( a
!= 0xFF && a
!= 0 )
1322 data
[index
+ 1] = g
;
1323 data
[index
+ 2] = b
;
1331 image
.SetMaskColour( MASK_RED
, MASK_GREEN
, MASK_BLUE
);
1336 #endif //wxUSE_IMAGE
1338 bool wxBitmap::SaveFile( const wxString
& filename
,
1339 wxBitmapType type
, const wxPalette
*palette
) const
1341 bool success
= false;
1342 wxBitmapHandler
*handler
= FindHandler(type
);
1346 success
= handler
->SaveFile(this, filename
, type
, palette
);
1351 wxImage image
= ConvertToImage();
1352 success
= image
.SaveFile(filename
, type
);
1354 wxLogWarning(wxT("no bitmap handler for type %d defined."), type
);
1361 int wxBitmap::GetHeight() const
1363 wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") );
1365 return M_BITMAPDATA
->GetHeight();
1368 int wxBitmap::GetWidth() const
1370 wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") );
1372 return M_BITMAPDATA
->GetWidth() ;
1375 int wxBitmap::GetDepth() const
1377 wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") );
1379 return M_BITMAPDATA
->GetDepth();
1382 wxMask
*wxBitmap::GetMask() const
1384 wxCHECK_MSG( IsOk(), NULL
, wxT("invalid bitmap") );
1386 return M_BITMAPDATA
->m_bitmapMask
;
1389 bool wxBitmap::HasAlpha() const
1391 wxCHECK_MSG( IsOk(), false , wxT("invalid bitmap") );
1393 return M_BITMAPDATA
->HasAlpha() ;
1396 void wxBitmap::SetWidth(int w
)
1399 M_BITMAPDATA
->SetWidth(w
);
1402 void wxBitmap::SetHeight(int h
)
1405 M_BITMAPDATA
->SetHeight(h
);
1408 void wxBitmap::SetDepth(int d
)
1411 M_BITMAPDATA
->SetDepth(d
);
1414 void wxBitmap::SetOk(bool isOk
)
1417 M_BITMAPDATA
->SetOk(isOk
);
1421 wxPalette
*wxBitmap::GetPalette() const
1423 wxCHECK_MSG( IsOk(), NULL
, wxT("Invalid bitmap GetPalette()") );
1425 return &M_BITMAPDATA
->m_bitmapPalette
;
1428 void wxBitmap::SetPalette(const wxPalette
& palette
)
1431 M_BITMAPDATA
->m_bitmapPalette
= palette
;
1433 #endif // wxUSE_PALETTE
1435 void wxBitmap::SetMask(wxMask
*mask
)
1438 // Remove existing mask if there is one.
1439 delete M_BITMAPDATA
->m_bitmapMask
;
1441 M_BITMAPDATA
->m_bitmapMask
= mask
;
1444 WXHBITMAP
wxBitmap::GetHBITMAP(WXHBITMAP
* mask
) const
1448 return WXHBITMAP(M_BITMAPDATA
->GetBitmapContext());
1451 // ----------------------------------------------------------------------------
1453 // ----------------------------------------------------------------------------
1460 wxMask::wxMask(const wxMask
&tocopy
) : wxObject()
1464 m_bytesPerRow
= tocopy
.m_bytesPerRow
;
1465 m_width
= tocopy
.m_width
;
1466 m_height
= tocopy
.m_height
;
1468 size_t size
= m_bytesPerRow
* m_height
;
1469 unsigned char* dest
= (unsigned char*)m_memBuf
.GetWriteBuf( size
);
1470 unsigned char* source
= (unsigned char*)tocopy
.m_memBuf
.GetData();
1471 memcpy( dest
, source
, size
);
1472 m_memBuf
.UngetWriteBuf( size
) ;
1476 // Construct a mask from a bitmap and a colour indicating
1477 // the transparent area
1478 wxMask::wxMask( const wxBitmap
& bitmap
, const wxColour
& colour
)
1481 Create( bitmap
, colour
);
1484 // Construct a mask from a mono bitmap (copies the bitmap).
1485 wxMask::wxMask( const wxBitmap
& bitmap
)
1491 // Construct a mask from a mono bitmap (copies the bitmap).
1493 wxMask::wxMask( const wxMemoryBuffer
& data
, int width
, int height
, int bytesPerRow
)
1496 Create( data
, width
, height
, bytesPerRow
);
1503 CGContextRelease( (CGContextRef
) m_maskBitmap
);
1504 m_maskBitmap
= NULL
;
1510 m_width
= m_height
= m_bytesPerRow
= 0 ;
1511 m_maskBitmap
= NULL
;
1514 void *wxMask::GetRawAccess() const
1516 return m_memBuf
.GetData() ;
1519 // The default ColorTable for k8IndexedGrayPixelFormat in Intel appears to be broken, so we'll use an non-indexed
1520 // bitmap mask instead; in order to keep the code simple, the change applies to PowerPC implementations as well
1522 void wxMask::RealizeNative()
1526 CGContextRelease( (CGContextRef
) m_maskBitmap
);
1527 m_maskBitmap
= NULL
;
1530 CGColorSpaceRef colorspace
= CGColorSpaceCreateDeviceGray();
1531 // from MouseTracking sample :
1532 // Ironically, due to a bug in CGImageCreateWithMask, you cannot use
1533 // CGColorSpaceCreateWithName(kCGColorSpaceGenericGray) at this point!
1535 m_maskBitmap
= CGBitmapContextCreate((char*) m_memBuf
.GetData(), m_width
, m_height
, 8, m_bytesPerRow
, colorspace
,
1536 kCGImageAlphaNone
);
1537 CGColorSpaceRelease( colorspace
);
1538 wxASSERT_MSG( m_maskBitmap
, wxT("Unable to create CGBitmapContext context") ) ;
1541 // Create a mask from a mono bitmap (copies the bitmap).
1543 bool wxMask::Create(const wxMemoryBuffer
& data
,int width
, int height
, int bytesPerRow
)
1548 m_bytesPerRow
= bytesPerRow
;
1550 wxASSERT( data
.GetDataLen() == (size_t)(height
* bytesPerRow
) ) ;
1557 // Create a mask from a mono bitmap (copies the bitmap).
1558 bool wxMask::Create(const wxBitmap
& bitmap
)
1560 m_width
= bitmap
.GetWidth() ;
1561 m_height
= bitmap
.GetHeight() ;
1562 m_bytesPerRow
= GetBestBytesPerRow( m_width
* kMaskBytesPerPixel
) ;
1564 size_t size
= m_bytesPerRow
* m_height
;
1565 unsigned char * destdatabase
= (unsigned char*) m_memBuf
.GetWriteBuf( size
) ;
1566 wxASSERT( destdatabase
!= NULL
) ;
1570 memset( destdatabase
, 0 , size
) ;
1571 unsigned char * srcdata
= (unsigned char*) bitmap
.GetRawAccess() ;
1573 for ( int y
= 0 ; y
< m_height
; ++y
, destdatabase
+= m_bytesPerRow
)
1575 unsigned char *destdata
= destdatabase
;
1576 unsigned char r
, g
, b
;
1578 for ( int x
= 0 ; x
< m_width
; ++x
)
1585 if ( ( r
+ g
+ b
) > 0x10 )
1586 *destdata
++ = 0xFF ;
1588 *destdata
++ = 0x00 ;
1593 m_memBuf
.UngetWriteBuf( size
) ;
1599 // Create a mask from a bitmap and a colour indicating
1600 // the transparent area
1601 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
1603 m_width
= bitmap
.GetWidth() ;
1604 m_height
= bitmap
.GetHeight() ;
1605 m_bytesPerRow
= GetBestBytesPerRow( m_width
* kMaskBytesPerPixel
) ;
1607 size_t size
= m_bytesPerRow
* m_height
;
1608 unsigned char * destdatabase
= (unsigned char*) m_memBuf
.GetWriteBuf( size
) ;
1609 wxASSERT( destdatabase
!= NULL
) ;
1611 memset( destdatabase
, 0 , size
) ;
1612 unsigned char * srcdatabase
= (unsigned char*) bitmap
.GetRawAccess() ;
1613 size_t sourceBytesRow
= bitmap
.GetBitmapData()->GetBytesPerRow();
1615 for ( int y
= 0 ; y
< m_height
; ++y
, srcdatabase
+= sourceBytesRow
, destdatabase
+= m_bytesPerRow
)
1617 unsigned char *srcdata
= srcdatabase
;
1618 unsigned char *destdata
= destdatabase
;
1619 unsigned char r
, g
, b
;
1621 for ( int x
= 0 ; x
< m_width
; ++x
)
1628 if ( colour
== wxColour( r
, g
, b
) )
1629 *destdata
++ = 0xFF ;
1631 *destdata
++ = 0x00 ;
1635 m_memBuf
.UngetWriteBuf( size
) ;
1641 WXHBITMAP
wxMask::GetHBITMAP() const
1643 return m_maskBitmap
;
1646 // ----------------------------------------------------------------------------
1647 // Standard Handlers
1648 // ----------------------------------------------------------------------------
1650 class WXDLLEXPORT wxBundleResourceHandler
: public wxBitmapHandler
1652 DECLARE_ABSTRACT_CLASS(wxBundleResourceHandler
)
1655 inline wxBundleResourceHandler()
1659 virtual bool LoadFile(wxBitmap
*bitmap
,
1660 const wxString
& name
,
1666 IMPLEMENT_ABSTRACT_CLASS(wxBundleResourceHandler
, wxBitmapHandler
);
1668 class WXDLLEXPORT wxPNGResourceHandler
: public wxBundleResourceHandler
1670 DECLARE_DYNAMIC_CLASS(wxPNGResourceHandler
)
1673 inline wxPNGResourceHandler()
1675 SetName(wxT("PNG resource"));
1676 SetExtension("PNG");
1677 SetType(wxBITMAP_TYPE_PNG_RESOURCE
);
1681 IMPLEMENT_DYNAMIC_CLASS(wxPNGResourceHandler
, wxBundleResourceHandler
)
1683 class WXDLLEXPORT wxJPEGResourceHandler
: public wxBundleResourceHandler
1685 DECLARE_DYNAMIC_CLASS(wxPNGResourceHandler
)
1688 inline wxJPEGResourceHandler()
1690 SetName(wxT("JPEG resource"));
1691 SetExtension("JPEG");
1692 SetType(wxBITMAP_TYPE_JPEG_RESOURCE
);
1696 IMPLEMENT_DYNAMIC_CLASS(wxJPEGResourceHandler
, wxBundleResourceHandler
)
1698 bool wxBundleResourceHandler::LoadFile(wxBitmap
*bitmap
,
1699 const wxString
& name
,
1700 wxBitmapType
WXUNUSED(type
),
1701 int WXUNUSED(desiredWidth
),
1702 int WXUNUSED(desiredHeight
))
1704 wxString ext
= GetExtension().Lower();
1705 wxCFStringRef
resname(name
);
1706 wxCFStringRef
restype(ext
);
1708 wxCFRef
<CFURLRef
> imageURL(CFBundleCopyResourceURL(CFBundleGetMainBundle(), resname
, restype
, NULL
));
1710 if ( imageURL
.get() != NULL
)
1712 // Create the data provider object
1713 wxCFRef
<CGDataProviderRef
> provider(CGDataProviderCreateWithURL (imageURL
) );
1714 CGImageRef image
= NULL
;
1716 if ( ext
== "jpeg" )
1717 image
= CGImageCreateWithJPEGDataProvider (provider
, NULL
, true,
1718 kCGRenderingIntentDefault
);
1719 else if ( ext
== "png" )
1720 image
= CGImageCreateWithPNGDataProvider (provider
, NULL
, true,
1721 kCGRenderingIntentDefault
);
1722 if ( image
!= NULL
)
1724 bitmap
->Create(image
);
1725 CGImageRelease(image
);
1732 void wxBitmap::InitStandardHandlers()
1734 #if wxOSX_USE_COCOA_OR_CARBON
1735 AddHandler( new wxICONResourceHandler
) ;
1737 AddHandler( new wxPNGResourceHandler
);
1738 AddHandler( new wxJPEGResourceHandler
);
1741 // ----------------------------------------------------------------------------
1742 // raw bitmap access support
1743 // ----------------------------------------------------------------------------
1745 void *wxBitmap::GetRawData(wxPixelDataBase
& data
, int WXUNUSED(bpp
))
1748 // no bitmap, no data (raw or otherwise)
1751 data
.m_width
= GetWidth() ;
1752 data
.m_height
= GetHeight() ;
1753 data
.m_stride
= GetBitmapData()->GetBytesPerRow() ;
1755 return BeginRawAccess() ;
1758 void wxBitmap::UngetRawData(wxPixelDataBase
& WXUNUSED(dataBase
))
1763 void wxBitmap::UseAlpha()
1765 // remember that we are using alpha channel:
1766 // we'll need to create a proper mask in UngetRawData()
1767 M_BITMAPDATA
->UseAlpha( true );