16 |
|
|
17 |
|
#include "color.h" |
18 |
|
|
19 |
– |
|
19 |
|
extern char *malloc(); |
20 |
|
|
21 |
|
#define CHECKRAD 1.5 /* radius to check for filtering */ |
27 |
|
int nrows = 0; /* number of rows for output */ |
28 |
|
int ncols = 0; /* number of columns for output */ |
29 |
|
|
30 |
< |
double xrat = 1.0; /* ratio of input x size to output */ |
31 |
< |
double yrat = 1.0; /* ratio of input y size to output */ |
30 |
> |
double x_c = 1.0; /* ratio of output x size to input */ |
31 |
> |
double y_r = 1.0; /* ratio of output y size to input */ |
32 |
|
|
33 |
|
int singlepass = 0; /* true means skip first pass */ |
34 |
|
|
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 |
|
|
50 |
– |
double x_c, y_r; /* conversion factors */ |
51 |
– |
|
51 |
|
int xrad; /* x window size */ |
52 |
|
int yrad; /* y window size */ |
53 |
|
|
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 |
|
|
89 |
|
if (argv[i][0] == '-') |
90 |
|
switch (argv[i][1]) { |
91 |
|
case 'x': |
92 |
< |
if (argv[i][2] == '/') |
93 |
< |
xrat = atof(argv[++i]); |
94 |
< |
else |
95 |
< |
ncols = atoi(argv[++i]); |
92 |
> |
i++; |
93 |
> |
if (argv[i][0] == '/') { |
94 |
> |
x_c = 1.0/atof(argv[i]+1); |
95 |
> |
ncols = 0; |
96 |
> |
} else |
97 |
> |
ncols = atoi(argv[i]); |
98 |
|
break; |
99 |
|
case 'y': |
100 |
< |
if (argv[i][2] == '/') |
101 |
< |
yrat = atof(argv[++i]); |
102 |
< |
else |
103 |
< |
nrows = atoi(argv[++i]); |
100 |
> |
i++; |
101 |
> |
if (argv[i][0] == '/') { |
102 |
> |
y_r = 1.0/atof(argv[i]+1); |
103 |
> |
nrows = 0; |
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])); |
137 |
|
case '1': |
138 |
|
singlepass = 1; |
139 |
|
break; |
140 |
< |
case 'p': |
140 |
> |
case '2': |
141 |
> |
singlepass = 0; |
142 |
> |
break; |
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 */ |
202 |
< |
if (fscanf(fin, "-Y %d +X %d\n", &yres, &xres) != 2) { |
202 |
> |
if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { |
203 |
|
fprintf(stderr, "%s: bad picture size\n", progname); |
204 |
|
quit(1); |
205 |
|
} |
206 |
< |
if (ncols > 0) |
207 |
< |
xrat = (double)xres/ncols; |
208 |
< |
else |
209 |
< |
ncols = xres/xrat + .5; |
210 |
< |
if (nrows > 0) |
211 |
< |
yrat = (double)yres/nrows; |
212 |
< |
else |
213 |
< |
nrows = yres/yrat + .5; |
206 |
> |
/* compute output resolution */ |
207 |
> |
if (ncols <= 0) |
208 |
> |
ncols = x_c*xres + .5; |
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) { |
202 |
< |
/* 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 |
|
|
313 |
– |
x_c = (double)ncols/xres; |
314 |
– |
y_r = (double)nrows/yres; |
315 |
– |
|
348 |
|
if (rad <= 0.0) { |
349 |
|
xrad = xres/ncols/2 + 1; |
350 |
|
yrad = yres/nrows/2 + 1; |
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 |
< |
printf("-Y %d +X %d\n", nrows, ncols); /* write picture size */ |
384 |
> |
fputresolu(YMAJOR|YDECR, ncols, nrows, stdout); /* resolution */ |
385 |
|
} |
386 |
|
|
387 |
|
|