ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/mt160r.c
Revision: 2.3
Committed: Wed Jan 29 15:18:34 1992 UTC (32 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.2: +4 -0 lines
Log Message:
removed line buffering of output

File Contents

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