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

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 * oki20.c - program to dump pixel file to OkiMate 20 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 if (argc < 2)
49 status = printp(NULL) == -1;
50 else
51 for (i = 1; i < argc; i++)
52 status += printp(argv[i]) == -1;
53 exit(status);
54 }
55
56
57 printp(fname) /* print a picture */
58 char *fname;
59 {
60 char buf[64];
61 FILE *input;
62 int xres, yres;
63 COLR scanline[NCOLS];
64 int i;
65
66 if (dofilter) {
67 if (fname == NULL) {
68 sprintf(buf, FILTER, "");
69 fname = "<stdin>";
70 } else
71 sprintf(buf, FILTER, fname);
72 if ((input = popen(buf, "r")) == NULL) {
73 fprintf(stderr, "Cannot execute: %s\n", buf);
74 return(-1);
75 }
76 } else if (fname == NULL) {
77 input = stdin;
78 fname = "<stdin>";
79 } else if ((input = fopen(fname, "r")) == NULL) {
80 fprintf(stderr, "%s: cannot open\n", fname);
81 return(-1);
82 }
83 /* discard header */
84 if (checkheader(input, COLRFMT, NULL) < 0) {
85 fprintf(stderr, "%s: not a Radiance picture\n", fname);
86 return(-1);
87 }
88 /* get picture dimensions */
89 if (fgetresolu(&xres, &yres, input) < 0) {
90 fprintf(stderr, "%s: bad picture size\n", fname);
91 return(-1);
92 }
93 if (xres > NCOLS) {
94 fprintf(stderr, "%s: resolution mismatch\n", fname);
95 return(-1);
96 }
97 /* set line spacing (overlap for knitting) */
98 fputs("\0333\042\022", stdout);
99 /* put out scanlines */
100 for (i = yres-1; i >= 0; i--) {
101 if (freadcolrs(scanline, xres, input) < 0) {
102 fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
103 return(-1);
104 }
105 normcolrs(scanline, xres, 0);
106 plotscan(scanline, xres, i);
107 }
108 /* advance page */
109 putchar('\f');
110
111 if (dofilter)
112 pclose(input);
113 else
114 fclose(input);
115
116 return(0);
117 }
118
119
120 plotscan(scan, len, y) /* plot a scanline */
121 COLR scan[];
122 int len;
123 int y;
124 {
125 int bpos, start, end;
126 register long c;
127 register int i;
128
129 bpos = y % 23;
130 for (i = 0; i < len; i++)
131 lpat[i] |= (long)bit(scan[i],i) << bpos;
132
133 if (bpos)
134 return;
135 /* find limits of non-zero print buffer */
136 for (i = 0; lpat[i] == 0; i++)
137 if (i == len-1) {
138 putchar('\n');
139 return;
140 }
141 start = i - i%12;
142 i = len;
143 while (lpat[--i] == 0)
144 ;
145 end = i;
146 /* skip to start position */
147 for (i = start/12; i-- > 0; )
148 putchar(' ');
149 /* print non-zero portion of buffer */
150 fputs("\033%O", stdout);
151 i = end+1-start;
152 putchar(i & 255);
153 putchar(i >> 8);
154 for (i = start; i <= end; i++) {
155 c = lpat[i];
156 putchar((int)(c>>16));
157 putchar((int)(c>>8 & 255));
158 putchar((int)(c & 255));
159 if (y) /* repeat this row next time */
160 lpat[i] = (c & 1) << 23;
161 else /* or clear for next image */
162 lpat[i] = 0L;
163 }
164 putchar('\r');
165 putchar('\n');
166 fflush(stdout);
167 }
168
169
170 bit(col, x) /* determine bit value for pixel at x */
171 COLR col;
172 register int x;
173 {
174 static int cerr[NCOLS];
175 static int err;
176 int b, errp;
177 register int ison;
178
179 b = normbright(col);
180 errp = err;
181 err += b + cerr[x];
182 ison = err < 128;
183 if (!ison) err -= 256;
184 err /= 3;
185 cerr[x] = err + errp;
186 return(ison);
187 }