ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/mt160r.c
Revision: 2.4
Committed: Mon Sep 21 12:13:29 1992 UTC (31 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.3: +12 -4 lines
Log Message:
Changes for PC port

File Contents

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