bin2c — embed data files into C as variables
] [-D dir_prefix
] [-G guard-name
] [ -p
] [ -v
bin2c converts files to C variables. It does so by reading the contents of each
file supplied on the argument line and writes out C program code that defines
a variable with the file's contents.
hxtools's bin2c implementation supports:
- space-efficient encoding of the arbitrary data
- multiple input files
- creation of either a standalone .h file, or a .c/.h file
pair. (See examples below.)
- -C file
- If specified, causes the variable definition to be
emitted to the given filename.
- -D dir_prefix
- All filenames on the command line will be prefixed with the
given directory. This has the implication that files will be searched
relative to dir_prefix, while the variable name ending up in the C
source for an image will remain non-prefixed.
- -G name
- Request that an include guard by the identifier
guard-name is emitted into the header file. If -C was specified and
a .c/.h pair is generated, an include guard is always emitted, and the -G
option can be used to set that name.
- -H file
- The file where the variable declarations will be
emitted to. If -C was not specified, h-file will not contain
any header guard by default, and it will contain the variable definition,
the latter of which will be marked as static (file scope).
- -p num
- Strip num leading path components when transforming
input paths to variable names. If num is negative, that many
trailing path components are retained. If -p is not
specified, the default is -1.
- Be verbose. Show all the names and filenames that bin2c
- Writeout the raw data as a string literal. As the literal
contains a trailing NUL byte, the size of the array is necessarily also
one byte longer than the raw data, which you need to account for. (In C,
it would be possible to write char x = "ABC", but this leads
to an error in C++ where x is required.)
- Generate C++ code that generates wxBitmap objects. (Implies
Ultra encoding, and deals with it appropriately, too.)
To generate a single C header file that behaves like XPM files and which is
suitable for inclusion into a C program file of your own:
bin2c -H images.h foo.png bar.png
To generate a .c/.h pair instead, the invocation is:
bin2c -C images.c foo.png bar.png
This will create a C program file "images.c" containing all the
definitions and a "images.h" that your code can use to get ahold of
hxtools's bin2c developed from the earlier png2wx.pl utility.