ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/mt160r.c
Revision: 1.7
Committed: Thu Apr 18 14:35:09 1991 UTC (33 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.6: +4 -1 lines
Log Message:
added format information to headers

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