www.pudn.com > xiaobo.zip.zip > coder_o0.c
#include#include #include #include #include #define TOT_MAX 4000 #define ALPHABET 128 #define ESCAPE (ALPHABET-1) #include "coder.h" void coderOzero_encodeBand(coder *me,int *band,int w,int h,int fullw,int *parent); void coderOzero_decodeBand(coder *me,int *band,int w,int h,int fullw,int *parent); #include struct O0coderInfoNew { struct FAI * arith; long numChars; context * order0; }; void coderOzero_init(coder *me) { if ( (me->data = ozeroCreateMax(me->arith,ALPHABET,TOT_MAX)) == NULL ) errexit("ozero init failed"); } void coderOzero_free(coder *me) { ozero *oz; oz = (ozero *)me->data; if ( oz ) { int p,c; for(c=0;c order0,c+1) - 1; if ( p > 0 ) printf("%3d : %d\n",c,p); } printf("tot : %d\n",contextGetCumProb(((struct O0coderInfoNew *)oz)->order0,ALPHABET)-ALPHABET); ozeroFree(oz); } } coder coderOzero = { "order 0", coderOzero_init, coderOzero_free, coderOzero_encodeBand, coderOzero_decodeBand }; void coderOzero_encodeBand(coder *me,int *band,int width,int height,int fullw,int *parent) { int x,y,v,sign; int *dp; ozero *oz = me->data; arithInfo *ari = me->arith; dp = band; for(y=0;y = ESCAPE ) { ozeroEncode(oz,ESCAPE); v -= ESCAPE; } ozeroEncode(oz,v); arithBit(ari,sign); } dp += (fullw - width); } } void coderOzero_decodeBand(coder *me,int *band,int width,int height,int fullw,int *parent) { int x,y,v,got; int *dp; arithInfo *ari = me->arith; ozero *oz = me->data; dp = band; for(y=0;y