]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/image.cpp
Implement bitmap mask copying in wxX11.
[wxWidgets.git] / src / common / image.cpp
index a3c94837675046e78b17694e0121b7dfc65a3628..4a070120399248e236e5c61f3cca4cc028a1251a 100644 (file)
@@ -668,13 +668,13 @@ wxImage wxImage::ResampleBilinear(int width, int height) const
 
             //result lines
 
-            dst_data[0] = r1 * dy1 + r2 * dy;
-            dst_data[1] = g1 * dy1 + g2 * dy;
-            dst_data[2] = b1 * dy1 + b2 * dy;
+            dst_data[0] = static_cast<unsigned char>(r1 * dy1 + r2 * dy);
+            dst_data[1] = static_cast<unsigned char>(g1 * dy1 + g2 * dy);
+            dst_data[2] = static_cast<unsigned char>(b1 * dy1 + b2 * dy);
             dst_data += 3;
 
             if ( src_alpha )
-                *dst_alpha++ = a1 * dy1 + a2 * dy;
+                *dst_alpha++ = static_cast<unsigned char>(a1 * dy1 + a2 * dy);
         }
     }
 
@@ -1857,6 +1857,17 @@ void wxImage::InitAlpha()
     }
 }
 
+void wxImage::ClearAlpha()
+{
+    wxCHECK_RET( HasAlpha(), wxT("image already doesn't have an alpha channel") );
+
+    if ( !M_IMGDATA->m_staticAlpha )
+        free( M_IMGDATA->m_alpha );
+
+    M_IMGDATA->m_alpha = NULL;
+}
+
+
 // ----------------------------------------------------------------------------
 // mask support
 // ----------------------------------------------------------------------------
@@ -2009,7 +2020,7 @@ bool wxImage::SetMaskFromImage(const wxImage& mask,
 bool wxImage::ConvertAlphaToMask(unsigned char threshold)
 {
     if ( !HasAlpha() )
-        return true;
+        return false;
 
     unsigned char mr, mg, mb;
     if ( !FindFirstUnusedColour(&mr, &mg, &mb) )
@@ -2018,17 +2029,16 @@ bool wxImage::ConvertAlphaToMask(unsigned char threshold)
         return false;
     }
 
-    ConvertAlphaToMask(mr, mg, mb, threshold);
-    return true;
+    return ConvertAlphaToMask(mr, mg, mb, threshold);
 }
 
-void wxImage::ConvertAlphaToMask(unsigned char mr,
+bool wxImage::ConvertAlphaToMask(unsigned char mr,
                                  unsigned char mg,
                                  unsigned char mb,
                                  unsigned char threshold)
 {
     if ( !HasAlpha() )
-        return;
+        return false;
 
     AllocExclusive();
 
@@ -2059,6 +2069,8 @@ void wxImage::ConvertAlphaToMask(unsigned char mr,
 
     M_IMGDATA->m_alpha = NULL;
     M_IMGDATA->m_staticAlpha = false;
+
+    return true;
 }
 
 // ----------------------------------------------------------------------------
@@ -2316,7 +2328,7 @@ int wxImage::GetImageCount( wxInputStream &stream, wxBitmapType type )
 
     if ( !handler )
     {
-        wxLogWarning(_("No image handler for type %ld defined."), type);
+        wxLogWarning(_("No image handler for type %d defined."), type);
         return false;
     }
 
@@ -2326,7 +2338,7 @@ int wxImage::GetImageCount( wxInputStream &stream, wxBitmapType type )
     }
     else
     {
-        wxLogError(_("Image file is not of type %ld."), type);
+        wxLogError(_("Image file is not of type %d."), type);
         return 0;
     }
 }
@@ -2341,8 +2353,6 @@ bool wxImage::DoLoad(wxImageHandler& handler, wxInputStream& stream, int index)
     if ( !handler.LoadFile(this, stream, true/*verbose*/, index) )
         return false;
 
-    M_IMGDATA->m_type = handler.GetType();
-
     // rescale the image to the specified size if needed
     if ( maxWidth || maxHeight )
     {
@@ -2363,6 +2373,9 @@ bool wxImage::DoLoad(wxImageHandler& handler, wxInputStream& stream, int index)
             Rescale(width, height, wxIMAGE_QUALITY_HIGH);
     }
 
+    // Set this after Rescale, which currently does not preserve it
+    M_IMGDATA->m_type = handler.GetType();
+
     return true;
 }
 
@@ -2393,13 +2406,13 @@ bool wxImage::LoadFile( wxInputStream& stream, wxBitmapType type, int index )
     handler = FindHandler(type);
     if ( !handler )
     {
-        wxLogWarning( _("No image handler for type %ld defined."), type );
+        wxLogWarning( _("No image handler for type %d defined."), type );
         return false;
     }
 
     if ( stream.IsSeekable() && !handler->CanRead(stream) )
     {
-        wxLogError(_("Image file is not of type %ld."), type);
+        wxLogError(_("Image file is not of type %d."), type);
         return false;
     }