AuroraRuntime/Source/Compression/Compression.hpp
2022-03-30 15:20:04 +01:00

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 == ECompressionType::eGZip)
{
out = 15 | 16;
}
else if (info.alg == ECompressionType::eDeflate)
{
out = -15;
}
else
{
out = 15;
return true;
}
}
if (info.windowBits < 0)
{
return {};
}
if (info.windowBits > 15)
{
return {};
}
if (info.alg == ECompressionType::eGZip)
{
out = info.windowBits | 16;
}
else if (info.alg == ECompressionType::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 == 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.windowBits | 16;
}
else if (info.type == ECompressionType::eDeflate)
{
out = 0 - info.windowBits;
}
else
{
out = info.windowBits;
}
return true;
}
}