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

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