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

📄 haar2.c

📁 it s very value.it can help you to learn matlab and vavelet .
💻 C
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <crblib/inc.h>

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

	if ( levels == 0 ) return;

	ll_width = width>>levels;
	block = 1<<levels;
	plane = rows[0];

	if ( ! inverse ) {

		for(bx=0;bx<width;bx += block) {
			for(by=0;by<height;by += block) {
				base = rows[by] + bx;

				for(step=1;step<block;step<<=1) {
					step2 = step + step;
					for(y=0;y<block;y += step2) {
						line = base + y*width;
						nextline = line + step*width;
						for(x=0;x<block;x += step2) {
							a = line[x]; 		c = nextline[x];
							b = line[x+step];	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;	nextline[x]			= C;
							line[x+step]		= B;	nextline[x+step]	= D;				
						}
					}
				}
			}
		}

	} else {

		for(bx=0;bx<width;bx += block) {
			for(by=0;by<height;by += block) {
				base = rows[by] + bx;

#define un_haar_quartet(line,nextline,step)								\
							A = line[0]; 		C = nextline[0];		\
 							B = line[step];		D = nextline[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[0]		= a;	nextline[0] 	= c;	\
 							line[step]	= b;	nextline[step]	= d;		
 /** un_haar_quartet() **/

				switch(levels) {
					case 0: break;
					case 1:
						line = base;	nextline = base + width;
						un_haar_quartet(line,nextline,1);
						break;
					case 2:
						line = base;	nextline = base + width+width;
						un_haar_quartet(line,nextline,2);

						line = base;	nextline = base + width;
						un_haar_quartet(line,nextline,1);
						line += 2; nextline += 2;
						un_haar_quartet(line,nextline,1);
						line += width+width; nextline += width+width;
						un_haar_quartet(line,nextline,1);
						line -= 2; nextline -= 2;
						un_haar_quartet(line,nextline,1);
						break;
					case 3:
						step = 4; step2 = step+step;
						line = base;	nextline = line + step*width; 
						un_haar_quartet(line,nextline,step);

						step = 2; step2 = step+step;
						line = base;	nextline = line + step*width; 
						un_haar_quartet(line,nextline,step);
						line += step2; nextline += step2;
						un_haar_quartet(line,nextline,step);
						line += width*step2; nextline += width*step2;
						un_haar_quartet(line,nextline,step);
						line -= step2; nextline -= step2;
						un_haar_quartet(line,nextline,step);

						step = 1; step2 = step+step;
						line = base;	nextline = line + width; 
						un_haar_quartet(line,nextline,step);
						line += step2; nextline += step2;
						un_haar_quartet(line,nextline,step);
						line += step2; nextline += step2;
						un_haar_quartet(line,nextline,step);
						line += step2; nextline += step2;
						un_haar_quartet(line,nextline,step);
						line = base+width*2;	nextline = line + width; 
						un_haar_quartet(line,nextline,step);
						line += step2; nextline += step2;
						un_haar_quartet(line,nextline,step);
						line += step2; nextline += step2;
						un_haar_quartet(line,nextline,step);
						line += step2; nextline += step2;
						un_haar_quartet(line,nextline,step);
						line = base+width*4;	nextline = line + width; 
						un_haar_quartet(line,nextline,step);
						line += step2; nextline += step2;
						un_haar_quartet(line,nextline,step);
						line += step2; nextline += step2;
						un_haar_quartet(line,nextline,step);
						line += step2; nextline += step2;
						un_haar_quartet(line,nextline,step);
						line = base+width*6;	nextline = line + width; 
						un_haar_quartet(line,nextline,step);
						line += step2; nextline += step2;
						un_haar_quartet(line,nextline,step);
						line += step2; nextline += step2;
						un_haar_quartet(line,nextline,step);
						line += step2; nextline += step2;
						un_haar_quartet(line,nextline,step);
						break;

					default:

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

							for(y=0;y<block;y += step2) {

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

								for(x=0;x<block;x += step2) {

									A = line[x]; 			C = nextline[x];
									B = line[x+step];		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;	nextline[x] 	= c;
									line[x+step]	= b;	nextline[x+step]= d;
								}
							}
						}
					break;
				}

			}
		}
	}
}

⌨️ 快捷键说明

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