| 1 |
– |
/* Copyright (c) 1992 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* pfilt.c - program to post-process picture file. |
| 6 |
|
* |
| 14 |
|
|
| 15 |
|
#include "color.h" |
| 16 |
|
|
| 17 |
< |
#include "resolu.h" |
| 17 |
> |
#include "view.h" |
| 18 |
|
|
| 19 |
|
#include "paths.h" |
| 20 |
|
|
| 61 |
|
|
| 62 |
|
int wrongformat = 0; |
| 63 |
|
|
| 64 |
+ |
VIEW ourview = STDVIEW; |
| 65 |
+ |
int gotview = 0; |
| 66 |
+ |
int wrapfilt = 0; /* wrap filter horizontally? */ |
| 67 |
+ |
|
| 68 |
+ |
int estatus = 0; /* exit status (for non-fatal errors) */ |
| 69 |
+ |
|
| 70 |
|
int xrad; /* x search radius */ |
| 71 |
|
int yrad; /* y search radius */ |
| 72 |
|
int xbrad; /* x box size */ |
| 87 |
|
int argc; |
| 88 |
|
char **argv; |
| 89 |
|
{ |
| 90 |
< |
extern long ftell(); |
| 88 |
< |
extern int quit(), headline(); |
| 90 |
> |
extern int headline(); |
| 91 |
|
FILE *fin; |
| 92 |
|
float *lampcolor; |
| 93 |
|
char *lamptype = NULL; |
| 149 |
|
fprintf(stderr, |
| 150 |
|
"%s: exposure out of range\n", |
| 151 |
|
argv[0]); |
| 152 |
< |
exit(1); |
| 152 |
> |
quit(1); |
| 153 |
|
} |
| 154 |
|
switch (argv[i][2]) { |
| 155 |
|
case '\0': |
| 199 |
|
case 'm': |
| 200 |
|
thresh = atof(argv[++i]); |
| 201 |
|
if (rad <= FTINY) |
| 202 |
< |
rad = 1.0; |
| 202 |
> |
rad = 0.6; |
| 203 |
|
break; |
| 204 |
|
case 'b': |
| 205 |
|
rad = thresh = 0.0; |
| 221 |
|
fprintf(stderr, "%s: unknown lamp type\n", lamptype); |
| 222 |
|
quit(1); |
| 223 |
|
} |
| 224 |
< |
for (i = 0; i < 3; i++) |
| 225 |
< |
if (lampcolor[i] > 1e-4) |
| 226 |
< |
colval(exposure,i) /= lampcolor[i]; |
| 224 |
> |
for (j = 0; j < 3; j++) |
| 225 |
> |
if (lampcolor[j] > 1e-4) |
| 226 |
> |
colval(exposure,j) /= lampcolor[j]; |
| 227 |
|
freelamps(); |
| 228 |
|
} |
| 229 |
|
/* open input file */ |
| 269 |
|
} |
| 270 |
|
if (!(order & YMAJOR)) |
| 271 |
|
inpaspect = 1.0/inpaspect; |
| 272 |
+ |
/* wrap around for cylindrical view? */ |
| 273 |
+ |
wrapfilt = gotview && ourview.type == VT_CYL && |
| 274 |
+ |
ourview.horiz >= 360.-FTINY && order & YMAJOR; |
| 275 |
|
/* compute output resolution */ |
| 276 |
|
if (ncols <= 0) |
| 277 |
|
ncols = x_c*xres + .5; |
| 303 |
|
} |
| 304 |
|
pass2(fin); |
| 305 |
|
|
| 306 |
< |
quit(0); |
| 306 |
> |
quit(estatus); |
| 307 |
|
} |
| 308 |
|
|
| 309 |
|
|
| 310 |
+ |
double |
| 311 |
+ |
rgb_bright(clr) |
| 312 |
+ |
COLOR clr; |
| 313 |
+ |
{ |
| 314 |
+ |
return(bright(clr)); |
| 315 |
+ |
} |
| 316 |
+ |
|
| 317 |
+ |
|
| 318 |
+ |
double |
| 319 |
+ |
xyz_bright(clr) |
| 320 |
+ |
COLOR clr; |
| 321 |
+ |
{ |
| 322 |
+ |
return(clr[CIEY]); |
| 323 |
+ |
} |
| 324 |
+ |
|
| 325 |
+ |
|
| 326 |
+ |
double (*ourbright)() = rgb_bright; |
| 327 |
+ |
|
| 328 |
+ |
|
| 329 |
+ |
int |
| 330 |
|
headline(s) /* process line from header */ |
| 331 |
|
char *s; |
| 332 |
|
{ |
| 335 |
|
fputs(s, stdout); /* copy to output */ |
| 336 |
|
if (isaspect(s)) /* get aspect ratio */ |
| 337 |
|
inpaspect *= aspectval(s); |
| 338 |
< |
else if (isexpos(s)) |
| 338 |
> |
else if (isexpos(s)) /* get exposure */ |
| 339 |
|
hotlvl *= exposval(s); |
| 340 |
< |
else if (isformat(s)) { |
| 341 |
< |
formatval(fmt, s); |
| 342 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
| 343 |
< |
} |
| 340 |
> |
else if (formatval(fmt, s)) { /* get format */ |
| 341 |
> |
wrongformat = 0; |
| 342 |
> |
if (!strcmp(COLRFMT, fmt)) |
| 343 |
> |
ourbright = rgb_bright; |
| 344 |
> |
else if (!strcmp(CIEFMT, fmt)) |
| 345 |
> |
ourbright = xyz_bright; |
| 346 |
> |
else |
| 347 |
> |
wrongformat = !globmatch(PICFMT, fmt); |
| 348 |
> |
} else if (isview(s) && sscanview(&ourview, s) > 0) |
| 349 |
> |
gotview++; |
| 350 |
> |
return(0); |
| 351 |
|
} |
| 352 |
|
|
| 353 |
|
|
| 390 |
|
progname, (int)(100L*i/yres)); |
| 391 |
|
yres = i; |
| 392 |
|
y_r = (double)nrows/yres; |
| 393 |
+ |
estatus++; |
| 394 |
|
break; |
| 395 |
|
} |
| 396 |
|
pass1scan(scan, i); |
| 397 |
|
} |
| 398 |
< |
free((char *)scan); |
| 398 |
> |
free((void *)scan); |
| 399 |
|
} |
| 400 |
|
|
| 401 |
|
|
| 410 |
|
scan2init(); |
| 411 |
|
yread = 0; |
| 412 |
|
for (r = 0; r < nrows; r++) { |
| 413 |
< |
ycent = (long)r*yres/nrows; |
| 413 |
> |
ycent = (r+.5)*yres/nrows; |
| 414 |
|
while (yread <= ycent+yrad) { |
| 415 |
|
if (yread < yres) { |
| 416 |
|
if (freadscan(scanin[yread%barsize], |
| 417 |
|
xres, in) < 0) { |
| 418 |
|
fprintf(stderr, |
| 419 |
< |
"%s: bad read (y=%d)\n", |
| 419 |
> |
"%s: truncated input (y=%d)\n", |
| 420 |
|
progname, yres-1-yread); |
| 421 |
|
quit(1); |
| 422 |
|
} |
| 427 |
|
if (obarsize > 0) |
| 428 |
|
scan2sync(r); |
| 429 |
|
for (c = 0; c < ncols; c++) { |
| 430 |
< |
xcent = (long)c*xres/ncols; |
| 430 |
> |
xcent = (c+.5)*xres/ncols; |
| 431 |
|
if (thresh > FTINY) |
| 432 |
|
dothresh(xcent, ycent, c, r); |
| 433 |
|
else if (rad > FTINY) |
| 463 |
|
rad *= (y_r + x_c)/2.0; |
| 464 |
|
|
| 465 |
|
if (thresh > FTINY) { |
| 433 |
– |
xrad = CHECKRAD*THRESHRAD*rad/x_c + xbrad; |
| 434 |
– |
yrad = CHECKRAD*THRESHRAD*rad/y_r + ybrad; |
| 466 |
|
orad = CHECKRAD*THRESHRAD*rad + 1; |
| 467 |
+ |
xrad = orad/x_c + xbrad; |
| 468 |
+ |
yrad = orad/y_r + ybrad; |
| 469 |
|
obarsize = 2*orad + 1; |
| 470 |
|
} else { |
| 471 |
|
xrad = CHECKRAD*rad/x_c + 1; |
| 508 |
|
fputaspect(d, stdout); |
| 509 |
|
} |
| 510 |
|
/* record exposure */ |
| 511 |
< |
d = bright(exposure); |
| 511 |
> |
d = (*ourbright)(exposure); |
| 512 |
|
if (!FEQ(d,1.0)) |
| 513 |
|
fputexpos(d, stdout); |
| 514 |
|
/* record color correction */ |
| 535 |
|
int ybot; |
| 536 |
|
register int c; |
| 537 |
|
/* average input scanlines */ |
| 538 |
< |
while (nextrow < r+orad && nextrow < nrows) { |
| 539 |
< |
ybot = (long)nextrow*yres/nrows; |
| 538 |
> |
while (nextrow <= r+orad && nextrow < nrows) { |
| 539 |
> |
ybot = (nextrow+.5)*yres/nrows; |
| 540 |
|
for (c = 0; c < ncols; c++) { |
| 541 |
< |
dobox(ctmp, (int)((long)c*xres/ncols),ybot, c,nextrow); |
| 542 |
< |
greybar[nextrow%obarsize][c] = bright(ctmp); |
| 541 |
> |
dobox(ctmp, (int)((c+.5)*xres/ncols),ybot, c,nextrow); |
| 542 |
> |
greybar[nextrow%obarsize][c] = (*ourbright)(ctmp); |
| 543 |
|
} |
| 544 |
|
/* and zero output scanline */ |
| 545 |
|
bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR)); |
| 562 |
|
break; |
| 563 |
|
if (fflush(stdout) < 0) { |
| 564 |
|
fprintf(stderr, "%s: write error at end of pass2\n", progname); |
| 565 |
< |
exit(1); |
| 565 |
> |
quit(1); |
| 566 |
|
} |
| 567 |
|
} |
| 568 |
|
|
| 569 |
|
|
| 570 |
+ |
void |
| 571 |
|
quit(code) /* remove temporary file and exit */ |
| 572 |
|
int code; |
| 573 |
|
{ |