Contact
Impressum
Why this name?
pdf

bin2c

Name

bin2c — embed data files into C as variables

Syntax

bin2c [−C program-file] [−D dir_prefix] [−H header-file] [−G guard-name] [−p num] [−v] [−−ultra] [−−wxbitmap] file...

Description

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.)

Options

−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.

−v

Be verbose. Show all the names and filenames that bin2c will write.

−−ultra

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[3] = "ABC", but this leads to an error in C++ where x[4] is required.)

−−wxbitmap

Generate C++ code that generates wxBitmap objects. (Implies Ultra encoding, and deals with it appropriately, too.)

Examples

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 the declarations.

History

hxtools’s bin2c developed from the earlier png2wx.pl utility.

pdf
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

NO to software patents