--- ray/src/px/mt160r.c 1989/10/20 16:44:32 1.3 +++ ray/src/px/mt160r.c 1992/01/29 15:18:34 2.3 @@ -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,6 +13,7 @@ static char SCCSid[] = "$SunId$ LBL"; #include #include "color.h" +#include "resolu.h" #define NCOLS 880 /* for wide carriage */ @@ -39,7 +40,6 @@ char *fname; FILE *input; int xres, yres; COLR scanline[NCOLS]; - char sbuf[256]; int i; if (fname == NULL) { @@ -50,10 +50,12 @@ char *fname; return(-1); } /* discard header */ - while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n') - ; + if (checkheader(input, COLRFMT, NULL) < 0) { + fprintf(stderr, "%s: not a Radiance picture\n", fname); + return(-1); + } /* get picture dimensions */ - if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) { + if (fgetresolu(&xres, &yres, input) < 0) { fprintf(stderr, "%s: bad picture size\n", fname); return(-1); } @@ -63,12 +65,16 @@ char *fname; } fputs("\033[6~\033[7z", stdout); +#ifdef _IOLBF + stdout->_flag &= ~_IOLBF; +#endif for (i = yres-1; i >= 0; i--) { if (freadcolrs(scanline, xres, input) < 0) { fprintf(stderr, "%s: read error (y=%d)\n", fname, i); return(-1); } + normcolrs(scanline, xres, 0); plotscan(scanline, xres, i); } @@ -107,6 +113,7 @@ int y; } putchar('\r'); putchar('\n'); + fflush(stdout); } } @@ -117,15 +124,15 @@ register int x; { static int cerr[NCOLS]; static int err; - COLR nclr; - int b; + int b, errp; register int isblack; - colr_norm(clr, nclr); - b = norm_bright(nclr); + b = normbright(clr); + errp = err; err += b + cerr[x]; isblack = err < 128; if (!isblack) err -= 256; - cerr[x] = err /= 2; + err /= 3; + cerr[x] = err + errp; return(isblack); }