--- ray/src/px/mt160r.c 1989/09/12 13:04:18 1.2 +++ ray/src/px/mt160r.c 1991/11/12 16:04:57 2.1 @@ -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 */ @@ -38,8 +39,7 @@ char *fname; { FILE *input; int xres, yres; - COLOR scanline[NCOLS]; - char sbuf[256]; + COLR scanline[NCOLS]; 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); } @@ -65,10 +67,11 @@ char *fname; fputs("\033[6~\033[7z", stdout); for (i = yres-1; i >= 0; i--) { - if (freadscan(scanline, xres, input) < 0) { + 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); } @@ -81,7 +84,7 @@ char *fname; plotscan(scan, len, y) /* plot a scanline */ -COLOR scan[]; +COLR scan[]; int len; int y; { @@ -111,20 +114,21 @@ int y; } -bit(col, x) /* return bit for color at x */ -COLOR col; +bit(clr, x) /* return bit for color at x */ +COLR clr; register int x; { - static float cerr[NCOLS]; - static double err; - double b; + static int cerr[NCOLS]; + static int err, errp; + int b; register int isblack; - b = bright(col); - if (b > 1.0) b = 1.0; + b = normbright(clr); + errp = err; err += b + cerr[x]; - isblack = err < 0.5; - if (!isblack) err -= 1.0; - cerr[x] = err *= 0.5; + isblack = err < 128; + if (!isblack) err -= 256; + err /= 3; + cerr[x] = err + errp; return(isblack); }