59 lines
1.4 KiB
C++
59 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "DeflateElements.h"
|
|
|
|
#include "BitStream.h"
|
|
|
|
class AbstractChecksumCalculator;
|
|
|
|
class DeflateBlock
|
|
{
|
|
public:
|
|
DeflateBlock(BitStream* inputStream, BitStream* outputStream);
|
|
|
|
void buildCodeLengthMapping();
|
|
|
|
std::string getMetaData() const;
|
|
|
|
void flushToStream();
|
|
|
|
bool isFinalBlock() const;
|
|
|
|
void readHeader();
|
|
|
|
void readDynamicHuffmanTable();
|
|
|
|
void readLiteralCodeLengths();
|
|
|
|
bool readNextCodeLengthSymbol(unsigned char& buffer);
|
|
|
|
void setCodeLengthAlphabetLengths(const std::vector<unsigned char>& lengths);
|
|
|
|
void setCodeLengthLength(unsigned length);
|
|
|
|
void setLiteralsTableLength(unsigned length);
|
|
|
|
void setDistanceTableLength(unsigned length);
|
|
|
|
void setIsFinalBlock(bool isFinal);
|
|
|
|
void write(uint16_t datalength);
|
|
|
|
private:
|
|
BitStream* mInputStream;
|
|
BitStream* mOutputStream;
|
|
|
|
unsigned mHlit{0};
|
|
unsigned mHdist{0};
|
|
unsigned mHclen{0};
|
|
|
|
using CodeLengthEntry = std::pair<unsigned char, unsigned>;
|
|
using CodeLengthCountEntry = std::pair<unsigned, std::vector<CodeLengthEntry> >;
|
|
std::vector<CodeLengthCountEntry> mCodeLengthMapping;
|
|
|
|
std::vector<unsigned char> mCodeLengthAlphabetLengths;
|
|
static constexpr unsigned CODE_LENGTH_ALPHABET_PERMUTATION[19]{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
|
|
|
|
bool mInFinalBlock{false};
|
|
Deflate::CompressionMethod mCompressionMethod{Deflate::CompressionMethod::NONE};
|
|
};
|