AuroraRuntime/Source/Compression/Compression.hpp

100 lines
2.1 KiB
C++

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