| 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 |
|
* |
| 8 |
|
* 6/23/93 Added additional buffers for value spreading |
| 9 |
|
*/ |
| 10 |
|
|
| 11 |
< |
#include "standard.h" |
| 11 |
> |
#include "copyright.h" |
| 12 |
|
|
| 13 |
|
#include <signal.h> |
| 14 |
< |
|
| 15 |
< |
#include "color.h" |
| 19 |
< |
|
| 20 |
< |
#include "resolu.h" |
| 21 |
< |
|
| 14 |
> |
#include "pfilt.h" |
| 15 |
> |
#include "platform.h" |
| 16 |
|
#include "paths.h" |
| 17 |
+ |
#include "view.h" |
| 18 |
|
|
| 24 |
– |
extern float *matchlamp(); |
| 25 |
– |
|
| 19 |
|
#define FEQ(a,b) ((a) >= .98*(b) && (a) <= 1.02*(b)) |
| 20 |
|
|
| 21 |
< |
double CHECKRAD = 1.5; /* radius to check for filtering */ |
| 21 |
> |
double CHECKRAD = 2.0; /* radius to check for filtering */ |
| 22 |
|
|
| 23 |
|
#define THRESHRAD 5.0 /* maximum sample spread in output */ |
| 24 |
|
|
| 46 |
|
|
| 47 |
|
char *tfname = NULL; |
| 48 |
|
|
| 49 |
+ |
char template[] = TEMPLATE; |
| 50 |
+ |
|
| 51 |
|
char *lampdat = "lamp.tab"; /* lamp data file */ |
| 52 |
|
|
| 53 |
|
int order; /* scanline ordering of input */ |
| 57 |
|
|
| 58 |
|
int wrongformat = 0; |
| 59 |
|
|
| 60 |
+ |
VIEW ourview = STDVIEW; |
| 61 |
+ |
int gotview = 0; |
| 62 |
+ |
int wrapfilt = 0; /* wrap filter horizontally? */ |
| 63 |
+ |
|
| 64 |
+ |
int estatus = 0; /* exit status (for non-fatal errors) */ |
| 65 |
+ |
|
| 66 |
|
int xrad; /* x search radius */ |
| 67 |
|
int yrad; /* y search radius */ |
| 68 |
|
int xbrad; /* x box size */ |
| 69 |
|
int ybrad; /* y box size */ |
| 70 |
|
|
| 71 |
|
int barsize; /* size of input scan bar */ |
| 72 |
< |
COLOR **scanin; /* input scan bar */ |
| 73 |
< |
COLOR *scanout; /* output scan line */ |
| 74 |
< |
COLOR **scoutbar; /* output scan bar (if thresh > 0) */ |
| 72 |
> |
COLORV **scanin; /* input scan bar */ |
| 73 |
> |
COLORV *scanout; /* output scan line */ |
| 74 |
> |
COLORV **scoutbar; /* output scan bar (if thresh > 0) */ |
| 75 |
|
float **greybar; /* grey-averaged input values */ |
| 76 |
|
int obarsize = 0; /* size of output scan bar */ |
| 77 |
|
int orad = 0; /* output window radius */ |
| 78 |
|
|
| 79 |
< |
char *progname; |
| 79 |
> |
static void copyfile(FILE *infp, FILE *out); |
| 80 |
> |
static void pass1(FILE *infp); |
| 81 |
> |
static void pass2(FILE *infp); |
| 82 |
> |
static void scan2init(void); |
| 83 |
> |
static void scan2sync(int r); |
| 84 |
> |
static void scan2flush(void); |
| 85 |
|
|
| 86 |
|
|
| 87 |
< |
main(argc, argv) |
| 88 |
< |
int argc; |
| 89 |
< |
char **argv; |
| 87 |
> |
static double |
| 88 |
> |
rgb_bright( |
| 89 |
> |
SCOLOR clr |
| 90 |
> |
) |
| 91 |
|
{ |
| 92 |
< |
extern long ftell(); |
| 93 |
< |
extern int quit(), headline(); |
| 92 |
> |
return(bright(clr)); |
| 93 |
> |
} |
| 94 |
> |
|
| 95 |
> |
|
| 96 |
> |
static double |
| 97 |
> |
xyz_bright( |
| 98 |
> |
SCOLOR clr |
| 99 |
> |
) |
| 100 |
> |
{ |
| 101 |
> |
return(colval(clr,CIEY)); |
| 102 |
> |
} |
| 103 |
> |
|
| 104 |
> |
|
| 105 |
> |
static double |
| 106 |
> |
spec_bright( |
| 107 |
> |
SCOLOR clr |
| 108 |
> |
) |
| 109 |
> |
{ |
| 110 |
> |
return(pbright(clr)); |
| 111 |
> |
} |
| 112 |
> |
|
| 113 |
> |
|
| 114 |
> |
brightfunc_t *ourbright = rgb_bright; |
| 115 |
> |
|
| 116 |
> |
|
| 117 |
> |
static int |
| 118 |
> |
headline( /* process line from header */ |
| 119 |
> |
char *s, |
| 120 |
> |
void *p |
| 121 |
> |
) |
| 122 |
> |
{ |
| 123 |
> |
char fmt[MAXFMTLEN]; |
| 124 |
> |
|
| 125 |
> |
fputs(s, stdout); /* copy to output */ |
| 126 |
> |
if (isaspect(s)) /* get aspect ratio */ |
| 127 |
> |
inpaspect *= aspectval(s); |
| 128 |
> |
else if (isexpos(s)) /* get exposure */ |
| 129 |
> |
hotlvl *= exposval(s); |
| 130 |
> |
else if (isncomp(s)) /* get #components (spectral) */ |
| 131 |
> |
NCSAMP = ncompval(s); |
| 132 |
> |
else if (iswlsplit(s)) /* get wavelength partitions */ |
| 133 |
> |
wlsplitval(WLPART, s); |
| 134 |
> |
else if (formatval(fmt, s)) { /* get format */ |
| 135 |
> |
wrongformat = 0; |
| 136 |
> |
if (!strcmp(COLRFMT, fmt)) |
| 137 |
> |
ourbright = rgb_bright; |
| 138 |
> |
else if (!strcmp(CIEFMT, fmt)) |
| 139 |
> |
ourbright = xyz_bright; |
| 140 |
> |
else if (!strcmp(SPECFMT, fmt)) |
| 141 |
> |
ourbright = spec_bright; |
| 142 |
> |
else |
| 143 |
> |
wrongformat = !globmatch(PICFMT, fmt); |
| 144 |
> |
} else if (isview(s) && sscanview(&ourview, s) > 0) |
| 145 |
> |
gotview++; |
| 146 |
> |
return(0); |
| 147 |
> |
} |
| 148 |
> |
|
| 149 |
> |
|
| 150 |
> |
int |
| 151 |
> |
main( |
| 152 |
> |
int argc, |
| 153 |
> |
char **argv |
| 154 |
> |
) |
| 155 |
> |
{ |
| 156 |
|
FILE *fin; |
| 157 |
|
float *lampcolor; |
| 158 |
|
char *lamptype = NULL; |
| 160 |
|
double outaspect = 0.0; |
| 161 |
|
double d; |
| 162 |
|
int i, j; |
| 163 |
< |
#ifdef MSDOS |
| 164 |
< |
extern int _fmode; |
| 165 |
< |
_fmode = O_BINARY; |
| 166 |
< |
setmode(fileno(stdin), O_BINARY); |
| 167 |
< |
setmode(fileno(stdout), O_BINARY); |
| 99 |
< |
#endif |
| 163 |
> |
|
| 164 |
> |
fixargv0(argv[0]); /* sets global progname */ |
| 165 |
> |
SET_DEFAULT_BINARY(); |
| 166 |
> |
SET_FILE_BINARY(stdin); |
| 167 |
> |
SET_FILE_BINARY(stdout); |
| 168 |
|
if (signal(SIGINT, quit) == SIG_IGN) |
| 169 |
|
signal(SIGINT, SIG_IGN); |
| 170 |
+ |
#ifdef SIGHUP |
| 171 |
|
if (signal(SIGHUP, quit) == SIG_IGN) |
| 172 |
< |
signal(SIGINT, SIG_IGN); |
| 172 |
> |
signal(SIGHUP, SIG_IGN); |
| 173 |
> |
#endif |
| 174 |
|
signal(SIGTERM, quit); |
| 175 |
+ |
#ifdef SIGPIPE |
| 176 |
|
signal(SIGPIPE, quit); |
| 177 |
+ |
#endif |
| 178 |
|
#ifdef SIGXCPU |
| 179 |
|
signal(SIGXCPU, quit); |
| 180 |
|
signal(SIGXFSZ, quit); |
| 181 |
|
#endif |
| 110 |
– |
|
| 111 |
– |
progname = argv[0] = fixargv0(argv[0]); |
| 112 |
– |
|
| 182 |
|
for (i = 1; i < argc; i++) |
| 183 |
|
if (argv[i][0] == '-') |
| 184 |
|
switch (argv[i][1]) { |
| 213 |
|
if (d < 1e-20 || d > 1e20) { |
| 214 |
|
fprintf(stderr, |
| 215 |
|
"%s: exposure out of range\n", |
| 216 |
< |
argv[0]); |
| 217 |
< |
exit(1); |
| 216 |
> |
progname); |
| 217 |
> |
quit(1); |
| 218 |
|
} |
| 219 |
|
switch (argv[i][2]) { |
| 220 |
|
case '\0': |
| 264 |
|
case 'm': |
| 265 |
|
thresh = atof(argv[++i]); |
| 266 |
|
if (rad <= FTINY) |
| 267 |
< |
rad = 1.0; |
| 267 |
> |
rad = 0.6; |
| 268 |
|
break; |
| 269 |
|
case 'b': |
| 270 |
|
rad = thresh = 0.0; |
| 286 |
|
fprintf(stderr, "%s: unknown lamp type\n", lamptype); |
| 287 |
|
quit(1); |
| 288 |
|
} |
| 289 |
< |
for (i = 0; i < 3; i++) |
| 290 |
< |
if (lampcolor[i] > 1e-4) |
| 291 |
< |
colval(exposure,i) /= lampcolor[i]; |
| 289 |
> |
for (j = 0; j < 3; j++) |
| 290 |
> |
if (lampcolor[j] > 1e-4) |
| 291 |
> |
colval(exposure,j) /= lampcolor[j]; |
| 292 |
|
freelamps(); |
| 293 |
|
} |
| 294 |
|
/* open input file */ |
| 296 |
|
if (singlepass) |
| 297 |
|
fin = stdin; |
| 298 |
|
else { |
| 299 |
< |
tfname = mktemp(TEMPLATE); |
| 300 |
< |
if ((fin = fopen(tfname, "w+")) == NULL) { |
| 299 |
> |
tfname = mktemp(template); |
| 300 |
> |
if ((fin = fopen(tfname, "w+b")) == NULL) { |
| 301 |
|
fprintf(stderr, "%s: can't create ", progname); |
| 302 |
|
fprintf(stderr, "temp file \"%s\"\n", tfname); |
| 303 |
|
quit(1); |
| 309 |
|
} |
| 310 |
|
} |
| 311 |
|
} else if (i == argc-1) { |
| 312 |
< |
if ((fin = fopen(argv[i], "r")) == NULL) { |
| 312 |
> |
if ((fin = fopen(argv[i], "rb")) == NULL) { |
| 313 |
|
fprintf(stderr, "%s: can't open file \"%s\"\n", |
| 314 |
|
progname, argv[i]); |
| 315 |
|
quit(1); |
| 325 |
|
progname); |
| 326 |
|
quit(1); |
| 327 |
|
} |
| 328 |
+ |
if ((ourbright == spec_bright) ^ (NCSAMP > 3) || |
| 329 |
+ |
setspectrsamp(CNDX, WLPART) < 0) { |
| 330 |
+ |
fprintf(stderr, "%s: bad number of components\n", progname); |
| 331 |
+ |
quit(1); |
| 332 |
+ |
} |
| 333 |
|
/* add new header info. */ |
| 334 |
|
printargs(i, argv, stdout); |
| 335 |
|
/* get picture size */ |
| 339 |
|
} |
| 340 |
|
if (!(order & YMAJOR)) |
| 341 |
|
inpaspect = 1.0/inpaspect; |
| 342 |
+ |
/* wrap around for cylindrical view? */ |
| 343 |
+ |
wrapfilt = gotview && ourview.type == VT_CYL && |
| 344 |
+ |
ourview.horiz >= 360.-FTINY && order & YMAJOR; |
| 345 |
|
/* compute output resolution */ |
| 346 |
|
if (ncols <= 0) |
| 347 |
|
ncols = x_c*xres + .5; |
| 373 |
|
} |
| 374 |
|
pass2(fin); |
| 375 |
|
|
| 376 |
< |
quit(0); |
| 376 |
> |
quit(estatus); |
| 377 |
> |
return estatus; /* pro forma return */ |
| 378 |
|
} |
| 379 |
|
|
| 380 |
|
|
| 381 |
< |
headline(s) /* process line from header */ |
| 382 |
< |
char *s; |
| 381 |
> |
static void |
| 382 |
> |
copyfile( /* copy a file */ |
| 383 |
> |
FILE *infp, |
| 384 |
> |
FILE *out |
| 385 |
> |
) |
| 386 |
|
{ |
| 387 |
< |
char fmt[32]; |
| 387 |
> |
int c; |
| 388 |
|
|
| 389 |
< |
fputs(s, stdout); /* copy to output */ |
| 309 |
< |
if (isaspect(s)) /* get aspect ratio */ |
| 310 |
< |
inpaspect *= aspectval(s); |
| 311 |
< |
else if (isexpos(s)) |
| 312 |
< |
hotlvl *= exposval(s); |
| 313 |
< |
else if (isformat(s)) { |
| 314 |
< |
formatval(fmt, s); |
| 315 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
| 316 |
< |
} |
| 317 |
< |
} |
| 318 |
< |
|
| 319 |
< |
|
| 320 |
< |
copyfile(in, out) /* copy a file */ |
| 321 |
< |
register FILE *in, *out; |
| 322 |
< |
{ |
| 323 |
< |
register int c; |
| 324 |
< |
|
| 325 |
< |
while ((c = getc(in)) != EOF) |
| 389 |
> |
while ((c = getc(infp)) != EOF) |
| 390 |
|
putc(c, out); |
| 391 |
|
|
| 392 |
|
if (ferror(out)) { |
| 396 |
|
} |
| 397 |
|
|
| 398 |
|
|
| 399 |
< |
pass1(in) /* first pass of picture file */ |
| 400 |
< |
FILE *in; |
| 399 |
> |
static void |
| 400 |
> |
pass1( /* first pass of picture file */ |
| 401 |
> |
FILE *infp |
| 402 |
> |
) |
| 403 |
|
{ |
| 404 |
|
int i; |
| 405 |
< |
COLOR *scan; |
| 405 |
> |
COLORV *scan; |
| 406 |
|
|
| 407 |
|
pass1init(); |
| 408 |
|
|
| 409 |
< |
scan = (COLOR *)malloc(xres*sizeof(COLOR)); |
| 409 |
> |
scan = (COLORV *)malloc(xres*NCSAMP*sizeof(COLORV)); |
| 410 |
|
if (scan == NULL) { |
| 411 |
|
fprintf(stderr, "%s: out of memory\n", progname); |
| 412 |
|
quit(1); |
| 413 |
|
} |
| 414 |
|
for (i = 0; i < yres; i++) { |
| 415 |
< |
if (freadscan(scan, xres, in) < 0) { |
| 415 |
> |
if (freadsscan(scan, NCSAMP, xres, infp) < 0) { |
| 416 |
|
nrows = (long)nrows * i / yres; /* adjust frame */ |
| 417 |
|
if (nrows <= 0) { |
| 418 |
|
fprintf(stderr, "%s: empty frame\n", progname); |
| 422 |
|
progname, (int)(100L*i/yres)); |
| 423 |
|
yres = i; |
| 424 |
|
y_r = (double)nrows/yres; |
| 425 |
+ |
estatus++; |
| 426 |
|
break; |
| 427 |
|
} |
| 428 |
|
pass1scan(scan, i); |
| 429 |
|
} |
| 430 |
< |
free((char *)scan); |
| 430 |
> |
free(scan); |
| 431 |
|
} |
| 432 |
|
|
| 433 |
|
|
| 434 |
< |
pass2(in) /* last pass on file, write to stdout */ |
| 435 |
< |
FILE *in; |
| 434 |
> |
static void |
| 435 |
> |
pass2( /* last pass on file, write to stdout */ |
| 436 |
> |
FILE *infp |
| 437 |
> |
) |
| 438 |
|
{ |
| 439 |
|
int yread; |
| 440 |
|
int ycent, xcent; |
| 444 |
|
scan2init(); |
| 445 |
|
yread = 0; |
| 446 |
|
for (r = 0; r < nrows; r++) { |
| 447 |
< |
ycent = (long)r*yres/nrows; |
| 447 |
> |
ycent = (r+.5)*yres/nrows; |
| 448 |
|
while (yread <= ycent+yrad) { |
| 449 |
|
if (yread < yres) { |
| 450 |
< |
if (freadscan(scanin[yread%barsize], |
| 451 |
< |
xres, in) < 0) { |
| 450 |
> |
if (freadsscan(scanin[yread%barsize], |
| 451 |
> |
NCSAMP, xres, infp) < 0) { |
| 452 |
|
fprintf(stderr, |
| 453 |
< |
"%s: bad read (y=%d)\n", |
| 453 |
> |
"%s: truncated input (y=%d)\n", |
| 454 |
|
progname, yres-1-yread); |
| 455 |
|
quit(1); |
| 456 |
|
} |
| 458 |
|
} |
| 459 |
|
yread++; |
| 460 |
|
} |
| 461 |
< |
if (obarsize > 0) |
| 461 |
> |
if (obarsize > 0) /* => thresh > FTINY */ |
| 462 |
|
scan2sync(r); |
| 463 |
|
for (c = 0; c < ncols; c++) { |
| 464 |
< |
xcent = (long)c*xres/ncols; |
| 464 |
> |
xcent = (c+.5)*xres/ncols; |
| 465 |
|
if (thresh > FTINY) |
| 466 |
|
dothresh(xcent, ycent, c, r); |
| 467 |
|
else if (rad > FTINY) |
| 468 |
< |
dogauss(scanout[c], xcent, ycent, c, r); |
| 468 |
> |
dogauss(scanout+c*NCSAMP, xcent, ycent, c, r); |
| 469 |
|
else |
| 470 |
< |
dobox(scanout[c], xcent, ycent, c, r); |
| 470 |
> |
dobox(scanout+c*NCSAMP, xcent, ycent, c, r); |
| 471 |
|
} |
| 472 |
< |
if (scanout != NULL && fwritescan(scanout, ncols, stdout) < 0) { |
| 472 |
> |
if (scanout != NULL && fwritesscan(scanout, NCSAMP, ncols, stdout) < 0) { |
| 473 |
|
fprintf(stderr, "%s: write error in pass2\n", progname); |
| 474 |
|
quit(1); |
| 475 |
|
} |
| 476 |
|
} |
| 477 |
|
/* skip leftover input */ |
| 478 |
|
while (yread < yres) { |
| 479 |
< |
if (freadscan(scanin[0], xres, in) < 0) |
| 479 |
> |
if (freadscolrs((uby8 *)tempbuffer(xres*(NCSAMP+1)), |
| 480 |
> |
NCSAMP, xres, infp) < 0) |
| 481 |
|
break; |
| 482 |
|
yread++; |
| 483 |
|
} |
| 485 |
|
} |
| 486 |
|
|
| 487 |
|
|
| 488 |
< |
scan2init() /* prepare scanline arrays */ |
| 488 |
> |
static void |
| 489 |
> |
scan2init(void) /* prepare scanline arrays */ |
| 490 |
|
{ |
| 491 |
|
COLOR ctmp; |
| 492 |
|
double d; |
| 493 |
< |
register int i; |
| 493 |
> |
int i; |
| 494 |
|
|
| 495 |
|
xbrad = xres/ncols/2 + 1; |
| 496 |
|
ybrad = yres/nrows/2 + 1; |
| 499 |
|
rad *= (y_r + x_c)/2.0; |
| 500 |
|
|
| 501 |
|
if (thresh > FTINY) { |
| 431 |
– |
xrad = CHECKRAD*THRESHRAD*rad/x_c + xbrad; |
| 432 |
– |
yrad = CHECKRAD*THRESHRAD*rad/y_r + ybrad; |
| 502 |
|
orad = CHECKRAD*THRESHRAD*rad + 1; |
| 503 |
+ |
xrad = orad/x_c + xbrad; |
| 504 |
+ |
yrad = orad/y_r + ybrad; |
| 505 |
|
obarsize = 2*orad + 1; |
| 506 |
|
} else { |
| 507 |
|
xrad = CHECKRAD*rad/x_c + 1; |
| 513 |
|
yrad = ybrad; |
| 514 |
|
} |
| 515 |
|
barsize = 2*yrad + 1; |
| 516 |
< |
scanin = (COLOR **)malloc(barsize*sizeof(COLOR *)); |
| 516 |
> |
scanin = (COLORV **)malloc(barsize*sizeof(COLORV *)); |
| 517 |
> |
if (scanin == NULL) |
| 518 |
> |
goto memerr; |
| 519 |
|
for (i = 0; i < barsize; i++) { |
| 520 |
< |
scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR)); |
| 521 |
< |
if (scanin[i] == NULL) { |
| 522 |
< |
fprintf(stderr, "%s: out of memory\n", progname); |
| 450 |
< |
quit(1); |
| 451 |
< |
} |
| 520 |
> |
scanin[i] = (COLORV *)malloc(xres*NCSAMP*sizeof(COLORV)); |
| 521 |
> |
if (scanin[i] == NULL) |
| 522 |
> |
goto memerr; |
| 523 |
|
} |
| 524 |
|
if (obarsize > 0) { |
| 525 |
< |
scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *)); |
| 525 |
> |
scoutbar = (COLORV **)malloc(obarsize*sizeof(COLORV *)); |
| 526 |
|
greybar = (float **)malloc(obarsize*sizeof(float *)); |
| 527 |
+ |
if ((scoutbar == NULL) | (greybar == NULL)) |
| 528 |
+ |
goto memerr; |
| 529 |
|
for (i = 0; i < obarsize; i++) { |
| 530 |
< |
scoutbar[i] = (COLOR *)malloc(ncols*sizeof(COLOR)); |
| 530 |
> |
scoutbar[i] = (COLORV *)malloc(ncols*NCSAMP*sizeof(COLORV)); |
| 531 |
|
greybar[i] = (float *)malloc(ncols*sizeof(float)); |
| 532 |
< |
if (scoutbar[i] == NULL | greybar[i] == NULL) { |
| 533 |
< |
fprintf(stderr, "%s: out of memory\n", |
| 461 |
< |
progname); |
| 462 |
< |
quit(1); |
| 463 |
< |
} |
| 532 |
> |
if ((scoutbar[i] == NULL) | (greybar[i] == NULL)) |
| 533 |
> |
goto memerr; |
| 534 |
|
} |
| 535 |
|
} else { |
| 536 |
< |
scanout = (COLOR *)malloc(ncols*sizeof(COLOR)); |
| 537 |
< |
if (scanout == NULL) { |
| 538 |
< |
fprintf(stderr, "%s: out of memory\n", progname); |
| 469 |
< |
quit(1); |
| 470 |
< |
} |
| 536 |
> |
scanout = (COLORV *)malloc(ncols*NCSAMP*sizeof(COLORV)); |
| 537 |
> |
if (scanout == NULL) |
| 538 |
> |
goto memerr; |
| 539 |
|
} |
| 540 |
|
/* record pixel aspect ratio */ |
| 541 |
|
if (!correctaspect) { |
| 556 |
|
printf("\n"); |
| 557 |
|
/* write out resolution */ |
| 558 |
|
fputresolu(order, ncols, nrows, stdout); |
| 559 |
+ |
return; |
| 560 |
+ |
memerr: |
| 561 |
+ |
fprintf(stderr, "%s: out of memory\n", progname); |
| 562 |
+ |
quit(1); |
| 563 |
|
} |
| 564 |
|
|
| 565 |
|
|
| 566 |
< |
scan2sync(r) /* synchronize grey averages and output scan */ |
| 567 |
< |
int r; |
| 566 |
> |
static void |
| 567 |
> |
scan2sync( /* synchronize grey averages and output scan */ |
| 568 |
> |
int r |
| 569 |
> |
) |
| 570 |
|
{ |
| 571 |
|
static int nextrow = 0; |
| 572 |
< |
COLOR ctmp; |
| 572 |
> |
SCOLOR ctmp; |
| 573 |
|
int ybot; |
| 574 |
< |
register int c; |
| 574 |
> |
int c; |
| 575 |
|
/* average input scanlines */ |
| 576 |
< |
while (nextrow < r+orad && nextrow < nrows) { |
| 577 |
< |
ybot = (long)nextrow*yres/nrows; |
| 576 |
> |
while (nextrow <= r+orad && nextrow < nrows) { |
| 577 |
> |
ybot = (nextrow+.5)*yres/nrows; |
| 578 |
|
for (c = 0; c < ncols; c++) { |
| 579 |
< |
dobox(ctmp, (int)((long)c*xres/ncols),ybot, c,nextrow); |
| 580 |
< |
greybar[nextrow%obarsize][c] = bright(ctmp); |
| 579 |
> |
dobox(ctmp, (int)((c+.5)*xres/ncols),ybot, c,nextrow); |
| 580 |
> |
greybar[nextrow%obarsize][c] = (*ourbright)(ctmp); |
| 581 |
|
} |
| 582 |
|
/* and zero output scanline */ |
| 583 |
< |
bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR)); |
| 583 |
> |
memset(scoutbar[nextrow%obarsize], 0, ncols*NCSAMP*sizeof(COLORV)); |
| 584 |
|
nextrow++; |
| 585 |
|
} |
| 586 |
|
/* point to top scanline for output */ |
| 591 |
|
} |
| 592 |
|
|
| 593 |
|
|
| 594 |
< |
scan2flush() /* flush output buffer */ |
| 594 |
> |
static void |
| 595 |
> |
scan2flush(void) /* flush output buffer */ |
| 596 |
|
{ |
| 597 |
< |
register int r; |
| 597 |
> |
int r; |
| 598 |
|
|
| 599 |
|
for (r = nrows-orad; r < nrows; r++) |
| 600 |
< |
if (fwritescan(scoutbar[r%obarsize], ncols, stdout) < 0) |
| 600 |
> |
if (fwritesscan(scoutbar[r%obarsize], NCSAMP, ncols, stdout) < 0) |
| 601 |
|
break; |
| 602 |
|
if (fflush(stdout) < 0) { |
| 603 |
|
fprintf(stderr, "%s: write error at end of pass2\n", progname); |
| 604 |
< |
exit(1); |
| 604 |
> |
quit(1); |
| 605 |
|
} |
| 606 |
|
} |
| 607 |
|
|
| 608 |
|
|
| 609 |
+ |
void |
| 610 |
|
quit(code) /* remove temporary file and exit */ |
| 611 |
|
int code; |
| 612 |
|
{ |