欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

图像特效之波浪特效

程序员文章站 2022-05-28 22:06:50
...

图像特效之波浪特效

1.关键代码

/*
*Function: 波浪特效
*/


int Wave(IMAGE_TYPE *BMP24_img,int degree)
{
	int X,Y;
	DWORD width,height,x,y,bfsize;
	WORD  biBitCount = 3;
	T_U8 *dst_data,*bmp,*img_data;
	T_U32 line_byte,src_Imgindex,dst_Imgindex;
	double PI_2;
	
	BITMAPFILEHEADER bf;
	BITMAPINFOHEADER bi;
	
	FILE *Wave_fp = fopen("Wave.bmp","wb");
	
	if(NULL == Wave_fp)
	{
		printf("Can't open Wave.bmp\n");
		return -1;
	}
	
	if (degree < 1) degree = 1;
	if (degree > 32) degree = 32;
	
	
	memset(&bf, 0, sizeof(bf));
	memset(&bi, 0, sizeof(bi));
	
	bmp = BMP24_img;
	memcpy(&bf,bmp,14);
	memcpy(&bi,&bmp[14],40);
	
	fwrite(&bf,sizeof(BITMAPFILEHEADER),1,Wave_fp);
	fwrite(&bi,sizeof(BITMAPINFOHEADER),1,Wave_fp);
	
	height = bi.biHeight;
	width  = bi.biWidth;
	bfsize = bf.bfSize;
	biBitCount = bi.biBitCount;
	line_byte =  (width*3+3) & ~0x3;
	img_data = bmp+54;
	PI_2 = PI*2;
	
	dst_data = (T_U8 *)malloc(line_byte*height);
	if (NULL == dst_data)
	{
		printf("Can't malloc for dst image!\n");
		return -1;
	}
	memset(dst_data,0,line_byte*height);
	
	
	for(y = 0; y < height; y+= 1)
	{
		dst_Imgindex = y*line_byte;
		for(x=0; x <width; x+= 1)
		{
			
			X = (int)(degree*cos(y*PI_2/128.0))+x;
			Y = (int)(degree*sin(x*PI_2/128.0))+y;
			
			if (X >= width) X = width-1;
			if (X < 0)	   X = 0;
			if (Y >= height)Y = height-1;
			if (Y < 0)	   Y = 0;
			
			src_Imgindex = Y*line_byte+3*X;
			
			dst_data[dst_Imgindex] = img_data[src_Imgindex];
			dst_data[dst_Imgindex+1] = img_data[src_Imgindex+1];
			dst_data[dst_Imgindex+2] = img_data[src_Imgindex+2];
			
			dst_Imgindex +=3;
		}
	}
	
	
	fwrite(dst_data,line_byte*height,1,Wave_fp);
	fclose(Wave_fp);
	Wave_fp = NULL;
	free(dst_data);
	return 0;
}

2.图像效果

图像特效之波浪特效图像特效之波浪特效