|
|
ff2col.c - ff2txt - farbfeld image to plain text visualization |
|
|
 |
git clone git://bitreich.org/ff2txt git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/ff2txt (git://bitreich.org) |
|
|
 |
Log |
|
|
 |
Files |
|
|
 |
Refs |
|
|
 |
Tags |
|
|
 |
README |
|
|
|
--- |
|
|
|
ff2col.c (760B) |
|
|
|
--- |
|
|
|
1 #include <stdio.h> |
|
|
|
2 #include <string.h> |
|
|
|
3 #include <stdlib.h> |
|
|
|
4 #include <stdint.h> |
|
|
|
5 |
|
|
|
6 #include "util.h" |
|
|
|
7 |
|
|
|
8 void |
|
|
|
9 print_2_rows(struct col *buf, uint32_t width, int height) |
|
|
|
10 { |
|
|
|
11 size_t w; |
|
|
|
12 int up, dn; |
|
|
|
13 char *map = " '.:"; |
|
|
|
14 |
|
|
|
15 for (w = 0; w < width; w++) { |
|
|
|
16 up = height > 0 && col_is_bright(buf[w]) ? 0x1 : 0x0; |
|
|
|
17 dn = height > 1 && col_is_bright(buf[w + width]) ? 0x2 : 0x0; |
|
|
|
18 putchar(map[up | dn]); |
|
|
|
19 } |
|
|
|
20 putchar('\n'); |
|
|
|
21 } |
|
|
|
22 |
|
|
|
23 int |
|
|
|
24 main(void) |
|
|
|
25 { |
|
|
|
26 struct col buf[MAX_WIDTH * 2]; |
|
|
|
27 uint32_t width, height, h, r; |
|
|
|
28 |
|
|
|
29 read_header(&width, &height); |
|
|
|
30 |
|
|
|
31 for (h = 0; h < height; h += 2) { |
|
|
|
32 r = fread(buf, sizeof(*buf), width * 2, stdin); |
|
|
|
33 if (r % width != 0) |
|
|
|
34 err("invalid line width"); |
|
|
|
35 if (ferror(stdin)) |
|
|
|
36 err("fread stdin"); |
|
|
|
37 print_2_rows(buf, width, r / width); |
|
|
|
38 } |
|
|
|
39 return 0; |
|
|
|
40 } |
|