高手请进:(附源码),256色旋转算法速度问题:角度越大,速度越慢.(原因是内存颠簸造成,)
procedure Rotate(Bmp:Pointer;BMPWidth,BMPHeight,cx,cy:Integer;Dst:Pointer;DstWidth,DSTHeight:integer;Angle:Double);
var
x,y,
dx,dy,
sdx,sdy,
xDiff,yDiff,
isinTheta,
icosTheta: Integer;
SrcTmp:PByteArray;
DstTmp: PByte;
sinTheta,
cosTheta,
Theta: Double;
x_1,y_1:Integer;
calcfirstx,calcfirsty:Double;
begin
Theta:=-Angle*Pi/180;
sinTheta:=Sin(Theta);
cosTheta:=Cos(Theta);
xDiff:=(DstWidth-BmpWidth)div 2;
yDiff:=(DstHeight-BmpHeight)div 2;
isinTheta:=Round(sinTheta*$10000);
icosTheta:=Round(cosTheta*$10000);
DstTmp:=PByte(DST);
SrcTmp:=PByteArray(BMP);
x_1:=DstWidth-1;
y_1:=DstHeight-1;
calcfirstx:=cx-cx*cosTheta+cy*sinTheta-xDiff;
calcfirsty:=cy-cx*sinTheta-cy*cosTheta-yDiff;
for y:=y_1-100 downto 0 do
begin
sdx:=Round((calcfirstx-y*sinTheta)*$10000);
sdy:=Round((calcfirsty+y*cosTheta)*$10000);
for x:=x_1 downto 0 do
begin
dx:=sdx shr 16;
dy:=sdy shr 16;
if(dy<BMPHeight)and(dx<BMPWidth) then
begin
DstTmp^:=SrcTMP[dx+dy*BMPWidth];//<<--------------此处角度大时内存颠簸严重(图像大小:2048*1536)
end;
inc(sdx,icosTheta);
inc(sdy,isinTheta);
Inc(DstTmp);
end;
end;
end;