Root/
| Source at commit 0e9b093d2ee3f8195e9848f5a931c2068d37e59f created 11 years 1 day ago. By Werner Almesberger, tornado/cpu/cpu.brd: improve 3V3 routing | |
|---|---|
| 1 | /* |
| 2 | * tools/libant/dump.c - Antorcha raw image dump |
| 3 | * |
| 4 | * Written 2012 by Werner Almesberger |
| 5 | * Copyright 2012 Werner Almesberger |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | |
| 14 | #include <stdint.h> |
| 15 | #include <stdio.h> |
| 16 | |
| 17 | #include "libant.h" |
| 18 | |
| 19 | |
| 20 | int dump_binary(FILE *file, const void *canvas, int width, int height) |
| 21 | { |
| 22 | const uint8_t *p = canvas; |
| 23 | int x, y, i; |
| 24 | uint8_t v; |
| 25 | |
| 26 | for (x = 0; x != width; x++) { |
| 27 | for (y = 0; y != height; y += 8) { |
| 28 | v = 0; |
| 29 | for (i = 0; i != 8; i++) |
| 30 | if (p[((y+i)*width+x) >> 3] & (1 << (x & 7))) |
| 31 | v |= 1 << i; |
| 32 | if (fputc(v, file) == EOF) |
| 33 | return -1; |
| 34 | } |
| 35 | } |
| 36 | return 0; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | int dump_xbm(FILE *file, const void *canvas, int width, int height) |
| 41 | { |
| 42 | const uint8_t *p = canvas; |
| 43 | int x, y, i, n; |
| 44 | uint8_t v = 0; |
| 45 | |
| 46 | if (fprintf(file, "#define foo_width %d\n", width) < 0) |
| 47 | return -1; |
| 48 | if (fprintf(file, "#define foo_height %d\n", height) < 0) |
| 49 | return -1; |
| 50 | if (fprintf(file, "static unsigned char foo_bits[] = {\n") < 0) |
| 51 | return -1; |
| 52 | n = 0; |
| 53 | for (y = 0; y != height; y++) { |
| 54 | for (x = 0; x < width; x += 8) { |
| 55 | if (n) |
| 56 | if (fprintf(file, "%s 0x%02x", |
| 57 | (n-1) % 12 ? "," : |
| 58 | n == 1 ? " " : ",\n ", v) < 0) |
| 59 | return -1; |
| 60 | v = 0; |
| 61 | for (i = x; i != width && i != x+8; i++) |
| 62 | if (p[(y*width+i) >> 3] & (1 << (i & 7))) |
| 63 | v |= 1 << (i-x); |
| 64 | n++; |
| 65 | } |
| 66 | } |
| 67 | if (fprintf(file, "%s 0x%02x};\n", (n-1) % 12 ? "," : ",\n ", v) < 0) |
| 68 | return -1; |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | |
| 73 | int dump_ascii(FILE *file, const void *canvas, int width, int height) |
| 74 | { |
| 75 | const uint8_t *p = canvas; |
| 76 | int x, y; |
| 77 | |
| 78 | for (y = 0; y != height; y++) { |
| 79 | for (x = 0; x != width; x++) |
| 80 | if (p[(y*width+x) >> 3] & (1 << (x & 7))) { |
| 81 | if (fputc('#', file) == EOF) |
| 82 | return -1; |
| 83 | } else { |
| 84 | if (fputc('.', file) == EOF) |
| 85 | return -1; |
| 86 | } |
| 87 | if (fputc('\n', file) == EOF) |
| 88 | return -1; |
| 89 | } |
| 90 | return 0; |
| 91 | } |
| 92 | |
Branches:
master
tornado-v1
