haar.c

来自「VC小波算法2,高效率VC小波算法2」· C语言 代码 · 共 72 行

C
72
字号
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <crblib/inc.h>

void haar_Transform2D(int **rows, int width, int height, int levels,bool inverse)
{
int *plane,*line,*nextline;
int step,step2,x,y,ll_width;
int a,b,c,d,A,B,C,D;

	ll_width = width>>levels;
	plane = rows[0];

	if ( ! inverse ) {

		for(step=1;step<=ll_width;step<<=1) {
			step2 = step + step;
			for(y=0;(y+step)<height;y += step2) {
				line = plane + y*width;
				nextline = line + step*width;
				for(x=0;(x+step)<width;x += step2) {

					a = line[x]; b = line[x+step];
					c = nextline[x]; d = nextline[x+step];

					A = (a+b+c+d)>>2;
					B = a-b-c+d;
					C = a+b-c-d;
					D = a-b+c-d;

					line[x] 			= A; // will be coded in next pass
					line[x+step]		= B;
					nextline[x]			= C;
					nextline[x+step]	= D;
				}
			}
		}

	} else {

		/** go backwards in scale **/
		for(step=ll_width;step>=1;step>>=1) {
			step2 = step + step;

			for(y=0;(y+step)<height;y += step2) {

				line = plane + y*width;
				nextline = line + step*width;

				for(x=0;(x+step)<width;x += step2) {

					A = line[x]; // already decoded.
					B = line[x+step];
					C = nextline[x];
					D = nextline[x+step];

					a = A + ((3 + B + C + D)>>2);
					b = A + ((3 - B + C - D)>>2);
					c = A + ((3 - B - C + D)>>2);
					d = A + ((3 + B - C - D)>>2);

					line[x]			= a;
					line[x+step]	= b;
					nextline[x] 	= c;
					nextline[x+step]= d;
				}
			}
		}
	}
}

⌨️ 快捷键说明

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