17 |
|
#include "color.h" |
18 |
|
|
19 |
|
extern char *malloc(); |
20 |
+ |
extern float *matchlamp(); |
21 |
|
|
22 |
+ |
#define FEQ(a,b) ((a) >= .98*(b) && (a) <= 1.02*(b)) |
23 |
+ |
|
24 |
|
#define CHECKRAD 1.5 /* radius to check for filtering */ |
25 |
|
|
26 |
|
COLOR exposure = WHTCOLOR; /* exposure for the frame */ |
47 |
|
|
48 |
|
char *tfname = NULL; |
49 |
|
|
50 |
+ |
char *lampdat = "lamp.tab"; /* lamp data file */ |
51 |
+ |
|
52 |
|
int xres, yres; /* resolution of input */ |
53 |
|
double inpaspect = 1.0; /* pixel aspect ratio of input */ |
54 |
|
int correctaspect = 0; /* aspect ratio correction? */ |
55 |
|
|
56 |
+ |
int wrongformat = 0; |
57 |
+ |
|
58 |
|
int xrad; /* x window size */ |
59 |
|
int yrad; /* y window size */ |
60 |
|
|
74 |
|
extern long ftell(); |
75 |
|
extern int quit(), headline(); |
76 |
|
FILE *fin; |
77 |
+ |
float *lampcolor; |
78 |
+ |
char *lamptype = NULL; |
79 |
|
long fpos; |
80 |
|
double outaspect = 0.0; |
81 |
|
double d; |
125 |
|
d = pow(2.0, atof(argv[i+1])); |
126 |
|
else |
127 |
|
d = atof(argv[i+1]); |
128 |
+ |
if (d < 1e-20 || d > 1e20) { |
129 |
+ |
fprintf(stderr, |
130 |
+ |
"%s: exposure out of range\n", |
131 |
+ |
argv[0]); |
132 |
+ |
exit(1); |
133 |
+ |
} |
134 |
|
switch (argv[i][2]) { |
135 |
|
case '\0': |
136 |
|
scalecolor(exposure, d); |
149 |
|
} |
150 |
|
i++; |
151 |
|
break; |
152 |
+ |
case 'f': |
153 |
+ |
lampdat = argv[++i]; |
154 |
+ |
break; |
155 |
+ |
case 't': |
156 |
+ |
lamptype = argv[++i]; |
157 |
+ |
break; |
158 |
|
case '1': |
159 |
|
singlepass = 1; |
160 |
|
break; |
188 |
|
} |
189 |
|
else |
190 |
|
break; |
191 |
< |
|
191 |
> |
/* get lamp data (if necessary) */ |
192 |
> |
if (lamptype != NULL) { |
193 |
> |
if (loadlamps(lampdat) < 0) |
194 |
> |
quit(1); |
195 |
> |
if ((lampcolor = matchlamp(lamptype)) == NULL) { |
196 |
> |
fprintf(stderr, "%s: unknown lamp type\n", lamptype); |
197 |
> |
quit(1); |
198 |
> |
} |
199 |
> |
colval(exposure,RED) /= lampcolor[0]; |
200 |
> |
colval(exposure,GRN) /= lampcolor[1]; |
201 |
> |
colval(exposure,BLU) /= lampcolor[2]; |
202 |
> |
freelamps(); |
203 |
> |
} |
204 |
> |
/* open input file */ |
205 |
|
if (i == argc) { |
206 |
|
if (singlepass) |
207 |
|
fin = stdin; |
229 |
|
quit(1); |
230 |
|
} |
231 |
|
/* get header */ |
232 |
< |
getheader(fin, headline); |
232 |
> |
getheader(fin, headline, NULL); |
233 |
> |
if (wrongformat) { |
234 |
> |
fprintf(stderr, "%s: input must be a Radiance picture\n", |
235 |
> |
progname); |
236 |
> |
quit(1); |
237 |
> |
} |
238 |
|
/* add new header info. */ |
239 |
|
printargs(i, argv, stdout); |
240 |
|
/* get picture size */ |
280 |
|
headline(s) /* process line from header */ |
281 |
|
char *s; |
282 |
|
{ |
283 |
+ |
char fmt[32]; |
284 |
+ |
|
285 |
|
fputs(s, stdout); /* copy to output */ |
286 |
|
if (isaspect(s)) /* get aspect ratio */ |
287 |
|
inpaspect *= aspectval(s); |
288 |
+ |
else if (isformat(s)) { |
289 |
+ |
formatval(fmt, s); |
290 |
+ |
wrongformat = strcmp(fmt, COLRFMT); |
291 |
+ |
} |
292 |
|
} |
293 |
|
|
294 |
|
|
387 |
|
|
388 |
|
scan2init() /* prepare scanline arrays */ |
389 |
|
{ |
390 |
+ |
COLOR ctmp; |
391 |
|
double d; |
392 |
|
register int i; |
393 |
|
|
403 |
|
|
404 |
|
initmask(); /* initialize filter table */ |
405 |
|
} |
406 |
< |
barsize = 2 * yrad; |
406 |
> |
barsize = 2*yrad + 1; |
407 |
|
scanin = (COLOR **)malloc(barsize*sizeof(COLOR *)); |
408 |
|
for (i = 0; i < barsize; i++) { |
409 |
|
scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR)); |
417 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
418 |
|
quit(1); |
419 |
|
} |
420 |
< |
/* record pixel aspect and exposure */ |
420 |
> |
/* record pixel aspect ratio */ |
421 |
|
if (!correctaspect) { |
422 |
|
d = x_c / y_r; |
423 |
< |
if (d < .99 || d > 1.01) |
423 |
> |
if (!FEQ(d,1.0)) |
424 |
|
fputaspect(d, stdout); |
425 |
|
} |
426 |
+ |
/* record exposure */ |
427 |
|
d = bright(exposure); |
428 |
< |
if (d < .995 || d > 1.005) |
428 |
> |
if (!FEQ(d,1.0)) |
429 |
|
fputexpos(d, stdout); |
430 |
+ |
/* record color correction */ |
431 |
+ |
copycolor(ctmp, exposure); |
432 |
+ |
scalecolor(ctmp, 1.0/d); |
433 |
+ |
if (!FEQ(colval(ctmp,RED),colval(ctmp,GRN)) || |
434 |
+ |
!FEQ(colval(ctmp,GRN),colval(ctmp,BLU))) |
435 |
+ |
fputcolcor(ctmp, stdout); |
436 |
|
printf("\n"); |
437 |
< |
fputresolu(YMAJOR|YDECR, ncols, nrows, stdout); /* resolution */ |
437 |
> |
/* write out resolution */ |
438 |
> |
fputresolu(YMAJOR|YDECR, ncols, nrows, stdout); |
439 |
|
} |
440 |
|
|
441 |
|
|