[+] brotli now respects CompressInfo::uCompressionLevel

[+] brotli now respects CompressInfo::uBlockSize
[*] refactored CompressInfo::uLz4BlockSize -> CompressInfo::uBlockSize
[*] zstd decompressor now respects user arguments
[*] zstd compressor now respects user arguments
[*] brotli decompressor now respects user arguments
[*] brotli compressor now respects user arguments
This commit is contained in:
Reece Wilson 2023-07-27 20:45:49 +01:00
parent c084f18c62
commit 3db5554673
7 changed files with 64 additions and 5 deletions

View File

@ -52,7 +52,7 @@ namespace Aurora::Compression
* @brief 64KiB is a recommended "small" block size
* todo: lzma respects this
*/
AuUInt16 uLz4BlockSize {};
AuUInt16 uBlockSize {};
bool bHasWindowbits {true};

View File

@ -36,6 +36,12 @@ namespace Aurora::Compression
return false;
}
if (meta.uCompressionLevel > BROTLI_MAX_QUALITY)
{
SysPushErrorArg("Invalid brotli compression level");
return false;
}
this->pState = BrotliEncoderCreateInstance(nullptr, nullptr, nullptr);
if (!this->pState)
{
@ -43,6 +49,30 @@ namespace Aurora::Compression
return false;
}
if (meta.uBlockSize)
{
if (!BrotliEncoderSetParameter(this->pState, BrotliEncoderParameter::BROTLI_PARAM_LGBLOCK, meta.uBlockSize))
{
SysPushErrorArg("Compressor couldn't set block size");
return false;
}
}
if (!BrotliEncoderSetParameter(this->pState, BrotliEncoderParameter::BROTLI_PARAM_QUALITY, meta.uCompressionLevel))
{
SysPushErrorArg("Compressor couldn't set block size");
return false;
}
for (const auto &[a, b] : meta.options)
{
if (!BrotliEncoderSetParameter(this->pState, (BrotliEncoderParameter)a, b))
{
SysPushErrorArg("Compressor argument assignment {} = {}", a, b);
return false;
}
}
this->InitByDesc(this->meta);
this->SetArray(this->din_);
this->SetOutArray(this->dout_);

View File

@ -44,6 +44,16 @@ namespace Aurora::Compression
return false;
}
for (const auto &[a, b] : meta.options)
{
if (!BrotliDecoderSetParameter(this->pState, (BrotliDecoderParameter)a, b))
{
SysPushErrorArg("Decompressor argument assignment {} = {}", a, b);
return false;
}
}
this->SetArray(this->din_);
this->SetOutArray(this->dout_);
return true;

View File

@ -66,7 +66,7 @@ namespace Aurora::Compression
if (meta.uThreads > 1)
{
lzma_mt options {};
options.block_size = meta.uLz4BlockSize;
options.block_size = meta.uBlockSize;
options.preset = meta.uCompressionLevel;
options.check = check;
options.threads = AuMin(AuHwInfo::GetCPUInfo().uThreads, meta.uThreads);

View File

@ -51,7 +51,7 @@ namespace Aurora::Compression
return false;
}
uRet = ZSTD_CCtx_setParameter(this->cctx_, ZSTD_c_checksumFlag, 1);
uRet = ZSTD_CCtx_setParameter(this->cctx_, ZSTD_c_checksumFlag, meta.bErrorCheck ? 1 : 0);
if (ZSTD_isError(uRet))
{
SysPushErrorGen("Invalid option");
@ -67,6 +67,16 @@ namespace Aurora::Compression
return false;
}
for (const auto &[a, b] : meta.options)
{
uRet = ZSTD_CCtx_setParameter(this->cctx_, (ZSTD_cParameter)a, b);
if (ZSTD_isError(uRet))
{
SysPushErrorArg("Compressor argument assignment {} = {}", a, b);
return false;
}
}
this->pIterator_ = this->din_;
this->uAvailableIn_ = 0;
this->SetArray(this->din_);

View File

@ -37,13 +37,22 @@ namespace Aurora::Compression
return false;
}
if (!this->dctx_)
{
SysPushErrorGen("Couldn't create decompressor");
return false;
}
for (const auto &[a, b] : meta.options)
{
auto uRet = ZSTD_DCtx_setParameter(this->dctx_, (ZSTD_dParameter)a, b);
if (ZSTD_isError(uRet))
{
SysPushErrorArg("Decompressor argument assignment {} = {}", a, b);
return false;
}
}
this->pIterator_ = this->din_;
this->uAvailableIn_ = 0;
this->SetArray(this->din_);

View File

@ -629,7 +629,7 @@ namespace Aurora::Compression
pref.compressionLevel = info.uCompressionLevel;
pref.autoFlush = true;
auto maxFrameSize = info.uLz4BlockSize ? info.uLz4BlockSize : 64 * 1024;
auto maxFrameSize = info.uBlockSize ? info.uBlockSize : 64 * 1024;
auto buffer = AuSPtr<char>(new char[maxFrameSize], AuDefaultDeleter<char[]>());
auto maxOut = LZ4F_compressBound(maxFrameSize, &pref);
auto outBuffer = AuSPtr<char>(new char[maxOut], AuDefaultDeleter<char[]>());;