Date:2012-09-14 10:32:10 (11 years 6 months ago)
Author:Werner Almesberger
Commit:8d967a0480d2cbc9ab20e333e8a822fcfb6c7e10
Message:tools/ant-txt/ant-txt.c: add option -x for X bitmap output

Files: tools/ant-txt/ant-txt.c (4 diffs)

Change Details

tools/ant-txt/ant-txt.c
5151}
5252
5353
54static 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
5480static void dump_text(const uint8_t *canvas)
5581{
5682    int x, y;
...... 
6894
6995static void usage(const char *name)
7096{
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);
7298    exit(1);
7399}
74100
...... 
78104    struct edit *edits = NULL, **last = &edits;
79105    uint8_t *canvas;
80106    const char *err;
81    int binary = 0;
107    int binary = 0, xbm = 0;
82108    int i, c;
83109
84    while ((c = getopt(argc, argv, "bF:")) != EOF)
110    while ((c = getopt(argc, argv, "bF:x")) != EOF)
85111        switch (c) {
86112        case 'b':
87113            binary = 1;
88114            break;
115        case 'x':
116            xbm = 1;
117            break;
89118        case 'F':
90119            add_font_dir(optarg);
91120            break;
92121        default:
93122            usage(*argv);
94123        }
124    if (binary && xbm)
125        usage(*argv);
95126    for (i = optind; i != argc; i++) {
96127        while (*last)
97128            last = &(*last)->next;
...... 
116147    }
117148    if (binary)
118149        dump_binary(canvas);
150    else if (xbm)
151        dump_xbm(canvas);
119152    else
120153        dump_text(canvas);
121154    return 0;

Archive Download the corresponding diff file

Branches:
master
tornado-v1



interactive