ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/oki20c.c
Revision: 2.14
Committed: Mon Oct 27 10:24:51 2003 UTC (20 years, 6 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.13: +2 -3 lines
Log Message:
Various compatibility fixes.

File Contents

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