| 1 | greg | 1.1 | #ifndef lint | 
| 2 | greg | 2.47 | static const char       RCSid[] = "$Id: pcomb.c,v 2.46 2016/08/01 00:08:53 greg Exp $"; | 
| 3 | greg | 1.1 | #endif | 
| 4 |  |  | /* | 
| 5 |  |  | *  Combine picture files according to calcomp functions. | 
| 6 |  |  | * | 
| 7 |  |  | *      1/4/89 | 
| 8 |  |  | */ | 
| 9 |  |  |  | 
| 10 | greg | 2.28 | #include "platform.h" | 
| 11 | greg | 2.33 | #include "standard.h" | 
| 12 | greg | 2.45 | #include "paths.h" | 
| 13 | greg | 1.1 | #include "color.h" | 
| 14 |  |  | #include "calcomp.h" | 
| 15 | greg | 2.10 | #include "view.h" | 
| 16 |  |  |  | 
| 17 | greg | 2.44 | #define MAXINP          1024            /* maximum number of input files */ | 
| 18 | greg | 2.46 | #define WINSIZ          127             /* scanline window size */ | 
| 19 | greg | 2.13 | #define MIDSCN          ((WINSIZ-1)/2+1) | 
| 20 | greg | 1.1 |  | 
| 21 |  |  | struct { | 
| 22 | greg | 1.19 | char    *name;          /* file or command name */ | 
| 23 | greg | 1.1 | FILE    *fp;            /* stream pointer */ | 
| 24 | greg | 2.10 | VIEW    vw;             /* view for picture */ | 
| 25 |  |  | RESOLU  rs;             /* image resolution and orientation */ | 
| 26 | greg | 2.17 | float   pa;             /* pixel aspect ratio */ | 
| 27 | greg | 1.14 | COLOR   *scan[WINSIZ];  /* input scanline window */ | 
| 28 | greg | 1.3 | COLOR   coef;           /* coefficient */ | 
| 29 | greg | 1.17 | COLOR   expos;          /* recorded exposure */ | 
| 30 | greg | 1.1 | }       input[MAXINP];                  /* input pictures */ | 
| 31 |  |  |  | 
| 32 |  |  | int     nfiles;                         /* number of input files */ | 
| 33 |  |  |  | 
| 34 | greg | 2.16 | char    ourfmt[LPICFMT+1] = PICFMT;     /* input picture format */ | 
| 35 |  |  |  | 
| 36 | greg | 2.31 | char    StandardInput[] = "<stdin>"; | 
| 37 | greg | 2.6 | char    Command[] = "<Command>"; | 
| 38 | greg | 1.21 | char    vcolin[3][4] = {"ri", "gi", "bi"}; | 
| 39 |  |  | char    vcolout[3][4] = {"ro", "go", "bo"}; | 
| 40 | greg | 1.15 | char    vbrtin[] = "li"; | 
| 41 |  |  | char    vbrtout[] = "lo"; | 
| 42 | greg | 1.21 | char    vcolexp[3][4] = {"re", "ge", "be"}; | 
| 43 | greg | 1.17 | char    vbrtexp[] = "le"; | 
| 44 | greg | 2.18 | char    vpixaspect[] = "pa"; | 
| 45 | greg | 1.1 |  | 
| 46 | greg | 2.18 | char    vray[7][4] = {"Ox", "Oy", "Oz", "Dx", "Dy", "Dz", "T"}; | 
| 47 | greg | 2.10 |  | 
| 48 | greg | 2.17 | char    vpsize[] = "S"; | 
| 49 |  |  |  | 
| 50 | greg | 1.18 | char    vnfiles[] = "nfiles"; | 
| 51 | greg | 2.18 | char    vwhteff[] = "WE"; | 
| 52 | greg | 1.18 | char    vxmax[] = "xmax"; | 
| 53 |  |  | char    vymax[] = "ymax"; | 
| 54 |  |  | char    vxres[] = "xres"; | 
| 55 |  |  | char    vyres[] = "yres"; | 
| 56 |  |  | char    vxpos[] = "x"; | 
| 57 |  |  | char    vypos[] = "y"; | 
| 58 | greg | 1.1 |  | 
| 59 |  |  | int     nowarn = 0;                     /* no warning messages? */ | 
| 60 |  |  |  | 
| 61 | greg | 1.18 | int     xmax = 0, ymax = 0;             /* input resolution */ | 
| 62 | greg | 1.9 |  | 
| 63 | greg | 1.18 | int     xscan, yscan;                   /* input position */ | 
| 64 | greg | 1.1 |  | 
| 65 | greg | 1.18 | int     xres, yres;                     /* output resolution */ | 
| 66 | greg | 1.1 |  | 
| 67 | greg | 1.18 | int     xpos, ypos;                     /* output position */ | 
| 68 |  |  |  | 
| 69 | greg | 2.10 | char    *progname;                      /* global argv[0] */ | 
| 70 |  |  |  | 
| 71 | greg | 2.39 | int     echoheader = 1; | 
| 72 | greg | 1.10 | int     wrongformat = 0; | 
| 73 | greg | 2.10 | int     gotview; | 
| 74 | greg | 1.1 |  | 
| 75 | greg | 1.10 |  | 
| 76 | greg | 2.39 | static gethfunc headline; | 
| 77 | schorsch | 2.32 | static void checkfile(void); | 
| 78 |  |  | static double rgb_bright(COLOR  clr); | 
| 79 |  |  | static double xyz_bright(COLOR  clr); | 
| 80 |  |  | static void init(void); | 
| 81 |  |  | static void combine(void); | 
| 82 |  |  | static void advance(void); | 
| 83 |  |  | static double l_expos(char      *nam); | 
| 84 |  |  | static double l_pixaspect(char *nm); | 
| 85 |  |  | static double l_colin(char      *nam); | 
| 86 |  |  | static double l_ray(char        *nam); | 
| 87 |  |  | static double l_psize(char *nm); | 
| 88 |  |  |  | 
| 89 |  |  |  | 
| 90 |  |  | int | 
| 91 |  |  | main( | 
| 92 |  |  | int     argc, | 
| 93 |  |  | char    *argv[] | 
| 94 |  |  | ) | 
| 95 | greg | 1.1 | { | 
| 96 | greg | 1.18 | int     original; | 
| 97 | greg | 1.3 | double  f; | 
| 98 | schorsch | 2.32 | int     a; | 
| 99 | greg | 2.47 |  | 
| 100 | schorsch | 2.23 | SET_DEFAULT_BINARY(); | 
| 101 |  |  | SET_FILE_BINARY(stdin); | 
| 102 |  |  | SET_FILE_BINARY(stdout); | 
| 103 | greg | 2.10 | progname = argv[0]; | 
| 104 | greg | 2.47 | esupport |= E_VARIABLE|E_FUNCTION|E_RCONST; | 
| 105 |  |  | esupport &= ~(E_OUTCHAN|E_INCHAN); | 
| 106 | greg | 1.15 | /* scan options */ | 
| 107 |  |  | for (a = 1; a < argc; a++) { | 
| 108 | greg | 1.1 | if (argv[a][0] == '-') | 
| 109 |  |  | switch (argv[a][1]) { | 
| 110 |  |  | case 'x': | 
| 111 |  |  | case 'y': | 
| 112 | greg | 1.18 | a++; | 
| 113 | greg | 1.15 | continue; | 
| 114 | greg | 1.1 | case 'w': | 
| 115 |  |  | nowarn = !nowarn; | 
| 116 | greg | 1.15 | continue; | 
| 117 | greg | 2.39 | case 'h': | 
| 118 |  |  | echoheader = !echoheader; | 
| 119 |  |  | continue; | 
| 120 | greg | 1.1 | case 'f': | 
| 121 |  |  | case 'e': | 
| 122 | greg | 1.16 | a++; | 
| 123 | greg | 1.15 | continue; | 
| 124 | greg | 1.1 | } | 
| 125 | greg | 1.15 | break; | 
| 126 |  |  | } | 
| 127 | greg | 2.14 | newheader("RADIANCE", stdout);  /* start header */ | 
| 128 | greg | 2.22 | fputnow(stdout); | 
| 129 | greg | 1.15 | /* process files */ | 
| 130 | greg | 1.17 | for (nfiles = 0; nfiles < MAXINP; nfiles++) { | 
| 131 | greg | 1.3 | setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); | 
| 132 | greg | 1.17 | setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); | 
| 133 | schorsch | 2.26 | input[nfiles].vw = stdview; | 
| 134 | greg | 2.17 | input[nfiles].pa = 1.0; | 
| 135 | greg | 1.17 | } | 
| 136 | greg | 1.1 | nfiles = 0; | 
| 137 | greg | 1.18 | original = 0; | 
| 138 | greg | 1.1 | for ( ; a < argc; a++) { | 
| 139 |  |  | if (nfiles >= MAXINP) { | 
| 140 |  |  | eputs(argv[0]); | 
| 141 |  |  | eputs(": too many picture files\n"); | 
| 142 |  |  | quit(1); | 
| 143 |  |  | } | 
| 144 | greg | 1.3 | if (argv[a][0] == '-') | 
| 145 |  |  | switch (argv[a][1]) { | 
| 146 |  |  | case '\0': | 
| 147 | greg | 2.31 | input[nfiles].name = StandardInput; | 
| 148 | greg | 1.3 | input[nfiles].fp = stdin; | 
| 149 |  |  | break; | 
| 150 | greg | 1.17 | case 'o': | 
| 151 |  |  | original++; | 
| 152 | greg | 1.22 | continue; | 
| 153 | greg | 1.3 | case 's': | 
| 154 |  |  | f = atof(argv[++a]); | 
| 155 |  |  | scalecolor(input[nfiles].coef, f); | 
| 156 |  |  | continue; | 
| 157 |  |  | case 'c': | 
| 158 |  |  | colval(input[nfiles].coef,RED)*=atof(argv[++a]); | 
| 159 |  |  | colval(input[nfiles].coef,GRN)*=atof(argv[++a]); | 
| 160 |  |  | colval(input[nfiles].coef,BLU)*=atof(argv[++a]); | 
| 161 |  |  | continue; | 
| 162 |  |  | default: | 
| 163 |  |  | goto usage; | 
| 164 |  |  | } | 
| 165 |  |  | else { | 
| 166 | greg | 2.2 | if (argv[a][0] == '!') { | 
| 167 | greg | 2.6 | input[nfiles].name = Command; | 
| 168 | greg | 2.2 | input[nfiles].fp = popen(argv[a]+1, "r"); | 
| 169 |  |  | } else { | 
| 170 |  |  | input[nfiles].name = argv[a]; | 
| 171 |  |  | input[nfiles].fp = fopen(argv[a], "r"); | 
| 172 |  |  | } | 
| 173 | greg | 1.1 | if (input[nfiles].fp == NULL) { | 
| 174 | greg | 1.6 | perror(argv[a]); | 
| 175 | greg | 1.1 | quit(1); | 
| 176 |  |  | } | 
| 177 |  |  | } | 
| 178 | greg | 1.16 | checkfile(); | 
| 179 | greg | 1.18 | if (original) { | 
| 180 |  |  | colval(input[nfiles].coef,RED) /= | 
| 181 |  |  | colval(input[nfiles].expos,RED); | 
| 182 |  |  | colval(input[nfiles].coef,GRN) /= | 
| 183 |  |  | colval(input[nfiles].expos,GRN); | 
| 184 |  |  | colval(input[nfiles].coef,BLU) /= | 
| 185 |  |  | colval(input[nfiles].expos,BLU); | 
| 186 | greg | 2.22 | setcolor(input[nfiles].expos, 1.0, 1.0, 1.0); | 
| 187 | greg | 1.18 | } | 
| 188 |  |  | nfiles++; | 
| 189 | greg | 1.17 | original = 0; | 
| 190 | greg | 1.15 | } | 
| 191 | greg | 1.18 | init();                         /* set constants */ | 
| 192 | greg | 1.15 | /* go back and get expressions */ | 
| 193 |  |  | for (a = 1; a < argc; a++) { | 
| 194 |  |  | if (argv[a][0] == '-') | 
| 195 |  |  | switch (argv[a][1]) { | 
| 196 |  |  | case 'x': | 
| 197 | greg | 1.21 | varset(vxres, ':', eval(argv[++a])); | 
| 198 | greg | 1.18 | continue; | 
| 199 | greg | 1.15 | case 'y': | 
| 200 | greg | 1.21 | varset(vyres, ':', eval(argv[++a])); | 
| 201 | greg | 1.16 | continue; | 
| 202 | greg | 1.15 | case 'w': | 
| 203 |  |  | continue; | 
| 204 | greg | 2.40 | case 'h': | 
| 205 |  |  | continue; | 
| 206 | greg | 1.15 | case 'f': | 
| 207 |  |  | fcompile(argv[++a]); | 
| 208 |  |  | continue; | 
| 209 |  |  | case 'e': | 
| 210 |  |  | scompile(argv[++a], NULL, 0); | 
| 211 |  |  | continue; | 
| 212 |  |  | } | 
| 213 |  |  | break; | 
| 214 |  |  | } | 
| 215 | greg | 1.18 | /* set/get output resolution */ | 
| 216 |  |  | if (!vardefined(vxres)) | 
| 217 |  |  | varset(vxres, ':', (double)xmax); | 
| 218 |  |  | if (!vardefined(vyres)) | 
| 219 |  |  | varset(vyres, ':', (double)ymax); | 
| 220 |  |  | xres = varvalue(vxres) + .5; | 
| 221 |  |  | yres = varvalue(vyres) + .5; | 
| 222 |  |  | if (xres <= 0 || yres <= 0) { | 
| 223 |  |  | eputs(argv[0]); | 
| 224 |  |  | eputs(": illegal output resolution\n"); | 
| 225 |  |  | quit(1); | 
| 226 |  |  | } | 
| 227 | greg | 1.15 | /* complete header */ | 
| 228 |  |  | printargs(argc, argv, stdout); | 
| 229 | greg | 2.16 | if (strcmp(ourfmt, PICFMT)) | 
| 230 |  |  | fputformat(ourfmt, stdout);     /* print format if known */ | 
| 231 | greg | 1.15 | putchar('\n'); | 
| 232 | greg | 1.23 | fprtresolu(xres, yres, stdout); | 
| 233 | greg | 1.15 | /* combine pictures */ | 
| 234 |  |  | combine(); | 
| 235 |  |  | quit(0); | 
| 236 |  |  | usage: | 
| 237 |  |  | eputs("Usage: "); | 
| 238 |  |  | eputs(argv[0]); | 
| 239 |  |  | eputs( | 
| 240 | greg | 2.43 | " [-w][-h][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] hdr ..]\n"); | 
| 241 | greg | 1.15 | quit(1); | 
| 242 | schorsch | 2.32 | return 1; /* pro forma return */ | 
| 243 | greg | 1.15 | } | 
| 244 |  |  |  | 
| 245 |  |  |  | 
| 246 | schorsch | 2.30 | static int | 
| 247 | greg | 2.39 | headline(                       /* check header line & echo if requested */ | 
| 248 | schorsch | 2.30 | char    *s, | 
| 249 |  |  | void    *p | 
| 250 |  |  | ) | 
| 251 | greg | 1.15 | { | 
| 252 |  |  | char    fmt[32]; | 
| 253 |  |  | double  d; | 
| 254 |  |  | COLOR   ctmp; | 
| 255 |  |  |  | 
| 256 | greg | 2.14 | if (isheadid(s))                        /* header id */ | 
| 257 | gwlarson | 2.21 | return(0);      /* don't echo */ | 
| 258 | greg | 2.14 | if (formatval(fmt, s)) {                /* check format */ | 
| 259 | greg | 2.16 | if (globmatch(ourfmt, fmt)) { | 
| 260 |  |  | wrongformat = 0; | 
| 261 |  |  | strcpy(ourfmt, fmt); | 
| 262 |  |  | } else | 
| 263 | greg | 2.22 | wrongformat = globmatch(PICFMT, fmt) ? 1 : -1; | 
| 264 | gwlarson | 2.21 | return(0);      /* don't echo */ | 
| 265 | greg | 1.17 | } | 
| 266 |  |  | if (isexpos(s)) {                       /* exposure */ | 
| 267 |  |  | d = exposval(s); | 
| 268 |  |  | scalecolor(input[nfiles].expos, d); | 
| 269 |  |  | } else if (iscolcor(s)) {               /* color correction */ | 
| 270 | greg | 1.15 | colcorval(ctmp, s); | 
| 271 | greg | 1.17 | multcolor(input[nfiles].expos, ctmp); | 
| 272 | greg | 2.18 | } else if (isaspect(s)) | 
| 273 | greg | 2.17 | input[nfiles].pa *= aspectval(s); | 
| 274 | greg | 2.18 | else if (isview(s) && sscanview(&input[nfiles].vw, s) > 0) | 
| 275 | greg | 2.10 | gotview++; | 
| 276 | greg | 2.39 |  | 
| 277 |  |  | if (echoheader) {                       /* echo line */ | 
| 278 |  |  | putchar('\t'); | 
| 279 |  |  | return(fputs(s, stdout)); | 
| 280 |  |  | } | 
| 281 |  |  | return(0); | 
| 282 | greg | 1.16 | } | 
| 283 | greg | 1.15 |  | 
| 284 | greg | 1.16 |  | 
| 285 | schorsch | 2.32 | static void | 
| 286 |  |  | checkfile(void)                 /* ready a file */ | 
| 287 | greg | 1.16 | { | 
| 288 | greg | 2.47 | int     i; | 
| 289 | greg | 1.16 | /* process header */ | 
| 290 | greg | 2.10 | gotview = 0; | 
| 291 | greg | 2.39 | if (echoheader) { | 
| 292 |  |  | fputs(input[nfiles].name, stdout); | 
| 293 |  |  | fputs(":\n", stdout); | 
| 294 |  |  | } | 
| 295 |  |  | getheader(input[nfiles].fp, headline, NULL); | 
| 296 | greg | 2.22 | if (wrongformat < 0) { | 
| 297 | greg | 1.16 | eputs(input[nfiles].name); | 
| 298 | greg | 2.22 | eputs(": not a Radiance picture\n"); | 
| 299 | greg | 1.16 | quit(1); | 
| 300 |  |  | } | 
| 301 | greg | 2.22 | if (wrongformat > 0) { | 
| 302 |  |  | wputs(input[nfiles].name); | 
| 303 |  |  | wputs(": warning -- incompatible picture format\n"); | 
| 304 |  |  | } | 
| 305 | greg | 2.10 | if (!gotview || setview(&input[nfiles].vw) != NULL) | 
| 306 |  |  | input[nfiles].vw.type = 0; | 
| 307 |  |  | if (!fgetsresolu(&input[nfiles].rs, input[nfiles].fp)) { | 
| 308 | greg | 1.16 | eputs(input[nfiles].name); | 
| 309 |  |  | eputs(": bad picture size\n"); | 
| 310 |  |  | quit(1); | 
| 311 |  |  | } | 
| 312 | greg | 1.18 | if (xmax == 0 && ymax == 0) { | 
| 313 | greg | 2.10 | xmax = scanlen(&input[nfiles].rs); | 
| 314 |  |  | ymax = numscans(&input[nfiles].rs); | 
| 315 |  |  | } else if (scanlen(&input[nfiles].rs) != xmax || | 
| 316 |  |  | numscans(&input[nfiles].rs) != ymax) { | 
| 317 | greg | 1.16 | eputs(input[nfiles].name); | 
| 318 |  |  | eputs(": resolution mismatch\n"); | 
| 319 |  |  | quit(1); | 
| 320 |  |  | } | 
| 321 |  |  | /* allocate scanlines */ | 
| 322 |  |  | for (i = 0; i < WINSIZ; i++) | 
| 323 | greg | 1.18 | input[nfiles].scan[i] = (COLOR *)emalloc(xmax*sizeof(COLOR)); | 
| 324 | greg | 1.15 | } | 
| 325 |  |  |  | 
| 326 |  |  |  | 
| 327 | schorsch | 2.32 | static double | 
| 328 |  |  | rgb_bright( | 
| 329 |  |  | COLOR  clr | 
| 330 |  |  | ) | 
| 331 | greg | 2.16 | { | 
| 332 |  |  | return(bright(clr)); | 
| 333 |  |  | } | 
| 334 |  |  |  | 
| 335 |  |  |  | 
| 336 | schorsch | 2.32 | static double | 
| 337 |  |  | xyz_bright( | 
| 338 |  |  | COLOR  clr | 
| 339 |  |  | ) | 
| 340 | greg | 2.16 | { | 
| 341 |  |  | return(clr[CIEY]); | 
| 342 |  |  | } | 
| 343 |  |  |  | 
| 344 |  |  |  | 
| 345 |  |  | double  (*ourbright)() = rgb_bright; | 
| 346 |  |  |  | 
| 347 |  |  |  | 
| 348 | schorsch | 2.32 | static void | 
| 349 |  |  | init(void)                                      /* perform final setup */ | 
| 350 | greg | 1.15 | { | 
| 351 | greg | 2.47 | int     i; | 
| 352 | greg | 1.15 | /* define constants */ | 
| 353 | greg | 2.19 | varset("PI", ':', PI); | 
| 354 | greg | 1.15 | varset(vnfiles, ':', (double)nfiles); | 
| 355 | greg | 1.18 | varset(vxmax, ':', (double)xmax); | 
| 356 |  |  | varset(vymax, ':', (double)ymax); | 
| 357 | greg | 1.15 | /* set functions */ | 
| 358 |  |  | for (i = 0; i < 3; i++) { | 
| 359 | greg | 1.17 | funset(vcolexp[i], 1, ':', l_expos); | 
| 360 | greg | 1.15 | funset(vcolin[i], 1, '=', l_colin); | 
| 361 |  |  | } | 
| 362 | greg | 1.17 | funset(vbrtexp, 1, ':', l_expos); | 
| 363 | greg | 1.15 | funset(vbrtin, 1, '=', l_colin); | 
| 364 | greg | 2.18 | funset(vpixaspect, 1, ':', l_pixaspect); | 
| 365 |  |  | for (i = 0; i < 7; i++) | 
| 366 | greg | 2.10 | funset(vray[i], 1, '=', l_ray); | 
| 367 | greg | 2.17 | funset(vpsize, 1, '=', l_psize); | 
| 368 | greg | 2.16 | /* set brightness function */ | 
| 369 | greg | 2.18 | if (!strcmp(ourfmt, CIEFMT)) { | 
| 370 |  |  | varset(vwhteff, ':', 1.0); | 
| 371 | greg | 2.16 | ourbright = xyz_bright; | 
| 372 | greg | 2.18 | } else | 
| 373 |  |  | varset(vwhteff, ':', WHTEFFICACY); | 
| 374 | greg | 1.1 | } | 
| 375 |  |  |  | 
| 376 |  |  |  | 
| 377 | schorsch | 2.32 | static void | 
| 378 |  |  | combine(void)                   /* combine pictures */ | 
| 379 | greg | 1.1 | { | 
| 380 | greg | 1.8 | EPNODE  *coldef[3], *brtdef; | 
| 381 | greg | 1.1 | COLOR   *scanout; | 
| 382 | greg | 1.8 | double  d; | 
| 383 | greg | 2.47 | int     i, j; | 
| 384 | greg | 1.1 | /* check defined variables */ | 
| 385 | greg | 1.4 | for (j = 0; j < 3; j++) { | 
| 386 |  |  | if (vardefined(vcolout[j])) | 
| 387 |  |  | coldef[j] = eparse(vcolout[j]); | 
| 388 |  |  | else | 
| 389 |  |  | coldef[j] = NULL; | 
| 390 |  |  | } | 
| 391 | greg | 1.8 | if (vardefined(vbrtout)) | 
| 392 |  |  | brtdef = eparse(vbrtout); | 
| 393 |  |  | else | 
| 394 |  |  | brtdef = NULL; | 
| 395 | greg | 1.1 | /* allocate scanline */ | 
| 396 |  |  | scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); | 
| 397 | greg | 1.18 | /* set input position */ | 
| 398 |  |  | yscan = ymax+MIDSCN; | 
| 399 | greg | 1.1 | /* combine files */ | 
| 400 |  |  | for (ypos = yres-1; ypos >= 0; ypos--) { | 
| 401 | greg | 1.14 | advance(); | 
| 402 | greg | 1.11 | varset(vypos, '=', (double)ypos); | 
| 403 | greg | 1.8 | for (xpos = 0; xpos < xres; xpos++) { | 
| 404 | greg | 2.42 | xscan = (xpos+.5)*xmax/xres; | 
| 405 | greg | 1.11 | varset(vxpos, '=', (double)xpos); | 
| 406 | greg | 1.8 | eclock++; | 
| 407 |  |  | if (brtdef != NULL) { | 
| 408 |  |  | d = evalue(brtdef); | 
| 409 |  |  | if (d < 0.0) | 
| 410 |  |  | d = 0.0; | 
| 411 |  |  | setcolor(scanout[xpos], d, d, d); | 
| 412 |  |  | } else { | 
| 413 |  |  | for (j = 0; j < 3; j++) { | 
| 414 |  |  | if (coldef[j] != NULL) { | 
| 415 | greg | 1.13 | d = evalue(coldef[j]); | 
| 416 | greg | 1.8 | } else { | 
| 417 | greg | 1.13 | d = 0.0; | 
| 418 | greg | 1.8 | for (i = 0; i < nfiles; i++) | 
| 419 | greg | 1.18 | d += colval(input[i].scan[MIDSCN][xscan],j); | 
| 420 | greg | 1.1 | } | 
| 421 | greg | 1.13 | if (d < 0.0) | 
| 422 |  |  | d = 0.0; | 
| 423 |  |  | colval(scanout[xpos],j) = d; | 
| 424 | greg | 1.8 | } | 
| 425 | greg | 1.1 | } | 
| 426 | greg | 1.8 | } | 
| 427 |  |  | if (fwritescan(scanout, xres, stdout) < 0) { | 
| 428 |  |  | perror("write error"); | 
| 429 |  |  | quit(1); | 
| 430 |  |  | } | 
| 431 | greg | 1.1 | } | 
| 432 | greg | 2.22 | efree((char *)scanout); | 
| 433 | greg | 1.1 | } | 
| 434 |  |  |  | 
| 435 |  |  |  | 
| 436 | schorsch | 2.32 | static void | 
| 437 |  |  | advance(void)                   /* read in data for next scanline */ | 
| 438 | greg | 1.14 | { | 
| 439 | greg | 1.18 | int     ytarget; | 
| 440 | greg | 2.47 | COLOR   *st; | 
| 441 |  |  | int     i, j; | 
| 442 | greg | 1.14 |  | 
| 443 | greg | 2.42 | for (ytarget = (ypos+.5)*ymax/yres; yscan > ytarget; yscan--) | 
| 444 | greg | 1.18 | for (i = 0; i < nfiles; i++) { | 
| 445 |  |  | st = input[i].scan[WINSIZ-1]; | 
| 446 |  |  | for (j = WINSIZ-1; j > 0; j--)  /* rotate window */ | 
| 447 |  |  | input[i].scan[j] = input[i].scan[j-1]; | 
| 448 |  |  | input[i].scan[0] = st; | 
| 449 |  |  | if (yscan <= MIDSCN)            /* hit bottom? */ | 
| 450 |  |  | continue; | 
| 451 | greg | 2.4 | if (freadscan(st, xmax, input[i].fp) < 0) {  /* read */ | 
| 452 | greg | 1.18 | eputs(input[i].name); | 
| 453 |  |  | eputs(": read error\n"); | 
| 454 |  |  | quit(1); | 
| 455 |  |  | } | 
| 456 | greg | 2.37 | for (j = 0; j < xmax; j++)      /* adjust color */ | 
| 457 |  |  | multcolor(st[j], input[i].coef); | 
| 458 | greg | 1.14 | } | 
| 459 |  |  | } | 
| 460 |  |  |  | 
| 461 |  |  |  | 
| 462 | schorsch | 2.32 | static double | 
| 463 |  |  | l_expos(                        /* return picture exposure */ | 
| 464 | greg | 2.42 | char    *nam | 
| 465 | schorsch | 2.32 | ) | 
| 466 | greg | 1.1 | { | 
| 467 | greg | 2.42 | int     fn, n; | 
| 468 |  |  | double  d; | 
| 469 | greg | 1.14 |  | 
| 470 | greg | 2.42 | d = argument(1); | 
| 471 |  |  | if (d <= -0.5 || d >= nfiles+0.5) { | 
| 472 |  |  | errno = EDOM; | 
| 473 |  |  | return(0.0); | 
| 474 |  |  | } | 
| 475 |  |  | if (d < 0.5) | 
| 476 |  |  | return((double)nfiles); | 
| 477 |  |  | fn = d - 0.5; | 
| 478 | greg | 1.17 | if (nam == vbrtexp) | 
| 479 | greg | 2.16 | return((*ourbright)(input[fn].expos)); | 
| 480 | greg | 1.15 | n = 3; | 
| 481 |  |  | while (n--) | 
| 482 | greg | 1.17 | if (nam == vcolexp[n]) | 
| 483 |  |  | return(colval(input[fn].expos,n)); | 
| 484 |  |  | eputs("Bad call to l_expos()!\n"); | 
| 485 | greg | 1.15 | quit(1); | 
| 486 | schorsch | 2.32 | return 1; /* pro forma return */ | 
| 487 | greg | 1.15 | } | 
| 488 |  |  |  | 
| 489 |  |  |  | 
| 490 | schorsch | 2.32 | static double | 
| 491 | greg | 2.27 | l_pixaspect(char *nm)           /* return pixel aspect ratio */ | 
| 492 | greg | 2.18 | { | 
| 493 | greg | 2.42 | int     fn; | 
| 494 |  |  | double  d; | 
| 495 | greg | 2.18 |  | 
| 496 | greg | 2.42 | d = argument(1); | 
| 497 |  |  | if (d <= -0.5 || d >= nfiles+0.5) { | 
| 498 |  |  | errno = EDOM; | 
| 499 |  |  | return(0.0); | 
| 500 |  |  | } | 
| 501 |  |  | if (d < 0.5) | 
| 502 |  |  | return((double)nfiles); | 
| 503 |  |  | fn = d - 0.5; | 
| 504 | greg | 2.18 | return(input[fn].pa); | 
| 505 |  |  | } | 
| 506 |  |  |  | 
| 507 |  |  |  | 
| 508 | schorsch | 2.32 | static double | 
| 509 |  |  | l_colin(                        /* return color value for picture */ | 
| 510 | greg | 2.47 | char    *nam | 
| 511 | schorsch | 2.32 | ) | 
| 512 | greg | 1.15 | { | 
| 513 |  |  | int     fn; | 
| 514 | greg | 2.47 | int     n, xoff, yoff; | 
| 515 | greg | 1.15 | double  d; | 
| 516 |  |  |  | 
| 517 | greg | 2.42 | d = argument(1); | 
| 518 |  |  | if (d <= -0.5 || d >= nfiles+0.5) { | 
| 519 | greg | 1.15 | errno = EDOM; | 
| 520 |  |  | return(0.0); | 
| 521 |  |  | } | 
| 522 | greg | 2.42 | if (d < 0.5) | 
| 523 |  |  | return((double)nfiles); | 
| 524 |  |  | fn = d - 0.5; | 
| 525 | greg | 1.14 | xoff = yoff = 0; | 
| 526 |  |  | n = nargum(); | 
| 527 |  |  | if (n >= 2) { | 
| 528 |  |  | d = argument(2); | 
| 529 |  |  | if (d < 0.0) { | 
| 530 |  |  | xoff = d-.5; | 
| 531 | greg | 1.18 | if (xscan+xoff < 0) | 
| 532 |  |  | xoff = -xscan; | 
| 533 | greg | 1.14 | } else { | 
| 534 |  |  | xoff = d+.5; | 
| 535 | greg | 1.18 | if (xscan+xoff >= xmax) | 
| 536 |  |  | xoff = xmax-1-xscan; | 
| 537 | greg | 1.14 | } | 
| 538 |  |  | } | 
| 539 |  |  | if (n >= 3) { | 
| 540 |  |  | d = argument(3); | 
| 541 |  |  | if (d < 0.0) { | 
| 542 |  |  | yoff = d-.5; | 
| 543 |  |  | if (yoff+MIDSCN < 0) | 
| 544 |  |  | yoff = -MIDSCN; | 
| 545 | greg | 1.18 | if (yscan+yoff < 0) | 
| 546 |  |  | yoff = -yscan; | 
| 547 | greg | 1.14 | } else { | 
| 548 |  |  | yoff = d+.5; | 
| 549 |  |  | if (yoff+MIDSCN >= WINSIZ) | 
| 550 |  |  | yoff = WINSIZ-1-MIDSCN; | 
| 551 | greg | 1.18 | if (yscan+yoff >= ymax) | 
| 552 |  |  | yoff = ymax-1-yscan; | 
| 553 | greg | 1.14 | } | 
| 554 |  |  | } | 
| 555 | greg | 1.15 | if (nam == vbrtin) | 
| 556 | greg | 2.16 | return((*ourbright)(input[fn].scan[MIDSCN+yoff][xscan+xoff])); | 
| 557 | greg | 1.15 | n = 3; | 
| 558 |  |  | while (n--) | 
| 559 |  |  | if (nam == vcolin[n]) | 
| 560 | greg | 1.18 | return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n)); | 
| 561 | greg | 1.15 | eputs("Bad call to l_colin()!\n"); | 
| 562 | greg | 2.10 | quit(1); | 
| 563 | schorsch | 2.32 | return 1; /* pro forma return */ | 
| 564 | greg | 2.10 | } | 
| 565 |  |  |  | 
| 566 |  |  |  | 
| 567 | schorsch | 2.32 | static double | 
| 568 |  |  | l_ray(          /* return ray origin or direction */ | 
| 569 | greg | 2.47 | char    *nam | 
| 570 | schorsch | 2.32 | ) | 
| 571 | greg | 2.10 | { | 
| 572 | greg | 2.15 | static unsigned long    ltick[MAXINP]; | 
| 573 | greg | 2.10 | static FVECT    lorg[MAXINP], ldir[MAXINP]; | 
| 574 | greg | 2.18 | static double   ldist[MAXINP]; | 
| 575 | schorsch | 2.25 | RREAL   loc[2]; | 
| 576 | greg | 2.42 | double  d; | 
| 577 | greg | 2.10 | int     fn; | 
| 578 | greg | 2.47 | int     i; | 
| 579 | greg | 2.10 |  | 
| 580 | greg | 2.42 | d = argument(1); | 
| 581 |  |  | if (d <= -0.5 || d >= nfiles+0.5) { | 
| 582 | greg | 2.10 | errno = EDOM; | 
| 583 |  |  | return(0.0); | 
| 584 |  |  | } | 
| 585 | greg | 2.42 | if (d < 0.5) | 
| 586 |  |  | return((double)nfiles); | 
| 587 |  |  | fn = d - 0.5; | 
| 588 | greg | 2.22 | if (ltick[fn] != eclock) {              /* need to compute? */ | 
| 589 | greg | 2.10 | lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0; | 
| 590 |  |  | ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0; | 
| 591 | greg | 2.20 | ldist[fn] = -1.0; | 
| 592 | greg | 2.10 | if (input[fn].vw.type == 0) | 
| 593 | greg | 2.12 | errno = EDOM; | 
| 594 | greg | 2.10 | else { | 
| 595 | greg | 2.11 | pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan); | 
| 596 | greg | 2.18 | ldist[fn] = viewray(lorg[fn], ldir[fn], | 
| 597 |  |  | &input[fn].vw, loc[0], loc[1]); | 
| 598 | greg | 2.10 | } | 
| 599 | greg | 2.18 | ltick[fn] = eclock; | 
| 600 | greg | 2.10 | } | 
| 601 | greg | 2.18 | if (nam == vray[i=6]) | 
| 602 |  |  | return(ldist[fn]); | 
| 603 | greg | 2.10 | while (i--) | 
| 604 |  |  | if (nam == vray[i]) | 
| 605 |  |  | return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]); | 
| 606 |  |  | eputs("Bad call to l_ray()!\n"); | 
| 607 | greg | 1.15 | quit(1); | 
| 608 | schorsch | 2.32 | return 1; /* pro forma return */ | 
| 609 | greg | 2.17 | } | 
| 610 |  |  |  | 
| 611 |  |  |  | 
| 612 | schorsch | 2.32 | static double | 
| 613 | greg | 2.27 | l_psize(char *nm)               /* compute pixel size in steradians */ | 
| 614 | greg | 2.17 | { | 
| 615 |  |  | static unsigned long    ltick[MAXINP]; | 
| 616 |  |  | static double   psize[MAXINP]; | 
| 617 | greg | 2.18 | FVECT   dir0, org, dirx, diry; | 
| 618 | schorsch | 2.25 | RREAL   locx[2], locy[2]; | 
| 619 | greg | 2.17 | double  d; | 
| 620 |  |  | int     fn; | 
| 621 | greg | 2.47 | int     i; | 
| 622 | greg | 2.17 |  | 
| 623 |  |  | d = argument(1); | 
| 624 | greg | 2.42 | if (d <= -0.5 || d >= nfiles+0.5) { | 
| 625 | greg | 2.17 | errno = EDOM; | 
| 626 |  |  | return(0.0); | 
| 627 |  |  | } | 
| 628 | greg | 2.42 | if (d < 0.5) | 
| 629 |  |  | return((double)nfiles); | 
| 630 |  |  | fn = d - 0.5; | 
| 631 | greg | 2.22 | if (ltick[fn] != eclock) {              /* need to compute? */ | 
| 632 | greg | 2.18 | psize[fn] = 0.0; | 
| 633 |  |  | if (input[fn].vw.type == 0) | 
| 634 | greg | 2.17 | errno = EDOM; | 
| 635 | greg | 2.18 | else if (input[fn].vw.type != VT_PAR && | 
| 636 | greg | 2.36 | funvalue(vray[6], 1, &d) >= -FTINY) { | 
| 637 | greg | 2.18 | for (i = 0; i < 3; i++) | 
| 638 |  |  | dir0[i] = funvalue(vray[3+i], 1, &d); | 
| 639 |  |  | pix2loc(locx, &input[fn].rs, xscan+1, ymax-1-yscan); | 
| 640 |  |  | pix2loc(locy, &input[fn].rs, xscan, ymax-yscan); | 
| 641 |  |  | if (viewray(org, dirx, &input[fn].vw, | 
| 642 | greg | 2.35 | locx[0], locx[1]) >= -FTINY && | 
| 643 | greg | 2.18 | viewray(org, diry, &input[fn].vw, | 
| 644 | greg | 2.35 | locy[0], locy[1]) >= -FTINY) { | 
| 645 | greg | 2.17 | /* approximate solid angle */ | 
| 646 | greg | 2.18 | for (i = 0; i < 3; i++) { | 
| 647 |  |  | dirx[i] -= dir0[i]; | 
| 648 |  |  | diry[i] -= dir0[i]; | 
| 649 |  |  | } | 
| 650 |  |  | fcross(dir0, dirx, diry); | 
| 651 | greg | 2.35 | psize[fn] = VLEN(dir0); | 
| 652 | greg | 2.17 | } | 
| 653 |  |  | } | 
| 654 | greg | 2.18 | ltick[fn] = eclock; | 
| 655 |  |  | } | 
| 656 | greg | 2.17 | return(psize[fn]); | 
| 657 | greg | 1.1 | } | 
| 658 |  |  |  | 
| 659 |  |  |  | 
| 660 | schorsch | 2.29 | extern void | 
| 661 |  |  | wputs(char      *msg) | 
| 662 | greg | 1.1 | { | 
| 663 |  |  | if (!nowarn) | 
| 664 |  |  | eputs(msg); | 
| 665 |  |  | } | 
| 666 |  |  |  | 
| 667 |  |  |  | 
| 668 | schorsch | 2.29 | extern void | 
| 669 |  |  | eputs(char *msg) | 
| 670 | greg | 1.1 | { | 
| 671 |  |  | fputs(msg, stderr); | 
| 672 |  |  | } | 
| 673 |  |  |  | 
| 674 |  |  |  | 
| 675 | schorsch | 2.29 | extern void | 
| 676 |  |  | quit(int code)          /* exit gracefully */ | 
| 677 | greg | 2.4 | { | 
| 678 | greg | 2.47 | int  i; | 
| 679 | greg | 2.5 | /* close input files */ | 
| 680 |  |  | for (i = 0; i < nfiles; i++) | 
| 681 | greg | 2.6 | if (input[i].name == Command) | 
| 682 |  |  | pclose(input[i].fp); | 
| 683 |  |  | else | 
| 684 |  |  | fclose(input[i].fp); | 
| 685 | greg | 1.1 | exit(code); | 
| 686 |  |  | } |