Resize image?

Hello!

I got to do a function here that creates a copy of an image but with
bigger size. I dont want to make it bigger (scretch), only want it to resize! I
am using PNG images with alpha, the mouth and eyes are transparents! I
made it with Gimp:

But I got problems! The image is not how it should be, it is all white!

Here is how I am doing it:

loadedImage = IMG_Load(path); // I test to see if it loaded right, I removed to make it smaller
surface = SDL_DisplayFormatAlpha(loadedImage);
SDL_FreeSurface(loadedImage);
surface = redImage(surface->w2,surface->h2,surface);

SDL_Surface* redImage(int w,int h,SDL_Surface* src)
{
SDL_Surface* ret = SDL_CreateRGBSurface(src->flags,w,h,src->format->BitsPerPixel,
src->format->Rmask,src->format->Gmask,src->format->Bmask,src->format->Amask);
if (!ret)
return src;
SDL_BlitSurface(src,NULL,ret,NULL);
SDL_FreeSurface(src);
SDL_Surface* surface = SDL_DisplayFormatAlpha(ret);
SDL_FreeSurface(ret);
return surface;
}
I fell that I am making something wrong, tryed many things but nothing seems to work! Whats wrong with it?

Thank you!From: http://img41.imageshack.us/img41/8241/imagemqat.png
To: http://img178.imageshack.us/img178/4120/imagem2l.png


Deixe suas conversas mais divertidas. Baixe agora mesmo novos emoticons. ? gr?tis!
http://specials.br.msn.com/ilovemessenger/pacotes.aspx

I got to do a function here that creates a copy of an image but with
bigger size. I dont want to make it bigger (scretch), only want it to resize!

what is the difference between stretching and resizing ? i assume stretch
( correct aspect ratio ) is resizing?

mattOn Mon, 3 Aug 2009, Bruno Adami wrote:

I think he just wants to extend the width and height of a surface. I
don’t see anything wrong at first glance…

Jonny DOn Mon, Aug 3, 2009 at 9:08 PM, wrote:

On Mon, 3 Aug 2009, Bruno Adami wrote:

I got to do a function here that creates a copy of an image but with
bigger size. I dont want to make it bigger (scretch), only want it to
resize!

what is the difference between stretching and resizing ? ?i assume stretch (
correct aspect ratio ) is resizing?

matt


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

Have you tried changing your call to SDL_CreateRGBSurface to parameters like the following :
SDL_CreateRGBSurface(0,w,h,32,0,0,0,0)

try it out and see if it works. I often find that if you are going to call SDL_DisplayFormat/Alpha it is better to just work with a plain 32 bit blank surface.

Give it a shot, and it just might work…
-Dave----- Original Message -----
From: Bruno Adami
To: sdl at lists.libsdl.org
Sent: Monday, August 03, 2009 3:56 PM
Subject: [SDL] Resize image?

Hello!

I got to do a function here that creates a copy of an image but with bigger size. I dont want to make it bigger (scretch), only want it to resize! I am using PNG images with alpha, the mouth and eyes are transparents! I made it with Gimp:

From: http://img41.imageshack.us/img41/8241/imagemqat.png
To: http://img178.imageshack.us/img178/4120/imagem2l.png

But I got problems! The image is not how it should be, it is all white!
Here is how I am doing it:

…loadedImage = IMG_Load(path); // I test to see if it loaded right, I removed to make it smallersurface = SDL_DisplayFormatAlpha(loadedImage);SDL_FreeSurface(loadedImage);surface = redImage(surface->w2,surface->h2,surface);…SDL_Surface* redImage(int w,int h,SDL_Surface* src){ SDL_Surface* ret = SDL_CreateRGBSurface(src->flags,w,h,src->format->BitsPerPixel, src->format->Rmask,src->format->Gmask,src->format->Bmask,src->format->Amask); if (!ret) return src; SDL_BlitSurface(src,NULL,ret,NULL); SDL_FreeSurface(src); SDL_Surface* surface = SDL_DisplayFormatAlpha(ret); SDL_FreeSurface(ret); return surface;}I fell that I am making something wrong, tryed many things but nothing seems to work! Whats wrong with it?

