From 52b6c4f7c098adc84ffee41ef45849cc4d9611c4 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 13 Feb 2022 18:44:22 +0100 Subject: [PATCH] Fix broken importer and add some review findings2 --- code/AssetLib/Blender/BlenderLoader.cpp | 2 +- code/AssetLib/FBX/FBXParser.cpp | 2 +- code/AssetLib/X/XFileParser.cpp | 2 +- code/AssetLib/XGL/XGLLoader.cpp | 2 +- code/Common/Compression.cpp | 13 ++++++------- code/Common/Compression.h | 16 +++++++++++----- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/code/AssetLib/Blender/BlenderLoader.cpp b/code/AssetLib/Blender/BlenderLoader.cpp index 5d3757ca1..c67879be5 100644 --- a/code/AssetLib/Blender/BlenderLoader.cpp +++ b/code/AssetLib/Blender/BlenderLoader.cpp @@ -175,7 +175,7 @@ void BlenderImporter::InternReadFile(const std::string &pFile, size_t total = 0; Compression compression; - if (compression.open(Compression::Format::Binary, Compression::FlushMode::Finish) ) { + if (compression.open(Compression::Format::Binary, Compression::FlushMode::NoFlush, 16 + MAX_WBITS)) { total = compression.decompress((unsigned char *)reader->GetPtr(), reader->GetRemainingSize(), uncompressed); compression.close(); } diff --git a/code/AssetLib/FBX/FBXParser.cpp b/code/AssetLib/FBX/FBXParser.cpp index 2c0ff95b1..c453647e0 100644 --- a/code/AssetLib/FBX/FBXParser.cpp +++ b/code/AssetLib/FBX/FBXParser.cpp @@ -567,7 +567,7 @@ void ReadBinaryDataArray(char type, uint32_t count, const char*& data, const cha // zlib/deflate, next comes ZIP head (0x78 0x01) // see http://www.ietf.org/rfc/rfc1950.txt Compression compress; - if (compress.open(Compression::Format::Binary, Compression::FlushMode::Finish)) { + if (compress.open(Compression::Format::Binary, Compression::FlushMode::Finish,0)) { compress.decompress(data, comp_len, buff); compress.close(); } diff --git a/code/AssetLib/X/XFileParser.cpp b/code/AssetLib/X/XFileParser.cpp index 4731710d7..90a257dfa 100644 --- a/code/AssetLib/X/XFileParser.cpp +++ b/code/AssetLib/X/XFileParser.cpp @@ -188,7 +188,7 @@ XFileParser::XFileParser(const std::vector &pBuffer) : Compression compression; uncompressed.resize(est_out + 1); char *out = &uncompressed.front(); - if (compression.open(mIsBinaryFormat ? Compression::Format::Binary : Compression::Format::ASCII, Compression::FlushMode::SyncFlush)) { + if (compression.open(mIsBinaryFormat ? Compression::Format::Binary : Compression::Format::ASCII, Compression::FlushMode::SyncFlush, -MAX_WBITS)) { while (mP + 3 < mEnd) { uint16_t ofs = *((uint16_t *)mP); AI_SWAP2(ofs); diff --git a/code/AssetLib/XGL/XGLLoader.cpp b/code/AssetLib/XGL/XGLLoader.cpp index 966d547ac..4fbee6eea 100644 --- a/code/AssetLib/XGL/XGLLoader.cpp +++ b/code/AssetLib/XGL/XGLLoader.cpp @@ -132,7 +132,7 @@ void XGLImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy Compression compression; size_t total = 0l; - if (compression.open(Compression::Format::Binary, Compression::FlushMode::NoFlush)) { + if (compression.open(Compression::Format::Binary, Compression::FlushMode::NoFlush, -MAX_WBITS)) { // skip two extra bytes, zgl files do carry a crc16 upfront (I think) raw_reader->IncPtr(2); total = compression.decompress((unsigned char *)raw_reader->GetPtr(), raw_reader->GetRemainingSize(), uncompressed); diff --git a/code/Common/Compression.cpp b/code/Common/Compression.cpp index f6f0db4f4..86f1e9ec0 100644 --- a/code/Common/Compression.cpp +++ b/code/Common/Compression.cpp @@ -43,11 +43,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#ifdef ASSIMP_BUILD_NO_OWN_ZLIB -#include -#else -#include "../contrib/zlib/zlib.h" -#endif namespace Assimp { @@ -73,7 +68,7 @@ Compression::~Compression() { delete mImpl; } -bool Compression::open(Format format, FlushMode flush) { +bool Compression::open(Format format, FlushMode flush, int windowBits) { ai_assert(mImpl != nullptr); if (mImpl->mOpen) { @@ -92,7 +87,11 @@ bool Compression::open(Format format, FlushMode flush) { } // raw decompression without a zlib or gzip header - inflateInit(&mImpl->mZSstream); + if (windowBits == 0) { + inflateInit(&mImpl->mZSstream); + } else { + inflateInit2(&mImpl->mZSstream, windowBits); + } mImpl->mOpen = true; return mImpl->mOpen; diff --git a/code/Common/Compression.h b/code/Common/Compression.h index aa552ab60..05beed7f7 100644 --- a/code/Common/Compression.h +++ b/code/Common/Compression.h @@ -41,6 +41,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma once +#ifdef ASSIMP_BUILD_NO_OWN_ZLIB +#include +#else +#include "../contrib/zlib/zlib.h" +#endif + #include namespace Assimp { @@ -49,20 +55,20 @@ namespace Assimp { class Compression { public: enum class Format { + InvalidFormat = -1, Binary = 0, ASCII, - NumFormats, - InvalidFormat + NumFormats }; enum class FlushMode { + InvalidFormat = -1, NoFlush = 0, SyncFlush, Finish, - NumModes, - InvalidMode + NumModes }; /// @brief The class constructor. @@ -73,7 +79,7 @@ public: /// @brief Will open the access to the compression. /// @return true if close was successful, false if not. - bool open(Format format, FlushMode flush); + bool open(Format format, FlushMode flush, int windowBits); /// @brief Will return the open state. /// @return true if the access is opened, false if not.