ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/oki20c.c
Revision: 1.2
Committed: Tue Sep 12 13:04:20 1989 UTC (34 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +1 -1 lines
Log Message:
added calls to get/put picture resolution (bug fix)

File Contents

# Content
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 if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) {
62 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
70 fputs("\033A\014\0332", stdout);
71
72 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
80 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 if (bpos = y % 24) {
99
100 for (j = 0; j < 3; j++)
101 for (i = 0; i < len; i++)
102 pat[i][j] |= (long)colbit(scan[i],i,j) << bpos;
103
104 } else {
105
106 fputs("\033\031", stdout);
107
108 for (j = 0; j < 3; j++) {
109 fputs("\033%O", stdout);
110 putchar(len & 255);
111 putchar(len >> 8);
112 for (i = 0; i < len; i++) {
113 c = pat[i][j] | colbit(scan[i],i,j);
114 pat[i][j] = 0;
115 putchar(c>>16);
116 putchar(c>>8 & 255);
117 putchar(c & 255);
118 }
119 putchar('\r');
120 }
121 putchar('\n');
122 }
123 }
124
125
126 colbit(col, x, s) /* determine bit value for primary at x */
127 COLOR col;
128 register int x;
129 int s;
130 {
131 static float cerr[NCOLS][3];
132 static double err[3];
133 double b;
134 register int a, ison;
135
136 a = sub_add(s); /* use additive primary */
137 b = colval(col,a);
138 if (b > 1.0) b = 1.0;
139 err[a] += b + cerr[x][a];
140 ison = err[a] < 0.5;
141 if (!ison) err[a] -= 1.0;
142 cerr[x][a] = err[a] *= 0.5;
143 return(ison);
144 }