Debian Codegraph @

contrib/admintools/gen_splash.py

raw symbols SCIP
1 #!/usr/bin/env python3
2
3 from PIL import Image
4 import sys
5 import textwrap
6
7 TEMPLATE = """/* Copyright (C) 2000-2012 by George Williams
8 * Image replaced in 2019 by @ctrlcctrlv (Fred Brennan) */
9 /*
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12
13 * Redistributions of source code must retain the above copyright notice, this
14 * list of conditions and the following disclaimer.
15
16 * Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19
20 * The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
22
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
26 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <fontforge-config.h>
36
37 #include "gimage.h"
38
39 static uint8_t splashimage0_data[] = {{
40 {data}
41 }};
42
43 static struct _GImage splashimage0_base = {{
44 it_true,
45 0,
46 {width},
47 {height},
48 {bytes_per_line},
49 (uint8_t *) splashimage0_data,
50 NULL,
51 0xffffffff
52 }};
53
54 GImage splashimage = {{ 0, {{ &splashimage0_base }}, NULL }};
55 """
56
57 if __name__ == "__main__":
58 if len(sys.argv) != 2:
59 print("Usage: {} input.png".format(sys.argv[0]))
60 sys.exit(-1)
61
62 img = Image.open(sys.argv[1]).convert("RGB")
63 data = ", ".join(
64 "0x{:02x}, 0x{:02x}, 0x{:02x}, 0xff".format(b, g, r)
65 for r, g, b in img.getdata()
66 )
67 wrapper = textwrap.TextWrapper(
68 width=79,
69 break_long_words=False,
70 )
71 data = "\n".join(wrapper.wrap(data))
72
73 with open("splashimage.c", "w") as fp:
74 fp.write(
75 TEMPLATE.format(
76 data=data,
77 width=img.width,
78 height=img.height,
79 bytes_per_line=img.width * 4,
80 )
81 )