mirror of
https://github.com/MacPaw/XADMaster.git
synced 2025-08-29 19:43:47 +02:00
Page:
SitxRangeCoder
Pages
AlZipSpecs
ArchiveFormatSpecs
CompactProLzhAlgorithm
CompactProSpecs
CompressAlgorithm
Deflate64Algorithm
Disassembling68KMacExecutables
DiskDoublerAdAlgorithm
DiskDoublerAlgorithm2
DiskDoublerDdAlgorithm
DiskDoublerSpecs
Home
InfoZipAppnoteAdditions
LzwAlgorithm
MacBinarySpecs
Rle8182Algorithm
Rle90Algorithm
SitxBlendAlgorithm
SitxBrimstoneAlgorithm
SitxCyanideAlgorithm
SitxDarkhorseAlgorithm
SitxDeflateAlgorithm
SitxEnglishPreprocessingAlgorithm
SitxIronAlgorithm
SitxJpegAlgorithm
SitxRangeCoder
SitxSpecs
StuffIt5Format
StuffItAlgorithm13
StuffItAlgorithm3
StuffItArsenicAlgorithm
StuffItFormat
StuffItSpecs
SupportedFormats
VersionTwoAlphaTest
WARC Specs
WinZipJpegErrata
XadMasterApiDocumentation
ZipSpecs
No results
1
SitxRangeCoder
Paul Taykalo edited this page 2018-03-09 17:43:00 +02:00
Table of Contents
Overview
The range coder used in all sitx compressors is functionally similar to Dmitry Subbotin's carryless rangecoder from the PPMd project.
Initialization
low=0;
code=0;
range=-1;
for(int i=0;i<4;i++) code=(code<<8)|NextByteFromStream();
Fetching a symbol
Here, freqtable
is an array of symbol frequencies, and num
is the number of symbols.
unsigned int totalfreq=0;
for(int i=0;i<num;i++) totalfreq+=freqtable[i];
range=range/totalfreq;
unsigned int tmp=(code-low)/range;
unsigned int cumulativefreq=0;
unsigned int n=0;
while(n<num-1 && cumulativefreq+freqtable[n]<=tmp)
{
cumulativefreq+=freqtable[n++];
}
low=low+range*cumulativefreq;
range=range*freqtable[n];
The index of the decoded symbol is n
. This is followed by normalization:
Normalization
for(;;)
{
if( (low^(low+range))>=0x1000000 )
{
if(range>=0x10000) break;
else range=-low&0xffff;
}
code=(code<<8) | NextByteFromStream();
range=range<<8;
low=low<<8;
}