--- ray/src/px/oki20.c 1992/04/18 09:10:51 2.2 +++ ray/src/px/oki20.c 1992/07/03 10:46:27 2.5 @@ -6,8 +6,6 @@ static char SCCSid[] = "$SunId$ LBL"; /* * oki20c.c - program to dump pixel file to OkiMate 20 color printer. - * - * 6/10/87 */ #include @@ -22,12 +20,6 @@ static char SCCSid[] = "$SunId$ LBL"; #define FILTER "pfilt -1 -x %d -y %d -p %f %s",NCOLS,NROWS,ASPECT -#ifdef BSD -#define clearlbuf() bzero((char *)lpat, sizeof(lpat)) -#else -#define clearlbuf() (void)memset((char *)lpat, 0, sizeof(lpat)) -#endif - long lpat[NCOLS]; int dofilter = 0; /* filter through pfilt first? */ @@ -91,14 +83,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(); + fputs("\0333\042\022", stdout); /* put out scanlines */ for (i = yres-1; i >= 0; i--) { if (freadcolrs(scanline, xres, input) < 0) { @@ -125,32 +115,48 @@ COLR scan[]; int len; int y; { - int bpos; + int bpos, start, end; register long c; register int i; - if (bpos = y % 23) { + bpos = y % 23; + for (i = 0; i < len; i++) + lpat[i] |= (long)bit(scan[i],i) << bpos; - for (i = 0; i < len; i++) - lpat[i] |= (long)bit(scan[i],i) << bpos; - - } else { - - fputs("\033%O", stdout); - putchar(len & 255); - putchar(len >> 8); - for (i = 0; i < len; i++) { - c = lpat[i] | bit(scan[i],i); - /* repeat this row */ - lpat[i] = (c & 1) << 23; - putchar(c>>16); - putchar(c>>8 & 255); - putchar(c & 255); + if (bpos) + return; + /* find limits of non-zero print buffer */ + for (i = 0; lpat[i] == 0; i++) + if (i == len-1) { + putchar('\n'); + return; } - putchar('\r'); - putchar('\n'); - fflush(stdout); + start = i - i%12; + i = len; + while (lpat[--i] == 0) + ; + end = i; + /* skip to start position */ + for (i = start/12; i-- > 0; ) + putchar(' '); + /* print non-zero portion of buffer */ + fputs("\033%O", stdout); + i = end+1-start; + putchar(i & 255); + putchar(i >> 8); + for (i = start; i <= end; i++) { + c = lpat[i]; + putchar(c>>16); + putchar(c>>8 & 255); + putchar(c & 255); + if (y) /* repeat this row next time */ + lpat[i] = (c & 1) << 23; + else /* or clear for next image */ + lpat[i] = 0L; } + putchar('\r'); + putchar('\n'); + fflush(stdout); }