ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/oki20.c
Revision: 2.3
Committed: Fri Jul 3 08:59:24 1992 UTC (31 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +1 -1 lines
Log Message:
removed limit on number of rows in output

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