ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/mt160r.c
Revision: 1.4
Committed: Fri Oct 20 20:35:59 1989 UTC (34 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.3: +2 -3 lines
Log Message:
change to color normalization calls

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 normcolrs(scanline, xres);
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 COLR 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(clr, x) /* return bit for color at x */
116 COLR clr;
117 register int x;
118 {
119 static int cerr[NCOLS];
120 static int err;
121 int b;
122 register int isblack;
123
124 b = normbright(clr);
125 err += b + cerr[x];
126 isblack = err < 128;
127 if (!isblack) err -= 256;
128 cerr[x] = err /= 2;
129 return(isblack);
130 }