您的位置:首页 > 其它

高斯模糊算法 c源码.

2011-12-19 17:32 387 查看
SPGUI(Simple Powerfull Graphics User Interface)是使用简单、功能强大的嵌入式图形开发系统。主要为开发嵌入式LINUX图形窗口应用提供工具集。她具有美观友好的图形控件,面向对像的编程接口,多平台可移植性等特点SPGUI为设计运行于嵌入式设备,个人电脑及工作站平台的图形窗口应用程序,提供一个完整的开发平台。她的核心是为应用程序提供资源库及编译链接环境,开发者使用SPGUI提供的资源及环境,来开发自己的应用程序。SPGUI为应用程序设计者提供的资源包括:嵌入式图形引擎,图形控件,数据库引擎,底层驱动封装,常用数据结构封装及中文支持等

SPGUI是源码级高度可移植的,
目前经过本人的努力已经移植到window xp 使用vc 2005开发(可称作:模拟器),开发出来的程序只需要在嵌入式平台编译就可运行.
同时也扩展了如下功能.
图片支持 png ,gif, bmp,jpg
字库管理 freetype 矢量字库 ,fnt字库
压缩 zip
脚本 xml expat
窗口框架 : ems ui( 下个文章更新 )
提供帮助:124736442@qq.com

言归正传.

先看效果图

之前



之后



高斯模糊算法 c源码.

颜色信息是565 可修改到 rgb888 argb 以及灰度的处理.

//---------------------------------------------------------------------------------

// 124736442@qq.com

//

//

//图象的平滑(去噪声)、锐化

//

//

//---------------------------------------------------------------------------------

#include <mach/effect.h>

#include <mach/datatype.h>

enum EFFECT_TYPE{

SMOOTH_BOX = 0,

SMOOTH_GAUSS,

SHARPEN_LL

};

//template array

SINT32 Smooth_Box[10]={1,1,1,1,1,1,1,1,1,3};

SINT32 Smooth_Gauss[10]={1,2,1,2,4,2,1,2,1,4};

SINT32 Sharpen_Laplacian[10]={-1,-1,-1,-1,9,-1,-1,-1,-1,1};

SINT32 Bitmap_SmoothDeal(spBitmap_t *p,spRect_t *rect,int type)

{

SINT32 *tEffect = NULL;

UINT8 *stpos;

UINT16 *pbg;

int r,g,b,Index,row,col;

int x;int y;

UINT8 r1,g1,b1;

UINT32 colorref;

UINT32 sumcol;

switch(type)

{

case SMOOTH_BOX:

tEffect = Smooth_Box;

break;

case SMOOTH_GAUSS:

tEffect = Smooth_Gauss;

break;

case SHARPEN_LL:

tEffect = Sharpen_Laplacian;

break;

default:

return SP_FAIL;

}

stpos = (UINT8 *)( p->pData + (rect->x*p->bpl/p->width + rect->y*p->bpl) );

for(y = 1 ; y<rect->height-1;y++)

for( x = 1;x <rect->width-1;x++)

{

r=0,g=0,b=0;

Index=0;

sumcol = 0 ;

for(col=-1;col<=1;col++)

{

pbg = (UINT16*)(stpos+(y+col)*p->bpl);

for(row=-1;row<=1;row++)

{

colorref=pbg[x+row];

RGB_FROM_RGB565(colorref,r1,g1,b1);

r+=r1*tEffect[Index];

g+=g1*tEffect[Index];

b+=b1*tEffect[Index];

Index++;

}

}

r>>=tEffect[Index];//调节亮度.

g>>=tEffect[Index];

b>>=tEffect[Index];

RGB565_FROM_RGB(colorref,r,g,b);

pbg[x] = (UINT16)colorref;

}

return SP_OK;

}

SINT32 effect_do(spBitmap_t *image,spRect_t *rect,SINT32 type)

{

spRect_t tRect;

if(image == NULL)

return SP_FAIL;

if(rect==NULL){

tRect.x = tRect.y = 0 ;

tRect.width = image->width;

tRect.height = image->height;

}

else

tRect = *rect;

//check rect

tRect.x = tRect.x <0 ?0:tRect.x;

tRect.y = tRect.y <0 ?0:tRect.y;

tRect.width = tRect.width >image->width ?image->width:tRect.width;

tRect.height = tRect.height >image->height?image->height:tRect.height;

//do effect

switch(type)

{

case SMOOTH_BOX:

case SMOOTH_GAUSS:

case SHARPEN_LL:

//return SP_OK;

Bitmap_SmoothDeal(image,&tRect,type);

break;

}

return SP_OK;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: