]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/bitmap.cpp
revert my last change
[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 #ifdef __GNUG__
13 #pragma implementation "bitmap.h"
14 #endif
15
16 #include "wx/defs.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/xpmdecod.h"
23
24 #include "wx/rawbmp.h"
25
26 IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
27 IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
28 IMPLEMENT_DYNAMIC_CLASS(wxBitmapHandler, wxObject )
29
30 #ifdef __DARWIN__
31 #include <ApplicationServices/ApplicationServices.h>
32 #else
33 #include <PictUtils.h>
34 #endif
35
36 #include "wx/mac/uma.h"
37
38 CTabHandle wxMacCreateColorTable( int numColors )
39 {
40 CTabHandle newColors; /* Handle to the new color table */
41
42 /* Allocate memory for the color table */
43 newColors = (CTabHandle)NewHandleClear( sizeof (ColorTable) +
44 sizeof (ColorSpec) * (numColors - 1) );
45 if (newColors != nil)
46 {
47 /* Initialize the fields */
48 (**newColors).ctSeed = GetCTSeed();
49 (**newColors).ctFlags = 0;
50 (**newColors).ctSize = numColors - 1;
51 /* Initialize the table of colors */
52 }
53 return newColors ;
54 }
55
56 void wxMacDestroyColorTable( CTabHandle colors )
57 {
58 DisposeHandle( (Handle) colors ) ;
59 }
60
61 void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue )
62 {
63 (**newColors).ctTable[index].value = index;
64 (**newColors).ctTable[index].rgb.red = red ; // someRedValue;
65 (**newColors).ctTable[index].rgb.green = green ; // someGreenValue;
66 (**newColors).ctTable[index].rgb.blue = blue ; // someBlueValue;
67 }
68
69 GWorldPtr wxMacCreateGWorld( int width , int height , int depth )
70 {
71 OSErr err = noErr ;
72 GWorldPtr port ;
73 Rect rect = { 0 , 0 , height , width } ;
74
75 if ( depth < 0 )
76 {
77 depth = wxDisplayDepth() ;
78 }
79
80 err = NewGWorld( &port , depth , &rect , NULL , NULL , 0 ) ;
81 if ( err == noErr )
82 {
83 return port ;
84 }
85 return NULL ;
86 }
87
88 void wxMacDestroyGWorld( GWorldPtr gw )
89 {
90 if ( gw )
91 DisposeGWorld( gw ) ;
92 }
93
94 #define kDefaultRes 0x00480000 /* Default resolution is 72 DPI; Fixed type */
95
96 OSErr SetupCIconHandlePixMap( CIconHandle icon , short depth , Rect *bounds , CTabHandle colors )
97 {
98 CTabHandle newColors; /* Color table used for the off-screen PixMap */
99 Ptr offBaseAddr; /* Pointer to the off-screen pixel image */
100 OSErr error; /* Returns error code */
101 short bytesPerRow; /* Number of bytes per row in the PixMap */
102
103
104 error = noErr;
105 newColors = nil;
106 offBaseAddr = nil;
107
108 bytesPerRow = ((depth * (bounds->right - bounds->left) + 31) / 32) * 4;
109
110 /* Clone the clut if indexed color; allocate a dummy clut if direct color*/
111 if (depth <= 8)
112 {
113 newColors = colors;
114 error = HandToHand((Handle *) &newColors);
115 }
116 else
117 {
118 newColors = (CTabHandle) NewHandle(sizeof(ColorTable) -
119 sizeof(CSpecArray));
120 error = MemError();
121 }
122 if (error == noErr)
123 {
124 /* Allocate pixel image; long integer multiplication avoids overflow */
125 (**icon).iconData = NewHandle((unsigned long) bytesPerRow * (bounds->bottom -
126 bounds->top));
127 if ((**icon).iconData != nil)
128 {
129 /* Initialize fields common to indexed and direct PixMaps */
130 (**icon).iconPMap.baseAddr = 0; /* Point to image */
131 (**icon).iconPMap.rowBytes = bytesPerRow | /* MSB set for PixMap */
132 0x8000;
133 (**icon).iconPMap.bounds = *bounds; /* Use given bounds */
134 (**icon).iconPMap.pmVersion = 0; /* No special stuff */
135 (**icon).iconPMap.packType = 0; /* Default PICT pack */
136 (**icon).iconPMap.packSize = 0; /* Always zero in mem */
137 (**icon).iconPMap.hRes = kDefaultRes; /* 72 DPI default res */
138 (**icon).iconPMap.vRes = kDefaultRes; /* 72 DPI default res */
139 (**icon).iconPMap.pixelSize = depth; /* Set # bits/pixel */
140
141 /* Initialize fields specific to indexed and direct PixMaps */
142 if (depth <= 8)
143 {
144 /* PixMap is indexed */
145 (**icon).iconPMap.pixelType = 0; /* Indicates indexed */
146 (**icon).iconPMap.cmpCount = 1; /* Have 1 component */
147 (**icon).iconPMap.cmpSize = depth; /* Component size=depth */
148 (**icon).iconPMap.pmTable = newColors; /* Handle to CLUT */
149 }
150 else
151 {
152 /* PixMap is direct */
153 (**icon).iconPMap.pixelType = RGBDirect; /* Indicates direct */
154 (**icon).iconPMap.cmpCount = 3; /* Have 3 components */
155 if (depth == 16)
156 (**icon).iconPMap.cmpSize = 5; /* 5 bits/component */
157 else
158 (**icon).iconPMap.cmpSize = 8; /* 8 bits/component */
159 (**newColors).ctSeed = 3 * (**icon).iconPMap.cmpSize;
160 (**newColors).ctFlags = 0;
161 (**newColors).ctSize = 0;
162 (**icon).iconPMap.pmTable = newColors;
163 }
164 }
165 else
166 error = MemError();
167 }
168 else
169 newColors = nil;
170
171 /* If no errors occured, return a handle to the new off-screen PixMap */
172 if (error != noErr)
173 {
174 if (newColors != nil)
175 DisposeCTable(newColors);
176 }
177
178 /* Return the error code */
179 return error;
180 }
181
182 CIconHandle wxMacCreateCIcon(GWorldPtr image , GWorldPtr mask , short dstDepth , short iconSize )
183 {
184 GWorldPtr saveWorld;
185 GDHandle saveHandle;
186
187 GetGWorld(&saveWorld,&saveHandle); // save Graphics env state
188 SetGWorld(image,nil);
189
190 Rect frame = { 0 , 0 , iconSize , iconSize } ;
191 Rect imageBounds = frame ;
192 GetPortBounds( image , &imageBounds ) ;
193
194 int bwSize = iconSize / 8 * iconSize ;
195 CIconHandle icon = (CIconHandle) NewHandleClear( sizeof ( CIcon ) + 2 * bwSize) ;
196 HLock((Handle)icon) ;
197 SetupCIconHandlePixMap( icon , dstDepth , &frame,GetCTable(dstDepth)) ;
198 HLock( (**icon).iconData ) ;
199 (**icon).iconPMap.baseAddr = *(**icon).iconData ;
200
201 LockPixels(GetGWorldPixMap(image));
202
203 CopyBits(GetPortBitMapForCopyBits(image),
204 (BitMapPtr)&((**icon).iconPMap),
205 &imageBounds,
206 &imageBounds,
207 srcCopy | ditherCopy, nil);
208
209
210 UnlockPixels(GetGWorldPixMap(image));
211 HUnlock( (**icon).iconData ) ;
212
213 (**icon).iconMask.rowBytes = iconSize / 8 ;
214 (**icon).iconMask.bounds = frame ;
215
216 (**icon).iconBMap.rowBytes = iconSize / 8 ;
217 (**icon).iconBMap.bounds = frame ;
218 (**icon).iconMask.baseAddr = (char*) &(**icon).iconMaskData ;
219 (**icon).iconBMap.baseAddr = (char*) &(**icon).iconMaskData + bwSize ;
220
221 if ( mask )
222 {
223 Rect r ;
224 GetPortBounds( image , &r ) ;
225 LockPixels(GetGWorldPixMap(mask) ) ;
226 CopyBits(GetPortBitMapForCopyBits(mask) ,
227 &(**icon).iconBMap , &r , &r, srcCopy , nil ) ;
228 CopyBits(GetPortBitMapForCopyBits(mask) ,
229 &(**icon).iconMask , &r , &r, srcCopy , nil ) ;
230 UnlockPixels(GetGWorldPixMap( mask ) ) ;
231 }
232 else
233 {
234 Rect r ;
235 GetPortBounds( image , &r ) ;
236 LockPixels(GetGWorldPixMap(image));
237 CopyBits(GetPortBitMapForCopyBits(image) ,
238 &(**icon).iconBMap , &r , &r, srcCopy , nil ) ;
239 CopyBits(GetPortBitMapForCopyBits(image) ,
240 &(**icon).iconMask , &r , &r, srcCopy , nil ) ;
241 UnlockPixels(GetGWorldPixMap(image));
242 }
243
244 (**icon).iconMask.baseAddr = NULL ;
245 (**icon).iconBMap.baseAddr = NULL ;
246 (**icon).iconPMap.baseAddr = NULL ;
247 HUnlock((Handle)icon) ;
248 SetGWorld(saveWorld,saveHandle);
249
250 return icon;
251 }
252
253 PicHandle wxMacCreatePict(GWorldPtr wp, GWorldPtr mask)
254 {
255 CGrafPtr origPort ;
256 GDHandle origDev ;
257
258 PicHandle pict;
259
260 RGBColor white = { 0xffff ,0xffff , 0xffff } ;
261 RGBColor black = { 0x0000 ,0x0000 , 0x0000 } ;
262
263 GetGWorld( &origPort , &origDev ) ;
264
265 RgnHandle clipRgn = NULL ;
266
267 if ( mask )
268 {
269 clipRgn = NewRgn() ;
270 LockPixels( GetGWorldPixMap( mask ) ) ;
271 BitMapToRegion( clipRgn , (BitMap*) *GetGWorldPixMap( mask ) ) ;
272 UnlockPixels( GetGWorldPixMap( mask ) ) ;
273 }
274
275 SetGWorld( wp , NULL ) ;
276 Rect portRect ;
277 if ( clipRgn )
278 GetRegionBounds( clipRgn , &portRect ) ;
279 else
280 GetPortBounds( wp , &portRect ) ;
281 pict = OpenPicture(&portRect);
282 if(pict)
283 {
284 RGBForeColor( &black ) ;
285 RGBBackColor( &white ) ;
286
287 if ( clipRgn )
288 SetClip( clipRgn ) ;
289
290 LockPixels( GetGWorldPixMap( wp ) ) ;
291 CopyBits(GetPortBitMapForCopyBits(wp),
292 GetPortBitMapForCopyBits(wp),
293 &portRect,
294 &portRect,
295 srcCopy,clipRgn);
296 UnlockPixels( GetGWorldPixMap( wp ) ) ;
297 ClosePicture();
298 }
299 SetGWorld( origPort , origDev ) ;
300 if ( clipRgn )
301 DisposeRgn( clipRgn ) ;
302 return pict;
303 }
304
305 void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType )
306 {
307 memset( info , 0 , sizeof(ControlButtonContentInfo) ) ;
308 if ( bitmap.Ok() )
309 {
310 wxBitmapRefData * bmap = (wxBitmapRefData*) ( bitmap.GetRefData()) ;
311 if ( bmap == NULL )
312 return ;
313
314 if ( bmap->m_bitmapType == kMacBitmapTypePict )
315 {
316 info->contentType = kControlContentPictHandle ;
317 info->u.picture = MAC_WXHMETAFILE(bmap->m_hPict) ;
318 }
319 else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
320 {
321 if ( (forceType == kControlContentCIconHandle || ( bmap->m_width == bmap->m_height && forceType != kControlContentPictHandle ) ) && ((bmap->m_width & 0x3) == 0) )
322 {
323 info->contentType = kControlContentCIconHandle ;
324 if ( bitmap.GetMask() )
325 {
326 info->u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , MAC_WXHBITMAP(bitmap.GetMask()->GetMaskBitmap()) ,
327 8 , bmap->m_width ) ;
328 }
329 else
330 {
331 info->u.cIconHandle = wxMacCreateCIcon( MAC_WXHBITMAP(bmap->m_hBitmap) , NULL ,
332 8 , bmap->m_width ) ;
333 }
334 }
335 else
336 {
337 info->contentType = kControlContentPictHandle ;
338 if ( bitmap.GetMask() )
339 {
340 info->u.picture = wxMacCreatePict( MAC_WXHBITMAP(bmap->m_hBitmap) , MAC_WXHBITMAP(bitmap.GetMask()->GetMaskBitmap() ) ) ;
341 }
342 else
343 {
344 info->u.picture = wxMacCreatePict( MAC_WXHBITMAP(bmap->m_hBitmap) , NULL ) ;
345 }
346 }
347 }
348 else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
349 {
350 info->contentType = kControlContentCIconHandle ;
351 info->u.cIconHandle = MAC_WXHICON(bmap->m_hIcon) ;
352 }
353 }
354 }
355
356 wxBitmapRefData::wxBitmapRefData()
357 : m_width(0)
358 , m_height(0)
359 , m_depth(0)
360 , m_ok(FALSE)
361 , m_numColors(0)
362 , m_quality(0)
363 {
364 m_bitmapMask = NULL;
365 m_hBitmap = NULL ;
366 m_hPict = NULL ;
367 m_hIcon = NULL ;
368 m_bitmapType = kMacBitmapTypeUnknownType ;
369 }
370
371 // TODO move this to a public function of Bitmap Ref
372 static void DisposeBitmapRefData(wxBitmapRefData *data)
373 {
374 if ( !data )
375 return ;
376
377 switch (data->m_bitmapType)
378 {
379 case kMacBitmapTypePict :
380 {
381 if ( data->m_hPict )
382 {
383 KillPicture( MAC_WXHMETAFILE( data->m_hPict ) ) ;
384 data->m_hPict = NULL ;
385 }
386 }
387 break ;
388 case kMacBitmapTypeGrafWorld :
389 {
390 if ( data->m_hBitmap )
391 {
392 wxMacDestroyGWorld( MAC_WXHBITMAP(data->m_hBitmap) ) ;
393 data->m_hBitmap = NULL ;
394 }
395 }
396 break ;
397 case kMacBitmapTypeIcon :
398 if ( data->m_hIcon )
399 {
400 DisposeCIcon( MAC_WXHICON(data->m_hIcon) ) ;
401 data->m_hIcon = NULL ;
402 }
403
404 default :
405 // unkown type ?
406 break ;
407 }
408
409 if (data->m_bitmapMask)
410 {
411 delete data->m_bitmapMask;
412 data->m_bitmapMask = NULL;
413 }
414 }
415
416 wxBitmapRefData::~wxBitmapRefData()
417 {
418 DisposeBitmapRefData( this ) ;
419 }
420
421 bool wxBitmap::CopyFromIcon(const wxIcon& icon)
422 {
423 Ref(icon) ;
424 return true;
425 }
426
427 wxBitmap::wxBitmap()
428 {
429 m_refData = NULL;
430 }
431
432 wxBitmap::~wxBitmap()
433 {
434 }
435
436 wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits)
437 {
438 m_refData = new wxBitmapRefData;
439
440 M_BITMAPDATA->m_width = the_width ;
441 M_BITMAPDATA->m_height = the_height ;
442 M_BITMAPDATA->m_depth = no_bits ;
443 M_BITMAPDATA->m_numColors = 0;
444 if ( no_bits == 1 )
445 {
446 M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
447 MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) = wxMacCreateGWorld( the_width , the_height , no_bits ) ;
448 M_BITMAPDATA->m_ok = (MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) != NULL ) ;
449
450 CGrafPtr origPort ;
451 GDHandle origDevice ;
452
453 GetGWorld( &origPort , &origDevice ) ;
454 SetGWorld( MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) , NULL ) ;
455 LockPixels( GetGWorldPixMap( MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) ) ) ;
456
457 // bits is a char array
458
459 unsigned char* linestart = (unsigned char*) bits ;
460 int linesize = ( the_width / (sizeof(unsigned char) * 8)) ;
461 if ( the_width % (sizeof(unsigned char) * 8) ) {
462 linesize += sizeof(unsigned char);
463 }
464
465 RGBColor colors[2] = {
466 { 0xFFFF , 0xFFFF , 0xFFFF } ,
467 { 0, 0 , 0 }
468 } ;
469
470 for ( int y = 0 ; y < the_height ; ++y , linestart += linesize )
471 {
472 for ( int x = 0 ; x < the_width ; ++x )
473 {
474 int index = x / 8 ;
475 int bit = x % 8 ;
476 int mask = 1 << bit ;
477 if ( linestart[index] & mask )
478 {
479 SetCPixel( x , y , &colors[1] ) ;
480 }
481 else
482 {
483 SetCPixel( x , y , &colors[0] ) ;
484 }
485 }
486 }
487 UnlockPixels( GetGWorldPixMap( MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) ) ) ;
488
489 SetGWorld( origPort , origDevice ) ;
490 }
491 else
492 {
493 wxFAIL_MSG(wxT("multicolor BITMAPs not yet implemented"));
494 }
495 }
496
497 wxBitmap::wxBitmap(int w, int h, int d)
498 {
499 (void)Create(w, h, d);
500 }
501
502 wxBitmap::wxBitmap(void *data, wxBitmapType type, int width, int height, int depth)
503 {
504 (void) Create(data, type, width, height, depth);
505 }
506
507 wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type)
508 {
509 LoadFile(filename, type);
510 }
511
512 bool wxBitmap::CreateFromXpm(const char **bits)
513 {
514 wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") )
515 wxXPMDecoder decoder;
516 wxImage img = decoder.ReadData(bits);
517 wxCHECK_MSG( img.Ok(), FALSE, wxT("invalid bitmap data") )
518 *this = wxBitmap(img);
519 return TRUE;
520 }
521
522 wxBitmap::wxBitmap(const char **bits)
523 {
524 (void) CreateFromXpm(bits);
525 }
526
527 wxBitmap::wxBitmap(char **bits)
528 {
529 (void) CreateFromXpm((const char **)bits);
530 }
531
532 wxBitmap wxBitmap::GetSubBitmap(const wxRect &rect) const
533 {
534 wxCHECK_MSG( Ok() &&
535 (rect.x >= 0) && (rect.y >= 0) &&
536 (rect.x+rect.width <= GetWidth()) &&
537 (rect.y+rect.height <= GetHeight()),
538 wxNullBitmap, wxT("invalid bitmap or bitmap region") );
539
540
541 wxBitmap ret( rect.width, rect.height, GetDepth() );
542 wxASSERT_MSG( ret.Ok(), wxT("GetSubBitmap error") );
543
544 GWorldPtr origPort;
545 GDHandle origDevice;
546
547 GetGWorld( &origPort, &origDevice );
548
549 // Update the subbitmaps reference data
550 wxBitmapRefData *ref = (wxBitmapRefData *)ret.GetRefData();
551
552 ref->m_numColors = M_BITMAPDATA->m_numColors;
553 ref->m_bitmapPalette = M_BITMAPDATA->m_bitmapPalette;
554 ref->m_bitmapType = M_BITMAPDATA->m_bitmapType;
555
556 // Copy sub region of this bitmap
557 if(M_BITMAPDATA->m_bitmapType == kMacBitmapTypePict)
558 {
559 printf("GetSubBitmap: Copy a region of a Pict structure - TODO\n");
560 }
561 else if(M_BITMAPDATA->m_bitmapType == kMacBitmapTypeGrafWorld)
562 {
563 // Copy mask
564 if(GetMask())
565 {
566 GWorldPtr submask, mask;
567 RGBColor color;
568
569 mask = (GWorldPtr) GetMask()->GetMaskBitmap();
570 submask = wxMacCreateGWorld(rect.width, rect.height, GetMask()->GetDepth() );
571 LockPixels(GetGWorldPixMap(mask));
572 LockPixels(GetGWorldPixMap(submask));
573
574 for(int yy = 0; yy < rect.height; yy++)
575 {
576 for(int xx = 0; xx < rect.width; xx++)
577 {
578 SetGWorld(mask, NULL);
579 GetCPixel(rect.x + xx, rect.y + yy, &color);
580 SetGWorld(submask, NULL);
581 SetCPixel(xx,yy, &color);
582 }
583 }
584 UnlockPixels(GetGWorldPixMap(mask));
585 UnlockPixels(GetGWorldPixMap(submask));
586 ref->m_bitmapMask = new wxMask;
587 ref->m_bitmapMask->SetMaskBitmap(submask);
588 }
589
590 // Copy bitmap
591 if(GetHBITMAP())
592 {
593 GWorldPtr subbitmap, bitmap;
594 RGBColor color;
595
596 bitmap = (GWorldPtr) GetHBITMAP();
597 subbitmap = (GWorldPtr) ref->m_hBitmap ;
598 LockPixels(GetGWorldPixMap(bitmap));
599 LockPixels(GetGWorldPixMap(subbitmap));
600
601 for(int yy = 0; yy < rect.height; yy++)
602 {
603 for(int xx = 0; xx < rect.width; xx++)
604 {
605 SetGWorld(bitmap, NULL);
606 GetCPixel(rect.x + xx, rect.y + yy, &color);
607 SetGWorld(subbitmap, NULL);
608 SetCPixel(xx, yy, &color);
609 }
610 }
611 UnlockPixels(GetGWorldPixMap(bitmap));
612 UnlockPixels(GetGWorldPixMap(subbitmap));
613 }
614 }
615 SetGWorld( origPort, origDevice );
616
617 return ret;
618 }
619
620 bool wxBitmap::Create(int w, int h, int d)
621 {
622 UnRef();
623
624 m_refData = new wxBitmapRefData;
625
626 M_BITMAPDATA->m_width = w;
627 M_BITMAPDATA->m_height = h;
628 M_BITMAPDATA->m_depth = d;
629
630 M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
631 M_BITMAPDATA->m_hBitmap = wxMacCreateGWorld( w , h , d ) ;
632 M_BITMAPDATA->m_ok = ( M_BITMAPDATA->m_hBitmap != NULL ) ;
633 return M_BITMAPDATA->m_ok;
634 }
635
636 int wxBitmap::GetBitmapType() const
637 {
638 wxCHECK_MSG( Ok(), kMacBitmapTypeUnknownType, wxT("invalid bitmap") );
639
640 return M_BITMAPDATA->m_bitmapType;
641 }
642
643 void wxBitmap::SetHBITMAP(WXHBITMAP bmp)
644 {
645 if (!M_BITMAPDATA)
646 m_refData = new wxBitmapRefData;
647 else
648 DisposeBitmapRefData( M_BITMAPDATA ) ;
649
650 M_BITMAPDATA->m_bitmapType = kMacBitmapTypeGrafWorld ;
651 M_BITMAPDATA->m_hBitmap = bmp ;
652 M_BITMAPDATA->m_ok = ( M_BITMAPDATA->m_hBitmap != NULL ) ;
653 }
654
655 void wxBitmap::SetHICON(WXHICON ico)
656 {
657 if (!M_BITMAPDATA)
658 m_refData = new wxBitmapRefData;
659 else
660 DisposeBitmapRefData( M_BITMAPDATA ) ;
661
662 M_BITMAPDATA->m_bitmapType = kMacBitmapTypeIcon ;
663 M_BITMAPDATA->m_hIcon = ico ;
664 M_BITMAPDATA->m_ok = ( M_BITMAPDATA->m_hIcon != NULL ) ;
665 }
666
667 void wxBitmap::SetPict(WXHMETAFILE pict)
668 {
669 if (!M_BITMAPDATA)
670 m_refData = new wxBitmapRefData;
671 else
672 DisposeBitmapRefData( M_BITMAPDATA ) ;
673
674 M_BITMAPDATA->m_bitmapType = kMacBitmapTypePict ;
675 M_BITMAPDATA->m_hPict = pict ;
676 M_BITMAPDATA->m_ok = ( M_BITMAPDATA->m_hPict != NULL ) ;
677 }
678
679 bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type)
680 {
681 UnRef();
682
683 wxBitmapHandler *handler = FindHandler(type);
684
685 if ( handler )
686 {
687 m_refData = new wxBitmapRefData;
688
689 return handler->LoadFile(this, filename, type, -1, -1);
690 }
691 else
692 {
693 wxImage loadimage(filename, type);
694 if (loadimage.Ok()) {
695 *this = loadimage;
696 return true;
697 }
698 }
699 wxLogWarning(wxT("no bitmap handler for type %d defined."), type);
700 return false;
701 }
702
703 bool wxBitmap::Create(void *data, wxBitmapType type, int width, int height, int depth)
704 {
705 UnRef();
706
707 m_refData = new wxBitmapRefData;
708
709 wxBitmapHandler *handler = FindHandler(type);
710
711 if ( handler == NULL ) {
712 wxLogWarning(wxT("no bitmap handler for type %d defined."), type);
713
714 return FALSE;
715 }
716
717 return handler->Create(this, data, type, width, height, depth);
718 }
719
720 wxBitmap::wxBitmap(const wxImage& image, int depth)
721 {
722 wxCHECK_RET( image.Ok(), wxT("invalid image") )
723 wxCHECK_RET( depth == -1, wxT("invalid bitmap depth") )
724
725 m_refData = new wxBitmapRefData();
726
727 // width and height of the device-dependent bitmap
728 int width = image.GetWidth();
729 int height = image.GetHeight();
730
731 // Create picture
732
733 Create( width , height , 32 ) ;
734
735 CGrafPtr origPort ;
736 GDHandle origDevice ;
737
738 PixMapHandle pixMap = GetGWorldPixMap((GWorldPtr)GetHBITMAP()) ;
739 LockPixels( pixMap );
740
741 GetGWorld( &origPort , &origDevice ) ;
742 SetGWorld( (GWorldPtr) GetHBITMAP() , NULL ) ;
743
744 // Render image
745 register unsigned char* data = image.GetData();
746 char* destinationBase = GetPixBaseAddr( pixMap );
747 register unsigned char* destination = (unsigned char*) destinationBase ;
748 for (int y = 0; y < height; y++)
749 {
750 for (int x = 0; x < width; x++)
751 {
752 *destination++ = 0 ;
753 *destination++ = *data++ ;
754 *destination++ = *data++ ;
755 *destination++ = *data++ ;
756 }
757 destinationBase += ((**pixMap).rowBytes & 0x7fff);
758 destination = (unsigned char*) destinationBase ;
759 }
760 if ( image.HasAlpha() )
761 {
762 unsigned char *alpha = image.GetAlpha();
763
764 wxColour maskcolor(image.GetMaskRed(), image.GetMaskGreen(), image.GetMaskBlue());
765 RGBColor color ;
766 wxBitmap maskBitmap ;
767
768 maskBitmap.Create( width, height, 24);
769 LockPixels( GetGWorldPixMap( (GWorldPtr) maskBitmap.GetHBITMAP()) );
770 SetGWorld( (GWorldPtr) maskBitmap.GetHBITMAP(), NULL);
771
772 for (int y = 0; y < height; y++)
773 {
774 for (int x = 0; x < width; x++)
775 {
776 memset( &color , 255 - *alpha , sizeof( color ) );
777 SetCPixel(x,y, &color);
778
779 alpha += 1 ;
780 }
781 } // for height
782 SetGWorld( (GWorldPtr) GetHBITMAP(), NULL);
783 SetMask(new wxMask( maskBitmap ));
784 UnlockPixels( GetGWorldPixMap( (GWorldPtr) maskBitmap.GetHBITMAP()) );
785 }
786 else if ( image.HasMask() )
787 {
788 data = image.GetData();
789
790 wxColour maskcolor(image.GetMaskRed(), image.GetMaskGreen(), image.GetMaskBlue());
791 RGBColor white = { 0xffff, 0xffff, 0xffff };
792 RGBColor black = { 0 , 0 , 0 };
793 wxBitmap maskBitmap ;
794
795 maskBitmap.Create( width, height, 1);
796 LockPixels( GetGWorldPixMap( (GWorldPtr) maskBitmap.GetHBITMAP()) );
797 SetGWorld( (GWorldPtr) maskBitmap.GetHBITMAP(), NULL);
798
799 for (int y = 0; y < height; y++)
800 {
801 for (int x = 0; x < width; x++)
802 {
803 if ( data[0] == image.GetMaskRed() && data[1] == image.GetMaskGreen() && data[2] == image.GetMaskBlue() )
804 {
805 SetCPixel(x,y, &white);
806 }
807 else {
808 SetCPixel(x,y, &black);
809 }
810 data += 3 ;
811 }
812 } // for height
813 SetGWorld( (GWorldPtr) GetHBITMAP(), NULL);
814 SetMask(new wxMask( maskBitmap ));
815 UnlockPixels( GetGWorldPixMap( (GWorldPtr) maskBitmap.GetHBITMAP()) );
816 }
817
818 UnlockPixels( GetGWorldPixMap( (GWorldPtr) GetHBITMAP()) );
819 SetGWorld( origPort, origDevice );
820 }
821
822 wxImage wxBitmap::ConvertToImage() const
823 {
824 wxImage image;
825
826 wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") );
827
828 // create an wxImage object
829 int width = GetWidth();
830 int height = GetHeight();
831 image.Create( width, height );
832
833 unsigned char *data = image.GetData();
834
835 wxCHECK_MSG( data, wxNullImage, wxT("Could not allocate data for image") );
836
837 GWorldPtr origPort;
838 GDHandle origDevice;
839 RgnHandle maskRgn = NULL ;
840 GWorldPtr tempPort = NULL ;
841 int index;
842 RGBColor color;
843 // background color set to RGB(16,16,16) in consistent with wxGTK
844 unsigned char mask_r=16, mask_g=16, mask_b=16;
845 SInt16 r,g,b;
846 wxMask *mask = GetMask();
847
848 GetGWorld( &origPort, &origDevice );
849 if ( GetBitmapType() != kMacBitmapTypeGrafWorld )
850 {
851 tempPort = wxMacCreateGWorld( width , height , -1) ;
852 }
853 else
854 {
855 tempPort = (GWorldPtr) GetHBITMAP() ;
856 }
857 LockPixels(GetGWorldPixMap(tempPort));
858 SetGWorld( tempPort, NULL);
859 if ( GetBitmapType() == kMacBitmapTypePict || GetBitmapType() == kMacBitmapTypeIcon )
860 {
861 Rect bitmaprect = { 0 , 0 , height, width };
862 if ( GetBitmapType() == kMacBitmapTypeIcon )
863 {
864 ::PlotCIconHandle( &bitmaprect , atNone , ttNone , MAC_WXHICON(GetHICON()) ) ;
865 maskRgn = NewRgn() ;
866 BitMapToRegion( maskRgn , &(**(MAC_WXHICON(GetHICON()))).iconMask ) ;
867 }
868 else
869 ::DrawPicture( (PicHandle) GetPict(), &bitmaprect ) ;
870 }
871 // Copy data into image
872 index = 0;
873 for (int yy = 0; yy < height; yy++)
874 {
875 for (int xx = 0; xx < width; xx++)
876 {
877 GetCPixel(xx,yy, &color);
878 r = ((color.red ) >> 8);
879 g = ((color.green ) >> 8);
880 b = ((color.blue ) >> 8);
881 data[index ] = r;
882 data[index + 1] = g;
883 data[index + 2] = b;
884 if ( maskRgn )
885 {
886 Point pt ;
887 pt.h = xx ;
888 pt.v = yy ;
889 if ( !PtInRgn( pt , maskRgn ) )
890 {
891 data[index ] = mask_r;
892 data[index + 1] = mask_g;
893 data[index + 2] = mask_b;
894 }
895 }
896 else
897 {
898 if (mask)
899 {
900 if (mask->PointMasked(xx,yy))
901 {
902 data[index ] = mask_r;
903 data[index + 1] = mask_g;
904 data[index + 2] = mask_b;
905 }
906 }
907 }
908 index += 3;
909 }
910 }
911 if (mask || maskRgn )
912 {
913 image.SetMaskColour( mask_r, mask_g, mask_b );
914 image.SetMask( true );
915 }
916
917 // Free resources
918 UnlockPixels(GetGWorldPixMap( tempPort ));
919 SetGWorld(origPort, origDevice);
920 if ( GetBitmapType() != kMacBitmapTypeGrafWorld )
921 {
922 wxMacDestroyGWorld( tempPort ) ;
923 }
924 if ( maskRgn )
925 {
926 DisposeRgn( maskRgn ) ;
927 }
928
929 return image;
930 }
931
932
933 bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type,
934 const wxPalette *palette) const
935 {
936 wxBitmapHandler *handler = FindHandler(type);
937
938 if ( handler )
939 {
940 return handler->SaveFile(this, filename, type, palette);
941 }
942 else
943 {
944 wxImage image = ConvertToImage();
945
946 return image.SaveFile(filename, type);
947 }
948
949 wxLogWarning(wxT("no bitmap handler for type %d defined."), type);
950 return false;
951 }
952
953 bool wxBitmap::Ok() const
954 {
955 return (M_BITMAPDATA && M_BITMAPDATA->m_ok);
956 }
957
958 int wxBitmap::GetHeight() const
959 {
960 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
961
962 return M_BITMAPDATA->m_height;
963 }
964
965 int wxBitmap::GetWidth() const
966 {
967 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
968
969 return M_BITMAPDATA->m_width;
970 }
971
972 int wxBitmap::GetDepth() const
973 {
974 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
975
976 return M_BITMAPDATA->m_depth;
977 }
978
979 int wxBitmap::GetQuality() const
980 {
981 wxCHECK_MSG( Ok(), -1, wxT("invalid bitmap") );
982
983 return M_BITMAPDATA->m_quality;
984 }
985
986 wxMask *wxBitmap::GetMask() const
987 {
988 wxCHECK_MSG( Ok(), (wxMask *) NULL, wxT("invalid bitmap") );
989
990 return M_BITMAPDATA->m_bitmapMask;
991 }
992
993 void wxBitmap::SetWidth(int w)
994 {
995 if (!M_BITMAPDATA)
996 m_refData = new wxBitmapRefData;
997
998 M_BITMAPDATA->m_width = w;
999 }
1000
1001 void wxBitmap::SetHeight(int h)
1002 {
1003 if (!M_BITMAPDATA)
1004 m_refData = new wxBitmapRefData;
1005
1006 M_BITMAPDATA->m_height = h;
1007 }
1008
1009 void wxBitmap::SetDepth(int d)
1010 {
1011 if (!M_BITMAPDATA)
1012 m_refData = new wxBitmapRefData;
1013
1014 M_BITMAPDATA->m_depth = d;
1015 }
1016
1017 void wxBitmap::SetQuality(int q)
1018 {
1019 if (!M_BITMAPDATA)
1020 m_refData = new wxBitmapRefData;
1021
1022 M_BITMAPDATA->m_quality = q;
1023 }
1024
1025 void wxBitmap::SetOk(bool isOk)
1026 {
1027 if (!M_BITMAPDATA)
1028 m_refData = new wxBitmapRefData;
1029
1030 M_BITMAPDATA->m_ok = isOk;
1031 }
1032
1033 wxPalette *wxBitmap::GetPalette() const
1034 {
1035 wxCHECK_MSG( Ok(), NULL, wxT("Invalid bitmap GetPalette()") );
1036
1037 return &M_BITMAPDATA->m_bitmapPalette;
1038 }
1039
1040 void wxBitmap::SetPalette(const wxPalette& palette)
1041 {
1042 if (!M_BITMAPDATA)
1043 m_refData = new wxBitmapRefData;
1044
1045 M_BITMAPDATA->m_bitmapPalette = palette ;
1046 }
1047
1048 void wxBitmap::SetMask(wxMask *mask)
1049 {
1050 if (!M_BITMAPDATA)
1051 m_refData = new wxBitmapRefData;
1052
1053 // Remove existing mask if there is one.
1054 if (M_BITMAPDATA->m_bitmapMask)
1055 delete M_BITMAPDATA->m_bitmapMask;
1056
1057 M_BITMAPDATA->m_bitmapMask = mask ;
1058 }
1059
1060 WXHBITMAP wxBitmap::GetHBITMAP() const
1061 {
1062 wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );
1063
1064 return MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap);
1065 }
1066
1067 WXHMETAFILE wxBitmap::GetPict( bool *created ) const
1068 {
1069 wxCHECK_MSG( Ok(), NULL, wxT("invalid bitmap") );
1070
1071 PicHandle picture = NULL ; // This is the returned picture
1072 if ( created )
1073 (*created) = false ;
1074 // If bitmap already in Pict format return pointer
1075 if(M_BITMAPDATA->m_bitmapType == kMacBitmapTypePict) {
1076 return M_BITMAPDATA->m_hPict;
1077 }
1078 else if(M_BITMAPDATA->m_bitmapType != kMacBitmapTypeGrafWorld) {
1079 // Invalid bitmap
1080 return NULL;
1081 }
1082 else
1083 {
1084 if ( GetMask() )
1085 {
1086 picture = wxMacCreatePict( MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) , MAC_WXHBITMAP(GetMask()->GetMaskBitmap() ) ) ;
1087 }
1088 else
1089 {
1090 picture = wxMacCreatePict( MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap) , NULL ) ;
1091 }
1092 if ( created && picture )
1093 (*created) = true ;
1094 }
1095 return picture ;
1096 }
1097
1098 /*
1099 * wxMask
1100 */
1101
1102 wxMask::wxMask()
1103 : m_maskBitmap(NULL)
1104 {
1105 }
1106
1107 // Construct a mask from a bitmap and a colour indicating
1108 // the transparent area
1109 wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour)
1110 : m_maskBitmap(NULL)
1111 {
1112 Create(bitmap, colour);
1113 }
1114
1115 // Construct a mask from a bitmap and a palette index indicating
1116 // the transparent area
1117 wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex)
1118 : m_maskBitmap(NULL)
1119 {
1120 Create(bitmap, paletteIndex);
1121 }
1122
1123 // Construct a mask from a mono bitmap (copies the bitmap).
1124 wxMask::wxMask(const wxBitmap& bitmap)
1125 : m_maskBitmap(NULL)
1126 {
1127 Create(bitmap);
1128 }
1129
1130 wxMask::~wxMask()
1131 {
1132 if ( m_maskBitmap )
1133 {
1134 wxMacDestroyGWorld( (GWorldPtr) m_maskBitmap ) ;
1135 m_maskBitmap = NULL ;
1136 }
1137 }
1138
1139 // Create a mask from a mono bitmap (copies the bitmap).
1140 bool wxMask::Create(const wxBitmap& bitmap)
1141 {
1142 if ( m_maskBitmap )
1143 {
1144 wxMacDestroyGWorld( (GWorldPtr) m_maskBitmap ) ;
1145 m_maskBitmap = NULL ;
1146 }
1147 wxCHECK_MSG( bitmap.GetBitmapType() == kMacBitmapTypeGrafWorld, false,
1148 wxT("Cannot create mask from this bitmap type (TODO)"));
1149 // other types would require a temporary bitmap. not yet implemented
1150
1151 wxCHECK_MSG( bitmap.Ok(), false, wxT("Invalid bitmap"));
1152
1153 m_depth = bitmap.GetDepth() ;
1154 m_maskBitmap = wxMacCreateGWorld(bitmap.GetWidth(), bitmap.GetHeight(), bitmap.GetDepth() );
1155 Rect rect = { 0,0, bitmap.GetHeight(), bitmap.GetWidth() };
1156
1157 LockPixels( GetGWorldPixMap( (GWorldPtr) m_maskBitmap) );
1158 LockPixels( GetGWorldPixMap( (GWorldPtr) bitmap.GetHBITMAP()) );
1159 CopyBits(GetPortBitMapForCopyBits( (GWorldPtr) bitmap.GetHBITMAP()),
1160 GetPortBitMapForCopyBits( (GWorldPtr) m_maskBitmap),
1161 &rect, &rect, srcCopy, 0);
1162 UnlockPixels( GetGWorldPixMap( (GWorldPtr) m_maskBitmap) );
1163 UnlockPixels( GetGWorldPixMap( (GWorldPtr) bitmap.GetHBITMAP()) );
1164
1165 return FALSE;
1166 }
1167
1168 // Create a mask from a bitmap and a palette index indicating
1169 // the transparent area
1170 bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex)
1171 {
1172 // TODO
1173 wxCHECK_MSG( 0, false, wxT("wxMask::Create not yet implemented"));
1174 return FALSE;
1175 }
1176
1177 // Create a mask from a bitmap and a colour indicating
1178 // the transparent area
1179 bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
1180 {
1181 if ( m_maskBitmap )
1182 {
1183 wxMacDestroyGWorld( (GWorldPtr) m_maskBitmap ) ;
1184 m_maskBitmap = NULL ;
1185 }
1186 wxCHECK_MSG( bitmap.GetBitmapType() == kMacBitmapTypeGrafWorld, false,
1187 wxT("Cannot create mask from this bitmap type (TODO)"));
1188 // other types would require a temporary bitmap. not yet implemented
1189
1190 wxCHECK_MSG( bitmap.Ok(), false, wxT("Illigal bitmap"));
1191
1192 m_maskBitmap = wxMacCreateGWorld( bitmap.GetWidth() , bitmap.GetHeight() , 1 );
1193 m_depth = 1 ;
1194 LockPixels( GetGWorldPixMap( (GWorldPtr) m_maskBitmap ) );
1195 LockPixels( GetGWorldPixMap( (GWorldPtr) bitmap.GetHBITMAP() ) );
1196 RGBColor maskColor = MAC_WXCOLORREF(colour.GetPixel());
1197
1198 // this is not very efficient, but I can't think
1199 // of a better way of doing it
1200 CGrafPtr origPort ;
1201 GDHandle origDevice ;
1202 RGBColor col;
1203 RGBColor colors[2] = {
1204 { 0xFFFF, 0xFFFF, 0xFFFF },
1205 { 0, 0, 0 }};
1206
1207 GetGWorld( &origPort , &origDevice ) ;
1208 for (int w = 0; w < bitmap.GetWidth(); w++)
1209 {
1210 for (int h = 0; h < bitmap.GetHeight(); h++)
1211 {
1212 SetGWorld( (GWorldPtr) bitmap.GetHBITMAP(), NULL ) ;
1213 GetCPixel( w , h , &col ) ;
1214 SetGWorld( (GWorldPtr) m_maskBitmap , NULL ) ;
1215 if (col.red == maskColor.red && col.green == maskColor.green && col.blue == maskColor.blue)
1216 {
1217 SetCPixel( w , h , &colors[0] ) ;
1218 }
1219 else
1220 {
1221 SetCPixel( w , h , &colors[1] ) ;
1222 }
1223 }
1224 }
1225 UnlockPixels( GetGWorldPixMap( (CGrafPtr) m_maskBitmap ) ) ;
1226 UnlockPixels( GetGWorldPixMap( (GWorldPtr) bitmap.GetHBITMAP() ) ) ;
1227 SetGWorld( origPort , origDevice ) ;
1228
1229 return TRUE;
1230 }
1231
1232 bool wxMask::PointMasked(int x, int y)
1233 {
1234 GWorldPtr origPort;
1235 GDHandle origDevice;
1236 RGBColor color;
1237 bool masked = true;
1238
1239 GetGWorld( &origPort, &origDevice);
1240
1241 //Set port to mask and see if it masked (1) or not ( 0 )
1242 SetGWorld( (GWorldPtr) m_maskBitmap, NULL);
1243 LockPixels(GetGWorldPixMap( (GWorldPtr) m_maskBitmap));
1244 GetCPixel(x,y, &color);
1245 masked = !(color.red == 0 && color.green == 0 && color.blue == 0);
1246 UnlockPixels(GetGWorldPixMap( (GWorldPtr) m_maskBitmap));
1247
1248 SetGWorld( origPort, origDevice);
1249
1250 return masked;
1251 }
1252
1253 /*
1254 * wxBitmapHandler
1255 */
1256
1257 wxBitmapHandler::~wxBitmapHandler()
1258 {
1259 }
1260
1261 bool wxBitmapHandler::Create(wxBitmap *bitmap, void *data, long type, int width, int height, int depth)
1262 {
1263 return FALSE;
1264 }
1265
1266 bool wxBitmapHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
1267 int desiredWidth, int desiredHeight)
1268 {
1269 return FALSE;
1270 }
1271
1272 bool wxBitmapHandler::SaveFile(const wxBitmap *bitmap, const wxString& name, int type, const wxPalette *palette)
1273 {
1274 return FALSE;
1275 }
1276
1277 /*
1278 * Standard handlers
1279 */
1280
1281 class WXDLLEXPORT wxPICTResourceHandler: public wxBitmapHandler
1282 {
1283 DECLARE_DYNAMIC_CLASS(wxPICTResourceHandler)
1284 public:
1285 inline wxPICTResourceHandler()
1286 {
1287 m_name = wxT("Macintosh Pict resource");
1288 m_extension = wxEmptyString;
1289 m_type = wxBITMAP_TYPE_PICT_RESOURCE;
1290 };
1291
1292 virtual bool LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
1293 int desiredWidth, int desiredHeight);
1294 };
1295 IMPLEMENT_DYNAMIC_CLASS(wxPICTResourceHandler, wxBitmapHandler)
1296
1297 bool wxPICTResourceHandler::LoadFile(wxBitmap *bitmap, const wxString& name, long flags,
1298 int desiredWidth, int desiredHeight)
1299 {
1300 Str255 theName ;
1301 wxMacStringToPascal( name , theName ) ;
1302
1303 PicHandle thePict = (PicHandle ) GetNamedResource( 'PICT' , theName ) ;
1304 if ( thePict )
1305 {
1306 PictInfo theInfo ;
1307
1308 GetPictInfo( thePict , &theInfo , 0 , 0 , systemMethod , 0 ) ;
1309 DetachResource( (Handle) thePict ) ;
1310 M_BITMAPHANDLERDATA->m_bitmapType = kMacBitmapTypePict ;
1311 M_BITMAPHANDLERDATA->m_hPict = thePict ;
1312 M_BITMAPHANDLERDATA->m_width = theInfo.sourceRect.right - theInfo.sourceRect.left ;
1313 M_BITMAPHANDLERDATA->m_height = theInfo.sourceRect.bottom - theInfo.sourceRect.top ;
1314
1315 M_BITMAPHANDLERDATA->m_depth = theInfo.depth ;
1316 M_BITMAPHANDLERDATA->m_ok = true ;
1317 M_BITMAPHANDLERDATA->m_numColors = theInfo.uniqueColors ;
1318 // M_BITMAPHANDLERDATA->m_bitmapPalette;
1319 // M_BITMAPHANDLERDATA->m_quality;
1320 return TRUE ;
1321 }
1322 return FALSE ;
1323 }
1324
1325 void wxBitmap::InitStandardHandlers()
1326 {
1327 AddHandler(new wxPICTResourceHandler) ;
1328 AddHandler(new wxICONResourceHandler) ;
1329 }
1330
1331 // ----------------------------------------------------------------------------
1332 // raw bitmap access support
1333 // ----------------------------------------------------------------------------
1334
1335 void *wxBitmap::GetRawData(wxPixelDataBase& data, int bpp)
1336 {
1337 if ( !Ok() )
1338 {
1339 // no bitmap, no data (raw or otherwise)
1340 return NULL;
1341 }
1342
1343 if ( M_BITMAPDATA->m_bitmapType != kMacBitmapTypeGrafWorld )
1344 {
1345 wxFAIL_MSG( _T("GetRawData() only supported for GWorlds") );
1346
1347 return NULL;
1348 }
1349
1350 GWorldPtr gworld = MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap);
1351 PixMapHandle hPixMap = GetGWorldPixMap(gworld);
1352 wxCHECK_MSG( hPixMap && *hPixMap, NULL,
1353 _T("GetRawData(): failed to get PixMap from GWorld?") );
1354
1355 wxCHECK_MSG( (*hPixMap)->pixelSize == bpp, NULL,
1356 _T("GetRawData(): pixel format mismatch") );
1357
1358 if ( !LockPixels(hPixMap) )
1359 {
1360 wxFAIL_MSG( _T("failed to lock PixMap in GetRawData()") );
1361
1362 return NULL;
1363 }
1364
1365 data.m_width = GetWidth();
1366 data.m_height = GetHeight();
1367 data.m_stride = (*hPixMap)->rowBytes & 0x7fff;
1368
1369 return GetPixBaseAddr(hPixMap);
1370 }
1371
1372 void wxBitmap::UngetRawData(wxPixelDataBase& data)
1373 {
1374 if ( !Ok() )
1375 return;
1376
1377 GWorldPtr gworld = MAC_WXHBITMAP(M_BITMAPDATA->m_hBitmap);
1378 PixMapHandle hPixMap = GetGWorldPixMap(gworld);
1379 if ( hPixMap )
1380 {
1381 UnlockPixels(hPixMap);
1382 }
1383 }
1384
1385 void wxBitmap::UseAlpha()
1386 {
1387 // nothing to do here so far
1388 }
1389