// Purpose: wxImage handler for Amiga IFF images
// Author: Steffen Gutmann, Thomas Meyer
// RCS-ID: $Id$
// Purpose: wxImage handler for Amiga IFF images
// Author: Steffen Gutmann, Thomas Meyer
// RCS-ID: $Id$
// by the author of xv, John Bradley for using the iff loading part
// in wxWidgets has been gratefully given.
// by the author of xv, John Bradley for using the iff loading part
// in wxWidgets has been gratefully given.
// constructor, destructor, etc.
wxIFFDecoder(wxInputStream *s);
~wxIFFDecoder() { Destroy(); }
// constructor, destructor, etc.
wxIFFDecoder(wxInputStream *s);
~wxIFFDecoder() { Destroy(); }
return (memcmp(buf, "FORM", 4) == 0) && (memcmp(buf+8, "ILBM", 4) == 0);
}
return (memcmp(buf, "FORM", 4) == 0) && (memcmp(buf+8, "ILBM", 4) == 0);
}
- void decomprle(source, destination, source length, buffer size)
+void decomprle(source, destination, source length, buffer size)
- Decompress run-length encoded data from source to destination. Terminates
- when source is decoded completely or destination buffer is full.
+Decompress run-length encoded data from source to destination. Terminates
+when source is decoded completely or destination buffer is full.
- The decruncher is as optimized as I could make it, without risking
- safety in case of corrupt BODY chunks.
+The decruncher is as optimized as I could make it, without risking
+safety in case of corrupt BODY chunks.
**************************************************************************/
static void decomprle(const byte *sptr, byte *dptr, long slen, long dlen)
**************************************************************************/
static void decomprle(const byte *sptr, byte *dptr, long slen, long dlen)
- off_t currentPos = m_f->TellI();
- m_f->SeekI(0, wxFromEnd);
+ wxFileOffset currentPos = m_f->TellI();
+ if (m_f->SeekI(0, wxFromEnd) == wxInvalidOffset) {
+ Destroy();
+ return wxIFF_MEMERR;
+ }
+
}
// check if we really got an IFF file
if (strncmp((char *)dataptr, "FORM", 4) != 0) {
}
// check if we really got an IFF file
if (strncmp((char *)dataptr, "FORM", 4) != 0) {
}
dataptr = dataptr + 8; // skip ID and length of FORM
// check if the IFF file is an ILBM (picture) file
if (strncmp((char *) dataptr, "ILBM", 4) != 0) {
}
dataptr = dataptr + 8; // skip ID and length of FORM
// check if the IFF file is an ILBM (picture) file
if (strncmp((char *) dataptr, "ILBM", 4) != 0) {
// main decoding loop. searches IFF chunks and handles them.
// terminates when BODY chunk was found or dataptr ran over end of file
//
// main decoding loop. searches IFF chunks and handles them.
// terminates when BODY chunk was found or dataptr ran over end of file
//
int bmhd_width = 0, bmhd_height = 0, bmhd_bitplanes = 0, bmhd_transcol = -1;
int bmhd_width = 0, bmhd_height = 0, bmhd_bitplanes = 0, bmhd_transcol = -1;
- size_t chunkLen = (iff_getlong(dataptr + 4) + 1) & 0xfffffffe;
-#ifdef __VMS
- // Silence compiler warning
- int chunkLen_;
- chunkLen_ = chunkLen;
- if (chunkLen_ < 0) { // format error?
-#else
- if (chunkLen < 0) { // format error?
-#endif
- break;
+ long chunkLen = (iff_getlong(dataptr + 4) + 1) & 0xfffffffe;
+ if (chunkLen < 0) { // format error?
+ break;
bmhd_width = iff_getword(dataptr + 8); // width of picture
bmhd_height= iff_getword(dataptr + 8 + 2); // height of picture
bmhd_bitplanes = *(dataptr + 8 + 8); // # of bitplanes
bmhd_width = iff_getword(dataptr + 8); // width of picture
bmhd_height= iff_getword(dataptr + 8 + 2); // height of picture
bmhd_bitplanes = *(dataptr + 8 + 8); // # of bitplanes
bmhd_compression = *(dataptr + 8 + 10); // get compression
bmhd_transcol = iff_getword(dataptr + 8 + 12);
BMHDok = true; // got BMHD
bmhd_compression = *(dataptr + 8 + 10); // get compression
bmhd_transcol = iff_getword(dataptr + 8 + 12);
BMHDok = true; // got BMHD
dataptr += 8 + chunkLen; // to next chunk
} else if (strncmp((char *)dataptr, "CAMG", 4) == 0) { // CAMG ?
if (chunkLen < 4 || truncated) {
dataptr += 8 + chunkLen; // to next chunk
} else if (strncmp((char *)dataptr, "CAMG", 4) == 0) { // CAMG ?
if (chunkLen < 4 || truncated) {
decomprle(bodyptr, decomp_mem, chunkLen, decomp_bufsize);
bodyptr = decomp_mem; // -> uncompressed BODY
chunkLen = decomp_bufsize;
decomprle(bodyptr, decomp_mem, chunkLen, decomp_bufsize);
bodyptr = decomp_mem; // -> uncompressed BODY
chunkLen = decomp_bufsize;
- 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" :
(fmt==ILBM_NORMAL) ? "Normal ILBM" :
(fmt==ILBM_HAM) ? "HAM ILBM" :
(fmt==ILBM_HAM8) ? "HAM8 ILBM" :
1<<bmhd_bitplanes, bmhd_compression);
if ((fmt==ILBM_NORMAL) || (fmt==ILBM_EHB) || (fmt==ILBM_HAM)) {
1<<bmhd_bitplanes, bmhd_compression);
if ((fmt==ILBM_NORMAL) || (fmt==ILBM_EHB) || (fmt==ILBM_HAM)) {
*dataptr, *(dataptr+1), *(dataptr+2), *(dataptr+3));
dataptr = dataptr + 8 + chunkLen; // skip unknown chunk
*dataptr, *(dataptr+1), *(dataptr+2), *(dataptr+3));
dataptr = dataptr + 8 + chunkLen; // skip unknown chunk