8 |
|
|
9 |
|
#include "rcontrib.h" |
10 |
|
#include "resolu.h" |
11 |
< |
#include "platform.h" |
11 |
> |
#include <ctype.h> |
12 |
|
|
13 |
+ |
/* Close output stream and free record */ |
14 |
+ |
static void |
15 |
+ |
closestream(void *p) |
16 |
+ |
{ |
17 |
+ |
STREAMOUT *sop = (STREAMOUT *)p; |
18 |
+ |
|
19 |
+ |
if (sop->ofp != NULL) { |
20 |
+ |
int status = 0; |
21 |
+ |
if (sop->outpipe) |
22 |
+ |
status = pclose(sop->ofp); |
23 |
+ |
else if (sop->ofp != stdout) |
24 |
+ |
status = fclose(sop->ofp); |
25 |
+ |
if (status) |
26 |
+ |
error(SYSTEM, "error closing output stream"); |
27 |
+ |
} |
28 |
+ |
free(p); |
29 |
+ |
} |
30 |
+ |
|
31 |
+ |
LUTAB ofiletab = LU_SINIT(free,closestream); /* output file table */ |
32 |
+ |
|
33 |
|
#define OF_MODIFIER 01 |
34 |
|
#define OF_BIN 02 |
35 |
|
|
103 |
|
if (octname[strlen(octname)-1] != '\n') |
104 |
|
fputc('\n', fout); |
105 |
|
} else { |
106 |
< |
FILE *fin = fopen(octname, "r"); |
106 |
> |
FILE *fin = fopen(octname, (outfmt=='a') ? "r" : "rb"); |
107 |
|
if (fin == NULL) |
108 |
|
quit(1); |
109 |
< |
checkheader(fin, "ignore", fout); |
109 |
> |
checkheader(fin, OCTFMT, fout); |
110 |
|
fclose(fin); |
111 |
|
} |
112 |
|
printargs(gargc-1, gargv, fout); /* add our command */ |
113 |
|
fprintf(fout, "SOFTWARE= %s\n", VersionID); |
114 |
|
fputnow(fout); |
115 |
+ |
fputs("NCOMP=3\n", fout); /* always RGB */ |
116 |
|
if (info != NULL) /* add extra info if given */ |
117 |
|
fputs(info, fout); |
118 |
|
fputformat(formstr(outfmt), fout); |
133 |
|
STREAMOUT * |
134 |
|
getostream(const char *ospec, const char *mname, int bn, int noopen) |
135 |
|
{ |
115 |
– |
/* static const DCOLOR nocontrib = BLKCOLOR; */ |
136 |
|
static STREAMOUT stdos; |
137 |
+ |
char info[1024]; |
138 |
|
int ofl; |
139 |
|
char oname[1024]; |
140 |
|
LUENT *lep; |
141 |
|
STREAMOUT *sop; |
142 |
+ |
char *cp; |
143 |
|
|
144 |
|
if (ospec == NULL) { /* use stdout? */ |
145 |
< |
if (!noopen && !using_stdout) { |
145 |
> |
if (!noopen & !using_stdout) { |
146 |
|
if (outfmt != 'a') |
147 |
|
SET_FILE_BINARY(stdout); |
148 |
< |
if (header) |
149 |
< |
printheader(stdout, NULL); |
148 |
> |
if (header) { |
149 |
> |
cp = info; |
150 |
> |
if (yres > 0) { |
151 |
> |
sprintf(cp, "NROWS=%d\n", yres * |
152 |
> |
(xres + !xres) ); |
153 |
> |
while (*cp) ++cp; |
154 |
> |
} |
155 |
> |
sprintf(cp, "NCOLS=%d\n", stdos.reclen); |
156 |
> |
printheader(stdout, info); |
157 |
> |
} |
158 |
|
printresolu(stdout, xres, yres); |
159 |
|
if (waitflush > 0) |
160 |
|
fflush(stdout); |
193 |
|
} |
194 |
|
} |
195 |
|
if (!noopen && sop->ofp == NULL) { /* open output stream */ |
166 |
– |
long i; |
196 |
|
if (oname[0] == '!') /* output to command */ |
197 |
|
sop->ofp = popen(oname+1, "w"); |
198 |
|
else /* else open file */ |
204 |
|
#ifdef getc_unlocked |
205 |
|
flockfile(sop->ofp); /* avoid lock/unlock overhead */ |
206 |
|
#endif |
207 |
+ |
if (accumulate > 0) { /* global resolution */ |
208 |
+ |
sop->xr = xres; sop->yr = yres; |
209 |
+ |
} |
210 |
|
if (header) { |
211 |
< |
char info[512]; |
180 |
< |
char *cp = info; |
211 |
> |
cp = info; |
212 |
|
if (ofl & OF_MODIFIER || sop->reclen == 1) { |
213 |
|
sprintf(cp, "MODIFIER=%s\n", mname); |
214 |
|
while (*cp) ++cp; |
217 |
|
sprintf(cp, "BIN=%d\n", bn); |
218 |
|
while (*cp) ++cp; |
219 |
|
} |
220 |
< |
*cp = '\0'; |
220 |
> |
if (sop->yr > 0) { |
221 |
> |
sprintf(cp, "NROWS=%d\n", sop->yr * |
222 |
> |
(sop->xr + !sop->xr) ); |
223 |
> |
while (*cp) ++cp; |
224 |
> |
} |
225 |
> |
sprintf(cp, "NCOLS=%d\nNCOMP=3\n", sop->reclen); |
226 |
|
printheader(sop->ofp, info); |
227 |
|
} |
192 |
– |
if (accumulate > 0) { /* global resolution */ |
193 |
– |
sop->xr = xres; sop->yr = yres; |
194 |
– |
} |
228 |
|
printresolu(sop->ofp, sop->xr, sop->yr); |
196 |
– |
#if 0 |
197 |
– |
/* play catch-up */ |
198 |
– |
for (i = accumulate > 0 ? lastdone/accumulate : 0; i--; ) { |
199 |
– |
int j = sop->reclen; |
200 |
– |
if (j <= 0) j = 1; |
201 |
– |
while (j--) |
202 |
– |
put_contrib(nocontrib, sop->ofp); |
203 |
– |
if (outfmt == 'a') |
204 |
– |
putc('\n', sop->ofp); |
205 |
– |
} |
206 |
– |
#endif |
229 |
|
if (waitflush > 0) |
230 |
|
fflush(sop->ofp); |
231 |
|
} |
278 |
|
put_contrib(const DCOLOR cnt, FILE *fout) |
279 |
|
{ |
280 |
|
double sf = 1; |
281 |
< |
float fv[3]; |
281 |
> |
COLOR fv; |
282 |
|
COLR cv; |
283 |
|
|
284 |
|
if (accumulate > 1) |
294 |
|
break; |
295 |
|
case 'f': |
296 |
|
if (accumulate > 1) { |
297 |
< |
fv[0] = sf*cnt[0]; fv[1] = sf*cnt[1]; fv[2] = sf*cnt[2]; |
297 |
> |
copycolor(fv, cnt); |
298 |
> |
scalecolor(fv, sf); |
299 |
|
} else |
300 |
|
copycolor(fv, cnt); |
301 |
|
fwrite(fv, sizeof(float), 3, fout); |
302 |
|
break; |
303 |
|
case 'd': |
304 |
|
if (accumulate > 1) { |
305 |
< |
double dv[3]; |
306 |
< |
dv[0] = sf*cnt[0]; dv[1] = sf*cnt[1]; dv[2] = sf*cnt[2]; |
305 |
> |
DCOLOR dv; |
306 |
> |
copycolor(dv, cnt); |
307 |
> |
scalecolor(dv, sf); |
308 |
|
fwrite(dv, sizeof(double), 3, fout); |
309 |
|
} else |
310 |
|
fwrite(cnt, sizeof(double), 3, fout); |
326 |
|
void |
327 |
|
mod_output(MODCONT *mp) |
328 |
|
{ |
329 |
< |
STREAMOUT *sop = getostream(mp->outspec, mp->modname, 0,0); |
329 |
> |
STREAMOUT *sop = getostream(mp->outspec, mp->modname, 0, 0); |
330 |
|
int j; |
331 |
|
|
332 |
|
put_contrib(mp->cbin[0], sop->ofp); |
333 |
|
if (mp->nbins > 3 && /* minor optimization */ |
334 |
< |
sop == getostream(mp->outspec, mp->modname, 1,0)) |
334 |
> |
sop == getostream(mp->outspec, mp->modname, 1, 0)) { |
335 |
|
for (j = 1; j < mp->nbins; j++) |
336 |
|
put_contrib(mp->cbin[j], sop->ofp); |
337 |
< |
else |
337 |
> |
} else { |
338 |
|
for (j = 1; j < mp->nbins; j++) { |
339 |
< |
sop = getostream(mp->outspec, mp->modname,j,0); |
339 |
> |
sop = getostream(mp->outspec, mp->modname, j, 0); |
340 |
|
put_contrib(mp->cbin[j], sop->ofp); |
341 |
|
} |
342 |
+ |
} |
343 |
|
} |
344 |
|
|
345 |
|
|
366 |
|
end_record() |
367 |
|
{ |
368 |
|
--waitflush; |
369 |
< |
lu_doall(&ofiletab, puteol, NULL); |
369 |
> |
lu_doall(&ofiletab, &puteol, NULL); |
370 |
|
if (using_stdout & (outfmt == 'a')) |
371 |
|
putc('\n', stdout); |
372 |
|
if (!waitflush) { |
516 |
|
*(STREAMOUT *)oent->data = sout; |
517 |
|
} |
518 |
|
} |
519 |
< |
lu_doall(&ofiletab, myclose, NULL); /* close all files */ |
519 |
> |
lu_doall(&ofiletab, &myclose, NULL); /* close all files */ |
520 |
|
} |
521 |
|
|
522 |
|
|
672 |
|
} |
673 |
|
/* seek on all files */ |
674 |
|
nvals = lastout * outvsiz; |
675 |
< |
lu_doall(&ofiletab, myseeko, &nvals); |
675 |
> |
lu_doall(&ofiletab, &myseeko, &nvals); |
676 |
|
/* skip repeated input */ |
677 |
+ |
lastout *= accumulate; |
678 |
|
for (nvals = 0; nvals < lastout; nvals++) { |
679 |
|
FVECT vdummy; |
680 |
|
if (getvec(vdummy) < 0 || getvec(vdummy) < 0) |
681 |
|
error(USER, "unexpected EOF on input"); |
682 |
|
} |
683 |
< |
lastray = lastdone = lastout * accumulate; |
683 |
> |
lastray = lastdone = (RNUMBER)lastout; |
684 |
|
if (raysleft) |
685 |
|
raysleft -= lastray; |
686 |
|
} |