ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/oki20c.c
Revision: 2.16
Committed: Sun Mar 28 20:33:14 2004 UTC (20 years, 1 month ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R6P1, rad3R6
Changes since 2.15: +26 -14 lines
Log Message:
Continued ANSIfication, and other fixes and clarifications.

File Contents

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