ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/mt160r.c
Revision: 2.5
Committed: Mon Aug 2 14:39:10 1993 UTC (30 years, 9 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.4: +0 -3 lines
Log Message:
removed questionable line buffer setting

File Contents

# Content
1 /* Copyright (c) 1992 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 #ifdef MSDOS
15 #include <fcntl.h>
16 #endif
17
18 #include "color.h"
19 #include "resolu.h"
20
21 #define NCOLS 880 /* for wide carriage */
22
23
24 main(argc, argv)
25 int argc;
26 char *argv[];
27 {
28 int i;
29 int status = 0;
30 #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 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 COLR scanline[NCOLS];
51 int i;
52
53 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 if (checkheader(input, COLRFMT, NULL) < 0) {
62 fprintf(stderr, "%s: not a Radiance picture\n", fname);
63 return(-1);
64 }
65 /* get picture dimensions */
66 if (fgetresolu(&xres, &yres, input) < 0) {
67 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
77 for (i = yres-1; i >= 0; i--) {
78 if (freadcolrs(scanline, xres, input) < 0) {
79 fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
80 return(-1);
81 }
82 normcolrs(scanline, xres, 0);
83 plotscan(scanline, xres, i);
84 }
85
86 fputs("\f\033[6~", stdout);
87
88 fclose(input);
89
90 return(0);
91 }
92
93
94 plotscan(scan, len, y) /* plot a scanline */
95 COLR scan[];
96 int len;
97 int y;
98 {
99 static BYTE pat[NCOLS];
100 int bpos;
101 register int i;
102
103 if (bpos = y & 7) {
104
105 for (i = 0; i < len; i++)
106 pat[i] |= bit(scan[i], i) << bpos;
107
108 } else {
109
110 fputs("\033%5", stdout);
111 putchar(len & 255);
112 putchar(len >> 8);
113
114 for (i = 0; i < len; i++) {
115 pat[i] |= bit(scan[i], i);
116 putchar(pat[i]);
117 pat[i] = 0;
118 }
119 putchar('\r');
120 putchar('\n');
121 fflush(stdout);
122 }
123 }
124
125
126 bit(clr, x) /* return bit for color at x */
127 COLR clr;
128 register int x;
129 {
130 static int cerr[NCOLS];
131 static int err;
132 int b, errp;
133 register int isblack;
134
135 b = normbright(clr);
136 errp = err;
137 err += b + cerr[x];
138 isblack = err < 128;
139 if (!isblack) err -= 256;
140 err /= 3;
141 cerr[x] = err + errp;
142 return(isblack);
143 }