]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/image.cpp
fix crashes due to missing npos handling in several wxString methods in STL build...
[wxWidgets.git] / src / common / image.cpp
index e739d5c71e09b2a1e92a59d1e989fa7a4a2d7fff..3f253221838056ec9259d797f5597e245f1de5d9 100644 (file)
@@ -1283,6 +1283,26 @@ void wxImage::Paste( const wxImage &image, int x, int y )
         return;
     }
 
+    // Copy over the alpha channel from the original image
+    if ( image.HasAlpha() )
+    {
+        if ( !HasAlpha() )
+            InitAlpha();
+
+        unsigned char* source_data = image.GetAlpha() + xx + yy*image.GetWidth();
+        int source_step = image.GetWidth();
+
+        unsigned char* target_data = GetAlpha() + (x+xx) + (y+yy)*M_IMGDATA->m_width;
+        int target_step = M_IMGDATA->m_width;
+
+        for (int j = 0; j < height; j++,
+                                    source_data += source_step,
+                                    target_data += target_step)
+        {
+            memcpy( target_data, source_data, width );
+        }
+    }
+
     if (!HasMask() && image.HasMask())
     {
         unsigned char r = image.GetMaskRed();
@@ -2139,13 +2159,19 @@ int wxImage::GetImageCount( wxInputStream &stream, long type )
 
     if ( type == wxBITMAP_TYPE_ANY )
     {
-        wxList &list=GetHandlers();
+        const wxList& list = GetHandlers();
 
-        for (wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext())
+        for ( wxList::compatibility_iterator node = list.GetFirst();
+              node;
+              node = node->GetNext() )
         {
-             handler=(wxImageHandler*)node->GetData();
+             handler = (wxImageHandler*)node->GetData();
              if ( handler->CanRead(stream) )
-                 return handler->GetImageCount(stream);
+             {
+                 const int count = handler->GetImageCount(stream);
+                 if ( count >= 0 )
+                     return count;
+             }
 
         }
 
@@ -2182,17 +2208,22 @@ bool wxImage::LoadFile( wxInputStream& stream, long type, int index )
 
     if ( type == wxBITMAP_TYPE_ANY )
     {
-        wxList &list=GetHandlers();
-
-        for ( wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext() )
+        const wxList& list = GetHandlers();
+        for ( wxList::compatibility_iterator node = list.GetFirst();
+              node;
+              node = node->GetNext() )
         {
-             handler=(wxImageHandler*)node->GetData();
-             if ( handler->CanRead(stream) )
-                 return handler->LoadFile(this, stream, true/*verbose*/, index);
+             handler = (wxImageHandler*)node->GetData();
+             if ( handler->CanRead(stream) &&
+                    handler->LoadFile(this, stream, true/*verbose*/, index) )
+             {
+                 return true;
+             }
 
         }
 
         wxLogWarning( _("No handler found for image type.") );
+
         return false;
     }