www.pudn.com > xiaobo.zip.zip > wt_codeutil.c


#include  
#include  
 
void cu_putEscaping_byte(int val,ubyte **streamp) 
{ 
ubyte *stream = *streamp; 
	while ( val >= 0xFF ) { 
		*stream++ = val; 
		val -= 0xFF; 
	} 
	*stream++ = val; 
*streamp = stream; 
} 
 
int  cu_getEscaping_byte(ubyte **streamp) 
{ 
ubyte *stream = *streamp; 
int ret,val; 
	ret = 0; 
	do { 
		val = *stream++; 
		ret += val; 
	} while( val == 0xFF ); 
*streamp = stream; 
return ret; 
} 
 
void cu_putEscaping_bii(int val,struct LBitIOInfo *stream,int escape_bits)	/** escape of (1<= escape) { 
		LBitIO_WriteBits(stream,escape,escape_bits); 
		val -= escape; 
	} 
	LBitIO_WriteBits(stream,val,escape_bits); 
} 
 
int  cu_getEscaping_bii(struct LBitIOInfo *stream,int escape_bits) 
{ 
int escape,ret,val; 
	escape = (1<= escape) { 
		arithEncode(stream,escape,escape+1,escape+1); 
		val -= escape; 
	} 
	arithEncode(stream,val,val+1,escape+1); 
} 
 
int  cu_getEscaping_ari(arithInfo *stream,int escape) 
{ 
int ret,val; 
	ret = 0; 
	do { 
		val = arithGet(stream,escape+1); 
		arithDecode(stream,val,val+1,escape+1); 
		ret += val; 
	} while ( val == escape); 
return ret; 
} 
 
void cu_putExpanding_bii(int val,struct LBitIOInfo *stream,int init_bits,int step_bits) 
{ 
int bits; 
ulong mask; 
 
	bits = init_bits; 
	mask = (1<= mask ) { 
		LBitIO_WriteBits(stream,mask,bits); 
		val -= mask; 
		bits += step_bits; if ( bits > 31 ) bits = 31; 
		mask = (1<= escape ) { 
		arithEncode(stream,escape,escape+1,escape+1); 
		val -= escape; 
		escape += step_max; 
		if ( escape > stream->safeProbMax ) escape = stream->safeProbMax; 
	} 
	arithEncode(stream,val,val+1,escape+1); 
} 
 
int  cu_getExpanding_ari(arithInfo *stream,int init_max,int step_max) 
{ 
int escape,ret,val; 
 
	escape = init_max; 
	ret = 0; 
	for(;;) { 
		val = arithGet(stream,escape+1); 
		arithDecode(stream,val,val+1,escape+1); 
		ret += val; 
		if ( val != escape ) 
			break; 
		escape += step_max; 
	} 
 
return ret; 
} 
 
 
 
void cu_putMulting_ari(int val,arithInfo *stream,int init_max,int step_mult) 
{ 
int max; 
 
	max = init_max; 
	while ( val >= max ) { 
		arithEncBitRaw(stream,1); 
		val -= max; 
		max *= step_mult; 
		if ( max > stream->safeProbMax ) max = stream->safeProbMax; 
	} 
	arithEncBitRaw(stream,0); 
	arithEncode(stream,val,val+1,max); 
} 
 
int  cu_getMulting_ari(arithInfo *stream,int init_max,int step_mult) 
{ 
int max,ret; 
 
	max = init_max; 
	ret = 0; 
	for(;;) { 
		if ( ! arithDecBitRaw(stream) ) { 
			int val; 
			val = arithGet(stream,max); 
			arithDecode(stream,val,val+1,max); 
			return ret+val; 
		} 
		ret += max; 
		max *= step_mult; 
		if ( max > stream->safeProbMax ) max = stream->safeProbMax; 
	} 
}