]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/gifdecod.cpp
replace m_nSelection by m_selection
[wxWidgets.git] / src / common / gifdecod.cpp
index 0a2dad27244465b6811980ccb722e872c247b656..27669b8d2a7b8271cccd565ff580b78da92d469e 100644 (file)
 
 #ifndef WX_PRECOMP
     #include "wx/palette.h"
+    #include "wx/intl.h"
+    #include "wx/log.h"
 #endif
 
 #include <stdlib.h>
 #include <string.h>
 #include "wx/gifdecod.h"
-#include "wx/ptr_scpd.h"
+#include "wx/scopedptr.h"
 #include "wx/scopeguard.h"
 
 
@@ -51,7 +53,7 @@ public:
     unsigned char *pal;             // palette
     unsigned int ncolours;          // number of colours
 
-    DECLARE_NO_COPY_CLASS(GIFImage)
+    wxDECLARE_NO_COPY_CLASS(GIFImage);
 };
 
 wxDECLARE_SCOPED_PTR(GIFImage, GIFImagePtr)
@@ -573,16 +575,13 @@ as an End of Information itself)
 // CanRead:
 //  Returns true if the file looks like a valid GIF, false otherwise.
 //
-bool wxGIFDecoder::CanRead(wxInputStream &stream) const
+bool wxGIFDecoder::DoCanRead(wxInputStream &stream) const
 {
     unsigned char buf[3];
 
     if ( !stream.Read(buf, WXSIZEOF(buf)) )
         return false;
 
-    if (stream.SeekI(-(wxFileOffset)WXSIZEOF(buf), wxFromCurrent) == wxInvalidOffset)
-        return false;       // this happens e.g. for non-seekable streams
-
     return memcmp(buf, "GIF", WXSIZEOF(buf)) == 0;
 }
 
@@ -757,9 +756,30 @@ wxGIFErrorCode wxGIFDecoder::LoadGIF(wxInputStream& stream)
             pimg->w = buf[4] + 256 * buf[5];
             pimg->h = buf[6] + 256 * buf[7];
 
-            if ( anim && ((pimg->w == 0) || (pimg->w > (unsigned int)m_szAnimation.GetWidth()) ||
-                  (pimg->h == 0) || (pimg->h > (unsigned int)m_szAnimation.GetHeight())) )
-                return wxGIF_INVFORMAT;
+            if ( anim )
+            {
+                // some GIF images specify incorrect animation size but we can
+                // still open them if we fix up the animation size, see #9465
+                if ( m_nFrames == 0 )
+                {
+                    if ( pimg->w > (unsigned)m_szAnimation.x )
+                        m_szAnimation.x = pimg->w;
+                    if ( pimg->h > (unsigned)m_szAnimation.y )
+                        m_szAnimation.y = pimg->h;
+                }
+                else // subsequent frames
+                {
+                    // check that we have valid size
+                    if ( (!pimg->w || pimg->w > (unsigned)m_szAnimation.x) ||
+                            (!pimg->h || pimg->h > (unsigned)m_szAnimation.y) )
+                    {
+                        wxLogError(_("Incorrect GIF frame size (%u, %d) for "
+                                     "the frame #%u"),
+                                   pimg->w, pimg->h, m_nFrames);
+                        return wxGIF_INVFORMAT;
+                    }
+                }
+            }
 
             interl = ((buf[8] & 0x40)? 1 : 0);
             size = pimg->w * pimg->h;