1 |
/* Copyright (c) 1986 Regents of the University of California */ |
2 |
|
3 |
#ifndef lint |
4 |
static char SCCSid[] = "$SunId$ LBL"; |
5 |
#endif |
6 |
|
7 |
/* |
8 |
* ttyimage.c - program to dump pixel file to dumb terminal. |
9 |
* |
10 |
* 8/15/85 |
11 |
*/ |
12 |
|
13 |
#include <stdio.h> |
14 |
|
15 |
#include "color.h" |
16 |
|
17 |
|
18 |
#define NCOLS 133 |
19 |
|
20 |
|
21 |
main(argc, argv) |
22 |
int argc; |
23 |
char **argv; |
24 |
{ |
25 |
FILE *input; |
26 |
int xres, yres; |
27 |
COLR scanline[NCOLS]; |
28 |
register int i, j; |
29 |
|
30 |
if (argc < 2) |
31 |
input = stdin; |
32 |
else if ((input = fopen(argv[1], "r")) == NULL) { |
33 |
fprintf(stderr, "%s: can't open file \"%s\"\n", argv[0], argv[1]); |
34 |
exit(1); |
35 |
} |
36 |
|
37 |
/* discard header */ |
38 |
getheader(input, NULL); |
39 |
/* get picture dimensions */ |
40 |
if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { |
41 |
fprintf(stderr, "%s: bad picture size\n", argv[0]); |
42 |
exit(1); |
43 |
} |
44 |
if (xres > NCOLS) { |
45 |
fprintf(stderr, "%s: resolution mismatch\n", argv[0]); |
46 |
exit(1); |
47 |
} |
48 |
|
49 |
for (i = 0; i < yres; i++) { |
50 |
if (freadcolrs(scanline, xres, input) < 0) { |
51 |
fprintf(stderr, "%s: read error\n", argv[0]); |
52 |
exit(1); |
53 |
} |
54 |
normcolrs(scanline, xres); |
55 |
for (j = 0; j < xres; j++) |
56 |
putchar(shade(scanline[j])); |
57 |
putchar('\n'); |
58 |
} |
59 |
|
60 |
exit(0); |
61 |
} |
62 |
|
63 |
|
64 |
int |
65 |
shade(clr) /* return character for color */ |
66 |
COLR clr; |
67 |
{ |
68 |
#define NSHADES 13 |
69 |
|
70 |
static char shadech[NSHADES+1] = " .,:;+?%&*$@#"; |
71 |
|
72 |
return(shadech[normbright(clr)*NSHADES/256]); |
73 |
|
74 |
#undef NSHADES |
75 |
} |