3
3cs
Unregistered / Unconfirmed
GUEST, unregistred user!
例子如下:我用它作800*600的BMP图片的处理,速度太慢了 >80毫秒!
现在的要求是<15毫秒!谁能帮我,测试的机器(CPU1。2G,内存256) 只要能帮我优化到现在4-5倍的处理速度,200分马上奉上!
procedure bmpSmooth(mybitmap: tbitmap; smoothlevel: byte; x1,y1,x2,y2: integer);
var
p,p1,p2: pbytearray;
i,j: integer;
thew,theh: integer;
s1,s2,s3: integer;
rvalue: integer;
gvalue: integer;
bvalue: integer;
tmpbitmap: tbitmap;
maxnum,minnum: integer;
begin
tmpbitmap:=tbitmap.create;
tmpbitmap.assign(mybitmap);
with mybitmap do
begin
thew:=width;
theh:=height;
if (x1=x2) or (y1=y2) then
begin
x1:=2;
y1:=2;
x2:=thew-2;
y2:=theh-2;
end
else
begin
minnum:=min(y1,y2);
maxnum:=max(y1,y2);
y1:=minnum;
y2:=maxnum;
minnum:=min(x1,x2);
maxnum:=max(x1,x2);
x1:=minnum;
x2:=maxnum;
end;
if x1<2 then x1:=2;
if y1<2 then y1:=2;
if x2>thew-2 then x2:=thew-2;
if y2>theh-2 then y2:=theh-2;
for i:=y1 to y2 do
begin
p:=ScanLine;
p1:=tmpbitmap.scanline[i-1];
p2:=tmpbitmap.scanline[i+1];
for j:=x1 to x2 do
begin
s1:=j*3;
s2:=j*3+1;
s3:=j*3+2;
case smoothlevel of
1: begin // 轻微
rvalue:=(p[s3]*3+p[s3-3]+p[s3+3]+p1[s3]+p1[s3-3]+p1[s3+3]+
p2[s3]+p2[s3-3]+p2[s3+3]) div 11;
gvalue:=(p[s2]*3+p[s2-3]+p[s2+3]+p1[s2]+p1[s2-3]+p1[s2+3]+
p2[s2]+p2[s2-3]+p2[s2+3]) div 11;
bvalue:=(p[s1]*3+p[s1-3]+p[s1+3]+p1[s1]+p1[s1-3]+p1[s1+3]+
p2[s1]+p2[s1-3]+p2[s1+3]) div 11;
end;
2: begin // 普通
rvalue:=(p[s3]*2+p[s3-3]+p[s3+3]+p1[s3]+p1[s3-3]+p1[s3+3]+
p2[s3]+p2[s3-3]+p2[s3+3]) div 10;
gvalue:=(p[s2]*2+p[s2-3]+p[s2+3]+p1[s2]+p1[s2-3]+p1[s2+3]+
p2[s2]+p2[s2-3]+p2[s2+3]) div 10;
bvalue:=(p[s1]*2+p[s1-3]+p[s1+3]+p1[s1]+p1[s1-3]+p1[s1+3]+
p2[s1]+p2[s1-3]+p2[s1+3]) div 10;
end;
3: begin // 加强
rvalue:=(p[s3]+p[s3-3]+p[s3+3]+p1[s3]+p1[s3-3]+p1[s3+3]+
p2[s3]+p2[s3-3]+p2[s3+3]) div 9;
gvalue:=(p[s2]+p[s2-3]+p[s2+3]+p1[s2]+p1[s2-3]+p1[s2+3]+
p2[s2]+p2[s2-3]+p2[s2+3]) div 9;
bvalue:=(p[s1]+p[s1-3]+p[s1+3]+p1[s1]+p1[s1-3]+p1[s1+3]+
p2[s1]+p2[s1-3]+p2[s1+3]) div 9;
end;
else
begin
rvalue:=p[s3];
gvalue:=p[s2];
bvalue:=p[s1];
end;
end;
p[s3]:=rvalue;
p[s2]:=gvalue;
p[s1]:=bvalue;
end;
end;
end;
tmpbitmap.free;
end;
现在的要求是<15毫秒!谁能帮我,测试的机器(CPU1。2G,内存256) 只要能帮我优化到现在4-5倍的处理速度,200分马上奉上!
procedure bmpSmooth(mybitmap: tbitmap; smoothlevel: byte; x1,y1,x2,y2: integer);
var
p,p1,p2: pbytearray;
i,j: integer;
thew,theh: integer;
s1,s2,s3: integer;
rvalue: integer;
gvalue: integer;
bvalue: integer;
tmpbitmap: tbitmap;
maxnum,minnum: integer;
begin
tmpbitmap:=tbitmap.create;
tmpbitmap.assign(mybitmap);
with mybitmap do
begin
thew:=width;
theh:=height;
if (x1=x2) or (y1=y2) then
begin
x1:=2;
y1:=2;
x2:=thew-2;
y2:=theh-2;
end
else
begin
minnum:=min(y1,y2);
maxnum:=max(y1,y2);
y1:=minnum;
y2:=maxnum;
minnum:=min(x1,x2);
maxnum:=max(x1,x2);
x1:=minnum;
x2:=maxnum;
end;
if x1<2 then x1:=2;
if y1<2 then y1:=2;
if x2>thew-2 then x2:=thew-2;
if y2>theh-2 then y2:=theh-2;
for i:=y1 to y2 do
begin
p:=ScanLine;
p1:=tmpbitmap.scanline[i-1];
p2:=tmpbitmap.scanline[i+1];
for j:=x1 to x2 do
begin
s1:=j*3;
s2:=j*3+1;
s3:=j*3+2;
case smoothlevel of
1: begin // 轻微
rvalue:=(p[s3]*3+p[s3-3]+p[s3+3]+p1[s3]+p1[s3-3]+p1[s3+3]+
p2[s3]+p2[s3-3]+p2[s3+3]) div 11;
gvalue:=(p[s2]*3+p[s2-3]+p[s2+3]+p1[s2]+p1[s2-3]+p1[s2+3]+
p2[s2]+p2[s2-3]+p2[s2+3]) div 11;
bvalue:=(p[s1]*3+p[s1-3]+p[s1+3]+p1[s1]+p1[s1-3]+p1[s1+3]+
p2[s1]+p2[s1-3]+p2[s1+3]) div 11;
end;
2: begin // 普通
rvalue:=(p[s3]*2+p[s3-3]+p[s3+3]+p1[s3]+p1[s3-3]+p1[s3+3]+
p2[s3]+p2[s3-3]+p2[s3+3]) div 10;
gvalue:=(p[s2]*2+p[s2-3]+p[s2+3]+p1[s2]+p1[s2-3]+p1[s2+3]+
p2[s2]+p2[s2-3]+p2[s2+3]) div 10;
bvalue:=(p[s1]*2+p[s1-3]+p[s1+3]+p1[s1]+p1[s1-3]+p1[s1+3]+
p2[s1]+p2[s1-3]+p2[s1+3]) div 10;
end;
3: begin // 加强
rvalue:=(p[s3]+p[s3-3]+p[s3+3]+p1[s3]+p1[s3-3]+p1[s3+3]+
p2[s3]+p2[s3-3]+p2[s3+3]) div 9;
gvalue:=(p[s2]+p[s2-3]+p[s2+3]+p1[s2]+p1[s2-3]+p1[s2+3]+
p2[s2]+p2[s2-3]+p2[s2+3]) div 9;
bvalue:=(p[s1]+p[s1-3]+p[s1+3]+p1[s1]+p1[s1-3]+p1[s1+3]+
p2[s1]+p2[s1-3]+p2[s1+3]) div 9;
end;
else
begin
rvalue:=p[s3];
gvalue:=p[s2];
bvalue:=p[s1];
end;
end;
p[s3]:=rvalue;
p[s2]:=gvalue;
p[s1]:=bvalue;
end;
end;
end;
tmpbitmap.free;
end;