--- ray/src/px/mt160r.c 1989/02/02 10:49:20 1.1 +++ ray/src/px/mt160r.c 2003/06/05 19:29:34 2.7 @@ -1,9 +1,6 @@ -/* Copyright (c) 1986 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: mt160r.c,v 2.7 2003/06/05 19:29:34 schorsch Exp $"; #endif - /* * mt160r.c - program to dump pixel file to Mannesman-Tally 160. * @@ -11,10 +8,13 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include +#include +#include "platform.h" #include "color.h" +#include "resolu.h" -#define NCOLS 880 /* for wide carriage */ +#define NCOLS 880 /* for wide carriage */ main(argc, argv) @@ -23,7 +23,9 @@ char *argv[]; { int i; int status = 0; - + SET_DEFAULT_BINARY(); + SET_FILE_BINARY(stdin); + SET_FILE_BINARY(stdout); if (argc < 2) status += printp(NULL) == -1; else @@ -38,10 +40,9 @@ char *fname; { FILE *input; int xres, yres; - COLOR scanline[NCOLS]; - char sbuf[256]; + COLR scanline[NCOLS]; int i; - + if (fname == NULL) { input = stdin; fname = ""; @@ -50,11 +51,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 (fgets(sbuf, sizeof(sbuf), input) == NULL || - sscanf(sbuf, "-Y %d +X %d\n", &yres, &xres) != 2) { + if (fgetresolu(&xres, &yres, input) < 0) { fprintf(stderr, "%s: bad picture size\n", fname); return(-1); } @@ -66,10 +68,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); } @@ -82,7 +85,7 @@ char *fname; plotscan(scan, len, y) /* plot a scanline */ -COLOR scan[]; +COLR scan[]; int len; int y; { @@ -108,24 +111,26 @@ int y; } putchar('\r'); putchar('\n'); + fflush(stdout); } } -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; + int b, errp; 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); }