[SDL] Fast IMG Load

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


Hello again,

>>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?
> 
> 
> Sure you can. Load it using SDL_Image, get access to the pixel data, and
> generate your .c file. To use it, link with the corresponding .o
> defining my_image, and create a SDL_Surface from that. You may want to
> save the pixel format as well as the raw data.

Sorry, actually I meant "has someone alreay written a program or script 
that does this, so I won't have to write one, or does gcc even come with 
a hidden flag for such purposes?"

And I would probably not embed the decompressed image, but the 
compressed PNG. Though it is intriguing to say "disk space is cheaper 
than RAM", I'd bet the extra time taken for loading the uncompressed vs. 
compressed image is longer than decompression time. On the other hand, 
Having the compressed image still stick around sounds like a waste of 
memory...

Bye,
   Benjamin




More information about the SDL mailing list