From 061911bdbff6ac9613d8daaf202b95ebaf37cac4 Mon Sep 17 00:00:00 2001 From: Gargaj Date: Thu, 7 Aug 2014 08:05:07 +0200 Subject: [PATCH] add support for compressed, drop support for shortened --- code/AssbinLoader.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/code/AssbinLoader.cpp b/code/AssbinLoader.cpp index 1739659b1..9bc9a0a08 100644 --- a/code/AssbinLoader.cpp +++ b/code/AssbinLoader.cpp @@ -51,6 +51,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // internal headers #include "AssbinLoader.h" #include "assbin_chunks.h" +#ifdef ASSIMP_BUILD_NO_OWN_ZLIB +# include +#else +# include "../contrib/zlib/zlib.h" +#include "MemoryIOWrapper.h" +#endif using namespace Assimp; @@ -563,13 +569,31 @@ void AssbinImporter::InternReadFile( const std::string& pFile, aiScene* pScene, shortened = Read(stream) > 0; compressed = Read(stream) > 0; + if (shortened) + throw DeadlyImportError( "Shortened binaries are not supported!" ); + stream->Seek( 256, aiOrigin_CUR ); // original filename stream->Seek( 128, aiOrigin_CUR ); // options stream->Seek( 64, aiOrigin_CUR ); // padding if (compressed) { - // TODO + uLongf uncompressedSize = Read(stream); + uLongf compressedSize = stream->FileSize() - stream->Tell(); + + unsigned char * compressedData = new unsigned char[ compressedSize ]; + stream->Read( compressedData, 1, compressedSize ); + + unsigned char * uncompressedData = new unsigned char[ uncompressedSize ]; + + uncompress( uncompressedData, &uncompressedSize, compressedData, compressedSize ); + + MemoryIOStream io( uncompressedData, uncompressedSize ); + + ReadBinaryScene(&io,pScene); + + delete[] uncompressedData; + delete[] compressedData; } else {