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 xrad; /* x window size */ |
57 |
|
int yrad; /* y window size */ |
70 |
|
extern char *mktemp(); |
71 |
|
extern double atof(), pow(); |
72 |
|
extern long ftell(); |
73 |
< |
extern int quit(); |
73 |
> |
extern int quit(), headline(); |
74 |
|
FILE *fin; |
75 |
+ |
float *lampcolor; |
76 |
+ |
char *lamptype = NULL; |
77 |
|
long fpos; |
78 |
+ |
double outaspect = 0.0; |
79 |
|
double d; |
80 |
|
int i; |
81 |
|
|
111 |
|
} else |
112 |
|
nrows = atoi(argv[i]); |
113 |
|
break; |
114 |
+ |
case 'c': |
115 |
+ |
correctaspect = !correctaspect; |
116 |
+ |
break; |
117 |
+ |
case 'p': |
118 |
+ |
i++; |
119 |
+ |
outaspect = atof(argv[i]); |
120 |
+ |
break; |
121 |
|
case 'e': |
122 |
|
if (argv[i+1][0] == '+' || argv[i+1][0] == '-') |
123 |
|
d = pow(2.0, atof(argv[i+1])); |
124 |
|
else |
125 |
|
d = atof(argv[i+1]); |
126 |
+ |
if (d < 1e-20 || d > 1e20) { |
127 |
+ |
fprintf(stderr, |
128 |
+ |
"%s: exposure out of range\n", |
129 |
+ |
argv[0]); |
130 |
+ |
exit(1); |
131 |
+ |
} |
132 |
|
switch (argv[i][2]) { |
133 |
|
case '\0': |
134 |
|
scalecolor(exposure, d); |
147 |
|
} |
148 |
|
i++; |
149 |
|
break; |
150 |
+ |
case 'f': |
151 |
+ |
lampdat = argv[++i]; |
152 |
+ |
break; |
153 |
+ |
case 't': |
154 |
+ |
lamptype = argv[++i]; |
155 |
+ |
break; |
156 |
|
case '1': |
157 |
|
singlepass = 1; |
158 |
|
break; |
159 |
|
case '2': |
160 |
|
singlepass = 0; |
161 |
|
break; |
162 |
< |
case 'p': |
162 |
> |
case 'n': |
163 |
|
npts = atoi(argv[++i]) / 2; |
164 |
|
break; |
165 |
|
case 's': |
186 |
|
} |
187 |
|
else |
188 |
|
break; |
189 |
< |
|
189 |
> |
/* get lamp data (if necessary) */ |
190 |
> |
if (lamptype != NULL) { |
191 |
> |
if (loadlamps(lampdat) < 0) |
192 |
> |
quit(1); |
193 |
> |
if ((lampcolor = matchlamp(lamptype)) == NULL) { |
194 |
> |
fprintf(stderr, "%s: unknown lamp type\n", lamptype); |
195 |
> |
quit(1); |
196 |
> |
} |
197 |
> |
colval(exposure,RED) /= lampcolor[0]; |
198 |
> |
colval(exposure,GRN) /= lampcolor[1]; |
199 |
> |
colval(exposure,BLU) /= lampcolor[2]; |
200 |
> |
freelamps(); |
201 |
> |
} |
202 |
> |
/* open input file */ |
203 |
|
if (i == argc) { |
204 |
|
if (singlepass) |
205 |
|
fin = stdin; |
226 |
|
fprintf(stderr, "%s: bad # file arguments\n", progname); |
227 |
|
quit(1); |
228 |
|
} |
229 |
< |
/* copy header */ |
230 |
< |
copyheader(fin, stdout); |
229 |
> |
/* get header */ |
230 |
> |
getheader(fin, headline); |
231 |
|
/* add new header info. */ |
232 |
|
printargs(i, argv, stdout); |
233 |
|
/* get picture size */ |
235 |
|
fprintf(stderr, "%s: bad picture size\n", progname); |
236 |
|
quit(1); |
237 |
|
} |
238 |
< |
if (ncols > 0) |
239 |
< |
x_c = (double)ncols/xres; |
199 |
< |
else |
238 |
> |
/* compute output resolution */ |
239 |
> |
if (ncols <= 0) |
240 |
|
ncols = x_c*xres + .5; |
241 |
< |
if (nrows > 0) |
202 |
< |
y_r = (double)nrows/yres; |
203 |
< |
else |
241 |
> |
if (nrows <= 0) |
242 |
|
nrows = y_r*yres + .5; |
243 |
+ |
if (outaspect > .01) { |
244 |
+ |
d = inpaspect * yres/xres / outaspect; |
245 |
+ |
if (d * ncols > nrows) |
246 |
+ |
ncols = nrows / d; |
247 |
+ |
else |
248 |
+ |
nrows = ncols * d; |
249 |
+ |
} |
250 |
+ |
x_c = (double)ncols/xres; |
251 |
+ |
y_r = (double)nrows/yres; |
252 |
|
|
253 |
< |
if (singlepass) { |
207 |
< |
/* skip exposure, etc. */ |
253 |
> |
if (singlepass) { /* skip exposure, etc. */ |
254 |
|
pass1default(); |
255 |
|
pass2(fin); |
256 |
|
quit(0); |
270 |
|
} |
271 |
|
|
272 |
|
|
273 |
+ |
headline(s) /* process line from header */ |
274 |
+ |
char *s; |
275 |
+ |
{ |
276 |
+ |
fputs(s, stdout); /* copy to output */ |
277 |
+ |
if (isaspect(s)) /* get aspect ratio */ |
278 |
+ |
inpaspect *= aspectval(s); |
279 |
+ |
} |
280 |
+ |
|
281 |
+ |
|
282 |
|
copyfile(in, out) /* copy a file */ |
283 |
|
register FILE *in, *out; |
284 |
|
{ |
317 |
|
fprintf(stderr, "%s: warning - partial frame (%d%%)\n", |
318 |
|
progname, 100*i/yres); |
319 |
|
yres = i; |
320 |
+ |
y_r = (double)nrows/yres; |
321 |
|
break; |
322 |
|
} |
323 |
|
pass1scan(scan, i); |
363 |
|
quit(1); |
364 |
|
} |
365 |
|
} |
366 |
+ |
/* skip leftovers */ |
367 |
+ |
while (yread < yres) { |
368 |
+ |
if (freadscan(scanin[0], xres, in) < 0) |
369 |
+ |
break; |
370 |
+ |
yread++; |
371 |
+ |
} |
372 |
|
} |
373 |
|
|
374 |
|
|
375 |
|
scan2init() /* prepare scanline arrays */ |
376 |
|
{ |
377 |
< |
double e; |
377 |
> |
COLOR ctmp; |
378 |
> |
double d; |
379 |
|
register int i; |
380 |
|
|
381 |
|
if (rad <= 0.0) { |
404 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
405 |
|
quit(1); |
406 |
|
} |
407 |
< |
e = bright(exposure); |
408 |
< |
if (e < 1-1e-7 || e > 1+1e-7) /* record exposure */ |
409 |
< |
printf("EXPOSURE=%e\n", e); |
407 |
> |
/* record pixel aspect ratio */ |
408 |
> |
if (!correctaspect) { |
409 |
> |
d = x_c / y_r; |
410 |
> |
if (!FEQ(d,1.0)) |
411 |
> |
fputaspect(d, stdout); |
412 |
> |
} |
413 |
> |
/* record exposure */ |
414 |
> |
d = bright(exposure); |
415 |
> |
if (!FEQ(d,1.0)) |
416 |
> |
fputexpos(d, stdout); |
417 |
> |
/* record color correction */ |
418 |
> |
copycolor(ctmp, exposure); |
419 |
> |
scalecolor(ctmp, 1.0/d); |
420 |
> |
if (!FEQ(colval(ctmp,RED),colval(ctmp,GRN)) || |
421 |
> |
!FEQ(colval(ctmp,GRN),colval(ctmp,BLU))) |
422 |
> |
fputcolcor(ctmp, stdout); |
423 |
|
printf("\n"); |
424 |
< |
fputresolu(YMAJOR|YDECR, ncols, nrows, stdout); /* resolution */ |
424 |
> |
/* write out resolution */ |
425 |
> |
fputresolu(YMAJOR|YDECR, ncols, nrows, stdout); |
426 |
|
} |
427 |
|
|
428 |
|
|