ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/t4027.c
Revision: 2.1
Committed: Tue Nov 12 16:05:19 1991 UTC (32 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +0 -0 lines
Log Message:
updated revision number for release 2.0

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