ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/oki20c.c
Revision: 1.8
Committed: Fri Jan 26 08:17:33 1990 UTC (34 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.7: +1 -1 lines
Log Message:
added scale factor to normcolrs()

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 COLR 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 (freadcolrs(scanline, xres, input) < 0) {
74 fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
75 return(-1);
76 }
77 normcolrs(scanline, xres, 0);
78 plotscan(scanline, xres, i);
79 }
80 /* advance page */
81 putchar('\f');
82
83 fclose(input);
84
85 return(0);
86 }
87
88
89 plotscan(scan, len, y) /* plot a scanline */
90 COLR scan[];
91 int len;
92 int y;
93 {
94 static long pat[NCOLS][3];
95 int bpos;
96 register long c;
97 register int i, j;
98
99 if (bpos = y % 23) {
100
101 for (j = 0; j < 3; j++)
102 for (i = 0; i < len; i++)
103 pat[i][j] |= (long)colbit(scan[i],i,j) << bpos;
104
105 } else {
106
107 fputs("\033\031", stdout);
108
109 for (j = 0; j < 3; j++) {
110 fputs("\033%O", stdout);
111 putchar(len & 255);
112 putchar(len >> 8);
113 for (i = 0; i < len; i++) {
114 c = pat[i][j] | colbit(scan[i],i,j);
115 /* repeat this row */
116 pat[i][j] = (c & 1) << 23;
117 putchar(c>>16);
118 putchar(c>>8 & 255);
119 putchar(c & 255);
120 }
121 putchar('\r');
122 }
123 putchar('\n');
124 }
125 }
126
127
128 colbit(col, x, s) /* determine bit value for primary at x */
129 COLR col;
130 register int x;
131 int s;
132 {
133 static int cerr[NCOLS][3];
134 static int err[3];
135 int b;
136 register int a, ison;
137
138 a = sub_add(s); /* use additive primary */
139 b = col[a];
140 err[a] += b + cerr[x][a];
141 ison = err[a] < 128;
142 if (!ison) err[a] -= 256;
143 cerr[x][a] = err[a] /= 2;
144 return(ison);
145 }