ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ra_hexbit.c
Revision: 3.2
Committed: Sat Feb 22 02:07:27 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 3.1: +3 -7 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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