From: David Elliott Date: Fri, 27 Jul 2007 20:57:50 +0000 (+0000) Subject: * Implement the wxMask copy constructor to retain the source object's X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/319fe1034c0bdecf2b3a34669f3a15782c60d0b2?ds=inline * Implement the wxMask copy constructor to retain the source object's m_cocoaNSBitmapImageRep (fixes multiple release bug). * Add some debug messages for unimplemented wxMask::Create overloads. * Implement mask creation w/ key color from 8-bpp grayscale bitmap. This makes the mask image in the drawing sample's mask page work. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47757 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/cocoa/bitmap.h b/include/wx/cocoa/bitmap.h index 866b51a984..ca2b3b0775 100644 --- a/include/wx/cocoa/bitmap.h +++ b/include/wx/cocoa/bitmap.h @@ -43,6 +43,9 @@ public: // Construct a mask from a mono bitmap (copies the bitmap). wxMask(const wxBitmap& bitmap); + // Copy constructor + wxMask(const wxMask& src); + virtual ~wxMask(); bool Create(const wxBitmap& bitmap, const wxColour& colour); diff --git a/src/cocoa/bitmap.mm b/src/cocoa/bitmap.mm index ff0cb8cd36..b16ba01087 100644 --- a/src/cocoa/bitmap.mm +++ b/src/cocoa/bitmap.mm @@ -519,6 +519,13 @@ wxMask::wxMask(const wxBitmap& bitmap) Create(bitmap); } +// Copy constructor +wxMask::wxMask(const wxMask& src) +: wxObject(src) +, m_cocoaNSBitmapImageRep([src.m_cocoaNSBitmapImageRep retain]) +{ +} + wxMask::~wxMask() { [m_cocoaNSBitmapImageRep release]; @@ -528,6 +535,7 @@ wxMask::~wxMask() bool wxMask::Create(const wxBitmap& bitmap) { // TODO + wxLogDebug("Cannot yet create a mask from a mono bitmap"); return FALSE; } @@ -536,6 +544,7 @@ bool wxMask::Create(const wxBitmap& bitmap) bool wxMask::Create(const wxBitmap& bitmap, int paletteIndex) { // TODO + wxLogDebug("Cannot yet create a mask from a palette bitmap"); return FALSE; } @@ -642,6 +651,14 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour) wxCHECK_MSG(wxMask_CreateFromBitmapData(pixelData, colour, dstData), false, wxT("Unable to access raw data")); } + else if([srcBitmapRep bitsPerPixel]==8 && [srcBitmapRep bitsPerSample]==8 && [srcBitmapRep samplesPerPixel]==1 && [srcBitmapRep hasAlpha]==NO) + // 8-bpp Grayscale, no alpha + { // Force all RGB to access the same grayscale component + typedef wxPixelFormat PixelFormat; + wxPixelData pixelData(const_cast(bitmap)); + wxCHECK_MSG(wxMask_CreateFromBitmapData(pixelData, colour, dstData), + false, wxT("Unable to access raw data")); + } else { wxCHECK_MSG(false,false,wxT("Unimplemented pixel format")); }