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 |
char shadech[] = " .,:;+?%&*$@#"; |
21 |
|
22 |
#define NSHADES (sizeof(shadech)-1) |
23 |
|
24 |
#define shade(col) ( bright(col)>=1.0 ? NSHADES-1 : \ |
25 |
(int)(bright(col)*NSHADES) ) |
26 |
|
27 |
char *progname; |
28 |
|
29 |
|
30 |
main(argc, argv) |
31 |
int argc; |
32 |
char **argv; |
33 |
{ |
34 |
FILE *input; |
35 |
int xres, yres; |
36 |
COLOR scanline[NCOLS]; |
37 |
char sbuf[256]; |
38 |
register int i, j; |
39 |
|
40 |
progname = argv[0]; |
41 |
|
42 |
if (argc < 2) |
43 |
input = stdin; |
44 |
else if ((input = fopen(argv[1], "r")) == NULL) { |
45 |
fprintf(stderr, "%s: can't open file \"%s\"\n", progname, argv[1]); |
46 |
exit(1); |
47 |
} |
48 |
|
49 |
/* discard header */ |
50 |
while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n') |
51 |
; |
52 |
/* get picture dimensions */ |
53 |
if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { |
54 |
fprintf(stderr, "%s: bad picture size\n", progname); |
55 |
exit(1); |
56 |
} |
57 |
if (xres > NCOLS) { |
58 |
fprintf(stderr, "%s: resolution mismatch\n", progname); |
59 |
exit(1); |
60 |
} |
61 |
|
62 |
for (i = 0; i < yres; i++) { |
63 |
if (freadscan(scanline, xres, input) < 0) { |
64 |
fprintf(stderr, "%s: read error\n", progname); |
65 |
exit(1); |
66 |
} |
67 |
for (j = 0; j < xres; j++) |
68 |
putchar(shadech[shade(scanline[j])]); |
69 |
putchar('\n'); |
70 |
} |
71 |
|
72 |
exit(0); |
73 |
} |