--- ray/src/px/oki20c.c 1989/02/02 10:49:21 1.1 +++ ray/src/px/oki20c.c 1992/07/03 10:46:25 2.8 @@ -1,4 +1,4 @@ -/* Copyright (c) 1986 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -6,31 +6,44 @@ static char SCCSid[] = "$SunId$ LBL"; /* * oki20c.c - program to dump pixel file to OkiMate 20 color printer. - * - * 6/10/87 */ #include #include "color.h" +#include "resolu.h" - #define NROWS 1440 /* 10" at 144 dpi */ #define NCOLS 960 /* 8" at 120 dpi */ +#define ASPECT (120./144.) /* pixel aspect ratio */ + +#define FILTER "pfilt -1 -x %d -y %d -p %f %s",NCOLS,NROWS,ASPECT + /* * Subtractive primaries are ordered: Yellow, Magenta, Cyan. */ #define sub_add(sub) (2-(sub)) /* map subtractive to additive pri. */ +long lpat[NCOLS][3]; +int dofilter = 0; /* filter through pfilt first? */ + + main(argc, argv) int argc; char *argv[]; { int i, status = 0; + if (argc > 1 && !strcmp(argv[1], "-p")) { + dofilter++; + argv++; argc--; + } +#ifdef _IOLBF + stdout->_flag &= ~_IOLBF; +#endif if (argc < 2) status = printp(NULL) == -1; else @@ -43,12 +56,23 @@ char *argv[]; printp(fname) /* print a picture */ char *fname; { + char buf[64]; FILE *input; int xres, yres; - COLOR scanline[NCOLS]; + COLR scanline[NCOLS]; int i; - if (fname == NULL) { + if (dofilter) { + if (fname == NULL) { + sprintf(buf, FILTER, ""); + fname = ""; + } else + sprintf(buf, FILTER, fname); + if ((input = popen(buf, "r")) == NULL) { + fprintf(stderr, "Cannot execute: %s\n", buf); + return(-1); + } + } else if (fname == NULL) { input = stdin; fname = ""; } else if ((input = fopen(fname, "r")) == NULL) { @@ -56,89 +80,104 @@ 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 (fscanf(input, "-Y %d +X %d\n", &yres, &xres) != 2) { + if (fgetresolu(&xres, &yres, input) < 0) { fprintf(stderr, "%s: bad picture size\n", fname); return(-1); } - if (xres > NCOLS || yres > NROWS) { + if (xres > NCOLS) { fprintf(stderr, "%s: resolution mismatch\n", fname); return(-1); } - - fputs("\033A\014\0332", stdout); - + /* set line spacing (overlap for knitting) */ + fputs("\0333\042", stdout); + /* 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 */ putchar('\f'); - fclose(input); + if (dofilter) + pclose(input); + else + fclose(input); return(0); } 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 % 24) { + if (bpos = y % 23) { 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; + return; + } + fputs("\033\031", stdout); - } else { - - fputs("\033\031", stdout); - - for (j = 0; j < 3; j++) { - fputs("\033%O", stdout); - putchar(len & 255); - putchar(len >> 8); - for (i = 0; i < len; i++) { - c = pat[i][j] | colbit(scan[i],i,j); - pat[i][j] = 0; - putchar(c>>16); - putchar(c>>8 & 255); - putchar(c & 255); - } - putchar('\r'); + for (j = 0; j < 3; j++) { + i = (NCOLS + len)/2; /* center image */ + fputs("\033%O", stdout); + putchar(i & 255); + putchar(i >> 8); + while (i-- > len) { + putchar(0); + putchar(0); + putchar(0); } - putchar('\n'); + for (i = 0; i < len; i++) { + c = lpat[i][j] | colbit(scan[i],i,j); + putchar(c>>16); + putchar(c>>8 & 255); + putchar(c & 255); + if (y) /* repeat this row */ + lpat[i][j] = (c & 1) << 23; + else /* or clear for next image */ + lpat[i][j] = 0L; + } + putchar('\r'); } + putchar('\n'); + fflush(stdout); } 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]; + int b, errp; 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 = 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; return(ison); }