diff options
author | Ferenc Arn <tagcup@yahoo.com> | 2017-06-08 20:43:56 -0500 |
---|---|---|
committer | Ferenc Arn <tagcup@yahoo.com> | 2017-06-08 23:48:14 -0500 |
commit | f177c1534757973063f244450df063def879d7db (patch) | |
tree | f92cf1c822d71acfe5e56ea42b80018abe0e0117 /core/io | |
parent | 01ed55987c4c044191e50ecc94c277b97962ffc7 (diff) |
Add zstd compression support.
zstd has much better compression speed and ratio, and better decompression speed than currently available methods.
Also set zstd as the default compression method for Compression as well as FileAccessCompressed functions.
Diffstat (limited to 'core/io')
-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 |
4 files changed, 23 insertions, 6 deletions
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); |