孤独的猫

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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;

posted on 2008-09-10 21:51  孤独的猫  阅读(191)  评论(0编辑  收藏  举报