1 |
greg |
2.2 |
/* Copyright (c) 1992 Regents of the University of California */ |
2 |
greg |
1.1 |
|
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 |
greg |
2.2 |
#ifdef MSDOS |
15 |
|
|
#include <fcntl.h> |
16 |
|
|
#endif |
17 |
greg |
1.1 |
|
18 |
|
|
#include "color.h" |
19 |
greg |
1.8 |
#include "resolu.h" |
20 |
greg |
1.1 |
|
21 |
|
|
|
22 |
greg |
2.2 |
#define NCOLS 133 |
23 |
greg |
1.1 |
|
24 |
|
|
|
25 |
|
|
main(argc, argv) |
26 |
|
|
int argc; |
27 |
|
|
char **argv; |
28 |
|
|
{ |
29 |
|
|
FILE *input; |
30 |
|
|
int xres, yres; |
31 |
greg |
1.3 |
COLR scanline[NCOLS]; |
32 |
greg |
1.1 |
register int i, j; |
33 |
|
|
|
34 |
|
|
if (argc < 2) |
35 |
|
|
input = stdin; |
36 |
|
|
else if ((input = fopen(argv[1], "r")) == NULL) { |
37 |
greg |
1.3 |
fprintf(stderr, "%s: can't open file \"%s\"\n", argv[0], argv[1]); |
38 |
greg |
1.1 |
exit(1); |
39 |
|
|
} |
40 |
greg |
2.2 |
#ifdef MSDOS |
41 |
|
|
setmode(fileno(input), O_BINARY); |
42 |
|
|
#endif |
43 |
greg |
1.1 |
/* get picture dimensions */ |
44 |
greg |
1.7 |
if (checkheader(input, COLRFMT, NULL) < 0 || |
45 |
greg |
1.8 |
fgetresolu(&xres, &yres, input) < 0) { |
46 |
greg |
1.7 |
fprintf(stderr, "%s: bad picture format\n", argv[0]); |
47 |
greg |
1.1 |
exit(1); |
48 |
|
|
} |
49 |
|
|
if (xres > NCOLS) { |
50 |
greg |
1.3 |
fprintf(stderr, "%s: resolution mismatch\n", argv[0]); |
51 |
greg |
1.1 |
exit(1); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
for (i = 0; i < yres; i++) { |
55 |
greg |
1.3 |
if (freadcolrs(scanline, xres, input) < 0) { |
56 |
|
|
fprintf(stderr, "%s: read error\n", argv[0]); |
57 |
greg |
1.1 |
exit(1); |
58 |
|
|
} |
59 |
greg |
1.6 |
normcolrs(scanline, xres, 0); |
60 |
greg |
1.1 |
for (j = 0; j < xres; j++) |
61 |
greg |
1.3 |
putchar(shade(scanline[j])); |
62 |
greg |
1.1 |
putchar('\n'); |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
exit(0); |
66 |
greg |
1.3 |
} |
67 |
|
|
|
68 |
|
|
|
69 |
|
|
int |
70 |
|
|
shade(clr) /* return character for color */ |
71 |
|
|
COLR clr; |
72 |
|
|
{ |
73 |
greg |
2.2 |
#define NSHADES 13 |
74 |
greg |
1.3 |
|
75 |
|
|
static char shadech[NSHADES+1] = " .,:;+?%&*$@#"; |
76 |
|
|
|
77 |
greg |
1.4 |
return(shadech[normbright(clr)*NSHADES/256]); |
78 |
greg |
1.3 |
|
79 |
|
|
#undef NSHADES |
80 |
greg |
1.1 |
} |