50 |
|
} |
51 |
|
else |
52 |
|
break; |
53 |
+ |
/* set gamma correction */ |
54 |
+ |
setcolrgam(gamma); |
55 |
|
|
56 |
|
if (reverse) { |
57 |
|
if (i > argc-1 || i < argc-2) |
69 |
|
} |
70 |
|
/* put header */ |
71 |
|
printargs(i, argv, rafp); |
72 |
+ |
fputformat(COLRFMT, rafp); |
73 |
|
putc('\n', rafp); |
74 |
|
fputresolu(YMAJOR|YDECR, xmax, ymax, rafp); |
75 |
|
/* convert file */ |
85 |
|
quiterr(errmsg); |
86 |
|
} |
87 |
|
/* get header */ |
88 |
< |
getheader(rafp, NULL); |
89 |
< |
if (fgetresolu(&xmax, &ymax, rafp) != (YMAJOR|YDECR)) |
88 |
> |
if (checkheader(rafp, COLRFMT, NULL) < 0 || |
89 |
> |
fgetresolu(&xmax, &ymax, rafp) != (YMAJOR|YDECR)) |
90 |
|
quiterr("bad RADIANCE format"); |
91 |
|
if (openbarney(argv[i+1], "w") < 0) { |
92 |
|
sprintf(errmsg, "cannot open output \"%s\"", argv[i+1]); |
97 |
|
} |
98 |
|
quiterr(NULL); |
99 |
|
userr: |
100 |
< |
fprintf(stderr, "Usage: %s {input|-} output\n", progname); |
100 |
> |
fprintf(stderr, "Usage: %s [-g gamma] {input|-} output\n", progname); |
101 |
|
fprintf(stderr, " or: %s -r [-g gamma] input [output|-]\n", |
102 |
|
progname); |
103 |
|
exit(1); |
168 |
|
|
169 |
|
ra2bn() /* convert radiance to barneyscan */ |
170 |
|
{ |
171 |
< |
unsigned char gmap[1024]; |
172 |
< |
register int i,k,c; |
170 |
< |
register COLOR *inline; |
171 |
> |
register int i; |
172 |
> |
register COLR *inl; |
173 |
|
int j; |
174 |
|
|
175 |
< |
if ((inline = (COLOR *)malloc(xmax*sizeof(COLOR))) == NULL) |
175 |
> |
if ((inl = (COLR *)malloc(xmax*sizeof(COLR))) == NULL) |
176 |
|
quiterr("out of memory"); |
175 |
– |
for (i = 0; i < 1024; i++) |
176 |
– |
gmap[i] = 256.*pow((i+.5)/1024., 1./gamma); |
177 |
|
for (j = 0; j < ymax; j++) { |
178 |
< |
if (freadscan(inline, xmax, rafp) < 0) |
178 |
> |
if (freadcolrs(inl, xmax, rafp) < 0) |
179 |
|
quiterr("error reading RADIANCE file"); |
180 |
< |
for (i = 0; i < xmax; i++) |
181 |
< |
for (k = 0; k < 3; k++) { |
182 |
< |
c = 1024.*colval(inline[i],k); |
183 |
< |
if (c >= 1024) |
184 |
< |
c = 1023; |
185 |
< |
putc(gmap[c], bnfp[k]); |
186 |
< |
} |
180 |
> |
colrs_gambs(inl, xmax); |
181 |
> |
for (i = 0; i < xmax; i++) { |
182 |
> |
putc(inl[i][RED], bnfp[0]); |
183 |
> |
putc(inl[i][GRN], bnfp[1]); |
184 |
> |
putc(inl[i][BLU], bnfp[2]); |
185 |
> |
} |
186 |
> |
if (ferror(bnfp[0]) || ferror(bnfp[1]) || ferror(bnfp[2])) |
187 |
> |
quiterr("error writing Barney files"); |
188 |
|
} |
189 |
< |
free((char *)inline); |
189 |
> |
free((char *)inl); |
190 |
|
} |
191 |
|
|
192 |
|
|
193 |
|
bn2ra() /* convert barneyscan to radiance */ |
194 |
|
{ |
195 |
< |
float gmap[256]; |
196 |
< |
register int i,k,c; |
196 |
< |
register COLOR *outline; |
195 |
> |
register int i; |
196 |
> |
register COLR *outline; |
197 |
|
int j; |
198 |
|
|
199 |
< |
if ((outline = (COLOR *)malloc(xmax*sizeof(COLOR))) == NULL) |
199 |
> |
if ((outline = (COLR *)malloc(xmax*sizeof(COLR))) == NULL) |
200 |
|
quiterr("out of memory"); |
201 |
– |
for (i = 0; i < 256; i++) |
202 |
– |
gmap[i] = pow((i+.5)/256., gamma); |
201 |
|
for (j = 0; j < ymax; j++) { |
202 |
< |
for (i = 0; i < xmax; i++) |
203 |
< |
for (k = 0; k < 3; k++) |
204 |
< |
if ((c = getc(bnfp[k])) == EOF) |
205 |
< |
quiterr("error reading barney file"); |
206 |
< |
else |
207 |
< |
colval(outline[i],k) = gmap[c]; |
208 |
< |
if (fwritescan(outline, xmax, rafp) < 0) |
202 |
> |
for (i = 0; i < xmax; i++) { |
203 |
> |
outline[i][RED] = getc(bnfp[0]); |
204 |
> |
outline[i][GRN] = getc(bnfp[1]); |
205 |
> |
outline[i][BLU] = getc(bnfp[2]); |
206 |
> |
} |
207 |
> |
if (feof(bnfp[0]) || feof(bnfp[1]) || feof(bnfp[2])) |
208 |
> |
quiterr("error reading barney file"); |
209 |
> |
gambs_colrs(outline, xmax); |
210 |
> |
if (fwritecolrs(outline, xmax, rafp) < 0) |
211 |
|
quiterr("error writing RADIANCE file"); |
212 |
|
} |
213 |
|
free((char *)outline); |