]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/bitmap.cpp
slowly approaching dcscreen...
[wxWidgets.git] / src / mac / carbon / bitmap.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: bitmap.cpp
3 // Purpose: wxBitmap
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "bitmap.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #include "wx/bitmap.h"
19 #include "wx/icon.h"
20 #include "wx/log.h"
21 #include "wx/image.h"
22 #include "wx/metafile.h"
23 #include "wx/xpmdecod.h"
24
25 #include "wx/rawbmp.h"
26
27 IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
28 IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
29 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject )
30
31 #ifdef __DARWIN__
32 #include <ApplicationServices/ApplicationServices.h>
33 #else
34 #include <PictUtils.h>
35 #endif
36
37 #include "wx/mac/uma.h"
38
39 #include "wx/dcmemory.h"
40
41 // Implementation Notes
42 // --------------------
43 //
44 // we are always working with a 32 bit deep pixel buffer
45 // under QuickDraw its alpha parts are going to be ignored in the GWorld,
46 // therefore we have a separate GWorld there for blitting the mask in
47
48 // under Quartz then content is transformed into a CGImageRef representing the same data
49 // which can be transferred to the GPU by the OS for fast rendering
50
51 // we don't dare premultiplied alpha yet
52 #define wxMAC_USE_PREMULTIPLIED_ALPHA 0
53
54 IconFamilyHandle wxMacCreateIconFamily(const wxBitmap& bmp)
55 {
56 // setup the header properly
57
58 IconFamilyHandle iconFamily = (IconFamilyHandle) NewHandle(8) ;
59 (**iconFamily).resourceType = kIconFamilyType ;
60 (**iconFamily).resourceSize = sizeof(OSType) + sizeof(Size);
61
62 int w = bmp.GetWidth() ;
63 int h = bmp.GetHeight() ;
64 int sz = wxMax( w , h ) ;
65 if ( sz > 128 )
66 {
67 wxFAIL_MSG( wxT("Currently only 128 pixels wide images are supported") ) ;
68 }
69
70 Handle data = NULL ;
71 Handle maskdata = NULL ;
72 unsigned char * maskptr = NULL ;
73 unsigned char * ptr = NULL ;
74 size_t size ;
75 size_t masksize ;
76 OSType dataType ;
77 OSType maskType ;
78
79 bool hasAlpha = bmp.HasAlpha() ;
80 wxMask *mask = bmp.GetMask() ;
81 // thumbnail is 128 x 128 with 32 bits per pixel
82
83 if ( sz > 48 )
84 {
85 sz = 128 ;
86 dataType = kThumbnail32BitData ;
87 maskType = kThumbnail8BitMask ;
88 }
89 else if ( sz > 32 )
90 {
91 sz = 48 ;
92 dataType = kHuge32BitData ;
93 maskType = kHuge8BitMask ;
94 }
95 else if ( sz > 16 )
96 {
97 sz = 32 ;
98 dataType = kLarge32BitData ;
99 maskType = kLarge8BitMask ;
100 }
101 else
102 {
103 sz = 16 ;
104 dataType = kSmall32BitData ;
105 maskType = kSmall8BitMask ;
106 }
107
108 size = sz * sz * 4 ;
109 data = NewHandle( size) ;
110 HLock( data ) ;
111 ptr = (unsigned char*) *data ;
112 memset( ptr , 0, size ) ;
113
114 masksize = sz * sz ;
115 maskdata = NewHandle( masksize ) ;
116 HLock( maskdata ) ;
117 maskptr = (unsigned char*) *maskdata ;
118 memset( maskptr , 0 , masksize ) ;
119
120 unsigned char * source = (unsigned char*) bmp.GetRawAccess() ;
121 unsigned char * masksource = mask ? (unsigned char*) mask->GetRawAccess() : NULL ;
122 for ( int y = 0 ; y < h ; ++y )
123 {
124 unsigned char * dest = ptr + y * sz * 4 ;
125 unsigned char * maskdest = maskptr + y * sz ;
126 for ( int x = 0 ; x < w ; ++x )
127 {
128 unsigned char a = *source ++ ;
129 unsigned char r = *source ++ ;
130 unsigned char g = *source ++ ;
131 unsigned char b = *source ++ ;
132
133 *dest++ = 0 ;
134 *dest++ = r ;
135 *dest++ = g ;
136 *dest++ = b ;
137
138 if ( mask )
139 *maskdest++ = *masksource++ ;
140 else if ( hasAlpha )
141 *maskdest++ = a ;
142 else
143 *maskdest++ = 0xFF ;
144 }
145 }
146
147 OSStatus err = SetIconFamilyData( iconFamily, dataType , data ) ;
148 wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ;
149
150 err = SetIconFamilyData( iconFamily, maskType , maskdata ) ;
151 wxASSERT_MSG( err == noErr , wxT("Error when adding mask") ) ;
152 HUnlock( data ) ;
153 HUnlock( maskdata ) ;
154 DisposeHandle( data ) ;
155 DisposeHandle( maskdata ) ;
156 return iconFamily ;
157 }
158
159 IconRef wxMacCreateIconRef(const wxBitmap& bmp)
160 {
161 IconFamilyHandle iconFamily = wxMacCreateIconFamily( bmp ) ;
162 IconRef iconRef ;
163 static int iconCounter = 2 ;
164
165 OSStatus err = RegisterIconRefFromIconFamily( 'WXNG' , (OSType) iconCounter, iconFamily, &iconRef ) ;
166 UInt16 owners ;
167 err = GetIconRefOwners(iconRef , &owners ) ;
168
169 wxASSERT_MSG( err == noErr , wxT("Error when adding bitmap") ) ;
170 // we have to retain a reference, as Unregister will decrement it
171 AcquireIconRef( iconRef ) ;
172 UnregisterIconRef( 'WXNG' , (OSType) iconCounter ) ;
173 DisposeHandle( (Handle) iconFamily ) ;
174 ++iconCounter ;
175
176 return iconRef ;
177 }
178
179 PicHandle wxMacCreatePicHandle( const wxBitmap &bmp )
180 {
181 CGrafPtr origPort = NULL ;
182 GDHandle origDev = NULL ;
183 PicHandle pict = NULL ;
184 GWorldPtr wp = NULL ;
185 GWorldPtr mask = NULL ;
186
187 GetGWorld( &origPort , &origDev ) ;
188
189 wp = (GWorldPtr) bmp.GetHBITMAP( (WXHBITMAP*) &mask ) ;
190
191 SetGWorld( wp , NULL ) ;
192 Rect portRect ;
193 GetPortBounds( wp , &portRect ) ;
194 pict = OpenPicture(&portRect);
195
196 if(pict)
197 {
198 RGBColor white = { 0xffff ,0xffff , 0xffff } ;
199 RGBColor black = { 0x0000 ,0x0000 , 0x0000 } ;
200 RGBForeColor( &black ) ;
201 RGBBackColor( &white ) ;
202
203 LockPixels( GetGWorldPixMap( wp ) ) ;
204 CopyBits(GetPortBitMapForCopyBits(wp),
205 GetPortBitMapForCopyBits(wp),
206 &portRect,
207 &portRect,
208 srcCopy,NULL);
209 UnlockPixels( GetGWorldPixMap( wp ) ) ;
210 ClosePicture();
211 }
212 SetGWorld( origPort , origDev ) ;
213
214 return pict;
215 }
216
217 void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType )
218 {
219 memset( info , 0 , sizeof(ControlButtonContentInfo) ) ;
220 if ( bitmap.Ok() )
221 {
222 wxBitmapRefData * bmap = (wxBitmapRefData*) ( bitmap.GetRefData()) ;
223 if ( bmap == NULL )
224 return ;
225 info->contentType = kControlContentIconRef ;
226 info->u.iconRef = wxMacCreateIconRef( bitmap ) ;
227
228 #if wxMAC_USE_CORE_GRAPHICS
229 /*
230 // only on 10.4 more controls will accept a CGImage
231
232 info->contentType = kControlContentCGImageRef ;
233 info->u.imageRef = (CGImageRef) bmap->CGImageCreate() ;
234 */
235 #endif
236 }
237 }
238
239 void wxMacReleaseBitmapButton( ControlButtonContentInfo*info )
240 {
241 if ( info->contentType == kControlContentIconRef )
242 {
243 ReleaseIconRef(info->u.iconRef) ;
244 }
245 #if wxMAC_USE_CORE_GRAPHICS && MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
246 else if ( info->contentType == kControlContentCGImageRef )
247 {
248 CGImageRelease( info->u.imageRef ) ;
249 }
250 #endif
251 else
252 {
253 wxFAIL_MSG(wxT("Unexpected bitmap type") ) ;
254 }
255 }
256
257 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
258
259 void wxBitmapRefData::Init()
260 {
261 m_width = 0 ;
262 m_height = 0 ;
263 m_depth = 0 ;
264 m_ok = false ;
265 m_bitmapMask = NULL ;
266 #if wxMAC_USE_CORE_GRAPHICS
267 m_cgImageRef = NULL ;
268 #endif
269 m_hBitmap = NULL ;
270 m_hMaskBitmap = NULL;
271 m_maskBytesPerRow = NULL ;
272
273 m_rawAccessCount = 0 ;
274 m_hasAlpha = false;
275 }
276
277 wxBitmapRefData::wxBitmapRefData()
278 {
279 Init() ;
280 }
281
282 wxBitmapRefData::wxBitmapRefData( int w , int h , int d )
283 {
284 Init() ;
285 Create( w , h , d ) ;
286 }
287
288 bool wxBitmapRefData::Create( int w , int h , int d )
289 {
290 m_width = w ;
291 m_height = h ;
292 m_depth = d ;
293
294 m_bytesPerRow = w * 4 ;
295 size_t size = m_bytesPerRow * h ;
296 void* data = m_memBuf.GetWriteBuf(size) ;
297 memset( data , 0 , size) ;
298 m_memBuf.UngetWriteBuf(size) ;
299
300 m_hBitmap = NULL ;
301 Rect rect = { 0 , 0 , m_height , m_width } ;
302 verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_hBitmap , k32ARGBPixelFormat , &rect , NULL , NULL , 0 ,
303 (char*) data , m_bytesPerRow ) ) ;
304 wxASSERT_MSG( m_hBitmap , wxT("Unable to create GWorld context") ) ;
305 m_ok = ( m_hBitmap != NULL ) ;
306
307 return m_ok ;
308 }
309
310 void wxBitmapRefData::UseAlpha( bool use )
311 {
312 if ( m_hasAlpha == use )
313 return ;
314
315 m_hasAlpha = use ;
316 if ( m_hasAlpha )
317 {
318 int width = GetWidth() ;
319 int height = GetHeight() ;
320 m_maskBytesPerRow = ( width + 3 ) & 0xFFFFFFC ;
321 size_t size = height * m_maskBytesPerRow ;
322 unsigned char * data = (unsigned char * ) m_maskMemBuf.GetWriteBuf( size ) ;
323 memset( data , 0 , size ) ;
324 wxASSERT( m_hMaskBitmap == NULL ) ;
325 Rect rect = { 0 , 0 , height , width } ;
326 verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_hMaskBitmap , k8IndexedGrayPixelFormat , &rect , NULL , NULL , 0 ,
327 (char*) data , m_maskBytesPerRow ) ) ;
328 wxASSERT_MSG( m_hMaskBitmap , wxT("Unable to create GWorld context for alpha mask") ) ;
329 m_maskMemBuf.UngetWriteBuf(size) ;
330 #if !wxMAC_USE_CORE_GRAPHICS
331 UpdateAlphaMask() ;
332 #endif
333 }
334 else
335 {
336 DisposeGWorld( m_hMaskBitmap ) ;
337 m_hMaskBitmap = NULL ;
338 m_maskBytesPerRow = 0 ;
339 }
340 }
341
342 void *wxBitmapRefData::GetRawAccess() const
343 {
344 wxCHECK_MSG( Ok(), NULL , wxT("invalid bitmap") ) ;
345 return m_memBuf.GetData() ;
346 }
347
348 void *wxBitmapRefData::BeginRawAccess()
349 {
350 wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") ) ;
351 wxASSERT( m_rawAccessCount == 0 ) ;
352 ++m_rawAccessCount ;
353 #if wxMAC_USE_CORE_GRAPHICS
354 // we must destroy an existing cached image, as
355 // the bitmap data may change now
356 if ( m_cgImageRef )
357 {
358 CGImageRelease( m_cgImageRef ) ;
359 m_cgImageRef = NULL ;
360 }
361 #endif
362 return m_memBuf.GetData() ;
363 }
364
365 void wxBitmapRefData::EndRawAccess()
366 {
367 wxCHECK_RET( Ok() , wxT("invalid bitmap") ) ;
368 wxASSERT( m_rawAccessCount == 1 ) ;
369 --m_rawAccessCount ;
370 #if !wxMAC_USE_CORE_GRAPHICS
371 UpdateAlphaMask() ;
372 #endif
373 }
374
375
376 #if wxMAC_USE_CORE_GRAPHICS
377 void wxMacMemoryBufferReleaseProc(void *info, const void *data, size_t size)
378 {
379 wxMemoryBuffer* membuf = (wxMemoryBuffer*) info ;
380 wxASSERT( data == membuf->GetData() ) ;
381 delete membuf ;
382 }
383
384 CGImageRef wxBitmapRefData::CGImageCreate() const
385 {
386 wxASSERT( m_ok ) ;
387 wxASSERT( m_rawAccessCount >= 0 ) ;
388 CGImageRef image ;
389 if ( m_rawAccessCount > 0 || m_cgImageRef == NULL )
390 {
391 size_t imageSize = m_width * m_height * 4 ;
392 void * dataBuffer = m_memBuf.GetData() ;
393 int w = m_width ;
394 int h = m_height ;
395 CGImageAlphaInfo alphaInfo = kCGImageAlphaNoneSkipFirst ;
396 wxMemoryBuffer* membuf = NULL ;
397
398 if ( m_bitmapMask )
399 {
400 membuf = new wxMemoryBuffer( imageSize ) ;
401 memcpy( membuf->GetData() , dataBuffer , imageSize ) ;
402 unsigned char *sourcemaskstart = (unsigned char *) m_bitmapMask->GetRawAccess() ;
403 int maskrowbytes = m_bitmapMask->GetBytesPerRow() ;
404 unsigned char *destalpha = (unsigned char *) membuf->GetData() ;
405 alphaInfo = kCGImageAlphaFirst ;
406 for ( int y = 0 ; y < h ; ++y , sourcemaskstart += maskrowbytes)
407 {
408 unsigned char *sourcemask = sourcemaskstart ;
409 for( int x = 0 ; x < w ; ++x , sourcemask++ , destalpha += 4 )
410 {
411 *destalpha = *sourcemask ;
412 }
413 }
414 }
415 else if ( m_hasAlpha )
416 {
417 #if wxMAC_USE_PREMULTIPLIED_ALPHA
418 alphaInfo = kCGImageAlphaPremultipliedFirst ;
419 #else
420 alphaInfo = kCGImageAlphaFirst ;
421 #endif
422 membuf = new wxMemoryBuffer( m_memBuf ) ;
423 }
424 else
425 {
426 membuf = new wxMemoryBuffer( m_memBuf ) ;
427 }
428 CGColorSpaceRef colorSpace = wxMacGetGenericRGBColorSpace();
429 CGDataProviderRef dataProvider =
430 CGDataProviderCreateWithData( membuf , (const void *)membuf->GetData() , imageSize,
431 wxMacMemoryBufferReleaseProc );
432 image =
433 ::CGImageCreate( w, h, 8 , 32 , 4 * m_width , colorSpace, alphaInfo ,
434 dataProvider, NULL , false , kCGRenderingIntentDefault );
435 CGDataProviderRelease( dataProvider);
436 }
437 else
438 {
439 image = m_cgImageRef ;
440 CGImageRetain( image ) ;
441 }
442 if ( m_rawAccessCount == 0 && m_cgImageRef == NULL)
443 {
444 // we keep it for later use
445 m_cgImageRef = image ;
446 CGImageRetain( image ) ;
447 }
448 return image ;
449 }
450 #endif
451
452 GWorldPtr wxBitmapRefData::GetHBITMAP(GWorldPtr* mask) const
453 {
454 wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );
455 if ( mask )
456 {
457 *mask = NULL ;
458 if ( m_bitmapMask )
459 *mask = (GWorldPtr) m_bitmapMask->GetHBITMAP() ;
460 else if ( m_hasAlpha )
461 {
462 #if !wxMAC_USE_CORE_GRAPHICS
463 if ( m_rawAccessCount > 0 )
464 UpdateAlphaMask() ;
465 #else
466 // this structure is not kept in synch when using CG, so if someone
467 // is really accessing the Graphports, we have to sync it
468 UpdateAlphaMask() ;
469 #endif
470 *mask = m_hMaskBitmap ;
471 }
472 }
473 return m_hBitmap ;
474 }
475
476 void wxBitmapRefData::UpdateAlphaMask() const
477 {
478 if ( m_hasAlpha )
479 {
480 unsigned char *sourcemask = (unsigned char *) GetRawAccess() ;
481 unsigned char *destalphabase = (unsigned char *) m_maskMemBuf.GetData() ;
482
483 int h = GetHeight() ;
484 int w = GetWidth() ;
485
486 for ( int y = 0 ; y < h ; ++y , destalphabase += m_maskBytesPerRow )
487 {
488 unsigned char* destalpha = destalphabase ;
489 for( int x = 0 ; x < w ; ++x , sourcemask += 4, ++destalpha )
490 {
491 *destalpha = *sourcemask ;
492 }
493 }
494 }
495 }
496
497 void wxBitmapRefData::Free()
498 {
499 wxASSERT_MSG( m_rawAccessCount == 0 , wxT("Bitmap still selected when destroyed") ) ;
500
501 #if wxMAC_USE_CORE_GRAPHICS
502 if ( m_cgImageRef )
503 {
504 CGImageRelease( m_cgImageRef ) ;
505 m_cgImageRef = NULL ;
506 }
507 #endif
508 if ( m_hBitmap )
509 {
510 DisposeGWorld( MAC_WXHBITMAP(m_hBitmap) ) ;
511 m_hBitmap = NULL ;
512 }
513 if ( m_hMaskBitmap )
514 {
515 DisposeGWorld( MAC_WXHBITMAP(m_hMaskBitmap) ) ;
516 m_hMaskBitmap = NULL ;
517 }
518
519 if (m_bitmapMask)
520 {
521 delete m_bitmapMask;
522 m_bitmapMask = NULL;
523 }
524 }
525
526 wxBitmapRefData::~wxBitmapRefData()
527 {
528 Free() ;
529 }
530
531 bool wxBitmap::CopyFromIcon(const wxIcon& icon)
532 {
533 int w = icon.GetWidth() ;
534 int h = icon.GetHeight() ;
535 Create( icon.GetWidth() , icon.GetHeight() ) ;
536
537 if ( w == h && ( w == 16 || w == 32 || w == 48 || w == 128 ) )
538 {
539 IconFamilyHandle iconFamily = NULL ;
540 Handle imagehandle = NewHandle(0) ;
541 Handle maskhandle = NewHandle(0) ;
542
543 OSType maskType = 0;
544 OSType dataType = 0;
545 IconSelectorValue selector = 0 ;
546 if ( w == 128 )
547 {
548 dataType = kThumbnail32BitData ;
549 maskType = kThumbnail8BitMask ;
550 selector = kSelectorAllAvailableData ;
551 }
552 else if ( w == 48 )
553 {
554 dataType = kHuge32BitData ;
555 maskType = kHuge8BitMask ;
556 selector = kSelectorHuge32Bit | kSelectorHuge8BitMask ;
557 }
558 else if ( w == 32 )
559 {
560 dataType = kLarge32BitData ;
561 maskType = kLarge8BitMask ;
562 selector = kSelectorLarge32Bit | kSelectorLarge8BitMask ;
563 }
564 else if ( w == 16 )
565 {
566 dataType = kSmall32BitData ;
567 maskType = kSmall8BitMask ;
568 selector = kSelectorSmall32Bit | kSelectorSmall8BitMask ;
569 }
570 else
571 {
572 wxFAIL_MSG(wxT("Illegal icon size for conversion") ) ;
573 }
574
575
576 OSStatus err = ( IconRefToIconFamily( MAC_WXHICON(icon.GetHICON()) , selector , &iconFamily ) ) ;
577
578 err =( GetIconFamilyData( iconFamily , dataType , imagehandle ) ) ;
579 err =( GetIconFamilyData( iconFamily , maskType , maskhandle ) ) ;
580 wxASSERT( GetHandleSize( imagehandle ) == w * 4 * h ) ;
581 wxASSERT( GetHandleSize( maskhandle ) == w * h ) ;
582 UseAlpha() ;
583 unsigned char *source = (unsigned char *) *imagehandle ;
584 unsigned char *sourcemask = (unsigned char *) *maskhandle ;
585
586 unsigned char* destination = (unsigned char*) BeginRawAccess() ;
587 for ( int y = 0 ; y < h ; ++y )
588 {
589 for ( int x = 0 ; x < w ; ++x )
590 {
591 *destination++ = *sourcemask++ ;
592 source++ ;
593 *destination++ = *source++ ;
594 *destination++ = *source++ ;
595 *destination++ = *source++ ;
596 }
597 }
598 EndRawAccess() ;
599 DisposeHandle( imagehandle ) ;
600 DisposeHandle( maskhandle ) ;
601 }
602 else
603 {
604 wxMemoryDC dc ;
605 dc.SelectObject( *this ) ;
606 dc.DrawIcon( icon , 0 , 0 ) ;
607 dc.SelectObject( wxNullBitmap ) ;
608 }
609 return true;
610 }
611
612 wxBitmap::wxBitmap()
613 {
614 }
615
616 wxBitmap::~wxBitmap()
617 {
618 }
619
620 wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits)
621 {
622 m_refData = new wxBitmapRefData( the_width , the_height , no_bits ) ;
623
624 if ( no_bits == 1 )
625 {
626 int linesize = ( the_width / (sizeof(unsigned char) * 8)) ;
627 if ( the_width % (sizeof(unsigned char) * 8) ) {
628 linesize += sizeof(unsigned char);
629 }
630 unsigned char* linestart = (unsigned char*) bits ;
631 unsigned char* destination = (unsigned char*) BeginRawAccess() ;
632 for ( int y = 0 ; y < the_height ; ++y , linestart += linesize )
633 {
634 for ( int x = 0 ; x < the_width ; ++x )
635 {
636 int index = x / 8 ;
637 int bit = x % 8 ;
638 int mask = 1 << bit ;
639 if ( linestart[index] & mask )
640 {
641 *destination++ = 0xFF ;
642 *destination++ = 0 ;
643 *destination++ = 0 ;
644 *destination++ = 0 ;
645 }
646 else
647 {
648 *destination++ = 0xFF ;
649 *destination++ = 0xFF ;
650 *destination++ = 0xFF ;
651 *destination++ = 0xFF ;
652 }
653 }
654 }
655 EndRawAccess() ;
656 }
657 else
658 {
659 wxFAIL_MSG(wxT("multicolor BITMAPs not yet implemented"));
660 }
661 }
662
663 wxBitmap::wxBitmap(int w, int h, int d)
664 {
665 (void)Create(w, h, d);
666 }
667
668 wxBitmap::wxBitmap(void *data, wxBitmapType type, int width, int height, int depth)
669 {
670 (void) Create(data, type, width, height, depth);
671 }
672
673 wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type)
674 {
675 LoadFile(filename, type);
676 }
677
678 wxBitmap::wxBitmap(const char **bits)
679 {
680 (void) CreateFromXpm(bits);
681 }
682
683 wxBitmap::wxBitmap(char **bits)
684 {
685 (void) CreateFromXpm((const char **)bits);
686 }
687
688 void* wxBitmap::GetRawAccess() const
689 {
690 wxCHECK_MSG( Ok() , NULL , wxT("invalid bitmap") ) ;
691 return M_BITMAPDATA->GetRawAccess() ;
692 }
693
694 void* wxBitmap::BeginRawAccess()
695 {
696 wxCHECK_MSG( Ok() , NULL , wxT("invalid bitmap") ) ;
697 return M_BITMAPDATA->BeginRawAccess() ;
698 }
699
700 void wxBitmap::EndRawAccess()
701 {
702 wxCHECK_RET( Ok() , wxT("invalid bitmap") ) ;
703 M_BITMAPDATA->EndRawAccess() ;
704 }
705
706 bool wxBitmap::CreateFromXpm(const char **bits)
707 {
708 wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") )
709 wxXPMDecoder decoder;
710 wxImage img = decoder.ReadData(bits);
711 wxCHECK_MSG( img.Ok(), FALSE, wxT("invalid bitmap data") )
712 *this = wxBitmap(img);
713 return TRUE;
714 }
715
716 #if wxMAC_USE_CORE_GRAPHICS
717 WXCGIMAGEREF wxBitmap::CGImageCreate() const
718 {
719 wxCHECK_MSG( Ok(), NULL , wxT("invalid bitmap") ) ;
720 return M_BITMAPDATA->CGImageCreate() ;
721 }
722 #endif
723
724 wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
725 {
726 wxCHECK_MSG( Ok() &&
727 (rect.x >= 0) && (rect.y >= 0) &&
728 (rect.x+rect.width <= GetWidth()) &&
729 (rect.y+rect.height <= GetHeight()),
730 wxNullBitmap, wxT("invalid bitmap or bitmap region") );
731
732
733 wxBitmap ret( rect.width, rect.height, GetDepth() );
734 wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") );
735
736
737 int sourcewidth = GetWidth() ;
738 int destwidth = rect.width ;
739 int destheight = rect.height ;
740 {
741 unsigned char * sourcedata = (unsigned char*) GetRawAccess() ;
742 unsigned char * destdata = (unsigned char*) ret.BeginRawAccess() ;
743 int sourcelinesize = sourcewidth * 4 ;
744 int destlinesize = destwidth * 4 ;
745 unsigned char *source = sourcedata + rect.x * 4 + rect.y * sourcelinesize ;
746 unsigned char *dest = destdata ;
747 for(int yy = 0; yy < destheight; ++yy, source += sourcelinesize , dest += destlinesize)
748 {
749 memcpy( dest , source , destlinesize ) ;
750 }
751 }
752 ret.EndRawAccess() ;
753
754 if ( M_BITMAPDATA->m_bitmapMask )
755 {
756 wxMemoryBuffer maskbuf ;
757 int rowBytes = ( destwidth + 3 ) & 0xFFFFFFC ;
758 size_t maskbufsize = rowBytes * destheight ;
759 unsigned char * destdata = (unsigned char * ) maskbuf.GetWriteBuf( maskbufsize ) ;
760
761 int sourcelinesize = M_BITMAPDATA->m_bitmapMask->GetBytesPerRow() ;
762 int destlinesize = rowBytes ;
763 unsigned char *source = (unsigned char *) M_BITMAPDATA->m_bitmapMask->GetRawAccess() ;
764 source += rect.x + rect.y * sourcelinesize ;
765 unsigned char *dest = destdata ;
766
767 for(int yy = 0; yy < destheight; ++yy, source += sourcelinesize , dest += destlinesize)
768 {
769 memcpy( dest , source , destlinesize ) ;
770 }
771 maskbuf.UngetWriteBuf( maskbufsize ) ;
772 ret.SetMask( new wxMask( maskbuf , destwidth , destheight , rowBytes ) ) ;
773 }
774 else if ( HasAlpha() )
775 ret.UseAlpha() ;
776
777 return ret;
778 }
779
780 bool wxBitmap::Create(int w, int h, int d)
781 {
782 UnRef();
783
784 if ( d < 0 )
785 d = wxDisplayDepth() ;
786
787 m_refData = new wxBitmapRefData( w , h , d );
788
789 return M_BITMAPDATA->Ok() ;
790 }
791
792 bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type)
793 {
794 UnRef();
795
796 wxBitmapHandler *handler = FindHandler(type);
797
798 if ( handler )
799 {
800 m_refData = new wxBitmapRefData;
801
802 return handler->LoadFile(this, filename, type, -1, -1);
803 }
804 else
805 {
806 wxImage loadimage(filename, type);
807 if (loadimage.Ok()) {
808 *this = loadimage;
809 return true;
810 }
811 }
812 wxLogWarning(wxT("no bitmap handler for type %d defined."), type);
813 return false;
814 }
815
816 bool wxBitmap::Create(void *data, wxBitmapType type, int width, int height, int depth)
817 {
818 UnRef();
819
820 m_refData = new wxBitmapRefData;
821
822 wxBitmapHandler *handler = FindHandler(type);
823
824 if ( handler == NULL ) {
825 wxLogWarning(wxT("no bitmap handler for type %d defined."), type);
826
827 return FALSE;
828 }
829
830 return handler->Create(this, data, type, width, height, depth);
831 }
832
833 wxBitmap::wxBitmap(const wxImage& image, int depth)
834 {
835 wxCHECK_RET( image.Ok(), wxT("invalid image") )
836
837 // width and height of the device-dependent bitmap
838 int width = image.GetWidth();
839 int height = image.GetHeight();
840
841 m_refData = new wxBitmapRefData( width , height , depth ) ;;
842
843 // Create picture
844
845 bool hasAlpha = false ;
846
847 if ( image.HasMask() )
848 {
849 // takes precedence, don't mix with alpha info
850 }
851 else
852 {
853 hasAlpha = image.HasAlpha() ;
854 }
855
856 if ( hasAlpha )
857 UseAlpha() ;
858
859 unsigned char* destination = (unsigned char*) BeginRawAccess() ;
860
861 register unsigned char* data = image.GetData();
862 const unsigned char *alpha = hasAlpha ? image.GetAlpha() : NULL ;
863 for (int y = 0; y < height; y++)
864 {
865 for (int x = 0; x < width; x++)
866 {
867 if ( hasAlpha )
868 {
869 const unsigned char a = *alpha++;
870 *destination++ = a ;
871 #if wxMAC_USE_PREMULTIPLIED_ALPHA
872 *destination++ = ((*data++) * a + 127 ) / 255 ;
873 *destination++ = ((*data++) * a + 127 ) / 255 ;
874 *destination++ = ((*data++) * a + 127 ) / 255 ;
875 #else
876 *destination++ = *data++ ;
877 *destination++ = *data++ ;
878 *destination++ = *data++ ;
879 #endif
880 }
881 else
882 {
883 *destination++ = 0xFF ;
884 *destination++ = *data++ ;
885 *destination++ = *data++ ;
886 *destination++ = *data++ ;
887 }
888 }
889 }
890 EndRawAccess() ;
891 if ( image.HasMask() )
892 {
893 SetMask( new wxMask( *this , wxColour( image.GetMaskRed() , image.GetMaskGreen() , image.GetMaskBlue() ) ) ) ;
894 }
895 }
896
897 wxImage wxBitmap::ConvertToImage() const
898 {
899 wxImage image;
900
901 wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") );
902
903 // create an wxImage object
904 int width = GetWidth();
905 int height = GetHeight();
906 image.Create( width, height );
907
908 unsigned char *data = image.GetData();
909 wxCHECK_MSG( data, wxNullImage, wxT("Could not allocate data for image") );
910
911 unsigned char* source = (unsigned char*) GetRawAccess() ;
912
913 bool hasAlpha = false ;
914 bool hasMask = false ;
915 unsigned char *alpha = NULL ;
916 unsigned char *mask = NULL ;
917 if ( HasAlpha() )
918 {
919 hasAlpha = true ;
920 }
921
922 if ( GetMask() )
923 {
924 hasMask = true ;
925 mask = (unsigned char*) GetMask()->GetRawAccess() ;
926 }
927
928 if ( hasAlpha )
929 {
930 image.SetAlpha() ;
931 alpha = image.GetAlpha() ;
932 }
933 int index = 0;
934
935 // The following masking algorithm is the same as well in msw/gtk:
936 // the colour used as transparent one in wxImage and the one it is
937 // replaced with when it really occurs in the bitmap
938 static const int MASK_RED = 1;
939 static const int MASK_GREEN = 2;
940 static const int MASK_BLUE = 3;
941 static const int MASK_BLUE_REPLACEMENT = 2;
942
943 for (int yy = 0; yy < height; yy++)
944 {
945 for (int xx = 0; xx < width; xx++)
946 {
947 long color = *((long*) source) ;
948 unsigned char a = ((color&0xFF000000) >> 24) ;
949 unsigned char r = ((color&0x00FF0000) >> 16) ;
950 unsigned char g = ((color&0x0000FF00) >> 8) ;
951 unsigned char b = (color&0x000000FF);
952 if ( hasMask )
953 {
954 if ( *mask++ == 0 )
955 {
956 if ( r == MASK_RED && g == MASK_GREEN && b == MASK_BLUE )
957 b = MASK_BLUE_REPLACEMENT ;
958 }
959 else
960 {
961 r = MASK_RED ;
962 g = MASK_GREEN ;
963 b = MASK_BLUE ;
964 }
965 }
966 else if ( hasAlpha )
967 *alpha++ = a ;
968
969 data[index ] = r ;
970 data[index + 1] = g ;
971 data[index + 2] = b ;
972 index += 3;
973 source += 4 ;
974 }
975 }
976 if ( hasMask )
977 image.SetMaskColour( MASK_RED, MASK_GREEN, MASK_BLUE );
978 return image;
979 }
980
981
982 bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type,
983 const wxPalette *palette) const
984 {
985 wxBitmapHandler *handler = FindHandler(type);
986
987 if ( handler )
988 {
989 return handler->SaveFile(this, filename, type, palette);
990 }
991 else
992 {
993 wxImage image = ConvertToImage();
994
995 return image.SaveFile(filename, type);
996 }
997
998 wxLogWarning(wxT("no bitmap handler for type %d defined."), type);
999 return false;
1000 }
1001
1002 bool wxBitmap::Ok() const
1003 {
1004 return (M_BITMAPDATA && M_BITMAPDATA->Ok());
1005 }
1006
1007 int wxBitmap::GetHeight() const
1008 {
1009 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
1010
1011 return M_BITMAPDATA->GetHeight();
1012 }
1013
1014 int wxBitmap::GetWidth() const
1015 {
1016 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
1017
1018 return M_BITMAPDATA->GetWidth() ;
1019 }
1020
1021 int wxBitmap::GetDepth() const
1022 {
1023 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
1024
1025 return M_BITMAPDATA->GetDepth();
1026 }
1027
1028 int wxBitmap::GetQuality() const
1029 {
1030 return 0;
1031 }
1032
1033 wxMask *wxBitmap::GetMask() const
1034 {
1035 wxCHECK_MSG( Ok(), (wxMask *) NULL, wxT("invalid bitmap") );
1036
1037 return M_BITMAPDATA->m_bitmapMask;
1038 }
1039
1040 bool wxBitmap::HasAlpha() const
1041 {
1042 wxCHECK_MSG( Ok(), false , wxT("invalid bitmap") );
1043
1044 return M_BITMAPDATA->HasAlpha() ;
1045 }
1046
1047 void wxBitmap::SetWidth(int w)
1048 {
1049 if (!M_BITMAPDATA)
1050 m_refData = new wxBitmapRefData;
1051
1052 M_BITMAPDATA->SetWidth(w);
1053 }
1054
1055 void wxBitmap::SetHeight(int h)
1056 {
1057 if (!M_BITMAPDATA)
1058 m_refData = new wxBitmapRefData;
1059
1060 M_BITMAPDATA->SetHeight(h);
1061 }
1062
1063 void wxBitmap::SetDepth(int d)
1064 {
1065 if (!M_BITMAPDATA)
1066 m_refData = new wxBitmapRefData;
1067
1068 M_BITMAPDATA->SetDepth(d);
1069 }
1070
1071 void wxBitmap::SetQuality(int WXUNUSED(quality))
1072 {
1073 }
1074
1075 void wxBitmap::SetOk(bool isOk)
1076 {
1077 if (!M_BITMAPDATA)
1078 m_refData = new wxBitmapRefData;
1079
1080 M_BITMAPDATA->SetOk(isOk);
1081 }
1082
1083 #if wxUSE_PALETTE
1084 wxPalette *wxBitmap::GetPalette() const
1085 {
1086 wxCHECK_MSG( Ok(), NULL, wxT("Invalid bitmap GetPalette()") );
1087
1088 return &M_BITMAPDATA->m_bitmapPalette;
1089 }
1090
1091 void wxBitmap::SetPalette(const wxPalette& palette)
1092 {
1093 if (!M_BITMAPDATA)
1094 m_refData = new wxBitmapRefData;
1095
1096 M_BITMAPDATA->m_bitmapPalette = palette ;
1097 }
1098 #endif // wxUSE_PALETTE
1099
1100 void wxBitmap::SetMask(wxMask *mask)
1101 {
1102 if (!M_BITMAPDATA)
1103 m_refData = new wxBitmapRefData;
1104
1105 // Remove existing mask if there is one.
1106 delete M_BITMAPDATA->m_bitmapMask;
1107
1108 M_BITMAPDATA->m_bitmapMask = mask ;
1109 }
1110
1111 WXHBITMAP wxBitmap::GetHBITMAP(WXHBITMAP* mask) const
1112 {
1113 return WXHBITMAP(M_BITMAPDATA->GetHBITMAP((GWorldPtr*)mask));
1114 }
1115
1116 // ----------------------------------------------------------------------------
1117 // wxMask
1118 // ----------------------------------------------------------------------------
1119
1120 wxMask::wxMask()
1121 {
1122 Init() ;
1123 }
1124
1125 // Construct a mask from a bitmap and a colour indicating
1126 // the transparent area
1127 wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour)
1128 {
1129 Init() ;
1130 Create(bitmap, colour);
1131 }
1132
1133 // Construct a mask from a mono bitmap (copies the bitmap).
1134 wxMask::wxMask(const wxBitmap& bitmap)
1135 {
1136 Init() ;
1137 Create(bitmap);
1138 }
1139
1140 // Construct a mask from a mono bitmap (copies the bitmap).
1141 wxMask::wxMask(const wxMemoryBuffer& data, int width , int height , int bytesPerRow )
1142 {
1143 Init() ;
1144 Create(data, width , height , bytesPerRow );
1145 }
1146
1147 wxMask::~wxMask()
1148 {
1149 if ( m_maskBitmap )
1150 {
1151 DisposeGWorld( (GWorldPtr) m_maskBitmap ) ;
1152 m_maskBitmap = NULL ;
1153 }
1154 }
1155
1156 void wxMask::Init()
1157 {
1158 m_width = m_height = m_bytesPerRow = 0 ;
1159 m_maskBitmap = NULL ;
1160 }
1161
1162 void *wxMask::GetRawAccess() const
1163 {
1164 return m_memBuf.GetData() ;
1165 }
1166
1167 void wxMask::RealizeNative()
1168 {
1169 if ( m_maskBitmap )
1170 {
1171 DisposeGWorld( (GWorldPtr) m_maskBitmap ) ;
1172 m_maskBitmap = NULL ;
1173 }
1174 Rect rect = { 0 , 0 , m_height , m_width } ;
1175 verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_maskBitmap , k8IndexedGrayPixelFormat , &rect , NULL , NULL , 0 ,
1176 (char*) m_memBuf.GetData() , m_bytesPerRow ) ) ;
1177 }
1178
1179 // Create a mask from a mono bitmap (copies the bitmap).
1180 bool wxMask::Create(const wxMemoryBuffer& data,int width , int height , int bytesPerRow)
1181 {
1182 m_memBuf = data ;
1183 m_width = width ;
1184 m_height = height ;
1185 m_bytesPerRow = bytesPerRow ;
1186 wxASSERT( data.GetDataLen() == (size_t)(height * bytesPerRow) ) ;
1187 RealizeNative() ;
1188 return true ;
1189 }
1190
1191 // Create a mask from a mono bitmap (copies the bitmap).
1192 bool wxMask::Create(const wxBitmap& bitmap)
1193 {
1194 m_width = bitmap.GetWidth() ;
1195 m_height = bitmap.GetHeight() ;
1196 m_bytesPerRow = ( m_width + 3 ) & 0xFFFFFFC ;
1197 size_t size = m_bytesPerRow * m_height ;
1198 unsigned char * destdatabase = (unsigned char*) m_memBuf.GetWriteBuf( size ) ;
1199 memset( destdatabase , 0 , size ) ;
1200 unsigned char * srcdata = (unsigned char*) bitmap.GetRawAccess() ;
1201 for ( int y = 0 ; y < m_height ; ++y , destdatabase += m_bytesPerRow )
1202 {
1203 unsigned char *destdata= destdatabase ;
1204 for( int x = 0 ; x < m_width ; ++x )
1205 {
1206 srcdata++ ;
1207 unsigned char r = *srcdata++ ;
1208 unsigned char g = *srcdata++ ;
1209 unsigned char b = *srcdata++ ;
1210 if ( ( r + g + b ) > 0x10 )
1211 *destdata++ = 0x00 ;
1212 else
1213 *destdata++ = 0xFF ;
1214 }
1215 }
1216 m_memBuf.UngetWriteBuf( size ) ;
1217 RealizeNative() ;
1218 return TRUE;
1219 }
1220
1221 // Create a mask from a bitmap and a colour indicating
1222 // the transparent area
1223 bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
1224 {
1225 m_width = bitmap.GetWidth() ;
1226 m_height = bitmap.GetHeight() ;
1227 m_bytesPerRow = ( m_width + 3 ) & 0xFFFFFFC ;
1228 size_t size = m_bytesPerRow * m_height ;
1229
1230 unsigned char * destdatabase = (unsigned char*) m_memBuf.GetWriteBuf( size ) ;
1231 memset( destdatabase , 0 , size ) ;
1232 unsigned char * srcdata = (unsigned char*) bitmap.GetRawAccess() ;
1233 for ( int y = 0 ; y < m_height ; ++y , destdatabase += m_bytesPerRow)
1234 {
1235 unsigned char *destdata= destdatabase ;
1236 for( int x = 0 ; x < m_width ; ++x )
1237 {
1238 srcdata++ ;
1239 unsigned char r = *srcdata++ ;
1240 unsigned char g = *srcdata++ ;
1241 unsigned char b = *srcdata++ ;
1242 if ( colour == wxColour( r , g , b) )
1243 *destdata++ = 0x00 ;
1244 else
1245 *destdata++ = 0xFF ;
1246 }
1247 }
1248 m_memBuf.UngetWriteBuf( size ) ;
1249 RealizeNative() ;
1250 return TRUE;
1251 }
1252
1253 WXHBITMAP wxMask::GetHBITMAP() const
1254 {
1255 return m_maskBitmap ;
1256 }
1257
1258 // ----------------------------------------------------------------------------
1259 // wxBitmapHandler
1260 // ----------------------------------------------------------------------------
1261
1262 wxBitmapHandler::~wxBitmapHandler()
1263 {
1264 }
1265
1266 bool wxBitmapHandler::Create(wxBitmap *bitmap, void *data, long type, int width, int height, int depth)
1267 {
1268 return FALSE;
1269 }
1270
1271 bool wxBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
1272 int desiredWidth, int desiredHeight)
1273 {
1274 return FALSE;
1275 }
1276
1277 bool wxBitmapHandler::SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette)
1278 {
1279 return FALSE;
1280 }
1281
1282 // ----------------------------------------------------------------------------
1283 // Standard Handlers
1284 // ----------------------------------------------------------------------------
1285
1286 class WXDLLEXPORT wxPICTResourceHandler: public wxBitmapHandler
1287 {
1288 DECLARE_DYNAMIC_CLASS(wxPICTResourceHandler)
1289 public:
1290 inline wxPICTResourceHandler()
1291 {
1292 SetName(wxT("Macintosh Pict resource"));
1293 SetExtension(wxEmptyString);
1294 SetType(wxBITMAP_TYPE_PICT_RESOURCE);
1295 };
1296
1297 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
1298 int desiredWidth, int desiredHeight);
1299 };
1300 IMPLEMENT_DYNAMIC_CLASS(wxPICTResourceHandler, wxBitmapHandler)
1301
1302 bool wxPICTResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
1303 int desiredWidth, int desiredHeight)
1304 {
1305 Str255 theName ;
1306 wxMacStringToPascal( name , theName ) ;
1307
1308 PicHandle thePict = (PicHandle ) GetNamedResource( 'PICT' , theName ) ;
1309 if ( thePict )
1310 {
1311 wxMetafile mf ;
1312 mf.SetHMETAFILE((WXHMETAFILE) thePict ) ;
1313 bitmap->Create( mf.GetWidth() , mf.GetHeight() ) ;
1314 wxMemoryDC dc ;
1315 dc.SelectObject( *bitmap ) ;
1316 mf.Play( &dc ) ;
1317 dc.SelectObject( wxNullBitmap ) ;
1318 return TRUE ;
1319 }
1320 return FALSE ;
1321 }
1322
1323 void wxBitmap::InitStandardHandlers()
1324 {
1325 AddHandler(new wxPICTResourceHandler) ;
1326 AddHandler(new wxICONResourceHandler) ;
1327 }
1328
1329 // ----------------------------------------------------------------------------
1330 // raw bitmap access support
1331 // ----------------------------------------------------------------------------
1332
1333 void *wxBitmap::GetRawData(wxPixelDataBase& data, int bpp)
1334 {
1335 if ( !Ok() )
1336 {
1337 // no bitmap, no data (raw or otherwise)
1338 return NULL;
1339 }
1340
1341 data.m_width = GetWidth() ;
1342 data.m_height = GetHeight() ;
1343 data.m_stride = GetWidth() * 4 ;
1344 return GetRawAccess() ;
1345 }
1346
1347 void wxBitmap::UngetRawData(wxPixelDataBase& dataBase)
1348 {
1349 if ( !Ok() )
1350 return;
1351
1352 // TODO : if we have some information about the API we should check
1353 // this code looks strange...
1354
1355 if ( M_BITMAPDATA->HasAlpha() )
1356 {
1357 wxAlphaPixelData& data = (wxAlphaPixelData&)dataBase;
1358
1359 int w = data.GetWidth(),
1360 h = data.GetHeight();
1361
1362 wxBitmap bmpMask(GetWidth(), GetHeight(), 32);
1363 wxAlphaPixelData dataMask(bmpMask, data.GetOrigin(), wxSize(w, h));
1364 wxAlphaPixelData::Iterator pMask(dataMask),
1365 p(data);
1366 for ( int y = 0; y < h; y++ )
1367 {
1368 wxAlphaPixelData::Iterator rowStartMask = pMask,
1369 rowStart = p;
1370
1371 for ( int x = 0; x < w; x++ )
1372 {
1373 const wxAlphaPixelData::Iterator::ChannelType
1374 alpha = p.Alpha();
1375
1376 pMask.Red() = alpha;
1377 pMask.Green() = alpha;
1378 pMask.Blue() = alpha;
1379
1380 ++p;
1381 ++pMask;
1382 }
1383
1384 p = rowStart;
1385 p.OffsetY(data, 1);
1386
1387 pMask = rowStartMask;
1388 pMask.OffsetY(dataMask, 1);
1389 }
1390
1391 SetMask(new wxMask(bmpMask));
1392 }
1393 }
1394
1395 void wxBitmap::UseAlpha()
1396 {
1397 // remember that we are using alpha channel, we'll need to create a proper
1398 // mask in UngetRawData()
1399 M_BITMAPDATA->UseAlpha( true );
1400 }