16 |
|
|
17 |
|
#include "color.h" |
18 |
|
|
19 |
– |
|
19 |
|
extern char *malloc(); |
20 |
|
|
21 |
|
#define CHECKRAD 1.5 /* radius to check for filtering */ |
45 |
|
char *tfname = NULL; |
46 |
|
|
47 |
|
int xres, yres; /* resolution of input */ |
48 |
+ |
double inpaspect = 1.0; /* pixel aspect ratio of input */ |
49 |
+ |
int correctaspect = 0; /* aspect ratio correction? */ |
50 |
|
|
51 |
|
int xrad; /* x window size */ |
52 |
|
int yrad; /* y window size */ |
65 |
|
extern char *mktemp(); |
66 |
|
extern double atof(), pow(); |
67 |
|
extern long ftell(); |
68 |
< |
extern int quit(); |
68 |
> |
extern int quit(), headline(); |
69 |
|
FILE *fin; |
70 |
|
long fpos; |
71 |
+ |
double outaspect = 0.0; |
72 |
|
double d; |
73 |
|
int i; |
74 |
|
|
104 |
|
} else |
105 |
|
nrows = atoi(argv[i]); |
106 |
|
break; |
107 |
+ |
case 'c': |
108 |
+ |
correctaspect = !correctaspect; |
109 |
+ |
break; |
110 |
+ |
case 'p': |
111 |
+ |
i++; |
112 |
+ |
outaspect = atof(argv[i]); |
113 |
+ |
break; |
114 |
|
case 'e': |
115 |
|
if (argv[i+1][0] == '+' || argv[i+1][0] == '-') |
116 |
|
d = pow(2.0, atof(argv[i+1])); |
140 |
|
case '2': |
141 |
|
singlepass = 0; |
142 |
|
break; |
143 |
< |
case 'p': |
143 |
> |
case 'n': |
144 |
|
npts = atoi(argv[++i]) / 2; |
145 |
|
break; |
146 |
|
case 's': |
194 |
|
fprintf(stderr, "%s: bad # file arguments\n", progname); |
195 |
|
quit(1); |
196 |
|
} |
197 |
< |
/* copy header */ |
198 |
< |
copyheader(fin, stdout); |
197 |
> |
/* get header */ |
198 |
> |
getheader(fin, headline); |
199 |
|
/* add new header info. */ |
200 |
|
printargs(i, argv, stdout); |
201 |
|
/* get picture size */ |
203 |
|
fprintf(stderr, "%s: bad picture size\n", progname); |
204 |
|
quit(1); |
205 |
|
} |
206 |
< |
if (ncols > 0) |
207 |
< |
x_c = (double)ncols/xres; |
199 |
< |
else |
206 |
> |
/* compute output resolution */ |
207 |
> |
if (ncols <= 0) |
208 |
|
ncols = x_c*xres + .5; |
209 |
< |
if (nrows > 0) |
202 |
< |
y_r = (double)nrows/yres; |
203 |
< |
else |
209 |
> |
if (nrows <= 0) |
210 |
|
nrows = y_r*yres + .5; |
211 |
+ |
if (outaspect > .01) { |
212 |
+ |
d = inpaspect * yres/xres / outaspect; |
213 |
+ |
if (d * ncols > nrows) |
214 |
+ |
ncols = nrows / d; |
215 |
+ |
else |
216 |
+ |
nrows = ncols * d; |
217 |
+ |
} |
218 |
+ |
x_c = (double)ncols/xres; |
219 |
+ |
y_r = (double)nrows/yres; |
220 |
|
|
221 |
< |
if (singlepass) { |
207 |
< |
/* skip exposure, etc. */ |
221 |
> |
if (singlepass) { /* skip exposure, etc. */ |
222 |
|
pass1default(); |
223 |
|
pass2(fin); |
224 |
|
quit(0); |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
+ |
headline(s) /* process line from header */ |
242 |
+ |
char *s; |
243 |
+ |
{ |
244 |
+ |
fputs(s, stdout); /* copy to output */ |
245 |
+ |
if (isaspect(s)) /* get aspect ratio */ |
246 |
+ |
inpaspect *= aspectval(s); |
247 |
+ |
} |
248 |
+ |
|
249 |
+ |
|
250 |
|
copyfile(in, out) /* copy a file */ |
251 |
|
register FILE *in, *out; |
252 |
|
{ |
285 |
|
fprintf(stderr, "%s: warning - partial frame (%d%%)\n", |
286 |
|
progname, 100*i/yres); |
287 |
|
yres = i; |
288 |
+ |
y_r = (double)nrows/yres; |
289 |
|
break; |
290 |
|
} |
291 |
|
pass1scan(scan, i); |
331 |
|
quit(1); |
332 |
|
} |
333 |
|
} |
334 |
+ |
/* skip leftovers */ |
335 |
+ |
while (yread < yres) { |
336 |
+ |
if (freadscan(scanin[0], xres, in) < 0) |
337 |
+ |
break; |
338 |
+ |
yread++; |
339 |
+ |
} |
340 |
|
} |
341 |
|
|
342 |
|
|
343 |
|
scan2init() /* prepare scanline arrays */ |
344 |
|
{ |
345 |
< |
double e; |
345 |
> |
double d; |
346 |
|
register int i; |
347 |
|
|
348 |
|
if (rad <= 0.0) { |
371 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
372 |
|
quit(1); |
373 |
|
} |
374 |
< |
e = bright(exposure); |
375 |
< |
if (e < 1-1e-7 || e > 1+1e-7) /* record exposure */ |
376 |
< |
printf("EXPOSURE=%e\n", e); |
374 |
> |
/* record pixel aspect and exposure */ |
375 |
> |
if (!correctaspect) { |
376 |
> |
d = x_c / y_r; |
377 |
> |
if (d < .99 || d > 1.01) |
378 |
> |
fputaspect(d, stdout); |
379 |
> |
} |
380 |
> |
d = bright(exposure); |
381 |
> |
if (d < .995 || d > 1.005) |
382 |
> |
fputexpos(d, stdout); |
383 |
|
printf("\n"); |
384 |
|
fputresolu(YMAJOR|YDECR, ncols, nrows, stdout); /* resolution */ |
385 |
|
} |