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