Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

In a 3D SDL application I inherited (I have little 3D or SDL experience), I have a 'screenshot' routine that either saves a full-size image or a scaled image, depending on the context (differing key-press). To save a full-size (i.e. graphics-mode-sized) screenshot I'm using:

SDL_SaveBMP(SDL_GetVideoSurface(), SDL_RWFromFile(filename.c_str(), "wb"), 1);

This works exactly as-intended, and saves an 8-bit bitmap (the display mode is always 8-bit, for another reason entirely) as expected.

However, in order to resize the image, I'm making use of a library that came heavily recommended in several places when searching for a suitable surface-/image-resizing library for SDL: SDL_Resize.

I'm implementing this as such:

SDL_Surface *toResize = SDL_GetVideoSurface();
SDL_Surface *resized = SDL_Resize(toResize, (int)w, (int)h);

SDL_SaveBMP(resized, SDL_RWFromFile(filename.c_str(), "wb"), 1);
SDL_FreeSurface(resized);

This works mostly as intended. It saves a resized, 8-bit bitmap, seemingly with the correct palette. However, the colours in parts of the image are incorrect, e.g.

IMAGE

Now, I don't need the output images to be 8-bit, I'd be perfectly happy with a 24-bit or 32-bit bitmap, if I could solve this problem; but I can't find out the answer to either of these questions:

  • How do I convert an SDL surface to a different bit-depth?
  • How do I ensure that the output image displays the colours correctly after resize?

I'm anticipating that I may have to settle for a higher-bit-depth bitmap, and that's fine... but a few pointers in the right direction would be fantastic.

Many thanks!

share|improve this question

1 Answer 1

up vote 1 down vote accepted

To "convert" an SDL surface to another bit-depth, use SDL_ConvertSurface. This function is slightly mis-named, as it actually makes a new surface rather than converting the surface in-place (which isn't really possible).

I don't know how SDL_Resize works, but the problems you are seeing can be caused by it using a 24/32 bit buffer internally when rescaling and performing bilinear filtering. This results in colors in the scaled image which are not present in the original, which must then be mapping back to the palette, apparently poorly.

It also looks bad enough that SDL_Resize may also only support one palette, forcing your image into that color space before working with it. But even if it kept the original palette, the accuracy would be questionable.

share|improve this answer
    
This appears to have done what I need, many thanks! –  James Burgess Dec 16 '10 at 9:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.