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 )
500 OSStatus err
= SetIconFamilyData( iconFamily
, dataType
, data
);
503 wxFAIL_MSG("Error when adding bitmap");
506 DisposeHandle( data
);
511 // setup the header properly
514 Handle maskdata
= NULL
;
515 unsigned char * maskptr
= NULL
;
516 unsigned char * ptr
= NULL
;
517 size_t datasize
, masksize
;
519 datasize
= sz
* sz
* 4 ;
520 data
= NewHandle( datasize
) ;
522 ptr
= (unsigned char*) *data
;
523 memset( ptr
, 0, datasize
) ;
526 maskdata
= NewHandle( masksize
) ;
528 maskptr
= (unsigned char*) *maskdata
;
529 memset( maskptr
, 0 , masksize
) ;
531 bool hasAlpha
= HasAlpha() ;
532 wxMask
*mask
= m_bitmapMask
;
533 unsigned char * sourcePtr
= (unsigned char*) GetRawAccess() ;
534 unsigned char * masksourcePtr
= mask
? (unsigned char*) mask
->GetRawAccess() : NULL
;
536 for ( int y
= 0 ; y
< h
; ++y
, sourcePtr
+= m_bytesPerRow
, masksourcePtr
+= mask
? mask
->GetBytesPerRow() : 0 )
538 unsigned char * source
= sourcePtr
;
539 unsigned char * masksource
= masksourcePtr
;
540 unsigned char * dest
= ptr
+ y
* sz
* 4 ;
541 unsigned char * maskdest
= maskptr
+ y
* sz
;
542 unsigned char a
, r
, g
, b
;
544 for ( int x
= 0 ; x
< w
; ++x
)
557 *maskdest
++ = 0xFF - *masksource
++ ;
565 OSStatus err
= SetIconFamilyData( iconFamily
, dataType
, data
) ;
566 wxASSERT_MSG( err
== noErr
, wxT("Error when adding bitmap") ) ;
568 err
= SetIconFamilyData( iconFamily
, maskType
, maskdata
) ;
569 wxASSERT_MSG( err
== noErr
, wxT("Error when adding mask") ) ;
572 HUnlock( maskdata
) ;
573 DisposeHandle( data
) ;
574 DisposeHandle( maskdata
) ;
579 PicHandle pic
= GetPictHandle() ;
580 SetIconFamilyData( iconFamily
, 'PICT' , (Handle
) pic
) ;
582 // transform into IconRef
584 // cleaner version existing from 10.3 upwards
585 HLock((Handle
) iconFamily
);
586 OSStatus err
= GetIconRefFromIconFamilyPtr( *iconFamily
, GetHandleSize((Handle
) iconFamily
), &m_iconRef
);
587 HUnlock((Handle
) iconFamily
);
588 DisposeHandle( (Handle
) iconFamily
) ;
590 wxCHECK_MSG( err
== noErr
, NULL
, wxT("Error when constructing icon ref") );
596 PicHandle
wxBitmapRefData::GetPictHandle()
598 if ( m_pictHandle
== NULL
)
601 GraphicsExportComponent exporter
= 0;
602 OSStatus err
= OpenADefaultComponent(GraphicsExporterComponentType
, kQTFileTypePicture
, &exporter
);
605 m_pictHandle
= (PicHandle
) NewHandle(0);
608 // QT does not correctly export the mask
609 // TODO if we get around to it create a synthetic PICT with the CopyBits and Mask commands
610 CGImageRef imageRef
= CreateCGImage();
611 err
= GraphicsExportSetInputCGImage( exporter
, imageRef
);
612 err
= GraphicsExportSetOutputHandle(exporter
, (Handle
)m_pictHandle
);
613 err
= GraphicsExportDoExport(exporter
, NULL
);
614 CGImageRelease( imageRef
);
616 size_t handleSize
= GetHandleSize( (Handle
) m_pictHandle
);
617 // the 512 bytes header is only needed for pict files, but not in memory
618 if ( handleSize
>= 512 )
620 memmove( *m_pictHandle
, (char*)(*m_pictHandle
)+512, handleSize
- 512 );
621 SetHandleSize( (Handle
) m_pictHandle
, handleSize
- 512 );
624 CloseComponent( exporter
);
629 return m_pictHandle
;
633 CGImageRef
wxBitmapRefData::CreateCGImage() const
636 wxASSERT( m_rawAccessCount
>= 0 ) ;
638 if ( m_rawAccessCount
> 0 || m_cgImageRef
== NULL
)
640 if ( m_depth
!= 1 && m_bitmapMask
== NULL
)
644 CGImageRef tempImage
= CGBitmapContextCreateImage( m_hBitmap
);
645 CGImageRef tempMask
= CGBitmapContextCreateImage((CGContextRef
) m_bitmapMask
->GetHBITMAP() );
646 image
= CGImageCreateWithMask( tempImage
, tempMask
);
647 CGImageRelease(tempMask
);
648 CGImageRelease(tempImage
);
651 image
= CGBitmapContextCreateImage( m_hBitmap
);
655 size_t imageSize
= m_height
* m_bytesPerRow
;
656 void * dataBuffer
= m_memBuf
.GetData() ;
659 CGImageAlphaInfo alphaInfo
= kCGImageAlphaNoneSkipFirst
;
660 wxMemoryBuffer membuf
;
664 alphaInfo
= kCGImageAlphaFirst
;
665 unsigned char *destalphastart
= (unsigned char*) membuf
.GetWriteBuf( imageSize
) ;
666 memcpy( destalphastart
, dataBuffer
, imageSize
) ;
667 unsigned char *sourcemaskstart
= (unsigned char *) m_bitmapMask
->GetRawAccess() ;
668 int maskrowbytes
= m_bitmapMask
->GetBytesPerRow() ;
669 for ( int y
= 0 ; y
< h
; ++y
, destalphastart
+= m_bytesPerRow
, sourcemaskstart
+= maskrowbytes
)
671 unsigned char *sourcemask
= sourcemaskstart
;
672 unsigned char *destalpha
= destalphastart
;
673 for ( int x
= 0 ; x
< w
; ++x
, sourcemask
+= kMaskBytesPerPixel
, destalpha
+= 4 )
675 *destalpha
= 0xFF - *sourcemask
;
678 membuf
.UngetWriteBuf( imageSize
);
684 #if wxOSX_USE_PREMULTIPLIED_ALPHA
685 alphaInfo
= kCGImageAlphaPremultipliedFirst
;
687 alphaInfo
= kCGImageAlphaFirst
;
694 CGDataProviderRef dataProvider
= NULL
;
697 // TODO CHECK ALIGNMENT
698 wxMemoryBuffer maskBuf
;
699 unsigned char * maskBufData
= (unsigned char*) maskBuf
.GetWriteBuf( m_width
* m_height
);
700 unsigned char * bufData
= (unsigned char *) membuf
.GetData() ;
701 // copy one color component
703 for( int y
= 0 ; y
< m_height
; bufData
+= m_bytesPerRow
, ++y
)
705 unsigned char *bufDataIter
= bufData
+3;
706 for ( int x
= 0 ; x
< m_width
; bufDataIter
+= 4, ++x
, ++i
)
708 maskBufData
[i
] = *bufDataIter
;
711 maskBuf
.UngetWriteBuf( m_width
* m_height
);
714 wxMacCGDataProviderCreateWithMemoryBuffer( maskBuf
);
716 image
= ::CGImageMaskCreate( w
, h
, 8, 8, m_width
, dataProvider
, NULL
, false );
720 CGColorSpaceRef colorSpace
= wxMacGetGenericRGBColorSpace();
721 dataProvider
= wxMacCGDataProviderCreateWithMemoryBuffer( membuf
);
724 w
, h
, 8 , 32 , m_bytesPerRow
, colorSpace
, alphaInfo
,
725 dataProvider
, NULL
, false , kCGRenderingIntentDefault
);
727 CGDataProviderRelease( dataProvider
);
732 image
= m_cgImageRef
;
733 CGImageRetain( image
) ;
736 if ( m_rawAccessCount
== 0 && m_cgImageRef
== NULL
)
738 // we keep it for later use
739 m_cgImageRef
= image
;
740 CGImageRetain( image
) ;
746 CGContextRef
wxBitmapRefData::GetBitmapContext() const
751 void wxBitmapRefData::Free()
753 wxASSERT_MSG( m_rawAccessCount
== 0 , wxT("Bitmap still selected when destroyed") ) ;
757 CGImageRelease( m_cgImageRef
) ;
758 m_cgImageRef
= NULL
;
760 #ifndef __WXOSX_IPHONE__
763 ReleaseIconRef( m_iconRef
) ;
770 KillPicture( m_pictHandle
) ;
771 m_pictHandle
= NULL
;
777 CGContextRelease(m_hBitmap
);
788 wxBitmapRefData::~wxBitmapRefData()
795 // ----------------------------------------------------------------------------
797 // ----------------------------------------------------------------------------
799 bool wxBitmap::CopyFromIcon(const wxIcon
& icon
)
801 bool created
= false ;
802 int w
= icon
.GetWidth() ;
803 int h
= icon
.GetHeight() ;
806 #ifdef __WXOSX_CARBON__
807 if ( w
== h
&& ( w
== 16 || w
== 32 || w
== 48 || w
== 128 ) )
809 IconFamilyHandle iconFamily
= NULL
;
810 Handle imagehandle
= NewHandle( 0 ) ;
811 Handle maskhandle
= NewHandle( 0 ) ;
815 IconSelectorValue selector
= 0 ;
820 dataType
= kThumbnail32BitData
;
821 maskType
= kThumbnail8BitMask
;
822 selector
= kSelectorAllAvailableData
;
826 dataType
= kHuge32BitData
;
827 maskType
= kHuge8BitMask
;
828 selector
= kSelectorHuge32Bit
| kSelectorHuge8BitMask
;
832 dataType
= kLarge32BitData
;
833 maskType
= kLarge8BitMask
;
834 selector
= kSelectorLarge32Bit
| kSelectorLarge8BitMask
;
838 dataType
= kSmall32BitData
;
839 maskType
= kSmall8BitMask
;
840 selector
= kSelectorSmall32Bit
| kSelectorSmall8BitMask
;
847 OSStatus err
= IconRefToIconFamily( MAC_WXHICON(icon
.GetHICON()) , selector
, &iconFamily
) ;
849 err
= GetIconFamilyData( iconFamily
, dataType
, imagehandle
) ;
850 err
= GetIconFamilyData( iconFamily
, maskType
, maskhandle
) ;
851 size_t imagehandlesize
= GetHandleSize( imagehandle
) ;
852 size_t maskhandlesize
= GetHandleSize( maskhandle
) ;
854 if ( imagehandlesize
!= 0 && maskhandlesize
!= 0 )
856 wxASSERT( GetHandleSize( imagehandle
) == w
* 4 * h
) ;
857 wxASSERT( GetHandleSize( maskhandle
) == w
* h
) ;
861 unsigned char *source
= (unsigned char *) *imagehandle
;
862 unsigned char *sourcemask
= (unsigned char *) *maskhandle
;
863 unsigned char* destination
= (unsigned char*) BeginRawAccess() ;
865 for ( int y
= 0 ; y
< h
; ++y
)
867 for ( int x
= 0 ; x
< w
; ++x
)
869 unsigned char a
= *sourcemask
++;
872 #if wxOSX_USE_PREMULTIPLIED_ALPHA
873 *destination
++ = ( (*source
++) * a
+ 127 ) / 255;
874 *destination
++ = ( (*source
++) * a
+ 127 ) / 255;
875 *destination
++ = ( (*source
++) * a
+ 127 ) / 255;
877 *destination
++ = *source
++ ;
878 *destination
++ = *source
++ ;
879 *destination
++ = *source
++ ;
885 DisposeHandle( imagehandle
) ;
886 DisposeHandle( maskhandle
) ;
890 DisposeHandle( (Handle
) iconFamily
) ;
896 dc
.SelectObject( *this ) ;
897 dc
.DrawIcon( icon
, 0 , 0 ) ;
898 dc
.SelectObject( wxNullBitmap
) ;
904 wxBitmap::wxBitmap(const char bits
[], int the_width
, int the_height
, int no_bits
)
906 wxBitmapRefData
* bitmapRefData
;
908 m_refData
= bitmapRefData
= new wxBitmapRefData( the_width
, the_height
, no_bits
) ;
910 if (bitmapRefData
->IsOk())
914 int linesize
= ( the_width
/ (sizeof(unsigned char) * 8)) ;
915 if ( the_width
% (sizeof(unsigned char) * 8) )
916 linesize
+= sizeof(unsigned char);
918 unsigned char* linestart
= (unsigned char*) bits
;
919 unsigned char* destptr
= (unsigned char*) BeginRawAccess() ;
921 for ( int y
= 0 ; y
< the_height
; ++y
, linestart
+= linesize
, destptr
+= M_BITMAPDATA
->GetBytesPerRow() )
923 unsigned char* destination
= destptr
;
924 int index
, bit
, mask
;
926 for ( int x
= 0 ; x
< the_width
; ++x
)
932 if ( linestart
[index
] & mask
)
934 *destination
++ = 0xFF ;
941 *destination
++ = 0xFF ;
942 *destination
++ = 0xFF ;
943 *destination
++ = 0xFF ;
944 *destination
++ = 0xFF ;
953 wxFAIL_MSG(wxT("multicolor BITMAPs not yet implemented"));
955 } /* bitmapRefData->IsOk() */
958 wxBitmap::wxBitmap(const void* data
, wxBitmapType type
, int width
, int height
, int depth
)
960 (void) Create(data
, type
, width
, height
, depth
);
963 wxBitmap::wxBitmap(const wxString
& filename
, wxBitmapType type
)
965 LoadFile(filename
, type
);
968 wxGDIRefData
* wxBitmap::CreateGDIRefData() const
970 return new wxBitmapRefData
;
973 wxGDIRefData
* wxBitmap::CloneGDIRefData(const wxGDIRefData
* data
) const
975 return new wxBitmapRefData(*static_cast<const wxBitmapRefData
*>(data
));
978 void * wxBitmap::GetRawAccess() const
980 wxCHECK_MSG( Ok() , NULL
, wxT("invalid bitmap") ) ;
982 return M_BITMAPDATA
->GetRawAccess() ;
985 void * wxBitmap::BeginRawAccess()
987 wxCHECK_MSG( Ok() , NULL
, wxT("invalid bitmap") ) ;
989 return M_BITMAPDATA
->BeginRawAccess() ;
992 void wxBitmap::EndRawAccess()
994 wxCHECK_RET( Ok() , wxT("invalid bitmap") ) ;
996 M_BITMAPDATA
->EndRawAccess() ;
999 CGImageRef
wxBitmap::CreateCGImage() const
1001 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") ) ;
1003 return M_BITMAPDATA
->CreateCGImage() ;
1006 #ifndef __WXOSX_IPHONE__
1007 IconRef
wxBitmap::GetIconRef() const
1009 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") ) ;
1011 return M_BITMAPDATA
->GetIconRef() ;
1014 IconRef
wxBitmap::CreateIconRef() const
1016 IconRef icon
= GetIconRef();
1017 verify_noerr( AcquireIconRef(icon
) );
1022 #if wxOSX_USE_COCOA_OR_IPHONE
1024 WX_NSImage
wxBitmap::GetNSImage() const
1026 wxCFRef
< CGImageRef
> cgimage(CreateCGImage());
1027 return wxOSXCreateNSImageFromCGImage( cgimage
);
1032 wxBitmap
wxBitmap::GetSubBitmap(const wxRect
&rect
) const
1034 wxCHECK_MSG( Ok() &&
1035 (rect
.x
>= 0) && (rect
.y
>= 0) &&
1036 (rect
.x
+rect
.width
<= GetWidth()) &&
1037 (rect
.y
+rect
.height
<= GetHeight()),
1038 wxNullBitmap
, wxT("invalid bitmap or bitmap region") );
1040 wxBitmap
ret( rect
.width
, rect
.height
, GetDepth() );
1041 wxASSERT_MSG( ret
.Ok(), wxT("GetSubBitmap error") );
1043 int destwidth
= rect
.width
;
1044 int destheight
= rect
.height
;
1047 unsigned char *sourcedata
= (unsigned char*) GetRawAccess() ;
1048 unsigned char *destdata
= (unsigned char*) ret
.BeginRawAccess() ;
1049 wxASSERT( (sourcedata
!= NULL
) && (destdata
!= NULL
) ) ;
1051 int sourcelinesize
= GetBitmapData()->GetBytesPerRow() ;
1052 int destlinesize
= ret
.GetBitmapData()->GetBytesPerRow() ;
1053 unsigned char *source
= sourcedata
+ rect
.x
* 4 + rect
.y
* sourcelinesize
;
1054 unsigned char *dest
= destdata
;
1056 for (int yy
= 0; yy
< destheight
; ++yy
, source
+= sourcelinesize
, dest
+= destlinesize
)
1058 memcpy( dest
, source
, destlinesize
) ;
1062 ret
.EndRawAccess() ;
1064 if ( M_BITMAPDATA
->m_bitmapMask
)
1066 wxMemoryBuffer maskbuf
;
1067 int rowBytes
= GetBestBytesPerRow( destwidth
* kMaskBytesPerPixel
);
1068 size_t maskbufsize
= rowBytes
* destheight
;
1070 int sourcelinesize
= M_BITMAPDATA
->m_bitmapMask
->GetBytesPerRow() ;
1071 int destlinesize
= rowBytes
;
1073 unsigned char *source
= (unsigned char *) M_BITMAPDATA
->m_bitmapMask
->GetRawAccess() ;
1074 unsigned char *destdata
= (unsigned char * ) maskbuf
.GetWriteBuf( maskbufsize
) ;
1075 wxASSERT( (source
!= NULL
) && (destdata
!= NULL
) ) ;
1077 source
+= rect
.x
* kMaskBytesPerPixel
+ rect
.y
* sourcelinesize
;
1078 unsigned char *dest
= destdata
;
1080 for (int yy
= 0; yy
< destheight
; ++yy
, source
+= sourcelinesize
, dest
+= destlinesize
)
1082 memcpy( dest
, source
, destlinesize
) ;
1085 maskbuf
.UngetWriteBuf( maskbufsize
) ;
1086 ret
.SetMask( new wxMask( maskbuf
, destwidth
, destheight
, rowBytes
) ) ;
1088 else if ( HasAlpha() )
1094 bool wxBitmap::Create(int w
, int h
, int d
)
1099 d
= wxDisplayDepth() ;
1101 m_refData
= new wxBitmapRefData( w
, h
, d
);
1103 return M_BITMAPDATA
->IsOk() ;
1106 bool wxBitmap::LoadFile(const wxString
& filename
, wxBitmapType type
)
1110 wxBitmapHandler
*handler
= FindHandler(type
);
1114 m_refData
= new wxBitmapRefData
;
1116 return handler
->LoadFile(this, filename
, type
, -1, -1);
1121 wxImage
loadimage(filename
, type
);
1131 wxLogWarning(wxT("no bitmap handler for type %d defined."), type
);
1136 bool wxBitmap::Create(const void* data
, wxBitmapType type
, int width
, int height
, int depth
)
1140 m_refData
= new wxBitmapRefData
;
1142 wxBitmapHandler
*handler
= FindHandler(type
);
1144 if ( handler
== NULL
)
1146 wxLogWarning(wxT("no bitmap handler for type %d defined."), type
);
1151 return handler
->Create(this, data
, type
, width
, height
, depth
);
1156 wxBitmap::wxBitmap(const wxImage
& image
, int depth
)
1158 wxCHECK_RET( image
.Ok(), wxT("invalid image") );
1160 // width and height of the device-dependent bitmap
1161 int width
= image
.GetWidth();
1162 int height
= image
.GetHeight();
1164 wxBitmapRefData
* bitmapRefData
;
1166 m_refData
= bitmapRefData
= new wxBitmapRefData( width
, height
, depth
) ;
1168 if ( bitmapRefData
->IsOk())
1172 bool hasAlpha
= false ;
1174 if ( image
.HasMask() )
1176 // takes precedence, don't mix with alpha info
1180 hasAlpha
= image
.HasAlpha() ;
1186 unsigned char* destinationstart
= (unsigned char*) BeginRawAccess() ;
1187 register unsigned char* data
= image
.GetData();
1188 if ( destinationstart
!= NULL
&& data
!= NULL
)
1190 const unsigned char *alpha
= hasAlpha
? image
.GetAlpha() : NULL
;
1191 for (int y
= 0; y
< height
; destinationstart
+= M_BITMAPDATA
->GetBytesPerRow(), y
++)
1193 unsigned char * destination
= destinationstart
;
1194 for (int x
= 0; x
< width
; x
++)
1198 const unsigned char a
= *alpha
++;
1199 *destination
++ = a
;
1201 #if wxOSX_USE_PREMULTIPLIED_ALPHA
1202 *destination
++ = ((*data
++) * a
+ 127) / 255 ;
1203 *destination
++ = ((*data
++) * a
+ 127) / 255 ;
1204 *destination
++ = ((*data
++) * a
+ 127) / 255 ;
1206 *destination
++ = *data
++ ;
1207 *destination
++ = *data
++ ;
1208 *destination
++ = *data
++ ;
1213 *destination
++ = 0xFF ;
1214 *destination
++ = *data
++ ;
1215 *destination
++ = *data
++ ;
1216 *destination
++ = *data
++ ;
1223 if ( image
.HasMask() )
1224 SetMask( new wxMask( *this , wxColour( image
.GetMaskRed() , image
.GetMaskGreen() , image
.GetMaskBlue() ) ) ) ;
1225 } /* bitmapRefData->IsOk() */
1228 wxImage
wxBitmap::ConvertToImage() const
1232 wxCHECK_MSG( Ok(), wxNullImage
, wxT("invalid bitmap") );
1234 // create an wxImage object
1235 int width
= GetWidth();
1236 int height
= GetHeight();
1237 image
.Create( width
, height
);
1239 unsigned char *data
= image
.GetData();
1240 wxCHECK_MSG( data
, wxNullImage
, wxT("Could not allocate data for image") );
1242 unsigned char* sourcestart
= (unsigned char*) GetRawAccess() ;
1244 bool hasAlpha
= false ;
1245 bool hasMask
= false ;
1246 int maskBytesPerRow
= 0 ;
1247 unsigned char *alpha
= NULL
;
1248 unsigned char *mask
= NULL
;
1256 mask
= (unsigned char*) GetMask()->GetRawAccess() ;
1257 maskBytesPerRow
= GetMask()->GetBytesPerRow() ;
1263 alpha
= image
.GetAlpha() ;
1268 // The following masking algorithm is the same as well in msw/gtk:
1269 // the colour used as transparent one in wxImage and the one it is
1270 // replaced with when it actually occurs in the bitmap
1271 static const int MASK_RED
= 1;
1272 static const int MASK_GREEN
= 2;
1273 static const int MASK_BLUE
= 3;
1274 static const int MASK_BLUE_REPLACEMENT
= 2;
1276 for (int yy
= 0; yy
< height
; yy
++ , sourcestart
+= M_BITMAPDATA
->GetBytesPerRow() , mask
+= maskBytesPerRow
)
1278 unsigned char * maskp
= mask
;
1279 unsigned char * source
= sourcestart
;
1280 unsigned char a
, r
, g
, b
;
1283 for (int xx
= 0; xx
< width
; xx
++)
1285 color
= *((long*) source
) ;
1286 #ifdef WORDS_BIGENDIAN
1287 a
= ((color
&0xFF000000) >> 24) ;
1288 r
= ((color
&0x00FF0000) >> 16) ;
1289 g
= ((color
&0x0000FF00) >> 8) ;
1290 b
= (color
&0x000000FF);
1292 b
= ((color
&0xFF000000) >> 24) ;
1293 g
= ((color
&0x00FF0000) >> 16) ;
1294 r
= ((color
&0x0000FF00) >> 8) ;
1295 a
= (color
&0x000000FF);
1299 if ( *maskp
++ == 0xFF )
1305 else if ( r
== MASK_RED
&& g
== MASK_GREEN
&& b
== MASK_BLUE
)
1306 b
= MASK_BLUE_REPLACEMENT
;
1308 else if ( hasAlpha
)
1311 #if wxOSX_USE_PREMULTIPLIED_ALPHA
1312 // this must be non-premultiplied data
1313 if ( a
!= 0xFF && a
!= 0 )
1323 data
[index
+ 1] = g
;
1324 data
[index
+ 2] = b
;
1332 image
.SetMaskColour( MASK_RED
, MASK_GREEN
, MASK_BLUE
);
1337 #endif //wxUSE_IMAGE
1339 bool wxBitmap::SaveFile( const wxString
& filename
,
1340 wxBitmapType type
, const wxPalette
*palette
) const
1342 bool success
= false;
1343 wxBitmapHandler
*handler
= FindHandler(type
);
1347 success
= handler
->SaveFile(this, filename
, type
, palette
);
1352 wxImage image
= ConvertToImage();
1353 success
= image
.SaveFile(filename
, type
);
1355 wxLogWarning(wxT("no bitmap handler for type %d defined."), type
);
1362 int wxBitmap::GetHeight() const
1364 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
1366 return M_BITMAPDATA
->GetHeight();
1369 int wxBitmap::GetWidth() const
1371 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
1373 return M_BITMAPDATA
->GetWidth() ;
1376 int wxBitmap::GetDepth() const
1378 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
1380 return M_BITMAPDATA
->GetDepth();
1383 wxMask
*wxBitmap::GetMask() const
1385 wxCHECK_MSG( Ok(), NULL
, wxT("invalid bitmap") );
1387 return M_BITMAPDATA
->m_bitmapMask
;
1390 bool wxBitmap::HasAlpha() const
1392 wxCHECK_MSG( Ok(), false , wxT("invalid bitmap") );
1394 return M_BITMAPDATA
->HasAlpha() ;
1397 void wxBitmap::SetWidth(int w
)
1400 M_BITMAPDATA
->SetWidth(w
);
1403 void wxBitmap::SetHeight(int h
)
1406 M_BITMAPDATA
->SetHeight(h
);
1409 void wxBitmap::SetDepth(int d
)
1412 M_BITMAPDATA
->SetDepth(d
);
1415 void wxBitmap::SetOk(bool isOk
)
1418 M_BITMAPDATA
->SetOk(isOk
);
1422 wxPalette
*wxBitmap::GetPalette() const
1424 wxCHECK_MSG( Ok(), NULL
, wxT("Invalid bitmap GetPalette()") );
1426 return &M_BITMAPDATA
->m_bitmapPalette
;
1429 void wxBitmap::SetPalette(const wxPalette
& palette
)
1432 M_BITMAPDATA
->m_bitmapPalette
= palette
;
1434 #endif // wxUSE_PALETTE
1436 void wxBitmap::SetMask(wxMask
*mask
)
1439 // Remove existing mask if there is one.
1440 delete M_BITMAPDATA
->m_bitmapMask
;
1442 M_BITMAPDATA
->m_bitmapMask
= mask
;
1445 WXHBITMAP
wxBitmap::GetHBITMAP(WXHBITMAP
* mask
) const
1449 return WXHBITMAP(M_BITMAPDATA
->GetBitmapContext());
1452 // ----------------------------------------------------------------------------
1454 // ----------------------------------------------------------------------------
1461 wxMask::wxMask(const wxMask
&tocopy
)
1465 m_bytesPerRow
= tocopy
.m_bytesPerRow
;
1466 m_width
= tocopy
.m_width
;
1467 m_height
= tocopy
.m_height
;
1469 size_t size
= m_bytesPerRow
* m_height
;
1470 unsigned char* dest
= (unsigned char*)m_memBuf
.GetWriteBuf( size
);
1471 unsigned char* source
= (unsigned char*)tocopy
.m_memBuf
.GetData();
1472 memcpy( dest
, source
, size
);
1473 m_memBuf
.UngetWriteBuf( size
) ;
1477 // Construct a mask from a bitmap and a colour indicating
1478 // the transparent area
1479 wxMask::wxMask( const wxBitmap
& bitmap
, const wxColour
& colour
)
1482 Create( bitmap
, colour
);
1485 // Construct a mask from a mono bitmap (copies the bitmap).
1486 wxMask::wxMask( const wxBitmap
& bitmap
)
1492 // Construct a mask from a mono bitmap (copies the bitmap).
1494 wxMask::wxMask( const wxMemoryBuffer
& data
, int width
, int height
, int bytesPerRow
)
1497 Create( data
, width
, height
, bytesPerRow
);
1504 CGContextRelease( (CGContextRef
) m_maskBitmap
);
1505 m_maskBitmap
= NULL
;
1511 m_width
= m_height
= m_bytesPerRow
= 0 ;
1512 m_maskBitmap
= NULL
;
1515 void *wxMask::GetRawAccess() const
1517 return m_memBuf
.GetData() ;
1520 // The default ColorTable for k8IndexedGrayPixelFormat in Intel appears to be broken, so we'll use an non-indexed
1521 // bitmap mask instead; in order to keep the code simple, the change applies to PowerPC implementations as well
1523 void wxMask::RealizeNative()
1527 CGContextRelease( (CGContextRef
) m_maskBitmap
);
1528 m_maskBitmap
= NULL
;
1531 CGColorSpaceRef colorspace
= CGColorSpaceCreateDeviceGray();
1532 // from MouseTracking sample :
1533 // Ironically, due to a bug in CGImageCreateWithMask, you cannot use
1534 // CGColorSpaceCreateWithName(kCGColorSpaceGenericGray) at this point!
1536 m_maskBitmap
= CGBitmapContextCreate((char*) m_memBuf
.GetData(), m_width
, m_height
, 8, m_bytesPerRow
, colorspace
,
1537 kCGImageAlphaNone
);
1538 CGColorSpaceRelease( colorspace
);
1539 wxASSERT_MSG( m_maskBitmap
, wxT("Unable to create CGBitmapContext context") ) ;
1542 // Create a mask from a mono bitmap (copies the bitmap).
1544 bool wxMask::Create(const wxMemoryBuffer
& data
,int width
, int height
, int bytesPerRow
)
1549 m_bytesPerRow
= bytesPerRow
;
1551 wxASSERT( data
.GetDataLen() == (size_t)(height
* bytesPerRow
) ) ;
1558 // Create a mask from a mono bitmap (copies the bitmap).
1559 bool wxMask::Create(const wxBitmap
& bitmap
)
1561 m_width
= bitmap
.GetWidth() ;
1562 m_height
= bitmap
.GetHeight() ;
1563 m_bytesPerRow
= GetBestBytesPerRow( m_width
* kMaskBytesPerPixel
) ;
1565 size_t size
= m_bytesPerRow
* m_height
;
1566 unsigned char * destdatabase
= (unsigned char*) m_memBuf
.GetWriteBuf( size
) ;
1567 wxASSERT( destdatabase
!= NULL
) ;
1569 memset( destdatabase
, 0 , size
) ;
1570 unsigned char * srcdata
= (unsigned char*) bitmap
.GetRawAccess() ;
1572 for ( int y
= 0 ; y
< m_height
; ++y
, destdatabase
+= m_bytesPerRow
)
1574 unsigned char *destdata
= destdatabase
;
1575 unsigned char r
, g
, b
;
1577 for ( int x
= 0 ; x
< m_width
; ++x
)
1584 if ( ( r
+ g
+ b
) > 0x10 )
1585 *destdata
++ = 0xFF ;
1587 *destdata
++ = 0x00 ;
1591 m_memBuf
.UngetWriteBuf( size
) ;
1597 // Create a mask from a bitmap and a colour indicating
1598 // the transparent area
1599 bool wxMask::Create(const wxBitmap
& bitmap
, const wxColour
& colour
)
1601 m_width
= bitmap
.GetWidth() ;
1602 m_height
= bitmap
.GetHeight() ;
1603 m_bytesPerRow
= GetBestBytesPerRow( m_width
* kMaskBytesPerPixel
) ;
1605 size_t size
= m_bytesPerRow
* m_height
;
1606 unsigned char * destdatabase
= (unsigned char*) m_memBuf
.GetWriteBuf( size
) ;
1607 wxASSERT( destdatabase
!= NULL
) ;
1609 memset( destdatabase
, 0 , size
) ;
1610 unsigned char * srcdatabase
= (unsigned char*) bitmap
.GetRawAccess() ;
1611 size_t sourceBytesRow
= bitmap
.GetBitmapData()->GetBytesPerRow();
1613 for ( int y
= 0 ; y
< m_height
; ++y
, srcdatabase
+= sourceBytesRow
, destdatabase
+= m_bytesPerRow
)
1615 unsigned char *srcdata
= srcdatabase
;
1616 unsigned char *destdata
= destdatabase
;
1617 unsigned char r
, g
, b
;
1619 for ( int x
= 0 ; x
< m_width
; ++x
)
1626 if ( colour
== wxColour( r
, g
, b
) )
1627 *destdata
++ = 0xFF ;
1629 *destdata
++ = 0x00 ;
1633 m_memBuf
.UngetWriteBuf( size
) ;
1639 WXHBITMAP
wxMask::GetHBITMAP() const
1641 return m_maskBitmap
;
1644 // ----------------------------------------------------------------------------
1645 // Standard Handlers
1646 // ----------------------------------------------------------------------------
1648 #if !defined( __LP64__ ) && !defined(__WXOSX_IPHONE__)
1650 class WXDLLEXPORT wxPICTResourceHandler
: public wxBitmapHandler
1652 DECLARE_DYNAMIC_CLASS(wxPICTResourceHandler
)
1655 inline wxPICTResourceHandler()
1657 SetName(wxT("Macintosh Pict resource"));
1658 SetExtension(wxEmptyString
);
1659 SetType(wxBITMAP_TYPE_PICT_RESOURCE
);
1662 virtual bool LoadFile(wxBitmap
*bitmap
,
1663 const wxString
& name
,
1669 IMPLEMENT_DYNAMIC_CLASS(wxPICTResourceHandler
, wxBitmapHandler
)
1672 bool wxPICTResourceHandler::LoadFile(wxBitmap
*bitmap
,
1673 const wxString
& name
,
1674 wxBitmapType
WXUNUSED(type
),
1675 int WXUNUSED(desiredWidth
),
1676 int WXUNUSED(desiredHeight
))
1680 wxMacStringToPascal( name
, theName
) ;
1682 PicHandle thePict
= (PicHandle
) GetNamedResource( 'PICT' , theName
) ;
1687 mf
.SetPICT( thePict
) ;
1688 bitmap
->Create( mf
.GetWidth() , mf
.GetHeight() ) ;
1690 dc
.SelectObject( *bitmap
) ;
1692 dc
.SelectObject( wxNullBitmap
) ;
1702 void wxBitmap::InitStandardHandlers()
1704 #if !defined( __LP64__ ) && !defined(__WXOSX_IPHONE__)
1705 AddHandler( new wxPICTResourceHandler
) ;
1707 #if wxOSX_USE_CARBON
1708 AddHandler( new wxICONResourceHandler
) ;
1712 // ----------------------------------------------------------------------------
1713 // raw bitmap access support
1714 // ----------------------------------------------------------------------------
1716 void *wxBitmap::GetRawData(wxPixelDataBase
& data
, int WXUNUSED(bpp
))
1719 // no bitmap, no data (raw or otherwise)
1722 data
.m_width
= GetWidth() ;
1723 data
.m_height
= GetHeight() ;
1724 data
.m_stride
= GetBitmapData()->GetBytesPerRow() ;
1726 return BeginRawAccess() ;
1729 void wxBitmap::UngetRawData(wxPixelDataBase
& WXUNUSED(dataBase
))
1734 void wxBitmap::UseAlpha()
1736 // remember that we are using alpha channel:
1737 // we'll need to create a proper mask in UngetRawData()
1738 M_BITMAPDATA
->UseAlpha( true );