--- ray/src/px/oki20c.c 1991/11/11 14:01:31 1.12 +++ ray/src/px/oki20c.c 1993/08/02 14:39:07 2.10 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -6,39 +6,51 @@ static char SCCSid[] = "$SunId$ LBL"; /* * oki20c.c - program to dump pixel file to OkiMate 20 color printer. - * - * 6/10/87 */ #include +#ifdef MSDOS +#include +#endif #include "color.h" #include "resolu.h" -#define NROWS 1440 /* 10" at 144 dpi */ -#define NCOLS 960 /* 8" at 120 dpi */ +#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. + * Subtractive primaries are ordered: Yellow, Magenta, Cyan. */ -#define sub_add(sub) (2-(sub)) /* map subtractive to additive pri. */ +#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]; +int dofilter = 0; /* filter through pfilt first? */ +extern FILE *popen(); + + main(argc, argv) int argc; char *argv[]; { int i, status = 0; - +#ifdef MSDOS + extern int _fmode; + _fmode = O_BINARY; + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); +#endif + if (argc > 1 && !strcmp(argv[1], "-p")) { + dofilter++; + argv++; argc--; + } if (argc < 2) status = printp(NULL) == -1; else @@ -51,12 +63,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) { @@ -73,14 +96,12 @@ char *fname; 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); } /* 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) { @@ -93,7 +114,10 @@ char *fname; /* advance page */ putchar('\f'); - fclose(input); + if (dofilter) + pclose(input); + else + fclose(input); return(0); } @@ -113,27 +137,34 @@ int y; for (j = 0; j < 3; j++) for (i = 0; i < len; i++) 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 = lpat[i][j] | colbit(scan[i],i,j); - /* repeat this row */ + 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); + } + for (i = 0; i < len; i++) { + c = lpat[i][j] | colbit(scan[i],i,j); + putchar((int)(c>>16)); + putchar((int)(c>>8 & 255)); + putchar((int)(c & 255)); + if (y) /* repeat this row */ lpat[i][j] = (c & 1) << 23; - putchar(c>>16); - putchar(c>>8 & 255); - putchar(c & 255); - } - putchar('\r'); + else /* or clear for next image */ + lpat[i][j] = 0L; } - putchar('\n'); + putchar('\r'); } + putchar('\n'); + fflush(stdout); } @@ -143,17 +174,17 @@ register int x; int s; { static int cerr[NCOLS][3]; - static int err[3], errp[3]; - int b; + static int err[3]; + int b, errp; register int a, ison; a = sub_add(s); /* use additive primary */ b = col[a]; - errp[a] = err[a]; + errp = err[a]; err[a] += b + cerr[x][a]; ison = err[a] < 128; if (!ison) err[a] -= 256; err[a] /= 3; - cerr[x][a] = err[a] + errp[a]; + cerr[x][a] = err[a] + errp; return(ison); }