]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/bitmap.mm
don't add 7 and 14 pixel horz/vertical padding in DoGetBestSize() when the best size...
[wxWidgets.git] / src / cocoa / bitmap.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/bitmap.mm
3 // Purpose: wxBitmap
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2003/07/19
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWidgets licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/bitmap.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/log.h"
18 #include "wx/utils.h"
19 #include "wx/palette.h"
20 #include "wx/icon.h"
21 #include "wx/colour.h"
22 #include "wx/image.h"
23 #endif //WX_PRECOMP
24
25 #include "wx/xpmdecod.h"
26 #include "wx/rawbmp.h"
27
28 #include "wx/cocoa/autorelease.h"
29 #include "wx/cocoa/string.h"
30
31 #import <AppKit/NSBitmapImageRep.h>
32 #import <AppKit/NSGraphics.h>
33 #import <AppKit/NSImage.h>
34 #import <AppKit/NSColor.h>
35
36 // ========================================================================
37 // wxBitmapRefData
38 // ========================================================================
39 class wxBitmapRefData: public wxGDIRefData
40 {
41 friend class wxBitmap;
42 public:
43 wxBitmapRefData();
44 wxBitmapRefData( const wxBitmapRefData& data );
45 virtual ~wxBitmapRefData();
46
47 protected:
48 int m_width;
49 int m_height;
50 int m_depth;
51 bool m_ok;
52 int m_numColors;
53 wxPalette m_bitmapPalette;
54 int m_quality;
55 WX_NSBitmapImageRep m_cocoaNSBitmapImageRep;
56 wxMask *m_bitmapMask; // Optional mask
57 };
58
59 #define M_BITMAPDATA ((wxBitmapRefData *)m_refData)
60
61 wxBitmapRefData::wxBitmapRefData()
62 {
63 m_ok = FALSE;
64 m_width = 0;
65 m_height = 0;
66 m_depth = 0;
67 m_quality = 0;
68 m_numColors = 0;
69 m_cocoaNSBitmapImageRep = nil;
70 m_bitmapMask = NULL;
71 }
72
73 wxBitmapRefData::wxBitmapRefData( const wxBitmapRefData& data)
74 {
75 m_width = data.m_width;
76 m_height = data.m_height;
77 m_depth = data.m_depth;
78 m_ok = data.m_ok;
79 m_numColors = data.m_numColors;
80 m_bitmapPalette = data.m_bitmapPalette;
81 m_quality = data.m_quality;
82 m_cocoaNSBitmapImageRep = [data.m_cocoaNSBitmapImageRep copyWithZone:nil];
83 m_bitmapMask = data.m_bitmapMask?new wxMask(*data.m_bitmapMask):NULL;
84 }
85
86 wxBitmapRefData::~wxBitmapRefData()
87 {
88 [m_cocoaNSBitmapImageRep release];
89 m_cocoaNSBitmapImageRep = NULL;
90
91 delete m_bitmapMask;
92 m_bitmapMask = NULL;
93 }
94
95 // ========================================================================
96 // wxBitmap
97 // ========================================================================
98 IMPLEMENT_DYNAMIC_CLASS(wxBitmap, wxGDIObject)
99
100 wxBitmap::wxBitmap()
101 {
102 m_refData = NULL;
103 }
104
105 wxBitmap::~wxBitmap()
106 {
107 }
108
109 wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits)
110 {
111 m_refData = new wxBitmapRefData;
112
113 M_BITMAPDATA->m_width = the_width ;
114 M_BITMAPDATA->m_height = the_height ;
115 M_BITMAPDATA->m_depth = no_bits ;
116 M_BITMAPDATA->m_numColors = 0;
117
118 /* TODO: create the bitmap from data */
119 }
120
121 wxBitmap::wxBitmap(int w, int h, int d)
122 {
123 (void)Create(w, h, d);
124 }
125
126 wxBitmap::wxBitmap(void *data, wxBitmapType type, int width, int height, int depth)
127 {
128 (void) Create(data, type, width, height, depth);
129 }
130
131 wxBitmap::wxBitmap(const wxString& filename, wxBitmapType type)
132 {
133 LoadFile(filename, type);
134 }
135
136 wxObjectRefData *wxBitmap::CreateRefData() const
137 {
138 return new wxBitmapRefData;
139 }
140
141 wxObjectRefData *wxBitmap::CloneRefData(const wxObjectRefData *data) const
142 {
143 return new wxBitmapRefData(*(wxBitmapRefData*)data);
144 }
145
146 WX_NSBitmapImageRep wxBitmap::GetNSBitmapImageRep()
147 {
148 if(!M_BITMAPDATA)
149 return NULL;
150 return M_BITMAPDATA->m_cocoaNSBitmapImageRep;
151 }
152
153 WX_NSImage wxBitmap::GetNSImage(bool useMask) const
154 {
155 if(!Ok())
156 return nil;
157 NSImage *nsimage = [[[NSImage alloc]
158 initWithSize:NSMakeSize(GetWidth(), GetHeight())] autorelease];
159 if(!nsimage)
160 return nil;
161 [nsimage addRepresentation: M_BITMAPDATA->m_cocoaNSBitmapImageRep];
162 if(useMask && GetMask())
163 {
164 // Show before/after to prove that the bitmap itself is not changed
165 // even though we just composited onto the NSImage
166 wxLogTrace(wxTRACE_COCOA,wxT("Before: bpp=%d"),[M_BITMAPDATA->m_cocoaNSBitmapImageRep bitsPerPixel]);
167 NSImage *maskImage = [[NSImage alloc]
168 initWithSize:NSMakeSize(GetWidth(), GetHeight())];
169 [maskImage addRepresentation: GetMask()->GetNSBitmapImageRep()];
170 [nsimage lockFocus];
171 [maskImage compositeToPoint:NSZeroPoint operation:NSCompositeDestinationIn];
172 [nsimage unlockFocus];
173 [maskImage release];
174 wxLogTrace(wxTRACE_COCOA,wxT("After: bpp=%d"),[M_BITMAPDATA->m_cocoaNSBitmapImageRep bitsPerPixel]);
175 }
176 return nsimage;
177 }
178
179 void wxBitmap::SetNSBitmapImageRep(WX_NSBitmapImageRep bitmapImageRep)
180 {
181 if(!M_BITMAPDATA)
182 return;
183 // NOTE: No checking is done to make sure width/height agree
184 [bitmapImageRep retain];
185 [M_BITMAPDATA->m_cocoaNSBitmapImageRep release];
186 M_BITMAPDATA->m_cocoaNSBitmapImageRep = bitmapImageRep;
187 }
188
189 void wxBitmap::SetWidth(int w)
190 {
191 if (!M_BITMAPDATA)
192 m_refData = new wxBitmapRefData;
193
194 M_BITMAPDATA->m_width = w;
195 }
196
197 void wxBitmap::SetHeight(int h)
198 {
199 if (!M_BITMAPDATA)
200 m_refData = new wxBitmapRefData;
201
202 M_BITMAPDATA->m_height = h;
203 }
204
205 void wxBitmap::SetDepth(int d)
206 {
207 if (!M_BITMAPDATA)
208 m_refData = new wxBitmapRefData;
209
210 M_BITMAPDATA->m_depth = d;
211 }
212
213 void wxBitmap::SetQuality(int q)
214 {
215 if (!M_BITMAPDATA)
216 m_refData = new wxBitmapRefData;
217
218 M_BITMAPDATA->m_quality = q;
219 }
220
221 void wxBitmap::SetOk(bool isOk)
222 {
223 if (!M_BITMAPDATA)
224 m_refData = new wxBitmapRefData;
225
226 M_BITMAPDATA->m_ok = isOk;
227 }
228
229 void wxBitmap::SetPalette(const wxPalette& palette)
230 {
231 if (!M_BITMAPDATA)
232 m_refData = new wxBitmapRefData;
233
234 M_BITMAPDATA->m_bitmapPalette = palette ;
235 }
236
237 void wxBitmap::SetMask(wxMask *mask)
238 {
239 if (!M_BITMAPDATA)
240 m_refData = new wxBitmapRefData;
241
242 M_BITMAPDATA->m_bitmapMask = mask ;
243 }
244
245 bool wxBitmap::Ok() const
246 {
247 return m_refData && M_BITMAPDATA->m_ok;
248 }
249
250 wxPalette* wxBitmap::GetPalette() const
251 {
252 if(!m_refData)
253 return NULL;
254 return &M_BITMAPDATA->m_bitmapPalette;
255 }
256
257 wxMask* wxBitmap::GetMask() const
258 {
259 if(!m_refData)
260 return NULL;
261 return M_BITMAPDATA->m_bitmapMask;
262 }
263
264 int wxBitmap::GetDepth() const
265 {
266 if(!m_refData)
267 return 0;
268 return M_BITMAPDATA->m_depth;
269 }
270
271 int wxBitmap::GetWidth() const
272 {
273 if(!m_refData)
274 return 0;
275 return M_BITMAPDATA->m_width;
276 }
277
278 int wxBitmap::GetHeight() const
279 {
280 if(!m_refData)
281 return 0;
282 return M_BITMAPDATA->m_height;
283 }
284
285 bool wxBitmap::Create(int w, int h, int d)
286 {
287 UnRef();
288
289 m_refData = new wxBitmapRefData;
290
291 M_BITMAPDATA->m_width = w;
292 M_BITMAPDATA->m_height = h;
293 M_BITMAPDATA->m_depth = d;
294
295 /* TODO: create new bitmap */
296 M_BITMAPDATA->m_cocoaNSBitmapImageRep = [[NSBitmapImageRep alloc]
297 initWithBitmapDataPlanes: NULL
298 pixelsWide: w
299 pixelsHigh: h
300 bitsPerSample: 8
301 samplesPerPixel: 3
302 hasAlpha: NO
303 isPlanar: NO
304 colorSpaceName: NSCalibratedRGBColorSpace
305 bytesPerRow: 0 // NOTE: Contrary to Apple documentation Mac OS
306 // 10.4 will add padding bytes when 0 is used here
307 bitsPerPixel: 0];
308
309 wxLogTrace(wxTRACE_COCOA,wxT("M_BITMAPDATA=%p NSBitmapImageRep bitmapData=%p"), M_BITMAPDATA, [M_BITMAPDATA->m_cocoaNSBitmapImageRep bitmapData]);
310 M_BITMAPDATA->m_ok = true;
311 M_BITMAPDATA->m_numColors = 0;
312 M_BITMAPDATA->m_quality = 0;
313 M_BITMAPDATA->m_bitmapMask = NULL;
314
315 return M_BITMAPDATA->m_ok;
316 }
317
318 bool wxBitmap::LoadFile(const wxString& filename, wxBitmapType type)
319 {
320 wxAutoNSAutoreleasePool pool;
321 UnRef();
322
323 m_refData = new wxBitmapRefData;
324
325 NSBitmapImageRep *imageRep = [NSBitmapImageRep
326 imageRepWithContentsOfFile:wxNSStringWithWxString(filename)];
327
328 if(imageRep)
329 {
330 M_BITMAPDATA->m_width = [imageRep pixelsWide];
331 M_BITMAPDATA->m_height = [imageRep pixelsHigh];
332 M_BITMAPDATA->m_depth = 24; // FIXME
333 M_BITMAPDATA->m_ok = true;
334 M_BITMAPDATA->m_numColors = 0;
335 M_BITMAPDATA->m_quality = 0;
336 M_BITMAPDATA->m_cocoaNSBitmapImageRep = [imageRep retain];
337 M_BITMAPDATA->m_bitmapMask = NULL;
338 return true;
339 }
340 wxImage image;
341 if(!image.LoadFile(filename,type))
342 return false;
343 if(!image.Ok())
344 return false;
345 *this = wxBitmap(image);
346 return true;
347 }
348
349 bool wxBitmap::Create(void *data, wxBitmapType type, int width, int height, int depth)
350 {
351 UnRef();
352
353 m_refData = new wxBitmapRefData;
354
355 return false;
356 }
357
358 bool wxBitmap::SaveFile(const wxString& filename, wxBitmapType type, const wxPalette *palette) const
359 {
360 return false;
361 }
362
363 bool wxBitmap::CopyFromIcon(const wxIcon& icon)
364 {
365 UnRef();
366 if(!icon.GetNSImage());
367 [icon.GetNSImage() lockFocus];
368 NSRect imageRect;
369 imageRect.origin.x = imageRect.origin.y = 0.0;
370 imageRect.size = [icon.GetNSImage() size];
371 NSBitmapImageRep *newBitmapRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:imageRect];
372 [icon.GetNSImage() unlockFocus];
373 if(!newBitmapRep)
374 return false;
375 m_refData = new wxBitmapRefData;
376 M_BITMAPDATA->m_cocoaNSBitmapImageRep = newBitmapRep;
377 M_BITMAPDATA->m_width = [newBitmapRep pixelsWide];
378 M_BITMAPDATA->m_height = [newBitmapRep pixelsHigh];
379 M_BITMAPDATA->m_depth = [newBitmapRep bitsPerSample]*[newBitmapRep samplesPerPixel];
380 M_BITMAPDATA->m_ok = true;
381 M_BITMAPDATA->m_numColors = 0;
382 M_BITMAPDATA->m_quality = 0;
383 M_BITMAPDATA->m_bitmapMask = NULL;
384 return true;
385 }
386
387 wxBitmap wxBitmap::GetSubBitmap(wxRect const&) const
388 {
389 return wxNullBitmap;
390 }
391
392 wxImage wxBitmap::ConvertToImage() const
393 {
394 wxAutoNSAutoreleasePool pool;
395 if(!Ok())
396 return /*wxImage(5,5)*/wxNullImage;
397 NSImage *nsimage = GetNSImage(false /* don't use mask */);
398 wxImage newImage(M_BITMAPDATA->m_width,M_BITMAPDATA->m_height);
399 [nsimage lockFocus];
400 for(int i=0; i < M_BITMAPDATA->m_width; i++)
401 {
402 // Don't let the pool get too big as you'll notice we're creating
403 // two autoreleased NSColor objects with every iteration.
404 wxAutoNSAutoreleasePool loopPool;
405 for(int j=0; j < M_BITMAPDATA->m_height; j++)
406 {
407 NSColor *pixelColor = NSReadPixel(NSMakePoint(i,M_BITMAPDATA->m_height - j - 1));
408 NSColor *color = [pixelColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
409 newImage.SetRGB(i,j,int([color redComponent]*255.0), int([color greenComponent]*255.0), int([color blueComponent]*255.0));
410 }
411 }
412 [nsimage unlockFocus];
413 return newImage;
414 }
415
416 bool wxBitmap::CreateFromXpm(const char **xpm)
417 {
418 #if wxUSE_IMAGE && wxUSE_XPM
419 UnRef();
420
421 wxCHECK_MSG( xpm, false, wxT("invalid XPM data") );
422
423 wxXPMDecoder decoder;
424 wxImage img = decoder.ReadData(xpm);
425 wxCHECK_MSG( img.Ok(), false, wxT("invalid XPM data") );
426
427 *this = wxBitmap(img);
428 return true;
429 #else
430 return false;
431 #endif
432 }
433
434 bool wxBitmap::CreateFromImage(const wxImage& image, int depth)
435 {
436 UnRef();
437
438 wxCHECK_MSG(image.Ok(), false, wxT("invalid image"));
439 wxCHECK_MSG(depth == -1 || depth == 1, false, wxT("invalid bitmap depth"));
440
441 m_refData = new wxBitmapRefData();
442
443 M_BITMAPDATA->m_width = image.GetWidth();
444 M_BITMAPDATA->m_height = image.GetHeight();
445 NSBitmapImageRep *bitmapImage = [[NSBitmapImageRep alloc]
446 initWithBitmapDataPlanes: NULL
447 pixelsWide: image.GetWidth()
448 pixelsHigh: image.GetHeight()
449 bitsPerSample: 8
450 samplesPerPixel: 3
451 hasAlpha: NO
452 isPlanar: NO
453 colorSpaceName: NSCalibratedRGBColorSpace
454 bytesPerRow: image.GetWidth()*3
455 bitsPerPixel: 0];
456
457 // TODO: Specify bytesPerRow:0 and then use [bitmapImage bytesPerRow]
458 // so that the rows are aligned suitably for altivec by the OS (Tiger)
459 const int numBytes = image.GetWidth()*image.GetHeight()*3;
460 memcpy([bitmapImage bitmapData], image.GetData(), numBytes);
461 // TODO: Alpha and convert to desired depth
462 M_BITMAPDATA->m_depth = 24;
463 M_BITMAPDATA->m_ok = true;
464 M_BITMAPDATA->m_numColors = 0;
465 M_BITMAPDATA->m_quality = 0;
466 M_BITMAPDATA->m_cocoaNSBitmapImageRep = bitmapImage;
467 M_BITMAPDATA->m_bitmapMask = new wxMask(*this,wxColour(image.GetMaskRed(),image.GetMaskGreen(),image.GetMaskBlue()));
468 return true;
469 }
470
471 void *wxBitmap::GetRawData(wxPixelDataBase& data, int bpp)
472 {
473 if(!Ok())
474 return NULL;
475
476 NSBitmapImageRep *bitmapRep = M_BITMAPDATA->m_cocoaNSBitmapImageRep;
477 if(!bitmapRep)
478 return NULL;
479
480 if([bitmapRep bitsPerPixel]!=bpp)
481 {
482 wxFAIL_MSG( _T("incorrect bitmap type in wxBitmap::GetRawData()") );
483 return NULL;
484 }
485 data.m_width = [bitmapRep pixelsWide];
486 data.m_height = [bitmapRep pixelsHigh];
487 data.m_stride = [bitmapRep bytesPerRow];
488 return [bitmapRep bitmapData];
489
490 // NOTE: It is up to the user to make sure they used the proper
491 // pixel format class that details what is actually inside the pixels
492 // We can only check to make sure that the total number of bits per
493 // pixel are being iterated over properly
494 // NSBitmapImageRep can contain grayscale or CMYK data and
495 // wxPixelDataBase doesn't really define the color format
496 }
497
498 void wxBitmap::UngetRawData(wxPixelDataBase& data)
499 { // TODO
500 }
501
502 void wxBitmap::UseAlpha()
503 { // TODO
504 }
505
506 // ========================================================================
507 // wxMask
508 // ========================================================================
509
510 IMPLEMENT_DYNAMIC_CLASS(wxMask, wxObject)
511
512 wxMask::wxMask()
513 {
514 m_cocoaNSBitmapImageRep = nil;
515 }
516
517 // Construct a mask from a bitmap and a colour indicating
518 // the transparent area
519 wxMask::wxMask(const wxBitmap& bitmap, const wxColour& colour)
520 {
521 m_cocoaNSBitmapImageRep = nil;
522 Create(bitmap, colour);
523 }
524
525 // Construct a mask from a bitmap and a palette index indicating
526 // the transparent area
527 wxMask::wxMask(const wxBitmap& bitmap, int paletteIndex)
528 {
529 m_cocoaNSBitmapImageRep = nil;
530
531 Create(bitmap, paletteIndex);
532 }
533
534 // Construct a mask from a mono bitmap (copies the bitmap).
535 wxMask::wxMask(const wxBitmap& bitmap)
536 {
537 m_cocoaNSBitmapImageRep = nil;
538
539 Create(bitmap);
540 }
541
542 wxMask::~wxMask()
543 {
544 [m_cocoaNSBitmapImageRep release];
545 }
546
547 // Create a mask from a mono bitmap (copies the bitmap).
548 bool wxMask::Create(const wxBitmap& bitmap)
549 {
550 // TODO
551 return FALSE;
552 }
553
554 // Create a mask from a bitmap and a palette index indicating
555 // the transparent area
556 bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex)
557 {
558 // TODO
559 return FALSE;
560 }
561
562 template <typename PixelData>
563 static bool wxMask_CreateFromBitmapData(PixelData srcData, const wxColour& colour, unsigned char *dstData)
564 {
565 wxCHECK_MSG(dstData,false,wxT("Couldn't access mask data"));
566 typename PixelData::Iterator p(srcData);
567 const int nRows = srcData.GetHeight();
568 const int nCols = srcData.GetWidth();
569 // Total number of bytes per destination column
570 const int dstRowLength = (nCols+7)/8;
571 // Number of source columns that fit into a byte in the destination
572 const int width_aligned = nCols/8*8;
573 for(int y=0; y<nRows; ++y)
574 {
575 typename PixelData::Iterator rowStart(p);
576 unsigned char *dstRow = dstData + y*dstRowLength;
577 for(int x=0; x<width_aligned; x+=8)
578 {
579 unsigned char *dstByte = dstRow + x/8;
580 *dstByte = 0;
581 // Take source RGB, compare it with the wxColour
582 for(int j=0; j<8; ++j, ++p)
583 {
584 *dstByte +=
585 ( p.Red()!=colour.Red()
586 || p.Green()!=colour.Green()
587 || p.Blue()!=colour.Blue()
588 ) << (7-j);
589 }
590 }
591 // Handle the remaining 0-7 pixels in the row
592 unsigned char *dstByte = dstRow + width_aligned/8;
593 if(nCols%8>0)
594 *dstByte = 0;
595 for(int j=0; j<(nCols%8); ++j, ++p)
596 {
597 *dstByte +=
598 ( p.Red()!=colour.Red()
599 || p.Green()!=colour.Green()
600 || p.Blue()!=colour.Blue()
601 ) << (7-j);
602 }
603 p = rowStart;
604 p.OffsetY(srcData,1);
605 }
606 return true;
607 }
608
609 // Create a mask from a bitmap and a colour indicating
610 // the transparent area
611 bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
612 {
613 wxAutoNSAutoreleasePool pool;
614 if(!bitmap.Ok())
615 return false;
616 int bmpWidth = bitmap.GetWidth();
617 int bmpHeight = bitmap.GetHeight();
618 int dstRowLength = (bmpWidth+7)/8;
619
620 // Create a bitmap image rep with 1-bit per pixel data representing
621 // the alpha channel padded such that rows end on byte boundaries
622 // Since NSBitmapImageRep doesn't have any sort of NSNullColorSpace
623 // we must have at least one channel of non-alpha data. In order to
624 // make our life easy, we use planar data which results in two
625 // separate arrays. We don't need to touch the first because it
626 // should never be used. The second is the 1-bit "alpha" data.
627 NSBitmapImageRep *maskRep = [[[NSBitmapImageRep alloc]
628 initWithBitmapDataPlanes:NULL pixelsWide:bmpWidth
629 pixelsHigh:bmpHeight bitsPerSample:1
630 samplesPerPixel:2 hasAlpha:YES isPlanar:YES
631 colorSpaceName:NSCalibratedWhiteColorSpace
632 bytesPerRow:dstRowLength bitsPerPixel:1] autorelease];
633 wxCHECK(maskRep,false);
634
635 // We need the source NSBitmapImageRep to detemine its pixel format
636 NSBitmapImageRep *srcBitmapRep = const_cast<wxBitmap&>(bitmap).GetNSBitmapImageRep();
637 wxCHECK_MSG(srcBitmapRep,false,wxT("Can't create mask for an uninitialized bitmap"));
638
639 // Get a pointer to the destination data
640 unsigned char *dstPlanes[5] = {NULL,NULL,NULL,NULL,NULL};
641 [maskRep getBitmapDataPlanes:dstPlanes];
642 unsigned char *dstData = dstPlanes[1];
643 // The wxImage format (which we use whenever we imported from wxImage)
644 if([srcBitmapRep bitsPerPixel]==24 && [srcBitmapRep bitsPerSample]==8 && [srcBitmapRep samplesPerPixel]==3 && [srcBitmapRep hasAlpha]==NO)
645 {
646 wxPixelData<wxBitmap,wxNativePixelFormat> pixelData(const_cast<wxBitmap&>(bitmap));
647 wxCHECK_MSG(wxMask_CreateFromBitmapData(pixelData, colour, dstData),
648 false, wxT("Unable to access raw data"));
649 }
650 // 32-bpp RGBx (x=throw away, no alpha)
651 else if([srcBitmapRep bitsPerPixel]==32 && [srcBitmapRep bitsPerSample]==8 && [srcBitmapRep samplesPerPixel]==3 && [srcBitmapRep hasAlpha]==NO)
652 {
653 typedef wxPixelFormat<unsigned char,32,0,1,2> PixelFormat;
654 wxPixelData<wxBitmap,PixelFormat> pixelData(const_cast<wxBitmap&>(bitmap));
655 wxCHECK_MSG(wxMask_CreateFromBitmapData(pixelData, colour, dstData),
656 false, wxT("Unable to access raw data"));
657 }
658 // 32-bpp RGBA
659 else if([srcBitmapRep bitsPerPixel]==32 && [srcBitmapRep bitsPerSample]==8 && [srcBitmapRep samplesPerPixel]==4 && [srcBitmapRep hasAlpha]==YES)
660 {
661 wxPixelData<wxBitmap,wxAlphaPixelFormat> pixelData(const_cast<wxBitmap&>(bitmap));
662 wxCHECK_MSG(wxMask_CreateFromBitmapData(pixelData, colour, dstData),
663 false, wxT("Unable to access raw data"));
664 }
665 else
666 { wxCHECK_MSG(false,false,wxT("Unimplemented pixel format")); }
667
668 // maskRep was autoreleased in case we had to exit quickly
669 m_cocoaNSBitmapImageRep = [maskRep retain];
670 return true;
671 }