Schüsse nach Tod despawnen.
[hackover2013-badge-firmware.git] / sprites / xpm_sprite_converter.c
1 #ifndef XPM_FILE
2 #error "XPM_FILE undefined"
3 #endif
4
5 #ifndef XPM_NAME
6 #error "XPM_NAME undefined"
7 #endif
8
9 #define STRINGIFY_I(x) #x
10 #define STRINGIFY(x) STRINGIFY_I(x)
11
12 #include STRINGIFY(XPM_FILE)
13
14 #include <stdio.h>
15 #include <stdint.h>
16 #include <stdlib.h>
17 #include <string.h>
18
19 int main(void) {
20 int width, height, color_count, foo;
21 char black = '\0';
22 uint8_t *data;
23
24 if(4 != sscanf(XPM_NAME[0], "%d %d %d %d", &width, &height, &color_count, &foo)) {
25 fputs("Fehler beim Parsen der Dimensionen\n", stderr);
26 return -1;
27 }
28
29 for(int i = 0; i < color_count; ++i) {
30 size_t len = strlen((char*) XPM_NAME[i + 1]);
31 if(len > 7 && strcmp((char*) XPM_NAME[i + 1] + len - 7, "#000000") == 0) {
32 black = XPM_NAME[i + 1][0];
33 break;
34 }
35 }
36
37 if(!black) {
38 fputs("Konnte Schwarz nicht identifizieren.\n", stderr);
39 return -1;
40 }
41
42 data = calloc(width * height / 8 + 1, 1);
43
44 printf("{ %d, %d, (uint8_t const *) \"", width, height);
45
46 if(data) {
47 int y, x;
48 int i = 0, j;
49
50 for(x = 0; x < width; ++x) {
51 for(y = 0; y < height; ++y) {
52 data[i / 8] |= (XPM_NAME[y + 1 + color_count][x] == black) << i % 8;
53 ++i;
54 }
55 }
56
57 for(j = 0; j < i / 8 + (i % 8 != 0); ++j) {
58 printf("\\x%02x", data[j]);
59 }
60 puts("\" }");
61 }
62
63 free(data);
64 }
This page took 0.057486 seconds and 5 git commands to generate.