ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_hexbit.c
Revision: 3.6
Committed: Sat Dec 28 18:05:14 2019 UTC (4 years, 4 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, rad5R3, HEAD
Changes since 3.5: +1 -4 lines
Log Message:
Removed redundant include files

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: ra_hexbit.c,v 3.5 2018/04/17 17:42:28 greg Exp $";
3 #endif
4 /*
5 * Create a 4x1 hex bitmap from a Radiance picture.
6 */
7
8 #include "platform.h"
9 #include "color.h"
10 #include "rtio.h"
11 #include "resolu.h"
12
13 char *progname;
14 int xmax, ymax;
15 double thresh = 0.5; /* threshold value */
16 COLR threshclr;
17
18 #define abovethresh(c) ((c)[EXP]>threshclr[EXP] || \
19 ((c)[EXP]==threshclr[EXP] && (c)[GRN]>threshclr[GRN]))
20
21 static void quiterr(char *err);
22 static void ra2hex(void);
23
24
25 int
26 main(
27 int argc,
28 char *argv[]
29 )
30 {
31 int i;
32
33 progname = argv[0];
34
35 for (i = 1; i < argc; i++)
36 if (argv[i][0] == '-')
37 switch (argv[i][1]) {
38 case 't': /* threshold value */
39 thresh = atof(argv[++i]);
40 break;
41 default:
42 goto userr;
43 }
44 else
45 break;
46
47 if (i < argc-2)
48 goto userr;
49 if (i <= argc-1 && freopen(argv[i], "r", stdin) == NULL) {
50 fprintf(stderr, "%s: can't open input \"%s\"\n",
51 progname, argv[i]);
52 exit(1);
53 }
54 if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) {
55 fprintf(stderr, "%s: can't open output \"%s\"\n",
56 progname, argv[i+1]);
57 exit(1);
58 }
59 /* assign threshold color */
60 setcolr(threshclr, thresh, thresh, thresh);
61 /* binary input */
62 SET_FILE_BINARY(stdin);
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 static void
78 quiterr( /* print message and exit */
79 char *err
80 )
81 {
82 if (err != NULL) {
83 fprintf(stderr, "%s: %s\n", progname, err);
84 exit(1);
85 }
86 exit(0);
87 }
88
89
90 static void
91 ra2hex(void) /* convert Radiance scanlines to 4x1 bit hex */
92 {
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 free((void *)scanin);
122 }