From 41bf4f1ced8b8357c0c3f1c482afece9e37ee77a Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sun, 30 Sep 2012 15:35:54 +0200 Subject: makexpm: generate XPM file from width, height, ncolors and cpp --- makexpm.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 makexpm.c diff --git a/makexpm.c b/makexpm.c new file mode 100644 index 0000000..262ba84 --- /dev/null +++ b/makexpm.c @@ -0,0 +1,64 @@ +#include +#include +#include + +/* chars to use for colors */ +static const char p[] = "0123456789" +"abcdefghijklmnopqrstuvwxyz" +"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +"!@#$%^&*()_+-=`~[]{}|;:',<.>/? "; +/* number of chars excl NIL */ +static const int q = sizeof(p) - 1; + +int main(int argc, char **argv) { + unsigned int width, height, ncolors, cpp, i, j; + if (argc != 5) { + fprintf(stderr, "Usage: %s width height ncolors cpp\n", argv[0]); + return 1; + } + /* + width = 1600; + height = 900; + ncolors = width * height / 1024; + cpp = 3; + */ + + width = strtoul(argv[1], NULL, 0); + height= strtoul(argv[2], NULL, 0); + ncolors=strtoul(argv[3], NULL, 0); + cpp = strtoul(argv[4], NULL, 0); + + printf( + "/* XPM */\n" + "static char *picture[] = {\n" + "/* columns rows colors chars-per-pixel */\n" + "\"%d %d %d %d \",\n" + , width, height, ncolors, cpp); + + + const char *fmt; + switch (cpp) { + case 1: fmt = "%c"; break; + case 2: fmt = "%c%c"; break; + case 3: fmt = "%c%c%c"; break; + default:fmt = "%c%c%c%c"; break; + } + for (i = 0; i