| 1 |
< |
/* Copyright (c) 1992 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1996 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 17 |
|
|
| 18 |
|
#include "color.h" |
| 19 |
|
|
| 20 |
+ |
#include "view.h" |
| 21 |
+ |
|
| 22 |
|
#include "resolu.h" |
| 23 |
|
|
| 24 |
|
#include "paths.h" |
| 55 |
|
|
| 56 |
|
char *tfname = NULL; |
| 57 |
|
|
| 58 |
+ |
char template[] = TEMPLATE; |
| 59 |
+ |
|
| 60 |
|
char *lampdat = "lamp.tab"; /* lamp data file */ |
| 61 |
|
|
| 62 |
|
int order; /* scanline ordering of input */ |
| 66 |
|
|
| 67 |
|
int wrongformat = 0; |
| 68 |
|
|
| 69 |
+ |
VIEW ourview = STDVIEW; |
| 70 |
+ |
int gotview = 0; |
| 71 |
+ |
int wrapfilt = 0; /* wrap filter horizontally? */ |
| 72 |
+ |
|
| 73 |
+ |
int estatus = 0; /* exit status (for non-fatal errors) */ |
| 74 |
+ |
|
| 75 |
|
int xrad; /* x search radius */ |
| 76 |
|
int yrad; /* y search radius */ |
| 77 |
|
int xbrad; /* x box size */ |
| 110 |
|
if (signal(SIGINT, quit) == SIG_IGN) |
| 111 |
|
signal(SIGINT, SIG_IGN); |
| 112 |
|
if (signal(SIGHUP, quit) == SIG_IGN) |
| 113 |
< |
signal(SIGINT, SIG_IGN); |
| 113 |
> |
signal(SIGHUP, SIG_IGN); |
| 114 |
|
signal(SIGTERM, quit); |
| 115 |
|
signal(SIGPIPE, quit); |
| 116 |
|
#ifdef SIGXCPU |
| 155 |
|
fprintf(stderr, |
| 156 |
|
"%s: exposure out of range\n", |
| 157 |
|
argv[0]); |
| 158 |
< |
exit(1); |
| 158 |
> |
quit(1); |
| 159 |
|
} |
| 160 |
|
switch (argv[i][2]) { |
| 161 |
|
case '\0': |
| 227 |
|
fprintf(stderr, "%s: unknown lamp type\n", lamptype); |
| 228 |
|
quit(1); |
| 229 |
|
} |
| 230 |
< |
for (i = 0; i < 3; i++) |
| 231 |
< |
if (lampcolor[i] > 1e-4) |
| 232 |
< |
colval(exposure,i) /= lampcolor[i]; |
| 230 |
> |
for (j = 0; j < 3; j++) |
| 231 |
> |
if (lampcolor[j] > 1e-4) |
| 232 |
> |
colval(exposure,j) /= lampcolor[j]; |
| 233 |
|
freelamps(); |
| 234 |
|
} |
| 235 |
|
/* open input file */ |
| 237 |
|
if (singlepass) |
| 238 |
|
fin = stdin; |
| 239 |
|
else { |
| 240 |
< |
tfname = mktemp(TEMPLATE); |
| 240 |
> |
tfname = mktemp(template); |
| 241 |
|
if ((fin = fopen(tfname, "w+")) == NULL) { |
| 242 |
|
fprintf(stderr, "%s: can't create ", progname); |
| 243 |
|
fprintf(stderr, "temp file \"%s\"\n", tfname); |
| 275 |
|
} |
| 276 |
|
if (!(order & YMAJOR)) |
| 277 |
|
inpaspect = 1.0/inpaspect; |
| 278 |
+ |
/* wrap around for cylindrical view? */ |
| 279 |
+ |
wrapfilt = gotview && ourview.type == VT_CYL && |
| 280 |
+ |
ourview.horiz >= 360.-FTINY && order & YMAJOR; |
| 281 |
|
/* compute output resolution */ |
| 282 |
|
if (ncols <= 0) |
| 283 |
|
ncols = x_c*xres + .5; |
| 309 |
|
} |
| 310 |
|
pass2(fin); |
| 311 |
|
|
| 312 |
< |
quit(0); |
| 312 |
> |
quit(estatus); |
| 313 |
|
} |
| 314 |
|
|
| 315 |
|
|
| 316 |
+ |
double |
| 317 |
+ |
rgb_bright(clr) |
| 318 |
+ |
COLOR clr; |
| 319 |
+ |
{ |
| 320 |
+ |
return(bright(clr)); |
| 321 |
+ |
} |
| 322 |
+ |
|
| 323 |
+ |
|
| 324 |
+ |
double |
| 325 |
+ |
xyz_bright(clr) |
| 326 |
+ |
COLOR clr; |
| 327 |
+ |
{ |
| 328 |
+ |
return(clr[CIEY]); |
| 329 |
+ |
} |
| 330 |
+ |
|
| 331 |
+ |
|
| 332 |
+ |
double (*ourbright)() = rgb_bright; |
| 333 |
+ |
|
| 334 |
+ |
|
| 335 |
|
headline(s) /* process line from header */ |
| 336 |
|
char *s; |
| 337 |
|
{ |
| 340 |
|
fputs(s, stdout); /* copy to output */ |
| 341 |
|
if (isaspect(s)) /* get aspect ratio */ |
| 342 |
|
inpaspect *= aspectval(s); |
| 343 |
< |
else if (isexpos(s)) |
| 343 |
> |
else if (isexpos(s)) /* get exposure */ |
| 344 |
|
hotlvl *= exposval(s); |
| 345 |
< |
else if (isformat(s)) { |
| 346 |
< |
formatval(fmt, s); |
| 347 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
| 348 |
< |
} |
| 345 |
> |
else if (formatval(fmt, s)) { /* get format */ |
| 346 |
> |
wrongformat = 0; |
| 347 |
> |
if (!strcmp(COLRFMT, fmt)) |
| 348 |
> |
ourbright = rgb_bright; |
| 349 |
> |
else if (!strcmp(CIEFMT, fmt)) |
| 350 |
> |
ourbright = xyz_bright; |
| 351 |
> |
else |
| 352 |
> |
wrongformat = !globmatch(PICFMT, fmt); |
| 353 |
> |
} else if (isview(s) && sscanview(&ourview, s) > 0) |
| 354 |
> |
gotview++; |
| 355 |
|
} |
| 356 |
|
|
| 357 |
|
|
| 394 |
|
progname, (int)(100L*i/yres)); |
| 395 |
|
yres = i; |
| 396 |
|
y_r = (double)nrows/yres; |
| 397 |
+ |
estatus++; |
| 398 |
|
break; |
| 399 |
|
} |
| 400 |
|
pass1scan(scan, i); |
| 414 |
|
scan2init(); |
| 415 |
|
yread = 0; |
| 416 |
|
for (r = 0; r < nrows; r++) { |
| 417 |
< |
ycent = (long)r*yres/nrows; |
| 417 |
> |
ycent = (r+.5)*yres/nrows; |
| 418 |
|
while (yread <= ycent+yrad) { |
| 419 |
|
if (yread < yres) { |
| 420 |
|
if (freadscan(scanin[yread%barsize], |
| 421 |
|
xres, in) < 0) { |
| 422 |
|
fprintf(stderr, |
| 423 |
< |
"%s: bad read (y=%d)\n", |
| 423 |
> |
"%s: truncated input (y=%d)\n", |
| 424 |
|
progname, yres-1-yread); |
| 425 |
|
quit(1); |
| 426 |
|
} |
| 431 |
|
if (obarsize > 0) |
| 432 |
|
scan2sync(r); |
| 433 |
|
for (c = 0; c < ncols; c++) { |
| 434 |
< |
xcent = (long)c*xres/ncols; |
| 434 |
> |
xcent = (c+.5)*xres/ncols; |
| 435 |
|
if (thresh > FTINY) |
| 436 |
|
dothresh(xcent, ycent, c, r); |
| 437 |
|
else if (rad > FTINY) |
| 467 |
|
rad *= (y_r + x_c)/2.0; |
| 468 |
|
|
| 469 |
|
if (thresh > FTINY) { |
| 431 |
– |
xrad = CHECKRAD*THRESHRAD*rad/x_c + xbrad; |
| 432 |
– |
yrad = CHECKRAD*THRESHRAD*rad/y_r + ybrad; |
| 470 |
|
orad = CHECKRAD*THRESHRAD*rad + 1; |
| 471 |
+ |
xrad = orad/x_c + xbrad; |
| 472 |
+ |
yrad = orad/y_r + ybrad; |
| 473 |
|
obarsize = 2*orad + 1; |
| 474 |
|
} else { |
| 475 |
|
xrad = CHECKRAD*rad/x_c + 1; |
| 482 |
|
} |
| 483 |
|
barsize = 2*yrad + 1; |
| 484 |
|
scanin = (COLOR **)malloc(barsize*sizeof(COLOR *)); |
| 485 |
+ |
if (scanin == NULL) |
| 486 |
+ |
goto memerr; |
| 487 |
|
for (i = 0; i < barsize; i++) { |
| 488 |
|
scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR)); |
| 489 |
< |
if (scanin[i] == NULL) { |
| 490 |
< |
fprintf(stderr, "%s: out of memory\n", progname); |
| 450 |
< |
quit(1); |
| 451 |
< |
} |
| 489 |
> |
if (scanin[i] == NULL) |
| 490 |
> |
goto memerr; |
| 491 |
|
} |
| 492 |
|
if (obarsize > 0) { |
| 493 |
|
scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *)); |
| 494 |
|
greybar = (float **)malloc(obarsize*sizeof(float *)); |
| 495 |
+ |
if (scoutbar == NULL | greybar == NULL) |
| 496 |
+ |
goto memerr; |
| 497 |
|
for (i = 0; i < obarsize; i++) { |
| 498 |
|
scoutbar[i] = (COLOR *)malloc(ncols*sizeof(COLOR)); |
| 499 |
|
greybar[i] = (float *)malloc(ncols*sizeof(float)); |
| 500 |
< |
if (scoutbar[i] == NULL | greybar[i] == NULL) { |
| 501 |
< |
fprintf(stderr, "%s: out of memory\n", |
| 461 |
< |
progname); |
| 462 |
< |
quit(1); |
| 463 |
< |
} |
| 500 |
> |
if (scoutbar[i] == NULL | greybar[i] == NULL) |
| 501 |
> |
goto memerr; |
| 502 |
|
} |
| 503 |
|
} else { |
| 504 |
|
scanout = (COLOR *)malloc(ncols*sizeof(COLOR)); |
| 505 |
< |
if (scanout == NULL) { |
| 506 |
< |
fprintf(stderr, "%s: out of memory\n", progname); |
| 469 |
< |
quit(1); |
| 470 |
< |
} |
| 505 |
> |
if (scanout == NULL) |
| 506 |
> |
goto memerr; |
| 507 |
|
} |
| 508 |
|
/* record pixel aspect ratio */ |
| 509 |
|
if (!correctaspect) { |
| 512 |
|
fputaspect(d, stdout); |
| 513 |
|
} |
| 514 |
|
/* record exposure */ |
| 515 |
< |
d = bright(exposure); |
| 515 |
> |
d = (*ourbright)(exposure); |
| 516 |
|
if (!FEQ(d,1.0)) |
| 517 |
|
fputexpos(d, stdout); |
| 518 |
|
/* record color correction */ |
| 524 |
|
printf("\n"); |
| 525 |
|
/* write out resolution */ |
| 526 |
|
fputresolu(order, ncols, nrows, stdout); |
| 527 |
+ |
return; |
| 528 |
+ |
memerr: |
| 529 |
+ |
fprintf(stderr, "%s: out of memory\n", progname); |
| 530 |
+ |
quit(1); |
| 531 |
|
} |
| 532 |
|
|
| 533 |
|
|
| 539 |
|
int ybot; |
| 540 |
|
register int c; |
| 541 |
|
/* average input scanlines */ |
| 542 |
< |
while (nextrow < r+orad && nextrow < nrows) { |
| 543 |
< |
ybot = (long)nextrow*yres/nrows; |
| 542 |
> |
while (nextrow <= r+orad && nextrow < nrows) { |
| 543 |
> |
ybot = (nextrow+.5)*yres/nrows; |
| 544 |
|
for (c = 0; c < ncols; c++) { |
| 545 |
< |
dobox(ctmp, (int)((long)c*xres/ncols),ybot, c,nextrow); |
| 546 |
< |
greybar[nextrow%obarsize][c] = bright(ctmp); |
| 545 |
> |
dobox(ctmp, (int)((c+.5)*xres/ncols),ybot, c,nextrow); |
| 546 |
> |
greybar[nextrow%obarsize][c] = (*ourbright)(ctmp); |
| 547 |
|
} |
| 548 |
|
/* and zero output scanline */ |
| 549 |
|
bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR)); |
| 566 |
|
break; |
| 567 |
|
if (fflush(stdout) < 0) { |
| 568 |
|
fprintf(stderr, "%s: write error at end of pass2\n", progname); |
| 569 |
< |
exit(1); |
| 569 |
> |
quit(1); |
| 570 |
|
} |
| 571 |
|
} |
| 572 |
|
|