LZS无损压缩encoder

发布时间:

1Encode
Algorithm1Encodealgorithm1:procedureEncode2:whileinputdataexistsdo3:Readbyte4:ifthereisnomatchingpatterninthehistorybuffertheextractlymatchesthesourcepaternintheholdingbuffer,thatalsosatisfilesthecon-ditionthatoffsetless2047then5:Outputtoken6:endif7:endwhile8:Flush
9:endprocedure
1

2Readbyte
Algorithm2Readbytealgorithm1:procedureReadbyte2:Get8-bitfromtheinputstream3:Insertbyteintohistorybuffer4:Insertbyteintoholdingbuffer5:endprocedure
2

3Outputtoken
Algorithm3Outputtokenalgorithm1:procedureOutputtoken2:ifnumberofbytesinhodlingbuffer2then3:Putsingle0bittooutputbitstream4:Putoldestbyteinholdingbuffertooutputstream5:Cleartheoldestbytefromtheholdingbuffer6:elseif7:thenPutsingle1bittooutputbitstream8:ifOffset127then9:Putsingle1bittooutputbitstream10:Put7-bitbinaryvalueofoffsettooutputstream11:elseif12:thenPutsingle0bittooutputbitstream13:Put11-bitbinaryvalueofoffsettooutputstream14:endif15:Outputlength16:Clearallbytesfromtheholdingbufferexceptthenewestbyte17:endif
18:endprocedure
3

4Outputlength
Algorithm4Outputlengthalgorithm1:procedureOutputlength2:Xnumberofbytesinholdingbuffer13:ifX4then4:Put2-bitbinaryvalueof(X-2tooutputstream5:elseif6:ifthenthenX77:Put2-bitpatternwithallbitssettoa1bittooutputstream8:Put2-bitbinaryvalueof(X-5tooutputstream9:elseif10:thenPut4-bitpatternwithallbitssettoa1bittooutputstream11:XX812:whileX15do13:Put4-bitpatternwithallbitssetto1bittooutputstream14:XX1515:endwhile16:endif17:endif
18:endprocedure
4

5Offset
Algorithm5Offsetalgorithm
1:procedureOffsetReturnthevalueof(thedistanceinbyteswithinthehistorybufferfromthefirstbyteofthesourcepatterntothefirstbyteofthematchingpattern.2:endprocedure
5

6Flush
Algorithm6Flushalgorithm1:procedureFlush2:whilenumberofbytesinholdingbuffer>0do3:Outputtoken4:endwhile5:Put9-bitpatternwithb8andb9setto1sandbitsb1throughb7to0stooutputstream6:ifdesiredtoclearthehistorythen7:Clearallbytefromthehistorybuffer8:endif
9:endprocedure
6

LZS无损压缩encoder

相关推荐