--- ray/src/px/mt160r.c 1989/10/20 16:44:32 1.3 +++ ray/src/px/mt160r.c 2003/02/22 02:07:27 2.6 @@ -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.6 2003/02/22 02:07:27 greg Exp $"; #endif - /* * mt160r.c - program to dump pixel file to Mannesman-Tally 160. * @@ -11,10 +8,15 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include +#ifdef MSDOS +#include +#endif +#include #include "color.h" +#include "resolu.h" -#define NCOLS 880 /* for wide carriage */ +#define NCOLS 880 /* for wide carriage */ main(argc, argv) @@ -23,7 +25,12 @@ char *argv[]; { int i; int status = 0; - +#ifdef MSDOS + extern int _fmode; + _fmode = O_BINARY; + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); +#endif if (argc < 2) status += printp(NULL) == -1; else @@ -39,9 +46,8 @@ char *fname; FILE *input; int xres, yres; COLR scanline[NCOLS]; - char sbuf[256]; int i; - + if (fname == NULL) { input = stdin; fname = ""; @@ -50,10 +56,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); } @@ -69,6 +77,7 @@ char *fname; fprintf(stderr, "%s: read error (y=%d)\n", fname, i); return(-1); } + normcolrs(scanline, xres, 0); plotscan(scanline, xres, i); } @@ -107,6 +116,7 @@ int y; } putchar('\r'); putchar('\n'); + fflush(stdout); } } @@ -117,15 +127,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); }