SDL Digest, Vol 19, Issue 57

Message: 7
Message-ID: <4889DBAA.1070005 at>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Use the rotozoom feature of SDL_gfx. :stuck_out_tongue:

Andre Botelho wrote:

is there a fast way to resize images on SDL?

SDL mailing list
SDL at

Message: 8
Message-ID: <789951.74947.qm at>
Content-Type: text/plain; charset=“utf-8”

You can also do it by hand copying pixel per pixel …
But you need to know a little bit of direct access to pixels,
algorithmic, and antialiasing for zoom in.

To give an idea, if you divide an image size by two, you
simply copy pixels with an even x and y coordinate.
This is a very simply example, it is not so straightforward
when the destination size is not an exact divisor of the original size …
(or only the width, not the height and vice versa).

When you make an image bigger, aliasing appear and you need
to apply an antialiasing filter to it (neighbours, gauss, etc.).

If you want to play and learn new things, try doing it by hand, else,
as Andre suggested, use a library having this feature implemented for you,
like SDL_gfx.


I’m trying to strech a surface, i’ve tried rotozoom but it doesn’t work and
how I was interested on the scaling thing I tried one code posted on the
tutorial at but it?s sooo
slow that my proc usage goes to 100% in only a 1,2% strech of a 320x240
Here is the code:

SDL_Surface *ScaleSurface(SDL_Surface *Surface, Uint16 Width, Uint16 Height)
if(!Surface || !Width || !Height)
return 0;

SDL_Surface *_ret = SDL_CreateRGBSurface(Surface->flags, Width, Height,

Surface->format->Rmask, Surface->format->Gmask,
Surface->format->Bmask, Surface->format->Amask);

double  _stretch_factor_x = (static_cast<double>(Width)  /

_stretch_factor_y = (static_cast(Height) /

for(Sint32 y = 0; y < Surface->h; y++)
    for(Sint32 x = 0; x < Surface->w; x++)
        for(Sint32 o_y = 0; o_y < _stretch_factor_y; ++o_y)
            for(Sint32 o_x = 0; o_x < _stretch_factor_x; ++o_x)
                DrawPixel(_ret, static_cast<Sint32>(_stretch_factor_x *

x) + o_x,
static_cast(_stretch_factor_y * y) + o_y,
ReadPixel(Surface, x, y));
return _ret;

Can anyone tell me why is it so slow?
OBS: the prog tries to get 60FPS.> Date: Fri, 25 Jul 2008 08:56:58 -0500

From: Leo Cabrera
Subject: Re: [SDL] Image resize
To: "A list for developers using the SDL library. (includes
Date: Fri, 25 Jul 2008 14:06:48 +0000 (GMT)
From: julien CLEMENT
Subject: [SDL] Re : Image resize
To: "A list for developers using the SDL library. (includes

The fastest way is to use hardware acceleration through OpenGL or DirectX. The easiest is to use Sprig or SDL_gfx. I’m not sure that your computer can handle stretching an image of that size at 60hz. Try a lower framerate. My stuff runs real smooth at 40hz, but I try to use 33 for speed. Either way, you’re saving megabytes of data transfer each second.Sprig: can use SPG_TransformSurface to draw on a pre-existing surface (with colorkey too!). That saves an extra copy and delete in many cases.Jonny D