高手请进:(附源码),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;
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;
...全文
相关推荐
PID位置环和速度环源码
此部分代码是以编码器反馈来控制电机的速度和位置。利用PID来调整马达的转速和位置,尤其适合研究平衡小车的朋友参考和借鉴。
任意角度旋转图像源码
基于C++ Builder 的任意角度旋转位图源码,已经测试,好用
椭圆旋转源码
单张图片实现加速3D旋转效果,只用GDI+哦 另PS:本人深圳,欲换个工作 联系QQ:120148245
串口发送角度值控制舵机旋转角度并在LCD上显示旋转角度和PWM设定值.zip
单片机串口发送角度控制舵机转动角度附 带源码仿真图。
旋转倒立摆常规起摆源码.zip
里面是旋转倒立摆实现的源码,包含了代码详细注释,非常适合学习pid的新手入门学习。可以借鉴或者改写该源码作为自己的控制代码,也适用于其他项目的开发


语言基础/算法/系统设计
