mirror of
https://github.com/libAthena/athena.git
synced 2025-12-09 13:38:03 +00:00
* Add LZ77 Compression
This commit is contained in:
@@ -24,17 +24,19 @@ namespace io
|
||||
{
|
||||
namespace Compression
|
||||
{
|
||||
// Zlib compression
|
||||
atInt32 decompressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen);
|
||||
atInt32 compressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen);
|
||||
// Zlib compression
|
||||
atInt32 decompressZlib(const atUint8* src, atUint32 srcLen, atUint8*& dst, atUint32 dstLen);
|
||||
atInt32 compressZlib(const atUint8* src, atUint32 srcLen, atUint8*& dst, atUint32 dstLen);
|
||||
|
||||
// lzo compression
|
||||
atInt32 decompressLZO(const atUint8* source, atInt32 sourceSize, atUint8* dest, atInt32& dstSize);
|
||||
// lzo compression
|
||||
atInt32 decompressLZO(const atUint8* source, atInt32 sourceSize, atUint8*& dst, atInt32& dstSize);
|
||||
|
||||
// Yaz0 encoding
|
||||
atUint32 yaz0Decode(const atUint8* src, atUint8* dst, atUint32 uncompressedSize);
|
||||
atUint32 yaz0Encode(const atUint8* src, atUint32 srcSize, atUint8* data);
|
||||
// Yaz0 encoding
|
||||
atUint32 yaz0Decode(const atUint8* src, atUint8*& dst, atUint32 uncompressedSize);
|
||||
atUint32 yaz0Encode(const atUint8* src, atUint32 srcSize, atUint8* data);
|
||||
|
||||
atUint32 decompressLZ77(const atUint8* src, atUint32 srcLen, atUint8*& dst);
|
||||
atUint32 compressLZ77(const atUint8* src, atUint32 srcLen, atUint8*& dst, bool extended = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
44
include/LZ77/LZBase.hpp
Normal file
44
include/LZ77/LZBase.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef LZBASE_HPP
|
||||
#define LZBASE_HPP
|
||||
|
||||
#include <string>
|
||||
#include "LZ77/LZLookupTable.hpp"
|
||||
|
||||
class LZBase
|
||||
{
|
||||
public:
|
||||
explicit LZBase(atInt32 minimumOffset=1,atInt32 slidingWindow=4096, atInt32 minimumMatch=3, atInt32 blockSize=8);
|
||||
virtual ~LZBase() {}
|
||||
|
||||
virtual atUint32 compress(const atUint8* src, atUint8*& dest, atUint32 srcLength)=0;
|
||||
virtual atUint32 decompress(const atUint8* src, atUint8*& dest, atUint32 srcLength)=0;
|
||||
|
||||
void setSlidingWindow(atInt32 SlidingWindow);
|
||||
atInt32 slidingWindow();
|
||||
void setReadAheadBuffer(atInt32 ReadAheadBuffer);
|
||||
atInt32 readAheadBuffer();
|
||||
void setMinMatch(atInt32 minimumMatch);
|
||||
atInt32 minMatch();
|
||||
void setBlockSize(atInt32 BlockSize);
|
||||
atInt32 blockSize();
|
||||
void setMinimumOffset(atUint32 minimumOffset);
|
||||
atUint32 minimumOffset();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
atInt32 subMatch(const atUint8* str1,const uint8_t* str2,const atInt32 len);
|
||||
LZLengthOffset windowSearch(atUint8* beginSearchPtr, atUint8* searchPosPtr, atUint8* endLABufferPtr, atUint8* startLBPtr);
|
||||
protected:
|
||||
LZLengthOffset search(atUint8* posPtr, atUint8* dataBegin, atUint8* dataEnd);
|
||||
|
||||
atInt32 m_slidingWindow;
|
||||
atInt32 m_readAheadBuffer;
|
||||
atInt32 m_minMatch;//Minimum number of bytes that have to matched to go through with compression
|
||||
atInt32 m_blockSize;
|
||||
atUint32 m_minOffset;
|
||||
LZLookupTable m_lookupTable;
|
||||
|
||||
};
|
||||
|
||||
#endif // LZBASE_HPP
|
||||
39
include/LZ77/LZLookupTable.hpp
Normal file
39
include/LZ77/LZLookupTable.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef LZLOOKUPTABLE_HPP
|
||||
#define LZLOOKUPTABLE_HPP
|
||||
|
||||
#include <map>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <Athena/Types.hpp>
|
||||
|
||||
struct LZLengthOffset
|
||||
{
|
||||
atUint32 length;//The number of bytes compressed
|
||||
atUint16 offset;//How far back in sliding window where bytes that match the lookAheadBuffer is located
|
||||
bool compare_equal(const LZLengthOffset& lo_pair)
|
||||
{
|
||||
return length == lo_pair.length && offset == lo_pair.offset;
|
||||
}
|
||||
};
|
||||
|
||||
class LZLookupTable
|
||||
{
|
||||
public:
|
||||
LZLookupTable();
|
||||
LZLookupTable(atInt32 minimumMatch, atInt32 slidingWindow=4096, atInt32 lookAheadWindow=18);
|
||||
~LZLookupTable();
|
||||
LZLengthOffset search(atUint8* curPos, const atUint8* dataBegin, const atUint8* dataEnd);
|
||||
void setLookAheadWindow(atInt32 lookAheadWindow);
|
||||
private:
|
||||
typedef std::multimap<std::vector<uint8_t>, int32_t> LookupTable;
|
||||
LookupTable table;
|
||||
atInt32 m_minimumMatch;
|
||||
atInt32 m_slidingWindow;
|
||||
atInt32 m_lookAheadWindow;
|
||||
std::vector<uint8_t> m_buffer;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // LZLOOKUPTABLE_HPP
|
||||
13
include/LZ77/LZType10.hpp
Normal file
13
include/LZ77/LZType10.hpp
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef LZ77TYPE10_HPP
|
||||
#define LZ77TYPE10_HPP
|
||||
|
||||
#include "LZBase.hpp"
|
||||
|
||||
class LZType10 : public LZBase {
|
||||
public:
|
||||
explicit LZType10(atInt32 minimumOffset=1, atInt32 SlidingWindow=4096, atInt32 MinimumMatch=3, atInt32 BlockSize=8);
|
||||
atUint32 compress(const atUint8* src, atUint8*& dest, atUint32 srcLength);
|
||||
atUint32 decompress(const atUint8* src, atUint8*& dst, atUint32 srcLen);
|
||||
};
|
||||
|
||||
#endif // LZ77TYPE10_HPP
|
||||
15
include/LZ77/LZType11.hpp
Normal file
15
include/LZ77/LZType11.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef LZTYPE11_HPP
|
||||
#define LZTYPE11_HPP
|
||||
|
||||
|
||||
#include "LZBase.hpp"
|
||||
|
||||
class LZType11 : public LZBase {
|
||||
public:
|
||||
explicit LZType11(atInt32 MinimumOffset=1, atInt32 SlidingWindow=4096, atInt32 MinimumMatch=3, atInt32 BlockSize=8);
|
||||
atUint32 compress(const atUint8 *src, atUint8*& dest, atUint32 srcLength);
|
||||
atUint32 decompress(const atUint8 *src, atUint8*& dest, atUint32 srcLength);
|
||||
|
||||
};
|
||||
|
||||
#endif // LZTYPE11_HPP
|
||||
Reference in New Issue
Block a user