ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/mt160r.c
Revision: 1.3
Committed: Fri Oct 20 16:44:32 1989 UTC (34 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.2: +14 -13 lines
Log Message:
eliminated unnecessary use of floating point color

File Contents

# Content
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 COLR scanline[NCOLS];
42 char sbuf[256];
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 while (fgets(sbuf, sizeof(sbuf), input) != NULL && sbuf[0] != '\n')
54 ;
55 /* get picture dimensions */
56 if (fgetresolu(&xres, &yres, input) != (YMAJOR|YDECR)) {
57 fprintf(stderr, "%s: bad picture size\n", fname);
58 return(-1);
59 }
60 if (xres > NCOLS) {
61 fprintf(stderr, "%s: resolution mismatch\n", fname);
62 return(-1);
63 }
64
65 fputs("\033[6~\033[7z", stdout);
66
67 for (i = yres-1; i >= 0; i--) {
68 if (freadcolrs(scanline, xres, input) < 0) {
69 fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
70 return(-1);
71 }
72 plotscan(scanline, xres, i);
73 }
74
75 fputs("\f\033[6~", stdout);
76
77 fclose(input);
78
79 return(0);
80 }
81
82
83 plotscan(scan, len, y) /* plot a scanline */
84 COLR scan[];
85 int len;
86 int y;
87 {
88 static BYTE pat[NCOLS];
89 int bpos;
90 register int i;
91
92 if (bpos = y & 7) {
93
94 for (i = 0; i < len; i++)
95 pat[i] |= bit(scan[i], i) << bpos;
96
97 } else {
98
99 fputs("\033%5", stdout);
100 putchar(len & 255);
101 putchar(len >> 8);
102
103 for (i = 0; i < len; i++) {
104 pat[i] |= bit(scan[i], i);
105 putchar(pat[i]);
106 pat[i] = 0;
107 }
108 putchar('\r');
109 putchar('\n');
110 }
111 }
112
113
114 bit(clr, x) /* return bit for color at x */
115 COLR clr;
116 register int x;
117 {
118 static int cerr[NCOLS];
119 static int err;
120 COLR nclr;
121 int b;
122 register int isblack;
123
124 colr_norm(clr, nclr);
125 b = norm_bright(nclr);
126 err += b + cerr[x];
127 isblack = err < 128;
128 if (!isblack) err -= 256;
129 cerr[x] = err /= 2;
130 return(isblack);
131 }