--- ray/src/px/ttyimage.c 1989/02/02 10:49:42 1.1 +++ ray/src/px/ttyimage.c 1990/01/25 08:28:36 1.5 @@ -17,58 +17,59 @@ static char SCCSid[] = "$SunId$ LBL"; #define NCOLS 133 -char shadech[] = " .,:;+?%&*$@#"; -#define NSHADES (sizeof(shadech)-1) - -#define shade(col) ( bright(col)>=1.0 ? NSHADES-1 : \ - (int)(bright(col)*NSHADES) ) - -char *progname; - - main(argc, argv) int argc; char **argv; { FILE *input; int xres, yres; - COLOR scanline[NCOLS]; - char sbuf[256]; + COLR scanline[NCOLS]; register int i, j; - progname = argv[0]; - if (argc < 2) input = stdin; else if ((input = fopen(argv[1], "r")) == NULL) { - fprintf(stderr, "%s: can't open file \"%s\"\n", progname, argv[1]); + fprintf(stderr, "%s: can't open file \"%s\"\n", argv[0], argv[1]); exit(1); } /* discard header */ - while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n') - ; + getheader(input, NULL); /* get picture dimensions */ - if (fgets(sbuf, sizeof(sbuf), input) == NULL || - sscanf(sbuf, "-Y %d +X %d\n", &yres, &xres) != 2) { - fprintf(stderr, "%s: bad picture size\n", progname); + if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { + fprintf(stderr, "%s: bad picture size\n", argv[0]); exit(1); } if (xres > NCOLS) { - fprintf(stderr, "%s: resolution mismatch\n", progname); + fprintf(stderr, "%s: resolution mismatch\n", argv[0]); exit(1); } for (i = 0; i < yres; i++) { - if (freadscan(scanline, xres, input) < 0) { - fprintf(stderr, "%s: read error\n", progname); + if (freadcolrs(scanline, xres, input) < 0) { + fprintf(stderr, "%s: read error\n", argv[0]); exit(1); } + normcolrs(scanline, xres); for (j = 0; j < xres; j++) - putchar(shadech[shade(scanline[j])]); + putchar(shade(scanline[j])); putchar('\n'); } exit(0); +} + + +int +shade(clr) /* return character for color */ +COLR clr; +{ +#define NSHADES 13 + + static char shadech[NSHADES+1] = " .,:;+?%&*$@#"; + + return(shadech[normbright(clr)*NSHADES/256]); + +#undef NSHADES }