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

📄 coder_none.c

📁 小波变换算法
💻 C
字号:
#include <stdlib.h>
#include <string.h>
#include <crblib/inc.h>
#include <crblib/arithc.h>

#include "coder.h"

void coderNone_encodeBand(coder *me,int *band,int w,int h,int fullw,int *parent);
void coderNone_decodeBand(coder *me,int *band,int w,int h,int fullw,int *parent);

void coderNone_init(coder *me) { }
void coderNone_free(coder *me) { }

#define RANGE	32
#define ESCAPE	(RANGE-1)

coder coderNone = {
		"none",
		coderNone_init,
		coderNone_free,
		coderNone_encodeBand,
		coderNone_decodeBand
	};

void coderNone_encodeBand(coder *me,int *band,int width,int height,int fullw,int *parent)
{
int x,y,v,sign;
int *dp;
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 ) {
				arithEncode(ari,0,1,RANGE);
				continue;
			} else if ( isneg(v) ) { sign = 1; v = -v; 
			} else sign = 0;

			while( v >= ESCAPE ) {
				arithEncode(ari,ESCAPE,RANGE,RANGE);
				v -= ESCAPE;
			}
			arithEncode(ari,v,v+1,RANGE);
			
			arithBit(ari,sign);
		}
		dp += (fullw - width);
	}
}

void coderNone_decodeBand(coder *me,int *band,int width,int height,int fullw,int *parent)
{
int x,y,v,got,sign;
int *dp;
arithInfo *ari = me->arith;

	dp = band;
	for(y=0;y<height;y++) {
		if ( coder_timetostopd(me,y) ) { dbf(); return; }
		for(x=width;x--;) {
			got = arithGet(ari,RANGE);
			arithDecode(ari,got,got+1,RANGE);
			if ( got == 0 ) {
				*dp++ = 0;
				continue;
			}
			v=0;
			while ( got == ESCAPE ) {
				v+=ESCAPE;
				got = arithGet(ari,RANGE);
				arithDecode(ari,got,got+1,RANGE);
			}
			v+=got;

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

⌨️ 快捷键说明

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