Jump to content
  • Advertisement
Sign in to follow this  
NM_

[SDL+DevIL] - Pixel Data question

This topic is 3085 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone! Ok, my goal is to create sdl surface and save it by using devil... So here is the code: Code: ____________________________________________________________ int memory_needed = w * h * 3 * sizeof(unsigned char); ILubyte * data = (ILubyte *)malloc(memory_needed); ilCopyPixels(0, 0, 0,w, h, 1, IL_RGB, IL_UNSIGNED_BYTE, data); ilSetPixels(0, 0, 0, w, h, 1, IL_RGB, IL_UNSIGNED_BYTE, data); /* and dump them to the disc... */ ilSaveImage("result.png"); Image = SDL_CreateRGBSurfaceFrom(data, w, h , ilGetInteger(IL_IMAGE_BPP),w* (ilGetInteger(IL_IMAGE_BPP) / 8),0x000000FF,0x0000FF00, 0x00FF0000, 0); CrapImage = SDL_DisplayFormat( Image ); if ( SDL_SaveBMP(CrapImage, "screen.bmp") < 0 ) printf("Couldn't save screen: %s\n", SDL_GetError()); ____________________________________________________________ ilSaveImage does good job while SDL_SaveBMP gets only w and h value(SDL_DisplayFormat) and creates bmp with black background... How to get that pixel data and fill it into surface? Thanks for the attention!

Share this post


Link to post
Share on other sites
Advertisement
Hidden
I'm not any math expert, but something tells me you may have a problem with:

w* (ilGetInteger(IL_IMAGE_BPP) / 8)

You pass that calculation as the pitch for the image data you try to copy. According to this the pitch is "the size of the scanline of the surface, in bytes, i.e. widthInPixels*bytesPerPixel", and "The scanline is the width of the image multiplied by bytes per pixel, plus any bytes added for alignment".

Because my brain is a complete mess right now (well, all the time to be honest, hehe) I'm unable to calculate it for you, but you should take a second look and see if you're really calculating it right. Good luck.

Share this post


Link to post
Hmm...perhaps it's easy to transfer data to open gl texture and then create sdl_surface from opengl one.
How can it be done with opengl? (code pls)

Share this post


Link to post
Share on other sites
Hidden
This is my function for saving an OpenGL screen using SDL:


void save_screenshot(char *file) {
SDL_Surface *tmp;
int bpp, i;
unsigned char *pixels;

if (SDL_BYTEORDER == SDL_LIL_ENDIAN)
tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, mainscr->w, mainscr->h, 24, 0x000000FF, 0x0000FF00, 0x00FF0000, 0);
else
tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, mainscr->w, mainscr->h, 24, 0x00FF0000, 0x0000FF00, 0x000000FF, 0);
if (tmp == NULL)
exit(0); /* houston we have a problem */
bpp = tmp->format->BytesPerPixel;
pixels = malloc(mainscr->w * mainscr->h * bpp);
if (pixels != NULL) {
glReadPixels(0, 0, mainscr->w, mainscr->h, GL_RGB, GL_UNSIGNED_BYTE, pixels);
for (i = 0; i < mainscr->h; i++)
memcpy((char *)tmp->pixels + tmp->pitch * i, pixels + mainscr->w * (mainscr->h - i - 1) * bpp, mainscr->w * bpp);
free(pixels);
SDL_SaveBMP(tmp, file);
SDL_FreeSurface(tmp);
}
}

Share this post


Link to post
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!