28 #include "../idlib/precompiled.h"
50 int Read(
void *outData,
int outLength );
51 int Write(
const void *inData,
int inLength );
133 if (
compress ==
false || inLength <= 0 ) {
145 if (
compress ==
true || outLength <= 0 ) {
148 return file->
Read( outData, outLength );
241 int Write(
const void *inData,
int inLength );
242 int Read(
void *outData,
int outLength );
261 void InitCompress(
const void *inData,
const int inLength );
266 int Compare(
const byte *src1,
int bitPtr1,
const byte *src2,
int bitPtr2,
int maxBits )
const;
276 assert( wordLength >= 1 && wordLength <= 32 );
371 if ( put > numBits ) {
374 fraction = value & ( ( 1 << put ) - 1 );
378 writeBit = ( writeBit + put ) & 7;
388 int value, valueBits,
get, fraction;
400 while ( valueBits < numBits ) {
407 get = numBits - valueBits;
418 if (
get > (numBits - valueBits) ) {
419 get = (numBits - valueBits);
423 fraction &= ( 1 << get ) - 1;
424 value |= fraction << valueBits;
465 if ( ( bitPtr1 & 7 ) == (bitPtr2 & 7 ) && maxBits > 16 ) {
466 const byte *p1 = &src1[bitPtr1 >> 3];
467 const byte *p2 = &src2[bitPtr2 >> 3];
471 int bitsRemain = maxBits;
475 for ( i = (bitPtr1 & 7); i < 8; i++, bits++ ) {
476 if ( ( ( *p1 >> i ) ^ ( *p2 >> i ) ) & 1 ) {
485 int remain = bitsRemain >> 3;
488 while ( remain >= 4 && (*(
const int *)p1 == *(
const int *)p2) ) {
496 while ( remain > 0 && (*p1 == *p2) ) {
506 finalBits = ( bitsRemain & 7 );
508 for ( i = 0; i < finalBits; i++, bits++ ) {
509 if ( ( ( *p1 >> i ) ^ ( *p2 >> i ) ) & 1 ) {
517 for ( i = 0; i < maxBits; i++ ) {
518 if ( ( ( src1[bitPtr1 >> 3] >> ( bitPtr1 & 7 ) ) ^ ( src2[bitPtr2 >> 3] >> ( bitPtr2 & 7 ) ) ) & 1 ) {
536 if (
compress ==
false || inLength <= 0 ) {
542 for ( i = 0; i < inLength; i++ ) {
574 if (
compress ==
true || outLength <= 0 ) {
580 for ( i = 0; i < outLength && readLength >= 0; i++ ) {
617 int Write(
const void *inData,
int inLength );
618 int Read(
void *outData,
int outLength );
642 if (
compress ==
false || inLength <= 0 ) {
659 if ( nextBits != bits ) {
687 if (
compress ==
true || outLength <= 0 ) {
693 while( writeByte <= writeLength && readLength >= 0 ) {
728 int Write(
const void *inData,
int inLength );
729 int Read(
void *outData,
int outLength );
742 if (
compress ==
false || inLength <= 0 ) {
773 if (
compress ==
true || outLength <= 0 ) {
779 while( writeByte <= writeLength && readLength >= 0 ) {
783 while( count-- > 0 ) {
827 int Write(
const void *inData,
int inLength );
828 int Read(
void *outData,
int outLength );
888 for( i = 0; i < (
HMAX+1); i++ ) {
893 for( i = 0; i < 768; i++ ) {
923 if ( (
bloc&7) == 0 ) {
939 t = (fin[(
bloc>>3)] >> (
bloc&7)) & 0x1;
953 if ( (
bloc&7) == 0 ) {
976 t = (
seq[wh] >> (
bloc & 7 ) ) & 0x1;
1021 if ( par1->
left == node1 ) {
1024 par1->
right = node2;
1031 if ( par2->
left == node2 ) {
1034 par2->
right = node1;
1062 if ( node1->
next == node1 ) {
1063 node1->
next = node2;
1065 if ( node2->
next == node2 ) {
1066 node2->
next = node1;
1068 if ( node1->
next ) {
1071 if ( node2->
next ) {
1074 if ( node1->
prev ) {
1077 if ( node2->
prev ) {
1095 lnode = *node->
head;
1096 if ( lnode != node->
parent ) {
1097 Swap( lnode, node );
1118 if ( *node->
head == node ) {
1145 *tnode2->
head = tnode2;
1149 *tnode2->
head = tnode2;
1164 *tnode->
head = tnode2;
1169 *tnode->
head = tnode;
1185 tnode2->
right = tnode;
1217 return (*ch = node->
symbol);
1232 if ( node->
right == child ) {
1252 for ( i = 7; i >= 0; i-- ) {
1253 Add_bit( (
char)((ch >> i) & 0x1), fout );
1268 if (
compress ==
false || inLength <= 0 ) {
1272 for ( i = 0; i < inLength; i++ ) {
1273 ch = ((
const byte *)inData)[
i];
1301 int str = (
bloc>>3);
1316 if (
compress ==
true || outLength <= 0 ) {
1325 for ( i = 0; i < outLength; i++ ) {
1334 for ( j = 0; j < 8; j++ ) {
1339 ((
byte *)outData)[
i] = ch;
1385 int Write(
const void *inData,
int inLength );
1386 int Read(
void *outData,
int outLength );
1486 return (
unsigned int) ( ( ( ( (long)
code -
low ) + 1 ) *
scale - 1 ) / ( ( (long)
high -
low ) + 1 ) );
1557 range = ( long )(
high -
low ) + 1;
1559 low = low + (
unsigned short )( ( range * symbol->
low ) /
scale );
1567 low &= AC_MSB2_MASK - 1;
1615 low = low + (
unsigned short )(( range * symbol->
low ) /
scale );
1631 low &= AC_MSB2_MASK - 1;
1698 if (
compress ==
false || inLength <= 0 ) {
1704 for( i = 0; i < inLength; i++ ) {
1716 for ( j = 0; j < 8; j++ ) {
1747 if (
compress ==
true || outLength <= 0 ) {
1753 for( i = 0; i < outLength && readLength >= 0; i++ ) {
1768 for ( j = 0; j < 8; j++ ) {
1813 int Write(
const void *inData,
int inLength );
1814 int Read(
void *outData,
int outLength );
1829 bool FindMatch(
int startWord,
int startValue,
int &wordOffset,
int &numWords );
1860 wordOffset = startWord;
1869 if ( n > numWords * wordLength ) {
1898 int blockBit, blockByte,
value, valueBits,
get, fraction;
1901 blockByte = ( wordOffset *
wordLength ) >> 3;
1902 if ( blockBit != 0 ) {
1910 if ( blockBit == 0 ) {
1920 fraction =
block[blockByte - 1];
1921 fraction >>= blockBit;
1922 fraction &= ( 1 << get ) - 1;
1923 value |= fraction << valueBits;
1925 blockBit = ( blockBit + get ) & 7;
1937 int i, startWord, startValue, wordOffset, numWords;
1947 if (
FindMatch( startWord, startValue, wordOffset, numWords ) ) {
1952 for ( i = 0; i < numWords; i++ ) {
1974 int i,
offset, startWord, numWords;
1979 while( writeByte < writeLength && readLength >= 0 ) {
1983 for ( i = 0; i < numWords; i++ ) {
2004 if (
compress ==
false || inLength <= 0 ) {
2008 for ( n = i = 0; i < inLength; i +=
n ) {
2010 if ( inLength - i >= n ) {
2011 memcpy(
block + blockSize, ((
const byte *)inData) + i, n );
2016 memcpy(
block + blockSize, ((
const byte *)inData) + i, inLength - i );
2048 if (
compress ==
true || outLength <= 0 ) {
2056 for ( n = i = 0; i < outLength; i +=
n ) {
2061 if ( outLength - i >= n ) {
2062 memcpy( ((
byte *)outData) + i,
block + blockIndex, n );
2066 memcpy( ((
byte *)outData) + i,
block + blockIndex, outLength - i );
2117 int i, startWord, startValue, wordOffset, numWords;
2127 if (
FindMatch( startWord, startValue, wordOffset, numWords ) ) {
2131 for ( i = 0; i < numWords; i++ ) {
2153 int i,
offset, startWord, numWords;
2158 while( writeByte < writeLength && readLength >= 0 ) {
2163 for ( i = 0; i < numWords; i++ ) {
2231 int Write(
const void *inData,
int inLength );
2232 int Read(
void *outData,
int outLength );
2303 if (
compress ==
true || outLength <= 0 ) {
2311 for ( n = i = 0; i < outLength; i +=
n ) {
2316 if ( outLength - i >= n ) {
2317 memcpy( ((
byte *)outData) + i,
block + blockIndex, n );
2321 memcpy( ((
byte *)outData) + i,
block + blockIndex, outLength - i );
2341 for ( j =
index.First( w ^ k ); j >= 0 ; j =
index.Next( j ) ) {
2404 for ( i = 0; i < inLength; i++ ) {
2434 assert( i < LZW_DICT_SIZE-1 && code >= 0 );
2437 }
while ( code >= 0 );
2438 firstChar = chain[--
i];
2439 for ( ; i >= 0; i-- ) {
2451 int code, firstChar;
2455 while( writeByte < writeLength - LZW_DICT_SIZE && readLength > 0 ) {
byte block[LZSS_BLOCK_SIZE]
static idCompressor * AllocRunLength_ZeroBased(void)
void Init(idFile *f, bool compress, int wordLength)
GLsizei const GLfloat * value
void CharToSymbol(byte c, acSymbol_t *symbol)
assert(prefInfo.fullscreenBtn)
int hashNext[LZSS_BLOCK_SIZE *8]
idCompressor_RunLength(void)
int Write(const void *inData, int inLength)
float GetCompressionRatio(void) const
const int LZSS_OFFSET_BITS
huffmanNode_t * nodePtrs[768]
static idCompressor * AllocLZW(void)
virtual void CompressBlock(void)
void FinishCompress(void)
virtual void ForceFlush(void)
float GetCompressionRatio(void) const
float GetCompressionRatio(void) const
static const int LZW_DICT_SIZE
void FinishCompress(void)
ID_INLINE T Max(T x, T y)
struct nodetype huffmanNode_t
unsigned int underflowBits
GLenum GLenum GLenum GLenum GLenum scale
int Read(void *outData, int outLength)
void Swap(huffmanNode_t *node1, huffmanNode_t *node2)
int Write(const void *inData, int inLength)
int Write(const void *inData, int inLength)
ID_TIME_T Timestamp(void)
virtual void CompressBlock(void)
struct idCompressor_Arithmetic::acProbs_s acProbs_t
static idCompressor * AllocLZSS_WordAligned(void)
void FinishCompress(void)
void Add_bit(char bit, byte *fout)
void FinishCompress(void)
void Init(idFile *f, bool compress, int wordLength)
void Init(idFile *f, bool compress, int wordLength)
idCompressor_Arithmetic(void)
virtual const char * GetName(void)
void Transmit(int ch, byte *fout)
idCompressor_LZSS_WordAligned(void)
static idCompressor * AllocArithmetic(void)
int Read(void *outData, int outLength)
idCompressor_RunLength_ZeroBased(void)
int GetBit(byte *fout, int *offset)
static const int LZW_BLOCK_SIZE
int Read(void *outData, int outLength)
void Init(idFile *f, bool compress, int wordLength)
const char * GetName(void)
GLuint GLuint GLsizei count
int Read(void *outData, int outLength)
int ProbabilityForCount(unsigned int count)
void FinishCompress(void)
huffmanNode_t * loc[HMAX+1]
GLubyte GLubyte GLubyte GLubyte w
int Read(void *outData, int outLength)
const int LZSS_BLOCK_SIZE
bool FindMatch(int startWord, int startValue, int &wordOffset, int &numWords)
void RemoveSymbolFromStream(acSymbol_t *symbol)
huffmanNode_t ** Get_ppnode()
void InitDecompress(void *outData, int outLength)
int Write(const void *inData, int inLength)
int Write(const void *inData, int inLength)
void UnreadBits(int numBits)
int Write(const void *inData, int inLength)
virtual int Read(void *buffer, int len)
byte block[LZW_BLOCK_SIZE]
int Compare(const byte *src1, int bitPtr1, const byte *src2, int bitPtr2, int maxBits) const
int ReadBits(int numBits)
int Seek(long offset, fsOrigin_t origin)
static idCompressor * AllocRunLength(void)
int AddToDict(int w, int k)
void Swaplist(huffmanNode_t *node1, huffmanNode_t *node2)
int Receive(huffmanNode_t *node, int *ch)
static const int LZW_FIRST_CODE
void UpdateProbabilities(acSymbol_t *symbol)
virtual ID_TIME_T Timestamp(void)
int hashTable[LZSS_HASH_SIZE]
static const int LZW_DICT_BITS
huffmanNode_t nodeList[768]
static idCompressor * AllocHuffman(void)
void FinishCompress(void)
void PutBit(int bit, byte *fout, int *offset)
static idCompressor * AllocNoCompression(void)
void AddToHash(int index, int hash)
void Increment(huffmanNode_t *node)
virtual void DecompressBlock(void)
const char * GetFullPath(void)
static const int LZW_START_BITS
int Write(const void *inData, int inLength)
int Read(void *outData, int outLength)
idCompressor_Huffman(void)
int Read(void *outData, int outLength)
virtual int Write(const void *buffer, int len)
struct idCompressor_LZW::@47 dictionary[LZW_DICT_SIZE]
idCompressor_BitStream(void)
huffmanNode_t ** freelist
static idCompressor * AllocLZSS(void)
int Read(void *outData, int outLength)
void Init(idFile *f, bool compress, int wordLength)
int SymbolFromCount(unsigned int count, acSymbol_t *symbol)
void EncodeSymbol(acSymbol_t *symbol)
static idCompressor * AllocBitStream(void)
virtual void DecompressBlock(void)
void Init(idFile *f, bool compress, int wordLength)
acProbs_t probabilities[1<< AC_WORD_LENGTH]
void InitCompress(const void *inData, const int inLength)
void InitProbabilities(void)
virtual void Error(const char *fmt,...) id_attribute((format(printf
const int LZSS_LENGTH_BITS
int GetCurrentCount(void)
int GetWordFromBlock(int wordOffset) const
ID_INLINE T Min(T x, T y)
void Init(idFile *f, bool compress, int wordLength)
void WriteBits(int value, int numBits)
struct idCompressor_Arithmetic::acSymbol_s acSymbol_t
virtual const char * GetFullPath(void)
void Send(huffmanNode_t *node, huffmanNode_t *child, byte *fout)
void Free_ppnode(huffmanNode_t **ppnode)
void WriteOverflowBits(void)
void Init(idFile *f, bool compress, int wordLength)
int Write(const void *inData, int inLength)