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 "platform.h" |
16 |
+ |
#include "standard.h" |
17 |
+ |
#include "rtio.h" |
18 |
|
#include "color.h" |
19 |
< |
|
20 |
< |
#include "resolu.h" |
21 |
< |
|
19 |
> |
#include "view.h" |
20 |
|
#include "paths.h" |
21 |
+ |
#include "pfilt.h" |
22 |
|
|
24 |
– |
extern float *matchlamp(); |
23 |
|
|
24 |
|
#define FEQ(a,b) ((a) >= .98*(b) && (a) <= 1.02*(b)) |
25 |
|
|
26 |
< |
double CHECKRAD = 1.5; /* radius to check for filtering */ |
26 |
> |
double CHECKRAD = 2.0; /* radius to check for filtering */ |
27 |
|
|
28 |
|
#define THRESHRAD 5.0 /* maximum sample spread in output */ |
29 |
|
|
62 |
|
|
63 |
|
int wrongformat = 0; |
64 |
|
|
65 |
+ |
VIEW ourview = STDVIEW; |
66 |
+ |
int gotview = 0; |
67 |
+ |
int wrapfilt = 0; /* wrap filter horizontally? */ |
68 |
+ |
|
69 |
+ |
int estatus = 0; /* exit status (for non-fatal errors) */ |
70 |
+ |
|
71 |
|
int xrad; /* x search radius */ |
72 |
|
int yrad; /* y search radius */ |
73 |
|
int xbrad; /* x box size */ |
83 |
|
|
84 |
|
char *progname; |
85 |
|
|
86 |
+ |
static gethfunc headline; |
87 |
+ |
static brightfunc_t rgb_bright; |
88 |
+ |
static brightfunc_t xyz_bright; |
89 |
+ |
static void copyfile(FILE *in, FILE *out); |
90 |
+ |
static void pass1(FILE *in); |
91 |
+ |
static void pass2(FILE *in); |
92 |
+ |
static void scan2init(void); |
93 |
+ |
static void scan2sync(int r); |
94 |
+ |
static void scan2flush(void); |
95 |
|
|
96 |
< |
main(argc, argv) |
97 |
< |
int argc; |
98 |
< |
char **argv; |
96 |
> |
|
97 |
> |
int |
98 |
> |
main( |
99 |
> |
int argc, |
100 |
> |
char **argv |
101 |
> |
) |
102 |
|
{ |
87 |
– |
extern long ftell(); |
88 |
– |
extern int quit(), headline(); |
103 |
|
FILE *fin; |
104 |
|
float *lampcolor; |
105 |
|
char *lamptype = NULL; |
107 |
|
double outaspect = 0.0; |
108 |
|
double d; |
109 |
|
int i, j; |
110 |
< |
#ifdef MSDOS |
111 |
< |
extern int _fmode; |
112 |
< |
_fmode = O_BINARY; |
99 |
< |
setmode(fileno(stdin), O_BINARY); |
100 |
< |
setmode(fileno(stdout), O_BINARY); |
101 |
< |
#endif |
110 |
> |
SET_DEFAULT_BINARY(); |
111 |
> |
SET_FILE_BINARY(stdin); |
112 |
> |
SET_FILE_BINARY(stdout); |
113 |
|
if (signal(SIGINT, quit) == SIG_IGN) |
114 |
|
signal(SIGINT, SIG_IGN); |
115 |
+ |
#ifdef SIGHUP |
116 |
|
if (signal(SIGHUP, quit) == SIG_IGN) |
117 |
|
signal(SIGHUP, SIG_IGN); |
118 |
+ |
#endif |
119 |
|
signal(SIGTERM, quit); |
120 |
+ |
#ifdef SIGPIPE |
121 |
|
signal(SIGPIPE, quit); |
122 |
+ |
#endif |
123 |
|
#ifdef SIGXCPU |
124 |
|
signal(SIGXCPU, quit); |
125 |
|
signal(SIGXFSZ, quit); |
162 |
|
fprintf(stderr, |
163 |
|
"%s: exposure out of range\n", |
164 |
|
argv[0]); |
165 |
< |
exit(1); |
165 |
> |
quit(1); |
166 |
|
} |
167 |
|
switch (argv[i][2]) { |
168 |
|
case '\0': |
212 |
|
case 'm': |
213 |
|
thresh = atof(argv[++i]); |
214 |
|
if (rad <= FTINY) |
215 |
< |
rad = 1.0; |
215 |
> |
rad = 0.6; |
216 |
|
break; |
217 |
|
case 'b': |
218 |
|
rad = thresh = 0.0; |
282 |
|
} |
283 |
|
if (!(order & YMAJOR)) |
284 |
|
inpaspect = 1.0/inpaspect; |
285 |
+ |
/* wrap around for cylindrical view? */ |
286 |
+ |
wrapfilt = gotview && ourview.type == VT_CYL && |
287 |
+ |
ourview.horiz >= 360.-FTINY && order & YMAJOR; |
288 |
|
/* compute output resolution */ |
289 |
|
if (ncols <= 0) |
290 |
|
ncols = x_c*xres + .5; |
316 |
|
} |
317 |
|
pass2(fin); |
318 |
|
|
319 |
< |
quit(0); |
319 |
> |
quit(estatus); |
320 |
> |
return estatus; /* pro forma return */ |
321 |
|
} |
322 |
|
|
323 |
|
|
324 |
< |
double |
325 |
< |
rgb_bright(clr) |
326 |
< |
COLOR clr; |
324 |
> |
static double |
325 |
> |
rgb_bright( |
326 |
> |
COLOR clr |
327 |
> |
) |
328 |
|
{ |
329 |
|
return(bright(clr)); |
330 |
|
} |
331 |
|
|
332 |
|
|
333 |
< |
double |
334 |
< |
xyz_bright(clr) |
335 |
< |
COLOR clr; |
333 |
> |
static double |
334 |
> |
xyz_bright( |
335 |
> |
COLOR clr |
336 |
> |
) |
337 |
|
{ |
338 |
|
return(clr[CIEY]); |
339 |
|
} |
340 |
|
|
341 |
|
|
342 |
< |
double (*ourbright)() = rgb_bright; |
342 |
> |
brightfunc_t *ourbright = rgb_bright; |
343 |
|
|
344 |
< |
|
345 |
< |
headline(s) /* process line from header */ |
346 |
< |
char *s; |
344 |
> |
static int |
345 |
> |
headline( /* process line from header */ |
346 |
> |
char *s, |
347 |
> |
void *p |
348 |
> |
) |
349 |
|
{ |
350 |
< |
char fmt[32]; |
350 |
> |
char fmt[MAXFMTLEN]; |
351 |
|
|
352 |
|
fputs(s, stdout); /* copy to output */ |
353 |
|
if (isaspect(s)) /* get aspect ratio */ |
362 |
|
ourbright = xyz_bright; |
363 |
|
else |
364 |
|
wrongformat = !globmatch(PICFMT, fmt); |
365 |
< |
} |
365 |
> |
} else if (isview(s) && sscanview(&ourview, s) > 0) |
366 |
> |
gotview++; |
367 |
> |
return(0); |
368 |
|
} |
369 |
|
|
370 |
|
|
371 |
< |
copyfile(in, out) /* copy a file */ |
372 |
< |
register FILE *in, *out; |
371 |
> |
static void |
372 |
> |
copyfile( /* copy a file */ |
373 |
> |
FILE *in, |
374 |
> |
FILE *out |
375 |
> |
) |
376 |
|
{ |
377 |
< |
register int c; |
377 |
> |
int c; |
378 |
|
|
379 |
|
while ((c = getc(in)) != EOF) |
380 |
|
putc(c, out); |
386 |
|
} |
387 |
|
|
388 |
|
|
389 |
< |
pass1(in) /* first pass of picture file */ |
390 |
< |
FILE *in; |
389 |
> |
static void |
390 |
> |
pass1( /* first pass of picture file */ |
391 |
> |
FILE *in |
392 |
> |
) |
393 |
|
{ |
394 |
|
int i; |
395 |
|
COLOR *scan; |
412 |
|
progname, (int)(100L*i/yres)); |
413 |
|
yres = i; |
414 |
|
y_r = (double)nrows/yres; |
415 |
+ |
estatus++; |
416 |
|
break; |
417 |
|
} |
418 |
|
pass1scan(scan, i); |
419 |
|
} |
420 |
< |
free((char *)scan); |
420 |
> |
free((void *)scan); |
421 |
|
} |
422 |
|
|
423 |
|
|
424 |
< |
pass2(in) /* last pass on file, write to stdout */ |
425 |
< |
FILE *in; |
424 |
> |
static void |
425 |
> |
pass2( /* last pass on file, write to stdout */ |
426 |
> |
FILE *in |
427 |
> |
) |
428 |
|
{ |
429 |
|
int yread; |
430 |
|
int ycent, xcent; |
434 |
|
scan2init(); |
435 |
|
yread = 0; |
436 |
|
for (r = 0; r < nrows; r++) { |
437 |
< |
ycent = (long)r*yres/nrows; |
437 |
> |
ycent = (r+.5)*yres/nrows; |
438 |
|
while (yread <= ycent+yrad) { |
439 |
|
if (yread < yres) { |
440 |
|
if (freadscan(scanin[yread%barsize], |
451 |
|
if (obarsize > 0) |
452 |
|
scan2sync(r); |
453 |
|
for (c = 0; c < ncols; c++) { |
454 |
< |
xcent = (long)c*xres/ncols; |
454 |
> |
xcent = (c+.5)*xres/ncols; |
455 |
|
if (thresh > FTINY) |
456 |
|
dothresh(xcent, ycent, c, r); |
457 |
|
else if (rad > FTINY) |
474 |
|
} |
475 |
|
|
476 |
|
|
477 |
< |
scan2init() /* prepare scanline arrays */ |
477 |
> |
static void |
478 |
> |
scan2init(void) /* prepare scanline arrays */ |
479 |
|
{ |
480 |
|
COLOR ctmp; |
481 |
|
double d; |
482 |
< |
register int i; |
482 |
> |
int i; |
483 |
|
|
484 |
|
xbrad = xres/ncols/2 + 1; |
485 |
|
ybrad = yres/nrows/2 + 1; |
488 |
|
rad *= (y_r + x_c)/2.0; |
489 |
|
|
490 |
|
if (thresh > FTINY) { |
457 |
– |
xrad = CHECKRAD*THRESHRAD*rad/x_c + xbrad; |
458 |
– |
yrad = CHECKRAD*THRESHRAD*rad/y_r + ybrad; |
491 |
|
orad = CHECKRAD*THRESHRAD*rad + 1; |
492 |
+ |
xrad = orad/x_c + xbrad; |
493 |
+ |
yrad = orad/y_r + ybrad; |
494 |
|
obarsize = 2*orad + 1; |
495 |
|
} else { |
496 |
|
xrad = CHECKRAD*rad/x_c + 1; |
513 |
|
if (obarsize > 0) { |
514 |
|
scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *)); |
515 |
|
greybar = (float **)malloc(obarsize*sizeof(float *)); |
516 |
< |
if (scoutbar == NULL | greybar == NULL) |
516 |
> |
if ((scoutbar == NULL) | (greybar == NULL)) |
517 |
|
goto memerr; |
518 |
|
for (i = 0; i < obarsize; i++) { |
519 |
|
scoutbar[i] = (COLOR *)malloc(ncols*sizeof(COLOR)); |
520 |
|
greybar[i] = (float *)malloc(ncols*sizeof(float)); |
521 |
< |
if (scoutbar[i] == NULL | greybar[i] == NULL) |
521 |
> |
if ((scoutbar[i] == NULL) | (greybar[i] == NULL)) |
522 |
|
goto memerr; |
523 |
|
} |
524 |
|
} else { |
552 |
|
} |
553 |
|
|
554 |
|
|
555 |
< |
scan2sync(r) /* synchronize grey averages and output scan */ |
556 |
< |
int r; |
555 |
> |
static void |
556 |
> |
scan2sync( /* synchronize grey averages and output scan */ |
557 |
> |
int r |
558 |
> |
) |
559 |
|
{ |
560 |
|
static int nextrow = 0; |
561 |
|
COLOR ctmp; |
562 |
|
int ybot; |
563 |
< |
register int c; |
563 |
> |
int c; |
564 |
|
/* average input scanlines */ |
565 |
< |
while (nextrow < r+orad && nextrow < nrows) { |
566 |
< |
ybot = (long)nextrow*yres/nrows; |
565 |
> |
while (nextrow <= r+orad && nextrow < nrows) { |
566 |
> |
ybot = (nextrow+.5)*yres/nrows; |
567 |
|
for (c = 0; c < ncols; c++) { |
568 |
< |
dobox(ctmp, (int)((long)c*xres/ncols),ybot, c,nextrow); |
568 |
> |
dobox(ctmp, (int)((c+.5)*xres/ncols),ybot, c,nextrow); |
569 |
|
greybar[nextrow%obarsize][c] = (*ourbright)(ctmp); |
570 |
|
} |
571 |
|
/* and zero output scanline */ |
572 |
< |
bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR)); |
572 |
> |
memset((char *)scoutbar[nextrow%obarsize], '\0', ncols*sizeof(COLOR)); |
573 |
|
nextrow++; |
574 |
|
} |
575 |
|
/* point to top scanline for output */ |
580 |
|
} |
581 |
|
|
582 |
|
|
583 |
< |
scan2flush() /* flush output buffer */ |
583 |
> |
static void |
584 |
> |
scan2flush(void) /* flush output buffer */ |
585 |
|
{ |
586 |
< |
register int r; |
586 |
> |
int r; |
587 |
|
|
588 |
|
for (r = nrows-orad; r < nrows; r++) |
589 |
|
if (fwritescan(scoutbar[r%obarsize], ncols, stdout) < 0) |
590 |
|
break; |
591 |
|
if (fflush(stdout) < 0) { |
592 |
|
fprintf(stderr, "%s: write error at end of pass2\n", progname); |
593 |
< |
exit(1); |
593 |
> |
quit(1); |
594 |
|
} |
595 |
|
} |
596 |
|
|
597 |
|
|
598 |
+ |
void |
599 |
|
quit(code) /* remove temporary file and exit */ |
600 |
|
int code; |
601 |
|
{ |