ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/oki20.c
Revision: 2.6
Committed: Mon Sep 21 12:13:33 1992 UTC (31 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.5: +18 -8 lines
Log Message:
Changes for PC port

File Contents

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