From ce7efe2d0f056042d86cc581a7ee3af694b1fd6b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 9 Oct 2006 22:26:25 +0000 Subject: [PATCH] swap wxANIHeader bytes on big endian architectures git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41845 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/anidecod.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/common/anidecod.cpp b/src/common/anidecod.cpp index 455dc12a4e..76d2f9c0ba 100644 --- a/src/common/anidecod.cpp +++ b/src/common/anidecod.cpp @@ -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) + + // 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 ) @@ -228,6 +247,7 @@ bool wxANIDecoder::Load( wxInputStream& stream ) struct wxANIHeader header; stream.Read(&header, sizeof(wxANIHeader)); + header.AdjustEndianness(); // 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; - 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); @@ -278,7 +298,9 @@ bool wxANIDecoder::Load( wxInputStream& stream ) m_images.Add(image); } else + { stream.SeekI(stream.TellI() + datalen); + } // try to read next data chunk: stream.Read(&FCC1, 4); -- 2.45.2