ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/mt160r.c
Revision: 2.7
Committed: Thu Jun 5 19:29:34 2003 UTC (20 years, 11 months ago) by schorsch
Content type: text/plain
Branch: MAIN
Changes since 2.6: +5 -10 lines
Log Message:
Macros for setting binary file mode. Replacing MSDOS by _WIN32.

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 schorsch 2.7 static const char RCSid[] = "$Id: mt160r.c,v 2.6 2003/02/22 02:07:27 greg Exp $";
3 greg 1.1 #endif
4     /*
5     * mt160r.c - program to dump pixel file to Mannesman-Tally 160.
6     *
7     * 8/16/85
8     */
9    
10     #include <stdio.h>
11 greg 2.6 #include <time.h>
12 greg 1.1
13 schorsch 2.7 #include "platform.h"
14 greg 1.1 #include "color.h"
15 greg 1.9 #include "resolu.h"
16 greg 1.1
17 greg 2.4 #define NCOLS 880 /* for wide carriage */
18 greg 1.1
19    
20     main(argc, argv)
21     int argc;
22     char *argv[];
23     {
24     int i;
25     int status = 0;
26 schorsch 2.7 SET_DEFAULT_BINARY();
27     SET_FILE_BINARY(stdin);
28     SET_FILE_BINARY(stdout);
29 greg 1.1 if (argc < 2)
30     status += printp(NULL) == -1;
31     else
32     for (i = 1; i < argc; i++)
33     status += printp(argv[i]) == -1;
34     exit(status);
35     }
36    
37    
38     printp(fname) /* print a picture */
39     char *fname;
40     {
41     FILE *input;
42     int xres, yres;
43 greg 1.3 COLR scanline[NCOLS];
44 greg 1.1 int i;
45 greg 2.4
46 greg 1.1 if (fname == NULL) {
47     input = stdin;
48     fname = "<stdin>";
49     } else if ((input = fopen(fname, "r")) == NULL) {
50     fprintf(stderr, "%s: cannot open\n", fname);
51     return(-1);
52     }
53     /* discard header */
54 greg 1.7 if (checkheader(input, COLRFMT, NULL) < 0) {
55     fprintf(stderr, "%s: not a Radiance picture\n", fname);
56     return(-1);
57     }
58 greg 1.1 /* get picture dimensions */
59 greg 1.9 if (fgetresolu(&xres, &yres, input) < 0) {
60 greg 1.1 fprintf(stderr, "%s: bad picture size\n", fname);
61     return(-1);
62     }
63     if (xres > NCOLS) {
64     fprintf(stderr, "%s: resolution mismatch\n", fname);
65     return(-1);
66     }
67    
68     fputs("\033[6~\033[7z", stdout);
69    
70     for (i = yres-1; i >= 0; i--) {
71 greg 1.3 if (freadcolrs(scanline, xres, input) < 0) {
72 greg 1.1 fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
73     return(-1);
74     }
75 greg 1.6 normcolrs(scanline, xres, 0);
76 greg 1.1 plotscan(scanline, xres, i);
77     }
78    
79     fputs("\f\033[6~", stdout);
80    
81     fclose(input);
82    
83     return(0);
84     }
85    
86    
87     plotscan(scan, len, y) /* plot a scanline */
88 greg 1.3 COLR scan[];
89 greg 1.1 int len;
90     int y;
91     {
92     static BYTE pat[NCOLS];
93     int bpos;
94     register int i;
95    
96     if (bpos = y & 7) {
97    
98     for (i = 0; i < len; i++)
99     pat[i] |= bit(scan[i], i) << bpos;
100    
101     } else {
102    
103     fputs("\033%5", stdout);
104     putchar(len & 255);
105     putchar(len >> 8);
106    
107     for (i = 0; i < len; i++) {
108     pat[i] |= bit(scan[i], i);
109     putchar(pat[i]);
110     pat[i] = 0;
111     }
112     putchar('\r');
113     putchar('\n');
114 greg 2.3 fflush(stdout);
115 greg 1.1 }
116     }
117    
118    
119 greg 1.3 bit(clr, x) /* return bit for color at x */
120     COLR clr;
121 greg 1.1 register int x;
122     {
123 greg 1.3 static int cerr[NCOLS];
124 greg 2.2 static int err;
125     int b, errp;
126 greg 1.1 register int isblack;
127    
128 greg 1.4 b = normbright(clr);
129 greg 1.8 errp = err;
130 greg 1.1 err += b + cerr[x];
131 greg 1.3 isblack = err < 128;
132     if (!isblack) err -= 256;
133 greg 1.8 err /= 3;
134     cerr[x] = err + errp;
135 greg 1.1 return(isblack);
136     }