]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/core/bitmap.cpp
Standardize on using "Added" instead of "Add" in the change log.
[wxWidgets.git] / src / osx / core / bitmap.cpp
index fcc3a24ac0828c28d84a85b2c205ee476967ec87..22efcde42a143c08c02db1a68b85e9782344e96e 100644 (file)
@@ -890,9 +890,9 @@ wxBitmap::wxBitmap(const char bits[], int the_width, int the_height, int no_bits
     {
         if ( no_bits == 1 )
         {
-            int linesize = ( the_width / (sizeof(unsigned char) * 8)) ;
-            if ( the_width % (sizeof(unsigned char) * 8) )
-                linesize += sizeof(unsigned char);
+            int linesize = the_width / 8;
+            if ( the_width % 8 )
+                linesize++;
 
             unsigned char* linestart = (unsigned char*) bits ;
             unsigned char* destptr = (unsigned char*) BeginRawAccess() ;
@@ -1005,6 +1005,17 @@ IconRef wxBitmap::CreateIconRef() const
 
 #if wxOSX_USE_COCOA
 
+wxBitmap::wxBitmap(WX_NSImage image)
+{
+    (void)Create(image);
+}
+
+bool wxBitmap::Create(WX_NSImage image)
+{
+    wxCFRef<CGImageRef> cgimage(wxOSXCreateCGImageFromNSImage(image));
+    return Create(cgimage);
+}
+
 WX_NSImage wxBitmap::GetNSImage() const
 {
     wxCFRef< CGImageRef > cgimage(CreateCGImage());
@@ -1649,6 +1660,28 @@ bool wxMask::Create(const wxBitmap& bitmap, const wxColour& colour)
     return true;
 }
 
+wxBitmap wxMask::GetBitmap() const
+{
+    wxBitmap bitmap(m_width, m_height, 1);
+    unsigned char* dst = static_cast<unsigned char*>(bitmap.BeginRawAccess());
+    const int dst_stride = bitmap.GetBitmapData()->GetBytesPerRow();
+    const unsigned char* src = static_cast<unsigned char*>(GetRawAccess());
+    for (int j = 0; j < m_height; j++, src += m_bytesPerRow, dst += dst_stride)
+    {
+        unsigned char* d = dst;
+        for (int i = 0; i < m_width; i++)
+        {
+            const unsigned char byte = src[i];
+            *d++ = 0xff;
+            *d++ = byte;
+            *d++ = byte;
+            *d++ = byte;
+        }
+    }
+    bitmap.EndRawAccess();
+    return bitmap;
+}
+
 WXHBITMAP wxMask::GetHBITMAP() const
 {
     return m_maskBitmap ;