Hi!

I've only had a look at SDL, and I've never really used it, but here are few ideas how could speed-up your function:


1) If SDL had someting like SDL_GetPixels(source_surface, source_rect, memory_buffer_1), then you could do all transformations in memory and after that you call SDL_AddPixels(dest_surface, dest_rect, memory_buffer_2).


2) Try avoiding floating operations. For example, you can do something like:

aSin, aCos: Longint

aCos := Round (degCOS[Angle] * 1024);
aSin := (degSIN[Angle] * 1024);

And then you do

NX := mx + (RX * aSin + RY * aCos) shr 10;
NY := my + (RY * aSin - RX * aCos) shr 10;


3) You should put

if ((DX > 0) and (DX < MAXX)) and
((DY > 0) and (DY < MAXY)) then

outside the loop - you first find limits for DX and DY, and then you loop between them.


4) Little trick: Change

if (NX >= srcRect.x) and (NX <= srcRect.x + srcRect.w) then

to

if (UInt32(NX - srcRect.x) <= UInt32(srcRect.w)) then

Also do the same with NY.


5) You can completely avoid SX and SY from your calculations:
SX := 0 -> RX := -OX
Inc(SX) -> Inc(RX)
SY := 0 -> RY := -OY
Inc(SY) -> Inc(RY)


Well, those are few thoughts that come to my mind. Hope they will help


Best regards
Alexa