16 |
|
|
17 |
|
#include "color.h" |
18 |
|
|
19 |
– |
|
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 |
|
|
72 |
|
extern char *mktemp(); |
73 |
|
extern double atof(), pow(); |
74 |
|
extern long ftell(); |
75 |
< |
extern int quit(); |
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; |
82 |
|
int i; |
83 |
|
|
113 |
|
} else |
114 |
|
nrows = atoi(argv[i]); |
115 |
|
break; |
116 |
+ |
case 'c': |
117 |
+ |
correctaspect = !correctaspect; |
118 |
+ |
break; |
119 |
+ |
case 'p': |
120 |
+ |
i++; |
121 |
+ |
outaspect = atof(argv[i]); |
122 |
+ |
break; |
123 |
|
case 'e': |
124 |
|
if (argv[i+1][0] == '+' || argv[i+1][0] == '-') |
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; |
161 |
|
case '2': |
162 |
|
singlepass = 0; |
163 |
|
break; |
164 |
< |
case 'p': |
164 |
> |
case 'n': |
165 |
|
npts = atoi(argv[++i]) / 2; |
166 |
|
break; |
167 |
|
case 's': |
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; |
228 |
|
fprintf(stderr, "%s: bad # file arguments\n", progname); |
229 |
|
quit(1); |
230 |
|
} |
231 |
< |
/* copy header */ |
232 |
< |
copyheader(fin, stdout); |
231 |
> |
/* get header */ |
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 */ |
242 |
|
fprintf(stderr, "%s: bad picture size\n", progname); |
243 |
|
quit(1); |
244 |
|
} |
245 |
< |
if (ncols > 0) |
246 |
< |
x_c = (double)ncols/xres; |
199 |
< |
else |
245 |
> |
/* compute output resolution */ |
246 |
> |
if (ncols <= 0) |
247 |
|
ncols = x_c*xres + .5; |
248 |
< |
if (nrows > 0) |
202 |
< |
y_r = (double)nrows/yres; |
203 |
< |
else |
248 |
> |
if (nrows <= 0) |
249 |
|
nrows = y_r*yres + .5; |
250 |
+ |
if (outaspect > .01) { |
251 |
+ |
d = inpaspect * yres/xres / outaspect; |
252 |
+ |
if (d * ncols > nrows) |
253 |
+ |
ncols = nrows / d; |
254 |
+ |
else |
255 |
+ |
nrows = ncols * d; |
256 |
+ |
} |
257 |
+ |
x_c = (double)ncols/xres; |
258 |
+ |
y_r = (double)nrows/yres; |
259 |
|
|
260 |
< |
if (singlepass) { |
207 |
< |
/* skip exposure, etc. */ |
260 |
> |
if (singlepass) { /* skip exposure, etc. */ |
261 |
|
pass1default(); |
262 |
|
pass2(fin); |
263 |
|
quit(0); |
277 |
|
} |
278 |
|
|
279 |
|
|
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 |
+ |
|
295 |
|
copyfile(in, out) /* copy a file */ |
296 |
|
register FILE *in, *out; |
297 |
|
{ |
330 |
|
fprintf(stderr, "%s: warning - partial frame (%d%%)\n", |
331 |
|
progname, 100*i/yres); |
332 |
|
yres = i; |
333 |
+ |
y_r = (double)nrows/yres; |
334 |
|
break; |
335 |
|
} |
336 |
|
pass1scan(scan, i); |
376 |
|
quit(1); |
377 |
|
} |
378 |
|
} |
379 |
+ |
/* skip leftovers */ |
380 |
+ |
while (yread < yres) { |
381 |
+ |
if (freadscan(scanin[0], xres, in) < 0) |
382 |
+ |
break; |
383 |
+ |
yread++; |
384 |
+ |
} |
385 |
|
} |
386 |
|
|
387 |
|
|
388 |
|
scan2init() /* prepare scanline arrays */ |
389 |
|
{ |
390 |
< |
double e; |
390 |
> |
COLOR ctmp; |
391 |
> |
double d; |
392 |
|
register int i; |
393 |
|
|
394 |
|
if (rad <= 0.0) { |
417 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
418 |
|
quit(1); |
419 |
|
} |
420 |
< |
e = bright(exposure); |
421 |
< |
if (e < 1-1e-7 || e > 1+1e-7) /* record exposure */ |
422 |
< |
printf("EXPOSURE=%e\n", e); |
420 |
> |
/* record pixel aspect ratio */ |
421 |
> |
if (!correctaspect) { |
422 |
> |
d = x_c / y_r; |
423 |
> |
if (!FEQ(d,1.0)) |
424 |
> |
fputaspect(d, stdout); |
425 |
> |
} |
426 |
> |
/* record exposure */ |
427 |
> |
d = bright(exposure); |
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 |
|
|