Image resize

is there a fast way to resize images on SDL?

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 lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Message: 7
SDL-announce)"
Message-ID: <4889DBAA.1070005 at gmail.com>
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 lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Message: 8
SDL-announce)"
Message-ID: <789951.74947.qm at web28607.mail.ukl.yahoo.com>
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.

Regards

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 http://www.sdltutorials.com/sdl-scale-surface/ but it?s sooo
slow that my proc usage goes to 100% in only a 120% strech of a 320x240
surface.
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->BitsPerPixel,
Surface->format->Rmask, Surface->format->Gmask,
Surface->format->Bmask, Surface->format->Amask);

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

static_cast(Surface->w)),
_stretch_factor_y = (static_cast(Height) /
static_cast(Surface->h));

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.---------- Forwarded message ----------
From: @Andre_Botelho (Andre Botelho)
Date: 2008/7/25
Subject: Re: SDL Digest, Vol 19, Issue 57
To: sdl at lists.libsdl.org

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

Eww… What happened to my formatting?

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:
http://pubpages.unh.edu/~jmb97/SPriG.html

You 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

try to not allocate a new surface every time. Save the surface, and reuse it.

That should go at least 2x faster, probably more.On Sat, Jul 26, 2008 at 12:41 AM, Andre Botelho wrote:

---------- Forwarded message ----------
From: Andre Botelho
Date: 2008/7/25
Subject: Re: SDL Digest, Vol 19, Issue 57
To: sdl at lists.libsdl.org

Message: 7
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
SDL-announce)”
Message-ID: <4889DBAA.1070005 at gmail.com>
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 lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Message: 8
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
SDL-announce)”
Message-ID: <789951.74947.qm at web28607.mail.ukl.yahoo.com>
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.

Regards

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 http://www.sdltutorials.com/sdl-scale-surface/ but it?s sooo
slow that my proc usage goes to 100% in only a 120% strech of a 320x240
surface.
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->BitsPerPixel,
Surface->format->Rmask, Surface->format->Gmask,
Surface->format->Bmask, Surface->format->Amask);

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

static_cast(Surface->w)),
_stretch_factor_y = (static_cast(Height) /
static_cast(Surface->h));

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.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org