X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/63f8abca79edfcf92641b21b0a16687ac84d152b..63e02796620637b50a96d74a2264f3dea8def866:/src/common/imagiff.cpp diff --git a/src/common/imagiff.cpp b/src/common/imagiff.cpp index bd6fb87cfe..311fcadfbb 100644 --- a/src/common/imagiff.cpp +++ b/src/common/imagiff.cpp @@ -1,36 +1,37 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: imagiff.h +// Name: src/common/imagiff.h // Purpose: wxImage handler for Amiga IFF images -// Author: Steffen Gutmann +// Author: Steffen Gutmann, Thomas Meyer // RCS-ID: $Id$ // Copyright: (c) Steffen Gutmann, 2002 // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -// parts of the source are based on xviff by Thomas Meyer -// Permission for use in wxWindows has been gratefully given. - -#ifdef __GNUG__ -#pragma implementation "imagiff.h" -#endif +// Parts of this source are based on the iff loading algorithm found +// in xviff.c. Permission by the original author, Thomas Meyer, and +// by the author of xv, John Bradley for using the iff loading part +// in wxWidgets has been gratefully given. // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -# pragma hdrstop + #pragma hdrstop #endif +#if wxUSE_IMAGE && wxUSE_IFF + #ifndef WX_PRECOMP -# include "wx/defs.h" + #include "wx/log.h" + #include "wx/intl.h" #endif -#if wxUSE_IMAGE && wxUSE_IFF - #include "wx/imagiff.h" #include "wx/wfstream.h" -#include "wx/log.h" -#include "wx/intl.h" + +#if wxUSE_PALETTE + #include "wx/palette.h" +#endif // wxUSE_PALETTE #include #include @@ -66,7 +67,7 @@ public: unsigned int w; /* width */ unsigned int h; /* height */ int transparent; /* transparent color (-1 = none) */ - int colors; /* number of colors */ + int colors; /* number of colors */ unsigned char *p; /* bitmap */ unsigned char *pal; /* palette */ @@ -77,10 +78,10 @@ public: class WXDLLEXPORT wxIFFDecoder { private: - IFFImage *m_image; // image data - wxInputStream *m_f; // input stream - unsigned char *databuf; - unsigned char *picptr; + IFFImage *m_image; // image data + wxInputStream *m_f; // input stream + unsigned char *databuf; + unsigned char *picptr; unsigned char *decomp_mem; void Destroy(); @@ -140,7 +141,7 @@ bool wxIFFDecoder::ConvertToImage(wxImage *image) const image->Create(GetWidth(), GetHeight()); if (!image->Ok()) - return FALSE; + return false; unsigned char *pal = GetPalette(); unsigned char *src = GetData(); @@ -169,7 +170,7 @@ bool wxIFFDecoder::ConvertToImage(wxImage *image) const image->SetMaskColour(255, 0, 255); } else - image->SetMask(FALSE); + image->SetMask(false); #if wxUSE_PALETTE if (pal && colors > 0) @@ -201,7 +202,7 @@ bool wxIFFDecoder::ConvertToImage(wxImage *image) const dst[2] = src[2]; } - return TRUE; + return true; } @@ -224,22 +225,24 @@ int wxIFFDecoder::GetTransparentColour() const { return m_image->transparent; } // // CanRead: -// Returns TRUE if the file looks like a valid IFF, FALSE otherwise. +// Returns true if the file looks like a valid IFF, false otherwise. // bool wxIFFDecoder::CanRead() { - unsigned char buf[12] = ""; + unsigned char buf[12]; + + if ( !m_f->Read(buf, WXSIZEOF(buf)) ) + return false; - m_f->Read(buf, 12); - m_f->SeekI(-12, wxFromCurrent); + m_f->SeekI(-(wxFileOffset)WXSIZEOF(buf), wxFromCurrent); - return (memcmp(buf, "FORM", 4) == 0 && memcmp(buf+8, "ILBM", 4) == 0); + return (memcmp(buf, "FORM", 4) == 0) && (memcmp(buf+8, "ILBM", 4) == 0); } // ReadIFF: // Based on xv source code by Thomas Meyer -// Permission for use in wxWindows has been gratefully given. +// Permission for use in wxWidgets has been gratefully given. typedef unsigned char byte; #define IFFDEBUG 0 @@ -331,7 +334,7 @@ int wxIFFDecoder::ReadIFF() } // compute file length - off_t currentPos = m_f->TellI(); + wxFileOffset currentPos = m_f->TellI(); m_f->SeekI(0, wxFromEnd); long filesize = m_f->TellI(); m_f->SeekI(currentPos, wxFromStart); @@ -392,7 +395,7 @@ int wxIFFDecoder::ReadIFF() #else if (chunkLen < 0) { // format error? #endif - break; + break; } bool truncated = (dataptr + 8 + chunkLen > dataend); @@ -727,7 +730,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxIFFHandler, wxImageHandler) #if wxUSE_STREAMS -bool wxIFFHandler::LoadFile(wxImage *image, wxInputStream& stream, +bool wxIFFHandler::LoadFile(wxImage *image, wxInputStream& stream, bool verbose, int WXUNUSED(index)) { wxIFFDecoder *decod; @@ -755,7 +758,7 @@ bool wxIFFHandler::LoadFile(wxImage *image, wxInputStream& stream, } } delete decod; - return FALSE; + return false; } if ((error == wxIFF_TRUNCATED) && verbose) @@ -776,19 +779,14 @@ bool wxIFFHandler::SaveFile(wxImage * WXUNUSED(image), if (verbose) wxLogDebug(wxT("IFF: the handler is read-only!!")); - return FALSE; + return false; } bool wxIFFHandler::DoCanRead(wxInputStream& stream) { - wxIFFDecoder *decod; - bool ok; + wxIFFDecoder decod(&stream); - decod = new wxIFFDecoder(&stream); - ok = decod->CanRead(); - delete decod; - - return ok; + return decod.CanRead(); } #endif // wxUSE_STREAMS