1 |
greg |
1.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 |
greg |
1.3 |
COLR scanline[NCOLS]; |
28 |
greg |
1.1 |
char sbuf[256]; |
29 |
|
|
register int i, j; |
30 |
|
|
|
31 |
|
|
if (argc < 2) |
32 |
|
|
input = stdin; |
33 |
|
|
else if ((input = fopen(argv[1], "r")) == NULL) { |
34 |
greg |
1.3 |
fprintf(stderr, "%s: can't open file \"%s\"\n", argv[0], argv[1]); |
35 |
greg |
1.1 |
exit(1); |
36 |
|
|
} |
37 |
|
|
|
38 |
|
|
/* discard header */ |
39 |
|
|
while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n') |
40 |
|
|
; |
41 |
|
|
/* get picture dimensions */ |
42 |
greg |
1.2 |
if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { |
43 |
greg |
1.3 |
fprintf(stderr, "%s: bad picture size\n", argv[0]); |
44 |
greg |
1.1 |
exit(1); |
45 |
|
|
} |
46 |
|
|
if (xres > NCOLS) { |
47 |
greg |
1.3 |
fprintf(stderr, "%s: resolution mismatch\n", argv[0]); |
48 |
greg |
1.1 |
exit(1); |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
for (i = 0; i < yres; i++) { |
52 |
greg |
1.3 |
if (freadcolrs(scanline, xres, input) < 0) { |
53 |
|
|
fprintf(stderr, "%s: read error\n", argv[0]); |
54 |
greg |
1.1 |
exit(1); |
55 |
|
|
} |
56 |
|
|
for (j = 0; j < xres; j++) |
57 |
greg |
1.3 |
putchar(shade(scanline[j])); |
58 |
greg |
1.1 |
putchar('\n'); |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
exit(0); |
62 |
greg |
1.3 |
} |
63 |
|
|
|
64 |
|
|
|
65 |
|
|
int |
66 |
|
|
shade(clr) /* return character for color */ |
67 |
|
|
COLR clr; |
68 |
|
|
{ |
69 |
|
|
#define NSHADES 13 |
70 |
|
|
|
71 |
|
|
static char shadech[NSHADES+1] = " .,:;+?%&*$@#"; |
72 |
|
|
COLR nclr; |
73 |
|
|
register int b; |
74 |
|
|
|
75 |
|
|
colr_norm(clr, nclr); |
76 |
|
|
b = norm_bright(nclr); |
77 |
|
|
b = b*NSHADES/256; |
78 |
|
|
return(shadech[b]); |
79 |
|
|
|
80 |
|
|
#undef NSHADES |
81 |
greg |
1.1 |
} |