AuroraRuntime/Source/Compression/AuCompression.hpp

102 lines
2.2 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuCompression.hpp
Date: 2021-6-17
Author: Reece
***/
#pragma once
namespace Aurora::Compression
{
static const AuUInt64 kChunkSize = 128 * 1024;
/// * compression type + bits -> internal zlib windowBits
static bool CompressionLevelFromExternalApi(const DecompressInfo &info, AuInt8 &out)
{
out = 0;
if (!info.uOptWindowBits)
{
if (info.alg == ECompressionType::eGZip)
{
out = 15 | 16;
}
else if (info.alg == ECompressionType::eDeflate)
{
out = -15;
}
else
{
out = 15;
}
return true;
}
if (info.uOptWindowBits.value() < 0)
{
return {};
}
if (info.uOptWindowBits.value() > 15)
{
return {};
}
if (info.alg == ECompressionType::eGZip)
{
out = info.uOptWindowBits.value() | 16;
}
else if (info.alg == ECompressionType::eDeflate)
{
out = 0 - info.uOptWindowBits.value();
}
else
{
out = info.uOptWindowBits.value();
}
return true;
}
/// * compression type + bits -> internal zlib windowBits
static bool CompressionLevelFromExternalApi(const CompressInfo &info, AuInt8 &out)
{
out = 0;
if (!info.uOptWindowBits)
{
if (info.type == ECompressionType::eGZip)
{
out = 15 | 16;
}
else if (info.type == ECompressionType::eDeflate)
{
out = -15;
}
else
{
out = 15;
}
return true;
}
if (info.type == ECompressionType::eGZip)
{
out = info.uOptWindowBits.value() | 16;
}
else if (info.type == ECompressionType::eDeflate)
{
out = 0 - info.uOptWindowBits.value();
}
else
{
out = info.uOptWindowBits.value();
}
return true;
}
}