ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/mt160r.c
Revision: 2.2
Committed: Mon Dec 23 22:35:30 1991 UTC (32 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.1: +2 -2 lines
Log Message:
removed unnecessary static declarations

File Contents

# User Rev Content
1 greg 1.9 /* Copyright (c) 1991 Regents of the University of California */
2 greg 1.1
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 greg 1.9 #include "resolu.h"
17 greg 1.1
18     #define NCOLS 880 /* for wide carriage */
19    
20    
21     main(argc, argv)
22     int argc;
23     char *argv[];
24     {
25     int i;
26     int status = 0;
27    
28     if (argc < 2)
29     status += printp(NULL) == -1;
30     else
31     for (i = 1; i < argc; i++)
32     status += printp(argv[i]) == -1;
33     exit(status);
34     }
35    
36    
37     printp(fname) /* print a picture */
38     char *fname;
39     {
40     FILE *input;
41     int xres, yres;
42 greg 1.3 COLR scanline[NCOLS];
43 greg 1.1 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 greg 1.7 if (checkheader(input, COLRFMT, NULL) < 0) {
54     fprintf(stderr, "%s: not a Radiance picture\n", fname);
55     return(-1);
56     }
57 greg 1.1 /* get picture dimensions */
58 greg 1.9 if (fgetresolu(&xres, &yres, input) < 0) {
59 greg 1.1 fprintf(stderr, "%s: bad picture size\n", fname);
60     return(-1);
61     }
62     if (xres > NCOLS) {
63     fprintf(stderr, "%s: resolution mismatch\n", fname);
64     return(-1);
65     }
66    
67     fputs("\033[6~\033[7z", stdout);
68    
69     for (i = yres-1; i >= 0; i--) {
70 greg 1.3 if (freadcolrs(scanline, xres, input) < 0) {
71 greg 1.1 fprintf(stderr, "%s: read error (y=%d)\n", fname, i);
72     return(-1);
73     }
74 greg 1.6 normcolrs(scanline, xres, 0);
75 greg 1.1 plotscan(scanline, xres, i);
76     }
77    
78     fputs("\f\033[6~", stdout);
79    
80     fclose(input);
81    
82     return(0);
83     }
84    
85    
86     plotscan(scan, len, y) /* plot a scanline */
87 greg 1.3 COLR scan[];
88 greg 1.1 int len;
89     int y;
90     {
91     static BYTE pat[NCOLS];
92     int bpos;
93     register int i;
94    
95     if (bpos = y & 7) {
96    
97     for (i = 0; i < len; i++)
98     pat[i] |= bit(scan[i], i) << bpos;
99    
100     } else {
101    
102     fputs("\033%5", stdout);
103     putchar(len & 255);
104     putchar(len >> 8);
105    
106     for (i = 0; i < len; i++) {
107     pat[i] |= bit(scan[i], i);
108     putchar(pat[i]);
109     pat[i] = 0;
110     }
111     putchar('\r');
112     putchar('\n');
113     }
114     }
115    
116    
117 greg 1.3 bit(clr, x) /* return bit for color at x */
118     COLR clr;
119 greg 1.1 register int x;
120     {
121 greg 1.3 static int cerr[NCOLS];
122 greg 2.2 static int err;
123     int b, errp;
124 greg 1.1 register int isblack;
125    
126 greg 1.4 b = normbright(clr);
127 greg 1.8 errp = err;
128 greg 1.1 err += b + cerr[x];
129 greg 1.3 isblack = err < 128;
130     if (!isblack) err -= 256;
131 greg 1.8 err /= 3;
132     cerr[x] = err + errp;
133 greg 1.1 return(isblack);
134     }