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
);
61 wxBitmapRefData(const wxBitmapRefData
&tocopy
);
63 virtual ~wxBitmapRefData();
65 virtual bool IsOk() const { return m_ok
; }
68 void SetOk( bool isOk
) { m_ok
= isOk
; }
70 void SetWidth( int width
) { m_width
= width
; }
71 void SetHeight( int height
) { m_height
= height
; }
72 void SetDepth( int depth
) { m_depth
= depth
; }
74 int GetWidth() const { return m_width
; }
75 int GetHeight() const { return m_height
; }
76 int GetDepth() const { return m_depth
; }
78 void *GetRawAccess() const;
79 void *BeginRawAccess();
82 bool HasAlpha() const { return m_hasAlpha
; }
83 void UseAlpha( bool useAlpha
);
87 wxPalette m_bitmapPalette
;
88 #endif // wxUSE_PALETTE
90 wxMask
* m_bitmapMask
; // Optional mask
91 CGImageRef
CreateCGImage() const;
93 // returns true if the bitmap has a size that
94 // can be natively transferred into a true icon
95 // if no is returned GetIconRef will still produce
96 // an icon but it will be generated via a PICT and
97 // rescaled to 16 x 16
100 // caller should increase ref count if needed longer
101 // than the bitmap exists
102 IconRef
GetIconRef();
104 #ifndef __WXOSX_IPHONE__
105 // returns a Pict from the bitmap content
106 PicHandle
GetPictHandle();
109 CGContextRef
GetBitmapContext() const;
111 int GetBytesPerRow() const { return m_bytesPerRow
; }
113 bool Create(int width
, int height
, int depth
);
121 wxMemoryBuffer m_memBuf
;
122 int m_rawAccessCount
;
124 mutable CGImageRef m_cgImageRef
;
127 #ifndef __WXOSX_IPHONE__
128 PicHandle m_pictHandle
;
130 CGContextRef m_hBitmap
;
134 #define wxOSX_USE_PREMULTIPLIED_ALPHA 1
135 static const int kBestByteAlignement
= 16;
136 static const int kMaskBytesPerPixel
= 1;
138 static int GetBestBytesPerRow( int rawBytes
)
140 return (((rawBytes
)+kBestByteAlignement
-1) & ~(kBestByteAlignement
-1) );
143 #if wxUSE_GUI && !defined(__WXOSX_IPHONE__)
145 // this is used for more controls than just the wxBitmap button, also for notebooks etc
147 void wxMacCreateBitmapButton( ControlButtonContentInfo
*info
, const wxBitmap
& bitmap
, int forceType
)
149 memset( info
, 0 , sizeof(ControlButtonContentInfo
) ) ;
152 wxBitmapRefData
* bmap
= bitmap
.GetBitmapData() ;
156 if ( forceType
== 0 )
158 forceType
= kControlContentCGImageRef
;
161 if ( forceType
== kControlContentIconRef
)
164 wxBitmapRefData
* bmp
= bmap
;
166 if ( !bmap
->HasNativeSize() )
168 // as PICT conversion will only result in a 16x16 icon, let's attempt
169 // a few scales for better results
171 int w
= bitmap
.GetWidth() ;
172 int h
= bitmap
.GetHeight() ;
173 int sz
= wxMax( w
, h
) ;
174 if ( sz
== 24 || sz
== 64 )
176 scaleBmp
= wxBitmap( bitmap
.ConvertToImage().Scale( w
* 2 , h
* 2 ) ) ;
177 bmp
= scaleBmp
.GetBitmapData() ;
181 info
->contentType
= kControlContentIconRef
;
182 info
->u
.iconRef
= bmp
->GetIconRef() ;
183 AcquireIconRef( info
->u
.iconRef
) ;
185 else if ( forceType
== kControlContentCGImageRef
)
187 info
->contentType
= kControlContentCGImageRef
;
188 info
->u
.imageRef
= (CGImageRef
) bmap
->CreateCGImage() ;
193 info
->contentType
= kControlContentPictHandle
;
194 info
->u
.picture
= bmap
->GetPictHandle() ;
200 CGImageRef
wxMacCreateCGImageFromBitmap( const wxBitmap
& bitmap
)
202 wxBitmapRefData
* bmap
= bitmap
.GetBitmapData() ;
205 return (CGImageRef
) bmap
->CreateCGImage();
208 void wxMacReleaseBitmapButton( ControlButtonContentInfo
*info
)
210 if ( info
->contentType
== kControlContentIconRef
)
212 ReleaseIconRef( info
->u
.iconRef
) ;
214 else if ( info
->contentType
== kControlNoContent
)
216 // there's no bitmap at all, fall through silently
218 else if ( info
->contentType
== kControlContentPictHandle
)
220 // owned by the bitmap, no release here
222 else if ( info
->contentType
== kControlContentCGImageRef
)
224 CGImageRelease( info
->u
.imageRef
) ;
228 wxFAIL_MSG(wxT("Unexpected bitmap type") ) ;
232 #endif //wxUSE_BMPBUTTON
234 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
236 void wxBitmapRefData::Init()
243 m_bitmapMask
= NULL
;
244 m_cgImageRef
= NULL
;
246 #ifndef __WXOSX_IPHONE__
248 m_pictHandle
= NULL
;
252 m_rawAccessCount
= 0 ;
256 wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData
&tocopy
)
259 Create(tocopy
.m_width
, tocopy
.m_height
, tocopy
.m_depth
);
261 if (tocopy
.m_bitmapMask
)
262 m_bitmapMask
= new wxMask(*tocopy
.m_bitmapMask
);
263 else if (tocopy
.m_hasAlpha
)
266 unsigned char* dest
= (unsigned char*)GetRawAccess();
267 unsigned char* source
= (unsigned char*)tocopy
.GetRawAccess();
268 size_t numbytes
= m_bytesPerRow
* m_height
;
269 memcpy( dest
, source
, numbytes
);
272 wxBitmapRefData::wxBitmapRefData()
277 wxBitmapRefData::wxBitmapRefData( int w
, int h
, int d
)
280 Create( w
, h
, d
) ;
283 bool wxBitmapRefData::Create( int w
, int h
, int d
)
285 m_width
= wxMax(1, w
);
286 m_height
= wxMax(1, h
);
290 m_bytesPerRow
= GetBestBytesPerRow( w
* 4 ) ;
291 size_t size
= m_bytesPerRow
* h
;
292 void* data
= m_memBuf
.GetWriteBuf( size
) ;
295 memset( data
, 0 , size
) ;
296 m_memBuf
.UngetWriteBuf( size
) ;
298 m_hBitmap
= CGBitmapContextCreate((char*) data
, m_width
, m_height
, 8, m_bytesPerRow
, wxMacGetGenericRGBColorSpace(), kCGImageAlphaNoneSkipFirst
);
299 wxASSERT_MSG( m_hBitmap
, wxT("Unable to create CGBitmapContext context") ) ;
300 CGContextTranslateCTM( m_hBitmap
, 0, m_height
);
301 CGContextScaleCTM( m_hBitmap
, 1, -1 );
303 m_ok
= ( m_hBitmap
!= NULL
) ;
308 void wxBitmapRefData::UseAlpha( bool use
)
310 if ( m_hasAlpha
== use
)
315 CGContextRelease( m_hBitmap
);
316 m_hBitmap
= CGBitmapContextCreate((char*) m_memBuf
.GetData(), m_width
, m_height
, 8, m_bytesPerRow
, wxMacGetGenericRGBColorSpace(), m_hasAlpha
? kCGImageAlphaPremultipliedFirst
: kCGImageAlphaNoneSkipFirst
);
317 wxASSERT_MSG( m_hBitmap
, wxT("Unable to create CGBitmapContext context") ) ;
318 CGContextTranslateCTM( m_hBitmap
, 0, m_height
);
319 CGContextScaleCTM( m_hBitmap
, 1, -1 );
322 void *wxBitmapRefData::GetRawAccess() const
324 wxCHECK_MSG( IsOk(), NULL
, wxT("invalid bitmap") ) ;
325 return m_memBuf
.GetData() ;
328 void *wxBitmapRefData::BeginRawAccess()
330 wxCHECK_MSG( IsOk(), NULL
, wxT("invalid bitmap") ) ;
331 wxASSERT( m_rawAccessCount
== 0 ) ;
332 #ifndef __WXOSX_IPHONE__
333 wxASSERT_MSG( m_pictHandle
== NULL
&& m_iconRef
== NULL
,
334 wxT("Currently, modifing bitmaps that are used in controls already is not supported") ) ;
338 // we must destroy an existing cached image, as
339 // the bitmap data may change now
342 CGImageRelease( m_cgImageRef
) ;
343 m_cgImageRef
= NULL
;
346 return m_memBuf
.GetData() ;
349 void wxBitmapRefData::EndRawAccess()
351 wxCHECK_RET( IsOk() , wxT("invalid bitmap") ) ;
352 wxASSERT( m_rawAccessCount
== 1 ) ;
357 bool wxBitmapRefData::HasNativeSize()
360 int h
= GetHeight() ;
361 int sz
= wxMax( w
, h
) ;
363 return ( sz
== 128 || sz
== 48 || sz
== 32 || sz
== 16 );
366 #ifndef __WXOSX_IPHONE__
367 IconRef
wxBitmapRefData::GetIconRef()
369 if ( m_iconRef
== NULL
)
371 // Create Icon Family Handle
373 IconFamilyHandle iconFamily
= (IconFamilyHandle
) NewHandle( 0 );
376 int h
= GetHeight() ;
377 int sz
= wxMax( w
, h
) ;
379 OSType dataType
= 0 ;
380 OSType maskType
= 0 ;
385 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
386 if ( UMAGetSystemVersion() >= 0x1050 )
388 dataType
= kIconServices128PixelDataARGB
;
393 dataType
= kThumbnail32BitData
;
394 maskType
= kThumbnail8BitMask
;
399 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
400 if ( UMAGetSystemVersion() >= 0x1050 )
402 dataType
= kIconServices48PixelDataARGB
;
407 dataType
= kHuge32BitData
;
408 maskType
= kHuge8BitMask
;
413 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
414 if ( UMAGetSystemVersion() >= 0x1050 )
416 dataType
= kIconServices32PixelDataARGB
;
421 dataType
= kLarge32BitData
;
422 maskType
= kLarge8BitMask
;
427 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
428 if ( UMAGetSystemVersion() >= 0x1050 )
430 dataType
= kIconServices16PixelDataARGB
;
435 dataType
= kSmall32BitData
;
436 maskType
= kSmall8BitMask
;
446 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
447 if ( maskType
== 0 && UMAGetSystemVersion() >= 0x1050 )
449 size_t datasize
= sz
* sz
* 4 ;
450 Handle data
= NewHandle( datasize
) ;
452 unsigned char* ptr
= (unsigned char*) *data
;
453 memset( ptr
, 0, datasize
);
454 bool hasAlpha
= HasAlpha() ;
455 wxMask
*mask
= m_bitmapMask
;
456 unsigned char * sourcePtr
= (unsigned char*) GetRawAccess() ;
457 unsigned char * masksourcePtr
= mask
? (unsigned char*) mask
->GetRawAccess() : NULL
;
459 for ( int y
= 0 ; y
< h
; ++y
, sourcePtr
+= m_bytesPerRow
, masksourcePtr
+= mask
? mask
->GetBytesPerRow() : 0 )
461 unsigned char * source
= sourcePtr
;
462 unsigned char * masksource
= masksourcePtr
;
463 unsigned char * dest
= ptr
+ y
* sz
* 4 ;
464 unsigned char a
, r
, g
, b
;
466 for ( int x
= 0 ; x
< w
; ++x
)
475 a
= 0xFF - *masksource
++ ;
477 else if ( !hasAlpha
)
481 #if wxOSX_USE_PREMULTIPLIED_ALPHA
482 // this must be non-premultiplied data
483 if ( a
!= 0xFF && a
!= 0 )
499 OSStatus err
= SetIconFamilyData( iconFamily
, dataType
, data
);
500 wxASSERT_MSG( err
== noErr
, wxT("Error when adding bitmap") );
501 DisposeHandle( data
);
506 // setup the header properly
509 Handle maskdata
= NULL
;
510 unsigned char * maskptr
= NULL
;
511 unsigned char * ptr
= NULL
;
512 size_t datasize
, masksize
;
514 datasize
= sz
* sz
* 4 ;
515 data
= NewHandle( datasize
) ;
517 ptr
= (unsigned char*) *data
;
518 memset( ptr
, 0, datasize
) ;
521 maskdata
= NewHandle( masksize
) ;
523 maskptr
= (unsigned char*) *maskdata
;
524 memset( maskptr
, 0 , masksize
) ;
526 bool hasAlpha
= HasAlpha() ;
527 wxMask
*mask
= m_bitmapMask
;
528 unsigned char * sourcePtr
= (unsigned char*) GetRawAccess() ;
529 unsigned char * masksourcePtr
= mask
? (unsigned char*) mask
->GetRawAccess() : NULL
;
531 for ( int y
= 0 ; y
< h
; ++y
, sourcePtr
+= m_bytesPerRow
, masksourcePtr
+= mask
? mask
->GetBytesPerRow() : 0 )
533 unsigned char * source
= sourcePtr
;
534 unsigned char * masksource
= masksourcePtr
;
535 unsigned char * dest
= ptr
+ y
* sz
* 4 ;
536 unsigned char * maskdest
= maskptr
+ y
* sz
;
537 unsigned char a
, r
, g
, b
;
539 for ( int x
= 0 ; x
< w
; ++x
)
552 *maskdest
++ = 0xFF - *masksource
++ ;
560 OSStatus err
= SetIconFamilyData( iconFamily
, dataType
, data
) ;
561 wxASSERT_MSG( err
== noErr
, wxT("Error when adding bitmap") ) ;
563 err
= SetIconFamilyData( iconFamily
, maskType
, maskdata
) ;
564 wxASSERT_MSG( err
== noErr
, wxT("Error when adding mask") ) ;
567 HUnlock( maskdata
) ;
568 DisposeHandle( data
) ;
569 DisposeHandle( maskdata
) ;
574 PicHandle pic
= GetPictHandle() ;
575 SetIconFamilyData( iconFamily
, 'PICT' , (Handle
) pic
) ;
577 // transform into IconRef
579 // cleaner version existing from 10.3 upwards
580 HLock((Handle
) iconFamily
);
581 OSStatus err
= GetIconRefFromIconFamilyPtr( *iconFamily
, GetHandleSize((Handle
) iconFamily
), &m_iconRef
);
582 HUnlock((Handle
) iconFamily
);
583 DisposeHandle( (Handle
) iconFamily
) ;
585 wxCHECK_MSG( err
== noErr
, NULL
, wxT("Error when constructing icon ref") );
591 PicHandle
wxBitmapRefData::GetPictHandle()
593 if ( m_pictHandle
== NULL
)
596 GraphicsExportComponent exporter
= 0;
597 OSStatus err
= OpenADefaultComponent(GraphicsExporterComponentType
, kQTFileTypePicture
, &exporter
);
600 m_pictHandle
= (PicHandle
) NewHandle(0);
603 // QT does not correctly export the mask
604 // TODO if we get around to it create a synthetic PICT with the CopyBits and Mask commands
605 CGImageRef imageRef
= CreateCGImage();
606 err
= GraphicsExportSetInputCGImage( exporter
, imageRef
);
607 err
= GraphicsExportSetOutputHandle(exporter
, (Handle
)m_pictHandle
);
608 err
= GraphicsExportDoExport(exporter
, NULL
);
609 CGImageRelease( imageRef
);
611 size_t handleSize
= GetHandleSize( (Handle
) m_pictHandle
);
612 // the 512 bytes header is only needed for pict files, but not in memory
613 if ( handleSize
>= 512 )
615 memmove( *m_pictHandle
, (char*)(*m_pictHandle
)+512, handleSize
- 512 );
616 SetHandleSize( (Handle
) m_pictHandle
, handleSize
- 512 );
619 CloseComponent( exporter
);
624 return m_pictHandle
;
628 CGImageRef
wxBitmapRefData::CreateCGImage() const
631 wxASSERT( m_rawAccessCount
>= 0 ) ;
633 if ( m_rawAccessCount
> 0 || m_cgImageRef
== NULL
)
635 if ( m_depth
!= 1 && m_bitmapMask
== NULL
)
639 CGImageRef tempImage
= CGBitmapContextCreateImage( m_hBitmap
);
640 CGImageRef tempMask
= CGBitmapContextCreateImage((CGContextRef
) m_bitmapMask
->GetHBITMAP() );
641 image
= CGImageCreateWithMask( tempImage
, tempMask
);
642 CGImageRelease(tempMask
);
643 CGImageRelease(tempImage
);
646 image
= CGBitmapContextCreateImage( m_hBitmap
);
650 size_t imageSize
= m_height
* m_bytesPerRow
;
651 void * dataBuffer
= m_memBuf
.GetData() ;
654 CGImageAlphaInfo alphaInfo
= kCGImageAlphaNoneSkipFirst
;
655 wxMemoryBuffer membuf
;
659 alphaInfo
= kCGImageAlphaFirst
;
660 unsigned char *destalphastart
= (unsigned char*) membuf
.GetWriteBuf( imageSize
) ;
661 memcpy( destalphastart
, dataBuffer
, imageSize
) ;
662 unsigned char *sourcemaskstart
= (unsigned char *) m_bitmapMask
->GetRawAccess() ;
663 int maskrowbytes
= m_bitmapMask
->GetBytesPerRow() ;
664 for ( int y
= 0 ; y
< h
; ++y
, destalphastart
+= m_bytesPerRow
, sourcemaskstart
+= maskrowbytes
)
666 unsigned char *sourcemask
= sourcemaskstart
;
667 unsigned char *destalpha
= destalphastart
;
668 for ( int x
= 0 ; x
< w
; ++x
, sourcemask
+= kMaskBytesPerPixel
, destalpha
+= 4 )
670 *destalpha
= 0xFF - *sourcemask
;
673 membuf
.UngetWriteBuf( imageSize
);
679 #if wxOSX_USE_PREMULTIPLIED_ALPHA
680 alphaInfo
= kCGImageAlphaPremultipliedFirst
;
682 alphaInfo
= kCGImageAlphaFirst
;
689 CGDataProviderRef dataProvider
= NULL
;
692 // TODO CHECK ALIGNMENT
693 wxMemoryBuffer maskBuf
;
694 unsigned char * maskBufData
= (unsigned char*) maskBuf
.GetWriteBuf( m_width
* m_height
);
695 unsigned char * bufData
= (unsigned char *) membuf
.GetData() ;
696 // copy one color component
698 for( int y
= 0 ; y
< m_height
; bufData
+= m_bytesPerRow
, ++y
)
700 unsigned char *bufDataIter
= bufData
+3;
701 for ( int x
= 0 ; x
< m_width
; bufDataIter
+= 4, ++x
, ++i
)
703 maskBufData
[i
] = *bufDataIter
;
706 maskBuf
.UngetWriteBuf( m_width
* m_height
);
709 wxMacCGDataProviderCreateWithMemoryBuffer( maskBuf
);
711 image
= ::CGImageMaskCreate( w
, h
, 8, 8, m_width
, dataProvider
, NULL
, false );
715 CGColorSpaceRef colorSpace
= wxMacGetGenericRGBColorSpace();
716 dataProvider
= wxMacCGDataProviderCreateWithMemoryBuffer( membuf
);
719 w
, h
, 8 , 32 , m_bytesPerRow
, colorSpace
, alphaInfo
,
720 dataProvider
, NULL
, false , kCGRenderingIntentDefault
);
722 CGDataProviderRelease( dataProvider
);
727 image
= m_cgImageRef
;
728 CGImageRetain( image
) ;
731 if ( m_rawAccessCount
== 0 && m_cgImageRef
== NULL
)
733 // we keep it for later use
734 m_cgImageRef
= image
;
735 CGImageRetain( image
) ;
741 CGContextRef
wxBitmapRefData::GetBitmapContext() const
746 void wxBitmapRefData::Free()
748 wxASSERT_MSG( m_rawAccessCount
== 0 , wxT("Bitmap still selected when destroyed") ) ;
752 CGImageRelease( m_cgImageRef
) ;
753 m_cgImageRef
= NULL
;
755 #ifndef __WXOSX_IPHONE__
758 ReleaseIconRef( m_iconRef
) ;
765 KillPicture( m_pictHandle
) ;
766 m_pictHandle
= NULL
;
772 CGContextRelease(m_hBitmap
);
783 wxBitmapRefData::~wxBitmapRefData()
788 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
790 bool created
= false ;
791 int w
= icon
.GetWidth() ;
792 int h
= icon
.GetHeight() ;
795 #ifdef __WXOSX_CARBON__
796 if ( w
== h
&& ( w
== 16 || w
== 32 || w
== 48 || w
== 128 ) )
798 IconFamilyHandle iconFamily
= NULL
;
799 Handle imagehandle
= NewHandle( 0 ) ;
800 Handle maskhandle
= NewHandle( 0 ) ;
804 IconSelectorValue selector
= 0 ;
809 dataType
= kThumbnail32BitData
;
810 maskType
= kThumbnail8BitMask
;
811 selector
= kSelectorAllAvailableData
;
815 dataType
= kHuge32BitData
;
816 maskType
= kHuge8BitMask
;
817 selector
= kSelectorHuge32Bit
| kSelectorHuge8BitMask
;
821 dataType
= kLarge32BitData
;
822 maskType
= kLarge8BitMask
;
823 selector
= kSelectorLarge32Bit
| kSelectorLarge8BitMask
;
827 dataType
= kSmall32BitData
;
828 maskType
= kSmall8BitMask
;
829 selector
= kSelectorSmall32Bit
| kSelectorSmall8BitMask
;
836 OSStatus err
= IconRefToIconFamily( MAC_WXHICON(icon
.GetHICON()) , selector
, &iconFamily
) ;
838 err
= GetIconFamilyData( iconFamily
, dataType
, imagehandle
) ;
839 err
= GetIconFamilyData( iconFamily
, maskType
, maskhandle
) ;
840 size_t imagehandlesize
= GetHandleSize( imagehandle
) ;
841 size_t maskhandlesize
= GetHandleSize( maskhandle
) ;
843 if ( imagehandlesize
!= 0 && maskhandlesize
!= 0 )
845 wxASSERT( GetHandleSize( imagehandle
) == w
* 4 * h
) ;
846 wxASSERT( GetHandleSize( maskhandle
) == w
* h
) ;
850 unsigned char *source
= (unsigned char *) *imagehandle
;
851 unsigned char *sourcemask
= (unsigned char *) *maskhandle
;
852 unsigned char* destination
= (unsigned char*) BeginRawAccess() ;
854 for ( int y
= 0 ; y
< h
; ++y
)
856 for ( int x
= 0 ; x
< w
; ++x
)
858 unsigned char a
= *sourcemask
++;
861 #if wxOSX_USE_PREMULTIPLIED_ALPHA
862 *destination
++ = ( (*source
++) * a
+ 127 ) / 255;
863 *destination
++ = ( (*source
++) * a
+ 127 ) / 255;
864 *destination
++ = ( (*source
++) * a
+ 127 ) / 255;
866 *destination
++ = *source
++ ;
867 *destination
++ = *source
++ ;
868 *destination
++ = *source
++ ;
874 DisposeHandle( imagehandle
) ;
875 DisposeHandle( maskhandle
) ;
879 DisposeHandle( (Handle
) iconFamily
) ;
885 dc
.SelectObject( *this ) ;
886 dc
.DrawIcon( icon
, 0 , 0 ) ;
887 dc
.SelectObject( wxNullBitmap
) ;
897 wxBitmap::~wxBitmap()
901 wxBitmap::wxBitmap(const char bits
[], int the_width
, int the_height
, int no_bits
)
903 wxBitmapRefData
* bitmapRefData
;
905 m_refData
= bitmapRefData
= new wxBitmapRefData( the_width
, the_height
, no_bits
) ;
907 if (bitmapRefData
->IsOk())
911 int linesize
= ( the_width
/ (sizeof(unsigned char) * 8)) ;
912 if ( the_width
% (sizeof(unsigned char) * 8) )
913 linesize
+= sizeof(unsigned char);
915 unsigned char* linestart
= (unsigned char*) bits
;
916 unsigned char* destptr
= (unsigned char*) BeginRawAccess() ;
918 for ( int y
= 0 ; y
< the_height
; ++y
, linestart
+= linesize
, destptr
+= M_BITMAPDATA
->GetBytesPerRow() )
920 unsigned char* destination
= destptr
;
921 int index
, bit
, mask
;
923 for ( int x
= 0 ; x
< the_width
; ++x
)
929 if ( linestart
[index
] & mask
)
931 *destination
++ = 0xFF ;
938 *destination
++ = 0xFF ;
939 *destination
++ = 0xFF ;
940 *destination
++ = 0xFF ;
941 *destination
++ = 0xFF ;
950 wxFAIL_MSG(wxT("multicolor BITMAPs not yet implemented"));
952 } /* bitmapRefData->IsOk() */
955 wxBitmap::wxBitmap(int w
, int h
, int d
)
957 (void)Create(w
, h
, d
);
960 wxBitmap::wxBitmap(const void* data
, wxBitmapType type
, int width
, int height
, int depth
)
962 (void) Create(data
, type
, width
, height
, depth
);
965 wxBitmap::wxBitmap(const wxString
& filename
, wxBitmapType type
)
967 LoadFile(filename
, type
);
970 wxGDIRefData
* wxBitmap::CreateGDIRefData() const
972 return new wxBitmapRefData
;
975 wxGDIRefData
* wxBitmap::CloneGDIRefData(const wxGDIRefData
* data
) const
977 return new wxBitmapRefData(*static_cast<const wxBitmapRefData
*>(data
));
980 void * wxBitmap::GetRawAccess() const
982 wxCHECK_MSG( Ok() , NULL
, wxT("invalid bitmap") ) ;
984 return M_BITMAPDATA
->GetRawAccess() ;
987 void * wxBitmap::BeginRawAccess()
989 wxCHECK_MSG( Ok() , NULL
, wxT("invalid bitmap") ) ;
991 return M_BITMAPDATA
->BeginRawAccess() ;
994 void wxBitmap::EndRawAccess()
996 wxCHECK_RET( Ok() , wxT("invalid bitmap") ) ;
998 M_BITMAPDATA
->EndRawAccess() ;
1001 CGImageRef
wxBitmap::CreateCGImage() const
1003 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") ) ;
1005 return M_BITMAPDATA
->CreateCGImage() ;
1008 #ifndef __WXOSX_IPHONE__
1009 IconRef
wxBitmap::GetIconRef() const
1011 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") ) ;
1013 return M_BITMAPDATA
->GetIconRef() ;
1016 IconRef
wxBitmap::CreateIconRef() const
1018 IconRef icon
= GetIconRef();
1019 verify_noerr( AcquireIconRef(icon
) );
1024 #if wxOSX_USE_COCOA_OR_IPHONE
1026 WX_NSImage
wxBitmap::GetNSImage() const
1028 wxCFRef
< CGImageRef
> cgimage(CreateCGImage());
1029 return wxOSXCreateNSImageFromCGImage( cgimage
);
1034 wxBitmap
wxBitmap::GetSubBitmap(const wxRect
&rect
) const
1036 wxCHECK_MSG( Ok() &&
1037 (rect
.x
>= 0) && (rect
.y
>= 0) &&
1038 (rect
.x
+rect
.width
<= GetWidth()) &&
1039 (rect
.y
+rect
.height
<= GetHeight()),
1040 wxNullBitmap
, wxT("invalid bitmap or bitmap region") );
1042 wxBitmap
ret( rect
.width
, rect
.height
, GetDepth() );
1043 wxASSERT_MSG( ret
.Ok(), wxT("GetSubBitmap error") );
1045 int destwidth
= rect
.width
;
1046 int destheight
= rect
.height
;
1049 unsigned char *sourcedata
= (unsigned char*) GetRawAccess() ;
1050 unsigned char *destdata
= (unsigned char*) ret
.BeginRawAccess() ;
1051 wxASSERT( (sourcedata
!= NULL
) && (destdata
!= NULL
) ) ;
1053 int sourcelinesize
= GetBitmapData()->GetBytesPerRow() ;
1054 int destlinesize
= ret
.GetBitmapData()->GetBytesPerRow() ;
1055 unsigned char *source
= sourcedata
+ rect
.x
* 4 + rect
.y
* sourcelinesize
;
1056 unsigned char *dest
= destdata
;
1058 for (int yy
= 0; yy
< destheight
; ++yy
, source
+= sourcelinesize
, dest
+= destlinesize
)
1060 memcpy( dest
, source
, destlinesize
) ;
1064 ret
.EndRawAccess() ;
1066 if ( M_BITMAPDATA
->m_bitmapMask
)
1068 wxMemoryBuffer maskbuf
;
1069 int rowBytes
= GetBestBytesPerRow( destwidth
* kMaskBytesPerPixel
);
1070 size_t maskbufsize
= rowBytes
* destheight
;
1072 int sourcelinesize
= M_BITMAPDATA
->m_bitmapMask
->GetBytesPerRow() ;
1073 int destlinesize
= rowBytes
;
1075 unsigned char *source
= (unsigned char *) M_BITMAPDATA
->m_bitmapMask
->GetRawAccess() ;
1076 unsigned char *destdata
= (unsigned char * ) maskbuf
.GetWriteBuf( maskbufsize
) ;
1077 wxASSERT( (source
!= NULL
) && (destdata
!= NULL
) ) ;
1079 source
+= rect
.x
* kMaskBytesPerPixel
+ rect
.y
* sourcelinesize
;
1080 unsigned char *dest
= destdata
;
1082 for (int yy
= 0; yy
< destheight
; ++yy
, source
+= sourcelinesize
, dest
+= destlinesize
)
1084 memcpy( dest
, source
, destlinesize
) ;
1087 maskbuf
.UngetWriteBuf( maskbufsize
) ;
1088 ret
.SetMask( new wxMask( maskbuf
, destwidth
, destheight
, rowBytes
) ) ;
1090 else if ( HasAlpha() )
1096 bool wxBitmap::Create(int w
, int h
, int d
)
1101 d
= wxDisplayDepth() ;
1103 m_refData
= new wxBitmapRefData( w
, h
, d
);
1105 return M_BITMAPDATA
->IsOk() ;
1108 bool wxBitmap::LoadFile(const wxString
& filename
, wxBitmapType type
)
1112 wxBitmapHandler
*handler
= FindHandler(type
);
1116 m_refData
= new wxBitmapRefData
;
1118 return handler
->LoadFile(this, filename
, type
, -1, -1);
1123 wxImage
loadimage(filename
, type
);
1133 wxLogWarning(wxT("no bitmap handler for type %d defined."), type
);
1138 bool wxBitmap::Create(const void* data
, wxBitmapType type
, int width
, int height
, int depth
)
1142 m_refData
= new wxBitmapRefData
;
1144 wxBitmapHandler
*handler
= FindHandler(type
);
1146 if ( handler
== NULL
)
1148 wxLogWarning(wxT("no bitmap handler for type %d defined."), type
);
1153 return handler
->Create(this, data
, type
, width
, height
, depth
);
1158 wxBitmap::wxBitmap(const wxImage
& image
, int depth
)
1160 wxCHECK_RET( image
.Ok(), wxT("invalid image") );
1162 // width and height of the device-dependent bitmap
1163 int width
= image
.GetWidth();
1164 int height
= image
.GetHeight();
1166 wxBitmapRefData
* bitmapRefData
;
1168 m_refData
= bitmapRefData
= new wxBitmapRefData( width
, height
, depth
) ;
1170 if ( bitmapRefData
->IsOk())
1174 bool hasAlpha
= false ;
1176 if ( image
.HasMask() )
1178 // takes precedence, don't mix with alpha info
1182 hasAlpha
= image
.HasAlpha() ;
1188 unsigned char* destinationstart
= (unsigned char*) BeginRawAccess() ;
1189 register unsigned char* data
= image
.GetData();
1190 if ( destinationstart
!= NULL
&& data
!= NULL
)
1192 const unsigned char *alpha
= hasAlpha
? image
.GetAlpha() : NULL
;
1193 for (int y
= 0; y
< height
; destinationstart
+= M_BITMAPDATA
->GetBytesPerRow(), y
++)
1195 unsigned char * destination
= destinationstart
;
1196 for (int x
= 0; x
< width
; x
++)
1200 const unsigned char a
= *alpha
++;
1201 *destination
++ = a
;
1203 #if wxOSX_USE_PREMULTIPLIED_ALPHA
1204 *destination
++ = ((*data
++) * a
+ 127) / 255 ;
1205 *destination
++ = ((*data
++) * a
+ 127) / 255 ;
1206 *destination
++ = ((*data
++) * a
+ 127) / 255 ;
1208 *destination
++ = *data
++ ;
1209 *destination
++ = *data
++ ;
1210 *destination
++ = *data
++ ;
1215 *destination
++ = 0xFF ;
1216 *destination
++ = *data
++ ;
1217 *destination
++ = *data
++ ;
1218 *destination
++ = *data
++ ;
1225 if ( image
.HasMask() )
1226 SetMask( new wxMask( *this , wxColour( image
.GetMaskRed() , image
.GetMaskGreen() , image
.GetMaskBlue() ) ) ) ;
1227 } /* bitmapRefData->IsOk() */
1230 wxImage
wxBitmap::ConvertToImage() const
1234 wxCHECK_MSG( Ok(), wxNullImage
, wxT("invalid bitmap") );
1236 // create an wxImage object
1237 int width
= GetWidth();
1238 int height
= GetHeight();
1239 image
.Create( width
, height
);
1241 unsigned char *data
= image
.GetData();
1242 wxCHECK_MSG( data
, wxNullImage
, wxT("Could not allocate data for image") );
1244 unsigned char* sourcestart
= (unsigned char*) GetRawAccess() ;
1246 bool hasAlpha
= false ;
1247 bool hasMask
= false ;
1248 int maskBytesPerRow
= 0 ;
1249 unsigned char *alpha
= NULL
;
1250 unsigned char *mask
= NULL
;
1258 mask
= (unsigned char*) GetMask()->GetRawAccess() ;
1259 maskBytesPerRow
= GetMask()->GetBytesPerRow() ;
1265 alpha
= image
.GetAlpha() ;
1270 // The following masking algorithm is the same as well in msw/gtk:
1271 // the colour used as transparent one in wxImage and the one it is
1272 // replaced with when it actually occurs in the bitmap
1273 static const int MASK_RED
= 1;
1274 static const int MASK_GREEN
= 2;
1275 static const int MASK_BLUE
= 3;
1276 static const int MASK_BLUE_REPLACEMENT
= 2;
1278 for (int yy
= 0; yy
< height
; yy
++ , sourcestart
+= M_BITMAPDATA
->GetBytesPerRow() , mask
+= maskBytesPerRow
)
1280 unsigned char * maskp
= mask
;
1281 unsigned char * source
= sourcestart
;
1282 unsigned char a
, r
, g
, b
;
1285 for (int xx
= 0; xx
< width
; xx
++)
1287 color
= *((long*) source
) ;
1288 #ifdef WORDS_BIGENDIAN
1289 a
= ((color
&0xFF000000) >> 24) ;
1290 r
= ((color
&0x00FF0000) >> 16) ;
1291 g
= ((color
&0x0000FF00) >> 8) ;
1292 b
= (color
&0x000000FF);
1294 b
= ((color
&0xFF000000) >> 24) ;
1295 g
= ((color
&0x00FF0000) >> 16) ;
1296 r
= ((color
&0x0000FF00) >> 8) ;
1297 a
= (color
&0x000000FF);
1301 if ( *maskp
++ == 0xFF )
1307 else if ( r
== MASK_RED
&& g
== MASK_GREEN
&& b
== MASK_BLUE
)
1308 b
= MASK_BLUE_REPLACEMENT
;
1310 else if ( hasAlpha
)
1313 #if wxOSX_USE_PREMULTIPLIED_ALPHA
1314 // this must be non-premultiplied data
1315 if ( a
!= 0xFF && a
!= 0 )
1325 data
[index
+ 1] = g
;
1326 data
[index
+ 2] = b
;
1334 image
.SetMaskColour( MASK_RED
, MASK_GREEN
, MASK_BLUE
);
1339 #endif //wxUSE_IMAGE
1341 bool wxBitmap::SaveFile( const wxString
& filename
,
1342 wxBitmapType type
, const wxPalette
*palette
) const
1344 bool success
= false;
1345 wxBitmapHandler
*handler
= FindHandler(type
);
1349 success
= handler
->SaveFile(this, filename
, type
, palette
);
1354 wxImage image
= ConvertToImage();
1355 success
= image
.SaveFile(filename
, type
);
1357 wxLogWarning(wxT("no bitmap handler for type %d defined."), type
);
1364 int wxBitmap::GetHeight() const
1366 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
1368 return M_BITMAPDATA
->GetHeight();
1371 int wxBitmap::GetWidth() const
1373 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
1375 return M_BITMAPDATA
->GetWidth() ;
1378 int wxBitmap::GetDepth() const
1380 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
1382 return M_BITMAPDATA
->GetDepth();
1385 wxMask
*wxBitmap::GetMask() const
1387 wxCHECK_MSG( Ok(), (wxMask
*) NULL
, wxT("invalid bitmap") );
1389 return M_BITMAPDATA
->m_bitmapMask
;
1392 bool wxBitmap::HasAlpha() const
1394 wxCHECK_MSG( Ok(), false , wxT("invalid bitmap") );
1396 return M_BITMAPDATA
->HasAlpha() ;
1399 void wxBitmap::SetWidth(int w
)
1402 M_BITMAPDATA
->SetWidth(w
);
1405 void wxBitmap::SetHeight(int h
)
1408 M_BITMAPDATA
->SetHeight(h
);
1411 void wxBitmap::SetDepth(int d
)
1414 M_BITMAPDATA
->SetDepth(d
);
1417 void wxBitmap::SetOk(bool isOk
)
1420 M_BITMAPDATA
->SetOk(isOk
);
1424 wxPalette
*wxBitmap::GetPalette() const
1426 wxCHECK_MSG( Ok(), NULL
, wxT("Invalid bitmap GetPalette()") );
1428 return &M_BITMAPDATA
->m_bitmapPalette
;
1431 void wxBitmap::SetPalette(const wxPalette
& palette
)
1434 M_BITMAPDATA
->m_bitmapPalette
= palette
;
1436 #endif // wxUSE_PALETTE
1438 void wxBitmap::SetMask(wxMask
*mask
)
1441 // Remove existing mask if there is one.
1442 delete M_BITMAPDATA
->m_bitmapMask
;
1444 M_BITMAPDATA
->m_bitmapMask
= mask
;
1447 WXHBITMAP
wxBitmap::GetHBITMAP(WXHBITMAP
* mask
) const
1451 return WXHBITMAP(M_BITMAPDATA
->GetBitmapContext());
1454 // ----------------------------------------------------------------------------
1456 // ----------------------------------------------------------------------------
1463 wxMask::wxMask(const wxMask
&tocopy
)
1467 m_bytesPerRow
= tocopy
.m_bytesPerRow
;
1468 m_width
= tocopy
.m_width
;
1469 m_height
= tocopy
.m_height
;
1471 size_t size
= m_bytesPerRow
* m_height
;
1472 unsigned char* dest
= (unsigned char*)m_memBuf
.GetWriteBuf( size
);
1473 unsigned char* source
= (unsigned char*)tocopy
.m_memBuf
.GetData();
1474 memcpy( dest
, source
, size
);
1475 m_memBuf
.UngetWriteBuf( size
) ;
1479 // Construct a mask from a bitmap and a colour indicating
1480 // the transparent area
1481 wxMask::wxMask( const wxBitmap
& bitmap
, const wxColour
& colour
)
1484 Create( bitmap
, colour
);
1487 // Construct a mask from a mono bitmap (copies the bitmap).
1488 wxMask::wxMask( const wxBitmap
& bitmap
)
1494 // Construct a mask from a mono bitmap (copies the bitmap).
1496 wxMask::wxMask( const wxMemoryBuffer
& data
, int width
, int height
, int bytesPerRow
)
1499 Create( data
, width
, height
, bytesPerRow
);
1506 CGContextRelease( (CGContextRef
) m_maskBitmap
);
1507 m_maskBitmap
= NULL
;
1513 m_width
= m_height
= m_bytesPerRow
= 0 ;
1514 m_maskBitmap
= NULL
;
1517 void *wxMask::GetRawAccess() const
1519 return m_memBuf
.GetData() ;
1522 // The default ColorTable for k8IndexedGrayPixelFormat in Intel appears to be broken, so we'll use an non-indexed
1523 // bitmap mask instead; in order to keep the code simple, the change applies to PowerPC implementations as well
1525 void wxMask::RealizeNative()
1529 CGContextRelease( (CGContextRef
) m_maskBitmap
);
1530 m_maskBitmap
= NULL
;
1533 CGColorSpaceRef colorspace
= CGColorSpaceCreateDeviceGray();
1534 // from MouseTracking sample :
1535 // Ironically, due to a bug in CGImageCreateWithMask, you cannot use
1536 // CGColorSpaceCreateWithName(kCGColorSpaceGenericGray) at this point!
1538 m_maskBitmap
= CGBitmapContextCreate((char*) m_memBuf
.GetData(), m_width
, m_height
, 8, m_bytesPerRow
, colorspace
,
1539 kCGImageAlphaNone
);
1540 CGColorSpaceRelease( colorspace
);
1541 wxASSERT_MSG( m_maskBitmap
, wxT("Unable to create CGBitmapContext context") ) ;
1544 // Create a mask from a mono bitmap (copies the bitmap).
1546 bool wxMask::Create(const wxMemoryBuffer
& data
,int width
, int height
, int bytesPerRow
)
1551 m_bytesPerRow
= bytesPerRow
;
1553 wxASSERT( data
.GetDataLen() == (size_t)(height
* bytesPerRow
) ) ;
1560 // Create a mask from a mono bitmap (copies the bitmap).
1561 bool wxMask::Create(const wxBitmap
& bitmap
)
1563 m_width
= bitmap
.GetWidth() ;
1564 m_height
= bitmap
.GetHeight() ;
1565 m_bytesPerRow
= GetBestBytesPerRow( m_width
* kMaskBytesPerPixel
) ;
1567 size_t size
= m_bytesPerRow
* m_height
;
1568 unsigned char * destdatabase
= (unsigned char*) m_memBuf
.GetWriteBuf( size
) ;
1569 wxASSERT( destdatabase
!= NULL
) ;
1571 memset( destdatabase
, 0 , size
) ;
1572 unsigned char * srcdata
= (unsigned char*) bitmap
.GetRawAccess() ;
1574 for ( int y
= 0 ; y
< m_height
; ++y
, destdatabase
+= m_bytesPerRow
)
1576 unsigned char *destdata
= destdatabase
;
1577 unsigned char r
, g
, b
;
1579 for ( int x
= 0 ; x
< m_width
; ++x
)
1586 if ( ( r
+ g
+ b
) > 0x10 )
1587 *destdata
++ = 0xFF ;
1589 *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 #if !defined( __LP64__ ) && !defined(__WXOSX_IPHONE__)
1652 class WXDLLEXPORT wxPICTResourceHandler
: public wxBitmapHandler
1654 DECLARE_DYNAMIC_CLASS(wxPICTResourceHandler
)
1657 inline wxPICTResourceHandler()
1659 SetName(wxT("Macintosh Pict resource"));
1660 SetExtension(wxEmptyString
);
1661 SetType(wxBITMAP_TYPE_PICT_RESOURCE
);
1664 virtual bool LoadFile(wxBitmap
*bitmap
, const wxString
& name
, long flags
,
1665 int desiredWidth
, int desiredHeight
);
1668 IMPLEMENT_DYNAMIC_CLASS(wxPICTResourceHandler
, wxBitmapHandler
)
1671 bool wxPICTResourceHandler::LoadFile(wxBitmap
*bitmap
,
1672 const wxString
& name
,
1673 long WXUNUSED(flags
),
1674 int WXUNUSED(desiredWidth
),
1675 int WXUNUSED(desiredHeight
))
1679 wxMacStringToPascal( name
, theName
) ;
1681 PicHandle thePict
= (PicHandle
) GetNamedResource( 'PICT' , theName
) ;
1686 mf
.SetPICT( thePict
) ;
1687 bitmap
->Create( mf
.GetWidth() , mf
.GetHeight() ) ;
1689 dc
.SelectObject( *bitmap
) ;
1691 dc
.SelectObject( wxNullBitmap
) ;
1701 void wxBitmap::InitStandardHandlers()
1703 #if !defined( __LP64__ ) && !defined(__WXOSX_IPHONE__)
1704 AddHandler( new wxPICTResourceHandler
) ;
1706 #if wxOSX_USE_CARBON
1707 AddHandler( new wxICONResourceHandler
) ;
1711 // ----------------------------------------------------------------------------
1712 // raw bitmap access support
1713 // ----------------------------------------------------------------------------
1715 void *wxBitmap::GetRawData(wxPixelDataBase
& data
, int WXUNUSED(bpp
))
1718 // no bitmap, no data (raw or otherwise)
1721 data
.m_width
= GetWidth() ;
1722 data
.m_height
= GetHeight() ;
1723 data
.m_stride
= GetBitmapData()->GetBytesPerRow() ;
1725 return BeginRawAccess() ;
1728 void wxBitmap::UngetRawData(wxPixelDataBase
& WXUNUSED(dataBase
))
1733 void wxBitmap::UseAlpha()
1735 // remember that we are using alpha channel:
1736 // we'll need to create a proper mask in UngetRawData()
1737 M_BITMAPDATA
->UseAlpha( true );