Change Details
tools/ant-txt/ant-txt.c |
51 | 51 | } |
52 | 52 | |
53 | 53 | |
| 54 | static void dump_xbm(const uint8_t *canvas) |
| 55 | { |
| 56 | int x, y, i, n; |
| 57 | uint8_t v = 0; |
| 58 | |
| 59 | printf("#define foo_width %d\n", W); |
| 60 | printf("#define foo_height %d\n", H); |
| 61 | printf("static unsigned char foo_bits[] = {\n"); |
| 62 | n = 0; |
| 63 | for (y = 0; y != H; y++) { |
| 64 | for (x = 0; x < W; x += 8) { |
| 65 | if (n) |
| 66 | printf("%s 0x%02x", |
| 67 | (n-1) % 12 ? "," : |
| 68 | n == 1 ? " " : ",\n ", v); |
| 69 | v = 0; |
| 70 | for (i = x; i != W && i != x+8; i++) |
| 71 | if (canvas[(y*W+i) >> 3] & (1 << (i & 7))) |
| 72 | v |= 1 << (i-x); |
| 73 | n++; |
| 74 | } |
| 75 | } |
| 76 | printf("%s 0x%02x};\n", (n-1) % 12 ? "," : ",\n ", v); |
| 77 | } |
| 78 | |
| 79 | |
54 | 80 | static void dump_text(const uint8_t *canvas) |
55 | 81 | { |
56 | 82 | int x, y; |
... | ... | |
68 | 94 | |
69 | 95 | static void usage(const char *name) |
70 | 96 | { |
71 | | fprintf(stderr, "usage: %s [-b] [-F font_dir ...] [text]\n", name); |
| 97 | fprintf(stderr, "usage: %s [-b|-x] [-F font_dir ...] [text]\n", name); |
72 | 98 | exit(1); |
73 | 99 | } |
74 | 100 | |
... | ... | |
78 | 104 | struct edit *edits = NULL, **last = &edits; |
79 | 105 | uint8_t *canvas; |
80 | 106 | const char *err; |
81 | | int binary = 0; |
| 107 | int binary = 0, xbm = 0; |
82 | 108 | int i, c; |
83 | 109 | |
84 | | while ((c = getopt(argc, argv, "bF:")) != EOF) |
| 110 | while ((c = getopt(argc, argv, "bF:x")) != EOF) |
85 | 111 | switch (c) { |
86 | 112 | case 'b': |
87 | 113 | binary = 1; |
88 | 114 | break; |
| 115 | case 'x': |
| 116 | xbm = 1; |
| 117 | break; |
89 | 118 | case 'F': |
90 | 119 | add_font_dir(optarg); |
91 | 120 | break; |
92 | 121 | default: |
93 | 122 | usage(*argv); |
94 | 123 | } |
| 124 | if (binary && xbm) |
| 125 | usage(*argv); |
95 | 126 | for (i = optind; i != argc; i++) { |
96 | 127 | while (*last) |
97 | 128 | last = &(*last)->next; |
... | ... | |
116 | 147 | } |
117 | 148 | if (binary) |
118 | 149 | dump_binary(canvas); |
| 150 | else if (xbm) |
| 151 | dump_xbm(canvas); |
119 | 152 | else |
120 | 153 | dump_text(canvas); |
121 | 154 | return 0; |
Download the corresponding diff file