1 |
– |
/* Copyright (c) 1996 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" |
16 |
< |
|
14 |
> |
#include "pfilt.h" |
15 |
> |
#include "platform.h" |
16 |
> |
#include "paths.h" |
17 |
|
#include "view.h" |
18 |
|
|
22 |
– |
#include "resolu.h" |
23 |
– |
|
24 |
– |
#include "paths.h" |
25 |
– |
|
26 |
– |
extern float *matchlamp(); |
27 |
– |
|
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 |
|
|
78 |
|
|
79 |
|
char *progname; |
80 |
|
|
81 |
+ |
static gethfunc headline; |
82 |
+ |
static brightfunc_t rgb_bright; |
83 |
+ |
static brightfunc_t xyz_bright; |
84 |
+ |
static void copyfile(FILE *in, FILE *out); |
85 |
+ |
static void pass1(FILE *in); |
86 |
+ |
static void pass2(FILE *in); |
87 |
+ |
static void scan2init(void); |
88 |
+ |
static void scan2sync(int r); |
89 |
+ |
static void scan2flush(void); |
90 |
|
|
91 |
< |
main(argc, argv) |
92 |
< |
int argc; |
93 |
< |
char **argv; |
91 |
> |
|
92 |
> |
int |
93 |
> |
main( |
94 |
> |
int argc, |
95 |
> |
char **argv |
96 |
> |
) |
97 |
|
{ |
95 |
– |
extern long ftell(); |
96 |
– |
extern int quit(), headline(); |
98 |
|
FILE *fin; |
99 |
|
float *lampcolor; |
100 |
|
char *lamptype = NULL; |
102 |
|
double outaspect = 0.0; |
103 |
|
double d; |
104 |
|
int i, j; |
105 |
< |
#ifdef MSDOS |
106 |
< |
extern int _fmode; |
107 |
< |
_fmode = O_BINARY; |
107 |
< |
setmode(fileno(stdin), O_BINARY); |
108 |
< |
setmode(fileno(stdout), O_BINARY); |
109 |
< |
#endif |
105 |
> |
SET_DEFAULT_BINARY(); |
106 |
> |
SET_FILE_BINARY(stdin); |
107 |
> |
SET_FILE_BINARY(stdout); |
108 |
|
if (signal(SIGINT, quit) == SIG_IGN) |
109 |
|
signal(SIGINT, SIG_IGN); |
110 |
+ |
#ifdef SIGHUP |
111 |
|
if (signal(SIGHUP, quit) == SIG_IGN) |
112 |
|
signal(SIGHUP, SIG_IGN); |
113 |
+ |
#endif |
114 |
|
signal(SIGTERM, quit); |
115 |
+ |
#ifdef SIGPIPE |
116 |
|
signal(SIGPIPE, quit); |
117 |
+ |
#endif |
118 |
|
#ifdef SIGXCPU |
119 |
|
signal(SIGXCPU, quit); |
120 |
|
signal(SIGXFSZ, quit); |
207 |
|
case 'm': |
208 |
|
thresh = atof(argv[++i]); |
209 |
|
if (rad <= FTINY) |
210 |
< |
rad = 1.0; |
210 |
> |
rad = 0.6; |
211 |
|
break; |
212 |
|
case 'b': |
213 |
|
rad = thresh = 0.0; |
312 |
|
pass2(fin); |
313 |
|
|
314 |
|
quit(estatus); |
315 |
+ |
return estatus; /* pro forma return */ |
316 |
|
} |
317 |
|
|
318 |
|
|
319 |
< |
double |
320 |
< |
rgb_bright(clr) |
321 |
< |
COLOR clr; |
319 |
> |
static double |
320 |
> |
rgb_bright( |
321 |
> |
COLOR clr |
322 |
> |
) |
323 |
|
{ |
324 |
|
return(bright(clr)); |
325 |
|
} |
326 |
|
|
327 |
|
|
328 |
< |
double |
329 |
< |
xyz_bright(clr) |
330 |
< |
COLOR clr; |
328 |
> |
static double |
329 |
> |
xyz_bright( |
330 |
> |
COLOR clr |
331 |
> |
) |
332 |
|
{ |
333 |
|
return(clr[CIEY]); |
334 |
|
} |
335 |
|
|
336 |
|
|
337 |
< |
double (*ourbright)() = rgb_bright; |
337 |
> |
brightfunc_t *ourbright = rgb_bright; |
338 |
|
|
339 |
< |
|
340 |
< |
int |
341 |
< |
headline(s) /* process line from header */ |
342 |
< |
char *s; |
339 |
> |
static int |
340 |
> |
headline( /* process line from header */ |
341 |
> |
char *s, |
342 |
> |
void *p |
343 |
> |
) |
344 |
|
{ |
345 |
< |
char fmt[32]; |
345 |
> |
char fmt[MAXFMTLEN]; |
346 |
|
|
347 |
|
fputs(s, stdout); /* copy to output */ |
348 |
|
if (isaspect(s)) /* get aspect ratio */ |
363 |
|
} |
364 |
|
|
365 |
|
|
366 |
< |
copyfile(in, out) /* copy a file */ |
367 |
< |
register FILE *in, *out; |
366 |
> |
static void |
367 |
> |
copyfile( /* copy a file */ |
368 |
> |
FILE *in, |
369 |
> |
FILE *out |
370 |
> |
) |
371 |
|
{ |
372 |
< |
register int c; |
372 |
> |
int c; |
373 |
|
|
374 |
|
while ((c = getc(in)) != EOF) |
375 |
|
putc(c, out); |
381 |
|
} |
382 |
|
|
383 |
|
|
384 |
< |
pass1(in) /* first pass of picture file */ |
385 |
< |
FILE *in; |
384 |
> |
static void |
385 |
> |
pass1( /* first pass of picture file */ |
386 |
> |
FILE *in |
387 |
> |
) |
388 |
|
{ |
389 |
|
int i; |
390 |
|
COLOR *scan; |
412 |
|
} |
413 |
|
pass1scan(scan, i); |
414 |
|
} |
415 |
< |
free((char *)scan); |
415 |
> |
free((void *)scan); |
416 |
|
} |
417 |
|
|
418 |
|
|
419 |
< |
pass2(in) /* last pass on file, write to stdout */ |
420 |
< |
FILE *in; |
419 |
> |
static void |
420 |
> |
pass2( /* last pass on file, write to stdout */ |
421 |
> |
FILE *in |
422 |
> |
) |
423 |
|
{ |
424 |
|
int yread; |
425 |
|
int ycent, xcent; |
469 |
|
} |
470 |
|
|
471 |
|
|
472 |
< |
scan2init() /* prepare scanline arrays */ |
472 |
> |
static void |
473 |
> |
scan2init(void) /* prepare scanline arrays */ |
474 |
|
{ |
475 |
|
COLOR ctmp; |
476 |
|
double d; |
477 |
< |
register int i; |
477 |
> |
int i; |
478 |
|
|
479 |
|
xbrad = xres/ncols/2 + 1; |
480 |
|
ybrad = yres/nrows/2 + 1; |
508 |
|
if (obarsize > 0) { |
509 |
|
scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *)); |
510 |
|
greybar = (float **)malloc(obarsize*sizeof(float *)); |
511 |
< |
if (scoutbar == NULL | greybar == NULL) |
511 |
> |
if ((scoutbar == NULL) | (greybar == NULL)) |
512 |
|
goto memerr; |
513 |
|
for (i = 0; i < obarsize; i++) { |
514 |
|
scoutbar[i] = (COLOR *)malloc(ncols*sizeof(COLOR)); |
515 |
|
greybar[i] = (float *)malloc(ncols*sizeof(float)); |
516 |
< |
if (scoutbar[i] == NULL | greybar[i] == NULL) |
516 |
> |
if ((scoutbar[i] == NULL) | (greybar[i] == NULL)) |
517 |
|
goto memerr; |
518 |
|
} |
519 |
|
} else { |
547 |
|
} |
548 |
|
|
549 |
|
|
550 |
< |
scan2sync(r) /* synchronize grey averages and output scan */ |
551 |
< |
int r; |
550 |
> |
static void |
551 |
> |
scan2sync( /* synchronize grey averages and output scan */ |
552 |
> |
int r |
553 |
> |
) |
554 |
|
{ |
555 |
|
static int nextrow = 0; |
556 |
|
COLOR ctmp; |
557 |
|
int ybot; |
558 |
< |
register int c; |
558 |
> |
int c; |
559 |
|
/* average input scanlines */ |
560 |
|
while (nextrow <= r+orad && nextrow < nrows) { |
561 |
|
ybot = (nextrow+.5)*yres/nrows; |
564 |
|
greybar[nextrow%obarsize][c] = (*ourbright)(ctmp); |
565 |
|
} |
566 |
|
/* and zero output scanline */ |
567 |
< |
bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR)); |
567 |
> |
memset((char *)scoutbar[nextrow%obarsize], '\0', ncols*sizeof(COLOR)); |
568 |
|
nextrow++; |
569 |
|
} |
570 |
|
/* point to top scanline for output */ |
575 |
|
} |
576 |
|
|
577 |
|
|
578 |
< |
scan2flush() /* flush output buffer */ |
578 |
> |
static void |
579 |
> |
scan2flush(void) /* flush output buffer */ |
580 |
|
{ |
581 |
< |
register int r; |
581 |
> |
int r; |
582 |
|
|
583 |
|
for (r = nrows-orad; r < nrows; r++) |
584 |
|
if (fwritescan(scoutbar[r%obarsize], ncols, stdout) < 0) |
590 |
|
} |
591 |
|
|
592 |
|
|
593 |
+ |
void |
594 |
|
quit(code) /* remove temporary file and exit */ |
595 |
|
int code; |
596 |
|
{ |