--- ray/src/px/oki20c.c 1990/07/10 09:07:48 1.9 +++ ray/src/px/oki20c.c 1992/04/18 09:10:53 2.6 @@ -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,11 +13,15 @@ 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 */ +#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. */ @@ -32,13 +36,22 @@ static char SCCSid[] = "$SunId$ LBL"; 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 @@ -51,12 +64,23 @@ char *argv[]; printp(fname) /* print a picture */ char *fname; { + char buf[64]; FILE *input; int xres, yres; 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) { @@ -64,9 +88,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); } @@ -90,7 +117,10 @@ char *fname; /* advance page */ putchar('\f'); - fclose(input); + if (dofilter) + pclose(input); + else + fclose(input); return(0); } @@ -116,9 +146,15 @@ int y; fputs("\033\031", stdout); for (j = 0; j < 3; j++) { + i = (NCOLS + len)/2; /* center image */ fputs("\033%O", stdout); - putchar(len & 255); - putchar(len >> 8); + putchar(i & 255); + putchar(i >> 8); + while (i-- > len) { + putchar(0); + putchar(0); + putchar(0); + } for (i = 0; i < len; i++) { c = lpat[i][j] | colbit(scan[i],i,j); /* repeat this row */ @@ -130,6 +166,7 @@ int y; putchar('\r'); } putchar('\n'); + fflush(stdout); } } @@ -141,14 +178,16 @@ int s; { static int cerr[NCOLS][3]; static int err[3]; - int b; + int b, errp; register int a, ison; a = sub_add(s); /* use additive primary */ b = col[a]; + errp = 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; return(ison); }