高斯模糊

procedure Effect_GaussianBlur(Amount:integer;Picture:TBitmap);

var BB:TBitmap;

begin

BB :=TBitmap.Create;

BB.PixelFormat :=pf24bit;

BB.Assign(Picture.Bitmap);

GaussianBlur(BB,Amount);

Picture.Bitmap.Assign(BB);

BB.Free;

end;

procedure GaussianBlur(var clip:TBitmap;Amount:integer);

var

i:integer;

begin

for i:=Amount downto 0 do

SplitBlur(clip,3);

end;

procedure SplitBlur(var clip:TBitmap;Amount:integer);

var

p0,p1,p2:PByteArray;

cx,x,y:integer;

Buf:array[0..3,0..2] of byte;

begin

if Amount=0 then Exit;

for y:=0 to clip.Height-1 do

begin

if y-Amount<0 then

p1:=clip.Scanline[y]

else

p1:=clip.Scanline[y-Amount];

if y+Amount<clip.Height then

p2:=clip.Scanline[y+Amount]

else

p2:=clip.Scanline[clip.Height-y]

for x:=0 to clip.Width-1 do

begin

if x-Amount<0 then cx:=x;

Buf[0,0]:=p1[cx*3];

Buf[0,1]:=p1[cx*3+1];

Buf[0,2]:=p1[cx*3+2];

Buf[1,0]:=p2[cx*3];

Buf[1,1]:=p2[cx*3+1];

Buf[1,2]:=p2[cx*3+2];

if x+Amount<clip.Width then

cx:=x+Amount

else

cx:=clip.Width-x;

Buf[2,0]:=p1[cx*3];

Buf[2,1]:=p1[cx*3+1];

Buf[2,2]:=p1[cx*3+2];

Buf[3,0]:=p1[cx*3];

Buf[3,1]:=p1[cx*3+1];

Buf[3,2]:=p1[cx*3+2];

p0[x*3+1]:=(Buf[0,1]+Buf[1,1]+Buf[2,1]+Buf[3,1]) shr 2;

p0[x*3+2]:=(Buf[0,2]+Buf[1,2]+Buf[2,2]+Buf[3,2]) shr 2;

end;

end;

end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值