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

📄 coder_o0.c

📁 用C++语言实现的基于小波分析的源代码,实现了小波分析的诸多算法
💻 C
字号:
#include <stdio.h>
#include <stdlib.h>
#include <crblib/inc.h>
#include <crblib/arithc.h>
#include <crblib/o0coder.h>

#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 <crblib/context.h>

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<ALPHABET;c++) {
			p = contextGetProb(((struct O0coderInfoNew *)oz)->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<height;y++) {
		if ( coder_timetostop(me) ) { coder_didstop(me,y); return; }
		for(x=width;x--;) {
			v = *dp++;
			if ( v == 0 ) {
				ozeroEncode(oz,0);
				continue;
			} else if ( isneg(v) ) { sign = 1; v = -v; 
			} else sign = 0;

			while( v >= 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<height;y++) {
		if ( coder_timetostopd(me,y) ) { dbf(); return; }
		for(x=width;x--;) {
			got = ozeroDecode(oz);
			if ( got == 0 ) {
				*dp++ = 0;
				continue;
			}
			v=0;
			while ( got == ESCAPE ) {
				v+=ESCAPE;
				got = ozeroDecode(oz);
			}
			v+=got;

			if ( arithGetBit(ari) ) v = -v;
			*dp++ = v;
		}
		dp += (fullw - width);
	}
}

⌨️ 快捷键说明

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