--- ray/src/px/oki20c.c 1989/10/20 12:07:08 1.4 +++ 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[]; @@ -45,7 +53,7 @@ char *fname; { FILE *input; int xres, yres; - COLOR scanline[NCOLS]; + COLR scanline[NCOLS]; int i; if (fname == NULL) { @@ -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); } @@ -67,13 +78,16 @@ char *fname; return(-1); } /* set line spacing (overlap for knitting) */ - fputs("\0333\036", stdout); + fputs("\0333\042", stdout); + /* clear line buffer */ + clearlbuf(); /* put out scanlines */ 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); } /* advance page */ @@ -86,27 +100,19 @@ char *fname; plotscan(scan, len, y) /* plot a scanline */ -COLOR scan[]; +COLR scan[]; int len; int y; { - static long pat[NCOLS][3]; int bpos; register long c; register int i, j; - if (bpos = y % 20) { + if (bpos = y % 23) { - if (y > 20 & bpos < 4) /* knit bits */ - for (j = 0; j < 3; j++) - for (i = 0; i < len; i++) - pat[i][j] |= (long)colbit(scan[i],i,j) - << (i+j & 4 ? bpos+24 : bpos); - else - for (j = 0; j < 3; j++) - for (i = 0; i < len; i++) - pat[i][j] |= (long)colbit(scan[i],i,j) - << bpos; + for (j = 0; j < 3; j++) + for (i = 0; i < len; i++) + lpat[i][j] |= (long)colbit(scan[i],i,j) << bpos; } else { @@ -114,18 +120,15 @@ int y; for (j = 0; j < 3; j++) { fputs("\033%O", stdout); - putchar(len & 0xff); + putchar(len & 255); putchar(len >> 8); for (i = 0; i < len; i++) { - c = pat[i][j]; - pat[i][j] = c>>4 & 0xf00000; - if (i+j & 4) /* knit last bit */ - pat[i][j] |= colbit(scan[i],i,j) << 20; - else - c |= colbit(scan[i],i,j); - putchar(c>>16 & 0xff); - putchar(c>>8 & 0xff); - putchar(c & 0xff); + c = lpat[i][j] | colbit(scan[i],i,j); + /* repeat this row */ + lpat[i][j] = (c & 1) << 23; + putchar(c>>16); + putchar(c>>8 & 255); + putchar(c & 255); } putchar('\r'); } @@ -135,21 +138,22 @@ int y; colbit(col, x, s) /* determine bit value for primary at x */ -COLOR col; +COLR col; register int x; int s; { - static float cerr[NCOLS][3]; - static double err[3]; - double b; + static int cerr[NCOLS][3]; + static int err[3], errp[3]; + int b; register int a, ison; a = sub_add(s); /* use additive primary */ - b = colval(col,a); - if (b > 1.0) b = 1.0; + b = col[a]; + errp[a] = err[a]; err[a] += b + cerr[x][a]; - ison = err[a] < 0.5; - if (!ison) err[a] -= 1.0; - cerr[x][a] = err[a] *= 0.5; + ison = err[a] < 128; + if (!ison) err[a] -= 256; + err[a] /= 3; + cerr[x][a] = err[a] + errp[a]; return(ison); }