ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/mt160r.c
Revision: 1.6
Committed: Fri Jan 26 08:17:31 1990 UTC (34 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.5: +1 -1 lines
Log Message:
added scale factor to normcolrs()

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