]> git.saurik.com Git - wxWidgets.git/commitdiff
swap wxANIHeader bytes on big endian architectures
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 9 Oct 2006 22:26:25 +0000 (22:26 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 9 Oct 2006 22:26:25 +0000 (22:26 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41845 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/anidecod.cpp

index 455dc12a4e422f4eab1e84eeeb6592017d6c611e..76d2f9c0ba8261e7b9c2cfd45123a60c05b3399f 100644 (file)
@@ -171,6 +171,25 @@ struct wxANIHeader
     wxInt32 cPlanes;      // 1
     wxInt32 JifRate;      // Default Jiffies (1/60th of a second) if rate chunk not present.
     wxInt32 flags;        // Animation Flag (see AF_ constants)
     wxInt32 cPlanes;      // 1
     wxInt32 JifRate;      // Default Jiffies (1/60th of a second) if rate chunk not present.
     wxInt32 flags;        // Animation Flag (see AF_ constants)
+
+    // ANI files are always little endian so we need to swap bytes on big
+    // endian architectures
+#ifdef WORDS_BIGENDIAN
+    void AdjustEndianness()
+    {
+        // this works because all our fields are wxInt32 and they must be
+        // packed without holes between them (if they're not, they wouldn't map
+        // to the file header!)
+        wxInt32 * const start = (wxInt32 *)this;
+        wxInt32 * const end = start + sizeof(wxANIHeader)/sizeof(wxInt32);
+        for ( wxInt32 *p = start; p != end; p++ )
+        {
+            *p = wxINT32_SWAP_ALWAYS(*p);
+        }
+    }
+#else
+    void AdjustEndianness() { }
+#endif
 };
 
 bool wxANIDecoder::Load( wxInputStream& stream )
 };
 
 bool wxANIDecoder::Load( wxInputStream& stream )
@@ -228,6 +247,7 @@ bool wxANIDecoder::Load( wxInputStream& stream )
 
             struct wxANIHeader header;
             stream.Read(&header, sizeof(wxANIHeader));
 
             struct wxANIHeader header;
             stream.Read(&header, sizeof(wxANIHeader));
+            header.AdjustEndianness();
 
             // we should have a global frame size
             m_szAnimation = wxSize(header.cx, header.cy);
 
             // we should have a global frame size
             m_szAnimation = wxSize(header.cx, header.cy);
@@ -237,7 +257,7 @@ bool wxANIDecoder::Load( wxInputStream& stream )
             if ( m_nFrames == 0 )
                 return false;
 
             if ( m_nFrames == 0 )
                 return false;
 
-            globaldelay = wxINT32_SWAP_ON_BE(header.JifRate) * 1000 / 60;
+            globaldelay = header.JifRate * 1000 / 60;
 
             m_images.Alloc(header.cFrames);
             m_info.Add(wxANIFrameInfo(), m_nFrames);
 
             m_images.Alloc(header.cFrames);
             m_info.Add(wxANIFrameInfo(), m_nFrames);
@@ -278,7 +298,9 @@ bool wxANIDecoder::Load( wxInputStream& stream )
             m_images.Add(image);
         }
         else
             m_images.Add(image);
         }
         else
+        {
             stream.SeekI(stream.TellI() + datalen);
             stream.SeekI(stream.TellI() + datalen);
+        }
 
         // try to read next data chunk:
         stream.Read(&FCC1, 4);
 
         // try to read next data chunk:
         stream.Read(&FCC1, 4);