From: <sag...@us...> - 2009-10-10 00:03:47
|
Revision: 393 http://modplug.svn.sourceforge.net/modplug/?rev=393&view=rev Author: saga-games Date: 2009-10-10 00:03:35 +0000 (Sat, 10 Oct 2009) Log Message: ----------- [Imp] Added *.j2b to format filter in the "open" dialog [Ref] Minor rewriting of the j2b loader Modified Paths: -------------- trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/soundlib/Load_gdm.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/load_j2b.cpp Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2009-10-09 21:12:52 UTC (rev 392) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2009-10-10 00:03:35 UTC (rev 393) @@ -1390,13 +1390,20 @@ OFN_HIDEREADONLY | OFN_ENABLESIZING | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_FORCESHOWHIDDEN | OFN_ALLOWMULTISELECT, // -> CODE#0023 // -> DESC="IT project files (.itp)" + "All Modules|*.mod;*.nst;*.wow;*.s3m;*.stm;*.669;*.mtm;*.xm;*.it;*.itp;*.mptm;*.ult;*.mdz;*.s3z;*.xmz;*.itz;mod.*;*.far;*.mdl;*.okt;*.dmf;*.ptm;*.mdr;*.med;*.ams;*.dbm;*.dsm;*.mid;*.rmi;*.smf;*.umx;*.amf;*.psm;*.mt2;*.gdm;*.imf;*.j2b" #ifndef NO_MO3_SUPPORT - "All Modules|*.mod;*.nst;*.wow;*.s3m;*.stm;*.669;*.mtm;*.xm;*.it;*.itp;*.mptm;*.ult;*.mdz;*.s3z;*.xmz;*.itz;mod.*;*.far;*.mdl;*.okt;*.dmf;*.ptm;*.mdr;*.med;*.ams;*.dbm;*.dsm;*.mid;*.rmi;*.smf;*.umx;*.amf;*.psm;*.mt2;*.gdm;*.imf;*.mo3|" - "Compressed Modules (*.mdz;*.s3z;*.xmz;*.itz;*.mo3)|*.mdz;*.s3z;*.xmz;*.itz;*.mdr;*.zip;*.rar;*.lha;*.mo3|" - #else - "All Modules|*.mod;*.nst;*.wow;*.s3m;*.stm;*.669;*.mtm;*.xm;*.it;*.itp;*.mptm;*.ult;*.mdz;*.s3z;*.xmz;*.itz;mod.*;*.far;*.mdl;*.okt;*.dmf;*.ptm;*.mdr;*.med;*.ams;*.dbm;*.dsm;*.mid;*.rmi;*.smf;*.umx;*.amf;*.psm;*.mt2;*.gdm;*.imf|" - "Compressed Modules (*.mdz;*.s3z;*.xmz;*.itz)|*.mdz;*.s3z;*.xmz;*.itz;*.mdr;*.zip;*.rar;*.lha|" + ";*.mo3" #endif + "|" + "Compressed Modules (*.mdz;*.s3z;*.xmz;*.itz" + #ifndef NO_MO3_SUPPORT + ";*.mo3" + #endif + ")|*.mdz;*.s3z;*.xmz;*.itz;*.mdr;*.zip;*.rar;*.lha" + #ifndef NO_MO3_SUPPORT + ";*.mo3" + #endif + "|" // -! NEW_FEATURE#0023 "ProTracker Modules (*.mod,*.nst)|*.mod;mod.*;*.mdz;*.nst;*.m15|" "ScreamTracker Modules (*.s3m,*.stm)|*.s3m;*.stm;*.s3z|" @@ -1407,7 +1414,7 @@ "Impulse Tracker Projects (*.itp)|*.itp;*.itpz|" // -! NEW_FEATURE#0023 "OpenMPT Modules (*.mptm)|*.mptm;*.mptmz|" - "Other Modules (mtm,okt,mdl,669,far,...)|*.mtm;*.669;*.ult;*.wow;*.far;*.mdl;*.okt;*.dmf;*.ptm;*.med;*.ams;*.dbm;*.dsm;*.umx;*.amf;*.psm;*.mt2;*.gdm;*.imf|" + "Other Modules (mtm,okt,mdl,669,far,...)|*.mtm;*.669;*.ult;*.wow;*.far;*.mdl;*.okt;*.dmf;*.ptm;*.med;*.ams;*.dbm;*.dsm;*.umx;*.amf;*.psm;*.mt2;*.gdm;*.imf;*.j2b|" "Wave Files (*.wav)|*.wav|" "Midi Files (*.mid,*.rmi)|*.mid;*.rmi;*.smf|" "All Files (*.*)|*.*||", Modified: trunk/OpenMPT/soundlib/Load_gdm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_gdm.cpp 2009-10-09 21:12:52 UTC (rev 392) +++ trunk/OpenMPT/soundlib/Load_gdm.cpp 2009-10-10 00:03:35 UTC (rev 393) @@ -275,7 +275,7 @@ // read patterns Patterns.ResizeArray(max(MAX_PATTERNS, pHeader->NOP + 1)); - BOOL bS3MCommandSet = (GetBestSaveFormat() & (MOD_TYPE_S3M | MOD_TYPE_IT | MOD_TYPE_MPT)); + bool bS3MCommandSet = (GetBestSaveFormat() & (MOD_TYPE_S3M | MOD_TYPE_IT | MOD_TYPE_MPT)) != 0 ? true : false; // we'll start at position iPatternsOffset and decode all patterns for (PATTERNINDEX iPat = 0; iPat < pHeader->NOP + 1; iPat++) Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2009-10-09 21:12:52 UTC (rev 392) +++ trunk/OpenMPT/soundlib/Sndfile.h 2009-10-10 00:03:35 UTC (rev 393) @@ -708,7 +708,7 @@ bool ReadMID(LPCBYTE lpStream, DWORD dwMemLength); void SetupMODPanning(bool bForceSetup = false); // Setup LRRL panning, max channel volume - bool Convert_RIFF_AM_Pattern(PATTERNINDEX nPat, const LPCBYTE lpStream, DWORD dwMemLength, bool bIsAM); + bool Convert_RIFF_AM_Pattern(PATTERNINDEX nPat, const LPCBYTE lpStream, DWORD dwMemLength, bool bIsAM); // used by ReadAM(...) to convert AM(FF) patterns // Save Functions #ifndef MODPLUG_NO_FILESAVE Modified: trunk/OpenMPT/soundlib/load_j2b.cpp =================================================================== --- trunk/OpenMPT/soundlib/load_j2b.cpp 2009-10-09 21:12:52 UTC (rev 392) +++ trunk/OpenMPT/soundlib/load_j2b.cpp 2009-10-10 00:03:35 UTC (rev 393) @@ -1,9 +1,9 @@ /* - * Purpose: Load RIFF AM and RIFF AMFF modules. - * Note: J2B is a compressed variant of RIFF AM and RIFF AMFF files used in Jazz Jackrabbit 2 - * Authors: Johannes Schultz - * Chris Moeller (foo_dumb) - * Luigi Elettrico (J2B To IT Convertor Class) + * Purpose: Load RIFF AM and RIFF AMFF modules (Galaxy Sound System). + * Note: J2B is a compressed variant of RIFF AM and RIFF AMFF files used in Jazz Jackrabbit 2. + * It seems like no other game used the AM(FF) format. + * Authors: Johannes Schultz (OpenMPT port) + * Chris Moeller (foo_dumb - this is almost a complete port of his code, thanks) * */ @@ -17,12 +17,12 @@ // header for compressed j2b files struct J2BHEADER { - DWORD signature; // MUSE - DWORD deadbeaf; // 0xDEADBEAF or 0xDEADBABE - DWORD j2blength; - DWORD crc32; - DWORD packed_length; - DWORD unpacked_length; + DWORD signature; // MUSE + DWORD deadbeaf; // 0xDEADBEAF (AM) or 0xDEADBABE (AMFF) + DWORD j2blength; // complete filesize + DWORD crc32; // checksum of the compressed data block + DWORD packed_length; // length of the compressed data block + DWORD unpacked_length; // length of the decompressed module }; // am(ff) stuff @@ -97,7 +97,7 @@ bool CSoundFile::Convert_RIFF_AM_Pattern(PATTERNINDEX nPat, const LPCBYTE lpStream, DWORD dwMemLength, bool bIsAM) //---------------------------------------------------------------------------------------------------------------- { - // version 0 = AMFF, else = AM + // version false = AMFF, true = AM #define ASSERT_CAN_READ(x) \ if( dwMemPos > dwMemLength || x > dwMemLength - dwMemPos ) return false; @@ -252,7 +252,6 @@ ASSERT_CAN_READ(LittleEndian(chunkheader->chunksize)); DWORD dwChunkEnd = dwMemPos + LittleEndian(chunkheader->chunksize); - if(bIsAM && (LittleEndian(chunkheader->chunksize) & 1)) dwChunkEnd++; switch(LittleEndian(chunkheader->signature)) { @@ -437,6 +436,8 @@ } dwMemPos = dwChunkEnd; + // RIFF AM has a padding byte + if(bIsAM && (LittleEndian(chunkheader->chunksize) & 1)) dwMemPos++; } return true; @@ -468,36 +469,16 @@ dwMemPos += sizeof(J2BHEADER); // header is valid, now unpack the RIFF AM file using inflate - z_stream strm; - strm.zalloc = Z_NULL; - strm.zfree = Z_NULL; - strm.opaque = Z_NULL; - strm.avail_in = 0; - strm.next_in = Z_NULL; - if(inflateInit(&strm) != Z_OK) - return false; + DWORD destSize = LittleEndian(header->unpacked_length); + Bytef *bOutput = new Bytef[destSize]; + int nRetVal = uncompress(bOutput, &destSize, &lpStream[dwMemPos], LittleEndian(header->unpacked_length)); - Bytef* bOutput = new Bytef[LittleEndian(header->unpacked_length) + 1]; - - strm.avail_in = dwMemLength - dwMemPos; - strm.next_in = (Bytef *)(lpStream + dwMemPos); - strm.avail_out = LittleEndian(header->unpacked_length); - strm.next_out = bOutput; - - int nRetVal = inflate(&strm, Z_NO_FLUSH); - (void)inflateEnd(&strm); - - if(strm.avail_in != 0 || nRetVal == Z_STREAM_ERROR || nRetVal == Z_NEED_DICT || nRetVal == Z_DATA_ERROR || nRetVal == Z_MEM_ERROR || nRetVal != Z_STREAM_END) - { - return false; - } - bool bResult = false; - if(strm.total_out == LittleEndian(header->unpacked_length)) + if(destSize == LittleEndian(header->unpacked_length) && nRetVal == Z_OK) { // Success, now load the RIFF AM(FF) module. - bResult = ReadAM(bOutput, strm.total_out); + bResult = ReadAM(bOutput, destSize); } delete[] bOutput; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |