--- ray/src/px/mt160r.c 1989/02/02 10:49:20 1.1 +++ ray/src/px/mt160r.c 2004/03/28 20:33:14 2.8 @@ -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.8 2004/03/28 20:33:14 schorsch Exp $"; #endif - /* * mt160r.c - program to dump pixel file to Mannesman-Tally 160. * @@ -11,19 +8,30 @@ 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 */ +static int printp(char *fname); +static void plotscan(COLR scan[], int len, int y); +static int bit(COLR clr, int x); -main(argc, argv) -int argc; -char *argv[]; + +int +main( + int argc, + 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 @@ -33,15 +41,16 @@ char *argv[]; } -printp(fname) /* print a picture */ -char *fname; +static int +printp( /* print a picture */ + 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 +59,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 +76,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,16 +92,18 @@ char *fname; } -plotscan(scan, len, y) /* plot a scanline */ -COLOR scan[]; -int len; -int y; +static void +plotscan( /* plot a scanline */ + COLR scan[], + int len, + int y +) { static BYTE pat[NCOLS]; int bpos; register int i; - if (bpos = y & 7) { + if ((bpos = y & 7)) { for (i = 0; i < len; i++) pat[i] |= bit(scan[i], i) << bpos; @@ -108,24 +121,28 @@ int y; } putchar('\r'); putchar('\n'); + fflush(stdout); } } -bit(col, x) /* return bit for color at x */ -COLOR col; -register int x; +static int +bit( /* 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); }