| 1 |
/* Copyright (c) 1992 Regents of the University of California */
|
| 2 |
|
| 3 |
#ifndef lint
|
| 4 |
static char SCCSid[] = "$SunId$ LBL";
|
| 5 |
#endif
|
| 6 |
|
| 7 |
/*
|
| 8 |
* oki20c.c - program to dump pixel file to OkiMate 20 color printer.
|
| 9 |
*
|
| 10 |
* 6/10/87
|
| 11 |
*/
|
| 12 |
|
| 13 |
#include <stdio.h>
|
| 14 |
|
| 15 |
#include "color.h"
|
| 16 |
#include "resolu.h"
|
| 17 |
|
| 18 |
#define NROWS 1440 /* 10" at 144 dpi */
|
| 19 |
#define NCOLS 960 /* 8" at 120 dpi */
|
| 20 |
|
| 21 |
#define ASPECT (120./144.) /* pixel aspect ratio */
|
| 22 |
|
| 23 |
#define FILTER "pfilt -1 -x %d -y %d -p %f %s",NCOLS,NROWS,ASPECT
|
| 24 |
|
| 25 |
#ifdef BSD
|
| 26 |
#define clearlbuf() bzero((char *)lpat, sizeof(lpat))
|
| 27 |
#else
|
| 28 |
#define clearlbuf() (void)memset((char *)lpat, 0, sizeof(lpat))
|
| 29 |
#endif
|
| 30 |
|
| 31 |
long lpat[NCOLS];
|
| 32 |
|
| 33 |
int dofilter = 0; /* filter through pfilt first? */
|
| 34 |
|
| 35 |
|
| 36 |
main(argc, argv)
|
| 37 |
int argc;
|
| 38 |
char *argv[];
|
| 39 |
{
|
| 40 |
int i, status = 0;
|
| 41 |
|
| 42 |
if (argc > 1 && !strcmp(argv[1], "-p")) {
|
| 43 |
dofilter++;
|
| 44 |
argv++; argc--;
|
| 45 |
}
|
| 46 |
#ifdef _IOLBF
|
| 47 |
stdout->_flag &= ~_IOLBF;
|
| 48 |
#endif
|
| 49 |
if (argc < 2)
|
| 50 |
status = printp(NULL) == -1;
|
| 51 |
else
|
| 52 |
for (i = 1; i < argc; i++)
|
| 53 |
status += printp(argv[i]) == -1;
|
| 54 |
exit(status);
|
| 55 |
}
|
| 56 |
|
| 57 |
|
| 58 |
printp(fname) /* print a picture */
|
| 59 |
char *fname;
|
| 60 |
{
|
| 61 |
char buf[64];
|
| 62 |
FILE *input;
|
| 63 |
int xres, yres;
|
| 64 |
COLR scanline[NCOLS];
|
| 65 |
int i;
|
| 66 |
|
| 67 |
if (dofilter) {
|
| 68 |
if (fname == NULL)
|
| 69 |
fname = "";
|
| 70 |
sprintf(buf, FILTER, fname);
|
| 71 |
if ((input = popen(buf, "r")) == NULL) {
|
| 72 |
fprintf(stderr, "Cannot execute: %s\n", buf);
|
| 73 |
return(-1);
|
| 74 |
}
|
| 75 |
fname = buf;
|
| 76 |
} else if (fname == NULL) {
|
| 77 |
input = stdin;
|
| 78 |
fname = "<stdin>";
|
| 79 |
} else if ((input = fopen(fname, "r")) == NULL) {
|
| 80 |
fprintf(stderr, "%s: cannot open\n", fname);
|
| 81 |
return(-1);
|
| 82 |
}
|
| 83 |
/* discard header */
|
| 84 |
if (checkheader(input, COLRFMT, NULL) < 0) {
|
| 85 |
fprintf(stderr, "%s: not a Radiance picture\n", fname);
|
| 86 |
return(-1);
|
| 87 |
}
|
| 88 |
/* get picture dimensions */
|
| 89 |
if (fgetresolu(&xres, &yres, input) < 0) {
|
| 90 |
fprintf(stderr, "%s: bad picture size\n", fname);
|
| 91 |
return(-1);
|
| 92 |
}
|
| 93 |
if (xres > NCOLS || yres > NROWS) {
|
| 94 |
fprintf(stderr, "%s: resolution mismatch\n", fname);
|
| 95 |
return(-1);
|
| 96 |
}
|
| 97 |
/* set line spacing (overlap for knitting) */
|
| 98 |
fputs("\0333\042", stdout);
|
| 99 |
/* clear line buffer */
|
| 100 |
clearlbuf();
|
| 101 |
/* put out scanlines */
|
| 102 |
for (i = yres-1; i >= 0; i--) {
|
| 103 |
if (freadcolrs(scanline, xres, input) < 0) {
|
| 104 |
fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
|
| 105 |
return(-1);
|
| 106 |
}
|
| 107 |
normcolrs(scanline, xres, 0);
|
| 108 |
plotscan(scanline, xres, i);
|
| 109 |
}
|
| 110 |
/* advance page */
|
| 111 |
putchar('\f');
|
| 112 |
|
| 113 |
if (dofilter)
|
| 114 |
pclose(input);
|
| 115 |
else
|
| 116 |
fclose(input);
|
| 117 |
|
| 118 |
return(0);
|
| 119 |
}
|
| 120 |
|
| 121 |
|
| 122 |
plotscan(scan, len, y) /* plot a scanline */
|
| 123 |
COLR scan[];
|
| 124 |
int len;
|
| 125 |
int y;
|
| 126 |
{
|
| 127 |
int bpos;
|
| 128 |
register long c;
|
| 129 |
register int i;
|
| 130 |
|
| 131 |
if (bpos = y % 23) {
|
| 132 |
|
| 133 |
for (i = 0; i < len; i++)
|
| 134 |
lpat[i] |= (long)bit(scan[i],i) << bpos;
|
| 135 |
|
| 136 |
} else {
|
| 137 |
|
| 138 |
fputs("\033%O", stdout);
|
| 139 |
putchar(len & 255);
|
| 140 |
putchar(len >> 8);
|
| 141 |
for (i = 0; i < len; i++) {
|
| 142 |
c = lpat[i] | bit(scan[i],i);
|
| 143 |
/* repeat this row */
|
| 144 |
lpat[i] = (c & 1) << 23;
|
| 145 |
putchar(c>>16);
|
| 146 |
putchar(c>>8 & 255);
|
| 147 |
putchar(c & 255);
|
| 148 |
}
|
| 149 |
putchar('\r');
|
| 150 |
putchar('\n');
|
| 151 |
fflush(stdout);
|
| 152 |
}
|
| 153 |
}
|
| 154 |
|
| 155 |
|
| 156 |
bit(col, x) /* determine bit value for pixel at x */
|
| 157 |
COLR col;
|
| 158 |
register int x;
|
| 159 |
{
|
| 160 |
static int cerr[NCOLS];
|
| 161 |
static int err;
|
| 162 |
int b, errp;
|
| 163 |
register int ison;
|
| 164 |
|
| 165 |
b = normbright(col);
|
| 166 |
errp = err;
|
| 167 |
err += b + cerr[x];
|
| 168 |
ison = err < 128;
|
| 169 |
if (!ison) err -= 256;
|
| 170 |
err /= 3;
|
| 171 |
cerr[x] = err + errp;
|
| 172 |
return(ison);
|
| 173 |
}
|