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