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