X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9d9e3858509a4b6ca657991c76a7036fde6092d5..5fa150e233fa449ee270ac26ecf074f5c40acb1e:/src/common/anidecod.cpp diff --git a/src/common/anidecod.cpp b/src/common/anidecod.cpp index 455dc12a4e..7f90c8fdeb 100644 --- a/src/common/anidecod.cpp +++ b/src/common/anidecod.cpp @@ -14,7 +14,9 @@ #pragma hdrstop #endif -#if wxUSE_STREAMS && wxUSE_GIF +#if wxUSE_STREAMS && wxUSE_ICO_CUR + +#include "wx/anidecod.h" #ifndef WX_PRECOMP #include "wx/palette.h" @@ -22,13 +24,10 @@ #include #include -#include "wx/anidecod.h" // static wxCURHandler wxANIDecoder::sm_handler; - - //--------------------------------------------------------------------------- // wxANIFrameInfo //--------------------------------------------------------------------------- @@ -43,13 +42,11 @@ public: int m_imageIndex; }; -#include // this is a magic incantation which must be done! -WX_DEFINE_OBJARRAY(wxImageArray); - -#include // this is a magic incantation which must be done! -WX_DEFINE_OBJARRAY(wxANIFrameInfoArray); - +#include "wx/arrimpl.cpp" // this is a magic incantation which must be done! +WX_DEFINE_OBJARRAY(wxImageArray) +#include "wx/arrimpl.cpp" // this is a magic incantation which must be done! +WX_DEFINE_OBJARRAY(wxANIFrameInfoArray) //--------------------------------------------------------------------------- @@ -171,6 +168,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 +244,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 +254,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 +295,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); @@ -308,7 +327,7 @@ bool wxANIDecoder::Load( wxInputStream& stream ) m_szAnimation.GetHeight() == 0) m_szAnimation = wxSize(m_images[0].GetWidth(), m_images[0].GetHeight()); - return m_szAnimation!=wxDefaultSize; + return m_szAnimation != wxDefaultSize; } -#endif // wxUSE_STREAMS && wxUSE_GIF +#endif // wxUSE_STREAMS && wxUSE_ICO_CUR