Unit LZSS32

LZ77 compression for 32-bit Delphi 2: Ported by C.J.Rankin from the 16-bit unit LZSSUnit. Rumour has it that the Pentium Pro cannot handle `partial register loads' efficiently; apparently, assigning a value to AL,AH,AX (e.g.) and then reading EAX, or assigning AL,AH and reading AX causes the pipelines to stall. Call me optimistic/pedantic, but I have tried to avoid this where possible. Original unit credits: Assembler Programmer: Andy Tam, Pascal Conversion: Douglas Webb, Unit Conversion and Dynamic Memory Allocation: Andrew Eigus. Written by Andrew Eigus (aka: Mr. Byte) of: Fidonet: 2:5100/33, Internet: aeigus@fgate.castle.riga.lv, aeigus@kristin.cclu.lv.

Classes

Functions

LZDecode - } { Restore registers and flush Output buffer } {
LZDone - #X LZDone

LZInit
LZEncode - #Z-

} { Move this node as the root of the subtree .
LZInit - #Z-

} { Restore registers and flush Output buffer .
LZSquash - #X LZUnsquash

LZDone
LZUnSquash - #X LZDone

LZSquash

Types

PBinaryTree
PLZRWBuffer
TBinaryTree
TLeftMomTree
TLZRWBuffer
TLZSSWord
TLZTextBuf
TReadProc
TRightTree
TWriteProc

Constants

F
Log2TLZSSWord
LZRWBufSize
LZSSMemRequired
N
Nul
Threshold

Variables

BinaryTree
CodeBuf
Height
InBufP
InBufPtr
InBufSize
IsLZInitialized
LastLen
LZReadProc
LZWriteProc
MatchLen
MatchPos
OutBufP
OutBufPtr


Functions


procedure LZDecode;

} { Restore registers and flush Output buffer } {

procedure LZDone;

#X LZDone

LZInit


procedure LZEncode;

#Z-

} { Move this node as the root of the subtree ... } {


function LZInit : boolean;

#Z-

} { Restore registers and flush Output buffer ... } {


procedure LZSquash(ReadProc: TReadProc; WriteProc: TWriteProc);

#X LZUnsquash

LZDone


procedure LZUnSquash(ReadProc: TReadProc; WriteProc: TWriteProc);

#X LZDone

LZSquash


Types


PBinaryTree = ^TBinaryTree

PLZRWBuffer = ^TLZRWBuffer
This is declaration for custom write function. It should write Count bytes into WriteBuf, returning the number of actual bytes written. } {#Z+
TBinaryTree = record
TextBuf : TLZTextBuf;
Left : TLeftMomTree;
Right : TRightTree;
Mom : TLeftMomTree
end;

TLeftMomTree = array[0..N] of TLZSSWord;

TLZRWBuffer = array[0..LZRWBufSize - 1] of Byte;

TLZSSWord = Cardinal
#Z+
TLZTextBuf = array[0..N + F - 2] of Byte;
file buffers
TReadProc = function(var ReadBuf): TLZSSWord
#X LZUnsquash
TRightTree = array[0..N + 256] of TLZSSWord;

TWriteProc = function(var WriteBuf;
                            Count: TLZSSWord): TLZSSWord
#X LZUnsquash

Constants

F = 18

Log2TLZSSWord = 2

#Z+} { This unit is ready for use with Dj. Murdoch's ScanHelp utility which will make a Borland .TPH file for it. } {#Z-

LZRWBufSize = 32000{8192}

#Z-

LZSSMemRequired = SizeOf(TLZRWBuffer)*2 + SizeOf(TBinaryTree)

N = 4096

Read Buffer Size } {#Z+

Nul = N*SizeOf(TLZSSWord)

Threshold = 2


Variables

BinaryTree : PBinaryTree = nil

CodeBuf : array[0..16] of Byte

Height : TLZSSWord

InBufP : PLZRWBuffer = nil

InBufPtr : TLZSSWord = LZRWBufSize

InBufSize : TLZSSWord = LZRWBufSize

IsLZInitialized : boolean = False

#X LZUnsquash} {#Z+

LastLen : TLZSSWord

LZReadProc : TReadProc

LZWriteProc : TWriteProc

MatchLen : TLZSSWord

MatchPos : TLZSSWord

OutBufP : PLZRWBuffer = nil

OutBufPtr : TLZSSWord = 0