ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/oki20c.c
Revision: 1.10
Committed: Thu Apr 18 14:35:11 1991 UTC (33 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.9: +4 -1 lines
Log Message:
added format information to headers

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 greg 1.9 #ifdef BSD
28     #define clearlbuf() bzero((char *)lpat, sizeof(lpat))
29     #else
30     #define clearlbuf() (void)memset((char *)lpat, 0, sizeof(lpat))
31     #endif
32 greg 1.1
33 greg 1.9 long lpat[NCOLS][3];
34    
35    
36 greg 1.1 main(argc, argv)
37     int argc;
38     char *argv[];
39     {
40     int i, status = 0;
41    
42     if (argc < 2)
43     status = printp(NULL) == -1;
44     else
45     for (i = 1; i < argc; i++)
46     status += printp(argv[i]) == -1;
47     exit(status);
48     }
49    
50    
51     printp(fname) /* print a picture */
52     char *fname;
53     {
54     FILE *input;
55     int xres, yres;
56 greg 1.6 COLR scanline[NCOLS];
57 greg 1.1 int i;
58    
59     if (fname == NULL) {
60     input = stdin;
61     fname = "<stdin>";
62     } else if ((input = fopen(fname, "r")) == NULL) {
63     fprintf(stderr, "%s: cannot open\n", fname);
64     return(-1);
65     }
66     /* discard header */
67 greg 1.10 if (checkheader(input, COLRFMT, NULL) < 0) {
68     fprintf(stderr, "%s: not a Radiance picture\n", fname);
69     return(-1);
70     }
71 greg 1.1 /* get picture dimensions */
72 greg 1.2 if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) {
73 greg 1.1 fprintf(stderr, "%s: bad picture size\n", fname);
74     return(-1);
75     }
76     if (xres > NCOLS || yres > NROWS) {
77     fprintf(stderr, "%s: resolution mismatch\n", fname);
78     return(-1);
79     }
80 greg 1.3 /* set line spacing (overlap for knitting) */
81 greg 1.5 fputs("\0333\042", stdout);
82 greg 1.9 /* clear line buffer */
83     clearlbuf();
84 greg 1.3 /* put out scanlines */
85 greg 1.1 for (i = yres-1; i >= 0; i--) {
86 greg 1.6 if (freadcolrs(scanline, xres, input) < 0) {
87 greg 1.1 fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
88     return(-1);
89     }
90 greg 1.8 normcolrs(scanline, xres, 0);
91 greg 1.1 plotscan(scanline, xres, i);
92     }
93 greg 1.3 /* advance page */
94 greg 1.1 putchar('\f');
95    
96     fclose(input);
97    
98     return(0);
99 greg 1.6 }
100    
101    
102 greg 1.1 plotscan(scan, len, y) /* plot a scanline */
103 greg 1.6 COLR scan[];
104 greg 1.1 int len;
105     int y;
106     {
107     int bpos;
108     register long c;
109     register int i, j;
110    
111 greg 1.5 if (bpos = y % 23) {
112 greg 1.1
113 greg 1.5 for (j = 0; j < 3; j++)
114     for (i = 0; i < len; i++)
115 greg 1.9 lpat[i][j] |= (long)colbit(scan[i],i,j) << bpos;
116 greg 1.1
117     } else {
118    
119     fputs("\033\031", stdout);
120    
121     for (j = 0; j < 3; j++) {
122     fputs("\033%O", stdout);
123 greg 1.5 putchar(len & 255);
124 greg 1.1 putchar(len >> 8);
125     for (i = 0; i < len; i++) {
126 greg 1.9 c = lpat[i][j] | colbit(scan[i],i,j);
127 greg 1.5 /* repeat this row */
128 greg 1.9 lpat[i][j] = (c & 1) << 23;
129 greg 1.5 putchar(c>>16);
130     putchar(c>>8 & 255);
131     putchar(c & 255);
132 greg 1.1 }
133     putchar('\r');
134     }
135     putchar('\n');
136     }
137     }
138    
139    
140     colbit(col, x, s) /* determine bit value for primary at x */
141 greg 1.6 COLR col;
142 greg 1.1 register int x;
143     int s;
144     {
145 greg 1.6 static int cerr[NCOLS][3];
146     static int err[3];
147     int b;
148 greg 1.1 register int a, ison;
149    
150     a = sub_add(s); /* use additive primary */
151 greg 1.6 b = col[a];
152 greg 1.1 err[a] += b + cerr[x][a];
153 greg 1.6 ison = err[a] < 128;
154     if (!ison) err[a] -= 256;
155     cerr[x][a] = err[a] /= 2;
156 greg 1.1 return(ison);
157     }