ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/oki20c.c
Revision: 2.11
Committed: Sat Feb 22 02:07:27 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.10: +2 -4 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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