ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/oki20.c
Revision: 2.11
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.10: +2 -3 lines
Log Message:
Various compatibility fixes.

File Contents

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