--- ray/src/px/ttyimage.c 1989/09/12 13:04:41 1.2 +++ ray/src/px/ttyimage.c 1991/11/11 14:01:29 1.8 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -13,61 +13,63 @@ static char SCCSid[] = "$SunId$ LBL"; #include #include "color.h" +#include "resolu.h" #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') - ; /* get picture dimensions */ - if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { - fprintf(stderr, "%s: bad picture size\n", progname); + if (checkheader(input, COLRFMT, NULL) < 0 || + fgetresolu(&xres, &yres, input) < 0) { + fprintf(stderr, "%s: bad picture format\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, 0); 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 }