files that use a literal table and 8k dictionary, and that the just-added Shrink support works at all. - Replaced the bit-at-a-time Shannon-Fano decoder from GunZip.c64 with the word-at-a-time one from 7-Zip for a slight speedup when working with Imploded files. SVN r1588 (trunk)
47 lines
No EOL
1.4 KiB
C++
47 lines
No EOL
1.4 KiB
C++
#include "files.h"
|
|
#include "doomerrors.h"
|
|
|
|
class FZipExploder
|
|
{
|
|
unsigned int Hold, Bits;
|
|
FileReader *In;
|
|
unsigned int InLeft;
|
|
|
|
/****************************************************************
|
|
Shannon-Fano tree structures, variables and related routines
|
|
****************************************************************/
|
|
|
|
enum { kNumBitsInLongestCode = 16 };
|
|
|
|
struct DecoderBase
|
|
{
|
|
unsigned int Limits[kNumBitsInLongestCode + 2]; // Limits[i] = value limit for symbols with length = i
|
|
unsigned char Positions[kNumBitsInLongestCode + 2]; // Positions[i] = index in Symbols[] of first symbol with length = i
|
|
unsigned char Symbols[1];
|
|
|
|
bool SetCodeLengths(const unsigned char *codeLengths, const int kNumSymbols);
|
|
};
|
|
|
|
template<int kNumSymbols>
|
|
struct Decoder : DecoderBase
|
|
{
|
|
unsigned char RestOfSymbols[kNumSymbols];
|
|
};
|
|
|
|
Decoder<256> LiteralDecoder;
|
|
Decoder<64> DistanceDecoder;
|
|
Decoder<64> LengthDecoder;
|
|
|
|
int DecodeSFValue(const DecoderBase ¤tTree, const unsigned int kNumSymbols);
|
|
int DecodeSF(unsigned char *table);
|
|
public:
|
|
int Explode(unsigned char *out, unsigned int outsize, FileReader *in, unsigned int insize, int flags);
|
|
};
|
|
|
|
class CExplosionError : CRecoverableError
|
|
{
|
|
public:
|
|
CExplosionError(const char *message) : CRecoverableError(message) {}
|
|
};
|
|
|
|
int ShrinkLoop(unsigned char *out, unsigned int outsize, FileReader *in, unsigned int insize); |