[SDL] Fast IMG Load

Michael B. Edwin Rickert panda at industry.no-ip.com
Thu Jan 13 12:11:16 PST 2005


Gabriel wrote:
>>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.

Or, the GIMP (gimp.org) allready has support for exporting to C files. 
Instead of using unsigned chars, it uses normal character literals 
escaped as needed. I'm not sure if this is easily automated though, you 
may need to create a converter if you want to do:

my_image.png.o : my_image.png.c
my_image.png.c : my_image.png
     convert $^ -o $@ --export=C

... or the like. This may allready have been done however, so I suggest 
google.




More information about the SDL mailing list