ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/t4027.c
Revision: 2.2
Committed: Sat Feb 22 02:07:28 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.1: +1 -4 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id$";
3 #endif
4 /*
5 * t4027.c - program to dump pixel file to Tektronix 4027.
6 *
7 * 8/15/85
8 */
9
10 #include <stdio.h>
11
12 #include "color.h"
13
14
15 #define NROWS 462
16 #define NCOLS 640
17
18 #define COM 31 /* command character */
19
20 char *progname;
21
22
23 main(argc, argv)
24 int argc;
25 char **argv;
26 {
27 int xres, yres;
28 COLOR scanline[NCOLS];
29 char sbuf[128];
30 FILE *fp;
31 register int i;
32
33 progname = argv[0];
34
35 if (argc < 2)
36 fp = stdin;
37 else if ((fp = fopen(argv[1], "r")) == NULL) {
38 fprintf(stderr, "%s: can't open file \"%s\"\n",
39 progname, argv[1]);
40 exit(1);
41 }
42 /* discard header */
43 while (fgets(sbuf, sizeof(sbuf), fp) != NULL && sbuf[0] != '\n')
44 ;
45 /* get picture dimensions */
46 if (fgets(sbuf, sizeof(sbuf), fp) == NULL ||
47 sscanf(sbuf, "-Y %d +X %d\n", &yres, &xres) != 2) {
48 fprintf(stderr, "%s: bad picture size\n", progname);
49 exit(1);
50 }
51 if (xres > NCOLS || yres > NROWS) {
52 fprintf(stderr, "%s: resolution mismatch\n", progname);
53 exit(1);
54 }
55
56 printf("%cMON1H", COM);
57 printf("%cGRA1 33", COM);
58
59 for (i = 0; i < yres; i++) {
60 if (freadscan(scanline, xres, fp) < 0) {
61 fprintf(stderr, "%s: read error\n", progname);
62 exit(1);
63 }
64 plotscan(scanline, xres, NROWS-1-i);
65 }
66 fclose(fp);
67
68 if (isatty(fileno(stdout))) {
69 printf("Hit return when done: ");
70 fflush(stdout);
71 fp = fopen("/dev/tty", "r");
72 getc(fp);
73 fclose(fp);
74 printf("%cMON34", COM);
75 }
76 putchar('\r');
77
78 exit(0);
79 }
80
81
82 plotscan(scan, len, y) /* plot a scanline */
83 COLOR scan[];
84 int len;
85 int y;
86 {
87 int color, lastcolor = -1;
88 int lastpos = -1;
89 register int i;
90
91 for (i = 0; i < len; i++) {
92
93 color = colormap(scan[i]);
94 if (color != lastcolor) {
95 if (lastpos >= 0) {
96 setdcolr(lastcolor);
97 vector(lastpos, y, i, y);
98 }
99 lastcolor = color;
100 lastpos = i;
101 }
102 }
103 setdcolr(lastcolor);
104 vector(lastpos, y, len-1, y);
105 }
106
107
108 int
109 colormap(col) /* compute 4027 color value for col */
110 COLOR col;
111 {
112 register int red, grn, blu;
113
114 red = col[RED] >= 1.0 ? 3 : col[RED]*4;
115 grn = col[GRN] >= 1.0 ? 3 : col[GRN]*4;
116 blu = col[BLU] >= 1.0 ? 3 : col[BLU]*4;
117
118 return(red<<4 | grn<<2 | blu);
119 }
120
121
122 vector(x0, y0, x1, y1) /* output a vector */
123 int x0, y0, x1, y1;
124 {
125 printf("%cVEC%d %d %d %d", COM, x0, y0, x1, y1);
126 }
127
128
129 setdcolr(col) /* set dithered pattern for terminal */
130 int col;
131 {
132 static int cmask[3][4] = {
133 { 0, 0x88, 0xca, 0xff },
134 { 0, 0x44, 0xb2, 0xff },
135 { 0, 0x22, 0x2d, 0xff }
136 };
137 static short isset[64];
138 int pat;
139 register int r, g, b;
140
141 if (isset[col]) {
142 printf("%cCOL P%d", COM, col);
143 return;
144 }
145
146 printf("%cPAT P%d C7", COM, col);
147
148 r = cmask[0][col>>4];
149 g = cmask[1][(col>>2) & 03];
150 b = cmask[2][col & 03];
151
152 pat = r & ~(g|b);
153 if (pat) {
154 printf(" C1"); /* red */
155 printpat(pat);
156 }
157 pat = g & ~(r|b);
158 if (pat) {
159 printf(" C2"); /* green */
160 printpat(pat);
161 }
162 pat = b & ~(r|g);
163 if (pat) {
164 printf(" C3"); /* blue */
165 printpat(pat);
166 }
167 pat = r & g & ~b;
168 if (pat) {
169 printf(" C4"); /* yellow */
170 printpat(pat);
171 }
172 pat = r & b & ~g;
173 if (pat) {
174 printf(" C6"); /* magenta */
175 printpat(pat);
176 }
177 pat = g & b & ~r;
178 if (pat) {
179 printf(" C5"); /* cyan */
180 printpat(pat);
181 }
182 pat = r & g & b;
183 if (pat) {
184 printf(" C0"); /* white */
185 printpat(pat);
186 }
187 isset[col] = 1;
188 printf("%cCOL P%d", COM, col);
189 }
190
191
192 printpat(p) /* print out a pattern */
193 register int p;
194 {
195 register int i;
196
197 for (i = 0; i < 14; i++) { /* 14 rows */
198
199 printf(",%d", p);
200 p = rorb(rorb(rorb(p))); /* rotate 3 bits */
201 }
202 }
203
204
205 int
206 rorb(b) /* rotate a byte to the right */
207 register int b;
208 {
209 b |= (b&01) << 8;
210 b >>= 1;
211 return(b);
212 }