[SDL] Embedded Images

David Olofson david at olofson.net
Tue Oct 10 10:00:16 PDT 2006


On Tuesday 10 October 2006 18:21, Gabriele Greco wrote:
> David Olofson wrote:
> > Hints:
> > 	SDL_RWops
> > 	IMG_Load_RW()
> >
> >   
> There is still the problem to link the image in your source code.
> It's an easy task if it's an XPM (you can include it with #include),
> but not that easy if you want to use a binary format. There is a
> portable way to do this without external programs that convert
> images in source files?

Well, unless you're relying on build tools (like GNU autotools) that 
come with a scripting language or something you can use for this, 
there's always the option of implementing your own tool in whatever 
language you're using for the "real" code of the project.

The downside of this approach is that it can result in trouble with 
cross compilers. Having a cross compiler for some language doesn't 
automatically mean you have a native compiler for that language!

Of course, if you're only releasing binaries, you can use whatever 
tools that work for you, as no one else is going to have any problems 
with missing tools or anything.


Another approach is to simply append the data files at the end of your 
executable, after compiling and linking it. Most loaders will just 
ignore anything beyond the chunks mentioned in the header, so the 
appended data will be ignored.

Mark the start of the data with some reasonably long string that won't 
appear in the binary. (Oh, and if you pass a constant to you search 
function, keep in mind where that constant goes... ;-)

Alternatively, check the size of the data, compile that into the 
executable, and seek from EOF to find your data.

The potential portability issue here is that some platforms may have 
loaders that either try to load the whole file before parsing it, 
resulting in waste of memory and/or long load times. There may also 
be issues with loaders being nervous about finding anything 
unexpected in executable files.

Another potential issue is that some platforms, or sysadmins, may 
prevent ordinary users from reading or writing executable files. (On 
platforms with dedicated "execute" flags, you normally don't need 
read permission to execute a file.)

Finally, antivirus software tends to have rather strong opinions about 
messing with executables. Logically, they should only react on actual 
write operations, but I wouldn't be surprised if some antiviruses 
complain about applications trying to read or even open executables.


//David Olofson - Programmer, Composer, Open Source Advocate

.-------  http://olofson.net - Games, SDL examples  -------.
|        http://zeespace.net - 2.5D rendering engine       |
|       http://audiality.org - Music/audio engine          |
|     http://eel.olofson.net - Real time scripting         |
'--  http://www.reologica.se - Rheology instrumentation  --'




More information about the SDL mailing list