16 |
|
|
17 |
|
#include "color.h" |
18 |
|
|
19 |
– |
|
19 |
|
extern char *malloc(); |
20 |
+ |
extern float *matchlamp(); |
21 |
|
|
22 |
|
#define CHECKRAD 1.5 /* radius to check for filtering */ |
23 |
|
|
45 |
|
|
46 |
|
char *tfname = NULL; |
47 |
|
|
48 |
+ |
char *lampdat = "lamp.tab"; /* lamp data file */ |
49 |
+ |
|
50 |
|
int xres, yres; /* resolution of input */ |
51 |
+ |
double inpaspect = 1.0; /* pixel aspect ratio of input */ |
52 |
+ |
int correctaspect = 0; /* aspect ratio correction? */ |
53 |
|
|
54 |
|
int xrad; /* x window size */ |
55 |
|
int yrad; /* y window size */ |
68 |
|
extern char *mktemp(); |
69 |
|
extern double atof(), pow(); |
70 |
|
extern long ftell(); |
71 |
< |
extern int quit(); |
71 |
> |
extern int quit(), headline(); |
72 |
|
FILE *fin; |
73 |
+ |
float *lampcolor; |
74 |
+ |
char *lamptype = NULL; |
75 |
|
long fpos; |
76 |
+ |
double outaspect = 0.0; |
77 |
|
double d; |
78 |
|
int i; |
79 |
|
|
109 |
|
} else |
110 |
|
nrows = atoi(argv[i]); |
111 |
|
break; |
112 |
+ |
case 'c': |
113 |
+ |
correctaspect = !correctaspect; |
114 |
+ |
break; |
115 |
+ |
case 'p': |
116 |
+ |
i++; |
117 |
+ |
outaspect = atof(argv[i]); |
118 |
+ |
break; |
119 |
|
case 'e': |
120 |
|
if (argv[i+1][0] == '+' || argv[i+1][0] == '-') |
121 |
|
d = pow(2.0, atof(argv[i+1])); |
139 |
|
} |
140 |
|
i++; |
141 |
|
break; |
142 |
+ |
case 'f': |
143 |
+ |
lampdat = argv[++i]; |
144 |
+ |
break; |
145 |
+ |
case 't': |
146 |
+ |
lamptype = argv[++i]; |
147 |
+ |
break; |
148 |
|
case '1': |
149 |
|
singlepass = 1; |
150 |
|
break; |
151 |
< |
case 'p': |
151 |
> |
case '2': |
152 |
> |
singlepass = 0; |
153 |
> |
break; |
154 |
> |
case 'n': |
155 |
|
npts = atoi(argv[++i]) / 2; |
156 |
|
break; |
157 |
|
case 's': |
178 |
|
} |
179 |
|
else |
180 |
|
break; |
181 |
< |
|
181 |
> |
/* get lamp data (if necessary) */ |
182 |
> |
if (lamptype != NULL) { |
183 |
> |
if (loadlamps(lampdat) < 0) |
184 |
> |
quit(1); |
185 |
> |
if ((lampcolor = matchlamp(lamptype)) == NULL) { |
186 |
> |
fprintf(stderr, "%s: unknown lamp type\n", lamptype); |
187 |
> |
quit(1); |
188 |
> |
} |
189 |
> |
colval(exposure,RED) /= lampcolor[0]; |
190 |
> |
colval(exposure,GRN) /= lampcolor[1]; |
191 |
> |
colval(exposure,BLU) /= lampcolor[2]; |
192 |
> |
freelamps(); |
193 |
> |
} |
194 |
> |
/* open input file */ |
195 |
|
if (i == argc) { |
196 |
|
if (singlepass) |
197 |
|
fin = stdin; |
218 |
|
fprintf(stderr, "%s: bad # file arguments\n", progname); |
219 |
|
quit(1); |
220 |
|
} |
221 |
< |
/* copy header */ |
222 |
< |
copyheader(fin, stdout); |
221 |
> |
/* get header */ |
222 |
> |
getheader(fin, headline); |
223 |
|
/* add new header info. */ |
224 |
|
printargs(i, argv, stdout); |
225 |
|
/* get picture size */ |
226 |
< |
if (fscanf(fin, "-Y %d +X %d\n", &yres, &xres) != 2) { |
226 |
> |
if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { |
227 |
|
fprintf(stderr, "%s: bad picture size\n", progname); |
228 |
|
quit(1); |
229 |
|
} |
230 |
< |
if (ncols > 0) |
231 |
< |
x_c = (double)ncols/xres; |
196 |
< |
else |
230 |
> |
/* compute output resolution */ |
231 |
> |
if (ncols <= 0) |
232 |
|
ncols = x_c*xres + .5; |
233 |
< |
if (nrows > 0) |
199 |
< |
y_r = (double)nrows/yres; |
200 |
< |
else |
233 |
> |
if (nrows <= 0) |
234 |
|
nrows = y_r*yres + .5; |
235 |
+ |
if (outaspect > .01) { |
236 |
+ |
d = inpaspect * yres/xres / outaspect; |
237 |
+ |
if (d * ncols > nrows) |
238 |
+ |
ncols = nrows / d; |
239 |
+ |
else |
240 |
+ |
nrows = ncols * d; |
241 |
+ |
} |
242 |
+ |
x_c = (double)ncols/xres; |
243 |
+ |
y_r = (double)nrows/yres; |
244 |
|
|
245 |
< |
if (singlepass) { |
204 |
< |
/* skip exposure, etc. */ |
245 |
> |
if (singlepass) { /* skip exposure, etc. */ |
246 |
|
pass1default(); |
247 |
|
pass2(fin); |
248 |
|
quit(0); |
262 |
|
} |
263 |
|
|
264 |
|
|
265 |
+ |
headline(s) /* process line from header */ |
266 |
+ |
char *s; |
267 |
+ |
{ |
268 |
+ |
fputs(s, stdout); /* copy to output */ |
269 |
+ |
if (isaspect(s)) /* get aspect ratio */ |
270 |
+ |
inpaspect *= aspectval(s); |
271 |
+ |
} |
272 |
+ |
|
273 |
+ |
|
274 |
|
copyfile(in, out) /* copy a file */ |
275 |
|
register FILE *in, *out; |
276 |
|
{ |
309 |
|
fprintf(stderr, "%s: warning - partial frame (%d%%)\n", |
310 |
|
progname, 100*i/yres); |
311 |
|
yres = i; |
312 |
+ |
y_r = (double)nrows/yres; |
313 |
|
break; |
314 |
|
} |
315 |
|
pass1scan(scan, i); |
355 |
|
quit(1); |
356 |
|
} |
357 |
|
} |
358 |
+ |
/* skip leftovers */ |
359 |
+ |
while (yread < yres) { |
360 |
+ |
if (freadscan(scanin[0], xres, in) < 0) |
361 |
+ |
break; |
362 |
+ |
yread++; |
363 |
+ |
} |
364 |
|
} |
365 |
|
|
366 |
|
|
367 |
|
scan2init() /* prepare scanline arrays */ |
368 |
|
{ |
369 |
< |
double e; |
369 |
> |
double d; |
370 |
|
register int i; |
371 |
|
|
372 |
|
if (rad <= 0.0) { |
395 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
396 |
|
quit(1); |
397 |
|
} |
398 |
< |
e = bright(exposure); |
399 |
< |
if (e < 1-1e-7 || e > 1+1e-7) /* record exposure */ |
400 |
< |
printf("EXPOSURE=%e\n", e); |
398 |
> |
/* record pixel aspect and exposure */ |
399 |
> |
if (!correctaspect) { |
400 |
> |
d = x_c / y_r; |
401 |
> |
if (d < .99 || d > 1.01) |
402 |
> |
fputaspect(d, stdout); |
403 |
> |
} |
404 |
> |
d = bright(exposure); |
405 |
> |
if (d < .995 || d > 1.005) |
406 |
> |
fputexpos(d, stdout); |
407 |
|
printf("\n"); |
408 |
< |
printf("-Y %d +X %d\n", nrows, ncols); /* write picture size */ |
408 |
> |
fputresolu(YMAJOR|YDECR, ncols, nrows, stdout); /* resolution */ |
409 |
|
} |
410 |
|
|
411 |
|
|