9 |
|
|
10 |
|
#include "platform.h" |
11 |
|
#include "standard.h" |
12 |
< |
#include "rtprocess.h" |
12 |
> |
#include "paths.h" |
13 |
|
#include "color.h" |
14 |
|
#include "calcomp.h" |
15 |
|
#include "view.h" |
16 |
|
|
17 |
< |
#define MAXINP 32 /* maximum number of input files */ |
18 |
< |
#define WINSIZ 64 /* scanline window size */ |
17 |
> |
#define MAXINP 1024 /* maximum number of input files */ |
18 |
> |
#define WINSIZ 127 /* scanline window size */ |
19 |
|
#define MIDSCN ((WINSIZ-1)/2+1) |
20 |
|
|
21 |
|
struct { |
23 |
|
FILE *fp; /* stream pointer */ |
24 |
|
VIEW vw; /* view for picture */ |
25 |
|
RESOLU rs; /* image resolution and orientation */ |
26 |
+ |
int infloat; /* input is floating point (#comp)? */ |
27 |
|
float pa; /* pixel aspect ratio */ |
28 |
|
COLOR *scan[WINSIZ]; /* input scanline window */ |
29 |
|
COLOR coef; /* coefficient */ |
32 |
|
|
33 |
|
int nfiles; /* number of input files */ |
34 |
|
|
35 |
< |
char ourfmt[LPICFMT+1] = PICFMT; /* input picture format */ |
35 |
> |
VIEW *commvp = NULL; /* common view parameters */ |
36 |
|
|
37 |
+ |
char ourfmt[MAXFMTLEN] = PICFMT; /* input picture format */ |
38 |
+ |
int outfloat = 0; /* #component float output? */ |
39 |
+ |
|
40 |
|
char StandardInput[] = "<stdin>"; |
41 |
|
char Command[] = "<Command>"; |
42 |
|
char vcolin[3][4] = {"ri", "gi", "bi"}; |
72 |
|
|
73 |
|
char *progname; /* global argv[0] */ |
74 |
|
|
75 |
+ |
int echoheader = 1; |
76 |
|
int wrongformat = 0; |
77 |
|
int gotview; |
78 |
|
|
79 |
|
|
80 |
< |
static gethfunc tabputs; |
81 |
< |
static void checkfile(void); |
80 |
> |
static gethfunc headline; |
81 |
> |
static void checkfile(int orig); |
82 |
|
static double rgb_bright(COLOR clr); |
83 |
|
static double xyz_bright(COLOR clr); |
84 |
|
static void init(void); |
100 |
|
int original; |
101 |
|
double f; |
102 |
|
int a; |
103 |
+ |
|
104 |
|
SET_DEFAULT_BINARY(); |
105 |
|
SET_FILE_BINARY(stdin); |
106 |
|
SET_FILE_BINARY(stdout); |
107 |
|
progname = argv[0]; |
108 |
+ |
esupport |= E_VARIABLE|E_FUNCTION|E_RCONST; |
109 |
+ |
esupport &= ~(E_OUTCHAN|E_INCHAN); |
110 |
|
/* scan options */ |
111 |
|
for (a = 1; a < argc; a++) { |
112 |
|
if (argv[a][0] == '-') |
118 |
|
case 'w': |
119 |
|
nowarn = !nowarn; |
120 |
|
continue; |
121 |
+ |
case 'h': |
122 |
+ |
echoheader = !echoheader; |
123 |
+ |
continue; |
124 |
|
case 'f': |
125 |
+ |
if (argv[a][2]) { |
126 |
+ |
outfloat = (argv[a][2] == 'f'); |
127 |
+ |
continue; |
128 |
+ |
} |
129 |
+ |
/* fall through */ |
130 |
|
case 'e': |
131 |
|
a++; |
132 |
|
continue; |
184 |
|
quit(1); |
185 |
|
} |
186 |
|
} |
187 |
< |
checkfile(); |
172 |
< |
if (original) { |
173 |
< |
colval(input[nfiles].coef,RED) /= |
174 |
< |
colval(input[nfiles].expos,RED); |
175 |
< |
colval(input[nfiles].coef,GRN) /= |
176 |
< |
colval(input[nfiles].expos,GRN); |
177 |
< |
colval(input[nfiles].coef,BLU) /= |
178 |
< |
colval(input[nfiles].expos,BLU); |
179 |
< |
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
180 |
< |
} |
187 |
> |
checkfile(original); |
188 |
|
nfiles++; |
189 |
|
original = 0; |
190 |
|
} |
191 |
|
init(); /* set constants */ |
192 |
|
/* go back and get expressions */ |
193 |
|
for (a = 1; a < argc; a++) { |
194 |
+ |
char *fpath; |
195 |
|
if (argv[a][0] == '-') |
196 |
|
switch (argv[a][1]) { |
197 |
|
case 'x': |
202 |
|
continue; |
203 |
|
case 'w': |
204 |
|
continue; |
205 |
+ |
case 'h': |
206 |
+ |
continue; |
207 |
|
case 'f': |
208 |
< |
fcompile(argv[++a]); |
208 |
> |
if (argv[a][2]) |
209 |
> |
continue; |
210 |
> |
fpath = getpath(argv[++a], getrlibpath(), 0); |
211 |
> |
if (fpath == NULL) { |
212 |
> |
eputs(argv[0]); |
213 |
> |
eputs(": cannot find file '"); |
214 |
> |
eputs(argv[a]); |
215 |
> |
eputs("'\n"); |
216 |
> |
quit(1); |
217 |
> |
} |
218 |
> |
fcompile(fpath); |
219 |
|
continue; |
220 |
|
case 'e': |
221 |
|
scompile(argv[++a], NULL, 0); |
223 |
|
} |
224 |
|
break; |
225 |
|
} |
226 |
< |
/* set/get output resolution */ |
207 |
< |
if (!vardefined(vxres)) |
208 |
< |
varset(vxres, ':', (double)xmax); |
209 |
< |
if (!vardefined(vyres)) |
210 |
< |
varset(vyres, ':', (double)ymax); |
226 |
> |
/* get output resolution */ |
227 |
|
xres = varvalue(vxres) + .5; |
228 |
|
yres = varvalue(vyres) + .5; |
229 |
|
if (xres <= 0 || yres <= 0) { |
231 |
|
eputs(": illegal output resolution\n"); |
232 |
|
quit(1); |
233 |
|
} |
234 |
< |
/* complete header */ |
235 |
< |
printargs(argc, argv, stdout); |
236 |
< |
if (strcmp(ourfmt, PICFMT)) |
237 |
< |
fputformat(ourfmt, stdout); /* print format if known */ |
238 |
< |
putchar('\n'); |
239 |
< |
fprtresolu(xres, yres, stdout); |
240 |
< |
/* combine pictures */ |
241 |
< |
combine(); |
234 |
> |
if (!vardefined(vbrtout)) /* single or 3-channel? */ |
235 |
> |
outfloat *= 3; |
236 |
> |
|
237 |
> |
printargs(argc, argv, stdout); /* complete header */ |
238 |
> |
if (commvp != NULL) { |
239 |
> |
fputs(VIEWSTR, stdout); |
240 |
> |
fprintview(commvp, stdout); |
241 |
> |
fputc('\n', stdout); |
242 |
> |
} |
243 |
> |
if (outfloat) { /* print output format */ |
244 |
> |
printf("NROWS=%d\nNCOLS=%d\n", yres, xres); |
245 |
> |
fputncomp(outfloat, stdout); |
246 |
> |
fputendian(stdout); |
247 |
> |
fputformat("float", stdout); |
248 |
> |
} else if (strcmp(ourfmt, PICFMT)) |
249 |
> |
fputformat(ourfmt, stdout); |
250 |
> |
else |
251 |
> |
fputformat(COLRFMT, stdout); |
252 |
> |
fputc('\n', stdout); /* end header */ |
253 |
> |
if (!outfloat) |
254 |
> |
fprtresolu(xres, yres, stdout); |
255 |
> |
|
256 |
> |
doptimize(1); /* optimize definitions */ |
257 |
> |
combine(); /* combine pictures */ |
258 |
|
quit(0); |
259 |
|
usage: |
260 |
|
eputs("Usage: "); |
261 |
|
eputs(argv[0]); |
262 |
|
eputs( |
263 |
< |
" [-w][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n"); |
263 |
> |
" [-w][-h][-ff][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] hdr ..]\n"); |
264 |
|
quit(1); |
265 |
|
return 1; /* pro forma return */ |
266 |
|
} |
267 |
|
|
268 |
|
|
269 |
|
static int |
270 |
< |
tabputs( /* put out string preceded by a tab */ |
270 |
> |
headline( /* check header line & echo if requested */ |
271 |
|
char *s, |
272 |
|
void *p |
273 |
|
) |
274 |
|
{ |
275 |
< |
char fmt[32]; |
275 |
> |
int orig = *(int *)p; |
276 |
> |
char fmt[MAXFMTLEN]; |
277 |
|
double d; |
278 |
+ |
int bigend; |
279 |
|
COLOR ctmp; |
280 |
|
|
281 |
|
if (isheadid(s)) /* header id */ |
284 |
|
if (globmatch(ourfmt, fmt)) { |
285 |
|
wrongformat = 0; |
286 |
|
strcpy(ourfmt, fmt); |
287 |
< |
} else |
287 |
> |
} else if (!strcmp("float", fmt)) |
288 |
> |
input[nfiles].infloat *= -1; |
289 |
> |
else |
290 |
|
wrongformat = globmatch(PICFMT, fmt) ? 1 : -1; |
291 |
|
return(0); /* don't echo */ |
292 |
|
} |
293 |
< |
if (isexpos(s)) { /* exposure */ |
293 |
> |
if ((bigend = isbigendian(s)) >= 0) { |
294 |
> |
if (bigend != nativebigendian()) { |
295 |
> |
eputs(input[nfiles].name); |
296 |
> |
eputs(": unsupported input byte ordering\n"); |
297 |
> |
quit(1); |
298 |
> |
} |
299 |
> |
return(0); /* don't echo */ |
300 |
> |
} |
301 |
> |
if (!strncmp("NROWS=", s, 6)) { /* X-resolution */ |
302 |
> |
input[nfiles].rs.yr = atoi(s+6); |
303 |
> |
return(0); /* don't echo */ |
304 |
> |
} |
305 |
> |
if (!strncmp("NCOLS=", s, 6)) { /* Y-resolution */ |
306 |
> |
input[nfiles].rs.xr = atoi(s+6); |
307 |
> |
return(0); /* don't echo */ |
308 |
> |
} |
309 |
> |
if (isncomp(s)) /* # components */ |
310 |
> |
input[nfiles].infloat *= ncompval(s); |
311 |
> |
|
312 |
> |
if (orig) { /* undo exposure? */ |
313 |
> |
if (isexpos(s)) { |
314 |
> |
d = 1./exposval(s); |
315 |
> |
scalecolor(input[nfiles].coef, d); |
316 |
> |
return(0); /* don't echo */ |
317 |
> |
} |
318 |
> |
if (iscolcor(s)) { |
319 |
> |
int i; |
320 |
> |
colcorval(ctmp, s); |
321 |
> |
for (i = 3; i--; ) |
322 |
> |
colval(input[nfiles].coef,i) /= colval(ctmp,i); |
323 |
> |
return(0); /* don't echo */ |
324 |
> |
} |
325 |
> |
} else if (isexpos(s)) { /* record exposure? */ |
326 |
|
d = exposval(s); |
327 |
|
scalecolor(input[nfiles].expos, d); |
328 |
< |
} else if (iscolcor(s)) { /* color correction */ |
328 |
> |
} else if (iscolcor(s)) { |
329 |
|
colcorval(ctmp, s); |
330 |
|
multcolor(input[nfiles].expos, ctmp); |
331 |
< |
} else if (isaspect(s)) |
331 |
> |
} |
332 |
> |
if (isaspect(s)) |
333 |
|
input[nfiles].pa *= aspectval(s); |
334 |
|
else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) |
335 |
|
gotview++; |
336 |
< |
/* echo line */ |
337 |
< |
putchar('\t'); |
338 |
< |
return(fputs(s, stdout)); |
336 |
> |
|
337 |
> |
if (echoheader) { /* echo line */ |
338 |
> |
putchar('\t'); |
339 |
> |
return(fputs(s, stdout)); |
340 |
> |
} |
341 |
> |
return(0); |
342 |
|
} |
343 |
|
|
344 |
|
|
345 |
|
static void |
346 |
< |
checkfile(void) /* ready a file */ |
346 |
> |
checkfile(int orig) /* ready a file */ |
347 |
|
{ |
348 |
< |
register int i; |
348 |
> |
int i; |
349 |
|
/* process header */ |
350 |
|
gotview = 0; |
351 |
< |
fputs(input[nfiles].name, stdout); |
352 |
< |
fputs(":\n", stdout); |
353 |
< |
getheader(input[nfiles].fp, tabputs, NULL); |
351 |
> |
input[nfiles].infloat = -1; |
352 |
> |
input[nfiles].rs.rt = PIXSTANDARD; |
353 |
> |
input[nfiles].rs.xr = input[nfiles].rs.yr = 0; |
354 |
> |
if (echoheader) { |
355 |
> |
fputs(input[nfiles].name, stdout); |
356 |
> |
fputs(":\n", stdout); |
357 |
> |
} |
358 |
> |
getheader(input[nfiles].fp, headline, &orig); |
359 |
> |
|
360 |
> |
if (input[nfiles].infloat <= 0) |
361 |
> |
input[nfiles].infloat = 0; |
362 |
> |
else if ((input[nfiles].infloat != 3) & |
363 |
> |
(input[nfiles].infloat != 1)) { |
364 |
> |
eputs(input[nfiles].name); |
365 |
> |
eputs(": unsupported number of components\n"); |
366 |
> |
quit(1); |
367 |
> |
} |
368 |
|
if (wrongformat < 0) { |
369 |
|
eputs(input[nfiles].name); |
370 |
< |
eputs(": not a Radiance picture\n"); |
370 |
> |
eputs(": not a Radiance picture or float matrix\n"); |
371 |
|
quit(1); |
372 |
|
} |
373 |
|
if (wrongformat > 0) { |
376 |
|
} |
377 |
|
if (!gotview || setview(&input[nfiles].vw) != NULL) |
378 |
|
input[nfiles].vw.type = 0; |
379 |
< |
if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) { |
379 |
> |
else if (commvp == NULL) |
380 |
> |
commvp = &input[nfiles].vw; |
381 |
> |
if ((input[nfiles].rs.xr <= 0) | (input[nfiles].rs.yr <= 0) && |
382 |
> |
!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) { |
383 |
|
eputs(input[nfiles].name); |
384 |
|
eputs(": bad picture size\n"); |
385 |
|
quit(1); |
423 |
|
static void |
424 |
|
init(void) /* perform final setup */ |
425 |
|
{ |
426 |
< |
double l_colin(char *), l_expos(char *), l_pixaspect(char *), |
338 |
< |
l_ray(char *), l_psize(char *); |
339 |
< |
register int i; |
426 |
> |
int i; |
427 |
|
/* define constants */ |
428 |
|
varset("PI", ':', PI); |
429 |
|
varset(vnfiles, ':', (double)nfiles); |
446 |
|
ourbright = xyz_bright; |
447 |
|
} else |
448 |
|
varset(vwhteff, ':', WHTEFFICACY); |
449 |
+ |
/* these may be overridden */ |
450 |
+ |
varset(vxres, ':', (double)xmax); |
451 |
+ |
varset(vyres, ':', (double)ymax); |
452 |
|
} |
453 |
|
|
454 |
|
|
456 |
|
combine(void) /* combine pictures */ |
457 |
|
{ |
458 |
|
EPNODE *coldef[3], *brtdef; |
459 |
+ |
int set_x, set_y; |
460 |
|
COLOR *scanout; |
461 |
|
double d; |
462 |
< |
register int i, j; |
462 |
> |
int i, j; |
463 |
|
/* check defined variables */ |
464 |
|
for (j = 0; j < 3; j++) { |
465 |
|
if (vardefined(vcolout[j])) |
471 |
|
brtdef = eparse(vbrtout); |
472 |
|
else |
473 |
|
brtdef = NULL; |
474 |
+ |
/* what to set */ |
475 |
+ |
set_x = varlookup(vxpos) != NULL && !vardefined(vxpos); |
476 |
+ |
set_y = varlookup(vypos) != NULL && !vardefined(vypos); |
477 |
|
/* allocate scanline */ |
478 |
|
scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); |
479 |
|
/* set input position */ |
481 |
|
/* combine files */ |
482 |
|
for (ypos = yres-1; ypos >= 0; ypos--) { |
483 |
|
advance(); |
484 |
< |
varset(vypos, '=', (double)ypos); |
484 |
> |
if (set_y) varset(vypos, '=', (double)ypos); |
485 |
|
for (xpos = 0; xpos < xres; xpos++) { |
486 |
< |
xscan = (long)xpos*xmax/xres; |
487 |
< |
varset(vxpos, '=', (double)xpos); |
486 |
> |
xscan = (xpos+.5)*xmax/xres; |
487 |
> |
if (set_x) varset(vxpos, '=', (double)xpos); |
488 |
|
eclock++; |
489 |
|
if (brtdef != NULL) { |
490 |
|
d = evalue(brtdef); |
491 |
< |
if (d < 0.0) |
398 |
< |
d = 0.0; |
491 |
> |
d *= (outfloat > 0) | (d >= 0); |
492 |
|
setcolor(scanout[xpos], d, d, d); |
493 |
|
} else { |
494 |
|
for (j = 0; j < 3; j++) { |
499 |
|
for (i = 0; i < nfiles; i++) |
500 |
|
d += colval(input[i].scan[MIDSCN][xscan],j); |
501 |
|
} |
502 |
< |
if (d < 0.0) |
410 |
< |
d = 0.0; |
502 |
> |
d *= (outfloat > 0) | (d >= 0); |
503 |
|
colval(scanout[xpos],j) = d; |
504 |
|
} |
505 |
|
} |
506 |
|
} |
507 |
< |
if (fwritescan(scanout, xres, stdout) < 0) { |
508 |
< |
perror("write error"); |
509 |
< |
quit(1); |
507 |
> |
switch (outfloat) { |
508 |
> |
case 3: /* writing out float triplets */ |
509 |
> |
if (fwrite(scanout, sizeof(float)*3, xres, stdout) != xres) |
510 |
> |
goto writerr; |
511 |
> |
break; |
512 |
> |
case 1: /* writing out gray float values */ |
513 |
> |
for (xpos = 0; xpos < xres; xpos++) |
514 |
> |
if (putbinary(&scanout[xpos][CIEY], |
515 |
> |
sizeof(float), 1, stdout) != 1) |
516 |
> |
goto writerr; |
517 |
> |
break; |
518 |
> |
default: /* writing out Radiance picture */ |
519 |
> |
if (fwritescan(scanout, xres, stdout) < 0) |
520 |
> |
goto writerr; |
521 |
> |
break; |
522 |
|
} |
523 |
|
} |
524 |
|
efree((char *)scanout); |
525 |
+ |
return; |
526 |
+ |
writerr: |
527 |
+ |
perror("write error"); |
528 |
+ |
quit(1); |
529 |
|
} |
530 |
|
|
531 |
|
|
533 |
|
advance(void) /* read in data for next scanline */ |
534 |
|
{ |
535 |
|
int ytarget; |
536 |
< |
register COLOR *st; |
537 |
< |
register int i, j; |
536 |
> |
COLOR *st; |
537 |
> |
int i, j; |
538 |
|
|
539 |
< |
for (ytarget = (long)ypos*ymax/yres; yscan > ytarget; yscan--) |
539 |
> |
for (ytarget = (ypos+.5)*ymax/yres; yscan > ytarget; yscan--) |
540 |
|
for (i = 0; i < nfiles; i++) { |
541 |
|
st = input[i].scan[WINSIZ-1]; |
542 |
|
for (j = WINSIZ-1; j > 0; j--) /* rotate window */ |
544 |
|
input[i].scan[0] = st; |
545 |
|
if (yscan <= MIDSCN) /* hit bottom? */ |
546 |
|
continue; |
547 |
< |
if (freadscan(st, xmax, input[i].fp) < 0) { /* read */ |
548 |
< |
eputs(input[i].name); |
549 |
< |
eputs(": read error\n"); |
550 |
< |
quit(1); |
551 |
< |
} |
552 |
< |
if (fabs(colval(input[i].coef,RED)-1.0) > 1e-3 || |
553 |
< |
fabs(colval(input[i].coef,GRN)-1.0) > 1e-3 || |
554 |
< |
fabs(colval(input[i].coef,BLU)-1.0) > 1e-3) |
555 |
< |
for (j = 0; j < xmax; j++) /* adjust color */ |
556 |
< |
multcolor(st[j], input[i].coef); |
547 |
> |
/* read scanline */ |
548 |
> |
if (input[i].infloat) { |
549 |
> |
if (fread(st, sizeof(float)*input[i].infloat, |
550 |
> |
xmax, input[i].fp) != xmax) |
551 |
> |
goto readerr; |
552 |
> |
if (input[i].infloat == 1) { |
553 |
> |
const COLORV *f = st[0] + xmax; |
554 |
> |
int x = xmax; |
555 |
> |
while (x-- > 0) |
556 |
> |
st[x][BLU] = st[x][GRN] = |
557 |
> |
st[x][RED] = *--f; |
558 |
> |
} |
559 |
> |
} else if (freadscan(st, xmax, input[i].fp) < 0) |
560 |
> |
goto readerr; |
561 |
> |
for (j = 0; j < xmax; j++) /* adjust color */ |
562 |
> |
multcolor(st[j], input[i].coef); |
563 |
|
} |
564 |
+ |
return; |
565 |
+ |
readerr: |
566 |
+ |
eputs(input[i].name); |
567 |
+ |
eputs(": read error\n"); |
568 |
+ |
quit(1); |
569 |
|
} |
570 |
|
|
571 |
|
|
572 |
|
static double |
573 |
|
l_expos( /* return picture exposure */ |
574 |
< |
register char *nam |
574 |
> |
char *nam |
575 |
|
) |
576 |
|
{ |
577 |
< |
register int fn, n; |
577 |
> |
int fn, n; |
578 |
> |
double d; |
579 |
|
|
580 |
< |
fn = argument(1) - .5; |
581 |
< |
if (fn < 0 || fn >= nfiles) |
582 |
< |
return(1.0); |
580 |
> |
d = argument(1); |
581 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
582 |
> |
errno = EDOM; |
583 |
> |
return(0.0); |
584 |
> |
} |
585 |
> |
if (d < 0.5) |
586 |
> |
return((double)nfiles); |
587 |
> |
fn = d - 0.5; |
588 |
|
if (nam == vbrtexp) |
589 |
|
return((*ourbright)(input[fn].expos)); |
590 |
|
n = 3; |
600 |
|
static double |
601 |
|
l_pixaspect(char *nm) /* return pixel aspect ratio */ |
602 |
|
{ |
603 |
< |
register int fn; |
603 |
> |
int fn; |
604 |
> |
double d; |
605 |
|
|
606 |
< |
fn = argument(1) - .5; |
607 |
< |
if (fn < 0 || fn >= nfiles) |
608 |
< |
return(1.0); |
606 |
> |
d = argument(1); |
607 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
608 |
> |
errno = EDOM; |
609 |
> |
return(0.0); |
610 |
> |
} |
611 |
> |
if (d < 0.5) |
612 |
> |
return((double)nfiles); |
613 |
> |
fn = d - 0.5; |
614 |
|
return(input[fn].pa); |
615 |
|
} |
616 |
|
|
617 |
|
|
618 |
|
static double |
619 |
|
l_colin( /* return color value for picture */ |
620 |
< |
register char *nam |
620 |
> |
char *nam |
621 |
|
) |
622 |
|
{ |
623 |
|
int fn; |
624 |
< |
register int n, xoff, yoff; |
624 |
> |
int n, xoff, yoff; |
625 |
|
double d; |
626 |
|
|
627 |
< |
fn = argument(1) - .5; |
628 |
< |
if (fn < 0 || fn >= nfiles) { |
627 |
> |
d = argument(1); |
628 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
629 |
|
errno = EDOM; |
630 |
|
return(0.0); |
631 |
|
} |
632 |
+ |
if (d < 0.5) |
633 |
+ |
return((double)nfiles); |
634 |
+ |
fn = d - 0.5; |
635 |
|
xoff = yoff = 0; |
636 |
|
n = nargum(); |
637 |
|
if (n >= 2) { |
676 |
|
|
677 |
|
static double |
678 |
|
l_ray( /* return ray origin or direction */ |
679 |
< |
register char *nam |
679 |
> |
char *nam |
680 |
|
) |
681 |
|
{ |
682 |
|
static unsigned long ltick[MAXINP]; |
683 |
|
static FVECT lorg[MAXINP], ldir[MAXINP]; |
684 |
|
static double ldist[MAXINP]; |
685 |
|
RREAL loc[2]; |
686 |
+ |
double d; |
687 |
|
int fn; |
688 |
< |
register int i; |
688 |
> |
int i; |
689 |
|
|
690 |
< |
fn = argument(1) - .5; |
691 |
< |
if (fn < 0 || fn >= nfiles) { |
690 |
> |
d = argument(1); |
691 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
692 |
|
errno = EDOM; |
693 |
|
return(0.0); |
694 |
|
} |
695 |
+ |
if (d < 0.5) |
696 |
+ |
return((double)nfiles); |
697 |
+ |
fn = d - 0.5; |
698 |
|
if (ltick[fn] != eclock) { /* need to compute? */ |
699 |
< |
lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0; |
700 |
< |
ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0; |
701 |
< |
ldist[fn] = -1.0; |
702 |
< |
if (input[fn].vw.type == 0) |
699 |
> |
if (input[fn].vw.type == 0) { |
700 |
> |
lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0; |
701 |
> |
ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0; |
702 |
> |
ldist[fn] = -1.0; |
703 |
|
errno = EDOM; |
704 |
< |
else { |
704 |
> |
} else { |
705 |
|
pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan); |
706 |
|
ldist[fn] = viewray(lorg[fn], ldir[fn], |
707 |
|
&input[fn].vw, loc[0], loc[1]); |
708 |
+ |
if (ldist[fn] < -FTINY) |
709 |
+ |
errno = EDOM; |
710 |
|
} |
711 |
|
ltick[fn] = eclock; |
712 |
|
} |
730 |
|
RREAL locx[2], locy[2]; |
731 |
|
double d; |
732 |
|
int fn; |
733 |
< |
register int i; |
733 |
> |
int i; |
734 |
|
|
735 |
|
d = argument(1); |
736 |
< |
if (d < .5 || d >= nfiles+.5) { |
736 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
737 |
|
errno = EDOM; |
738 |
|
return(0.0); |
739 |
|
} |
740 |
< |
fn = d - .5; |
740 |
> |
if (d < 0.5) |
741 |
> |
return((double)nfiles); |
742 |
> |
fn = d - 0.5; |
743 |
|
if (ltick[fn] != eclock) { /* need to compute? */ |
744 |
|
psize[fn] = 0.0; |
745 |
|
if (input[fn].vw.type == 0) |
746 |
|
errno = EDOM; |
747 |
|
else if (input[fn].vw.type != VT_PAR && |
748 |
< |
funvalue(vray[6], 1, &d) >= 0) { |
748 |
> |
funvalue(vray[6], 1, &d) >= -FTINY) { |
749 |
|
for (i = 0; i < 3; i++) |
750 |
|
dir0[i] = funvalue(vray[3+i], 1, &d); |
751 |
|
pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan); |
752 |
|
pix2loc(locy, &input[fn].rs, xscan, ymax-yscan); |
753 |
|
if (viewray(org, dirx, &input[fn].vw, |
754 |
< |
locx[0], locx[1]) >= 0 && |
754 |
> |
locx[0], locx[1]) >= -FTINY && |
755 |
|
viewray(org, diry, &input[fn].vw, |
756 |
< |
locy[0], locy[1]) >= 0) { |
756 |
> |
locy[0], locy[1]) >= -FTINY) { |
757 |
|
/* approximate solid angle */ |
758 |
|
for (i = 0; i < 3; i++) { |
759 |
|
dirx[i] -= dir0[i]; |
760 |
|
diry[i] -= dir0[i]; |
761 |
|
} |
762 |
|
fcross(dir0, dirx, diry); |
763 |
< |
psize[fn] = sqrt(DOT(dir0,dir0)); |
763 |
> |
psize[fn] = VLEN(dir0); |
764 |
|
} |
765 |
|
} |
766 |
|
ltick[fn] = eclock; |
770 |
|
|
771 |
|
|
772 |
|
extern void |
773 |
< |
wputs(char *msg) |
773 |
> |
wputs(const char *msg) |
774 |
|
{ |
775 |
|
if (!nowarn) |
776 |
|
eputs(msg); |
778 |
|
|
779 |
|
|
780 |
|
extern void |
781 |
< |
eputs(char *msg) |
781 |
> |
eputs(const char *msg) |
782 |
|
{ |
783 |
|
fputs(msg, stderr); |
784 |
|
} |
787 |
|
extern void |
788 |
|
quit(int code) /* exit gracefully */ |
789 |
|
{ |
790 |
< |
register int i; |
790 |
> |
int i; |
791 |
|
/* close input files */ |
792 |
|
for (i = 0; i < nfiles; i++) |
793 |
|
if (input[i].name == Command) |