1 |
< |
/* Copyright (c) 1987 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
22 |
|
|
23 |
|
#define CTRL(c) ('c'-'@') |
24 |
|
|
25 |
+ |
extern char VersionID[]; |
26 |
|
extern char *progname; |
27 |
+ |
extern char *octname; |
28 |
|
|
29 |
|
|
30 |
|
getframe(s) /* get a new frame */ |
308 |
|
int typ; |
309 |
|
register union {int i; double d; COLOR C;} *ptr; |
310 |
|
{ |
311 |
+ |
extern char *index(); |
312 |
|
int i0; |
313 |
|
double d0, d1, d2; |
314 |
|
char buf[48]; |
321 |
|
(*dev->comout)(buf); |
322 |
|
(*dev->comin)(buf, NULL); |
323 |
|
if (sscanf(buf, "%d", &i0) != 1) |
324 |
< |
break; |
324 |
> |
return(0); |
325 |
|
} |
326 |
|
ptr->i = i0; |
327 |
< |
break; |
327 |
> |
return(1); |
328 |
|
case 'r': /* real */ |
329 |
|
if (sscanf(str, "%lf", &d0) != 1) { |
330 |
|
(*dev->comout)(dsc); |
332 |
|
(*dev->comout)(buf); |
333 |
|
(*dev->comin)(buf, NULL); |
334 |
|
if (sscanf(buf, "%lf", &d0) != 1) |
335 |
< |
break; |
335 |
> |
return(0); |
336 |
|
} |
337 |
|
ptr->d = d0; |
338 |
< |
break; |
338 |
> |
return(1); |
339 |
|
case 'b': /* boolean */ |
340 |
|
if (sscanf(str, "%1s", buf) != 1) { |
341 |
|
(*dev->comout)(dsc); |
342 |
|
sprintf(buf, " (%c): ", ptr->i ? 'y' : 'n'); |
343 |
|
(*dev->comout)(buf); |
344 |
|
(*dev->comin)(buf, NULL); |
345 |
+ |
if (buf[0] == '\0' || |
346 |
+ |
index("yY+1tTnN-0fF", buf[0]) == NULL) |
347 |
+ |
return(0); |
348 |
|
} |
349 |
< |
ptr->i = tolower(buf[0]) == 'y'; |
350 |
< |
break; |
349 |
> |
ptr->i = index("yY+1tT", buf[0]) != NULL; |
350 |
> |
return(1); |
351 |
|
case 'C': /* color */ |
352 |
|
if (sscanf(str, "%lf %lf %lf", &d0, &d1, &d2) != 3) { |
353 |
|
(*dev->comout)(dsc); |
358 |
|
(*dev->comout)(buf); |
359 |
|
(*dev->comin)(buf, NULL); |
360 |
|
if (sscanf(buf, "%lf %lf %lf", &d0, &d1, &d2) != 3) |
361 |
< |
break; |
361 |
> |
return(0); |
362 |
|
} |
363 |
|
setcolor(ptr->C, d0, d1, d2); |
364 |
< |
break; |
364 |
> |
return(1); |
365 |
|
} |
366 |
|
} |
367 |
|
|
384 |
|
extern int ambssamp; |
385 |
|
extern int ambounce; |
386 |
|
extern int directinvis; |
387 |
+ |
extern double srcsizerat; |
388 |
|
extern int do_irrad; |
389 |
|
char buf[128]; |
390 |
|
|
391 |
|
if (s[0] == '\0') { |
392 |
|
(*dev->comout)( |
393 |
< |
"aa ab ad ar as av b dc di dj dt i lr lw sp st: "); |
393 |
> |
"aa ab ad ar as av b dc di dj ds dt i lr lw sp st: "); |
394 |
|
(*dev->comin)(buf, NULL); |
395 |
|
s = buf; |
396 |
|
} |
422 |
|
getparam(s+2, "direct invisibility", |
423 |
|
'b', &directinvis); |
424 |
|
break; |
425 |
+ |
case 's': /* sampling */ |
426 |
+ |
getparam(s+2, "direct sampling", 'r', &srcsizerat); |
427 |
+ |
break; |
428 |
|
default: |
429 |
|
goto badparam; |
430 |
|
} |
453 |
|
getparam(s+2, "ambient bounces", 'i', &ambounce); |
454 |
|
break; |
455 |
|
case 'r': |
456 |
< |
getparam(s+2, "ambient resolution", 'i', &ambres); |
457 |
< |
minarad = ambres > 0 ? thescene.cusize/ambres : 0.0; |
456 |
> |
if (getparam(s+2, "ambient resolution", 'i', &ambres)) |
457 |
> |
minarad = ambres > 0 ? |
458 |
> |
thescene.cusize/ambres : 0.0; |
459 |
|
break; |
460 |
|
default: |
461 |
|
goto badparam; |
464 |
|
case 's': /* sample */ |
465 |
|
switch (s[1]) { |
466 |
|
case 'p': /* pixel */ |
467 |
< |
getparam(s+2, "sample pixel", 'i', &psample); |
468 |
< |
pdepth = 0; |
467 |
> |
if (getparam(s+2, "sample pixel", 'i', &psample)) |
468 |
> |
pdepth = 0; |
469 |
|
break; |
470 |
|
case 't': /* threshold */ |
471 |
< |
getparam(s+2, "sample threshold", 'r', &maxdiff); |
472 |
< |
pdepth = 0; |
471 |
> |
if (getparam(s+2, "sample threshold", 'r', &maxdiff)) |
472 |
> |
pdepth = 0; |
473 |
|
break; |
474 |
|
default: |
475 |
|
goto badparam; |
479 |
|
break; |
480 |
|
default:; |
481 |
|
badparam: |
482 |
+ |
*sskip(s) = '\0'; |
483 |
|
sprintf(errmsg, "%s: unknown variable", s); |
484 |
|
error(COMMAND, errmsg); |
485 |
|
break; |
571 |
|
/* write header */ |
572 |
|
fputs(progname, fp); |
573 |
|
fprintview(&ourview, fp); |
574 |
< |
putc('\n', fp); |
574 |
> |
if (octname != NULL) |
575 |
> |
fprintf(fp, " %s\n", octname); |
576 |
> |
else |
577 |
> |
putc('\n', fp); |
578 |
> |
fprintf(fp, "SOFTWARE= %s\n", VersionID); |
579 |
|
if (exposure != 1.0) |
580 |
|
fputexpos(exposure, fp); |
581 |
|
if (dev->pixaspect != 1.0) |
585 |
|
fputresolu(YMAJOR|YDECR, hresolu, vresolu, fp); |
586 |
|
|
587 |
|
scanline = (COLR *)malloc(hresolu*sizeof(COLR)); |
588 |
< |
if (scanline == NULL) |
589 |
< |
error(SYSTEM, "out of memory in writepict"); |
588 |
> |
if (scanline == NULL) { |
589 |
> |
error(COMMAND, "not enough memory!"); |
590 |
> |
fclose(fp); |
591 |
> |
unlink(fname); |
592 |
> |
return; |
593 |
> |
} |
594 |
|
for (y = vresolu-1; y >= 0; y--) { |
595 |
|
getpictcolrs(y, scanline, &ptrunk, hresolu, vresolu); |
596 |
|
if (fwritecolrs(scanline, hresolu, fp) < 0) |
597 |
|
break; |
598 |
|
} |
599 |
+ |
free((char *)scanline); |
600 |
|
if (fclose(fp) < 0) |
601 |
|
error(COMMAND, "write error"); |
581 |
– |
free((char *)scanline); |
602 |
|
} |