diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-06-11 18:41:56 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-11 18:41:56 -0300 |
commit | 12b2652ecbe4acfe1a0391b162629cb2a86c1a0b (patch) | |
tree | 75d6a21525b8e75fe56b099465f62e2c77772831 /core | |
parent | 61c82f4356624c175378fd7a3640b37348f66359 (diff) | |
parent | f177c1534757973063f244450df063def879d7db (diff) |
Merge pull request #9104 from tagcup/zstd
Add zstd compression support.
Diffstat (limited to 'core')
-rw-r--r-- | core/SCsub | 21 | ||||
-rw-r--r-- | core/io/compression.cpp | 16 | ||||
-rw-r--r-- | core/io/compression.h | 9 | ||||
-rw-r--r-- | core/io/file_access_compressed.cpp | 2 | ||||
-rw-r--r-- | core/io/file_access_compressed.h | 2 |
5 files changed, 43 insertions, 7 deletions
diff --git a/core/SCsub b/core/SCsub index fd3f57dd7c..da2403f1d3 100644 --- a/core/SCsub +++ b/core/SCsub @@ -83,6 +83,25 @@ thirdparty_minizip_sources = [ thirdparty_minizip_sources = [thirdparty_minizip_dir + file for file in thirdparty_minizip_sources] env.add_source_files(env.core_sources, thirdparty_minizip_sources) +thirdparty_zstd_dir = "#thirdparty/zstd/" +thirdparty_zstd_sources = [ + "common/entropy_common.c", + "common/error_private.c", + "common/fse_decompress.c", + "common/pool.c", + "common/threading.c", + "common/xxhash.c", + "common/zstd_common.c", + "compress/fse_compress.c", + "compress/huf_compress.c", + "compress/zstd_compress.c", + "compress/zstdmt_compress.c", + "decompress/huf_decompress.c", + "decompress/zstd_decompress.c", +] +thirdparty_zstd_sources = [thirdparty_zstd_dir + file for file in thirdparty_zstd_sources] +env.add_source_files(env.core_sources, thirdparty_zstd_sources) + # Godot's own sources env.add_source_files(env.core_sources, "*.cpp") @@ -104,5 +123,5 @@ SConscript('helper/SCsub') # Build it all as a library lib = env.Library("core", env.core_sources) env.Prepend(LIBS=[lib]) - +env.Append(CPPPATH=["#thirdparty/zstd", "#thirdparty/zstd/common"]) Export('env') diff --git a/core/io/compression.cpp b/core/io/compression.cpp index 662411a62e..9c3e0e8eca 100644 --- a/core/io/compression.cpp +++ b/core/io/compression.cpp @@ -33,9 +33,12 @@ #include "zip_io.h" #include "thirdparty/misc/fastlz.h" +#include "thirdparty/zstd/zstd.h" #include <zlib.h> +#define ZSTD_DEFAULT_COMPRESSION 3 + int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode) { switch (p_mode) { @@ -76,6 +79,11 @@ int Compression::compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, return aout; } break; + case MODE_ZSTD: { + + int max_dst_size = get_max_compressed_buffer_size(p_src_size, MODE_ZSTD); + return ZSTD_compress(p_dst, max_dst_size, p_src, p_src_size, ZSTD_DEFAULT_COMPRESSION); + } break; } ERR_FAIL_V(-1); @@ -105,6 +113,10 @@ int Compression::get_max_compressed_buffer_size(int p_src_size, Mode p_mode) { deflateEnd(&strm); return aout; } break; + case MODE_ZSTD: { + + return ZSTD_compressBound(p_src_size); + } break; } ERR_FAIL_V(-1); @@ -148,6 +160,10 @@ int Compression::decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p ERR_FAIL_COND_V(err != Z_STREAM_END, -1); return total; } break; + case MODE_ZSTD: { + + return ZSTD_decompress(p_dst, p_dst_max_size, p_src, p_src_size); + } break; } ERR_FAIL_V(-1); diff --git a/core/io/compression.h b/core/io/compression.h index a982a074b1..742f0f4d68 100644 --- a/core/io/compression.h +++ b/core/io/compression.h @@ -36,12 +36,13 @@ class Compression { public: enum Mode { MODE_FASTLZ, - MODE_DEFLATE + MODE_DEFLATE, + MODE_ZSTD }; - static int compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode = MODE_FASTLZ); - static int get_max_compressed_buffer_size(int p_src_size, Mode p_mode = MODE_FASTLZ); - static int decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size, Mode p_mode = MODE_FASTLZ); + static int compress(uint8_t *p_dst, const uint8_t *p_src, int p_src_size, Mode p_mode = MODE_ZSTD); + static int get_max_compressed_buffer_size(int p_src_size, Mode p_mode = MODE_ZSTD); + static int decompress(uint8_t *p_dst, int p_dst_max_size, const uint8_t *p_src, int p_src_size, Mode p_mode = MODE_ZSTD); Compression(); }; diff --git a/core/io/file_access_compressed.cpp b/core/io/file_access_compressed.cpp index 4c6e8f5507..4e802579c6 100644 --- a/core/io/file_access_compressed.cpp +++ b/core/io/file_access_compressed.cpp @@ -369,7 +369,7 @@ FileAccessCompressed::FileAccessCompressed() { f = NULL; magic = "GCMP"; block_size = 16384; - cmode = Compression::MODE_DEFLATE; + cmode = Compression::MODE_ZSTD; writing = false; write_ptr = 0; write_buffer_size = 0; diff --git a/core/io/file_access_compressed.h b/core/io/file_access_compressed.h index 6af9d9b6ca..340c298a0f 100644 --- a/core/io/file_access_compressed.h +++ b/core/io/file_access_compressed.h @@ -64,7 +64,7 @@ class FileAccessCompressed : public FileAccess { FileAccess *f; public: - void configure(const String &p_magic, Compression::Mode p_mode = Compression::MODE_FASTLZ, int p_block_size = 4096); + void configure(const String &p_magic, Compression::Mode p_mode = Compression::MODE_ZSTD, int p_block_size = 4096); Error open_after_magic(FileAccess *p_base); |