]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/bitmap.cpp
96f0be423e457a50578c61291ceab2e2d99b3bb8
[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 #if WXWIN_COMPATIBILITY_2_4
1029
1030 int wxBitmap::GetQuality() const
1031 {
1032 return 0;
1033 }
1034
1035 #endif
1036
1037 wxMask *wxBitmap::GetMask() const
1038 {
1039 wxCHECK_MSG( Ok(), (wxMask *) NULL, wxT("invalid bitmap") );
1040
1041 return M_BITMAPDATA->m_bitmapMask;
1042 }
1043
1044 bool wxBitmap::HasAlpha() const
1045 {
1046 wxCHECK_MSG( Ok(), false , wxT("invalid bitmap") );
1047
1048 return M_BITMAPDATA->HasAlpha() ;
1049 }
1050
1051 void wxBitmap::SetWidth(int w)
1052 {
1053 if (!M_BITMAPDATA)
1054 m_refData = new wxBitmapRefData;
1055
1056 M_BITMAPDATA->SetWidth(w);
1057 }
1058
1059 void wxBitmap::SetHeight(int h)
1060 {
1061 if (!M_BITMAPDATA)
1062 m_refData = new wxBitmapRefData;
1063
1064 M_BITMAPDATA->SetHeight(h);
1065 }
1066
1067 void wxBitmap::SetDepth(int d)
1068 {
1069 if (!M_BITMAPDATA)
1070 m_refData = new wxBitmapRefData;
1071
1072 M_BITMAPDATA->SetDepth(d);
1073 }
1074
1075 #if WXWIN_COMPATIBILITY_2_4
1076
1077 void wxBitmap::SetQuality(int WXUNUSED(quality))
1078 {
1079 }
1080
1081 #endif
1082
1083 void wxBitmap::SetOk(bool isOk)
1084 {
1085 if (!M_BITMAPDATA)
1086 m_refData = new wxBitmapRefData;
1087
1088 M_BITMAPDATA->SetOk(isOk);
1089 }
1090
1091 #if wxUSE_PALETTE
1092 wxPalette *wxBitmap::GetPalette() const
1093 {
1094 wxCHECK_MSG( Ok(), NULL, wxT("Invalid bitmap GetPalette()") );
1095
1096 return &M_BITMAPDATA->m_bitmapPalette;
1097 }
1098
1099 void wxBitmap::SetPalette(const wxPalette& palette)
1100 {
1101 if (!M_BITMAPDATA)
1102 m_refData = new wxBitmapRefData;
1103
1104 M_BITMAPDATA->m_bitmapPalette = palette ;
1105 }
1106 #endif // wxUSE_PALETTE
1107
1108 void wxBitmap::SetMask(wxMask *mask)
1109 {
1110 if (!M_BITMAPDATA)
1111 m_refData = new wxBitmapRefData;
1112
1113 // Remove existing mask if there is one.
1114 delete M_BITMAPDATA->m_bitmapMask;
1115
1116 M_BITMAPDATA->m_bitmapMask = mask ;
1117 }
1118
1119 WXHBITMAP wxBitmap::GetHBITMAP(WXHBITMAP* mask) const
1120 {
1121 return WXHBITMAP(M_BITMAPDATA->GetHBITMAP((GWorldPtr*)mask));
1122 }
1123
1124 // ----------------------------------------------------------------------------
1125 // wxMask
1126 // ----------------------------------------------------------------------------
1127
1128 wxMask::wxMask()
1129 {
1130 Init() ;
1131 }
1132
1133 // Construct a mask from a bitmap and a colour indicating
1134 // the transparent area
1135 wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour)
1136 {
1137 Init() ;
1138 Create(bitmap, colour);
1139 }
1140
1141 // Construct a mask from a mono bitmap (copies the bitmap).
1142 wxMask::wxMask(const wxBitmap& bitmap)
1143 {
1144 Init() ;
1145 Create(bitmap);
1146 }
1147
1148 // Construct a mask from a mono bitmap (copies the bitmap).
1149 wxMask::wxMask(const wxMemoryBuffer& data, int width , int height , int bytesPerRow )
1150 {
1151 Init() ;
1152 Create(data, width , height , bytesPerRow );
1153 }
1154
1155 wxMask::~wxMask()
1156 {
1157 if ( m_maskBitmap )
1158 {
1159 DisposeGWorld( (GWorldPtr) m_maskBitmap ) ;
1160 m_maskBitmap = NULL ;
1161 }
1162 }
1163
1164 void wxMask::Init()
1165 {
1166 m_width = m_height = m_bytesPerRow = 0 ;
1167 m_maskBitmap = NULL ;
1168 }
1169
1170 void *wxMask::GetRawAccess() const
1171 {
1172 return m_memBuf.GetData() ;
1173 }
1174
1175 void wxMask::RealizeNative()
1176 {
1177 if ( m_maskBitmap )
1178 {
1179 DisposeGWorld( (GWorldPtr) m_maskBitmap ) ;
1180 m_maskBitmap = NULL ;
1181 }
1182 Rect rect = { 0 , 0 , m_height , m_width } ;
1183 verify_noerr( NewGWorldFromPtr( (GWorldPtr*) &m_maskBitmap , k8IndexedGrayPixelFormat , &rect , NULL , NULL , 0 ,
1184 (char*) m_memBuf.GetData() , m_bytesPerRow ) ) ;
1185 }
1186
1187 // Create a mask from a mono bitmap (copies the bitmap).
1188 bool wxMask::Create(const wxMemoryBuffer& data,int width , int height , int bytesPerRow)
1189 {
1190 m_memBuf = data ;
1191 m_width = width ;
1192 m_height = height ;
1193 m_bytesPerRow = bytesPerRow ;
1194 wxASSERT( data.GetDataLen() == (size_t)(height * bytesPerRow) ) ;
1195 RealizeNative() ;
1196 return true ;
1197 }
1198
1199 // Create a mask from a mono bitmap (copies the bitmap).
1200 bool wxMask::Create(const wxBitmap& bitmap)
1201 {
1202 m_width = bitmap.GetWidth() ;
1203 m_height = bitmap.GetHeight() ;
1204 m_bytesPerRow = ( m_width + 3 ) & 0xFFFFFFC ;
1205 size_t size = m_bytesPerRow * m_height ;
1206 unsigned char * destdatabase = (unsigned char*) m_memBuf.GetWriteBuf( size ) ;
1207 memset( destdatabase , 0 , size ) ;
1208 unsigned char * srcdata = (unsigned char*) bitmap.GetRawAccess() ;
1209 for ( int y = 0 ; y < m_height ; ++y , destdatabase += m_bytesPerRow )
1210 {
1211 unsigned char *destdata= destdatabase ;
1212 for( int x = 0 ; x < m_width ; ++x )
1213 {
1214 srcdata++ ;
1215 unsigned char r = *srcdata++ ;
1216 unsigned char g = *srcdata++ ;
1217 unsigned char b = *srcdata++ ;
1218 if ( ( r + g + b ) > 0x10 )
1219 *destdata++ = 0x00 ;
1220 else
1221 *destdata++ = 0xFF ;
1222 }
1223 }
1224 m_memBuf.UngetWriteBuf( size ) ;
1225 RealizeNative() ;
1226 return TRUE;
1227 }
1228
1229 // Create a mask from a bitmap and a colour indicating
1230 // the transparent area
1231 bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
1232 {
1233 m_width = bitmap.GetWidth() ;
1234 m_height = bitmap.GetHeight() ;
1235 m_bytesPerRow = ( m_width + 3 ) & 0xFFFFFFC ;
1236 size_t size = m_bytesPerRow * m_height ;
1237
1238 unsigned char * destdatabase = (unsigned char*) m_memBuf.GetWriteBuf( size ) ;
1239 memset( destdatabase , 0 , size ) ;
1240 unsigned char * srcdata = (unsigned char*) bitmap.GetRawAccess() ;
1241 for ( int y = 0 ; y < m_height ; ++y , destdatabase += m_bytesPerRow)
1242 {
1243 unsigned char *destdata= destdatabase ;
1244 for( int x = 0 ; x < m_width ; ++x )
1245 {
1246 srcdata++ ;
1247 unsigned char r = *srcdata++ ;
1248 unsigned char g = *srcdata++ ;
1249 unsigned char b = *srcdata++ ;
1250 if ( colour == wxColour( r , g , b) )
1251 *destdata++ = 0x00 ;
1252 else
1253 *destdata++ = 0xFF ;
1254 }
1255 }
1256 m_memBuf.UngetWriteBuf( size ) ;
1257 RealizeNative() ;
1258 return TRUE;
1259 }
1260
1261 WXHBITMAP wxMask::GetHBITMAP() const
1262 {
1263 return m_maskBitmap ;
1264 }
1265
1266 // ----------------------------------------------------------------------------
1267 // wxBitmapHandler
1268 // ----------------------------------------------------------------------------
1269
1270 wxBitmapHandler::~wxBitmapHandler()
1271 {
1272 }
1273
1274 bool wxBitmapHandler::Create(wxBitmap *bitmap, void *data, long type, int width, int height, int depth)
1275 {
1276 return FALSE;
1277 }
1278
1279 bool wxBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
1280 int desiredWidth, int desiredHeight)
1281 {
1282 return FALSE;
1283 }
1284
1285 bool wxBitmapHandler::SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette)
1286 {
1287 return FALSE;
1288 }
1289
1290 // ----------------------------------------------------------------------------
1291 // Standard Handlers
1292 // ----------------------------------------------------------------------------
1293
1294 class WXDLLEXPORT wxPICTResourceHandler: public wxBitmapHandler
1295 {
1296 DECLARE_DYNAMIC_CLASS(wxPICTResourceHandler)
1297 public:
1298 inline wxPICTResourceHandler()
1299 {
1300 SetName(wxT("Macintosh Pict resource"));
1301 SetExtension(wxEmptyString);
1302 SetType(wxBITMAP_TYPE_PICT_RESOURCE);
1303 };
1304
1305 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
1306 int desiredWidth, int desiredHeight);
1307 };
1308 IMPLEMENT_DYNAMIC_CLASS(wxPICTResourceHandler, wxBitmapHandler)
1309
1310
1311 bool wxPICTResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
1312 int desiredWidth, int desiredHeight)
1313 {
1314 #if wxUSE_METAFILE
1315 Str255 theName ;
1316 wxMacStringToPascal( name , theName ) ;
1317
1318 PicHandle thePict = (PicHandle ) GetNamedResource( 'PICT' , theName ) ;
1319 if ( thePict )
1320 {
1321 wxMetafile mf ;
1322 mf.SetHMETAFILE((WXHMETAFILE) thePict ) ;
1323 bitmap->Create( mf.GetWidth() , mf.GetHeight() ) ;
1324 wxMemoryDC dc ;
1325 dc.SelectObject( *bitmap ) ;
1326 mf.Play( &dc ) ;
1327 dc.SelectObject( wxNullBitmap ) ;
1328 return TRUE ;
1329 }
1330 #endif //wxUSE_METAFILE
1331 return FALSE ;
1332 }
1333
1334
1335 void wxBitmap::InitStandardHandlers()
1336 {
1337 AddHandler(new wxPICTResourceHandler) ;
1338 AddHandler(new wxICONResourceHandler) ;
1339 }
1340
1341 // ----------------------------------------------------------------------------
1342 // raw bitmap access support
1343 // ----------------------------------------------------------------------------
1344
1345 void *wxBitmap::GetRawData(wxPixelDataBase& data, int bpp)
1346 {
1347 if ( !Ok() )
1348 {
1349 // no bitmap, no data (raw or otherwise)
1350 return NULL;
1351 }
1352
1353 data.m_width = GetWidth() ;
1354 data.m_height = GetHeight() ;
1355 data.m_stride = GetWidth() * 4 ;
1356 return GetRawAccess() ;
1357 }
1358
1359 void wxBitmap::UngetRawData(wxPixelDataBase& dataBase)
1360 {
1361 if ( !Ok() )
1362 return;
1363
1364 // TODO : if we have some information about the API we should check
1365 // this code looks strange...
1366
1367 if ( M_BITMAPDATA->HasAlpha() )
1368 {
1369 wxAlphaPixelData& data = (wxAlphaPixelData&)dataBase;
1370
1371 int w = data.GetWidth(),
1372 h = data.GetHeight();
1373
1374 wxBitmap bmpMask(GetWidth(), GetHeight(), 32);
1375 wxAlphaPixelData dataMask(bmpMask, data.GetOrigin(), wxSize(w, h));
1376 wxAlphaPixelData::Iterator pMask(dataMask),
1377 p(data);
1378 for ( int y = 0; y < h; y++ )
1379 {
1380 wxAlphaPixelData::Iterator rowStartMask = pMask,
1381 rowStart = p;
1382
1383 for ( int x = 0; x < w; x++ )
1384 {
1385 const wxAlphaPixelData::Iterator::ChannelType
1386 alpha = p.Alpha();
1387
1388 pMask.Red() = alpha;
1389 pMask.Green() = alpha;
1390 pMask.Blue() = alpha;
1391
1392 ++p;
1393 ++pMask;
1394 }
1395
1396 p = rowStart;
1397 p.OffsetY(data, 1);
1398
1399 pMask = rowStartMask;
1400 pMask.OffsetY(dataMask, 1);
1401 }
1402
1403 SetMask(new wxMask(bmpMask));
1404 }
1405 }
1406
1407 void wxBitmap::UseAlpha()
1408 {
1409 // remember that we are using alpha channel, we'll need to create a proper
1410 // mask in UngetRawData()
1411 M_BITMAPDATA->UseAlpha( true );
1412 }