| 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 |
|
|
| 50 |
– |
double x_c, y_r; /* conversion factors */ |
| 51 |
– |
|
| 50 |
|
int xrad; /* x window size */ |
| 51 |
|
int yrad; /* y window size */ |
| 52 |
|
|
| 64 |
|
extern char *mktemp(); |
| 65 |
|
extern double atof(), pow(); |
| 66 |
|
extern long ftell(); |
| 67 |
< |
extern int quit(); |
| 67 |
> |
extern int quit(), headline(); |
| 68 |
|
FILE *fin; |
| 69 |
|
long fpos; |
| 70 |
+ |
double outaspect = 0.0; |
| 71 |
|
double d; |
| 72 |
|
int i; |
| 73 |
|
|
| 88 |
|
if (argv[i][0] == '-') |
| 89 |
|
switch (argv[i][1]) { |
| 90 |
|
case 'x': |
| 91 |
< |
if (argv[i][2] == '/') |
| 92 |
< |
xrat = atof(argv[++i]); |
| 93 |
< |
else |
| 94 |
< |
ncols = atoi(argv[++i]); |
| 91 |
> |
i++; |
| 92 |
> |
if (argv[i][0] == '/') { |
| 93 |
> |
x_c = 1.0/atof(argv[i]+1); |
| 94 |
> |
ncols = 0; |
| 95 |
> |
} else |
| 96 |
> |
ncols = atoi(argv[i]); |
| 97 |
|
break; |
| 98 |
|
case 'y': |
| 99 |
< |
if (argv[i][2] == '/') |
| 100 |
< |
yrat = atof(argv[++i]); |
| 101 |
< |
else |
| 102 |
< |
nrows = atoi(argv[++i]); |
| 99 |
> |
i++; |
| 100 |
> |
if (argv[i][0] == '/') { |
| 101 |
> |
y_r = 1.0/atof(argv[i]+1); |
| 102 |
> |
nrows = 0; |
| 103 |
> |
} else |
| 104 |
> |
nrows = atoi(argv[i]); |
| 105 |
|
break; |
| 106 |
+ |
case 'p': |
| 107 |
+ |
i++; |
| 108 |
+ |
outaspect = atof(argv[i]); |
| 109 |
+ |
break; |
| 110 |
|
case 'e': |
| 111 |
|
if (argv[i+1][0] == '+' || argv[i+1][0] == '-') |
| 112 |
|
d = pow(2.0, atof(argv[i+1])); |
| 133 |
|
case '1': |
| 134 |
|
singlepass = 1; |
| 135 |
|
break; |
| 136 |
< |
case 'p': |
| 136 |
> |
case '2': |
| 137 |
> |
singlepass = 0; |
| 138 |
> |
break; |
| 139 |
> |
case 'n': |
| 140 |
|
npts = atoi(argv[++i]) / 2; |
| 141 |
|
break; |
| 142 |
|
case 's': |
| 190 |
|
fprintf(stderr, "%s: bad # file arguments\n", progname); |
| 191 |
|
quit(1); |
| 192 |
|
} |
| 193 |
< |
/* copy header */ |
| 194 |
< |
copyheader(fin, stdout); |
| 193 |
> |
/* get header */ |
| 194 |
> |
getheader(fin, headline); |
| 195 |
|
/* add new header info. */ |
| 196 |
|
printargs(i, argv, stdout); |
| 197 |
|
/* get picture size */ |
| 198 |
< |
if (fscanf(fin, "-Y %d +X %d\n", &yres, &xres) != 2) { |
| 198 |
> |
if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { |
| 199 |
|
fprintf(stderr, "%s: bad picture size\n", progname); |
| 200 |
|
quit(1); |
| 201 |
|
} |
| 202 |
< |
if (ncols > 0) |
| 203 |
< |
xrat = (double)xres/ncols; |
| 204 |
< |
else |
| 205 |
< |
ncols = xres/xrat + .5; |
| 206 |
< |
if (nrows > 0) |
| 207 |
< |
yrat = (double)yres/nrows; |
| 208 |
< |
else |
| 209 |
< |
nrows = yres/yrat + .5; |
| 202 |
> |
/* compute output resolution */ |
| 203 |
> |
if (ncols <= 0) |
| 204 |
> |
ncols = x_c*xres + .5; |
| 205 |
> |
if (nrows <= 0) |
| 206 |
> |
nrows = y_r*yres + .5; |
| 207 |
> |
if (outaspect > .01) { |
| 208 |
> |
d = inpaspect * yres/xres / outaspect; |
| 209 |
> |
if (d * ncols > nrows) |
| 210 |
> |
ncols = nrows / d; |
| 211 |
> |
else |
| 212 |
> |
nrows = ncols * d; |
| 213 |
> |
} |
| 214 |
> |
x_c = (double)ncols/xres; |
| 215 |
> |
y_r = (double)nrows/yres; |
| 216 |
|
|
| 217 |
< |
if (singlepass) { |
| 202 |
< |
/* skip exposure, etc. */ |
| 217 |
> |
if (singlepass) { /* skip exposure, etc. */ |
| 218 |
|
pass1default(); |
| 219 |
|
pass2(fin); |
| 220 |
|
quit(0); |
| 234 |
|
} |
| 235 |
|
|
| 236 |
|
|
| 237 |
+ |
headline(s) /* process line from header */ |
| 238 |
+ |
char *s; |
| 239 |
+ |
{ |
| 240 |
+ |
fputs(s, stdout); /* copy to output */ |
| 241 |
+ |
if (isaspect(s)) /* get aspect ratio */ |
| 242 |
+ |
inpaspect *= aspectval(s); |
| 243 |
+ |
} |
| 244 |
+ |
|
| 245 |
+ |
|
| 246 |
|
copyfile(in, out) /* copy a file */ |
| 247 |
|
register FILE *in, *out; |
| 248 |
|
{ |
| 281 |
|
fprintf(stderr, "%s: warning - partial frame (%d%%)\n", |
| 282 |
|
progname, 100*i/yres); |
| 283 |
|
yres = i; |
| 284 |
+ |
y_r = (double)nrows/yres; |
| 285 |
|
break; |
| 286 |
|
} |
| 287 |
|
pass1scan(scan, i); |
| 327 |
|
quit(1); |
| 328 |
|
} |
| 329 |
|
} |
| 330 |
+ |
/* skip leftovers */ |
| 331 |
+ |
while (yread < yres) { |
| 332 |
+ |
if (freadscan(scanin[0], xres, in) < 0) |
| 333 |
+ |
break; |
| 334 |
+ |
yread++; |
| 335 |
+ |
} |
| 336 |
|
} |
| 337 |
|
|
| 338 |
|
|
| 339 |
|
scan2init() /* prepare scanline arrays */ |
| 340 |
|
{ |
| 341 |
< |
double e; |
| 341 |
> |
double d; |
| 342 |
|
register int i; |
| 343 |
|
|
| 313 |
– |
x_c = (double)ncols/xres; |
| 314 |
– |
y_r = (double)nrows/yres; |
| 315 |
– |
|
| 344 |
|
if (rad <= 0.0) { |
| 345 |
|
xrad = xres/ncols/2 + 1; |
| 346 |
|
yrad = yres/nrows/2 + 1; |
| 367 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
| 368 |
|
quit(1); |
| 369 |
|
} |
| 370 |
< |
e = bright(exposure); |
| 371 |
< |
if (e < 1-1e-7 || e > 1+1e-7) /* record exposure */ |
| 372 |
< |
printf("EXPOSURE=%e\n", e); |
| 370 |
> |
/* record pixel aspect and exposure */ |
| 371 |
> |
d = x_c / y_r; |
| 372 |
> |
if (d < .99 || d > 1.01) |
| 373 |
> |
fputaspect(d, stdout); |
| 374 |
> |
d = bright(exposure); |
| 375 |
> |
if (d < .995 || d > 1.005) |
| 376 |
> |
fputexpos(d, stdout); |
| 377 |
|
printf("\n"); |
| 378 |
< |
printf("-Y %d +X %d\n", nrows, ncols); /* write picture size */ |
| 378 |
> |
fputresolu(YMAJOR|YDECR, ncols, nrows, stdout); /* resolution */ |
| 379 |
|
} |
| 380 |
|
|
| 381 |
|
|