1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
2.6 |
static const char RCSid[] = "$Id: ttyimage.c,v 2.5 2004/03/28 20:33:14 schorsch Exp $"; |
3 |
greg |
1.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* ttyimage.c - program to dump pixel file to dumb terminal. |
6 |
|
|
* |
7 |
|
|
* 8/15/85 |
8 |
|
|
*/ |
9 |
|
|
|
10 |
greg |
2.6 |
#include "rtio.h" |
11 |
schorsch |
2.4 |
#include "platform.h" |
12 |
greg |
1.1 |
#include "color.h" |
13 |
greg |
1.8 |
#include "resolu.h" |
14 |
greg |
1.1 |
|
15 |
|
|
|
16 |
greg |
2.2 |
#define NCOLS 133 |
17 |
greg |
1.1 |
|
18 |
schorsch |
2.5 |
static int shade(COLR clr); |
19 |
greg |
1.1 |
|
20 |
schorsch |
2.5 |
|
21 |
|
|
int |
22 |
|
|
main(int argc, char **argv) |
23 |
greg |
1.1 |
{ |
24 |
|
|
FILE *input; |
25 |
|
|
int xres, yres; |
26 |
greg |
1.3 |
COLR scanline[NCOLS]; |
27 |
greg |
1.1 |
register int i, j; |
28 |
|
|
|
29 |
|
|
if (argc < 2) |
30 |
|
|
input = stdin; |
31 |
|
|
else if ((input = fopen(argv[1], "r")) == NULL) { |
32 |
greg |
1.3 |
fprintf(stderr, "%s: can't open file \"%s\"\n", argv[0], argv[1]); |
33 |
greg |
1.1 |
exit(1); |
34 |
|
|
} |
35 |
schorsch |
2.4 |
SET_FILE_BINARY(input); |
36 |
greg |
1.1 |
/* get picture dimensions */ |
37 |
greg |
1.7 |
if (checkheader(input, COLRFMT, NULL) < 0 || |
38 |
greg |
1.8 |
fgetresolu(&xres, &yres, input) < 0) { |
39 |
greg |
1.7 |
fprintf(stderr, "%s: bad picture format\n", argv[0]); |
40 |
greg |
1.1 |
exit(1); |
41 |
|
|
} |
42 |
|
|
if (xres > NCOLS) { |
43 |
greg |
1.3 |
fprintf(stderr, "%s: resolution mismatch\n", argv[0]); |
44 |
greg |
1.1 |
exit(1); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
for (i = 0; i < yres; i++) { |
48 |
greg |
1.3 |
if (freadcolrs(scanline, xres, input) < 0) { |
49 |
|
|
fprintf(stderr, "%s: read error\n", argv[0]); |
50 |
greg |
1.1 |
exit(1); |
51 |
|
|
} |
52 |
greg |
1.6 |
normcolrs(scanline, xres, 0); |
53 |
greg |
1.1 |
for (j = 0; j < xres; j++) |
54 |
greg |
1.3 |
putchar(shade(scanline[j])); |
55 |
greg |
1.1 |
putchar('\n'); |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
exit(0); |
59 |
greg |
1.3 |
} |
60 |
|
|
|
61 |
|
|
|
62 |
schorsch |
2.5 |
static int |
63 |
|
|
shade( /* return character for color */ |
64 |
|
|
COLR clr |
65 |
|
|
) |
66 |
greg |
1.3 |
{ |
67 |
greg |
2.2 |
#define NSHADES 13 |
68 |
greg |
1.3 |
|
69 |
|
|
static char shadech[NSHADES+1] = " .,:;+?%&*$@#"; |
70 |
|
|
|
71 |
greg |
1.4 |
return(shadech[normbright(clr)*NSHADES/256]); |
72 |
greg |
1.3 |
|
73 |
|
|
#undef NSHADES |
74 |
greg |
1.1 |
} |