Thank you!


Novo Internet Explorer 8: mais r?pido e muito mais seguro. Baixe agora, ? gr?tis!



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

Jonathan thats exactly what I am trying to do!

Dave, I tryed it, but the weird thing is that with some images it works, and with others it just stays all white!

I attached the testing code and the images, with zombie.png and building.png it works fine (the background stays black, it should be transparent), but with ambulance.png and city.png there is nothing on the image!

Lines 37 and 42 of Main.cpp have you testing the size of a freed
surface. This might be fine, but it scares me a little…

Jonny DOn Tue, Aug 4, 2009 at 8:36 AM, Bruno Adami<a_j_bruno at hotmail.com> wrote:

Jonathan thats exactly what I am trying to do!

Dave, I tryed it, but the weird thing is that with some images it works, and
with others it just stays all white!

I attached the testing code and the images, with zombie.png and building.png
it works fine (the background stays black, it should be transparent), but
with ambulance.png and city.png there is nothing on the image!

  • Bruno

Instale o novo Internet Explorer 8 vers?o especial para o MSN. Download aqui


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

Oh, sorry about that, I made this code on a rush, attached it again. But same results…_________________________________________________________________
Conhe?a os novos produtos Windows Live! Clique aqui.
http://www.windowslive.com.br
-------------- next part --------------
A non-text attachment was scrubbed…
Name: Main.cpp
Type: application/octet-stream
Size: 1690 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20090804/ff7bd24d/attachment.obj

2009/8/3 Bruno Adami <a_j_bruno at hotmail.com>:

Hello!

I got to do a function here that creates a copy of an image but with bigger
size. I dont want to make it bigger (scretch), only want it to resize! I am
using PNG images with alpha, the mouth and eyes are transparents! I made it
with Gimp:

But I got problems! The image is not how it should be, it is all white!
Here is how I am doing it:


loadedImage = IMG_Load(path); // I test to see if it loaded right, I removed
to make it smaller
surface = SDL_DisplayFormatAlpha(loadedImage);
SDL_FreeSurface(loadedImage);
surface = redImage(surface->w2,surface->h2,surface);

SDL_Surface* redImage(int w,int h,SDL_Surface* src)
{
SDL_Surface* ret =
SDL_CreateRGBSurface(src->flags,w,h,src->format->BitsPerPixel,

src->format->Rmask,src->format->Gmask,src->format->Bmask,src->format->Amask);
if (!ret)
return src;
SDL_BlitSurface(src,NULL,ret,NULL);
SDL_FreeSurface(src);
SDL_Surface* surface = SDL_DisplayFormatAlpha(ret);
SDL_FreeSurface(ret);
return surface;
}

I fell that I am making something wrong, tryed many things but nothing seems
to work! Whats wrong with it?

try this:

SDL_Surface* loadedImage = IMG_Load(path);
SDL_PixelFormat* format = loadedImage->format;
SDL_Surface* tmp = SDL_CreateRGBSurface(
SDL_SWSURFACE | SDL_SRCALPHA,
loadedImage->w2, loadedImage->h2,
format->BitsPerPixel,
format->Rmask, format->Gmask, format->Bmask, format->Amask
);
SDL_FillRect(tmp, NULL, SDL_MapRGBA(tmp->format, 0, 0, 0, 0));
SDL_SetSurfaceScaleMode(loadedImage, SDL_TEXTURESCALEMODE_FAST);
SDL_SoftStretch(loadedImage, NULL, tmp, NULL);
SDL_Surface* biggerImage = SDL_DisplayFormatAlpha(tmp);
SDL_FreeSurface(tmp);
SDL_FreeSurface(loadedImage);

SDL_FreeSurface(biggerImage);

