📄 arithc._h
字号:
#ifndef ARITHC_INTERNAL_H
#define ARITHC_INTERNAL_H
/* consts from Michael Schindler */
#define CODE_BITS 31
#define SHIFT_BITS (CODE_BITS - 8)
#define CODE_BYTES ((CODE_BITS+7)/8)
#define PRECISION_BITS 9 // coding is done to this accuracy (in terms of range>>PRECISION_BITS)
#define MinRange ((ulong)1<<SHIFT_BITS)
#define One ((ulong)1<<CODE_BITS)
#define CumProbMax (MinRange>>PRECISION_BITS)
#define CODE_MASK (One - 1)
#define EXTRA_BITS ((CODE_BITS-1) % 8 + 1) // == 7 == CODE_BITS - (8*(CODE_BYTES-1))
#define TAIL_EXTRA_BITS (8 - EXTRA_BITS) // == 1
// extra_bits are the bits in "code" that don't quite fit in bytes
//--------------------------------------------------------------
//--- range normalizers for encoder & decoder; also does the IO
void INLINE arithEncRenorm(arithInfo * ari,ulong code,ulong range)
{
assert( range <= One );
while( range <= MinRange )
{
ulong byte;
byte = (code >> SHIFT_BITS);
if ( byte == 0xFF )
{
/** the waiting queue is incremented like :
* (ari->queue), 0xFF, 0xFF, ... ,0xFF, code
***/
ari->overflow_bytes++;
}
else
{
ulong carry;
carry = code>>CODE_BITS;
/* carry == 1 or 0 : is the top bit on ?
* carry = byte>>8
* if ( carry ) send nextbyte+1
* MinRange queue with zeros
* else send nextbyte
* MinRange queue with ones
**/
*(ari->outPtr)++ = (ubyte)(ari->queue + carry); // propagate the carry.
// send the queue
if ( ari->overflow_bytes )
{
*(ari->outPtr)++ = (ubyte)(0xFF + carry);
while ( --(ari->overflow_bytes) ) *(ari->outPtr)++ = (ubyte)(0xFF + carry);
}
ari->queue = byte;
}
code = (code<<8) & CODE_MASK;
range <<= 8;
}
assert( range <= One );
ari->code = code;
ari->range = range;
}
void INLINE arithDecRenorm(arithInfo * ari,ulong *pcode,ulong *prange)
{
ulong range,code;
range = ari->range;
code = ari->code;
assert( range <= One );
while ( range <= MinRange )
{
range <<= 8;
code = (code<<8) + (((ari->queue)<<EXTRA_BITS)&0xFF); // use the top bit in the queue
ari->queue = *(ari->outPtr)++;
code += (ari->queue) >> (TAIL_EXTRA_BITS);
}
assert( range <= One );
*prange = range;
*pcode = code;
}
#endif // ARITHC_INTERNAL_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -