29 parser = argparse.ArgumentParser(
30 formatter_class=argparse.RawDescriptionHelpFormatter,
31 description=
'Convert resource files to embedded read only data.',
32 epilog=
'''The output (when compiled and linked) can be used as:
33struct SkEmbeddedResource {const uint8_t* data; const size_t size;};
34struct SkEmbeddedHeader {const SkEmbeddedResource* entries; const int count;};
35extern "C" SkEmbeddedHeader const NAME;''')
36 parser.add_argument(
'--align', default=1, type=int,
37 help=
'minimum alignment (in bytes) of resource data')
38 parser.add_argument(
'--name', default=
'_resource', type=str,
39 help=
'the name of the c identifier to export')
40 parser.add_argument(
'--input', required=
True, type=argparse.FileType(
'rb'),
41 nargs=
'+', help=
'list of resource files to embed')
42 parser.add_argument(
'--output', required=
True, type=argparse.FileType(
'w'),
43 help=
'the name of the cpp file to output')
44 args = parser.parse_args()
46 out = args.output.write;
47 out(
'#include <stddef.h>\n')
48 out(
'#include <stdint.h>\n')
53 out(
'alignas({1:d}) static const uint8_t resource{0:d}[] = {{\n'
54 .
format(index, args.align))
61 if bytes_on_line >= 32:
65 out(
'static const size_t resource{0:d}_size = {1:d};\n'
66 .
format(index, bytes_written))
70 out(
'struct SkEmbeddedResource { const uint8_t* d; const size_t s; };\n')
71 out(
'static const SkEmbeddedResource header[] = {\n')
74 out(
' {{ resource{0:d}, resource{0:d}_size }},\n'.
format(index))
77 out(
'static const int header_count = {0:d};\n'.
format(index))
80 out(
'struct SkEmbeddedHeader {const SkEmbeddedResource* e; const int c;};\n')
81 out(
'extern "C" const SkEmbeddedHeader {0:s} = {{ header, header_count }};\n'
uint32_t uint32_t * format