⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wt_codeutil.c

📁 好东西呢
💻 C
字号:
#include <crblib/inc.h>
#include <crblib/codeutil.h>

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_bits) **/
{
int escape;
	escape = (1<<escape_bits) - 1;
	while(val >= 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_bits) - 1;
	ret = 0;
	do {
		LBitIO_ReadBits(stream,val,escape_bits);
		ret += val;
	} while ( val == escape);
return ret;
}

void cu_putEscaping_ari(int val,arithInfo *stream,int escape)	/** escape of (1<<escape_bits) **/
{
	while(val >= 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<<bits) - 1;
	while(val >= mask ) {
		LBitIO_WriteBits(stream,mask,bits);
		val -= mask;
		bits += step_bits; if ( bits > 31 ) bits = 31;
		mask = (1<<bits) - 1;
	}
	LBitIO_WriteBits(stream,val,bits);
}

int  cu_getExpanding_bii(struct LBitIOInfo *stream,int init_bits,int step_bits)
{
int bits,ret,val;
ulong mask;

	bits = init_bits;
	ret = 0;
	do {
		mask = (1<<bits) - 1;
		LBitIO_ReadBits(stream,val,bits);
		bits += step_bits;
		ret += val;
	} while( val == mask);

return ret;
}


void cu_putExpanding_ari(int val,arithInfo *stream,int init_max,int step_max)
{
int escape;

	escape = init_max;
	while(val >= 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;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -