SDL: rescale jpeg surface.

Started by
5 comments, last by ministromayor 15 years, 7 months ago
I'm trying to rescale a surface obtained via IMG_LoadJPG_RW with zoomSurface with and whithout smooting and mi app crash with segmentation fault. I'm sure my stack is fine, at least with my code.
Advertisement
Show us the code you use, please?
The code involved with the problem:

Sorry: Class & object & method names in spanish. ;-)

imgmgr.h :

SDL_Surface *imagen;
SDL_RWops *rwop;

imgmgr.cpp :

AdministradorImagenes::
AdministradorImagenes()
{
imagen = NULL;
rwop = NULL;
}

SDL_Surface *AdministradorImagenes::
cargaImagen(char *ruta)
{
rwop = SDL_RWFromFile(ruta, "rb");
imagen = IMG_LoadJPG_RW(rwop);
return imagen;
}

SDL_Surface *AdministradorImagenes::
cargaQImagen(char *ruta)
{
SDL_Surface *orig = cargaImagen(ruta);
double w = orig->w/4;
double h = orig->h/4;
SDL_Surface *resc = zoomSurface(orig, w, h, SMOOTHING_OFF);
return resc;
}

principal.cpp :

AdministradorImagenes img_adm;
foto = img_adm.cargaQImagen(argv[1]);

Several of those functions can return NULL, such as SDL_RWFromFile or IMG_LoadJPG_RW. You should be checking for that first.
Yes! I have checked, no NULL returned. In fact, if I don't try to zoom the Surface the image is shown, but out of bounds. obviously.
Perhaps you could run the application in a debugger and find out exactly where the segmentation fault is.
I have already checked with debuger (gdb) I know exactly where the error ocurrs:

SDL_Surface *resc = zoomSurface(orig, w, h, SMOOTHING_OFF);

I left SDL_image and i'm using jpeglib instead. Now I have a SDL_Surface with my thumbnail but whith some problems, doesn't matters I'll deal with this errors by myself.

SDL_image creates an SDL_Surface with the jpeg image in a 1:1 scale. then I preferr to scale at loading time directly with jpeglib.

however, If somebody knows how to rescale an existing SDL_Surface with pixels within...

This topic is closed to new replies.

Advertisement