1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* ra_bn.c - program to convert between RADIANCE and barneyscan picture format. |
6 |
|
* |
8 |
|
*/ |
9 |
|
|
10 |
|
#include <stdio.h> |
11 |
+ |
#include <string.h> |
12 |
+ |
#include <time.h> |
13 |
+ |
#include <math.h> |
14 |
|
|
15 |
+ |
#include "platform.h" |
16 |
|
#include "color.h" |
17 |
+ |
#include "resolu.h" |
18 |
|
|
19 |
< |
extern double atof(), pow(); |
18 |
< |
|
19 |
< |
double gamma = 2.0; /* gamma correction */ |
20 |
< |
|
19 |
> |
double gamcor = 2.0; /* gamma correction */ |
20 |
|
int bradj = 0; /* brightness adjustment */ |
22 |
– |
|
21 |
|
char *progname; |
24 |
– |
|
22 |
|
char errmsg[128]; |
26 |
– |
|
23 |
|
FILE *rafp, *bnfp[3]; |
28 |
– |
|
24 |
|
int xmax, ymax; |
25 |
|
|
26 |
+ |
static void quiterr(char *err); |
27 |
+ |
static int openbarney(char *fname, char *mode); |
28 |
+ |
static int getint(FILE *fp); |
29 |
+ |
static void putint(int val, FILE *fp); |
30 |
+ |
static void ra2bn(void); |
31 |
+ |
static void bn2ra(void); |
32 |
|
|
33 |
< |
main(argc, argv) |
34 |
< |
int argc; |
35 |
< |
char *argv[]; |
33 |
> |
|
34 |
> |
int |
35 |
> |
main( |
36 |
> |
int argc, |
37 |
> |
char *argv[] |
38 |
> |
) |
39 |
|
{ |
40 |
|
int reverse = 0; |
41 |
|
int i; |
42 |
< |
|
42 |
> |
SET_DEFAULT_BINARY(); |
43 |
> |
SET_FILE_BINARY(stdin); |
44 |
> |
SET_FILE_BINARY(stdout); |
45 |
|
progname = argv[0]; |
46 |
|
|
47 |
|
for (i = 1; i < argc; i++) |
48 |
|
if (argv[i][0] == '-') |
49 |
|
switch (argv[i][1]) { |
50 |
|
case 'g': |
51 |
< |
gamma = atof(argv[++i]); |
51 |
> |
gamcor = atof(argv[++i]); |
52 |
|
break; |
53 |
|
case 'r': |
54 |
|
reverse = !reverse; |
64 |
|
else |
65 |
|
break; |
66 |
|
/* set gamma correction */ |
67 |
< |
setcolrgam(gamma); |
67 |
> |
setcolrgam(gamcor); |
68 |
|
|
69 |
|
if (reverse) { |
70 |
|
if (i > argc-1 || i < argc-2) |
81 |
|
quiterr(errmsg); |
82 |
|
} |
83 |
|
/* put header */ |
84 |
+ |
newheader("RADIANCE", stdout); |
85 |
|
printargs(i, argv, rafp); |
86 |
|
fputformat(COLRFMT, rafp); |
87 |
|
putc('\n', rafp); |
88 |
< |
fputresolu(YMAJOR|YDECR, xmax, ymax, rafp); |
88 |
> |
fprtresolu(xmax, ymax, rafp); |
89 |
|
/* convert file */ |
90 |
|
bn2ra(); |
91 |
|
} else { |
100 |
|
} |
101 |
|
/* get header */ |
102 |
|
if (checkheader(rafp, COLRFMT, NULL) < 0 || |
103 |
< |
fgetresolu(&xmax, &ymax, rafp) != (YMAJOR|YDECR)) |
103 |
> |
fgetresolu(&xmax, &ymax, rafp) < 0) |
104 |
|
quiterr("bad RADIANCE format"); |
105 |
|
if (openbarney(argv[i+1], "w") < 0) { |
106 |
|
sprintf(errmsg, "cannot open output \"%s\"", argv[i+1]); |
119 |
|
} |
120 |
|
|
121 |
|
|
122 |
< |
quiterr(err) /* print message and exit */ |
123 |
< |
char *err; |
122 |
> |
static void |
123 |
> |
quiterr( /* print message and exit */ |
124 |
> |
char *err |
125 |
> |
) |
126 |
|
{ |
127 |
|
if (err != NULL) { |
128 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
132 |
|
} |
133 |
|
|
134 |
|
|
135 |
< |
openbarney(fname, mode) /* open barneyscan files */ |
136 |
< |
char *fname; |
137 |
< |
char *mode; |
135 |
> |
static int |
136 |
> |
openbarney( /* open barneyscan files */ |
137 |
> |
char *fname, |
138 |
> |
char *mode |
139 |
> |
) |
140 |
|
{ |
141 |
|
static char suffix[3][4] = {"red", "grn", "blu"}; |
142 |
|
int i; |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
< |
int |
167 |
< |
getint(fp) /* get short int from barneyscan file */ |
168 |
< |
register FILE *fp; |
166 |
> |
static int |
167 |
> |
getint( /* get short int from barneyscan file */ |
168 |
> |
register FILE *fp |
169 |
> |
) |
170 |
|
{ |
171 |
|
register short val; |
172 |
|
|
177 |
|
} |
178 |
|
|
179 |
|
|
180 |
< |
putint(val, fp) /* put short int to barneyscan file */ |
181 |
< |
register int val; |
182 |
< |
register FILE *fp; |
180 |
> |
static void |
181 |
> |
putint( /* put short int to barneyscan file */ |
182 |
> |
register int val, |
183 |
> |
register FILE *fp |
184 |
> |
) |
185 |
|
{ |
186 |
|
putc(val&0xff, fp); |
187 |
|
putc((val >> 8)&0xff, fp); |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
< |
ra2bn() /* convert radiance to barneyscan */ |
191 |
> |
static void |
192 |
> |
ra2bn(void) /* convert radiance to barneyscan */ |
193 |
|
{ |
194 |
|
register int i; |
195 |
|
register COLR *inl; |
211 |
|
if (ferror(bnfp[0]) || ferror(bnfp[1]) || ferror(bnfp[2])) |
212 |
|
quiterr("error writing Barney files"); |
213 |
|
} |
214 |
< |
free((char *)inl); |
214 |
> |
free((void *)inl); |
215 |
|
} |
216 |
|
|
217 |
|
|
218 |
< |
bn2ra() /* convert barneyscan to radiance */ |
218 |
> |
static void |
219 |
> |
bn2ra(void) /* convert barneyscan to radiance */ |
220 |
|
{ |
221 |
|
register int i; |
222 |
|
register COLR *outline; |
238 |
|
if (fwritecolrs(outline, xmax, rafp) < 0) |
239 |
|
quiterr("error writing RADIANCE file"); |
240 |
|
} |
241 |
< |
free((char *)outline); |
241 |
> |
free((void *)outline); |
242 |
|
} |