Assuming you don’t care about quality, (and that you’re not asking about
something already built into an SDL module…I’ve only been playing with
SDL for a couple of days now.)
For scaling, the fastest alg is nearest neighbor. For rotation, it’s 2
skews (one X, one Y, using nearest neighbor).
Assuming you’ll be doing it in fixed-point and not knowing about your
CPU or memory organization, here’s some pseudo-code:
Scale:-----------
incX=width_of_input/width_of_output; /* fixed point /
incY=height_of_input/height_of_output; / fixed point /
inputX=0; / fixed point /
inputY=0; / fixed point */
for(outY=0;outY<height_of_output;outY++) {
for(outX=0;outX<width_of_output;outX++) {
inX=truncate_fixed_to_int(inputX);
inY=truncate_fixed_to_int(inputY);
pixelOut[outY][outX]=pixelIn[inY][inX];
inputX+=incX;
} /* end of X loop */
inputY+=incY;
} /* end of Y loop */
To scale from a different center point, start with inputX and inputY
set to something other than (0,0).
Rotate:
incX=cos_of_angle_shift_in_fixed_pixels(angle); /* fixed point /
incY=sin_of_angle_shift_in_fixed_pixels(angle); / fixed point /
inputX=0; / fixed point /
inputY=0; / fixed point */
startX=0;
startY=0;
for(outY=0;outY<height_of_output;outY++) {
inputX=startX;
inputY=startY;
for(outX=0;outX<width_of_output;outX++) {
inX=truncate_fixed_to_int(inputX);
inY=truncate_fixed_to_int(inputY);
pixelOut[outY][outX]=pixelIn[inY][inX];
inputX+=incX;
inputY+=incY;
} /* end of X loop */
startX+=incX;
startY+=incY;
} /* end of Y loop */
To do both at the same time, you can combine the source look-ups. Also,
with the rotate, the numbers can be negative. To rotate around a
different location, set startX/Y.
Keep in mind both pseduo-code snippets above don’t have any clipping.
You’ll probably need that for at least the rotation.
Hope that helps…
-Pat
Guilherme Campos Hazan wrote:
Hi folks,
I’m searching for the fastest possible not-asm code for scale and rotation of a
bitmap (separately).
I already saw the rotozoom, but it is a little complex and big, and the author
states that it is not optimized.
Why i need speed? The target device has 17Mhz.
Many thanks
guich
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl