ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/oki20c.c
Revision: 1.4
Committed: Fri Oct 20 12:07:08 1989 UTC (34 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.3: +22 -16 lines
Log Message:
changed to 4x4 knit

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1986 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    
17    
18     #define NROWS 1440 /* 10" at 144 dpi */
19     #define NCOLS 960 /* 8" at 120 dpi */
20    
21     /*
22     * Subtractive primaries are ordered: Yellow, Magenta, Cyan.
23     */
24    
25     #define sub_add(sub) (2-(sub)) /* map subtractive to additive pri. */
26    
27    
28     main(argc, argv)
29     int argc;
30     char *argv[];
31     {
32     int i, status = 0;
33    
34     if (argc < 2)
35     status = printp(NULL) == -1;
36     else
37     for (i = 1; i < argc; i++)
38     status += printp(argv[i]) == -1;
39     exit(status);
40     }
41    
42    
43     printp(fname) /* print a picture */
44     char *fname;
45     {
46     FILE *input;
47     int xres, yres;
48     COLOR scanline[NCOLS];
49     int i;
50    
51     if (fname == NULL) {
52     input = stdin;
53     fname = "<stdin>";
54     } else if ((input = fopen(fname, "r")) == NULL) {
55     fprintf(stderr, "%s: cannot open\n", fname);
56     return(-1);
57     }
58     /* discard header */
59     getheader(input, NULL);
60     /* get picture dimensions */
61 greg 1.2 if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) {
62 greg 1.1 fprintf(stderr, "%s: bad picture size\n", fname);
63     return(-1);
64     }
65     if (xres > NCOLS || yres > NROWS) {
66     fprintf(stderr, "%s: resolution mismatch\n", fname);
67     return(-1);
68     }
69 greg 1.3 /* set line spacing (overlap for knitting) */
70 greg 1.4 fputs("\0333\036", stdout);
71 greg 1.3 /* put out scanlines */
72 greg 1.1 for (i = yres-1; i >= 0; i--) {
73     if (freadscan(scanline, xres, input) < 0) {
74     fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
75     return(-1);
76     }
77     plotscan(scanline, xres, i);
78     }
79 greg 1.3 /* advance page */
80 greg 1.1 putchar('\f');
81    
82     fclose(input);
83    
84     return(0);
85     }
86    
87    
88     plotscan(scan, len, y) /* plot a scanline */
89     COLOR scan[];
90     int len;
91     int y;
92     {
93     static long pat[NCOLS][3];
94     int bpos;
95     register long c;
96     register int i, j;
97    
98 greg 1.4 if (bpos = y % 20) {
99 greg 1.1
100 greg 1.4 if (y > 20 & bpos < 4) /* knit bits */
101     for (j = 0; j < 3; j++)
102     for (i = 0; i < len; i++)
103     pat[i][j] |= (long)colbit(scan[i],i,j)
104     << (i+j & 4 ? bpos+24 : bpos);
105     else
106     for (j = 0; j < 3; j++)
107     for (i = 0; i < len; i++)
108     pat[i][j] |= (long)colbit(scan[i],i,j)
109     << bpos;
110 greg 1.1
111     } else {
112    
113     fputs("\033\031", stdout);
114    
115     for (j = 0; j < 3; j++) {
116     fputs("\033%O", stdout);
117 greg 1.4 putchar(len & 0xff);
118 greg 1.1 putchar(len >> 8);
119     for (i = 0; i < len; i++) {
120 greg 1.4 c = pat[i][j];
121     pat[i][j] = c>>4 & 0xf00000;
122     if (i+j & 4) /* knit last bit */
123     pat[i][j] |= colbit(scan[i],i,j) << 20;
124     else
125     c |= colbit(scan[i],i,j);
126     putchar(c>>16 & 0xff);
127     putchar(c>>8 & 0xff);
128     putchar(c & 0xff);
129 greg 1.1 }
130     putchar('\r');
131     }
132     putchar('\n');
133     }
134     }
135    
136    
137     colbit(col, x, s) /* determine bit value for primary at x */
138     COLOR col;
139     register int x;
140     int s;
141     {
142     static float cerr[NCOLS][3];
143     static double err[3];
144     double b;
145     register int a, ison;
146    
147     a = sub_add(s); /* use additive primary */
148     b = colval(col,a);
149     if (b > 1.0) b = 1.0;
150     err[a] += b + cerr[x][a];
151     ison = err[a] < 0.5;
152     if (!ison) err[a] -= 1.0;
153     cerr[x][a] = err[a] *= 0.5;
154     return(ison);
155     }