ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/oki20.c
Revision: 2.4
Committed: Fri Jul 3 10:30:07 1992 UTC (31 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.3: +35 -23 lines
Log Message:
made more efficint use of ribbon by skipping white areas

File Contents

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