| 1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
| 2 |
– |
|
| 1 |
|
#ifndef lint |
| 2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
| 2 |
> |
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 6 |
– |
|
| 4 |
|
/* |
| 5 |
|
* Combine picture files according to calcomp functions. |
| 6 |
|
* |
| 7 |
|
* 1/4/89 |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
< |
#include <stdio.h> |
| 11 |
< |
|
| 12 |
< |
#include <errno.h> |
| 16 |
< |
|
| 10 |
> |
#include "platform.h" |
| 11 |
> |
#include "standard.h" |
| 12 |
> |
#include "paths.h" |
| 13 |
|
#include "color.h" |
| 18 |
– |
|
| 19 |
– |
#include "resolu.h" |
| 20 |
– |
|
| 14 |
|
#include "calcomp.h" |
| 15 |
+ |
#include "view.h" |
| 16 |
|
|
| 17 |
< |
#define MAXINP 32 /* maximum number of input files */ |
| 18 |
< |
#define WINSIZ 9 /* scanline window size */ |
| 19 |
< |
#define MIDSCN 4 /* current scan position */ |
| 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 { |
| 22 |
|
char *name; /* file or command name */ |
| 23 |
|
FILE *fp; /* stream pointer */ |
| 24 |
+ |
VIEW vw; /* view for picture */ |
| 25 |
+ |
RESOLU rs; /* image resolution and orientation */ |
| 26 |
+ |
float pa; /* pixel aspect ratio */ |
| 27 |
|
COLOR *scan[WINSIZ]; /* input scanline window */ |
| 28 |
|
COLOR coef; /* coefficient */ |
| 29 |
|
COLOR expos; /* recorded exposure */ |
| 31 |
|
|
| 32 |
|
int nfiles; /* number of input files */ |
| 33 |
|
|
| 34 |
+ |
VIEW *commvp = NULL; /* common view parameters */ |
| 35 |
+ |
|
| 36 |
+ |
char ourfmt[LPICFMT+1] = PICFMT; /* input picture format */ |
| 37 |
+ |
|
| 38 |
+ |
char StandardInput[] = "<stdin>"; |
| 39 |
+ |
char Command[] = "<Command>"; |
| 40 |
|
char vcolin[3][4] = {"ri", "gi", "bi"}; |
| 41 |
|
char vcolout[3][4] = {"ro", "go", "bo"}; |
| 42 |
|
char vbrtin[] = "li"; |
| 43 |
|
char vbrtout[] = "lo"; |
| 44 |
|
char vcolexp[3][4] = {"re", "ge", "be"}; |
| 45 |
|
char vbrtexp[] = "le"; |
| 46 |
+ |
char vpixaspect[] = "pa"; |
| 47 |
|
|
| 48 |
+ |
char vray[7][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz", "T"}; |
| 49 |
+ |
|
| 50 |
+ |
char vpsize[] = "S"; |
| 51 |
+ |
|
| 52 |
|
char vnfiles[] = "nfiles"; |
| 53 |
+ |
char vwhteff[] = "WE"; |
| 54 |
|
char vxmax[] = "xmax"; |
| 55 |
|
char vymax[] = "ymax"; |
| 56 |
|
char vxres[] = "xres"; |
| 68 |
|
|
| 69 |
|
int xpos, ypos; /* output position */ |
| 70 |
|
|
| 71 |
+ |
char *progname; /* global argv[0] */ |
| 72 |
+ |
|
| 73 |
+ |
int echoheader = 1; |
| 74 |
|
int wrongformat = 0; |
| 75 |
+ |
int gotview; |
| 76 |
|
|
| 64 |
– |
FILE *popen(); |
| 77 |
|
|
| 78 |
+ |
static gethfunc headline; |
| 79 |
+ |
static void checkfile(int orig); |
| 80 |
+ |
static double rgb_bright(COLOR clr); |
| 81 |
+ |
static double xyz_bright(COLOR clr); |
| 82 |
+ |
static void init(void); |
| 83 |
+ |
static void combine(void); |
| 84 |
+ |
static void advance(void); |
| 85 |
+ |
static double l_expos(char *nam); |
| 86 |
+ |
static double l_pixaspect(char *nm); |
| 87 |
+ |
static double l_colin(char *nam); |
| 88 |
+ |
static double l_ray(char *nam); |
| 89 |
+ |
static double l_psize(char *nm); |
| 90 |
|
|
| 91 |
< |
main(argc, argv) |
| 92 |
< |
int argc; |
| 93 |
< |
char *argv[]; |
| 91 |
> |
|
| 92 |
> |
int |
| 93 |
> |
main( |
| 94 |
> |
int argc, |
| 95 |
> |
char *argv[] |
| 96 |
> |
) |
| 97 |
|
{ |
| 98 |
|
int original; |
| 99 |
|
double f; |
| 100 |
< |
int a, i; |
| 100 |
> |
int a; |
| 101 |
> |
|
| 102 |
> |
SET_DEFAULT_BINARY(); |
| 103 |
> |
SET_FILE_BINARY(stdin); |
| 104 |
> |
SET_FILE_BINARY(stdout); |
| 105 |
> |
progname = argv[0]; |
| 106 |
> |
esupport |= E_VARIABLE|E_FUNCTION|E_RCONST; |
| 107 |
> |
esupport &= ~(E_OUTCHAN|E_INCHAN); |
| 108 |
|
/* scan options */ |
| 109 |
|
for (a = 1; a < argc; a++) { |
| 110 |
|
if (argv[a][0] == '-') |
| 116 |
|
case 'w': |
| 117 |
|
nowarn = !nowarn; |
| 118 |
|
continue; |
| 119 |
+ |
case 'h': |
| 120 |
+ |
echoheader = !echoheader; |
| 121 |
+ |
continue; |
| 122 |
|
case 'f': |
| 123 |
|
case 'e': |
| 124 |
|
a++; |
| 126 |
|
} |
| 127 |
|
break; |
| 128 |
|
} |
| 129 |
+ |
newheader("RADIANCE", stdout); /* start header */ |
| 130 |
+ |
fputnow(stdout); |
| 131 |
|
/* process files */ |
| 132 |
|
for (nfiles = 0; nfiles < MAXINP; nfiles++) { |
| 133 |
|
setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); |
| 134 |
|
setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); |
| 135 |
+ |
input[nfiles].vw = stdview; |
| 136 |
+ |
input[nfiles].pa = 1.0; |
| 137 |
|
} |
| 138 |
|
nfiles = 0; |
| 139 |
|
original = 0; |
| 146 |
|
if (argv[a][0] == '-') |
| 147 |
|
switch (argv[a][1]) { |
| 148 |
|
case '\0': |
| 149 |
< |
input[nfiles].name = "<stdin>"; |
| 149 |
> |
input[nfiles].name = StandardInput; |
| 150 |
|
input[nfiles].fp = stdin; |
| 151 |
|
break; |
| 152 |
|
case 'o': |
| 166 |
|
} |
| 167 |
|
else { |
| 168 |
|
if (argv[a][0] == '!') { |
| 169 |
< |
input[nfiles].name = "<Command>"; |
| 169 |
> |
input[nfiles].name = Command; |
| 170 |
|
input[nfiles].fp = popen(argv[a]+1, "r"); |
| 171 |
|
} else { |
| 172 |
|
input[nfiles].name = argv[a]; |
| 177 |
|
quit(1); |
| 178 |
|
} |
| 179 |
|
} |
| 180 |
< |
checkfile(); |
| 140 |
< |
if (original) { |
| 141 |
< |
colval(input[nfiles].coef,RED) /= |
| 142 |
< |
colval(input[nfiles].expos,RED); |
| 143 |
< |
colval(input[nfiles].coef,GRN) /= |
| 144 |
< |
colval(input[nfiles].expos,GRN); |
| 145 |
< |
colval(input[nfiles].coef,BLU) /= |
| 146 |
< |
colval(input[nfiles].expos,BLU); |
| 147 |
< |
} |
| 180 |
> |
checkfile(original); |
| 181 |
|
nfiles++; |
| 182 |
|
original = 0; |
| 183 |
|
} |
| 184 |
|
init(); /* set constants */ |
| 185 |
|
/* go back and get expressions */ |
| 186 |
|
for (a = 1; a < argc; a++) { |
| 187 |
+ |
char *fpath; |
| 188 |
|
if (argv[a][0] == '-') |
| 189 |
|
switch (argv[a][1]) { |
| 190 |
|
case 'x': |
| 195 |
|
continue; |
| 196 |
|
case 'w': |
| 197 |
|
continue; |
| 198 |
+ |
case 'h': |
| 199 |
+ |
continue; |
| 200 |
|
case 'f': |
| 201 |
< |
fcompile(argv[++a]); |
| 201 |
> |
fpath = getpath(argv[++a], getrlibpath(), 0); |
| 202 |
> |
if (fpath == NULL) { |
| 203 |
> |
eputs(argv[0]); |
| 204 |
> |
eputs(": cannot find file '"); |
| 205 |
> |
eputs(argv[a]); |
| 206 |
> |
eputs("'\n"); |
| 207 |
> |
quit(1); |
| 208 |
> |
} |
| 209 |
> |
fcompile(fpath); |
| 210 |
|
continue; |
| 211 |
|
case 'e': |
| 212 |
|
scompile(argv[++a], NULL, 0); |
| 214 |
|
} |
| 215 |
|
break; |
| 216 |
|
} |
| 217 |
< |
/* set/get output resolution */ |
| 174 |
< |
if (!vardefined(vxres)) |
| 175 |
< |
varset(vxres, ':', (double)xmax); |
| 176 |
< |
if (!vardefined(vyres)) |
| 177 |
< |
varset(vyres, ':', (double)ymax); |
| 217 |
> |
/* get output resolution */ |
| 218 |
|
xres = varvalue(vxres) + .5; |
| 219 |
|
yres = varvalue(vyres) + .5; |
| 220 |
|
if (xres <= 0 || yres <= 0) { |
| 224 |
|
} |
| 225 |
|
/* complete header */ |
| 226 |
|
printargs(argc, argv, stdout); |
| 227 |
< |
fputformat(COLRFMT, stdout); |
| 227 |
> |
if (commvp != NULL) { |
| 228 |
> |
fputs(VIEWSTR, stdout); |
| 229 |
> |
fprintview(commvp, stdout); |
| 230 |
> |
fputc('\n', stdout); |
| 231 |
> |
} |
| 232 |
> |
if (strcmp(ourfmt, PICFMT)) |
| 233 |
> |
fputformat(ourfmt, stdout); /* print format if known */ |
| 234 |
|
putchar('\n'); |
| 235 |
|
fprtresolu(xres, yres, stdout); |
| 236 |
|
/* combine pictures */ |
| 240 |
|
eputs("Usage: "); |
| 241 |
|
eputs(argv[0]); |
| 242 |
|
eputs( |
| 243 |
< |
" [-w][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n"); |
| 243 |
> |
" [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] hdr ..]\n"); |
| 244 |
|
quit(1); |
| 245 |
+ |
return 1; /* pro forma return */ |
| 246 |
|
} |
| 247 |
|
|
| 248 |
|
|
| 249 |
< |
tputs(s) /* put out string preceded by a tab */ |
| 250 |
< |
char *s; |
| 249 |
> |
static int |
| 250 |
> |
headline( /* check header line & echo if requested */ |
| 251 |
> |
char *s, |
| 252 |
> |
void *p |
| 253 |
> |
) |
| 254 |
|
{ |
| 255 |
< |
char fmt[32]; |
| 255 |
> |
int orig = *(int *)p; |
| 256 |
> |
char fmt[MAXFMTLEN]; |
| 257 |
|
double d; |
| 258 |
|
COLOR ctmp; |
| 259 |
|
|
| 260 |
< |
if (isformat(s)) { /* check format */ |
| 261 |
< |
formatval(fmt, s); |
| 262 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
| 263 |
< |
return; /* don't echo */ |
| 260 |
> |
if (isheadid(s)) /* header id */ |
| 261 |
> |
return(0); /* don't echo */ |
| 262 |
> |
if (formatval(fmt, s)) { /* check format */ |
| 263 |
> |
if (globmatch(ourfmt, fmt)) { |
| 264 |
> |
wrongformat = 0; |
| 265 |
> |
strcpy(ourfmt, fmt); |
| 266 |
> |
} else |
| 267 |
> |
wrongformat = globmatch(PICFMT, fmt) ? 1 : -1; |
| 268 |
> |
return(0); /* don't echo */ |
| 269 |
|
} |
| 270 |
< |
if (isexpos(s)) { /* exposure */ |
| 270 |
> |
if (orig) { /* undo exposure? */ |
| 271 |
> |
if (isexpos(s)) { |
| 272 |
> |
d = 1./exposval(s); |
| 273 |
> |
scalecolor(input[nfiles].coef, d); |
| 274 |
> |
return(0); /* don't echo */ |
| 275 |
> |
} |
| 276 |
> |
if (iscolcor(s)) { |
| 277 |
> |
int i; |
| 278 |
> |
colcorval(ctmp, s); |
| 279 |
> |
for (i = 3; i--; ) |
| 280 |
> |
colval(input[nfiles].coef,i) /= colval(ctmp,i); |
| 281 |
> |
return(0); /* don't echo */ |
| 282 |
> |
} |
| 283 |
> |
} else if (isexpos(s)) { /* record exposure? */ |
| 284 |
|
d = exposval(s); |
| 285 |
|
scalecolor(input[nfiles].expos, d); |
| 286 |
< |
} else if (iscolcor(s)) { /* color correction */ |
| 286 |
> |
} else if (iscolcor(s)) { |
| 287 |
|
colcorval(ctmp, s); |
| 288 |
|
multcolor(input[nfiles].expos, ctmp); |
| 289 |
|
} |
| 290 |
< |
/* echo line */ |
| 291 |
< |
putchar('\t'); |
| 292 |
< |
fputs(s, stdout); |
| 290 |
> |
if (isaspect(s)) |
| 291 |
> |
input[nfiles].pa *= aspectval(s); |
| 292 |
> |
else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) |
| 293 |
> |
gotview++; |
| 294 |
> |
|
| 295 |
> |
if (echoheader) { /* echo line */ |
| 296 |
> |
putchar('\t'); |
| 297 |
> |
return(fputs(s, stdout)); |
| 298 |
> |
} |
| 299 |
> |
return(0); |
| 300 |
|
} |
| 301 |
|
|
| 302 |
|
|
| 303 |
< |
checkfile() /* ready a file */ |
| 303 |
> |
static void |
| 304 |
> |
checkfile(int orig) /* ready a file */ |
| 305 |
|
{ |
| 306 |
< |
int xinp, yinp; |
| 230 |
< |
register int i; |
| 306 |
> |
int i; |
| 307 |
|
/* process header */ |
| 308 |
< |
fputs(input[nfiles].name, stdout); |
| 309 |
< |
fputs(":\n", stdout); |
| 310 |
< |
getheader(input[nfiles].fp, tputs, NULL); |
| 311 |
< |
if (wrongformat) { |
| 308 |
> |
gotview = 0; |
| 309 |
> |
if (echoheader) { |
| 310 |
> |
fputs(input[nfiles].name, stdout); |
| 311 |
> |
fputs(":\n", stdout); |
| 312 |
> |
} |
| 313 |
> |
getheader(input[nfiles].fp, headline, &orig); |
| 314 |
> |
if (wrongformat < 0) { |
| 315 |
|
eputs(input[nfiles].name); |
| 316 |
< |
eputs(": not in Radiance picture format\n"); |
| 316 |
> |
eputs(": not a Radiance picture\n"); |
| 317 |
|
quit(1); |
| 318 |
|
} |
| 319 |
< |
if (fgetresolu(&xinp, &yinp, input[nfiles].fp) < 0) { |
| 319 |
> |
if (wrongformat > 0) { |
| 320 |
> |
wputs(input[nfiles].name); |
| 321 |
> |
wputs(": warning -- incompatible picture format\n"); |
| 322 |
> |
} |
| 323 |
> |
if (!gotview || setview(&input[nfiles].vw) != NULL) |
| 324 |
> |
input[nfiles].vw.type = 0; |
| 325 |
> |
else if (commvp == NULL) |
| 326 |
> |
commvp = &input[nfiles].vw; |
| 327 |
> |
if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) { |
| 328 |
|
eputs(input[nfiles].name); |
| 329 |
|
eputs(": bad picture size\n"); |
| 330 |
|
quit(1); |
| 331 |
|
} |
| 332 |
|
if (xmax == 0 && ymax == 0) { |
| 333 |
< |
xmax = xinp; |
| 334 |
< |
ymax = yinp; |
| 335 |
< |
} else if (xinp != xmax || yinp != ymax) { |
| 333 |
> |
xmax = scanlen(&input[nfiles].rs); |
| 334 |
> |
ymax = numscans(&input[nfiles].rs); |
| 335 |
> |
} else if (scanlen(&input[nfiles].rs) != xmax || |
| 336 |
> |
numscans(&input[nfiles].rs) != ymax) { |
| 337 |
|
eputs(input[nfiles].name); |
| 338 |
|
eputs(": resolution mismatch\n"); |
| 339 |
|
quit(1); |
| 344 |
|
} |
| 345 |
|
|
| 346 |
|
|
| 347 |
< |
init() /* perform final setup */ |
| 347 |
> |
static double |
| 348 |
> |
rgb_bright( |
| 349 |
> |
COLOR clr |
| 350 |
> |
) |
| 351 |
|
{ |
| 352 |
< |
double l_colin(), l_expos(); |
| 353 |
< |
register int i; |
| 352 |
> |
return(bright(clr)); |
| 353 |
> |
} |
| 354 |
> |
|
| 355 |
> |
|
| 356 |
> |
static double |
| 357 |
> |
xyz_bright( |
| 358 |
> |
COLOR clr |
| 359 |
> |
) |
| 360 |
> |
{ |
| 361 |
> |
return(clr[CIEY]); |
| 362 |
> |
} |
| 363 |
> |
|
| 364 |
> |
|
| 365 |
> |
double (*ourbright)() = rgb_bright; |
| 366 |
> |
|
| 367 |
> |
|
| 368 |
> |
static void |
| 369 |
> |
init(void) /* perform final setup */ |
| 370 |
> |
{ |
| 371 |
> |
int i; |
| 372 |
|
/* define constants */ |
| 373 |
+ |
varset("PI", ':', PI); |
| 374 |
|
varset(vnfiles, ':', (double)nfiles); |
| 375 |
|
varset(vxmax, ':', (double)xmax); |
| 376 |
|
varset(vymax, ':', (double)ymax); |
| 381 |
|
} |
| 382 |
|
funset(vbrtexp, 1, ':', l_expos); |
| 383 |
|
funset(vbrtin, 1, '=', l_colin); |
| 384 |
+ |
funset(vpixaspect, 1, ':', l_pixaspect); |
| 385 |
+ |
for (i = 0; i < 7; i++) |
| 386 |
+ |
funset(vray[i], 1, '=', l_ray); |
| 387 |
+ |
funset(vpsize, 1, '=', l_psize); |
| 388 |
+ |
/* set brightness function */ |
| 389 |
+ |
if (!strcmp(ourfmt, CIEFMT)) { |
| 390 |
+ |
varset(vwhteff, ':', 1.0); |
| 391 |
+ |
ourbright = xyz_bright; |
| 392 |
+ |
} else |
| 393 |
+ |
varset(vwhteff, ':', WHTEFFICACY); |
| 394 |
+ |
/* these may be overridden */ |
| 395 |
+ |
varset(vxres, ':', (double)xmax); |
| 396 |
+ |
varset(vyres, ':', (double)ymax); |
| 397 |
|
} |
| 398 |
|
|
| 399 |
|
|
| 400 |
< |
combine() /* combine pictures */ |
| 400 |
> |
static void |
| 401 |
> |
combine(void) /* combine pictures */ |
| 402 |
|
{ |
| 403 |
|
EPNODE *coldef[3], *brtdef; |
| 404 |
|
COLOR *scanout; |
| 405 |
|
double d; |
| 406 |
< |
register int i, j; |
| 406 |
> |
int i, j; |
| 407 |
|
/* check defined variables */ |
| 408 |
|
for (j = 0; j < 3; j++) { |
| 409 |
|
if (vardefined(vcolout[j])) |
| 424 |
|
advance(); |
| 425 |
|
varset(vypos, '=', (double)ypos); |
| 426 |
|
for (xpos = 0; xpos < xres; xpos++) { |
| 427 |
< |
xscan = (long)xpos*xmax/xres; |
| 427 |
> |
xscan = (xpos+.5)*xmax/xres; |
| 428 |
|
varset(vxpos, '=', (double)xpos); |
| 429 |
|
eclock++; |
| 430 |
|
if (brtdef != NULL) { |
| 452 |
|
quit(1); |
| 453 |
|
} |
| 454 |
|
} |
| 455 |
< |
efree(scanout); |
| 455 |
> |
efree((char *)scanout); |
| 456 |
|
} |
| 457 |
|
|
| 458 |
|
|
| 459 |
< |
advance() /* read in data for next scanline */ |
| 459 |
> |
static void |
| 460 |
> |
advance(void) /* read in data for next scanline */ |
| 461 |
|
{ |
| 462 |
|
int ytarget; |
| 463 |
< |
register COLOR *st; |
| 464 |
< |
register int i, j; |
| 463 |
> |
COLOR *st; |
| 464 |
> |
int i, j; |
| 465 |
|
|
| 466 |
< |
for (ytarget = (long)ypos*ymax/yres; yscan > ytarget; yscan--) |
| 466 |
> |
for (ytarget = (ypos+.5)*ymax/yres; yscan > ytarget; yscan--) |
| 467 |
|
for (i = 0; i < nfiles; i++) { |
| 468 |
|
st = input[i].scan[WINSIZ-1]; |
| 469 |
|
for (j = WINSIZ-1; j > 0; j--) /* rotate window */ |
| 471 |
|
input[i].scan[0] = st; |
| 472 |
|
if (yscan <= MIDSCN) /* hit bottom? */ |
| 473 |
|
continue; |
| 474 |
< |
if (freadscan(st, xmax, input[i].fp) < 0) { /* read */ |
| 474 |
> |
if (freadscan(st, xmax, input[i].fp) < 0) { /* read */ |
| 475 |
|
eputs(input[i].name); |
| 476 |
|
eputs(": read error\n"); |
| 477 |
|
quit(1); |
| 482 |
|
} |
| 483 |
|
|
| 484 |
|
|
| 485 |
< |
double |
| 486 |
< |
l_expos(nam) /* return picture exposure */ |
| 487 |
< |
register char *nam; |
| 485 |
> |
static double |
| 486 |
> |
l_expos( /* return picture exposure */ |
| 487 |
> |
char *nam |
| 488 |
> |
) |
| 489 |
|
{ |
| 490 |
< |
register int fn, n; |
| 490 |
> |
int fn, n; |
| 491 |
> |
double d; |
| 492 |
|
|
| 493 |
< |
fn = argument(1) - .5; |
| 494 |
< |
if (fn < 0 || fn >= nfiles) |
| 495 |
< |
return(1.0); |
| 493 |
> |
d = argument(1); |
| 494 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
| 495 |
> |
errno = EDOM; |
| 496 |
> |
return(0.0); |
| 497 |
> |
} |
| 498 |
> |
if (d < 0.5) |
| 499 |
> |
return((double)nfiles); |
| 500 |
> |
fn = d - 0.5; |
| 501 |
|
if (nam == vbrtexp) |
| 502 |
< |
return(bright(input[fn].expos)); |
| 502 |
> |
return((*ourbright)(input[fn].expos)); |
| 503 |
|
n = 3; |
| 504 |
|
while (n--) |
| 505 |
|
if (nam == vcolexp[n]) |
| 506 |
|
return(colval(input[fn].expos,n)); |
| 507 |
|
eputs("Bad call to l_expos()!\n"); |
| 508 |
|
quit(1); |
| 509 |
+ |
return 1; /* pro forma return */ |
| 510 |
|
} |
| 511 |
|
|
| 512 |
|
|
| 513 |
< |
double |
| 514 |
< |
l_colin(nam) /* return color value for picture */ |
| 382 |
< |
register char *nam; |
| 513 |
> |
static double |
| 514 |
> |
l_pixaspect(char *nm) /* return pixel aspect ratio */ |
| 515 |
|
{ |
| 516 |
|
int fn; |
| 385 |
– |
register int n, xoff, yoff; |
| 517 |
|
double d; |
| 518 |
|
|
| 519 |
|
d = argument(1); |
| 520 |
< |
if (d > -.5 && d < .5) |
| 520 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
| 521 |
> |
errno = EDOM; |
| 522 |
> |
return(0.0); |
| 523 |
> |
} |
| 524 |
> |
if (d < 0.5) |
| 525 |
|
return((double)nfiles); |
| 526 |
< |
fn = d - .5; |
| 527 |
< |
if (fn < 0 || fn >= nfiles) { |
| 526 |
> |
fn = d - 0.5; |
| 527 |
> |
return(input[fn].pa); |
| 528 |
> |
} |
| 529 |
> |
|
| 530 |
> |
|
| 531 |
> |
static double |
| 532 |
> |
l_colin( /* return color value for picture */ |
| 533 |
> |
char *nam |
| 534 |
> |
) |
| 535 |
> |
{ |
| 536 |
> |
int fn; |
| 537 |
> |
int n, xoff, yoff; |
| 538 |
> |
double d; |
| 539 |
> |
|
| 540 |
> |
d = argument(1); |
| 541 |
> |
if (d <= -0.5 || d >= nfiles+0.5) { |
| 542 |
|
errno = EDOM; |
| 543 |
|
return(0.0); |
| 544 |
|
} |
| 545 |
+ |
if (d < 0.5) |
| 546 |
+ |
return((double)nfiles); |
| 547 |
+ |
fn = d - 0.5; |
| 548 |
|
xoff = yoff = 0; |
| 549 |
|
n = nargum(); |
| 550 |
|
if (n >= 2) { |
| 576 |
|
} |
| 577 |
|
} |
| 578 |
|
if (nam == vbrtin) |
| 579 |
< |
return(bright(input[fn].scan[MIDSCN+yoff][xscan+xoff])); |
| 579 |
> |
return((*ourbright)(input[fn].scan[MIDSCN+yoff][xscan+xoff])); |
| 580 |
|
n = 3; |
| 581 |
|
while (n--) |
| 582 |
|
if (nam == vcolin[n]) |
| 583 |
|
return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n)); |
| 584 |
|
eputs("Bad call to l_colin()!\n"); |
| 585 |
|
quit(1); |
| 586 |
+ |
return 1; /* pro forma return */ |
| 587 |
|
} |
| 588 |
|
|
| 589 |
|
|
| 590 |
< |
wputs(msg) |
| 591 |
< |
char *msg; |
| 590 |
> |
static double |
| 591 |
> |
l_ray( /* return ray origin or direction */ |
| 592 |
> |
char *nam |
| 593 |
> |
) |
| 594 |
|
{ |
| 595 |
+ |
static unsigned long ltick[MAXINP]; |
| 596 |
+ |
static FVECT lorg[MAXINP], ldir[MAXINP]; |
| 597 |
+ |
static double ldist[MAXINP]; |
| 598 |
+ |
RREAL loc[2]; |
| 599 |
+ |
double d; |
| 600 |
+ |
int fn; |
| 601 |
+ |
int i; |
| 602 |
+ |
|
| 603 |
+ |
d = argument(1); |
| 604 |
+ |
if (d <= -0.5 || d >= nfiles+0.5) { |
| 605 |
+ |
errno = EDOM; |
| 606 |
+ |
return(0.0); |
| 607 |
+ |
} |
| 608 |
+ |
if (d < 0.5) |
| 609 |
+ |
return((double)nfiles); |
| 610 |
+ |
fn = d - 0.5; |
| 611 |
+ |
if (ltick[fn] != eclock) { /* need to compute? */ |
| 612 |
+ |
lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0; |
| 613 |
+ |
ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0; |
| 614 |
+ |
ldist[fn] = -1.0; |
| 615 |
+ |
if (input[fn].vw.type == 0) |
| 616 |
+ |
errno = EDOM; |
| 617 |
+ |
else { |
| 618 |
+ |
pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan); |
| 619 |
+ |
ldist[fn] = viewray(lorg[fn], ldir[fn], |
| 620 |
+ |
&input[fn].vw, loc[0], loc[1]); |
| 621 |
+ |
} |
| 622 |
+ |
ltick[fn] = eclock; |
| 623 |
+ |
} |
| 624 |
+ |
if (nam == vray[i=6]) |
| 625 |
+ |
return(ldist[fn]); |
| 626 |
+ |
while (i--) |
| 627 |
+ |
if (nam == vray[i]) |
| 628 |
+ |
return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]); |
| 629 |
+ |
eputs("Bad call to l_ray()!\n"); |
| 630 |
+ |
quit(1); |
| 631 |
+ |
return 1; /* pro forma return */ |
| 632 |
+ |
} |
| 633 |
+ |
|
| 634 |
+ |
|
| 635 |
+ |
static double |
| 636 |
+ |
l_psize(char *nm) /* compute pixel size in steradians */ |
| 637 |
+ |
{ |
| 638 |
+ |
static unsigned long ltick[MAXINP]; |
| 639 |
+ |
static double psize[MAXINP]; |
| 640 |
+ |
FVECT dir0, org, dirx, diry; |
| 641 |
+ |
RREAL locx[2], locy[2]; |
| 642 |
+ |
double d; |
| 643 |
+ |
int fn; |
| 644 |
+ |
int i; |
| 645 |
+ |
|
| 646 |
+ |
d = argument(1); |
| 647 |
+ |
if (d <= -0.5 || d >= nfiles+0.5) { |
| 648 |
+ |
errno = EDOM; |
| 649 |
+ |
return(0.0); |
| 650 |
+ |
} |
| 651 |
+ |
if (d < 0.5) |
| 652 |
+ |
return((double)nfiles); |
| 653 |
+ |
fn = d - 0.5; |
| 654 |
+ |
if (ltick[fn] != eclock) { /* need to compute? */ |
| 655 |
+ |
psize[fn] = 0.0; |
| 656 |
+ |
if (input[fn].vw.type == 0) |
| 657 |
+ |
errno = EDOM; |
| 658 |
+ |
else if (input[fn].vw.type != VT_PAR && |
| 659 |
+ |
funvalue(vray[6], 1, &d) >= -FTINY) { |
| 660 |
+ |
for (i = 0; i < 3; i++) |
| 661 |
+ |
dir0[i] = funvalue(vray[3+i], 1, &d); |
| 662 |
+ |
pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan); |
| 663 |
+ |
pix2loc(locy, &input[fn].rs, xscan, ymax-yscan); |
| 664 |
+ |
if (viewray(org, dirx, &input[fn].vw, |
| 665 |
+ |
locx[0], locx[1]) >= -FTINY && |
| 666 |
+ |
viewray(org, diry, &input[fn].vw, |
| 667 |
+ |
locy[0], locy[1]) >= -FTINY) { |
| 668 |
+ |
/* approximate solid angle */ |
| 669 |
+ |
for (i = 0; i < 3; i++) { |
| 670 |
+ |
dirx[i] -= dir0[i]; |
| 671 |
+ |
diry[i] -= dir0[i]; |
| 672 |
+ |
} |
| 673 |
+ |
fcross(dir0, dirx, diry); |
| 674 |
+ |
psize[fn] = VLEN(dir0); |
| 675 |
+ |
} |
| 676 |
+ |
} |
| 677 |
+ |
ltick[fn] = eclock; |
| 678 |
+ |
} |
| 679 |
+ |
return(psize[fn]); |
| 680 |
+ |
} |
| 681 |
+ |
|
| 682 |
+ |
|
| 683 |
+ |
extern void |
| 684 |
+ |
wputs(const char *msg) |
| 685 |
+ |
{ |
| 686 |
|
if (!nowarn) |
| 687 |
|
eputs(msg); |
| 688 |
|
} |
| 689 |
|
|
| 690 |
|
|
| 691 |
< |
eputs(msg) |
| 692 |
< |
char *msg; |
| 691 |
> |
extern void |
| 692 |
> |
eputs(const char *msg) |
| 693 |
|
{ |
| 694 |
|
fputs(msg, stderr); |
| 695 |
|
} |
| 696 |
|
|
| 697 |
|
|
| 698 |
< |
quit(code) |
| 699 |
< |
int code; |
| 698 |
> |
extern void |
| 699 |
> |
quit(int code) /* exit gracefully */ |
| 700 |
|
{ |
| 701 |
< |
int status; |
| 702 |
< |
|
| 703 |
< |
if (code == 0) /* reap any children */ |
| 704 |
< |
while (wait(&status) != -1) |
| 705 |
< |
if (code == 0) |
| 706 |
< |
code = status>>8 & 0xff; |
| 701 |
> |
int i; |
| 702 |
> |
/* close input files */ |
| 703 |
> |
for (i = 0; i < nfiles; i++) |
| 704 |
> |
if (input[i].name == Command) |
| 705 |
> |
pclose(input[i].fp); |
| 706 |
> |
else |
| 707 |
> |
fclose(input[i].fp); |
| 708 |
|
exit(code); |
| 709 |
|
} |