ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/ranimate.c
Revision: 2.38
Committed: Fri Jun 6 20:04:06 2003 UTC (20 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.37: +20 -19 lines
Log Message:
Fixed bug in blur computation for recovered frames

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: ranimate.c,v 2.37 2003/06/05 19:29:35 schorsch Exp $";
3 #endif
4 /*
5 * Radiance animation control program
6 *
7 * The main difference between this program and ranimove is that
8 * we have many optimizations here for camera motion in static
9 * environments, calling rpict and pinterp on multiple processors,
10 * where ranimove puts its emphasis on object motion, and does
11 * not use any external programs for image generation.
12 *
13 * See the ranimate(1) man page for further details.
14 */
15
16 #include "copyright.h"
17
18 #include "standard.h"
19 #include <ctype.h>
20 #include <sys/stat.h>
21 #include "view.h"
22 #include "vars.h"
23 #include "netproc.h"
24 /* default blur samples */
25 #ifndef DEF_NBLUR
26 #define DEF_NBLUR 5
27 #endif
28 /* default remote shell */
29 #ifdef _AUX_SOURCE
30 #define REMSH "remsh"
31 #else
32 #define REMSH "rsh"
33 #endif
34 /* input variables (alphabetical by name) */
35 #define ANIMATE 0 /* animation command */
36 #define ARCHIVE 1 /* archiving command */
37 #define BASENAME 2 /* output image base name */
38 #define DIRECTORY 3 /* working (sub)directory */
39 #define DISKSPACE 4 /* how much disk space to use */
40 #define END 5 /* ending frame number */
41 #define EXPOSURE 6 /* how to compute exposure */
42 #define HOST 7 /* rendering host machine */
43 #define INTERP 8 /* # frames to interpolate */
44 #define MBLUR 9 /* motion blur parameters */
45 #define NEXTANIM 10 /* next animation file */
46 #define OCTREE 11 /* octree file name */
47 #define OVERSAMP 12 /* # times to oversample image */
48 #define PFILT 13 /* pfilt options */
49 #define PINTERP 14 /* pinterp options */
50 #define RENDER 15 /* rendering options */
51 #define RESOLUTION 16 /* desired final resolution */
52 #define RIF 17 /* rad input file */
53 #define RSH 18 /* remote shell script or program */
54 #define RTRACE 19 /* use rtrace with pinterp? */
55 #define START 20 /* starting frame number */
56 #define TRANSFER 21 /* frame transfer command */
57 #define VIEWFILE 22 /* animation frame views */
58
59 int NVARS = 23; /* total number of variables */
60
61 VARIABLE vv[] = { /* variable-value pairs */
62 {"ANIMATE", 2, 0, NULL, onevalue},
63 {"ARCHIVE", 2, 0, NULL, onevalue},
64 {"BASENAME", 3, 0, NULL, onevalue},
65 {"DIRECTORY", 3, 0, NULL, onevalue},
66 {"DISKSPACE", 3, 0, NULL, fltvalue},
67 {"END", 2, 0, NULL, intvalue},
68 {"EXPOSURE", 3, 0, NULL, onevalue},
69 {"host", 4, 0, NULL, NULL},
70 {"INTERPOLATE", 3, 0, NULL, intvalue},
71 {"MBLUR", 2, 0, NULL, onevalue},
72 {"NEXTANIM", 3, 0, NULL, onevalue},
73 {"OCTREE", 3, 0, NULL, onevalue},
74 {"OVERSAMPLE", 2, 0, NULL, fltvalue},
75 {"pfilt", 2, 0, NULL, catvalues},
76 {"pinterp", 2, 0, NULL, catvalues},
77 {"render", 3, 0, NULL, catvalues},
78 {"RESOLUTION", 3, 0, NULL, onevalue},
79 {"RIF", 3, 0, NULL, onevalue},
80 {"RSH", 3, 0, NULL, onevalue},
81 {"RTRACE", 2, 0, NULL, boolvalue},
82 {"START", 2, 0, NULL, intvalue},
83 {"TRANSFER", 2, 0, NULL, onevalue},
84 {"VIEWFILE", 2, 0, NULL, onevalue},
85 };
86
87 #define SFNAME "STATUS" /* status file name */
88
89 struct {
90 char host[64]; /* control host name */
91 int pid; /* control process id */
92 char cfname[128]; /* control file name */
93 int rnext; /* next frame to render */
94 int fnext; /* next frame to filter */
95 int tnext; /* next frame to transfer */
96 } astat; /* animation status */
97
98 char *progname; /* our program name */
99 char *cfname; /* our control file name */
100
101 int nowarn = 0; /* turn warnings off? */
102 int silent = 0; /* silent mode? */
103 int noaction = 0; /* take no action? */
104
105 char *remsh; /* remote shell program/script */
106 char rendopt[2048]; /* rendering options */
107 char rresopt[32]; /* rendering resolution options */
108 char fresopt[32]; /* filter resolution options */
109 int pfiltalways; /* always use pfilt? */
110
111 char arcargs[10240]; /* files to archive */
112 char *arcfirst, *arcnext; /* pointers to first and next argument */
113
114 struct pslot {
115 int pid; /* process ID (0 if empty) */
116 int fout; /* output frame number */
117 int (*rcvf)(); /* recover function */
118 } *pslot; /* process slots */
119 int npslots; /* number of process slots */
120
121 #define phostname(ps) ((ps)->hostname[0] ? (ps)->hostname : astat.host)
122
123 struct pslot *findpslot();
124
125 PSERVER *lastpserver; /* last process server with error */
126
127 VIEW *getview();
128 char *getexp(), *dirfile();
129 int getblur();
130
131 extern time_t time();
132
133
134 main(argc, argv)
135 int argc;
136 char *argv[];
137 {
138 int explicate = 0;
139 int i;
140
141 progname = argv[0]; /* get arguments */
142 for (i = 1; i < argc && argv[i][0] == '-'; i++)
143 switch (argv[i][1]) {
144 case 'e': /* print variables */
145 explicate++;
146 break;
147 case 'w': /* turn off warnings */
148 nowarn++;
149 break;
150 case 's': /* silent mode */
151 silent++;
152 break;
153 case 'n': /* take no action */
154 noaction++;
155 break;
156 default:
157 goto userr;
158 }
159 if (i != argc-1)
160 goto userr;
161 cfname = argv[i];
162 /* load variables */
163 loadvars(cfname);
164 /* check variables */
165 checkvalues();
166 /* did we get DIRECTORY? */
167 checkdir();
168 /* check status */
169 if (getastat() < 0) {
170 fprintf(stderr, "%s: exiting\n", progname);
171 quit(1);
172 }
173 /* pfilt always if options given */
174 pfiltalways = vdef(PFILT);
175 /* load RIF if any */
176 if (vdef(RIF))
177 getradfile(vval(RIF));
178 /* set defaults */
179 setdefaults();
180 /* print variables */
181 if (explicate)
182 printvars(stdout);
183 /* set up process servers */
184 sethosts();
185 /* run animation */
186 animate();
187 /* all done */
188 if (vdef(NEXTANIM)) {
189 argv[i] = vval(NEXTANIM); /* just change input file */
190 if (!silent)
191 printargs(argc, argv, stdout);
192 if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL)
193 fprintf(stderr, "%s: command not found\n", progname);
194 else
195 execv(progname, argv);
196 quit(1);
197 }
198 quit(0);
199 userr:
200 fprintf(stderr, "Usage: %s [-s][-n][-w][-e] anim_file\n", progname);
201 quit(1);
202 }
203
204
205 getastat() /* check/set animation status */
206 {
207 char sfname[256];
208 FILE *fp;
209
210 sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME);
211 if ((fp = fopen(sfname, "r")) == NULL) {
212 if (errno != ENOENT) {
213 perror(sfname);
214 return(-1);
215 }
216 astat.rnext = astat.fnext = astat.tnext = 0;
217 goto setours;
218 }
219 if (fscanf(fp, "Control host: %s\n", astat.host) != 1)
220 goto fmterr;
221 if (fscanf(fp, "Control PID: %d\n", &astat.pid) != 1)
222 goto fmterr;
223 if (fscanf(fp, "Control file: %s\n", astat.cfname) != 1)
224 goto fmterr;
225 if (fscanf(fp, "Next render: %d\n", &astat.rnext) != 1)
226 goto fmterr;
227 if (fscanf(fp, "Next filter: %d\n", &astat.fnext) != 1)
228 goto fmterr;
229 if (fscanf(fp, "Next transfer: %d\n", &astat.tnext) != 1)
230 goto fmterr;
231 fclose(fp);
232 if (astat.pid != 0) { /* thinks it's still running */
233 if (strcmp(myhostname(), astat.host)) {
234 fprintf(stderr,
235 "%s: process %d may still be running on host %s\n",
236 progname, astat.pid, astat.host);
237 return(-1);
238 }
239 if (kill(astat.pid, 0) != -1 || errno != ESRCH) {
240 fprintf(stderr, "%s: process %d is still running\n",
241 progname, astat.pid);
242 return(-1);
243 }
244 /* assume it is dead */
245 }
246 if (strcmp(cfname, astat.cfname) && astat.pid != 0) { /* other's */
247 fprintf(stderr, "%s: unfinished job \"%s\"\n",
248 progname, astat.cfname);
249 return(-1);
250 }
251 /* check control file mods. */
252 if (!nowarn && fdate(cfname) > fdate(sfname))
253 fprintf(stderr,
254 "%s: warning - control file modified since last run\n",
255 progname);
256 setours: /* set our values */
257 strcpy(astat.host, myhostname());
258 astat.pid = getpid();
259 strcpy(astat.cfname, cfname);
260 return(0);
261 fmterr:
262 fprintf(stderr, "%s: format error in status file \"%s\"\n",
263 progname, sfname);
264 fclose(fp);
265 return(-1);
266 }
267
268
269 putastat() /* put out current status */
270 {
271 char buf[256];
272 FILE *fp;
273
274 if (noaction)
275 return;
276 sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME);
277 if ((fp = fopen(buf, "w")) == NULL) {
278 perror(buf);
279 quit(1);
280 }
281 fprintf(fp, "Control host: %s\n", astat.host);
282 fprintf(fp, "Control PID: %d\n", astat.pid);
283 fprintf(fp, "Control file: %s\n", astat.cfname);
284 fprintf(fp, "Next render: %d\n", astat.rnext);
285 fprintf(fp, "Next filter: %d\n", astat.fnext);
286 fprintf(fp, "Next transfer: %d\n", astat.tnext);
287 fclose(fp);
288 }
289
290
291 checkdir() /* make sure we have our directory */
292 {
293 struct stat stb;
294
295 if (!vdef(DIRECTORY)) {
296 fprintf(stderr, "%s: %s undefined\n",
297 progname, vnam(DIRECTORY));
298 quit(1);
299 }
300 if (stat(vval(DIRECTORY), &stb) == -1) {
301 if (errno == ENOENT && mkdir(vval(DIRECTORY), 0777) == 0)
302 return;
303 perror(vval(DIRECTORY));
304 quit(1);
305 }
306 if (!(stb.st_mode & S_IFDIR)) {
307 fprintf(stderr, "%s: not a directory\n", vval(DIRECTORY));
308 quit(1);
309 }
310 }
311
312
313 setdefaults() /* set default values */
314 {
315 extern char *atos();
316 int decades;
317 char buf[256];
318
319 if (vdef(ANIMATE)) {
320 vval(OCTREE) = NULL;
321 vdef(OCTREE) = 0;
322 } else if (!vdef(OCTREE)) {
323 fprintf(stderr, "%s: either %s or %s must be defined\n",
324 progname, vnam(OCTREE), vnam(ANIMATE));
325 quit(1);
326 }
327 if (!vdef(VIEWFILE)) {
328 fprintf(stderr, "%s: %s undefined\n", progname, vnam(VIEWFILE));
329 quit(1);
330 }
331 if (!vdef(HOST)) {
332 vval(HOST) = LHOSTNAME;
333 vdef(HOST)++;
334 }
335 if (!vdef(START)) {
336 vval(START) = "1";
337 vdef(START)++;
338 }
339 if (!vdef(END)) {
340 sprintf(buf, "%d", countviews()+vint(START)-1);
341 vval(END) = savqstr(buf);
342 vdef(END)++;
343 }
344 if (vint(END) < vint(START)) {
345 fprintf(stderr, "%s: ending frame less than starting frame\n",
346 progname);
347 quit(1);
348 }
349 if (!vdef(BASENAME)) {
350 decades = (int)log10((double)vint(END)) + 1;
351 if (decades < 3) decades = 3;
352 sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades);
353 vval(BASENAME) = savqstr(buf);
354 vdef(BASENAME)++;
355 }
356 if (!vdef(RESOLUTION)) {
357 vval(RESOLUTION) = "640";
358 vdef(RESOLUTION)++;
359 }
360 if (!vdef(OVERSAMP)) {
361 vval(OVERSAMP) = "2";
362 vdef(OVERSAMP)++;
363 }
364 if (!vdef(INTERP)) {
365 vval(INTERP) = "0";
366 vdef(INTERP)++;
367 }
368 if (!vdef(MBLUR)) {
369 vval(MBLUR) = "0";
370 vdef(MBLUR)++;
371 }
372 if (!vdef(RTRACE)) {
373 vval(RTRACE) = "F";
374 vdef(RTRACE)++;
375 }
376 if (!vdef(DISKSPACE)) {
377 if (!nowarn)
378 fprintf(stderr,
379 "%s: warning - no %s setting, assuming 100 Mbytes available\n",
380 progname, vnam(DISKSPACE));
381 vval(DISKSPACE) = "100";
382 vdef(DISKSPACE)++;
383 }
384 if (!vdef(RSH)) {
385 vval(RSH) = REMSH;
386 vdef(RSH)++;
387 }
388 /* locate remote shell program */
389 atos(buf, sizeof(buf), vval(RSH));
390 if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL)
391 remsh = savqstr(remsh);
392 else
393 remsh = vval(RSH); /* will generate error if used */
394
395 /* append rendering options */
396 if (vdef(RENDER))
397 sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER));
398 }
399
400
401 sethosts() /* set up process servers */
402 {
403 extern char *iskip();
404 char buf[256], *dir, *uname;
405 int np;
406 register char *cp;
407 int i;
408
409 npslots = 0;
410 if (noaction)
411 return;
412 for (i = 0; i < vdef(HOST); i++) { /* add each host */
413 dir = uname = NULL;
414 np = 1;
415 strcpy(cp=buf, nvalue(HOST, i)); /* copy to buffer */
416 cp = sskip(cp); /* skip host name */
417 while (isspace(*cp))
418 *cp++ = '\0';
419 if (*cp) { /* has # processes? */
420 np = atoi(cp);
421 if ((cp = iskip(cp)) == NULL || (*cp && !isspace(*cp)))
422 badvalue(HOST);
423 while (isspace(*cp))
424 cp++;
425 if (*cp) { /* has directory? */
426 dir = cp;
427 cp = sskip(cp); /* skip dir. */
428 while (isspace(*cp))
429 *cp++ = '\0';
430 if (*cp) { /* has user? */
431 uname = cp;
432 if (*sskip(cp))
433 badvalue(HOST);
434 }
435 }
436 }
437 if (addpserver(buf, dir, uname, np) == NULL) {
438 if (!nowarn)
439 fprintf(stderr,
440 "%s: cannot execute on host \"%s\"\n",
441 progname, buf);
442 } else
443 npslots += np;
444 }
445 if (npslots == 0) {
446 fprintf(stderr, "%s: no working process servers\n", progname);
447 quit(1);
448 }
449 pslot = (struct pslot *)calloc(npslots, sizeof(struct pslot));
450 if (pslot == NULL) {
451 perror("malloc");
452 quit(1);
453 }
454 }
455
456
457 getradfile(rfargs) /* run rad and get needed variables */
458 char *rfargs;
459 {
460 static short mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
461 char combuf[256];
462 register int i;
463 register char *cp;
464 char *pippt;
465 /* create rad command */
466 sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
467 sprintf(combuf,
468 "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
469 rfargs, rendopt+2);
470 cp = combuf;
471 while (*cp) {
472 if (*cp == '|') pippt = cp;
473 cp++;
474 } /* match unset variables */
475 for (i = 0; mvar[i] >= 0; i++)
476 if (!vdef(mvar[i])) {
477 *cp++ = '|';
478 strcpy(cp, vnam(mvar[i]));
479 while (*cp) cp++;
480 pippt = NULL;
481 }
482 if (pippt != NULL)
483 strcpy(pippt, "> /dev/null"); /* nothing to match */
484 else {
485 sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
486 cp += 11; /* point to file name */
487 }
488 system(combuf); /* ignore exit code */
489 if (pippt == NULL) { /* load variables and remove file */
490 loadvars(cp);
491 unlink(cp);
492 }
493 }
494
495
496 animate() /* run animation */
497 {
498 int xres, yres;
499 float pa, mult;
500 int frames_batch;
501 register int i;
502 double d1, d2;
503 /* compute rpict resolution */
504 i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa);
505 mult = vflt(OVERSAMP);
506 if (i == 3) {
507 sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres),
508 (int)(mult*yres), pa);
509 sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa);
510 } else if (i) {
511 if (i == 1) yres = xres;
512 sprintf(rresopt, "-x %d -y %d", (int)(mult*xres),
513 (int)(mult*yres));
514 sprintf(fresopt, "-x %d -y %d -pa 1", xres, yres);
515 } else
516 badvalue(RESOLUTION);
517 /* consistency checks */
518 if (vdef(ANIMATE)) {
519 if (vint(INTERP)) {
520 if (!nowarn)
521 fprintf(stderr,
522 "%s: resetting %s=0 for animation\n",
523 progname, vnam(INTERP));
524 vval(INTERP) = "0";
525 }
526 if (strcmp(vval(MBLUR),"0")) { /* can't handle this */
527 if (!nowarn)
528 fprintf(stderr,
529 "%s: resetting %s=0 for animation\n",
530 progname, vnam(MBLUR));
531 vval(MBLUR) = "0";
532 }
533 }
534 /* figure # frames per batch */
535 d1 = mult*xres*mult*yres*4; /* space for orig. picture */
536 if ((i=vint(INTERP)) || getblur(NULL) > 1)
537 d1 += mult*xres*mult*yres*sizeof(float); /* Z-buffer */
538 d2 = xres*yres*4; /* space for final picture */
539 frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2);
540 if (frames_batch < i+2) {
541 fprintf(stderr, "%s: insufficient disk space allocated\n",
542 progname);
543 quit(1);
544 }
545 /* initialize archive argument list */
546 i = vdef(ARCHIVE) ? strlen(vval(ARCHIVE))+132 : 132;
547 arcnext = arcfirst = arcargs + i;
548 /* initialize status file */
549 if (astat.rnext == 0)
550 astat.rnext = astat.fnext = astat.tnext = vint(START);
551 putastat();
552 /* render in batches */
553 while (astat.tnext <= vint(END)) {
554 renderframes(frames_batch);
555 filterframes();
556 transferframes();
557 }
558 /* mark status as finished */
559 astat.pid = 0;
560 putastat();
561 /* close open files */
562 getview(0);
563 getexp(0);
564 }
565
566
567 renderframes(nframes) /* render next nframes frames */
568 int nframes;
569 {
570 static char vendbuf[16];
571 VIEW *vp;
572 FILE *fp = NULL;
573 char vfname[128];
574 int lastframe;
575 register int i;
576
577 if (astat.tnext < astat.rnext) /* other work to do first */
578 return;
579 /* create batch view file */
580 if (!vdef(ANIMATE)) {
581 sprintf(vfname, "%s/anim.vf", vval(DIRECTORY));
582 if ((fp = fopen(vfname, "w")) == NULL) {
583 perror(vfname);
584 quit(1);
585 }
586 }
587 /* bound batch properly */
588 lastframe = astat.rnext + nframes - 1;
589 if ((lastframe-1) % (vint(INTERP)+1)) /* need even interval */
590 lastframe += vint(INTERP)+1 - ((lastframe-1)%(vint(INTERP)+1));
591 if (lastframe > vint(END)) /* check for end */
592 lastframe = vint(END);
593 /* render each view */
594 for (i = astat.rnext; i <= lastframe; i++) {
595 if ((vp = getview(i)) == NULL) {
596 if (!nowarn)
597 fprintf(stderr,
598 "%s: ran out of views before last frame\n",
599 progname);
600 sprintf(vval(END)=vendbuf, "%d", i-1);
601 lastframe = i - 1;
602 break;
603 }
604 if (vdef(ANIMATE)) /* animate frame */
605 animrend(i, vp);
606 else { /* else record it */
607 fputs(VIEWSTR, fp);
608 fprintview(vp, fp);
609 putc('\n', fp);
610 }
611 }
612 if (vdef(ANIMATE)) /* wait for renderings to finish */
613 bwait(0);
614 else { /* else if walk-through */
615 fclose(fp); /* close view file */
616 walkwait(astat.rnext, lastframe, vfname); /* walk it */
617 unlink(vfname); /* remove view file */
618 }
619 astat.rnext = i; /* update status */
620 putastat();
621 }
622
623
624 filterframes() /* catch up with filtering */
625 {
626 VIEW *vp;
627 register int i;
628
629 if (astat.tnext < astat.fnext) /* other work to do first */
630 return;
631 /* filter each view */
632 for (i = astat.fnext; i < astat.rnext; i++)
633 dofilt(i, 0);
634
635 bwait(0); /* wait for filter processes */
636 archive(); /* archive originals */
637 astat.fnext = i; /* update status */
638 putastat();
639 }
640
641
642 transferframes() /* catch up with picture transfers */
643 {
644 char combuf[10240], *fbase;
645 register char *cp;
646 register int i;
647
648 if (astat.tnext >= astat.fnext) /* nothing to do, yet */
649 return;
650 if (!vdef(TRANSFER)) { /* no transfer function -- leave 'em */
651 astat.tnext = astat.fnext;
652 putastat(); /* update status */
653 return;
654 }
655 strcpy(combuf, "cd "); /* start transfer command */
656 fbase = dirfile(cp = combuf+3, vval(BASENAME));
657 if (*cp) {
658 while (*++cp) ;
659 *cp++ = ';'; *cp++ = ' ';
660 } else
661 cp = combuf;
662 strcpy(cp, vval(TRANSFER));
663 while (*cp) cp++;
664 /* make argument list */
665 for (i = astat.tnext; i < astat.fnext; i++) {
666 *cp++ = ' ';
667 sprintf(cp, fbase, i);
668 while (*cp) cp++;
669 strcpy(cp, ".pic");
670 cp += 4;
671 }
672 if (runcom(combuf)) { /* transfer frames */
673 fprintf(stderr, "%s: error running transfer command\n",
674 progname);
675 quit(1);
676 }
677 astat.tnext = i; /* update status */
678 putastat();
679 }
680
681
682 animrend(frame, vp) /* start animation frame */
683 int frame;
684 VIEW *vp;
685 {
686 extern int recover();
687 char combuf[2048];
688 char fname[128];
689
690 sprintf(fname, vval(BASENAME), frame);
691 strcat(fname, ".unf");
692 if (access(fname, F_OK) == 0)
693 return;
694 sprintf(combuf, "%s %d | rpict%s%s -w0 %s > %s", vval(ANIMATE), frame,
695 rendopt, viewopt(vp), rresopt, fname);
696 bruncom(combuf, frame, recover); /* run in background */
697 }
698
699
700 walkwait(first, last, vfn) /* walk-through frames */
701 int first, last;
702 char *vfn;
703 {
704 double blurf;
705 int nblur = getblur(&blurf);
706 char combuf[2048];
707 register char *inspoint;
708 register int i;
709
710 if (!noaction && vint(INTERP)) /* create dummy frames */
711 for (i = first; i <= last; i++)
712 if (i < vint(END) && (i-1) % (vint(INTERP)+1)) {
713 sprintf(combuf, vval(BASENAME), i);
714 strcat(combuf, ".unf");
715 close(open(combuf, O_RDONLY|O_CREAT, 0666));
716 }
717 /* create command */
718 sprintf(combuf, "rpict%s%s -w0", rendopt,
719 viewopt(getview(first>1 ? first-1 : 1)));
720 inspoint = combuf;
721 while (*inspoint) inspoint++;
722 if (nblur) {
723 sprintf(inspoint, " -pm %.3f", blurf/nblur);
724 while (*inspoint) inspoint++;
725 }
726 if (nblur > 1 || vint(INTERP)) {
727 sprintf(inspoint, " -z %s.zbf", vval(BASENAME));
728 while (*inspoint) inspoint++;
729 }
730 sprintf(inspoint, " -o %s.unf %s -S %d",
731 vval(BASENAME), rresopt, first);
732 while (*inspoint) inspoint++;
733 sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
734 /* run in parallel */
735 i = (last-first+1)/(vint(INTERP)+1);
736 if (i < 1) i = 1;
737 if (pruncom(combuf, inspoint, i)) {
738 fprintf(stderr, "%s: error rendering frames %d through %d\n",
739 progname, first, last);
740 quit(1);
741 }
742 if (!noaction && vint(INTERP)) /* remove dummy frames */
743 for (i = first; i <= last; i++)
744 if (i < vint(END) && (i-1) % (vint(INTERP)+1)) {
745 sprintf(combuf, vval(BASENAME), i);
746 strcat(combuf, ".unf");
747 unlink(combuf);
748 }
749 }
750
751
752 int
753 recover(frame) /* recover the specified frame */
754 int frame;
755 {
756 static int *rfrm; /* list of recovered frames */
757 static int nrfrms = 0;
758 double blurf;
759 int nblur = getblur(&blurf);
760 char combuf[2048];
761 char fname[128];
762 register char *cp;
763 register int i;
764 /* check to see if recovered already */
765 for (i = nrfrms; i--; )
766 if (rfrm[i] == frame)
767 return(0);
768 /* build command */
769 sprintf(fname, vval(BASENAME), frame);
770 if (vdef(ANIMATE))
771 sprintf(combuf, "%s %d | rpict%s -w0",
772 vval(ANIMATE), frame, rendopt);
773 else
774 sprintf(combuf, "rpict%s -w0", rendopt);
775 cp = combuf;
776 while (*cp) cp++;
777 if (nblur) {
778 sprintf(cp, " -pm %.3f", blurf/nblur);
779 while (*cp) cp++;
780 }
781 if (nblur > 1 || vint(INTERP)) {
782 sprintf(cp, " -z %s.zbf", fname);
783 while (*cp) cp++;
784 }
785 sprintf(cp, " -ro %s.unf", fname);
786 while (*cp) cp++;
787 if (!vdef(ANIMATE)) {
788 *cp++ = ' ';
789 strcpy(cp, vval(OCTREE));
790 }
791 if (runcom(combuf)) /* run command */
792 return(1);
793 /* add frame to recovered list */
794 if (nrfrms)
795 rfrm = (int *)realloc((void *)rfrm, (nrfrms+1)*sizeof(int));
796 else
797 rfrm = (int *)malloc(sizeof(int));
798 if (rfrm == NULL) {
799 perror("malloc");
800 quit(1);
801 }
802 rfrm[nrfrms++] = frame;
803 return(0);
804 }
805
806
807 int
808 frecover(frame) /* recover filtered frame */
809 int frame;
810 {
811 if (dofilt(frame, 2) && dofilt(frame, 1))
812 return(1);
813 return(0);
814 }
815
816
817 archive() /* archive and remove renderings */
818 {
819 #define RMCOML (sizeof(rmcom)-1)
820 static char rmcom[] = "rm -f";
821 char basedir[128];
822 int dlen, alen;
823 register int j;
824
825 if (arcnext == arcfirst)
826 return; /* nothing to do */
827 dirfile(basedir, vval(BASENAME));
828 dlen = strlen(basedir);
829 if (vdef(ARCHIVE)) { /* run archive command */
830 alen = strlen(vval(ARCHIVE));
831 if (dlen) {
832 j = alen + dlen + 5;
833 strncpy(arcfirst-j, "cd ", 3);
834 strncpy(arcfirst-j+3, basedir, dlen);
835 (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
836 } else
837 j = alen;
838 strncpy(arcfirst-alen, vval(ARCHIVE), alen);
839 if (runcom(arcfirst-j)) {
840 fprintf(stderr, "%s: error running archive command\n",
841 progname);
842 quit(1);
843 }
844 }
845 if (dlen) {
846 j = RMCOML + dlen + 5;
847 strncpy(arcfirst-j, "cd ", 3);
848 strncpy(arcfirst-j+3, basedir, dlen);
849 (arcfirst-j)[dlen+3] = ';'; (arcfirst-j)[dlen+4] = ' ';
850 } else
851 j = RMCOML;
852 /* run remove command */
853 strncpy(arcfirst-RMCOML, rmcom, RMCOML);
854 runcom(arcfirst-j);
855 arcnext = arcfirst; /* reset argument list */
856 #undef RMCOML
857 }
858
859
860 int
861 dofilt(frame, rvr) /* filter frame */
862 int frame;
863 int rvr;
864 {
865 extern int frecover();
866 static int iter = 0;
867 double blurf;
868 int nblur = getblur(&blurf);
869 VIEW *vp = getview(frame);
870 char *ep = getexp(frame);
871 char fnbefore[128], fnafter[128], *fbase;
872 char combuf[1024], fname0[128], fname1[128];
873 int usepinterp, usepfilt, nora_rgbe;
874 int frseq[2];
875 /* check what is needed */
876 if (vp == NULL) {
877 fprintf(stderr,
878 "%s: unexpected error reading view for frame %d\n",
879 progname, frame);
880 quit(1);
881 }
882 if (ep == NULL) {
883 fprintf(stderr,
884 "%s: unexpected error reading exposure for frame %d\n",
885 progname, frame);
886 quit(1);
887 }
888 usepinterp = (nblur > 1);
889 usepfilt = pfiltalways | ep==NULL;
890 if (ep != NULL && !strcmp(ep, "1"))
891 ep = "+0";
892 nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
893 *ep != '+' || *ep != '-' || !isint(ep);
894 /* compute rendered views */
895 frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
896 frseq[1] = frseq[0] + vint(INTERP) + 1;
897 fbase = dirfile(NULL, vval(BASENAME));
898 if (frseq[1] > vint(END))
899 frseq[1] = vint(END);
900 if (frseq[1] == frame) { /* pfilt only */
901 frseq[0] = frseq[1];
902 usepinterp = 0; /* update what's needed */
903 usepfilt |= nora_rgbe;
904 } else if (frseq[0] == frame) { /* no interpolation needed */
905 if (!rvr && frame > 1+vint(INTERP)) { /* archive previous */
906 *arcnext++ = ' ';
907 sprintf(arcnext, fbase, frame-vint(INTERP)-1);
908 while (*arcnext) arcnext++;
909 strcpy(arcnext, ".unf");
910 arcnext += 4;
911 if (usepinterp || vint(INTERP)) { /* and Z-buf */
912 *arcnext++ = ' ';
913 sprintf(arcnext, fbase, frame-vint(INTERP)-1);
914 while (*arcnext) arcnext++;
915 strcpy(arcnext, ".zbf");
916 arcnext += 4;
917 }
918 }
919 if (!usepinterp) /* update what's needed */
920 usepfilt |= nora_rgbe;
921 } else /* interpolation needed */
922 usepinterp++;
923 if (frseq[1] >= astat.rnext) /* next batch unavailable */
924 frseq[1] = frseq[0];
925 sprintf(fnbefore, vval(BASENAME), frseq[0]);
926 sprintf(fnafter, vval(BASENAME), frseq[1]);
927 if (rvr == 1 && recover(frseq[0])) /* recover before frame? */
928 return(1);
929 /* generate command */
930 if (usepinterp) { /* using pinterp */
931 if (rvr == 2 && recover(frseq[1])) /* recover after? */
932 return(1);
933 if (nblur > 1) { /* with pmblur */
934 sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
935 'a'+(iter%26));
936 sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
937 'a'+(iter%26));
938 if (!noaction) {
939 FILE *fp; /* motion blurring */
940 if ((fp = fopen(fname0, "w")) == NULL) {
941 perror(fname0); quit(1);
942 }
943 fputs(VIEWSTR, fp);
944 fprintview(vp, fp);
945 putc('\n', fp); fclose(fp);
946 if ((vp = getview(frame+1)) == NULL) {
947 fprintf(stderr,
948 "%s: unexpected error reading view for frame %d\n",
949 progname, frame+1);
950 quit(1);
951 }
952 if ((fp = fopen(fname1, "w")) == NULL) {
953 perror(fname1); quit(1);
954 }
955 fputs(VIEWSTR, fp);
956 fprintview(vp, fp);
957 putc('\n', fp); fclose(fp);
958 }
959 sprintf(combuf,
960 "(pmblur %.3f %d %s %s; rm -f %s %s) | pinterp -B -a",
961 blurf, nblur,
962 fname0, fname1, fname0, fname1);
963 iter++;
964 } else /* no blurring */
965 strcpy(combuf, "pinterp");
966 strcat(combuf, viewopt(vp));
967 if (vbool(RTRACE))
968 sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'",
969 rendopt+1, vval(OCTREE));
970 if (vdef(PINTERP))
971 sprintf(combuf+strlen(combuf), " %s", vval(PINTERP));
972 if (usepfilt)
973 sprintf(combuf+strlen(combuf), " %s", rresopt);
974 else
975 sprintf(combuf+strlen(combuf), " -a %s -e %s",
976 fresopt, ep);
977 sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
978 fnbefore, fnbefore);
979 if (frseq[1] != frseq[0])
980 sprintf(combuf+strlen(combuf), " %s.unf %s.zbf",
981 fnafter, fnafter);
982 if (usepfilt) { /* also pfilt */
983 if (vdef(PFILT))
984 sprintf(combuf+strlen(combuf), " | pfilt %s",
985 vval(PFILT));
986 else
987 strcat(combuf, " | pfilt");
988 if (ep != NULL)
989 sprintf(combuf+strlen(combuf), " -1 -e %s %s",
990 ep, fresopt);
991 else
992 sprintf(combuf+strlen(combuf), " %s", fresopt);
993 }
994 } else if (usepfilt) { /* pfilt only */
995 if (rvr == 2)
996 return(1);
997 if (vdef(PFILT))
998 sprintf(combuf, "pfilt %s", vval(PFILT));
999 else
1000 strcpy(combuf, "pfilt");
1001 if (ep != NULL)
1002 sprintf(combuf+strlen(combuf), " -1 -e %s %s %s.unf",
1003 ep, fresopt, fnbefore);
1004 else
1005 sprintf(combuf+strlen(combuf), " %s %s.unf",
1006 fresopt, fnbefore);
1007 } else { /* else just check it */
1008 if (rvr == 2)
1009 return(1);
1010 sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore);
1011 }
1012 /* output file name */
1013 sprintf(fname0, vval(BASENAME), frame);
1014 sprintf(combuf+strlen(combuf), " > %s.pic", fname0);
1015 if (rvr) /* in recovery */
1016 return(runcom(combuf));
1017 bruncom(combuf, frame, frecover); /* else run in background */
1018 return(0);
1019 }
1020
1021
1022 VIEW *
1023 getview(n) /* get view number n */
1024 int n;
1025 {
1026 static FILE *viewfp = NULL; /* view file pointer */
1027 static int viewnum = 0; /* current view number */
1028 static VIEW curview = STDVIEW; /* current view */
1029 char linebuf[256];
1030
1031 if (n == 0) { /* signal to close file and clean up */
1032 if (viewfp != NULL) {
1033 fclose(viewfp);
1034 viewfp = NULL;
1035 viewnum = 0;
1036 copystruct(&curview, &stdview);
1037 }
1038 return(NULL);
1039 }
1040 if (viewfp == NULL) { /* open file */
1041 if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) {
1042 perror(vval(VIEWFILE));
1043 quit(1);
1044 }
1045 } else if (n > 0 && n < viewnum) { /* rewind file */
1046 if (viewnum == 1 && feof(viewfp))
1047 return(&curview); /* just one view */
1048 if (fseek(viewfp, 0L, 0) == EOF) {
1049 perror(vval(VIEWFILE));
1050 quit(1);
1051 }
1052 copystruct(&curview, &stdview);
1053 viewnum = 0;
1054 }
1055 if (n < 0) { /* get next view */
1056 register int c = getc(viewfp);
1057 if (c == EOF)
1058 return((VIEW *)NULL); /* that's it */
1059 ungetc(c, viewfp);
1060 n = viewnum + 1;
1061 }
1062 while (n > viewnum) { /* scan to desired view */
1063 if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
1064 return(viewnum==1 ? &curview : (VIEW *)NULL);
1065 if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
1066 viewnum++;
1067 }
1068 return(&curview); /* return it */
1069 }
1070
1071
1072 int
1073 countviews() /* count views in view file */
1074 {
1075 int n;
1076
1077 if (getview(n=1) == NULL)
1078 return(0);
1079 while (getview(-1) != NULL)
1080 n++;
1081 return(n);
1082 }
1083
1084
1085 char *
1086 getexp(n) /* get exposure for nth frame */
1087 int n;
1088 {
1089 extern char *fskip();
1090 static char expval[32];
1091 static FILE *expfp = NULL;
1092 static long *exppos;
1093 static int curfrm;
1094 register char *cp;
1095
1096 if (n == 0) { /* signal to close file */
1097 if (expfp != NULL) {
1098 fclose(expfp);
1099 free((void *)exppos);
1100 expfp = NULL;
1101 }
1102 return(NULL);
1103 } else if (n > vint(END)) /* request past end (error?) */
1104 return(NULL);
1105 if (!vdef(EXPOSURE)) /* no setting (auto) */
1106 return(NULL);
1107 if (isflt(vval(EXPOSURE))) /* always the same */
1108 return(vval(EXPOSURE));
1109 if (expfp == NULL) { /* open exposure file */
1110 if ((expfp = fopen(vval(EXPOSURE), "r")) == NULL) {
1111 fprintf(stderr,
1112 "%s: cannot open exposure file \"%s\"\n",
1113 progname, vval(EXPOSURE));
1114 quit(1);
1115 }
1116 curfrm = vint(END) + 1; /* init lookup tab. */
1117 exppos = (long *)malloc(curfrm*sizeof(long *));
1118 if (exppos == NULL) {
1119 perror(progname);
1120 quit(1);
1121 }
1122 while (curfrm--)
1123 exppos[curfrm] = -1L;
1124 curfrm = 0;
1125 }
1126 /* find position in file */
1127 if (n-1 != curfrm && n != curfrm && exppos[n-1] >= 0 &&
1128 fseek(expfp, exppos[curfrm=n-1], 0) == EOF) {
1129 fprintf(stderr, "%s: seek error on exposure file\n", progname);
1130 quit(1);
1131 }
1132 while (n > curfrm) { /* read exposure */
1133 if (exppos[curfrm] < 0)
1134 exppos[curfrm] = ftell(expfp);
1135 if (fgets(expval, sizeof(expval), expfp) == NULL) {
1136 fprintf(stderr, "%s: too few exposures\n",
1137 vval(EXPOSURE));
1138 quit(1);
1139 }
1140 curfrm++;
1141 cp = fskip(expval); /* check format */
1142 if (cp != NULL)
1143 while (isspace(*cp))
1144 *cp++ = '\0';
1145 if (cp == NULL || *cp) {
1146 fprintf(stderr,
1147 "%s: exposure format error on line %d\n",
1148 vval(EXPOSURE), curfrm);
1149 quit(1);
1150 }
1151 }
1152 return(expval); /* return value */
1153 }
1154
1155
1156 struct pslot *
1157 findpslot(pid) /* find or allocate a process slot */
1158 int pid;
1159 {
1160 register struct pslot *psempty = NULL;
1161 register int i;
1162
1163 for (i = 0; i < npslots; i++) { /* look for match */
1164 if (pslot[i].pid == pid)
1165 return(pslot+i);
1166 if (psempty == NULL && pslot[i].pid == 0)
1167 psempty = pslot+i;
1168 }
1169 return(psempty); /* return emtpy slot (error if NULL) */
1170 }
1171
1172
1173 int
1174 donecom(ps, pn, status) /* clean up after finished process */
1175 PSERVER *ps;
1176 int pn;
1177 int status;
1178 {
1179 register PROC *pp;
1180 register struct pslot *psl;
1181
1182 pp = ps->proc + pn;
1183 if (pp->elen) { /* pass errors */
1184 if (ps->hostname[0])
1185 fprintf(stderr, "%s: ", ps->hostname);
1186 fprintf(stderr, "Error output from: %s\n", pp->com);
1187 fputs(pp->errs, stderr);
1188 fflush(stderr);
1189 if (ps->hostname[0])
1190 status = 1; /* because rsh doesn't return status */
1191 }
1192 lastpserver = NULL;
1193 psl = findpslot(pp->pid); /* check for bruncom() slot */
1194 if (psl->pid) {
1195 if (status) {
1196 if (psl->rcvf != NULL) /* attempt recovery */
1197 status = (*psl->rcvf)(psl->fout);
1198 if (status) {
1199 fprintf(stderr,
1200 "%s: error rendering frame %d\n",
1201 progname, psl->fout);
1202 quit(1);
1203 }
1204 lastpserver = ps;
1205 }
1206 psl->pid = 0; /* free process slot */
1207 } else if (status)
1208 lastpserver = ps;
1209 freestr(pp->com); /* free command string */
1210 return(status);
1211 }
1212
1213
1214 int
1215 serverdown() /* check status of last process server */
1216 {
1217 if (lastpserver == NULL || !lastpserver->hostname[0])
1218 return(0);
1219 if (pserverOK(lastpserver)) /* server still up? */
1220 return(0);
1221 delpserver(lastpserver); /* else delete it */
1222 if (pslist == NULL) {
1223 fprintf(stderr, "%s: all process servers are down\n",
1224 progname);
1225 quit(1);
1226 }
1227 return(1);
1228 }
1229
1230
1231 int
1232 bruncom(com, fout, rf) /* run a command in the background */
1233 char *com;
1234 int fout;
1235 int (*rf)();
1236 {
1237 int pid;
1238 register struct pslot *psl;
1239
1240 if (noaction) {
1241 if (!silent)
1242 printf("\t%s\n", com); /* echo command */
1243 return(0);
1244 }
1245 com = savestr(com); /* else start it when we can */
1246 while ((pid = startjob(NULL, com, donecom)) == -1)
1247 bwait(1);
1248 if (!silent) { /* echo command */
1249 PSERVER *ps;
1250 int psn = pid;
1251 ps = findjob(&psn);
1252 printf("\t%s\n", com);
1253 printf("\tProcess started on %s\n", phostname(ps));
1254 fflush(stdout);
1255 }
1256 psl = findpslot(pid); /* record info. in appropriate slot */
1257 psl->pid = pid;
1258 psl->fout = fout;
1259 psl->rcvf = rf;
1260 return(pid);
1261 }
1262
1263
1264 bwait(ncoms) /* wait for batch job(s) to finish */
1265 int ncoms;
1266 {
1267 int status;
1268
1269 if (noaction)
1270 return;
1271 while ((status = wait4job(NULL, -1)) != -1) {
1272 serverdown(); /* update server status */
1273 if (--ncoms == 0)
1274 break; /* done enough */
1275 }
1276 }
1277
1278
1279 int
1280 pruncom(com, ppins, maxcopies) /* run a command in parallel over network */
1281 char *com, *ppins;
1282 int maxcopies;
1283 {
1284 int retstatus = 0;
1285 int hostcopies;
1286 char buf[10240], *com1, *s;
1287 int status;
1288 int pfd;
1289 register int n;
1290 register PSERVER *ps;
1291
1292 if (!silent)
1293 printf("\t%s\n", com); /* echo command */
1294 if (noaction)
1295 return(0);
1296 fflush(stdout);
1297 /* start jobs on each server */
1298 for (ps = pslist; ps != NULL; ps = ps->next) {
1299 hostcopies = 0;
1300 if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1301 strcpy(com1=buf, com); /* build -PP command */
1302 sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1303 vval(DIRECTORY), phostname(ps));
1304 unlink(com1+(ppins-com)+5);
1305 strcat(com1, ppins);
1306 } else
1307 com1 = com;
1308 while (maxcopies > 0) {
1309 s = savestr(com1);
1310 if (startjob(ps, s, donecom) != -1) {
1311 sleep(20);
1312 hostcopies++;
1313 maxcopies--;
1314 } else {
1315 freestr(s);
1316 break;
1317 }
1318 }
1319 if (!silent && hostcopies) {
1320 if (hostcopies > 1)
1321 printf("\t%d duplicate processes", hostcopies);
1322 else
1323 printf("\tProcess");
1324 printf(" started on %s\n", phostname(ps));
1325 fflush(stdout);
1326 }
1327 }
1328 /* wait for jobs to finish */
1329 while ((status = wait4job(NULL, -1)) != -1)
1330 retstatus += status && !serverdown();
1331 /* terminate parallel rpict's */
1332 for (ps = pslist; ps != NULL; ps = ps->next) {
1333 sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps));
1334 if ((pfd = open(buf, O_RDONLY)) >= 0) {
1335 n = read(pfd, buf, sizeof(buf)-1); /* get PID */
1336 buf[n] = '\0';
1337 close(pfd);
1338 for (n = 0; buf[n] && !isspace(buf[n]); n++)
1339 ;
1340 /* terminate */
1341 sprintf(buf, "kill -ALRM %d", atoi(buf+n));
1342 wait4job(ps, startjob(ps, buf, NULL));
1343 }
1344 }
1345 return(retstatus);
1346 }
1347
1348
1349 runcom(cs) /* run a command locally and wait for it */
1350 char *cs;
1351 {
1352 if (!silent) /* echo it */
1353 printf("\t%s\n", cs);
1354 if (noaction)
1355 return(0);
1356 fflush(stdout); /* flush output and pass to shell */
1357 return(system(cs));
1358 }
1359
1360
1361 rmfile(fn) /* remove a file */
1362 char *fn;
1363 {
1364 if (!silent)
1365 #ifdef _WIN32
1366 printf("\tdel %s\n", fn);
1367 #else
1368 printf("\trm -f %s\n", fn);
1369 #endif
1370 if (noaction)
1371 return(0);
1372 return(unlink(fn));
1373 }
1374
1375
1376 badvalue(vc) /* report bad variable value and exit */
1377 int vc;
1378 {
1379 fprintf(stderr, "%s: bad value for variable '%s'\n",
1380 progname, vnam(vc));
1381 quit(1);
1382 }
1383
1384
1385 char *
1386 dirfile(df, path) /* separate path into directory and file */
1387 char *df;
1388 register char *path;
1389 {
1390 register int i;
1391 int psep;
1392
1393 for (i = 0, psep = -1; path[i]; i++)
1394 if (path[i] == '/')
1395 psep = i;
1396 if (df != NULL)
1397 if (psep == 0) {
1398 df[0] = '/';
1399 df[1] = '\0';
1400 } else if (psep > 0) {
1401 strncpy(df, path, psep);
1402 df[psep] = '\0';
1403 } else
1404 df[0] = '\0';
1405 return(path+psep+1);
1406 }
1407
1408
1409 int
1410 getblur(double *bf) /* get # blur samples (and fraction) */
1411 {
1412 double blurf;
1413 int nblur;
1414 char *s;
1415
1416 if (!vdef(MBLUR)) {
1417 if (bf != NULL)
1418 *bf = 0.0;
1419 return(0);
1420 }
1421 blurf = atof(vval(MBLUR));
1422 if (blurf < 0.0)
1423 blurf = 0.0;
1424 if (bf != NULL)
1425 *bf = blurf;
1426 if (blurf <= FTINY)
1427 return(0);
1428 s = sskip(vval(MBLUR));
1429 if (!*s)
1430 return(DEF_NBLUR);
1431 nblur = atoi(s);
1432 if (nblur <= 0)
1433 return(1);
1434 return(nblur);
1435 }