function AA(bmp:tbitmap;haeufigkeit:integer;intensitaet:integer;backgroundcolor:tcolor):real;
var
x,y,i:integer;
col2,col4,col5,col6,col8,c1,c2,c3:tcolor;
background:tcolor;
relevance,r,g,b:integer;
b1,b2,b3,b4:pbytearray;
//Zeitmessung
freq: Int64;
startTime: Int64;
endTime: Int64;
tempbmp:tbitmap;
begin
QueryPerformanceFrequency(freq);
QueryPerformanceCounter(startTime);
//Zeitmessung
background:=backgroundcolor;
relevance:=intensitaet+1;
if bmp.PixelFormat<>pf24bit
then
bmp.PixelFormat:=pf24bit;
tempbmp:=tbitmap.Create;
tempbmp.Assign(bmp);
for i:=1
to haeufigkeit
do begin
for y:=bmp.Height-2
downto 1
do begin
// ____________
// <-| b1| b1| b1|->
// <-|___|___|___|->
// <-| b2| b2| b2|->
// <-|___|___|___|->
// <-| b3| b3| b3|->
// <-|___|___|___|->
b1:=bmp.ScanLine[y-1];
b2:=bmp.ScanLine[y];
b3:=bmp.ScanLine[y+1];
b4:=tempbmp.ScanLine[y];
for x:=1
to bmp.Width-2
do begin
// ____________
// | | 2 | |
// |___|___|___|
// | 4 | 5 | 6 |
// |___|___|___|
// | | 8 | |
// |___|___|___|
//pixel mitte-oben
r:=b1[(x)*3+2];
g:=b1[(x)*3+1];
b:=b1[(x)*3+0];
col2:=
rgb(r,g,b);
//pixel mitte-links
r:=b2[(x-1)*3+2];
g:=b2[(x-1)*3+1];
b:=b2[(x-1)*3+0];
col4:=
rgb(r,g,b);
//pixel mitte-mitte
r:=b2[(x)*3+2];
g:=b2[(x)*3+1];
b:=b2[(x)*3+0];
col5:=
rgb(r,g,b);
//pixel mitte-rechts
r:=b2[(x+1)*3+2];
g:=b2[(x+1)*3+1];
b:=b2[(x+1)*3+0];
col6:=
rgb(r,g,b);
//pixel unten-mitte
r:=b3[(x)*3+2];
g:=b3[(x)*3+1];
b:=b3[(x)*3+0];
col8:=
rgb(r,g,b);
// ____________
// | | 2 | |
// |___|___|___|
// | 4 | 5 | |
// |___|___|___|
// | | | |
// |___|___|___|
c1:=col2;
c2:=col4;
if (c1<>col5)
and (c2<>col5)
and (col5=background)
then begin
b4[x*3+2]:=(getrvalue(c1)+getrvalue(c2)+getrvalue(col5)*relevance)
div (3+relevance);
b4[x*3+1]:=(getgvalue(c1)+getgvalue(c2)+getgvalue(col5)*relevance)
div (3+relevance);
b4[x*3+0]:=(getbvalue(c1)+getbvalue(c2)+getbvalue(col5)*relevance)
div (3+relevance);
end;
// ____________
// | | 2 | |
// |___|___|___|
// | | 5 | 6 |
// |___|___|___|
// | | | |
// |___|___|___|
c1:=col2;
c2:=col6;
if (c1<>col5)
and (c2<>col5)
and (col5=background)
then begin
b4[x*3+2]:=(getrvalue(c1)+getrvalue(c2)+getrvalue(col5)*relevance)
div (3+relevance);
b4[x*3+1]:=(getgvalue(c1)+getgvalue(c2)+getgvalue(col5)*relevance)
div (3+relevance);
b4[x*3+0]:=(getbvalue(c1)+getbvalue(c2)+getbvalue(col5)*relevance)
div (3+relevance);
end;
// ____________
// | | | |
// |___|___|___|
// | 4 | 5 | |
// |___|___|___|
// | | 8 | |
// |___|___|___|
c1:=col8;
c2:=col4;
if (c1<>col5)
and (c2<>col5)
and (col5=background)
then begin
b4[x*3+2]:=(getrvalue(c1)+getrvalue(c2)+getrvalue(col5)*relevance)
div (3+relevance);
b4[x*3+1]:=(getgvalue(c1)+getgvalue(c2)+getgvalue(col5)*relevance)
div (3+relevance);
b4[x*3+0]:=(getbvalue(c1)+getbvalue(c2)+getbvalue(col5)*relevance)
div (3+relevance);
end;
// ____________
// | | | |
// |___|___|___|
// | | 5 | 6 |
// |___|___|___|
// | | 8 | |
// |___|___|___|
c1:=col8;
c2:=col6;
if (c1<>col5)
and (c2<>col5)
and (col5=background)
then begin
b4[x*3+2]:=(getrvalue(c1)+getrvalue(c2)+getrvalue(col5)*relevance)
div (3+relevance);
b4[x*3+1]:=(getgvalue(c1)+getgvalue(c2)+getgvalue(col5)*relevance)
div (3+relevance);
b4[x*3+0]:=(getbvalue(c1)+getbvalue(c2)+getbvalue(col5)*relevance)
div (3+relevance);
end;
end;
end;
bmp.Assign(tempbmp);
end;
//Zeitmessung
QueryPerformanceCounter(endTime);
result:=(endTime - startTime) * 1000 / freq;
//Zeitmessung
end;
procedure TForm1.BAAClick(Sender: TObject);
begin
Lzeit.Caption :=
floattostr(AA(image1.Picture.Bitmap,spinedit_haeufigkeit.Value,spinedit_intensitaet.Value,clblack))+'
ms';
end;