1 |
< |
/* Copyright (c) 1986 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
14 |
|
|
15 |
|
#include "color.h" |
16 |
|
|
17 |
< |
extern double atof(), pow(); |
17 |
> |
#include "resolu.h" |
18 |
|
|
19 |
+ |
extern double pow(); |
20 |
+ |
|
21 |
|
double gamma = 2.0; /* gamma correction */ |
22 |
|
|
23 |
+ |
int bradj = 0; /* brightness adjustment */ |
24 |
+ |
|
25 |
|
char *progname; |
26 |
|
|
27 |
|
char errmsg[128]; |
49 |
|
case 'r': |
50 |
|
reverse = !reverse; |
51 |
|
break; |
52 |
+ |
case 'e': |
53 |
+ |
if (argv[i+1][0] != '+' && argv[i+1][0] != '-') |
54 |
+ |
goto userr; |
55 |
+ |
bradj = atoi(argv[++i]); |
56 |
+ |
break; |
57 |
|
default: |
58 |
|
goto userr; |
59 |
|
} |
60 |
|
else |
61 |
|
break; |
62 |
+ |
/* set gamma correction */ |
63 |
+ |
setcolrgam(gamma); |
64 |
|
|
65 |
|
if (reverse) { |
66 |
|
if (i > argc-1 || i < argc-2) |
77 |
|
quiterr(errmsg); |
78 |
|
} |
79 |
|
/* put header */ |
80 |
< |
printargs(argc, argv, rafp); |
80 |
> |
printargs(i, argv, rafp); |
81 |
> |
fputformat(COLRFMT, rafp); |
82 |
|
putc('\n', rafp); |
83 |
< |
fprintf(rafp, "-Y %d +X %d\n", ymax, xmax); |
83 |
> |
fprtresolu(xmax, ymax, rafp); |
84 |
|
/* convert file */ |
85 |
|
bn2ra(); |
86 |
|
} else { |
94 |
|
quiterr(errmsg); |
95 |
|
} |
96 |
|
/* get header */ |
97 |
< |
getheader(rafp, NULL); |
98 |
< |
if (fscanf(rafp, "-Y %d +X %d\n", &ymax, &xmax) != 2) |
97 |
> |
if (checkheader(rafp, COLRFMT, NULL) < 0 || |
98 |
> |
fgetresolu(&xmax, &ymax, rafp) < 0) |
99 |
|
quiterr("bad RADIANCE format"); |
100 |
|
if (openbarney(argv[i+1], "w") < 0) { |
101 |
|
sprintf(errmsg, "cannot open output \"%s\"", argv[i+1]); |
106 |
|
} |
107 |
|
quiterr(NULL); |
108 |
|
userr: |
109 |
< |
fprintf(stderr, "Usage: %s {input|-} output\n", progname); |
98 |
< |
fprintf(stderr, " or: %s -r [-g gamma] input [output|-]\n", |
109 |
> |
fprintf(stderr, "Usage: %s [-g gamma][-e +/-stops] {input|-} output\n", |
110 |
|
progname); |
111 |
+ |
fprintf(stderr, " or: %s -r [-g gamma][-e +/-stops] input [output|-]\n", |
112 |
+ |
progname); |
113 |
|
exit(1); |
114 |
|
} |
115 |
|
|
178 |
|
|
179 |
|
ra2bn() /* convert radiance to barneyscan */ |
180 |
|
{ |
181 |
< |
unsigned char gmap[1024]; |
182 |
< |
register int i,k,c; |
170 |
< |
register COLOR *inline; |
181 |
> |
register int i; |
182 |
> |
register COLR *inl; |
183 |
|
int j; |
184 |
|
|
185 |
< |
if ((inline = (COLOR *)malloc(xmax*sizeof(COLOR))) == NULL) |
185 |
> |
if ((inl = (COLR *)malloc(xmax*sizeof(COLR))) == NULL) |
186 |
|
quiterr("out of memory"); |
175 |
– |
for (i = 0; i < 1024; i++) |
176 |
– |
gmap[i] = 256.*pow((i+.5)/1024., 1./gamma); |
187 |
|
for (j = 0; j < ymax; j++) { |
188 |
< |
if (freadscan(inline, xmax, rafp) < 0) |
188 |
> |
if (freadcolrs(inl, xmax, rafp) < 0) |
189 |
|
quiterr("error reading RADIANCE file"); |
190 |
< |
for (i = 0; i < xmax; i++) |
191 |
< |
for (k = 0; k < 3; k++) { |
192 |
< |
c = 1024.*colval(inline[i],k); |
193 |
< |
if (c >= 1024) |
194 |
< |
c = 1023; |
195 |
< |
putc(gmap[c], bnfp[k]); |
196 |
< |
} |
190 |
> |
if (bradj) |
191 |
> |
shiftcolrs(inl, xmax, bradj); |
192 |
> |
colrs_gambs(inl, xmax); |
193 |
> |
for (i = 0; i < xmax; i++) { |
194 |
> |
putc(inl[i][RED], bnfp[0]); |
195 |
> |
putc(inl[i][GRN], bnfp[1]); |
196 |
> |
putc(inl[i][BLU], bnfp[2]); |
197 |
> |
} |
198 |
> |
if (ferror(bnfp[0]) || ferror(bnfp[1]) || ferror(bnfp[2])) |
199 |
> |
quiterr("error writing Barney files"); |
200 |
|
} |
201 |
< |
free((char *)inline); |
201 |
> |
free((char *)inl); |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
|
bn2ra() /* convert barneyscan to radiance */ |
206 |
|
{ |
207 |
< |
float gmap[256]; |
208 |
< |
register int i,k,c; |
196 |
< |
register COLOR *outline; |
207 |
> |
register int i; |
208 |
> |
register COLR *outline; |
209 |
|
int j; |
210 |
|
|
211 |
< |
if ((outline = (COLOR *)malloc(xmax*sizeof(COLOR))) == NULL) |
211 |
> |
if ((outline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL) |
212 |
|
quiterr("out of memory"); |
201 |
– |
for (i = 0; i < 256; i++) |
202 |
– |
gmap[i] = pow((i+.5)/256., gamma); |
213 |
|
for (j = 0; j < ymax; j++) { |
214 |
< |
for (i = 0; i < xmax; i++) |
215 |
< |
for (k = 0; k < 3; k++) |
216 |
< |
if ((c = getc(bnfp[k])) == EOF) |
217 |
< |
quiterr("error reading barney file"); |
218 |
< |
else |
219 |
< |
colval(outline[i],k) = gmap[c]; |
220 |
< |
if (fwritescan(outline, xmax, rafp) < 0) |
214 |
> |
for (i = 0; i < xmax; i++) { |
215 |
> |
outline[i][RED] = getc(bnfp[0]); |
216 |
> |
outline[i][GRN] = getc(bnfp[1]); |
217 |
> |
outline[i][BLU] = getc(bnfp[2]); |
218 |
> |
} |
219 |
> |
if (feof(bnfp[0]) || feof(bnfp[1]) || feof(bnfp[2])) |
220 |
> |
quiterr("error reading barney file"); |
221 |
> |
gambs_colrs(outline, xmax); |
222 |
> |
if (bradj) |
223 |
> |
shiftcolrs(outline, xmax, bradj); |
224 |
> |
if (fwritecolrs(outline, xmax, rafp) < 0) |
225 |
|
quiterr("error writing RADIANCE file"); |
226 |
|
} |
227 |
|
free((char *)outline); |