You should be able to trim that down a bit. If using SDL 1.2, leave
out SDL_SetSurfaceScaleMode. If using C instead of C++, declare all
variables at the start of the function.

If you can’t get SDL_SoftStrech to work, either do it yourself (by
manually copying each pixel in the source surface to a 2x2 pixel
square in the destination) or use SDL_GFX or some other add on
library.> From: http://img41.imageshack.us/img41/8241/imagemqat.png

To: http://img178.imageshack.us/img178/4120/imagem2l.png

2009/8/4 Kenneth Bull <@Kenneth_Bull>:

try this:

SDL_Surface* loadedImage = IMG_Load(path);
SDL_PixelFormat* format = loadedImage->format;
SDL_Surface* tmp = SDL_CreateRGBSurface(
?SDL_SWSURFACE | SDL_SRCALPHA,
?loadedImage->w2, loadedImage->h2,
?format->BitsPerPixel,
?format->Rmask, format->Gmask, format->Bmask, format->Amask
);
SDL_FillRect(tmp, NULL, SDL_MapRGBA(tmp->format, 0, 0, 0, 0));
SDL_SetSurfaceScaleMode(loadedImage, SDL_TEXTURESCALEMODE_FAST);
SDL_SoftStretch(loadedImage, NULL, tmp, NULL);
SDL_Surface* biggerImage = SDL_DisplayFormatAlpha(tmp);
SDL_FreeSurface(tmp);
SDL_FreeSurface(loadedImage);

SDL_FreeSurface(biggerImage);

ok, that was stretching, this is adding space to the edges of the surface:

SDL_Surface* loadedImage = IMG_Load(path);
SDL_PixelFormat* format = loadedImage->format;
SDL_Surface* tmp = SDL_CreateRGBSurface(
SDL_SWSURFACE | SDL_SRCALPHA,
loadedImage->w2, loadedImage->h2,
format->BitsPerPixel,
format->Rmask, format->Gmask, format->Bmask, format->Amask
);
SDL_FillRect(tmp, NULL, SDL_MapRGBA(tmp->format, 0, 0, 0, 0));
SDL_Rect rect = {0, 0, loadedImage->w, loadedImage->h};
SDL_Blit(loadedImage, rect, tmp, rect); // or SDL_LowerBlit to save a
little CPU time
SDL_FreeSurface(loadedImage);
SDL_Surface* biggerImage = SDL_DisplayFormatAlpha(tmp);
SDL_FreeSurface(tmp);

SDL_FreeSurface(biggerImage);

I moved SDL_FreeSurface(loadedImage) to save memory.

You may noticed why I would like to make the imagem with bigger width and height. I am using OpenGL.

Kenneth, that didnt worked :frowning: nothing was shown!

I found a solution. I need to make every image width and height power of 2, because of the textures, some graphic cards dont support non power of 2 textures.
Then I made every image w&h power of 2! Simple isnt it?
But then came another problem! Making the text texture power of 2! So I made this function:

SDL_Surface* redImage(int w,int h,SDL_Surface* src)
{
SDL_Surface* surface = SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,COLOR_DEPTH,0,0,0,0);
SDL_SetColorKey(surface,SDL_SRCCOLORKEY,SDL_MapRGB(surface->format,0,0,0));
SDL_BlitSurface(src,NULL,surface,NULL);
SDL_FreeSurface(src);
return SDL_DisplayFormatAlpha(surface);
}

“src” is the surface created by:

SDL_Surface* temp = TTF_RenderText_Solid(font,text,textColor);
SDL_Surface* surface = SDL_DisplayFormatAlpha(temp);
SDL_FreeSurface(temp);

The only problem is that I cant draw black texts (0,0,0), but I can draw almost black texts (0,0,1) for example xD
This is a temporary solution, I did a MacGuyver solution but its good for now :stuck_out_tongue:

Thank you all for the support!_________________________________________________________________
Conhe?a os novos produtos Windows Live! Clique aqui.
http://www.windowslive.com.br