[SDL] Fast IMG Load

Benjamin Deutsch ben at fictiongroup.de
Thu Jan 13 10:21:18 PST 2005


Hi,

>>> I need to load a lot of images using too much memory space when loaded:
>>> 152 images, 35kb each but in memory they are much bigger because of image
>>> uncompression and byte alignment.
>>> My idea is to read all the image data compressed in png format in memory
>>> and load the images from memory instead of disk.

Try the following:

- Load the file into memory. Try the stdio.h functions, if you're using
   C or C++.

- Create an SDL_RWOps structure with SDL_RWFromMeM:
   http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fRWops

- Use the SDL_image library to load your images:
   http://jcatki.no-ip.org/SDL_image/
   Basically, IMG_Load_RW, IMG_LoadTyped_RW or IMG_LoadPNG_RW should
   work.

However:

>> The only way this would take less space than just loading the images
>> would be keeping the compressed data in memory and decompress it on the
>> fly while blitting. I bet that's too slow to be of any practical value :(
>>
> i think he means it would be faster if the raw file was loaded into ram and
> decompressed there.

I must agree here, without further information, we don't know what you 
mean or whether this will actually help.

On the other hand, I've been daydreaming about converting a .png file to 
a .o file, maybe through a .c file that contained

   unsigned char *my_image = {
   0, 0, 0, 42, ...

and then having my image embedded in my binary. The benefits and 
drawbacks of embedded images aside, is this already possible somehow?

Hope the above helps, though,

   Benjamin




More information about the SDL mailing list