(*
* LZHUF.C English version 1.0
* Based on Japanese version 29-NOV-1988
* LZSS coded by Haruhiko OKUMURA
* Adaptive Huffman Coding coded by Haruyasu YOSHIZAKI
* Edited and translated to English by Kenji RIKITAKE
* Translated from C to Turbo Pascal by Douglas Webb 2/18/91
* Update and bug correction of TP version 4/29/91 (Sorry!!)
*)
This unit allows the user to compress data using a combination of
LZSS compression and adaptive Huffman coding, or conversely to
decompress data that was previously compressed by this unit.
There are a number of options as to where the data being compressed/
decompressed is coming from/going to.
In fact it requires that you pass the "LZHPack" procedure 2 procedural
parameter of type 'GetProcType' and 'PutProcType' (declared below)
which will accept 3 parameters and act in every way like
a 'BlockRead' / 'BlockWrite' procedure call. Your 'GetBytesProc'
procedure should return the data to be compressed, and Your
'PutBytesProc' procedure should do something with the compressed
data (ie., put it in a file). In case you need to know (and you do
if you want to decompress this data again) the number of bytes in the
compressed data (original, not compressed size) is returned in
'Bytes_Written'.
GetBytesProc = PROCEDURE(VAR DTA; NBytes:WORD; VAR Bytes_Got : WORD);
DTA is the start of a memory location where the information returned
should be. NBytes is the number of bytes requested. The actual number
of bytes returned must be passed in Bytes_Got (if there is no more
data then 0 should be returned).
PutBytesProc = PROCEDURE(VAR DTA; NBytes:WORD; VAR Bytes_Got : WORD);
As above except instead of asking for data the procedure is dumping
out compressed data, do somthing with it.
"LZHUnPack" is basically the same thing in reverse. It requires
procedural parameters of type 'PutProcType'/'GetProcType' which
will act as above. 'GetProcType' must retrieve data compressed using
"LZHPack" (above) and feed it to the unpacking routine as requested.
'PutProcType' must accept the decompressed data and do something
withit. You must also pass in the original size of the decompressed
data, failure to do so will have adverse results.
Don't forget that as procedural parameters the
'GetProcType'/'PutProcType' procedures must be compiled
in the 'F+' state to avoid a catastrophe.
Note: All the large data structures for these routines are allocated
when needed from the heap, and deallocated when finished.
So when not in use memory requirements are minimal.
However, this unit uses about 34K of heap space, and 400 bytes of
stack when in use. }
Douglas P. Webb
dwebb@binkley.cs.mcgill.ca
|