X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b81e45065986abc34676fecc31515efeb3f3a8d4..87f0b1323b7ac77f02133b836c8dfee63b0fd387:/src/common/imagiff.cpp diff --git a/src/common/imagiff.cpp b/src/common/imagiff.cpp index 9fd15214d4..635758c559 100644 --- a/src/common/imagiff.cpp +++ b/src/common/imagiff.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/common/imagiff.h +// Name: src/common/imagiff.cpp // Purpose: wxImage handler for Amiga IFF images // Author: Steffen Gutmann, Thomas Meyer // RCS-ID: $Id$ @@ -81,7 +81,6 @@ private: IFFImage *m_image; // image data wxInputStream *m_f; // input stream unsigned char *databuf; - unsigned char *picptr; unsigned char *decomp_mem; void Destroy(); @@ -98,7 +97,10 @@ public: // constructor, destructor, etc. wxIFFDecoder(wxInputStream *s); ~wxIFFDecoder() { Destroy(); } + + // NOTE: this function modifies the current stream position bool CanRead(); + int ReadIFF(); bool ConvertToImage(wxImage *image) const; }; @@ -118,12 +120,9 @@ wxIFFDecoder::wxIFFDecoder(wxInputStream *s) void wxIFFDecoder::Destroy() { - delete m_image; - m_image = 0; - delete [] databuf; - databuf = 0; - delete [] decomp_mem; - decomp_mem = 0; + wxDELETE(m_image); + wxDELETEA(databuf); + wxDELETEA(decomp_mem); } //--------------------------------------------------------------------------- @@ -140,7 +139,7 @@ bool wxIFFDecoder::ConvertToImage(wxImage *image) const // create the image image->Create(GetWidth(), GetHeight()); - if (!image->Ok()) + if (!image->IsOk()) return false; unsigned char *pal = GetPalette(); @@ -234,9 +233,6 @@ bool wxIFFDecoder::CanRead() if ( !m_f->Read(buf, WXSIZEOF(buf)) ) return false; - if ( m_f->SeekI(-(wxFileOffset)WXSIZEOF(buf), wxFromCurrent) == wxInvalidOffset ) - return false; - return (memcmp(buf, "FORM", 4) == 0) && (memcmp(buf+8, "ILBM", 4) == 0); } @@ -379,7 +375,7 @@ int wxIFFDecoder::ReadIFF() return wxIFF_INVFORMAT; } - wxLogTrace(_T("iff"), _T("IFF ILBM file recognized")); + wxLogTrace(wxT("iff"), wxT("IFF ILBM file recognized")); dataptr = dataptr + 4; // skip ID @@ -420,8 +416,7 @@ int wxIFFDecoder::ReadIFF() const byte *cmapptr = dataptr + 8; colors = chunkLen / 3; // calc no of colors - delete m_image->pal; - m_image->pal = 0; + wxDELETE(m_image->pal); m_image->colors = colors; if (colors > 0) { m_image->pal = new byte[3*colors]; @@ -438,7 +433,7 @@ int wxIFFDecoder::ReadIFF() } } - wxLogTrace(_T("iff"), _T("Read %d colors from IFF file."), + wxLogTrace(wxT("iff"), wxT("Read %d colors from IFF file."), colors); dataptr += 8 + chunkLen; // to next chunk @@ -479,8 +474,7 @@ int wxIFFDecoder::ReadIFF() decomprle(bodyptr, decomp_mem, chunkLen, decomp_bufsize); bodyptr = decomp_mem; // -> uncompressed BODY chunkLen = decomp_bufsize; - delete [] databuf; - databuf = 0; + wxDELETEA(databuf); } // the following determines the type of the ILBM file. @@ -501,8 +495,8 @@ int wxIFFDecoder::ReadIFF() } } - wxLogTrace(_T("iff"), - _T("LoadIFF: %s %dx%d, planes=%d (%d cols), comp=%d"), + wxLogTrace(wxT("iff"), + wxT("LoadIFF: %s %dx%d, planes=%d (%d cols), comp=%d"), (fmt==ILBM_NORMAL) ? "Normal ILBM" : (fmt==ILBM_HAM) ? "HAM ILBM" : (fmt==ILBM_HAM8) ? "HAM8 ILBM" : @@ -512,8 +506,8 @@ int wxIFFDecoder::ReadIFF() 1<p = new byte[bmhd_width * bmhd_height * 3]; - byte *picptr = m_image->p; + byte *picptr = m_image->p; if (!picptr) { Destroy(); return wxIFF_MEMERR; @@ -647,7 +641,7 @@ int wxIFFDecoder::ReadIFF() } } else if ((fmt == ILBM_NORMAL) || (fmt == ILBM_EHB)) { if (fmt == ILBM_EHB) { - wxLogTrace(_T("iff"), _T("Doubling CMAP for EHB mode")); + wxLogTrace(wxT("iff"), wxT("Doubling CMAP for EHB mode")); for (int i=0; i<32; i++) { pal[3*(i + 32) + 0] = pal[3*i + 0] >> 1; @@ -704,12 +698,12 @@ int wxIFFDecoder::ReadIFF() m_image->h = height; m_image->transparent = bmhd_transcol; - wxLogTrace(_T("iff"), _T("Loaded IFF picture %s"), + wxLogTrace(wxT("iff"), wxT("Loaded IFF picture %s"), truncated? "truncated" : "completely"); return (truncated? wxIFF_TRUNCATED : wxIFF_OK); } else { - wxLogTrace(_T("iff"), _T("Skipping unknown chunk '%c%c%c%c'"), + wxLogTrace(wxT("iff"), wxT("Skipping unknown chunk '%c%c%c%c'"), *dataptr, *(dataptr+1), *(dataptr+2), *(dataptr+3)); dataptr = dataptr + 8 + chunkLen; // skip unknown chunk @@ -777,7 +771,9 @@ bool wxIFFHandler::SaveFile(wxImage * WXUNUSED(image), wxOutputStream& WXUNUSED(stream), bool verbose) { if (verbose) + { wxLogDebug(wxT("IFF: the handler is read-only!!")); + } return false; } @@ -787,6 +783,7 @@ bool wxIFFHandler::DoCanRead(wxInputStream& stream) wxIFFDecoder decod(&stream); return decod.CanRead(); + // it's ok to modify the stream position here } #endif // wxUSE_STREAMS