116 |
|
fputs("NCOMP=3\n", fout); /* always RGB */ |
117 |
|
if (info != NULL) /* add extra info if given */ |
118 |
|
fputs(info, fout); |
119 |
+ |
if ((outfmt == 'f') | (outfmt == 'd')) |
120 |
+ |
fputendian(fout); |
121 |
|
fputformat(formstr(outfmt), fout); |
122 |
|
fputc('\n', fout); /* empty line ends header */ |
123 |
|
} |
143 |
|
LUENT *lep; |
144 |
|
STREAMOUT *sop; |
145 |
|
char *cp; |
146 |
< |
|
146 |
> |
|
147 |
> |
info[0] = '\0'; |
148 |
|
if (ospec == NULL) { /* use stdout? */ |
149 |
|
if (!noopen & !using_stdout) { |
150 |
|
if (outfmt != 'a') |
151 |
|
SET_FILE_BINARY(stdout); |
152 |
+ |
#ifdef getc_unlocked |
153 |
+ |
flockfile(stdout); /* avoid lock/unlock overhead */ |
154 |
+ |
#endif |
155 |
|
if (header) { |
156 |
|
cp = info; |
157 |
|
if (yres > 0) { |
168 |
|
if (waitflush > 0) |
169 |
|
fflush(stdout); |
170 |
|
stdos.xr = xres; stdos.yr = yres; |
165 |
– |
#ifdef getc_unlocked |
166 |
– |
flockfile(stdout); /* avoid lock/unlock overhead */ |
167 |
– |
#endif |
171 |
|
using_stdout = 1; |
172 |
|
} |
173 |
|
stdos.ofp = stdout; |
187 |
|
sop = (STREAMOUT *)malloc(sizeof(STREAMOUT)); |
188 |
|
if (sop == NULL) |
189 |
|
error(SYSTEM, "out of memory in getostream"); |
190 |
< |
sop->outpipe = oname[0] == '!'; |
190 |
> |
sop->outpipe = (oname[0] == '!'); |
191 |
|
sop->reclen = 0; |
192 |
|
sop->ofp = NULL; /* open iff noopen==0 */ |
193 |
|
sop->xr = xres; sop->yr = yres; |
197 |
|
errno = EEXIST; /* file exists */ |
198 |
|
goto openerr; |
199 |
|
} |
200 |
+ |
} else if (noopen && outfmt == 'c' && /* stream exists to picture? */ |
201 |
+ |
(sop->xr > 0) & (sop->yr > 0)) { |
202 |
+ |
if (ofl & OF_BIN) |
203 |
+ |
return(NULL); /* let caller offset bins */ |
204 |
+ |
sprintf(errmsg, "output '%s' not a valid picture", oname); |
205 |
+ |
error(WARNING, errmsg); |
206 |
|
} |
207 |
|
if (!noopen && sop->ofp == NULL) { /* open output stream */ |
208 |
|
if (oname[0] == '!') /* output to command */ |
340 |
|
void |
341 |
|
mod_output(MODCONT *mp) |
342 |
|
{ |
343 |
< |
STREAMOUT *sop = getostream(mp->outspec, mp->modname, 0, 0); |
343 |
> |
STREAMOUT *sop = getostream(mp->outspec, mp->modname, mp->bin0, 0); |
344 |
|
int j; |
345 |
|
|
346 |
|
put_contrib(mp->cbin[0], sop->ofp); |
347 |
|
if (mp->nbins > 3 && /* minor optimization */ |
348 |
< |
sop == getostream(mp->outspec, mp->modname, 1, 0)) { |
348 |
> |
sop == getostream(mp->outspec, mp->modname, mp->bin0+1, 0)) { |
349 |
|
for (j = 1; j < mp->nbins; j++) |
350 |
|
put_contrib(mp->cbin[j], sop->ofp); |
351 |
|
} else { |
352 |
|
for (j = 1; j < mp->nbins; j++) { |
353 |
< |
sop = getostream(mp->outspec, mp->modname, j, 0); |
353 |
> |
sop = getostream(mp->outspec, mp->modname, mp->bin0+j, 0); |
354 |
|
put_contrib(mp->cbin[j], sop->ofp); |
355 |
|
} |
356 |
|
} |
448 |
|
char *outvfmt; |
449 |
|
LUENT *oent; |
450 |
|
int xr, yr; |
451 |
< |
STREAMOUT sout; |
451 |
> |
STREAMOUT *sop; |
452 |
|
DCOLOR rgbv; |
453 |
|
|
454 |
|
if (outfmt == 'a') |
461 |
|
error(USER, "cannot reload from stdout"); |
462 |
|
if (mp->outspec[0] == '!') |
463 |
|
error(USER, "cannot reload from command"); |
464 |
< |
for (j = 0; ; j++) { /* load each modifier bin */ |
465 |
< |
ofl = ofname(oname, mp->outspec, mp->modname, j); |
464 |
> |
for (j = 0; j < mp->nbins; j++) { /* load each modifier bin */ |
465 |
> |
ofl = ofname(oname, mp->outspec, mp->modname, mp->bin0+j); |
466 |
|
if (ofl < 0) |
467 |
|
error(USER, "bad output file specification"); |
468 |
|
oent = lu_find(&ofiletab, oname); |
469 |
< |
if (oent->data != NULL) { |
470 |
< |
sout = *(STREAMOUT *)oent->data; |
471 |
< |
} else { |
472 |
< |
sout.reclen = 0; |
473 |
< |
sout.outpipe = 0; |
474 |
< |
sout.xr = xres; sout.yr = yres; |
466 |
< |
sout.ofp = NULL; |
467 |
< |
} |
468 |
< |
if (sout.ofp == NULL) { /* open output as input */ |
469 |
< |
sout.ofp = fopen(oname, fmode); |
470 |
< |
if (sout.ofp == NULL) { |
471 |
< |
if (j == mp->nbins) |
472 |
< |
break; /* assume end of modifier */ |
469 |
> |
if (oent->data == NULL) |
470 |
> |
error(INTERNAL, "unallocated stream in reload_output()"); |
471 |
> |
sop = (STREAMOUT *)oent->data; |
472 |
> |
if (sop->ofp == NULL) { /* open output as input */ |
473 |
> |
sop->ofp = fopen(oname, fmode); |
474 |
> |
if (sop->ofp == NULL) { |
475 |
|
sprintf(errmsg, "missing reload file '%s'", |
476 |
|
oname); |
477 |
|
error(WARNING, errmsg); |
478 |
|
break; |
479 |
|
} |
480 |
|
#ifdef getc_unlocked |
481 |
< |
flockfile(sout.ofp); |
481 |
> |
flockfile(sop->ofp); |
482 |
|
#endif |
483 |
< |
if (header && checkheader(sout.ofp, outvfmt, NULL) != 1) { |
483 |
> |
if (header && checkheader(sop->ofp, outvfmt, NULL) != 1) { |
484 |
|
sprintf(errmsg, "format mismatch for '%s'", |
485 |
|
oname); |
486 |
|
error(USER, errmsg); |
487 |
|
} |
488 |
< |
if ((sout.reclen == 1) & (sout.xr > 0) & (sout.yr > 0) && |
489 |
< |
(!fscnresolu(&xr, &yr, sout.ofp) || |
490 |
< |
(xr != sout.xr) | |
491 |
< |
(yr != sout.yr))) { |
488 |
> |
if ((sop->reclen == 1) & (sop->xr > 0) & (sop->yr > 0) && |
489 |
> |
(!fscnresolu(&xr, &yr, sop->ofp) || |
490 |
> |
(xr != sop->xr) | |
491 |
> |
(yr != sop->yr))) { |
492 |
|
sprintf(errmsg, "resolution mismatch for '%s'", |
493 |
|
oname); |
494 |
|
error(USER, errmsg); |
495 |
|
} |
496 |
|
} |
497 |
|
/* read in RGB value */ |
498 |
< |
if (!get_contrib(rgbv, sout.ofp)) { |
498 |
> |
if (!get_contrib(rgbv, sop->ofp)) { |
499 |
|
if (!j) { |
500 |
< |
fclose(sout.ofp); |
500 |
> |
fclose(sop->ofp); |
501 |
|
break; /* ignore empty file */ |
502 |
|
} |
503 |
|
if (j < mp->nbins) { |
506 |
|
error(USER, errmsg); |
507 |
|
} |
508 |
|
break; |
509 |
< |
} |
508 |
< |
if (j >= mp->nbins) { /* check modifier size */ |
509 |
< |
sprintf(errmsg, |
510 |
< |
"mismatched -bn setting for reloading '%s'", |
511 |
< |
modname[i]); |
512 |
< |
error(USER, errmsg); |
513 |
< |
} |
514 |
< |
|
509 |
> |
} |
510 |
|
copycolor(mp->cbin[j], rgbv); |
516 |
– |
if (oent->key == NULL) /* new file entry */ |
517 |
– |
oent->key = strcpy((char *) |
518 |
– |
malloc(strlen(oname)+1), oname); |
519 |
– |
if (oent->data == NULL) |
520 |
– |
oent->data = (char *)malloc(sizeof(STREAMOUT)); |
521 |
– |
*(STREAMOUT *)oent->data = sout; |
511 |
|
} |
512 |
|
} |
513 |
|
lu_doall(&ofiletab, &myclose, NULL); /* close all files */ |
522 |
|
off_t nbytes = *(off_t *)p; |
523 |
|
|
524 |
|
if (sop->reclen > 1) |
525 |
< |
nbytes = nbytes * sop->reclen; |
525 |
> |
nbytes *= (off_t)sop->reclen; |
526 |
|
if (fseeko(sop->ofp, nbytes, SEEK_CUR) < 0) { |
527 |
|
sprintf(errmsg, "seek error on file '%s'", e->key); |
528 |
|
error(SYSTEM, errmsg); |
543 |
|
int ofl; |
544 |
|
char oname[1024]; |
545 |
|
LUENT *oent; |
546 |
< |
STREAMOUT sout; |
546 |
> |
STREAMOUT *sop; |
547 |
|
off_t nvals; |
548 |
|
int xr, yr; |
549 |
|
|
572 |
|
error(USER, "cannot recover from stdout"); |
573 |
|
if (mp->outspec[0] == '!') |
574 |
|
error(USER, "cannot recover from command"); |
575 |
< |
for (j = 0; ; j++) { /* check each bin's file */ |
576 |
< |
ofl = ofname(oname, mp->outspec, mp->modname, j); |
575 |
> |
for (j = 0; j < mp->nbins; j++) { /* check each bin's file */ |
576 |
> |
ofl = ofname(oname, mp->outspec, mp->modname, mp->bin0+j); |
577 |
|
if (ofl < 0) |
578 |
|
error(USER, "bad output file specification"); |
579 |
|
oent = lu_find(&ofiletab, oname); |
580 |
< |
if (oent->data != NULL) { |
581 |
< |
sout = *(STREAMOUT *)oent->data; |
582 |
< |
} else { |
583 |
< |
sout.reclen = 0; |
595 |
< |
sout.outpipe = 0; |
596 |
< |
sout.xr = xres; |
597 |
< |
sout.yr = yres; |
598 |
< |
sout.ofp = NULL; |
599 |
< |
} |
600 |
< |
if (sout.ofp != NULL) { /* already open? */ |
580 |
> |
if (oent->data == NULL) |
581 |
> |
error(INTERNAL, "unallocated stream in recover_output()"); |
582 |
> |
sop = (STREAMOUT *)oent->data; |
583 |
> |
if (sop->ofp != NULL) { /* already open? */ |
584 |
|
if (ofl & OF_BIN) |
585 |
|
continue; |
586 |
|
break; |
587 |
|
} |
588 |
|
/* open output */ |
589 |
< |
sout.ofp = fopen(oname, "rb+"); |
590 |
< |
if (sout.ofp == NULL) { |
608 |
< |
if (j == mp->nbins) |
609 |
< |
break; /* assume end of modifier */ |
589 |
> |
sop->ofp = fopen(oname, "rb+"); |
590 |
> |
if (sop->ofp == NULL) { |
591 |
|
sprintf(errmsg, "missing recover file '%s'", |
592 |
|
oname); |
593 |
|
error(WARNING, errmsg); |
594 |
+ |
lastout = 0; |
595 |
|
break; |
596 |
|
} |
597 |
< |
nvals = lseek(fileno(sout.ofp), 0, SEEK_END); |
597 |
> |
nvals = lseek(fileno(sop->ofp), 0, SEEK_END); |
598 |
|
if (nvals <= 0) { |
599 |
|
lastout = 0; /* empty output, quit here */ |
600 |
< |
fclose(sout.ofp); |
600 |
> |
fclose(sop->ofp); |
601 |
|
break; |
602 |
|
} |
603 |
< |
if (!sout.reclen) { |
622 |
< |
if (!(ofl & OF_BIN)) { |
623 |
< |
sprintf(errmsg, |
624 |
< |
"need -bn to recover file '%s'", |
625 |
< |
oname); |
626 |
< |
error(USER, errmsg); |
627 |
< |
} |
628 |
< |
recsiz = outvsiz; |
629 |
< |
} else |
630 |
< |
recsiz = outvsiz * sout.reclen; |
603 |
> |
recsiz = outvsiz * sop->reclen; |
604 |
|
|
605 |
< |
lseek(fileno(sout.ofp), 0, SEEK_SET); |
606 |
< |
if (header && checkheader(sout.ofp, outvfmt, NULL) != 1) { |
605 |
> |
lseek(fileno(sop->ofp), 0, SEEK_SET); |
606 |
> |
if (header && checkheader(sop->ofp, outvfmt, NULL) != 1) { |
607 |
|
sprintf(errmsg, "format mismatch for '%s'", |
608 |
|
oname); |
609 |
|
error(USER, errmsg); |
610 |
|
} |
611 |
< |
if ((sout.reclen == 1) & (sout.xr > 0) & (sout.yr > 0) && |
612 |
< |
(!fscnresolu(&xr, &yr, sout.ofp) || |
613 |
< |
(xr != sout.xr) | |
614 |
< |
(yr != sout.yr))) { |
611 |
> |
if ((sop->reclen == 1) & (sop->xr > 0) & (sop->yr > 0) && |
612 |
> |
(!fscnresolu(&xr, &yr, sop->ofp) || |
613 |
> |
(xr != sop->xr) | |
614 |
> |
(yr != sop->yr))) { |
615 |
|
sprintf(errmsg, "resolution mismatch for '%s'", |
616 |
|
oname); |
617 |
|
error(USER, errmsg); |
618 |
|
} |
619 |
< |
nvals = (nvals - (off_t)ftell(sout.ofp)) / recsiz; |
619 |
> |
nvals = (nvals - (off_t)ftell(sop->ofp)) / recsiz; |
620 |
|
if ((lastout < 0) | (nvals < lastout)) |
621 |
|
lastout = nvals; |
649 |
– |
if (oent->key == NULL) /* new entry */ |
650 |
– |
oent->key = strcpy((char *) |
651 |
– |
malloc(strlen(oname)+1), oname); |
652 |
– |
if (oent->data == NULL) |
653 |
– |
oent->data = (char *)malloc(sizeof(STREAMOUT)); |
654 |
– |
*(STREAMOUT *)oent->data = sout; |
622 |
|
if (!(ofl & OF_BIN)) |
623 |
|
break; /* no bin separation */ |
624 |
|
} |
625 |
|
if (!lastout) { /* empty output */ |
626 |
|
error(WARNING, "no previous data to recover"); |
627 |
< |
lu_done(&ofiletab); /* reclose all outputs */ |
627 |
> |
/* reclose all outputs */ |
628 |
> |
lu_doall(&ofiletab, &myclose, NULL); |
629 |
|
return; |
662 |
– |
} |
663 |
– |
if (j > mp->nbins) { /* check modifier size */ |
664 |
– |
sprintf(errmsg, |
665 |
– |
"mismatched -bn setting for recovering '%s'", |
666 |
– |
modname[i]); |
667 |
– |
error(USER, errmsg); |
630 |
|
} |
631 |
|
} |
632 |
|
if (lastout < 0) { |