summaryrefslogtreecommitdiff
path: root/src/win95/huffman.cpp
diff options
context:
space:
mode:
authorSteven Fuller <relnev@icculus.org>2008-05-09 02:11:36 -0700
committerPatryk Obara <dreamer.tan@gmail.com>2019-08-20 02:22:37 +0200
commite9788e390d5fe0e326a39762a04c628111bc0e84 (patch)
tree65175f0dfe53aa821efad1bd47cb70df2416458a /src/win95/huffman.cpp
parentc51b91cfe79a1ffd5da3f6a6ce202982cdfcdf85 (diff)
Windows WIP.
Diffstat (limited to 'src/win95/huffman.cpp')
-rw-r--r--src/win95/huffman.cpp33
1 files changed, 14 insertions, 19 deletions
diff --git a/src/win95/huffman.cpp b/src/win95/huffman.cpp
index f641071..4347959 100644
--- a/src/win95/huffman.cpp
+++ b/src/win95/huffman.cpp
@@ -61,11 +61,8 @@ static HuffEncode EncodingTable[257];
/* KJL 17:16:03 17/09/98 - Compression */
static void PerformSymbolCensus(unsigned char *sourcePtr, int length);
-#ifdef __WATCOMC__
static int HuffItemsSortSub(const void *cmp1, const void *cmp2);
-#else
static int __cdecl HuffItemsSortSub(const void *cmp1, const void *cmp2);
-#endif
static void SortCensusData(void);
static void BuildHuffmanTree(void);
static void MakeHuffTreeFromHuffItems(HuffNode *base, HuffItem *source, int count);
@@ -125,11 +122,7 @@ static void PerformSymbolCensus(unsigned char *sourcePtr, int length)
while (--length);
}
-#ifdef __WATCOMC__
-static int HuffItemsSortSub(const void *cmp1, const void *cmp2)
-#else
static int __cdecl HuffItemsSortSub(const void *cmp1, const void *cmp2)
-#endif
{
if (((HuffItem *)cmp1)->Count > ((HuffItem *)cmp2)->Count)
return 1;
@@ -321,6 +314,7 @@ static int HuffEncodeBytes(int *dest, unsigned char *source, int count, HuffEnco
if (!count) return 0;
+ accum = 0;
start = dest;
sourcelim = sourceend = source + count;
available = 32;
@@ -387,7 +381,7 @@ lpstart: val = *source++;
}
}
*dest++ = accum >> available;
- return (dest - start) * 4;
+ return (int)((dest - start) * 4);
}
@@ -398,11 +392,11 @@ lpstart: val = *source++;
/* KJL 17:16:24 17/09/98 - Decompression */
static int DecodeTable[1<<MAX_DEPTH];
-static void MakeHuffmanDecodeTable(int *depth, int depthmax, unsigned char *list);
-static int HuffmanDecode(unsigned char *dest, int *source, int *table, int length);
+static void MakeHuffmanDecodeTable(const int *depth, int depthmax, const unsigned char *list);
+static int HuffmanDecode(unsigned char *dest, const int *source, const int *table, int length);
-extern char *HuffmanDecompress(HuffmanPackage *inpackage)
+extern char *HuffmanDecompress(const HuffmanPackage *inpackage)
{
unsigned char *uncompressedData = NULL;
// Step 1: Make the decoding table
@@ -418,12 +412,12 @@ extern char *HuffmanDecompress(HuffmanPackage *inpackage)
return (char*)uncompressedData;
}
-static void MakeHuffmanDecodeTable(int *depth, int depthmax, unsigned char *list)
+static void MakeHuffmanDecodeTable(const int *depth, int depthmax, const unsigned char *list)
{
int thisdepth, depthbit, repcount, repspace, lenbits, temp, count;
int *outp;
int o = 0;
- unsigned char *p;
+ const unsigned char *p;
int *outtbl = DecodeTable;
lenbits = 0;
@@ -431,7 +425,7 @@ static void MakeHuffmanDecodeTable(int *depth, int depthmax, unsigned char *list
repspace = 1;
thisdepth = 0;
depthbit = 4;
- p = (unsigned char *)list + 255;
+ p = list + 255;
while (1)
{
do
@@ -476,17 +470,18 @@ static void MakeHuffmanDecodeTable(int *depth, int depthmax, unsigned char *list
#define EDXMASK ((((1 << (MAX_DEPTH + 1)) - 1) ^ 1) ^ -1)
-static int HuffmanDecode(unsigned char *dest, int *source, int *table, int length)
+static int HuffmanDecode(unsigned char *dest, const int *source, const int *table, int length)
{
unsigned char *start;
int available, reserve, fill, wid;
unsigned int bits=0, resbits;
- unsigned char *p;
+ const unsigned char *p;
start = dest;
available = 0;
reserve = 0;
- wid = 0;
+ wid = 0;
+ resbits = 0;
do
{
available += wid;
@@ -512,11 +507,11 @@ static int HuffmanDecode(unsigned char *dest, int *source, int *table, int lengt
{
bits >>= wid;
*dest++ = p[1];
-lpent: p = (unsigned char *)(((short *)table)+(bits & ~EDXMASK));
+lpent: p = (const unsigned char *)(((const short *)table)+(bits & ~EDXMASK));
}
while ((available -= (wid = *p)) >= 0 && (dest-start)!=length);
}
while (available > -32 && (dest-start)!=length);
- return dest - start;
+ return (int)(dest - start);
}