X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/63f8abca79edfcf92641b21b0a16687ac84d152b..f8d791e0a41f1021a69c3d6320ee6934c0dd7f36:/src/common/imagiff.cpp diff --git a/src/common/imagiff.cpp b/src/common/imagiff.cpp index bd6fb87cfe..e852c4f645 100644 --- a/src/common/imagiff.cpp +++ b/src/common/imagiff.cpp @@ -1,14 +1,16 @@ ///////////////////////////////////////////////////////////////////////////// // Name: 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. +// 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 wxWindows has been gratefully given. #ifdef __GNUG__ #pragma implementation "imagiff.h" @@ -79,8 +81,8 @@ class WXDLLEXPORT wxIFFDecoder private: IFFImage *m_image; // image data wxInputStream *m_f; // input stream - unsigned char *databuf; - unsigned char *picptr; + unsigned char *databuf; + unsigned char *picptr; unsigned char *decomp_mem; void Destroy(); @@ -228,12 +230,14 @@ int wxIFFDecoder::GetTransparentColour() const { return m_image->transparent; } // bool wxIFFDecoder::CanRead() { - unsigned char buf[12] = ""; + unsigned char buf[12]; - m_f->Read(buf, 12); - m_f->SeekI(-12, wxFromCurrent); + if ( !m_f->Read(buf, WXSIZEOF(buf)) ) + return FALSE; + + m_f->SeekI(-(off_t)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); } @@ -376,7 +380,7 @@ int wxIFFDecoder::ReadIFF() // main decoding loop. searches IFF chunks and handles them. // terminates when BODY chunk was found or dataptr ran over end of file // - bool BMHDok = false, CMAPok = false, CAMGok = false; + bool BMHDok = FALSE, CMAPok = FALSE, CAMGok = FALSE; int bmhd_width = 0, bmhd_height = 0, bmhd_bitplanes = 0, bmhd_transcol = -1; byte bmhd_masking = 0, bmhd_compression = 0; long camg_viewmode = 0; @@ -406,7 +410,7 @@ int wxIFFDecoder::ReadIFF() bmhd_masking = *(dataptr + 8 + 9); bmhd_compression = *(dataptr + 8 + 10); // get compression bmhd_transcol = iff_getword(dataptr + 8 + 12); - BMHDok = true; // got BMHD + BMHDok = TRUE; // got BMHD dataptr += 8 + chunkLen; // to next chunk } else if (strncmp((char *)dataptr, "CMAP", 4) == 0) { // CMAP ? @@ -437,14 +441,14 @@ int wxIFFDecoder::ReadIFF() wxLogTrace(_T("iff"), _T("Read %d colors from IFF file."), colors); - CMAPok = true; // got CMAP + CMAPok = TRUE; // got CMAP dataptr += 8 + chunkLen; // to next chunk } else if (strncmp((char *)dataptr, "CAMG", 4) == 0) { // CAMG ? if (chunkLen < 4 || truncated) { break; } camg_viewmode = iff_getlong(dataptr + 8); // get viewmodes - CAMGok = true; // got CAMG + CAMGok = TRUE; // got CAMG dataptr += 8 + chunkLen; // to next chunk } else if (strncmp((char *)dataptr, "BODY", 4) == 0) { // BODY ? @@ -727,7 +731,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; @@ -781,14 +785,9 @@ bool wxIFFHandler::SaveFile(wxImage * WXUNUSED(image), 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