ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/oki20.c
Revision: 2.9
Committed: Sat Feb 22 02:07:27 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.8: +2 -4 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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