www.pudn.com > wavecode.rar > coder_bp_zt.c


/***** 
 
coder_BP :  
 
	could get more speed out of arithc and scontext 
 
*****/ 
 
#include  
#include  
#include  
#include  
#include  
#include "coder.h" 
 
extern int tune_param; 
 
#define bitModel(bit,P0,PT)		do { PT += INC; if (!(bit)) P0 += INC;  if ( PT > TOTMAX ) { PT >>= 1; P0 >>= 1; P0++; PT += 2; } } while(0) 
#define bitEnc(bit,ari,P0,PT)	do { arithEncBit(ari,P0,PT,bit);	bitModel(bit,P0,PT); } while(0) 
#define bitDec(bit,ari,P0,PT)	do { bit = arithDecBit(ari,P0,PT);	bitModel(bit,P0,PT); } while(0) 
 
#define INC		20 
#define TOTMAX	4000 
 
#define ORDER1_CONTEXTS		5 
#define ORDER1_ALPHABET		16	//4 bits 
 
#define ORDER1_TOTMAX		15000 
#define ORDER1_INC			30 
 
void coderBPZT_encodeBandZT(coder *me,int *band,int width,int height,int bits,int fullw,int **rows); 
void coderBPZT_decodeBandZT(coder *me,int *band,int width,int height,int bits,int fullw,int **rows); 
 
typedef struct { 
	scontext ** o1; 
	int zeros_p0[ORDER1_CONTEXTS],zeros_pt[ORDER1_CONTEXTS]; 
} myInfo; 
 
void coderBPZT_init(coder *c) 
{ 
myInfo *d; 
int i; 
 
	if ( (d = new(myInfo)) == NULL ) 
		errexit("ozero init failed"); 
 
	c->data = d; 
 
	if ( (d->o1 = newarray(void *,ORDER1_CONTEXTS)) == NULL ) 
		errexit("Order1_Init failed!"); 
 
	for(i=0;io1[i] = scontextCreate(c->arith,ORDER1_ALPHABET,0, 
				ORDER1_TOTMAX,ORDER1_INC,true)) == NULL ) 
			errexit("context creation failed!"); 
 
		d->zeros_p0[i] = 1; d->zeros_pt[i] = 2; 
	} 
} 
 
void coderBPZT_free(coder *c) 
{ 
	if ( c->data ) { 
		myInfo *d; 
		d = c->data; 
		if ( d->o1 ) { 
			int i; 
			for(i=0;io1[i] ) scontextFree(d->o1[i]); 
			} 
		} 
		free(d); 
		c->data = NULL; 
	} 
} 
 
coder coderBPZT = { 
		"BP ZeroTree", 
		coderBPZT_init, 
		coderBPZT_free, 
		NULL,NULL,NULL,NULL, 
		coderBPZT_encodeBandZT, 
		coderBPZT_decodeBandZT 
	}; 
 
void coderBPZT_encodeBandZT(coder *me,int *band,int width,int height,int bits,int fullw,int **rows) 
{ 
int x,y,context,block; 
int *dp,*dpn; 
scontext **o1 = ((myInfo *)me->data)->o1; 
arithInfo *ari = me->arith; 
int donemask,nextmask,bitmask; 
int *zeros_p0,*zeros_pt; 
bool bottom; 
 
	zeros_p0 = ((myInfo *)me->data)->zeros_p0; 
	zeros_pt = ((myInfo *)me->data)->zeros_pt; 
 
	if ( width == (fullw>>1) ) bottom = true; 
	else bottom = false; 
 
	bitmask = 1<data)->o1; 
arithInfo *ari = me->arith; 
int donemask,nextmask,bitmask; 
int offwidth,offheight,*children; 
int bit,tx,ty; 
int *zeros_p0,*zeros_pt; 
bool bottom; 
 
	zeros_p0 = ((myInfo *)me->data)->zeros_p0; 
	zeros_pt = ((myInfo *)me->data)->zeros_pt; 
 
	if ( width == (fullw>>1) ) bottom = true; 
	else bottom = false; 
 
	bitmask = 1<