XPlor/libs/compression/compression.h

88 lines
3.4 KiB
C
Raw Normal View History

2025-04-04 20:42:41 -04:00
#ifndef COMPRESSION_H
#define COMPRESSION_H
2025-04-04 20:34:24 -04:00
#include "QtZlib/zlib.h"
2025-04-23 00:09:35 -04:00
#include <windows.h>
#include <QtGlobal>
2025-04-04 20:34:24 -04:00
#include <stddef.h>
#include <QByteArray>
#include <QVector>
#include <QCryptographicHash>
2025-04-04 20:42:41 -04:00
enum OodleFormat {
LZH = 0,
LZHLW = 1,
LZNIB = 2,
FormatNone = 3,
LZB16 = 4,
LZBLW = 5,
LZA = 6,
LZNA = 7,
Kraken = 8,
Mermaid = 9,
BitKnit = 10,
Selkie = 11,
Hydra = 12,
Leviathan = 13
};
2025-04-04 20:34:24 -04:00
2025-04-04 20:42:41 -04:00
enum OodleCompressionLevel {
LevelNone = 0,
SuperFast = 1,
VeryFast = 2,
Fast = 3,
Normal = 4,
Optimal1 = 5,
Optimal2 = 6,
Optimal3 = 7,
Optimal4 = 8,
Optimal5 = 9
};
2025-04-04 20:34:24 -04:00
2025-04-04 20:42:41 -04:00
typedef int (*OodleLZ_CompressFunc)(OodleFormat Format, std::byte *Buffer, long BufferSize, std::byte *OutputBuffer, OodleCompressionLevel Level, uint a, uint b, uint c);
typedef int (*OodleLZ_DecompressFunc)(std::byte* Buffer, long BufferSize, std::byte* OutputBuffer, long OutputBufferSize, uint a, uint b, uint c, uint d, uint e, uint f, uint g, uint h, uint i, int ThreadModule);
2025-04-04 20:34:24 -04:00
2025-04-04 20:42:41 -04:00
class Compression {
public:
2025-04-23 00:09:35 -04:00
static quint32 CalculateAdler32Checksum(const QByteArray &data);
2025-04-04 20:42:41 -04:00
static QByteArray DecompressZLIB(const QByteArray &aCompressedData);
static qint64 FindZlibOffset(const QByteArray &bytes);
static QByteArray StripHashBlocks(const QByteArray &raw,
int dataChunkSize = 0x200000,
int hashChunkSize = 0x2000);
2025-04-04 20:42:41 -04:00
static QByteArray CompressZLIB(const QByteArray &aData);
static QByteArray CompressZLIBWithSettings(const QByteArray &aData,
int aCompressionLevel = Z_BEST_COMPRESSION,
int aWindowBits = MAX_WBITS,
int aMemLevel = 8,
int aStrategy = Z_DEFAULT_STRATEGY,
const QByteArray &aDictionary = {});
static QByteArray DecompressDeflate(const QByteArray &aCompressedData);
static QByteArray CompressDeflate(const QByteArray &aData);
static QByteArray CompressDeflateWithSettings(const QByteArray &aData,
2025-04-23 00:09:35 -04:00
int aCompressionLevel = Z_BEST_COMPRESSION,
int aWindowBits = MAX_WBITS,
int aMemLevel = 8,
int aStrategy = Z_DEFAULT_STRATEGY,
const QByteArray &aDictionary = {});
2025-04-04 20:42:41 -04:00
static QByteArray DecompressLZO(const QByteArray &aCompressedData, quint32 aDestSize);
2025-04-04 20:42:41 -04:00
static QByteArray DecompressOodle(const QByteArray &aCompressedData, quint32 aDecompressedSize);
static QByteArray CompressOodle(const QByteArray &aData);
2025-04-23 00:09:35 -04:00
static QByteArray CompressXMem(const QByteArray &data);
static QByteArray DecompressXMem(const QByteArray &data, int flags = 0, int windowSize = 0x20000, int partSize = 0x80000);
2025-04-04 20:42:41 -04:00
private:
static quint32 pGetOodleCompressedBounds(quint32 aBufferSize);
static QByteArray pCompressOodle(QByteArray aBuffer, quint32 aBufferSize, quint32 aOutputBufferSize,
OodleFormat aformat, OodleCompressionLevel alevel);
static QByteArray pDecompressOodle(QByteArray aBuffer, quint32 aBufferSize, quint32 aOutputBufferSize);
2025-04-04 20:34:24 -04:00
};
2025-04-04 20:42:41 -04:00
#endif // COMPRESSION_H