Jump to content
  • Advertisement
Sign in to follow this  
Atash

SDL_Image loading/format question

This topic is 4436 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

In SDL_Image, when an image is loaded, is it loaded as an RGB or an RGBA surface? Thank you in advance :-) [Edited by - Atash on March 29, 2006 9:55:03 PM]

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure. I just spent a few minutes looking through some material but couldn't find anything. What I would do is load an image using it and than look at the Pixelformat structure through the format member. Maybe compare the differences to a non RGBA surface. I'm sure that certain values, such as Amask would be different for non-RGBA surfaces.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
depends on the image format.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If the image contains an alpha channel, it will load it. PNGs with an alpha channel get loaded as RGBA, but 24bit color BMPs load as RGB.

If you are using 32 BPP color on screen with an RGB surface loaded from a BMP, you'll want to use the SDL_ConvertSurface function in order to improve the speed of blits.

Share this post


Link to post
Share on other sites
Okay, that brings me to a different issue (because of OGL tex loading functions and... yeah)... When you have an SDL_Surface that has pixel data, is all of that data stored with slots for every single value (RGBA), and when using it in RGB mode you simply skip over the Alpha, or is it that it is ACTUALLY stored in an RGB format?

Thanks in advance!!!

Share this post


Link to post
Share on other sites
Quote:
Original post by Atash
Okay, that brings me to a different issue (because of OGL tex loading functions and... yeah)... When you have an SDL_Surface that has pixel data, is all of that data stored with slots for every single value (RGBA), and when using it in RGB mode you simply skip over the Alpha, or is it that it is ACTUALLY stored in an RGB format?

Thanks in advance!!!


If all you want is a consistent format when loading the image just convert the loaded surface to RGBA:

    
//The format
SDL_PixelFormat format;

//Set format
format.palette = NULL;
format.BitsPerPixel = 32;
format.BytesPerPixel = 4;

//Set mask
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
format.Rmask = 0xFF000000;
format.Gmask = 0x00FF0000;
format.Bmask = 0x0000FF00;
format.Amask = 0x000000FF;
#else
format.Rmask = 0x000000FF;
format.Gmask = 0x0000FF00;
format.Bmask = 0x00FF0000;
format.Amask = 0xFF000000;
#endif

//Set shift
format.Rshift = 8; format.Gshift = 8; format.Bshift = 8; format.Ashift = 8;

//Set loss
format.Rloss = 0; format.Gloss = 0; format.Bloss = 0; format.Aloss = 0;



then convert the surface with that pixel format.

Share this post


Link to post
Share on other sites
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!