50 |
|
} |
51 |
|
else |
52 |
|
break; |
53 |
+ |
/* set gamma correction */ |
54 |
+ |
setcolrgam(gamma); |
55 |
|
|
56 |
|
if (reverse) { |
57 |
|
if (i > argc-1 || i < argc-2) |
167 |
|
|
168 |
|
ra2bn() /* convert radiance to barneyscan */ |
169 |
|
{ |
170 |
< |
unsigned char gmap[1024]; |
171 |
< |
register int i,k,c; |
170 |
< |
register COLOR *inl; |
170 |
> |
register int i; |
171 |
> |
register COLR *inl; |
172 |
|
int j; |
173 |
|
|
174 |
< |
if ((inl = (COLOR *)malloc(xmax*sizeof(COLOR))) == NULL) |
174 |
> |
if ((inl = (COLR *)malloc(xmax*sizeof(COLR))) == NULL) |
175 |
|
quiterr("out of memory"); |
175 |
– |
for (i = 0; i < 1024; i++) |
176 |
– |
gmap[i] = 256.*pow((i+.5)/1024., 1./gamma); |
176 |
|
for (j = 0; j < ymax; j++) { |
177 |
< |
if (freadscan(inl, xmax, rafp) < 0) |
177 |
> |
if (freadcolrs(inl, xmax, rafp) < 0) |
178 |
|
quiterr("error reading RADIANCE file"); |
179 |
< |
for (i = 0; i < xmax; i++) |
180 |
< |
for (k = 0; k < 3; k++) { |
181 |
< |
c = 1024.*colval(inl[i],k); |
182 |
< |
if (c >= 1024) |
183 |
< |
c = 1023; |
184 |
< |
putc(gmap[c], bnfp[k]); |
185 |
< |
} |
179 |
> |
colrs_gambs(inl, xmax); |
180 |
> |
for (i = 0; i < xmax; i++) { |
181 |
> |
putc(inl[i][RED], bnfp[0]); |
182 |
> |
putc(inl[i][GRN], bnfp[1]); |
183 |
> |
putc(inl[i][BLU], bnfp[2]); |
184 |
> |
} |
185 |
> |
if (ferror(bnfp[0]) || ferror(bnfp[1]) || ferror(bnfp[2])) |
186 |
> |
quiterr("error writing Barney files"); |
187 |
|
} |
188 |
|
free((char *)inl); |
189 |
|
} |
191 |
|
|
192 |
|
bn2ra() /* convert barneyscan to radiance */ |
193 |
|
{ |
194 |
< |
float gmap[256]; |
195 |
< |
register int i,k,c; |
196 |
< |
register COLOR *outline; |
194 |
> |
register int i; |
195 |
> |
register COLR *outline; |
196 |
|
int j; |
197 |
|
|
198 |
< |
if ((outline = (COLOR *)malloc(xmax*sizeof(COLOR))) == NULL) |
198 |
> |
if ((outline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL) |
199 |
|
quiterr("out of memory"); |
201 |
– |
for (i = 0; i < 256; i++) |
202 |
– |
gmap[i] = pow((i+.5)/256., gamma); |
200 |
|
for (j = 0; j < ymax; j++) { |
201 |
< |
for (i = 0; i < xmax; i++) |
202 |
< |
for (k = 0; k < 3; k++) |
203 |
< |
if ((c = getc(bnfp[k])) == EOF) |
204 |
< |
quiterr("error reading barney file"); |
205 |
< |
else |
206 |
< |
colval(outline[i],k) = gmap[c]; |
207 |
< |
if (fwritescan(outline, xmax, rafp) < 0) |
201 |
> |
for (i = 0; i < xmax; i++) { |
202 |
> |
outline[i][RED] = getc(bnfp[0]); |
203 |
> |
outline[i][GRN] = getc(bnfp[1]); |
204 |
> |
outline[i][BLU] = getc(bnfp[2]); |
205 |
> |
} |
206 |
> |
if (feof(bnfp[0]) || feof(bnfp[1]) || feof(bnfp[2])) |
207 |
> |
quiterr("error reading barney file"); |
208 |
> |
gambs_colrs(outline, xmax); |
209 |
> |
if (fwritecolrs(outline, xmax, rafp) < 0) |
210 |
|
quiterr("error writing RADIANCE file"); |
211 |
|
} |
212 |
|
free((char *)outline); |