ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/mt160r.c
Revision: 2.6
Committed: Sat Feb 22 02:07:27 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 2.5: +2 -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

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 2.6 static const char RCSid[] = "$Id$";
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.4 #ifdef MSDOS
12     #include <fcntl.h>
13     #endif
14 greg 2.6 #include <time.h>
15 greg 1.1
16     #include "color.h"
17 greg 1.9 #include "resolu.h"
18 greg 1.1
19 greg 2.4 #define NCOLS 880 /* for wide carriage */
20 greg 1.1
21    
22     main(argc, argv)
23     int argc;
24     char *argv[];
25     {
26     int i;
27     int status = 0;
28 greg 2.4 #ifdef MSDOS
29     extern int _fmode;
30     _fmode = O_BINARY;
31     setmode(fileno(stdin), O_BINARY);
32     setmode(fileno(stdout), O_BINARY);
33     #endif
34 greg 1.1 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 greg 1.3 COLR scanline[NCOLS];
49 greg 1.1 int i;
50 greg 2.4
51 greg 1.1 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 greg 1.7 if (checkheader(input, COLRFMT, NULL) < 0) {
60     fprintf(stderr, "%s: not a Radiance picture\n", fname);
61     return(-1);
62     }
63 greg 1.1 /* get picture dimensions */
64 greg 1.9 if (fgetresolu(&xres, &yres, input) < 0) {
65 greg 1.1 fprintf(stderr, "%s: bad picture size\n", fname);
66     return(-1);
67     }
68     if (xres > NCOLS) {
69     fprintf(stderr, "%s: resolution mismatch\n", fname);
70     return(-1);
71     }
72    
73     fputs("\033[6~\033[7z", stdout);
74    
75     for (i = yres-1; i >= 0; i--) {
76 greg 1.3 if (freadcolrs(scanline, xres, input) < 0) {
77 greg 1.1 fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
78     return(-1);
79     }
80 greg 1.6 normcolrs(scanline, xres, 0);
81 greg 1.1 plotscan(scanline, xres, i);
82     }
83    
84     fputs("\f\033[6~", stdout);
85    
86     fclose(input);
87    
88     return(0);
89     }
90    
91    
92     plotscan(scan, len, y) /* plot a scanline */
93 greg 1.3 COLR scan[];
94 greg 1.1 int len;
95     int y;
96     {
97     static BYTE pat[NCOLS];
98     int bpos;
99     register int i;
100    
101     if (bpos = y & 7) {
102    
103     for (i = 0; i < len; i++)
104     pat[i] |= bit(scan[i], i) << bpos;
105    
106     } else {
107    
108     fputs("\033%5", stdout);
109     putchar(len & 255);
110     putchar(len >> 8);
111    
112     for (i = 0; i < len; i++) {
113     pat[i] |= bit(scan[i], i);
114     putchar(pat[i]);
115     pat[i] = 0;
116     }
117     putchar('\r');
118     putchar('\n');
119 greg 2.3 fflush(stdout);
120 greg 1.1 }
121     }
122    
123    
124 greg 1.3 bit(clr, x) /* return bit for color at x */
125     COLR clr;
126 greg 1.1 register int x;
127     {
128 greg 1.3 static int cerr[NCOLS];
129 greg 2.2 static int err;
130     int b, errp;
131 greg 1.1 register int isblack;
132    
133 greg 1.4 b = normbright(clr);
134 greg 1.8 errp = err;
135 greg 1.1 err += b + cerr[x];
136 greg 1.3 isblack = err < 128;
137     if (!isblack) err -= 256;
138 greg 1.8 err /= 3;
139     cerr[x] = err + errp;
140 greg 1.1 return(isblack);
141     }