ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/oki20c.c
Revision: 1.3
Committed: Fri Oct 20 10:28:59 1989 UTC (34 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.2: +12 -7 lines
Log Message:
added knitting to reduce printline artifacts

File Contents

# Content
1 /* Copyright (c) 1986 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
17
18 #define NROWS 1440 /* 10" at 144 dpi */
19 #define NCOLS 960 /* 8" at 120 dpi */
20
21 /*
22 * Subtractive primaries are ordered: Yellow, Magenta, Cyan.
23 */
24
25 #define sub_add(sub) (2-(sub)) /* map subtractive to additive pri. */
26
27
28 main(argc, argv)
29 int argc;
30 char *argv[];
31 {
32 int i, status = 0;
33
34 if (argc < 2)
35 status = printp(NULL) == -1;
36 else
37 for (i = 1; i < argc; i++)
38 status += printp(argv[i]) == -1;
39 exit(status);
40 }
41
42
43 printp(fname) /* print a picture */
44 char *fname;
45 {
46 FILE *input;
47 int xres, yres;
48 COLOR scanline[NCOLS];
49 int i;
50
51 if (fname == NULL) {
52 input = stdin;
53 fname = "<stdin>";
54 } else if ((input = fopen(fname, "r")) == NULL) {
55 fprintf(stderr, "%s: cannot open\n", fname);
56 return(-1);
57 }
58 /* discard header */
59 getheader(input, NULL);
60 /* get picture dimensions */
61 if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) {
62 fprintf(stderr, "%s: bad picture size\n", fname);
63 return(-1);
64 }
65 if (xres > NCOLS || yres > NROWS) {
66 fprintf(stderr, "%s: resolution mismatch\n", fname);
67 return(-1);
68 }
69 /* set line spacing (overlap for knitting) */
70 fputs("\0333\042", stdout);
71 /* put out scanlines */
72 for (i = yres-1; i >= 0; i--) {
73 if (freadscan(scanline, xres, input) < 0) {
74 fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
75 return(-1);
76 }
77 plotscan(scanline, xres, i);
78 }
79 /* advance page */
80 putchar('\f');
81
82 fclose(input);
83
84 return(0);
85 }
86
87
88 plotscan(scan, len, y) /* plot a scanline */
89 COLOR scan[];
90 int len;
91 int y;
92 {
93 static long pat[NCOLS][3];
94 int bpos;
95 register long c;
96 register int i, j;
97
98 if (bpos = y % 23) {
99
100 for (j = 0; j < 3; j++)
101 for (i = 0; i < len; i++)
102 pat[i][j] |= (long)colbit(scan[i],i,j) << bpos;
103
104 } else {
105
106 fputs("\033\031", stdout);
107
108 for (j = 0; j < 3; j++) {
109 fputs("\033%O", stdout);
110 putchar(len & 255);
111 putchar(len >> 8);
112 for (i = 0; i < len; i++) {
113 if (y!=0 & i+j) { /* knit bit */
114 c = pat[i][j];
115 pat[i][j] = colbit(scan[i],i,j) << 23;
116 } else {
117 c = pat[i][j] | colbit(scan[i],i,j);
118 pat[i][j] = 0;
119 }
120 putchar(c>>16);
121 putchar(c>>8 & 255);
122 putchar(c & 255);
123 }
124 putchar('\r');
125 }
126 putchar('\n');
127 }
128 }
129
130
131 colbit(col, x, s) /* determine bit value for primary at x */
132 COLOR col;
133 register int x;
134 int s;
135 {
136 static float cerr[NCOLS][3];
137 static double err[3];
138 double b;
139 register int a, ison;
140
141 a = sub_add(s); /* use additive primary */
142 b = colval(col,a);
143 if (b > 1.0) b = 1.0;
144 err[a] += b + cerr[x][a];
145 ison = err[a] < 0.5;
146 if (!ison) err[a] -= 1.0;
147 cerr[x][a] = err[a] *= 0.5;
148 return(ison);
149 }