ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/mt160r.c
Revision: 1.1
Committed: Thu Feb 2 10:49:20 1989 UTC (35 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

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 COLOR 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 (fgets(sbuf, sizeof(sbuf), input) == NULL ||
57 sscanf(sbuf, "-Y %d +X %d\n", &yres, &xres) != 2) {
58 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 if (freadscan(scanline, xres, input) < 0) {
70 fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
71 return(-1);
72 }
73 plotscan(scanline, xres, i);
74 }
75
76 fputs("\f\033[6~", stdout);
77
78 fclose(input);
79
80 return(0);
81 }
82
83
84 plotscan(scan, len, y) /* plot a scanline */
85 COLOR scan[];
86 int len;
87 int y;
88 {
89 static BYTE pat[NCOLS];
90 int bpos;
91 register int i;
92
93 if (bpos = y & 7) {
94
95 for (i = 0; i < len; i++)
96 pat[i] |= bit(scan[i], i) << bpos;
97
98 } else {
99
100 fputs("\033%5", stdout);
101 putchar(len & 255);
102 putchar(len >> 8);
103
104 for (i = 0; i < len; i++) {
105 pat[i] |= bit(scan[i], i);
106 putchar(pat[i]);
107 pat[i] = 0;
108 }
109 putchar('\r');
110 putchar('\n');
111 }
112 }
113
114
115 bit(col, x) /* return bit for color at x */
116 COLOR col;
117 register int x;
118 {
119 static float cerr[NCOLS];
120 static double err;
121 double b;
122 register int isblack;
123
124 b = bright(col);
125 if (b > 1.0) b = 1.0;
126 err += b + cerr[x];
127 isblack = err < 0.5;
128 if (!isblack) err -= 1.0;
129 cerr[x] = err *= 0.5;
130 return(isblack);
131 }