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 "color.h" |
19 |
< |
|
20 |
< |
#include "resolu.h" |
21 |
< |
|
19 |
> |
#include "view.h" |
20 |
|
#include "paths.h" |
21 |
|
|
22 |
|
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 |
|
|
88 |
+ |
|
89 |
|
main(argc, argv) |
90 |
|
int argc; |
91 |
|
char **argv; |
92 |
|
{ |
87 |
– |
extern long ftell(); |
88 |
– |
extern int quit(), headline(); |
93 |
|
FILE *fin; |
94 |
|
float *lampcolor; |
95 |
|
char *lamptype = NULL; |
97 |
|
double outaspect = 0.0; |
98 |
|
double d; |
99 |
|
int i, j; |
100 |
< |
#ifdef MSDOS |
101 |
< |
extern int _fmode; |
102 |
< |
_fmode = O_BINARY; |
99 |
< |
setmode(fileno(stdin), O_BINARY); |
100 |
< |
setmode(fileno(stdout), O_BINARY); |
101 |
< |
#endif |
100 |
> |
SET_DEFAULT_BINARY(); |
101 |
> |
SET_FILE_BINARY(stdin); |
102 |
> |
SET_FILE_BINARY(stdout); |
103 |
|
if (signal(SIGINT, quit) == SIG_IGN) |
104 |
|
signal(SIGINT, SIG_IGN); |
105 |
+ |
#ifdef SIGHUP |
106 |
|
if (signal(SIGHUP, quit) == SIG_IGN) |
107 |
|
signal(SIGHUP, SIG_IGN); |
108 |
+ |
#endif |
109 |
|
signal(SIGTERM, quit); |
110 |
+ |
#ifdef SIGPIPE |
111 |
|
signal(SIGPIPE, quit); |
112 |
+ |
#endif |
113 |
|
#ifdef SIGXCPU |
114 |
|
signal(SIGXCPU, quit); |
115 |
|
signal(SIGXFSZ, quit); |
152 |
|
fprintf(stderr, |
153 |
|
"%s: exposure out of range\n", |
154 |
|
argv[0]); |
155 |
< |
exit(1); |
155 |
> |
quit(1); |
156 |
|
} |
157 |
|
switch (argv[i][2]) { |
158 |
|
case '\0': |
202 |
|
case 'm': |
203 |
|
thresh = atof(argv[++i]); |
204 |
|
if (rad <= FTINY) |
205 |
< |
rad = 1.0; |
205 |
> |
rad = 0.6; |
206 |
|
break; |
207 |
|
case 'b': |
208 |
|
rad = thresh = 0.0; |
272 |
|
} |
273 |
|
if (!(order & YMAJOR)) |
274 |
|
inpaspect = 1.0/inpaspect; |
275 |
+ |
/* wrap around for cylindrical view? */ |
276 |
+ |
wrapfilt = gotview && ourview.type == VT_CYL && |
277 |
+ |
ourview.horiz >= 360.-FTINY && order & YMAJOR; |
278 |
|
/* compute output resolution */ |
279 |
|
if (ncols <= 0) |
280 |
|
ncols = x_c*xres + .5; |
306 |
|
} |
307 |
|
pass2(fin); |
308 |
|
|
309 |
< |
quit(0); |
309 |
> |
quit(estatus); |
310 |
|
} |
311 |
|
|
312 |
|
|
313 |
< |
headline(s) /* process line from header */ |
314 |
< |
char *s; |
313 |
> |
double |
314 |
> |
rgb_bright(clr) |
315 |
> |
COLOR clr; |
316 |
|
{ |
317 |
+ |
return(bright(clr)); |
318 |
+ |
} |
319 |
+ |
|
320 |
+ |
|
321 |
+ |
double |
322 |
+ |
xyz_bright(clr) |
323 |
+ |
COLOR clr; |
324 |
+ |
{ |
325 |
+ |
return(clr[CIEY]); |
326 |
+ |
} |
327 |
+ |
|
328 |
+ |
|
329 |
+ |
double (*ourbright)() = rgb_bright; |
330 |
+ |
|
331 |
+ |
|
332 |
+ |
static int |
333 |
+ |
headline( /* process line from header */ |
334 |
+ |
char *s, |
335 |
+ |
void *p |
336 |
+ |
) |
337 |
+ |
{ |
338 |
|
char fmt[32]; |
339 |
|
|
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 |
> |
return(0); |
356 |
|
} |
357 |
|
|
358 |
|
|
395 |
|
progname, (int)(100L*i/yres)); |
396 |
|
yres = i; |
397 |
|
y_r = (double)nrows/yres; |
398 |
+ |
estatus++; |
399 |
|
break; |
400 |
|
} |
401 |
|
pass1scan(scan, i); |
402 |
|
} |
403 |
< |
free((char *)scan); |
403 |
> |
free((void *)scan); |
404 |
|
} |
405 |
|
|
406 |
|
|
415 |
|
scan2init(); |
416 |
|
yread = 0; |
417 |
|
for (r = 0; r < nrows; r++) { |
418 |
< |
ycent = (long)r*yres/nrows; |
418 |
> |
ycent = (r+.5)*yres/nrows; |
419 |
|
while (yread <= ycent+yrad) { |
420 |
|
if (yread < yres) { |
421 |
|
if (freadscan(scanin[yread%barsize], |
432 |
|
if (obarsize > 0) |
433 |
|
scan2sync(r); |
434 |
|
for (c = 0; c < ncols; c++) { |
435 |
< |
xcent = (long)c*xres/ncols; |
435 |
> |
xcent = (c+.5)*xres/ncols; |
436 |
|
if (thresh > FTINY) |
437 |
|
dothresh(xcent, ycent, c, r); |
438 |
|
else if (rad > FTINY) |
468 |
|
rad *= (y_r + x_c)/2.0; |
469 |
|
|
470 |
|
if (thresh > FTINY) { |
433 |
– |
xrad = CHECKRAD*THRESHRAD*rad/x_c + xbrad; |
434 |
– |
yrad = CHECKRAD*THRESHRAD*rad/y_r + ybrad; |
471 |
|
orad = CHECKRAD*THRESHRAD*rad + 1; |
472 |
+ |
xrad = orad/x_c + xbrad; |
473 |
+ |
yrad = orad/y_r + ybrad; |
474 |
|
obarsize = 2*orad + 1; |
475 |
|
} else { |
476 |
|
xrad = CHECKRAD*rad/x_c + 1; |
493 |
|
if (obarsize > 0) { |
494 |
|
scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *)); |
495 |
|
greybar = (float **)malloc(obarsize*sizeof(float *)); |
496 |
< |
if (scoutbar == NULL | greybar == NULL) |
496 |
> |
if ((scoutbar == NULL) | (greybar == NULL)) |
497 |
|
goto memerr; |
498 |
|
for (i = 0; i < obarsize; i++) { |
499 |
|
scoutbar[i] = (COLOR *)malloc(ncols*sizeof(COLOR)); |
500 |
|
greybar[i] = (float *)malloc(ncols*sizeof(float)); |
501 |
< |
if (scoutbar[i] == NULL | greybar[i] == NULL) |
501 |
> |
if ((scoutbar[i] == NULL) | (greybar[i] == NULL)) |
502 |
|
goto memerr; |
503 |
|
} |
504 |
|
} else { |
513 |
|
fputaspect(d, stdout); |
514 |
|
} |
515 |
|
/* record exposure */ |
516 |
< |
d = bright(exposure); |
516 |
> |
d = (*ourbright)(exposure); |
517 |
|
if (!FEQ(d,1.0)) |
518 |
|
fputexpos(d, stdout); |
519 |
|
/* record color correction */ |
540 |
|
int ybot; |
541 |
|
register int c; |
542 |
|
/* average input scanlines */ |
543 |
< |
while (nextrow < r+orad && nextrow < nrows) { |
544 |
< |
ybot = (long)nextrow*yres/nrows; |
543 |
> |
while (nextrow <= r+orad && nextrow < nrows) { |
544 |
> |
ybot = (nextrow+.5)*yres/nrows; |
545 |
|
for (c = 0; c < ncols; c++) { |
546 |
< |
dobox(ctmp, (int)((long)c*xres/ncols),ybot, c,nextrow); |
547 |
< |
greybar[nextrow%obarsize][c] = bright(ctmp); |
546 |
> |
dobox(ctmp, (int)((c+.5)*xres/ncols),ybot, c,nextrow); |
547 |
> |
greybar[nextrow%obarsize][c] = (*ourbright)(ctmp); |
548 |
|
} |
549 |
|
/* and zero output scanline */ |
550 |
< |
bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR)); |
550 |
> |
memset((char *)scoutbar[nextrow%obarsize], '\0', ncols*sizeof(COLOR)); |
551 |
|
nextrow++; |
552 |
|
} |
553 |
|
/* point to top scanline for output */ |
567 |
|
break; |
568 |
|
if (fflush(stdout) < 0) { |
569 |
|
fprintf(stderr, "%s: write error at end of pass2\n", progname); |
570 |
< |
exit(1); |
570 |
> |
quit(1); |
571 |
|
} |
572 |
|
} |
573 |
|
|
574 |
|
|
575 |
+ |
void |
576 |
|
quit(code) /* remove temporary file and exit */ |
577 |
|
int code; |
578 |
|
{ |