ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_hexbit.c
Revision: 3.4
Committed: Tue Mar 20 18:45:04 2018 UTC (6 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 3.3: +2 -1 lines
Log Message:
Added missing rtio.h include to redefine getc, putc, etc.

File Contents

# User Rev Content
1 gwlarson 3.1 #ifndef lint
2 greg 3.4 static const char RCSid[] = "$Id: ra_hexbit.c,v 3.3 2004/03/28 20:33:14 schorsch Exp $";
3 gwlarson 3.1 #endif
4     /*
5     * Create a 4x1 hex bitmap from a Radiance picture.
6     */
7    
8     #include <stdio.h>
9 greg 3.2 #include <time.h>
10 schorsch 3.3
11 gwlarson 3.1 #include "color.h"
12 greg 3.4 #include "rtio.h"
13 gwlarson 3.1 #include "resolu.h"
14    
15     char *progname;
16     int xmax, ymax;
17     double thresh = 0.5; /* threshold value */
18     COLR threshclr;
19    
20     #define abovethresh(c) ((c)[EXP]>threshclr[EXP] || \
21     ((c)[EXP]==threshclr[EXP] && (c)[GRN]>threshclr[GRN]))
22    
23 schorsch 3.3 static void quiterr(char *err);
24     static void ra2hex(void);
25    
26 gwlarson 3.1
27 schorsch 3.3 int
28     main(
29     int argc,
30     char *argv[]
31     )
32 gwlarson 3.1 {
33     int i;
34    
35     progname = argv[0];
36    
37     for (i = 1; i < argc; i++)
38     if (argv[i][0] == '-')
39     switch (argv[i][1]) {
40     case 't': /* threshold value */
41     thresh = atof(argv[++i]);
42     break;
43     default:
44     goto userr;
45     }
46     else
47     break;
48    
49     if (i < argc-2)
50     goto userr;
51     if (i <= argc-1 && freopen(argv[i], "r", stdin) == NULL) {
52     fprintf(stderr, "%s: can't open input \"%s\"\n",
53     progname, argv[i]);
54     exit(1);
55     }
56     if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) {
57     fprintf(stderr, "%s: can't open output \"%s\"\n",
58     progname, argv[i+1]);
59     exit(1);
60     }
61     /* assign threshold color */
62     setcolr(threshclr, thresh, thresh, thresh);
63     /* get our header */
64     if (checkheader(stdin, COLRFMT, NULL) < 0 ||
65     fgetresolu(&xmax, &ymax, stdin) < 0)
66     quiterr("bad picture format");
67     /* convert file */
68     ra2hex();
69     exit(0);
70     userr:
71     fprintf(stderr,
72     "Usage: %s [-t thresh] [input [output]]\n", progname);
73     exit(1);
74     }
75    
76    
77 schorsch 3.3 static void
78     quiterr( /* print message and exit */
79     char *err
80     )
81 gwlarson 3.1 {
82     if (err != NULL) {
83     fprintf(stderr, "%s: %s\n", progname, err);
84     exit(1);
85     }
86     exit(0);
87     }
88    
89    
90 schorsch 3.3 static void
91     ra2hex(void) /* convert Radiance scanlines to 4x1 bit hex */
92 gwlarson 3.1 {
93     static char cmap[] = "0123456789ABCDEF";
94     COLR *scanin;
95     register int x, c, t;
96     int y;
97     /* allocate scanline */
98     scanin = (COLR *)malloc(xmax*sizeof(COLR));
99     if (scanin == NULL)
100     quiterr("out of memory in ra2skel");
101     /* convert image */
102     for (y = ymax-1; y >= 0; y--) {
103     if (freadcolrs(scanin, xmax, stdin) < 0)
104     quiterr("error reading Radiance picture");
105     c = 0;
106     for (x = 0; x < xmax; x++)
107     if ((t = 03 - (x&03)))
108     c |= abovethresh(scanin[x]) << t;
109     else {
110     c |= abovethresh(scanin[x]);
111     putchar(cmap[c]);
112     c = 0;
113     }
114     if (t)
115     fputc(cmap[c], stdout);
116     fputc('\n', stdout);
117     if (ferror(stdout))
118     quiterr("error writing hex bit file");
119     }
120     /* free scanline */
121 greg 3.2 free((void *)scanin);
122 gwlarson 3.1 }