ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/oki20c.c
Revision: 2.10
Committed: Mon Aug 2 14:39:07 1993 UTC (30 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.9: +0 -3 lines
Log Message:
removed questionable line buffer setting

File Contents

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