1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
13 |
|
#include <stdio.h> |
14 |
|
|
15 |
|
#include "color.h" |
16 |
+ |
#include "resolu.h" |
17 |
|
|
18 |
|
|
19 |
|
#define NCOLS 133 |
20 |
|
|
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 |
– |
|
22 |
|
main(argc, argv) |
23 |
|
int argc; |
24 |
|
char **argv; |
25 |
|
{ |
26 |
|
FILE *input; |
27 |
|
int xres, yres; |
28 |
< |
COLOR scanline[NCOLS]; |
37 |
< |
char sbuf[256]; |
28 |
> |
COLR scanline[NCOLS]; |
29 |
|
register int i, j; |
30 |
|
|
40 |
– |
progname = argv[0]; |
41 |
– |
|
31 |
|
if (argc < 2) |
32 |
|
input = stdin; |
33 |
|
else if ((input = fopen(argv[1], "r")) == NULL) { |
34 |
< |
fprintf(stderr, "%s: can't open file \"%s\"\n", progname, argv[1]); |
34 |
> |
fprintf(stderr, "%s: can't open file \"%s\"\n", argv[0], argv[1]); |
35 |
|
exit(1); |
36 |
|
} |
37 |
|
|
49 |
– |
/* discard header */ |
50 |
– |
while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n') |
51 |
– |
; |
38 |
|
/* get picture dimensions */ |
39 |
< |
if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { |
40 |
< |
fprintf(stderr, "%s: bad picture size\n", progname); |
39 |
> |
if (checkheader(input, COLRFMT, NULL) < 0 || |
40 |
> |
fgetresolu(&xres, &yres, input) < 0) { |
41 |
> |
fprintf(stderr, "%s: bad picture format\n", argv[0]); |
42 |
|
exit(1); |
43 |
|
} |
44 |
|
if (xres > NCOLS) { |
45 |
< |
fprintf(stderr, "%s: resolution mismatch\n", progname); |
45 |
> |
fprintf(stderr, "%s: resolution mismatch\n", argv[0]); |
46 |
|
exit(1); |
47 |
|
} |
48 |
|
|
49 |
|
for (i = 0; i < yres; i++) { |
50 |
< |
if (freadscan(scanline, xres, input) < 0) { |
51 |
< |
fprintf(stderr, "%s: read error\n", progname); |
50 |
> |
if (freadcolrs(scanline, xres, input) < 0) { |
51 |
> |
fprintf(stderr, "%s: read error\n", argv[0]); |
52 |
|
exit(1); |
53 |
|
} |
54 |
+ |
normcolrs(scanline, xres, 0); |
55 |
|
for (j = 0; j < xres; j++) |
56 |
< |
putchar(shadech[shade(scanline[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 |
|
} |