--- ray/src/px/oki20c.c 1989/10/20 16:44:34 1.6 +++ ray/src/px/oki20c.c 1991/11/11 14:01:31 1.12 @@ -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,8 +13,8 @@ static char SCCSid[] = "$SunId$ LBL"; #include #include "color.h" +#include "resolu.h" - #define NROWS 1440 /* 10" at 144 dpi */ #define NCOLS 960 /* 8" at 120 dpi */ @@ -24,7 +24,15 @@ static char SCCSid[] = "$SunId$ LBL"; #define sub_add(sub) (2-(sub)) /* map subtractive to additive pri. */ +#ifdef BSD +#define clearlbuf() bzero((char *)lpat, sizeof(lpat)) +#else +#define clearlbuf() (void)memset((char *)lpat, 0, sizeof(lpat)) +#endif +long lpat[NCOLS][3]; + + main(argc, argv) int argc; char *argv[]; @@ -56,9 +64,12 @@ char *fname; return(-1); } /* discard header */ - getheader(input, NULL); + 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); } @@ -68,13 +79,15 @@ char *fname; } /* set line spacing (overlap for knitting) */ fputs("\0333\042", stdout); + /* clear line buffer */ + clearlbuf(); /* put out scanlines */ 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); } - normscan(scanline, xres); + normcolrs(scanline, xres, 0); plotscan(scanline, xres, i); } /* advance page */ @@ -86,23 +99,11 @@ char *fname; } -normscan(scan, len) /* normalize a scanline */ -register COLR scan[]; -int len; -{ - register int i; - - for (i = 0; i < len; i++) - colr_norm(scan[i], scan[i]); -} - - plotscan(scan, len, y) /* plot a scanline */ COLR scan[]; int len; int y; { - static long pat[NCOLS][3]; int bpos; register long c; register int i, j; @@ -111,7 +112,7 @@ int y; for (j = 0; j < 3; j++) for (i = 0; i < len; i++) - pat[i][j] |= (long)colbit(scan[i],i,j) << bpos; + lpat[i][j] |= (long)colbit(scan[i],i,j) << bpos; } else { @@ -122,9 +123,9 @@ int y; putchar(len & 255); putchar(len >> 8); for (i = 0; i < len; i++) { - c = pat[i][j] | colbit(scan[i],i,j); + c = lpat[i][j] | colbit(scan[i],i,j); /* repeat this row */ - pat[i][j] = (c & 1) << 23; + lpat[i][j] = (c & 1) << 23; putchar(c>>16); putchar(c>>8 & 255); putchar(c & 255); @@ -142,15 +143,17 @@ register int x; int s; { static int cerr[NCOLS][3]; - static int err[3]; + static int err[3], errp[3]; int b; register int a, ison; a = sub_add(s); /* use additive primary */ b = col[a]; + errp[a] = err[a]; err[a] += b + cerr[x][a]; ison = err[a] < 128; if (!ison) err[a] -= 256; - cerr[x][a] = err[a] /= 2; + err[a] /= 3; + cerr[x][a] = err[a] + errp[a]; return(ison); }