[*] now brotli maps uWindowBits to BROTLI_PARAM_LGWIN

[+] CompressInfo::uQuality
This commit is contained in:
Reece Wilson 2023-07-27 22:55:28 +01:00
parent 3db5554673
commit 3d9ad0350e
4 changed files with 67 additions and 22 deletions

View File

@ -54,19 +54,25 @@ namespace Aurora::Compression
*/
AuUInt16 uBlockSize {};
bool bHasWindowbits {true};
/**
* @brief DEFLATE related variabl
*
* Deflate: 0 <= x >= 15,
* Deflate: 0 <= x <= 15,
* recommended: 15
* Zip: 0 <= x >= 15,
* Zip: 0 <= x <= 15,
* recommended: 15
* GZip: 0 <= x >= 15,
* GZip: 0 <= x <= 15,
* recommended: 15
* Brotli: 16 <= x <= 24
* recommended:
*/
AuUInt8 uWindowBits {15};
AuOptionalEx<AuUInt8> uWindowBits { };
/**
* brotli: 0 <= x <= 11,
* zstd: 0 <= x <= 9,
*/
AuOptionalEx<AuUInt8> uQuality { 7 };
/**
* @brief Internal output buffer size.
@ -109,12 +115,7 @@ namespace Aurora::Compression
/**
* @brief Flag for headerless decompression streams
*/
bool bHasWindowbits { true };
/**
* @brief Flag for headerless decompression streams
*/
AuInt8 uWindowBits { 15 };
AuOptionalEx<AuInt8> uWindowBits { 15 };
AuUInt8 uThreads { 1 };

View File

@ -16,7 +16,7 @@ namespace Aurora::Compression
{
out = 0;
if (!info.bHasWindowbits)
if (!info.uWindowBits)
{
if (info.alg == ECompressionType::eGZip)
{
@ -33,27 +33,27 @@ namespace Aurora::Compression
}
}
if (info.uWindowBits < 0)
if (info.uWindowBits.value() < 0)
{
return {};
}
if (info.uWindowBits > 15)
if (info.uWindowBits.value() > 15)
{
return {};
}
if (info.alg == ECompressionType::eGZip)
{
out = info.uWindowBits | 16;
out = info.uWindowBits.value() | 16;
}
else if (info.alg == ECompressionType::eDeflate)
{
out = 0 - info.uWindowBits;
out = 0 - info.uWindowBits.value();
}
else
{
out = info.uWindowBits;
out = info.uWindowBits.value();
}
return true;
@ -83,15 +83,15 @@ namespace Aurora::Compression
if (info.type == ECompressionType::eGZip)
{
out = info.uWindowBits | 16;
out = info.uWindowBits.value() | 16;
}
else if (info.type == ECompressionType::eDeflate)
{
out = 0 - info.uWindowBits;
out = 0 - info.uWindowBits.value();
}
else
{
out = info.uWindowBits;
out = info.uWindowBits.value();
}
return true;

View File

@ -57,6 +57,41 @@ namespace Aurora::Compression
return false;
}
}
if (meta.uQuality)
{
if (meta.uQuality <= BROTLI_MAX_QUALITY &&
meta.uQuality >= BROTLI_MIN_QUALITY)
{
if (!BrotliEncoderSetParameter(this->pState, BrotliEncoderParameter::BROTLI_PARAM_QUALITY, meta.uQuality))
{
SysPushErrorArg("Compressor couldn't set quality");
return false;
}
}
else
{
SysPushErrorArg("Compressor couldn't set quality");
}
}
if (meta.uWindowBits)
{
if (meta.uWindowBits.value() <= BROTLI_MAX_INPUT_BLOCK_BITS &&
meta.uWindowBits.value() >= BROTLI_MIN_INPUT_BLOCK_BITS)
{
if (!BrotliEncoderSetParameter(this->pState, BrotliEncoderParameter::BROTLI_PARAM_LGWIN, meta.uWindowBits))
{
SysPushErrorArg("Compressor couldn't set window bits");
return false;
}
}
else
{
SysPushErrorArg("Compressor couldn't set window bits");
return false;
}
}
if (!BrotliEncoderSetParameter(this->pState, BrotliEncoderParameter::BROTLI_PARAM_QUALITY, meta.uCompressionLevel))
{

View File

@ -58,8 +58,17 @@ namespace Aurora::Compression
return false;
}
meta.uThreads = AuMin(AuHwInfo::GetCPUInfo().uThreads, meta.uThreads);
if (meta.uQuality)
{
uRet = ZSTD_CCtx_setParameter(this->cctx_, ZSTD_c_strategy, meta.uQuality.value());
if (ZSTD_isError(uRet))
{
SysPushErrorGen("ZSTD_c_strategy");
return false;
}
}
meta.uThreads = AuMin(AuHwInfo::GetCPUInfo().uThreads, meta.uThreads);
uRet = ZSTD_CCtx_setParameter(this->cctx_, ZSTD_c_nbWorkers, AuMax(meta.uThreads, AuUInt8(1u)));
if (ZSTD_isError(uRet))
{