Skip to content

Commit 34a6828

Browse files
committed
(Assimp) Ability to disable zlib usage.
1 parent 1a3d5a3 commit 34a6828

4 files changed

Lines changed: 52 additions & 14 deletions

File tree

code/AssetLib/Assbin/AssbinFileWriter.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5050
#include <assimp/version.h>
5151
#include <assimp/IOStream.hpp>
5252

53-
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
54-
#include <zlib.h>
55-
#else
56-
#include "../contrib/zlib/zlib.h"
53+
#ifndef ASSIMP_BUILD_DISABLE_ZLIB
54+
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
55+
#include <zlib.h>
56+
#else
57+
#include "../contrib/zlib/zlib.h"
58+
#endif
5759
#endif
5860

5961
#include <ctime>
@@ -795,6 +797,7 @@ class AssbinFileWriter {
795797
// Up to here the data is uncompressed. For compressed files, the rest
796798
// is compressed using standard DEFLATE from zlib.
797799
if (compressed) {
800+
#ifndef ASSIMP_BUILD_DISABLE_ZLIB
798801
AssbinChunkWriter uncompressedStream(nullptr, 0);
799802
WriteBinaryScene(&uncompressedStream, pScene);
800803

@@ -812,6 +815,7 @@ class AssbinFileWriter {
812815
out->Write(compressedBuffer, sizeof(char), compressedSize);
813816

814817
delete[] compressedBuffer;
818+
#endif
815819
} else {
816820
WriteBinaryScene(out, pScene);
817821
}

code/AssetLib/Assxml/AssxmlFileWriter.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5555

5656
#include <stdarg.h>
5757

58-
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
59-
#include <zlib.h>
60-
#else
61-
#include <contrib/zlib/zlib.h>
58+
#ifndef ASSIMP_BUILD_DISABLE_ZLIB
59+
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
60+
#include <zlib.h>
61+
#else
62+
#include <contrib/zlib/zlib.h>
63+
#endif
6264
#endif
6365

6466
#include <stdio.h>

code/Common/Compression.cpp

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,18 @@ namespace Assimp {
4747

4848
struct Compression::impl {
4949
bool mOpen;
50+
51+
#ifndef ASSIMP_BUILD_DISABLE_ZLIB
5052
z_stream mZSstream;
53+
#endif
54+
5155
FlushMode mFlushMode;
5256

5357
impl() :
5458
mOpen(false),
59+
#ifndef ASSIMP_BUILD_DISABLE_ZLIB
5560
mZSstream(),
61+
#endif
5662
mFlushMode(Compression::FlushMode::NoFlush) {
5763
// empty
5864
}
@@ -70,6 +76,7 @@ Compression::~Compression() {
7076
}
7177

7278
bool Compression::open(Format format, FlushMode flush, int windowBits) {
79+
#ifndef ASSIMP_BUILD_DISABLE_ZLIB
7380
ai_assert(mImpl != nullptr);
7481

7582
if (mImpl->mOpen) {
@@ -96,8 +103,15 @@ bool Compression::open(Format format, FlushMode flush, int windowBits) {
96103
mImpl->mOpen = true;
97104

98105
return mImpl->mOpen;
106+
#else
107+
(void(format));
108+
(void(flush));
109+
(void(windowBits));
110+
return false;
111+
#endif
99112
}
100113

114+
#ifndef ASSIMP_BUILD_DISABLE_ZLIB
101115
static int getFlushMode(Compression::FlushMode flush) {
102116
int z_flush = 0;
103117
switch (flush) {
@@ -120,9 +134,9 @@ static int getFlushMode(Compression::FlushMode flush) {
120134
ai_assert(false);
121135
break;
122136
}
123-
124137
return z_flush;
125138
}
139+
#endif
126140

127141
constexpr size_t MYBLOCK = 32786;
128142

@@ -132,11 +146,13 @@ size_t Compression::decompress(const void *data, size_t in, std::vector<char> &u
132146
return 0l;
133147
}
134148

149+
#ifndef ASSIMP_BUILD_DISABLE_ZLIB
135150
mImpl->mZSstream.next_in = (Bytef*)(data);
136151
mImpl->mZSstream.avail_in = (uInt)in;
137152

138153
int ret = 0;
139154
size_t total = 0l;
155+
140156
const int flushMode = getFlushMode(mImpl->mFlushMode);
141157
if (flushMode == Z_FINISH) {
142158
mImpl->mZSstream.avail_out = static_cast<uInt>(uncompressed.size());
@@ -164,8 +180,11 @@ size_t Compression::decompress(const void *data, size_t in, std::vector<char> &u
164180
::memcpy(uncompressed.data() + total - have, block, have);
165181
} while (ret != Z_STREAM_END);
166182
}
167-
168183
return total;
184+
#else
185+
(void(uncompressed));
186+
return 0l;
187+
#endif
169188
}
170189

171190
size_t Compression::decompressBlock(const void *data, size_t in, char *out, size_t availableOut) {
@@ -174,6 +193,7 @@ size_t Compression::decompressBlock(const void *data, size_t in, char *out, size
174193
return 0l;
175194
}
176195

196+
#ifndef ASSIMP_BUILD_DISABLE_ZLIB
177197
// push data to the stream
178198
mImpl->mZSstream.next_in = (Bytef *)data;
179199
mImpl->mZSstream.avail_in = (uInt)in;
@@ -190,6 +210,9 @@ size_t Compression::decompressBlock(const void *data, size_t in, char *out, size
190210
::inflateSetDictionary(&mImpl->mZSstream, (const Bytef *)out, (uInt)availableOut - mImpl->mZSstream.avail_out);
191211

192212
return availableOut - (size_t)mImpl->mZSstream.avail_out;
213+
#else
214+
return 0;
215+
#endif
193216
}
194217

195218
bool Compression::isOpen() const {
@@ -205,7 +228,10 @@ bool Compression::close() {
205228
return false;
206229
}
207230

231+
#ifndef ASSIMP_BUILD_DISABLE_ZLIB
208232
inflateEnd(&mImpl->mZSstream);
233+
#endif
234+
209235
mImpl->mOpen = false;
210236

211237
return true;

code/Common/Compression.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4141

4242
#pragma once
4343

44-
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
45-
# include <zlib.h>
46-
#else
47-
# include "../contrib/zlib/zlib.h"
44+
#ifndef ASSIMP_BUILD_DISABLE_ZLIB
45+
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
46+
# include <zlib.h>
47+
#else
48+
# include "../contrib/zlib/zlib.h"
49+
#endif
4850
#endif
4951

5052
#include <vector>
@@ -55,7 +57,11 @@ namespace Assimp {
5557
/// @brief This class provides the decompression of zlib-compressed data.
5658
class Compression {
5759
public:
60+
#ifndef ASSIMP_BUILD_DISABLE_ZLIB
5861
static const int MaxWBits = MAX_WBITS;
62+
#else
63+
static const int MaxWBits = 0;
64+
#endif
5965

6066
/// @brief Describes the format data type
6167
enum class Format {

0 commit comments

Comments
 (0)