ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/oki20c.c
Revision: 2.12
Committed: Thu Jun 5 19:29:34 2003 UTC (20 years, 11 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.11: +5 -10 lines
Log Message:
Macros for setting binary file mode. Replacing MSDOS by _WIN32.

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: oki20c.c,v 2.11 2003/02/22 02:07:27 greg Exp $";
3 #endif
4 /*
5 * oki20c.c - program to dump pixel file to OkiMate 20 color printer.
6 */
7
8 #include <stdio.h>
9 #include <time.h>
10
11 #include "platform.h"
12 #include "color.h"
13 #include "resolu.h"
14
15 #define NROWS 1440 /* 10" at 144 dpi */
16 #define NCOLS 960 /* 8" at 120 dpi */
17
18 #define ASPECT (120./144.) /* pixel aspect ratio */
19
20 #define FILTER "pfilt -1 -x %d -y %d -p %f %s",NCOLS,NROWS,ASPECT
21
22 /*
23 * Subtractive primaries are ordered: Yellow, Magenta, Cyan.
24 */
25
26 #define sub_add(sub) (2-(sub)) /* map subtractive to additive pri. */
27
28 long lpat[NCOLS][3];
29
30 int dofilter = 0; /* filter through pfilt first? */
31
32 extern FILE *popen();
33
34
35 main(argc, argv)
36 int argc;
37 char *argv[];
38 {
39 int i, status = 0;
40 SET_DEFAULT_BINARY();
41 SET_FILE_BINARY(stdin);
42 SET_FILE_BINARY(stdout);
43 if (argc > 1 && !strcmp(argv[1], "-p")) {
44 dofilter++;
45 argv++; argc--;
46 }
47 if (argc < 2)
48 status = printp(NULL) == -1;
49 else
50 for (i = 1; i < argc; i++)
51 status += printp(argv[i]) == -1;
52 exit(status);
53 }
54
55
56 printp(fname) /* print a picture */
57 char *fname;
58 {
59 char buf[64];
60 FILE *input;
61 int xres, yres;
62 COLR scanline[NCOLS];
63 int i;
64
65 if (dofilter) {
66 if (fname == NULL) {
67 sprintf(buf, FILTER, "");
68 fname = "<stdin>";
69 } else
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 } else if (fname == NULL) {
76 input = stdin;
77 fname = "<stdin>";
78 } else if ((input = fopen(fname, "r")) == NULL) {
79 fprintf(stderr, "%s: cannot open\n", fname);
80 return(-1);
81 }
82 /* discard header */
83 if (checkheader(input, COLRFMT, NULL) < 0) {
84 fprintf(stderr, "%s: not a Radiance picture\n", fname);
85 return(-1);
86 }
87 /* get picture dimensions */
88 if (fgetresolu(&xres, &yres, input) < 0) {
89 fprintf(stderr, "%s: bad picture size\n", fname);
90 return(-1);
91 }
92 if (xres > NCOLS) {
93 fprintf(stderr, "%s: resolution mismatch\n", fname);
94 return(-1);
95 }
96 /* set line spacing (overlap for knitting) */
97 fputs("\0333\042", stdout);
98 /* put out scanlines */
99 for (i = yres-1; i >= 0; i--) {
100 if (freadcolrs(scanline, xres, input) < 0) {
101 fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
102 return(-1);
103 }
104 normcolrs(scanline, xres, 0);
105 plotscan(scanline, xres, i);
106 }
107 /* advance page */
108 putchar('\f');
109
110 if (dofilter)
111 pclose(input);
112 else
113 fclose(input);
114
115 return(0);
116 }
117
118
119 plotscan(scan, len, y) /* plot a scanline */
120 COLR scan[];
121 int len;
122 int y;
123 {
124 int bpos;
125 register long c;
126 register int i, j;
127
128 if (bpos = y % 23) {
129
130 for (j = 0; j < 3; j++)
131 for (i = 0; i < len; i++)
132 lpat[i][j] |= (long)colbit(scan[i],i,j) << bpos;
133 return;
134 }
135 fputs("\033\031", stdout);
136
137 for (j = 0; j < 3; j++) {
138 i = (NCOLS + len)/2; /* center image */
139 fputs("\033%O", stdout);
140 putchar(i & 255);
141 putchar(i >> 8);
142 while (i-- > len) {
143 putchar(0);
144 putchar(0);
145 putchar(0);
146 }
147 for (i = 0; i < len; i++) {
148 c = lpat[i][j] | colbit(scan[i],i,j);
149 putchar((int)(c>>16));
150 putchar((int)(c>>8 & 255));
151 putchar((int)(c & 255));
152 if (y) /* repeat this row */
153 lpat[i][j] = (c & 1) << 23;
154 else /* or clear for next image */
155 lpat[i][j] = 0L;
156 }
157 putchar('\r');
158 }
159 putchar('\n');
160 fflush(stdout);
161 }
162
163
164 colbit(col, x, s) /* determine bit value for primary at x */
165 COLR col;
166 register int x;
167 int s;
168 {
169 static int cerr[NCOLS][3];
170 static int err[3];
171 int b, errp;
172 register int a, ison;
173
174 a = sub_add(s); /* use additive primary */
175 b = col[a];
176 errp = err[a];
177 err[a] += b + cerr[x][a];
178 ison = err[a] < 128;
179 if (!ison) err[a] -= 256;
180 err[a] /= 3;
181 cerr[x][a] = err[a] + errp;
182 return(ison);
183 }