2 # Copyright © 2018 Jamie Zawinski <jwz@jwz.org>
4 # Permission to use, copy, modify, distribute, and sell this software and its
5 # documentation for any purpose is hereby granted without fee, provided that
6 # the above copyright notice appear in all copies and that both that
7 # copyright notice and this permission notice appear in supporting
8 # documentation. No representations are made about the suitability of this
9 # software for any purpose. It is provided "as is" without express or
12 # Converts a binary file to a C source code string, e.g., to embed the
13 # contents of a PNG file by including a .h file.
15 # Created: 7-Feb-2018.
18 echo "usage: $0 in.png out_png.h" >&2
22 if [ $# != 2 ]; then usage; fi
27 NAME=`echo "$OUT" | sed \
31 -e 's/^\([^a-z]\)/_\1/'`;
33 if [ x"$PERL" = "x" ]; then PERL=perl ; fi
35 # On Linux, we could do this and put the raw image into a .o data segment:
36 # $(LD) -r -b binary $< -o $@
37 # but that doesn't work on MacOS.
40 BEGIN { print \"#ifdef __GNUC__\\n\";
41 print \"__extension__\\n\";
43 print \"static const unsigned char ${NAME}[] =\\n \\\"\"; }
44 END { print \"\\\";\\n\"; }
45 s/([^ -\041\043-\076\100-\133\135-\176])/sprintf(\"\\\\%03o\",ord(\$1))/gse;"\