Fix compression for fbx

This commit is contained in:
Kim Kulling
2022-02-12 09:25:45 +01:00
parent 23b43d1825
commit 3e09d462fa
7 changed files with 88 additions and 55 deletions
+16 -25
View File
@@ -4,7 +4,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2022, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
@@ -48,10 +47,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
#include "Common/Compression.h"
/*# include <zlib.h>
#else
# include "../contrib/zlib/zlib.h"
#endif*/
//# include <zlib.h>
//#else
//# include "../contrib/zlib/zlib.h"
//#endif
#include "FBXTokenizer.h"
#include "FBXParser.h"
@@ -116,9 +115,7 @@ namespace Assimp {
namespace FBX {
// ------------------------------------------------------------------------------------------------
Element::Element(const Token& key_token, Parser& parser)
: key_token(key_token)
{
Element::Element(const Token& key_token, Parser& parser) : key_token(key_token) {
TokenPtr n = nullptr;
do {
n = parser.AdvanceToNextToken();
@@ -211,8 +208,7 @@ Scope::Scope(Parser& parser,bool topLevel)
}
// ------------------------------------------------------------------------------------------------
Scope::~Scope()
{
Scope::~Scope() {
for(ElementMap::value_type& v : elements) {
delete v.second;
}
@@ -528,9 +524,7 @@ void ReadBinaryDataArrayHead(const char*& data, const char* end, char& type, uin
// ------------------------------------------------------------------------------------------------
// read binary data array, assume cursor points to the 'compression mode' field (i.e. behind the header)
void ReadBinaryDataArray(char type, uint32_t count, const char*& data, const char* end,
std::vector<char>& buff,
const Element& /*el*/)
{
std::vector<char>& buff, const Element& /*el*/) {
BE_NCONST uint32_t encmode = SafeParse<uint32_t>(data, end);
AI_SWAP4(encmode);
data += 4;
@@ -572,11 +566,12 @@ void ReadBinaryDataArray(char type, uint32_t count, const char*& data, const cha
else if(encmode == 1) {
// 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 compress;
if (compress.open(Compression::Format::Binary, Compression::FlushMode::Finish)) {
compress.decompress(data, comp_len, buff);
compress.close();
}
/* z_stream zstream;
/* z_stream zstream = {};
zstream.opaque = Z_NULL;
zstream.zalloc = Z_NULL;
zstream.zfree = Z_NULL;
@@ -585,9 +580,9 @@ void ReadBinaryDataArray(char type, uint32_t count, const char*& data, const cha
// http://hewgill.com/journal/entries/349-how-to-decompress-gzip-stream-with-zlib
if(Z_OK != inflateInit(&zstream)) {
ParseError("failure initializing zlib");
}*/
}
/* zstream.next_in = reinterpret_cast<Bytef *>(const_cast<char *>(data));
zstream.next_in = reinterpret_cast<Bytef *>(const_cast<char *>(data));
zstream.avail_in = comp_len;
zstream.avail_out = static_cast<uInt>(buff.size());
@@ -705,7 +700,6 @@ void ParseVectorDataArray(std::vector<aiVector3D>& out, const Element& el)
}
}
// ------------------------------------------------------------------------------------------------
// read an array of color4 tuples
void ParseVectorDataArray(std::vector<aiColor4D>& out, const Element& el)
@@ -790,8 +784,7 @@ void ParseVectorDataArray(std::vector<aiColor4D>& out, const Element& el)
// ------------------------------------------------------------------------------------------------
// read an array of float2 tuples
void ParseVectorDataArray(std::vector<aiVector2D>& out, const Element& el)
{
void ParseVectorDataArray(std::vector<aiVector2D>& out, const Element& el) {
out.resize( 0 );
const TokenList& tok = el.Tokens();
if(tok.empty()) {
@@ -835,8 +828,7 @@ void ParseVectorDataArray(std::vector<aiVector2D>& out, const Element& el)
out.push_back(aiVector2D(static_cast<float>(d[0]),
static_cast<float>(d[1])));
}
}
else if (type == 'f') {
} else if (type == 'f') {
const float* f = reinterpret_cast<const float*>(&buff[0]);
for (unsigned int i = 0; i < count2; ++i, f += 2) {
out.push_back(aiVector2D(f[0],f[1]));
@@ -869,8 +861,7 @@ void ParseVectorDataArray(std::vector<aiVector2D>& out, const Element& el)
// ------------------------------------------------------------------------------------------------
// read an array of ints
void ParseVectorDataArray(std::vector<int>& out, const Element& el)
{
void ParseVectorDataArray(std::vector<int>& out, const Element& el) {
out.resize( 0 );
const TokenList& tok = el.Tokens();
if(tok.empty()) {