我写的图像放大线性插入在执行时用的时间太长了,比人家的卷积法时间都长。
那位高手能帮我看看代码吗?
function Scale2(cnv:TCanvas;scale:double):TBitmap;
var
w,h: Integer;
i,j,m,n: Integer;
x,y:integer;
neww,newh:integer;
xt,yt:double;
color: LongInt;
xx,yy: array[0..1] of integer;
r,g,b: array[0..1,0..1] of byte;
red,green,blue :byte;
u,v:double;
bmp:TBitmap;
begin
bmp:=TBitmap.Create ; w := cnv.ClipRect.Right -cnv.ClipRect.Left;
h := cnv.Cliprect.Bottom-cnv.Cliprect.Top ; neww:=Trunc(w*scale+0.5);
newh:=Trunc(h*scale+0.5); bmp.Width :=neww-1;
bmp.Height :=newh-1; for i:=0 to newh-1 do
begin
yt:=i/scale;
y:=Trunc(yt);
v:=yt-y; for j:=0 to neww-1 do
begin
xt:=j/scale;
x:=Trunc(xt);
u:=xt-x; xx[0]:=x;
xx[1]:=x+1;
if x=neww-1 then xx[1]:=x; yy[0]:=y;
yy[1]:=y+1;
if y=newh-1 then yy[1]:=y; for m:=0 to 1 do
begin
for n:=0 to 1 do
begin
color := ColorToRGB(cnv.Pixels[xx[n], yy[m]]);
b[n,m] := (Color and $FF0000) shr 16;
g[n,m] := (Color and $FF00) shr 8;
r[n,m] := (Color and $FF);
end;
end ;
red:=Trunc((1-u)*(1-v)*r[0][0]+(1-u)*v*r[0][1]+u*(1-v)*r[1][0]+u*v*r[1][1]);
green:=Trunc((1-u)*(1-v)*g[0][0]+(1-u)*v*g[0][1]+u*(1-v)*g[1][0]+u*v*g[1][1]);
blue:=Trunc((1-u)*(1-v)*b[0][0]+(1-u)*v*b[0][1]+u*(1-v)*b[1][0]+u*v*b[1][1]);
bmp.Canvas.Pixels[j,i]:=RGB(red, green, blue);
end;
end ;
result:=bmp;
end;
那位高手能帮我看看代码吗?
function Scale2(cnv:TCanvas;scale:double):TBitmap;
var
w,h: Integer;
i,j,m,n: Integer;
x,y:integer;
neww,newh:integer;
xt,yt:double;
color: LongInt;
xx,yy: array[0..1] of integer;
r,g,b: array[0..1,0..1] of byte;
red,green,blue :byte;
u,v:double;
bmp:TBitmap;
begin
bmp:=TBitmap.Create ; w := cnv.ClipRect.Right -cnv.ClipRect.Left;
h := cnv.Cliprect.Bottom-cnv.Cliprect.Top ; neww:=Trunc(w*scale+0.5);
newh:=Trunc(h*scale+0.5); bmp.Width :=neww-1;
bmp.Height :=newh-1; for i:=0 to newh-1 do
begin
yt:=i/scale;
y:=Trunc(yt);
v:=yt-y; for j:=0 to neww-1 do
begin
xt:=j/scale;
x:=Trunc(xt);
u:=xt-x; xx[0]:=x;
xx[1]:=x+1;
if x=neww-1 then xx[1]:=x; yy[0]:=y;
yy[1]:=y+1;
if y=newh-1 then yy[1]:=y; for m:=0 to 1 do
begin
for n:=0 to 1 do
begin
color := ColorToRGB(cnv.Pixels[xx[n], yy[m]]);
b[n,m] := (Color and $FF0000) shr 16;
g[n,m] := (Color and $FF00) shr 8;
r[n,m] := (Color and $FF);
end;
end ;
red:=Trunc((1-u)*(1-v)*r[0][0]+(1-u)*v*r[0][1]+u*(1-v)*r[1][0]+u*v*r[1][1]);
green:=Trunc((1-u)*(1-v)*g[0][0]+(1-u)*v*g[0][1]+u*(1-v)*g[1][0]+u*v*g[1][1]);
blue:=Trunc((1-u)*(1-v)*b[0][0]+(1-u)*v*b[0][1]+u*(1-v)*b[1][0]+u*v*b[1][1]);
bmp.Canvas.Pixels[j,i]:=RGB(red, green, blue);
end;
end ;
result:=bmp;
end;
解决方案 »
- ■■ 高分求助 内存映射文件 不成功!■■
- GetFocus 取得的究竟是哪一个窗体的句柄?!
- 在D7编写的Dll中 长字符串 用什么数据类型
- 自已编写的控件,如果要在KeyDown事件中监听键盘的事件需要设置什么。
- 运行时拖动TGraphicControl的代码
- 进者有分——关于delphi7
- 怎么样实现可以对一个Label象在DELPHI中的设计器那样操作?
- 我想找份兼职(杭州)
- 动态创建的菜单,如何动态调用已有的窗体,我把窗体的名称保存在数据库里,可以读菜单ID 时一块读出窗体名称
- 数据库的备份问题?
- 哪个网站可以下载delphi控件的图标?
- 那位大哥可以告诉我INI文件究竟怎么用,具体点。
color := ColorToRGB(cnv.Pixels[xx[n], yy[m]]);
b[n,m] := (Color and $FF0000) shr 16;
g[n,m] := (Color and $FF00) shr 8;
r[n,m] := (Color and $FF);
这么写的读取RGB代码本身效率就低,更别说后面的运算了。
想节省时间必须用Scanline方法,详细请看图形版的斑竹置顶的帖子。
begin
SetStretchBltMode(DestCanvas.Handle,HALFTONE); // !!!
DestCanvas.CopyRect(DestRect,SrcCanvas,SrcRect);
end;