| 1 | greg | 1.34 | /* Copyright (c) 1991 Regents of the University of California */ | 
| 2 |  |  |  | 
| 3 | greg | 1.1 | #ifndef lint | 
| 4 |  |  | static char SCCSid[] = "$SunId$ LBL"; | 
| 5 |  |  | #endif | 
| 6 |  |  |  | 
| 7 |  |  | /* | 
| 8 |  |  | * Interpolate and extrapolate pictures with different view parameters. | 
| 9 |  |  | * | 
| 10 |  |  | *      Greg Ward       09Dec89 | 
| 11 |  |  | */ | 
| 12 |  |  |  | 
| 13 |  |  | #include "standard.h" | 
| 14 |  |  |  | 
| 15 | greg | 1.24 | #include <fcntl.h> | 
| 16 | greg | 1.19 |  | 
| 17 | greg | 2.3 | #include <ctype.h> | 
| 18 |  |  |  | 
| 19 | greg | 1.1 | #include "view.h" | 
| 20 |  |  |  | 
| 21 |  |  | #include "color.h" | 
| 22 |  |  |  | 
| 23 | greg | 1.34 | #include "resolu.h" | 
| 24 |  |  |  | 
| 25 | greg | 1.21 | #ifndef BSD | 
| 26 |  |  | #define vfork           fork | 
| 27 |  |  | #endif | 
| 28 |  |  |  | 
| 29 | greg | 1.17 | #define pscan(y)        (ourpict+(y)*hresolu) | 
| 30 |  |  | #define zscan(y)        (ourzbuf+(y)*hresolu) | 
| 31 | greg | 1.1 |  | 
| 32 | greg | 1.13 | #define F_FORE          1               /* fill foreground */ | 
| 33 |  |  | #define F_BACK          2               /* fill background */ | 
| 34 | greg | 1.11 |  | 
| 35 | greg | 2.3 | #define PACKSIZ         256             /* max. calculation packet size */ | 
| 36 | greg | 1.13 |  | 
| 37 | greg | 2.4 | #define RTCOM           "rtrace -h- -ovl -fff " | 
| 38 | greg | 1.13 |  | 
| 39 | greg | 1.3 | #define ABS(x)          ((x)>0?(x):-(x)) | 
| 40 |  |  |  | 
| 41 | greg | 1.15 | struct position {int x,y; float z;}; | 
| 42 |  |  |  | 
| 43 | greg | 1.17 | VIEW    ourview = STDVIEW;              /* desired view */ | 
| 44 |  |  | int     hresolu = 512;                  /* horizontal resolution */ | 
| 45 |  |  | int     vresolu = 512;                  /* vertical resolution */ | 
| 46 | greg | 1.18 | double  pixaspect = 1.0;                /* pixel aspect ratio */ | 
| 47 | greg | 1.1 |  | 
| 48 | greg | 1.8 | double  zeps = .02;                     /* allowed z epsilon */ | 
| 49 | greg | 1.1 |  | 
| 50 |  |  | COLR    *ourpict;                       /* output picture */ | 
| 51 |  |  | float   *ourzbuf;                       /* corresponding z-buffer */ | 
| 52 |  |  |  | 
| 53 |  |  | char    *progname; | 
| 54 |  |  |  | 
| 55 | greg | 1.25 | int     fillo = F_FORE|F_BACK;          /* selected fill options */ | 
| 56 | greg | 1.26 | int     fillsamp = 0;                   /* sample separation (0 == inf) */ | 
| 57 | greg | 1.14 | extern int      backfill(), rcalfill(); /* fill functions */ | 
| 58 | greg | 1.25 | int     (*fillfunc)() = backfill;       /* selected fill function */ | 
| 59 | greg | 1.11 | COLR    backcolr = BLKCOLR;             /* background color */ | 
| 60 | greg | 1.13 | double  backz = 0.0;                    /* background z value */ | 
| 61 | greg | 1.16 | int     normdist = 1;                   /* normalized distance? */ | 
| 62 |  |  | double  ourexp = -1;                    /* output picture exposure */ | 
| 63 | greg | 1.11 |  | 
| 64 | greg | 1.17 | VIEW    theirview = STDVIEW;            /* input view */ | 
| 65 | greg | 1.16 | int     gotview;                        /* got input view? */ | 
| 66 | greg | 1.33 | int     wrongformat = 0;                /* input in another format? */ | 
| 67 | greg | 1.34 | RESOLU  tresolu;                        /* input resolution */ | 
| 68 | greg | 1.17 | double  theirexp;                       /* input picture exposure */ | 
| 69 | greg | 1.5 | double  theirs2ours[4][4];              /* transformation matrix */ | 
| 70 | greg | 1.30 | int     hasmatrix = 0;                  /* has transformation matrix */ | 
| 71 | greg | 1.1 |  | 
| 72 | greg | 2.3 | int     PDesc[3] = {-1,-1,-1};          /* rtrace process descriptor */ | 
| 73 |  |  | #define childpid        (PDesc[2]) | 
| 74 |  |  | unsigned short  queue[PACKSIZ][2];      /* pending pixels */ | 
| 75 |  |  | int     packsiz;                        /* actual packet size */ | 
| 76 | greg | 1.13 | int     queuesiz;                       /* number of pixels pending */ | 
| 77 | greg | 1.5 |  | 
| 78 | greg | 1.13 |  | 
| 79 | greg | 1.1 | main(argc, argv)                        /* interpolate pictures */ | 
| 80 |  |  | int     argc; | 
| 81 |  |  | char    *argv[]; | 
| 82 |  |  | { | 
| 83 | greg | 2.3 | #define  check(ol,al)           if (argv[i][ol] || \ | 
| 84 |  |  | badarg(argc-i-1,argv+i+1,al)) \ | 
| 85 |  |  | goto badopt | 
| 86 | greg | 1.1 | int     gotvfile = 0; | 
| 87 | greg | 1.11 | char    *zfile = NULL; | 
| 88 | greg | 1.1 | char    *err; | 
| 89 | greg | 1.17 | int     i, rval; | 
| 90 | greg | 1.1 |  | 
| 91 |  |  | progname = argv[0]; | 
| 92 |  |  |  | 
| 93 | greg | 1.17 | for (i = 1; i < argc && argv[i][0] == '-'; i++) { | 
| 94 |  |  | rval = getviewopt(&ourview, argc-i, argv+i); | 
| 95 |  |  | if (rval >= 0) { | 
| 96 |  |  | i += rval; | 
| 97 |  |  | continue; | 
| 98 |  |  | } | 
| 99 | greg | 1.1 | switch (argv[i][1]) { | 
| 100 |  |  | case 't':                               /* threshold */ | 
| 101 | greg | 2.3 | check(2,"f"); | 
| 102 | greg | 1.1 | zeps = atof(argv[++i]); | 
| 103 |  |  | break; | 
| 104 | greg | 1.11 | case 'n':                               /* dist. normalized? */ | 
| 105 | greg | 2.3 | check(2,NULL); | 
| 106 | greg | 1.11 | normdist = !normdist; | 
| 107 | greg | 1.10 | break; | 
| 108 | greg | 1.11 | case 'f':                               /* fill type */ | 
| 109 |  |  | switch (argv[i][2]) { | 
| 110 |  |  | case '0':                               /* none */ | 
| 111 | greg | 2.3 | check(3,NULL); | 
| 112 | greg | 1.25 | fillo = 0; | 
| 113 | greg | 1.11 | break; | 
| 114 |  |  | case 'f':                               /* foreground */ | 
| 115 | greg | 2.3 | check(3,NULL); | 
| 116 | greg | 1.25 | fillo = F_FORE; | 
| 117 | greg | 1.11 | break; | 
| 118 |  |  | case 'b':                               /* background */ | 
| 119 | greg | 2.3 | check(3,NULL); | 
| 120 | greg | 1.25 | fillo = F_BACK; | 
| 121 | greg | 1.11 | break; | 
| 122 |  |  | case 'a':                               /* all */ | 
| 123 | greg | 2.3 | check(3,NULL); | 
| 124 | greg | 1.25 | fillo = F_FORE|F_BACK; | 
| 125 | greg | 1.11 | break; | 
| 126 | greg | 1.25 | case 's':                               /* sample */ | 
| 127 | greg | 2.3 | check(3,"i"); | 
| 128 | greg | 1.26 | fillsamp = atoi(argv[++i]); | 
| 129 | greg | 1.25 | break; | 
| 130 | greg | 1.11 | case 'c':                               /* color */ | 
| 131 | greg | 2.3 | check(3,"fff"); | 
| 132 | greg | 1.25 | fillfunc = backfill; | 
| 133 | greg | 1.11 | setcolr(backcolr, atof(argv[i+1]), | 
| 134 |  |  | atof(argv[i+2]), atof(argv[i+3])); | 
| 135 |  |  | i += 3; | 
| 136 |  |  | break; | 
| 137 | greg | 1.13 | case 'z':                               /* z value */ | 
| 138 | greg | 2.3 | check(3,"f"); | 
| 139 | greg | 1.25 | fillfunc = backfill; | 
| 140 | greg | 1.13 | backz = atof(argv[++i]); | 
| 141 |  |  | break; | 
| 142 |  |  | case 'r':                               /* rtrace */ | 
| 143 | greg | 2.3 | check(3,"s"); | 
| 144 | greg | 1.25 | fillfunc = rcalfill; | 
| 145 | greg | 1.13 | calstart(RTCOM, argv[++i]); | 
| 146 |  |  | break; | 
| 147 | greg | 1.11 | default: | 
| 148 |  |  | goto badopt; | 
| 149 |  |  | } | 
| 150 |  |  | break; | 
| 151 |  |  | case 'z':                               /* z file */ | 
| 152 | greg | 2.3 | check(2,"s"); | 
| 153 | greg | 1.11 | zfile = argv[++i]; | 
| 154 |  |  | break; | 
| 155 | greg | 1.6 | case 'x':                               /* x resolution */ | 
| 156 | greg | 2.3 | check(2,"i"); | 
| 157 | greg | 1.17 | hresolu = atoi(argv[++i]); | 
| 158 | greg | 1.6 | break; | 
| 159 |  |  | case 'y':                               /* y resolution */ | 
| 160 | greg | 2.3 | check(2,"i"); | 
| 161 | greg | 1.17 | vresolu = atoi(argv[++i]); | 
| 162 | greg | 1.6 | break; | 
| 163 | greg | 1.18 | case 'p':                               /* pixel aspect */ | 
| 164 | greg | 2.3 | check(2,"f"); | 
| 165 | greg | 1.18 | pixaspect = atof(argv[++i]); | 
| 166 |  |  | break; | 
| 167 | greg | 1.17 | case 'v':                               /* view file */ | 
| 168 |  |  | if (argv[i][2] != 'f') | 
| 169 | greg | 1.1 | goto badopt; | 
| 170 | greg | 2.3 | check(3,"s"); | 
| 171 | greg | 1.19 | gotvfile = viewfile(argv[++i], &ourview, 0, 0); | 
| 172 | greg | 1.17 | if (gotvfile < 0) { | 
| 173 |  |  | perror(argv[i]); | 
| 174 |  |  | exit(1); | 
| 175 |  |  | } else if (gotvfile == 0) { | 
| 176 |  |  | fprintf(stderr, "%s: bad view file\n", | 
| 177 |  |  | argv[i]); | 
| 178 |  |  | exit(1); | 
| 179 | greg | 1.1 | } | 
| 180 |  |  | break; | 
| 181 |  |  | default: | 
| 182 |  |  | badopt: | 
| 183 | greg | 1.10 | fprintf(stderr, "%s: command line error at '%s'\n", | 
| 184 | greg | 1.1 | progname, argv[i]); | 
| 185 | greg | 1.10 | goto userr; | 
| 186 | greg | 1.1 | } | 
| 187 | greg | 1.17 | } | 
| 188 | greg | 1.1 | /* check arguments */ | 
| 189 | greg | 1.13 | if ((argc-i)%2) | 
| 190 | greg | 1.10 | goto userr; | 
| 191 | greg | 2.3 | if (fillsamp == 1) | 
| 192 |  |  | fillo &= ~F_BACK; | 
| 193 | greg | 1.1 | /* set view */ | 
| 194 |  |  | if (err = setview(&ourview)) { | 
| 195 |  |  | fprintf(stderr, "%s: %s\n", progname, err); | 
| 196 |  |  | exit(1); | 
| 197 |  |  | } | 
| 198 | greg | 1.18 | normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu); | 
| 199 | greg | 1.1 | /* allocate frame */ | 
| 200 | greg | 1.17 | ourpict = (COLR *)malloc(hresolu*vresolu*sizeof(COLR)); | 
| 201 |  |  | ourzbuf = (float *)calloc(hresolu*vresolu,sizeof(float)); | 
| 202 | greg | 1.15 | if (ourpict == NULL || ourzbuf == NULL) | 
| 203 |  |  | syserror(); | 
| 204 | greg | 1.1 | /* get input */ | 
| 205 |  |  | for ( ; i < argc; i += 2) | 
| 206 |  |  | addpicture(argv[i], argv[i+1]); | 
| 207 |  |  | /* fill in spaces */ | 
| 208 | greg | 1.25 | if (fillo&F_BACK) | 
| 209 | greg | 1.26 | backpicture(fillfunc, fillsamp); | 
| 210 | greg | 1.12 | else | 
| 211 | greg | 1.25 | fillpicture(fillfunc); | 
| 212 | greg | 1.13 | /* close calculation */ | 
| 213 | greg | 1.14 | caldone(); | 
| 214 | greg | 1.1 | /* add to header */ | 
| 215 |  |  | printargs(argc, argv, stdout); | 
| 216 |  |  | if (gotvfile) { | 
| 217 | greg | 1.25 | fputs(VIEWSTR, stdout); | 
| 218 | greg | 1.1 | fprintview(&ourview, stdout); | 
| 219 | greg | 1.25 | putc('\n', stdout); | 
| 220 | greg | 1.1 | } | 
| 221 | greg | 1.18 | if (pixaspect < .99 || pixaspect > 1.01) | 
| 222 |  |  | fputaspect(pixaspect, stdout); | 
| 223 |  |  | if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) | 
| 224 | greg | 1.16 | fputexpos(ourexp, stdout); | 
| 225 | greg | 1.33 | fputformat(COLRFMT, stdout); | 
| 226 | greg | 1.25 | putc('\n', stdout); | 
| 227 | greg | 1.11 | /* write picture */ | 
| 228 | greg | 1.1 | writepicture(); | 
| 229 | greg | 1.11 | /* write z file */ | 
| 230 |  |  | if (zfile != NULL) | 
| 231 |  |  | writedistance(zfile); | 
| 232 | greg | 1.1 |  | 
| 233 |  |  | exit(0); | 
| 234 | greg | 1.10 | userr: | 
| 235 |  |  | fprintf(stderr, | 
| 236 | greg | 1.17 | "Usage: %s [view opts][-t eps][-z zout][-fT][-n] pfile zspec ..\n", | 
| 237 | greg | 1.10 | progname); | 
| 238 |  |  | exit(1); | 
| 239 | greg | 1.1 | #undef check | 
| 240 |  |  | } | 
| 241 |  |  |  | 
| 242 |  |  |  | 
| 243 |  |  | headline(s)                             /* process header string */ | 
| 244 |  |  | char    *s; | 
| 245 |  |  | { | 
| 246 | greg | 1.25 | static char     *altname[] = {VIEWSTR,"rpict","rview","pinterp",NULL}; | 
| 247 | greg | 1.1 | register char   **an; | 
| 248 | greg | 1.33 | char    fmt[32]; | 
| 249 | greg | 1.1 |  | 
| 250 | greg | 1.33 | if (isformat(s)) { | 
| 251 |  |  | formatval(fmt, s); | 
| 252 |  |  | wrongformat = strcmp(fmt, COLRFMT); | 
| 253 |  |  | return; | 
| 254 |  |  | } | 
| 255 | greg | 1.25 | putc('\t', stdout); | 
| 256 |  |  | fputs(s, stdout); | 
| 257 | greg | 1.1 |  | 
| 258 | greg | 1.16 | if (isexpos(s)) { | 
| 259 |  |  | theirexp *= exposval(s); | 
| 260 |  |  | return; | 
| 261 |  |  | } | 
| 262 | greg | 1.1 | for (an = altname; *an != NULL; an++) | 
| 263 |  |  | if (!strncmp(*an, s, strlen(*an))) { | 
| 264 | greg | 1.17 | if (sscanview(&theirview, s+strlen(*an)) > 0) | 
| 265 | greg | 1.1 | gotview++; | 
| 266 |  |  | break; | 
| 267 |  |  | } | 
| 268 |  |  | } | 
| 269 |  |  |  | 
| 270 |  |  |  | 
| 271 | greg | 1.10 | addpicture(pfile, zspec)                /* add picture to output */ | 
| 272 |  |  | char    *pfile, *zspec; | 
| 273 | greg | 1.1 | { | 
| 274 | greg | 1.19 | FILE    *pfp; | 
| 275 |  |  | int     zfd; | 
| 276 | greg | 1.8 | char    *err; | 
| 277 | greg | 1.1 | COLR    *scanin; | 
| 278 | greg | 1.15 | float   *zin; | 
| 279 |  |  | struct position *plast; | 
| 280 | greg | 1.1 | int     y; | 
| 281 | greg | 1.10 | /* open picture file */ | 
| 282 | greg | 1.1 | if ((pfp = fopen(pfile, "r")) == NULL) { | 
| 283 |  |  | perror(pfile); | 
| 284 |  |  | exit(1); | 
| 285 |  |  | } | 
| 286 | greg | 1.16 | /* get header with exposure and view */ | 
| 287 |  |  | theirexp = 1.0; | 
| 288 |  |  | gotview = 0; | 
| 289 | greg | 1.1 | printf("%s:\n", pfile); | 
| 290 | greg | 1.33 | getheader(pfp, headline, NULL); | 
| 291 | greg | 1.34 | if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) { | 
| 292 | greg | 1.33 | fprintf(stderr, "%s: picture format error\n", pfile); | 
| 293 | greg | 1.1 | exit(1); | 
| 294 |  |  | } | 
| 295 | greg | 1.16 | if (ourexp <= 0) | 
| 296 |  |  | ourexp = theirexp; | 
| 297 |  |  | else if (ABS(theirexp-ourexp) > .01*ourexp) | 
| 298 |  |  | fprintf(stderr, "%s: different exposure (warning)\n", pfile); | 
| 299 | greg | 1.1 | if (err = setview(&theirview)) { | 
| 300 |  |  | fprintf(stderr, "%s: %s\n", pfile, err); | 
| 301 |  |  | exit(1); | 
| 302 |  |  | } | 
| 303 | greg | 1.5 | /* compute transformation */ | 
| 304 | greg | 1.30 | hasmatrix = pixform(theirs2ours, &theirview, &ourview); | 
| 305 | greg | 1.1 | /* allocate scanlines */ | 
| 306 | greg | 1.34 | scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); | 
| 307 |  |  | zin = (float *)malloc(scanlen(&tresolu)*sizeof(float)); | 
| 308 |  |  | plast = (struct position *)calloc(scanlen(&tresolu), | 
| 309 |  |  | sizeof(struct position)); | 
| 310 | greg | 1.15 | if (scanin == NULL || zin == NULL || plast == NULL) | 
| 311 |  |  | syserror(); | 
| 312 | greg | 1.10 | /* get z specification or file */ | 
| 313 | greg | 1.19 | if ((zfd = open(zspec, O_RDONLY)) == -1) { | 
| 314 | greg | 1.10 | double  zvalue; | 
| 315 |  |  | register int    x; | 
| 316 |  |  | if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) { | 
| 317 |  |  | perror(zspec); | 
| 318 |  |  | exit(1); | 
| 319 |  |  | } | 
| 320 | greg | 1.34 | for (x = scanlen(&tresolu); x-- > 0; ) | 
| 321 | greg | 1.10 | zin[x] = zvalue; | 
| 322 |  |  | } | 
| 323 | greg | 1.1 | /* load image */ | 
| 324 | greg | 1.34 | for (y = 0; y < numscans(&tresolu); y++) { | 
| 325 |  |  | if (freadcolrs(scanin, scanlen(&tresolu), pfp) < 0) { | 
| 326 | greg | 1.1 | fprintf(stderr, "%s: read error\n", pfile); | 
| 327 |  |  | exit(1); | 
| 328 |  |  | } | 
| 329 | greg | 1.34 | if (zfd != -1 && read(zfd,(char *)zin, | 
| 330 |  |  | scanlen(&tresolu)*sizeof(float)) | 
| 331 |  |  | < scanlen(&tresolu)*sizeof(float)) { | 
| 332 | greg | 1.10 | fprintf(stderr, "%s: read error\n", zspec); | 
| 333 | greg | 1.1 | exit(1); | 
| 334 |  |  | } | 
| 335 | greg | 1.15 | addscanline(y, scanin, zin, plast); | 
| 336 | greg | 1.1 | } | 
| 337 |  |  | /* clean up */ | 
| 338 |  |  | free((char *)scanin); | 
| 339 |  |  | free((char *)zin); | 
| 340 | greg | 1.9 | free((char *)plast); | 
| 341 | greg | 1.1 | fclose(pfp); | 
| 342 | greg | 1.19 | if (zfd != -1) | 
| 343 |  |  | close(zfd); | 
| 344 | greg | 1.1 | } | 
| 345 |  |  |  | 
| 346 |  |  |  | 
| 347 | greg | 1.5 | pixform(xfmat, vw1, vw2)                /* compute view1 to view2 matrix */ | 
| 348 |  |  | register double xfmat[4][4]; | 
| 349 |  |  | register VIEW   *vw1, *vw2; | 
| 350 |  |  | { | 
| 351 |  |  | double  m4t[4][4]; | 
| 352 |  |  |  | 
| 353 | greg | 1.30 | if (vw1->type != VT_PER && vw1->type != VT_PAR) | 
| 354 |  |  | return(0); | 
| 355 |  |  | if (vw2->type != VT_PER && vw2->type != VT_PAR) | 
| 356 |  |  | return(0); | 
| 357 | greg | 1.5 | setident4(xfmat); | 
| 358 | greg | 1.17 | xfmat[0][0] = vw1->hvec[0]; | 
| 359 |  |  | xfmat[0][1] = vw1->hvec[1]; | 
| 360 |  |  | xfmat[0][2] = vw1->hvec[2]; | 
| 361 |  |  | xfmat[1][0] = vw1->vvec[0]; | 
| 362 |  |  | xfmat[1][1] = vw1->vvec[1]; | 
| 363 |  |  | xfmat[1][2] = vw1->vvec[2]; | 
| 364 | greg | 1.5 | xfmat[2][0] = vw1->vdir[0]; | 
| 365 |  |  | xfmat[2][1] = vw1->vdir[1]; | 
| 366 |  |  | xfmat[2][2] = vw1->vdir[2]; | 
| 367 |  |  | xfmat[3][0] = vw1->vp[0]; | 
| 368 |  |  | xfmat[3][1] = vw1->vp[1]; | 
| 369 |  |  | xfmat[3][2] = vw1->vp[2]; | 
| 370 |  |  | setident4(m4t); | 
| 371 | greg | 1.17 | m4t[0][0] = vw2->hvec[0]/vw2->hn2; | 
| 372 |  |  | m4t[1][0] = vw2->hvec[1]/vw2->hn2; | 
| 373 |  |  | m4t[2][0] = vw2->hvec[2]/vw2->hn2; | 
| 374 |  |  | m4t[3][0] = -DOT(vw2->vp,vw2->hvec)/vw2->hn2; | 
| 375 |  |  | m4t[0][1] = vw2->vvec[0]/vw2->vn2; | 
| 376 |  |  | m4t[1][1] = vw2->vvec[1]/vw2->vn2; | 
| 377 |  |  | m4t[2][1] = vw2->vvec[2]/vw2->vn2; | 
| 378 |  |  | m4t[3][1] = -DOT(vw2->vp,vw2->vvec)/vw2->vn2; | 
| 379 | greg | 1.5 | m4t[0][2] = vw2->vdir[0]; | 
| 380 |  |  | m4t[1][2] = vw2->vdir[1]; | 
| 381 |  |  | m4t[2][2] = vw2->vdir[2]; | 
| 382 |  |  | m4t[3][2] = -DOT(vw2->vp,vw2->vdir); | 
| 383 |  |  | multmat4(xfmat, xfmat, m4t); | 
| 384 | greg | 1.30 | return(1); | 
| 385 | greg | 1.5 | } | 
| 386 |  |  |  | 
| 387 |  |  |  | 
| 388 | greg | 1.15 | addscanline(y, pline, zline, lasty)     /* add scanline to output */ | 
| 389 | greg | 1.1 | int     y; | 
| 390 |  |  | COLR    *pline; | 
| 391 |  |  | float   *zline; | 
| 392 | greg | 1.15 | struct position *lasty;         /* input/output */ | 
| 393 | greg | 1.1 | { | 
| 394 | greg | 1.11 | extern double   sqrt(); | 
| 395 | greg | 1.30 | FVECT   pos; | 
| 396 | greg | 1.15 | struct position lastx, newpos; | 
| 397 | greg | 1.1 | register int    x; | 
| 398 |  |  |  | 
| 399 | greg | 1.20 | lastx.z = 0; | 
| 400 | greg | 1.34 | for (x = scanlen(&tresolu); x-- > 0; ) { | 
| 401 |  |  | pix2loc(pos, &tresolu, x, y); | 
| 402 | greg | 1.5 | pos[2] = zline[x]; | 
| 403 | greg | 1.30 | if (movepixel(pos) < 0) { | 
| 404 | greg | 1.15 | lasty[x].z = lastx.z = 0;       /* mark invalid */ | 
| 405 | greg | 1.1 | continue; | 
| 406 | greg | 1.15 | } | 
| 407 | greg | 1.17 | newpos.x = pos[0] * hresolu; | 
| 408 |  |  | newpos.y = pos[1] * vresolu; | 
| 409 | greg | 1.15 | newpos.z = zline[x]; | 
| 410 | greg | 1.8 | /* add pixel to our image */ | 
| 411 | greg | 1.17 | if (pos[0] >= 0 && newpos.x < hresolu | 
| 412 |  |  | && pos[1] >= 0 && newpos.y < vresolu) { | 
| 413 | greg | 1.15 | addpixel(&newpos, &lastx, &lasty[x], pline[x], pos[2]); | 
| 414 |  |  | lasty[x].x = lastx.x = newpos.x; | 
| 415 |  |  | lasty[x].y = lastx.y = newpos.y; | 
| 416 |  |  | lasty[x].z = lastx.z = newpos.z; | 
| 417 |  |  | } else | 
| 418 |  |  | lasty[x].z = lastx.z = 0;       /* mark invalid */ | 
| 419 | greg | 1.1 | } | 
| 420 |  |  | } | 
| 421 |  |  |  | 
| 422 |  |  |  | 
| 423 | greg | 1.15 | addpixel(p0, p1, p2, pix, z)            /* fill in pixel parallelogram */ | 
| 424 |  |  | struct position *p0, *p1, *p2; | 
| 425 | greg | 1.8 | COLR    pix; | 
| 426 |  |  | double  z; | 
| 427 |  |  | { | 
| 428 | greg | 1.15 | double  zt = 2.*zeps*p0->z;             /* threshold */ | 
| 429 |  |  | int     s1x, s1y, s2x, s2y;             /* step sizes */ | 
| 430 |  |  | int     l1, l2, c1, c2;                 /* side lengths and counters */ | 
| 431 |  |  | int     p1isy;                          /* p0p1 along y? */ | 
| 432 |  |  | int     x1, y1;                         /* p1 position */ | 
| 433 |  |  | register int    x, y;                   /* final position */ | 
| 434 |  |  |  | 
| 435 |  |  | /* compute vector p0p1 */ | 
| 436 | greg | 1.25 | if (fillo&F_FORE && ABS(p1->z-p0->z) <= zt) { | 
| 437 | greg | 1.15 | s1x = p1->x - p0->x; | 
| 438 |  |  | s1y = p1->y - p0->y; | 
| 439 |  |  | l1 = ABS(s1x); | 
| 440 |  |  | if (p1isy = (ABS(s1y) > l1)) | 
| 441 |  |  | l1 = ABS(s1y); | 
| 442 |  |  | } else { | 
| 443 |  |  | l1 = s1x = s1y = 1; | 
| 444 |  |  | p1isy = -1; | 
| 445 |  |  | } | 
| 446 |  |  | /* compute vector p0p2 */ | 
| 447 | greg | 1.25 | if (fillo&F_FORE && ABS(p2->z-p0->z) <= zt) { | 
| 448 | greg | 1.15 | s2x = p2->x - p0->x; | 
| 449 |  |  | s2y = p2->y - p0->y; | 
| 450 |  |  | if (p1isy == 1) | 
| 451 |  |  | l2 = ABS(s2x); | 
| 452 |  |  | else { | 
| 453 |  |  | l2 = ABS(s2y); | 
| 454 |  |  | if (p1isy != 0 && ABS(s2x) > l2) | 
| 455 |  |  | l2 = ABS(s2x); | 
| 456 |  |  | } | 
| 457 |  |  | } else | 
| 458 |  |  | l2 = s2x = s2y = 1; | 
| 459 |  |  | /* fill the parallelogram */ | 
| 460 |  |  | for (c1 = l1; c1-- > 0; ) { | 
| 461 |  |  | x1 = p0->x + c1*s1x/l1; | 
| 462 |  |  | y1 = p0->y + c1*s1y/l1; | 
| 463 |  |  | for (c2 = l2; c2-- > 0; ) { | 
| 464 |  |  | x = x1 + c2*s2x/l2; | 
| 465 | greg | 1.28 | if (x < 0 || x >= hresolu) | 
| 466 |  |  | continue; | 
| 467 | greg | 1.15 | y = y1 + c2*s2y/l2; | 
| 468 | greg | 1.28 | if (y < 0 || y >= vresolu) | 
| 469 |  |  | continue; | 
| 470 | greg | 1.15 | if (zscan(y)[x] <= 0 || zscan(y)[x]-z | 
| 471 |  |  | > zeps*zscan(y)[x]) { | 
| 472 | greg | 1.8 | zscan(y)[x] = z; | 
| 473 |  |  | copycolr(pscan(y)[x], pix); | 
| 474 |  |  | } | 
| 475 | greg | 1.15 | } | 
| 476 |  |  | } | 
| 477 | greg | 1.30 | } | 
| 478 |  |  |  | 
| 479 |  |  |  | 
| 480 |  |  | movepixel(pos)                          /* reposition image point */ | 
| 481 |  |  | FVECT   pos; | 
| 482 |  |  | { | 
| 483 |  |  | FVECT   pt, direc; | 
| 484 |  |  |  | 
| 485 | greg | 1.32 | if (pos[2] <= 0)                /* empty pixel */ | 
| 486 |  |  | return(-1); | 
| 487 | greg | 1.30 | if (hasmatrix) { | 
| 488 |  |  | pos[0] += theirview.hoff - .5; | 
| 489 |  |  | pos[1] += theirview.voff - .5; | 
| 490 |  |  | if (theirview.type == VT_PER) { | 
| 491 |  |  | if (normdist)   /* adjust for eye-ray distance */ | 
| 492 |  |  | pos[2] /= sqrt( 1. | 
| 493 |  |  | + pos[0]*pos[0]*theirview.hn2 | 
| 494 |  |  | + pos[1]*pos[1]*theirview.vn2 ); | 
| 495 |  |  | pos[0] *= pos[2]; | 
| 496 |  |  | pos[1] *= pos[2]; | 
| 497 |  |  | } | 
| 498 |  |  | multp3(pos, pos, theirs2ours); | 
| 499 |  |  | if (pos[2] <= 0) | 
| 500 |  |  | return(-1); | 
| 501 |  |  | if (ourview.type == VT_PER) { | 
| 502 |  |  | pos[0] /= pos[2]; | 
| 503 |  |  | pos[1] /= pos[2]; | 
| 504 |  |  | } | 
| 505 |  |  | pos[0] += .5 - ourview.hoff; | 
| 506 |  |  | pos[1] += .5 - ourview.voff; | 
| 507 |  |  | return(0); | 
| 508 |  |  | } | 
| 509 |  |  | if (viewray(pt, direc, &theirview, pos[0], pos[1]) < 0) | 
| 510 |  |  | return(-1); | 
| 511 |  |  | pt[0] += direc[0]*pos[2]; | 
| 512 |  |  | pt[1] += direc[1]*pos[2]; | 
| 513 |  |  | pt[2] += direc[2]*pos[2]; | 
| 514 | greg | 1.34 | viewloc(pos, &ourview, pt); | 
| 515 | greg | 1.30 | if (pos[2] <= 0) | 
| 516 |  |  | return(-1); | 
| 517 |  |  | return(0); | 
| 518 | greg | 1.8 | } | 
| 519 |  |  |  | 
| 520 |  |  |  | 
| 521 | greg | 1.26 | backpicture(fill, samp)                 /* background fill algorithm */ | 
| 522 | greg | 1.25 | int     (*fill)(); | 
| 523 | greg | 1.26 | int     samp; | 
| 524 | greg | 1.1 | { | 
| 525 | greg | 1.2 | int     *yback, xback; | 
| 526 | greg | 1.1 | int     y; | 
| 527 | greg | 1.2 | register int    x, i; | 
| 528 |  |  | /* get back buffer */ | 
| 529 | greg | 1.17 | yback = (int *)malloc(hresolu*sizeof(int)); | 
| 530 | greg | 1.15 | if (yback == NULL) | 
| 531 |  |  | syserror(); | 
| 532 | greg | 1.17 | for (x = 0; x < hresolu; x++) | 
| 533 | greg | 1.4 | yback[x] = -2; | 
| 534 | greg | 1.7 | /* | 
| 535 |  |  | * Xback and yback are the pixel locations of suitable | 
| 536 |  |  | * background values in each direction. | 
| 537 |  |  | * A value of -2 means unassigned, and -1 means | 
| 538 |  |  | * that there is no suitable background in this direction. | 
| 539 |  |  | */ | 
| 540 | greg | 1.2 | /* fill image */ | 
| 541 | greg | 1.17 | for (y = 0; y < vresolu; y++) { | 
| 542 | greg | 1.4 | xback = -2; | 
| 543 | greg | 1.17 | for (x = 0; x < hresolu; x++) | 
| 544 | greg | 1.8 | if (zscan(y)[x] <= 0) {         /* empty pixel */ | 
| 545 | greg | 1.7 | /* | 
| 546 |  |  | * First, find background from above or below. | 
| 547 |  |  | * (farthest assigned pixel) | 
| 548 |  |  | */ | 
| 549 | greg | 1.4 | if (yback[x] == -2) { | 
| 550 | greg | 1.17 | for (i = y+1; i < vresolu; i++) | 
| 551 | greg | 1.8 | if (zscan(i)[x] > 0) | 
| 552 | greg | 1.4 | break; | 
| 553 | greg | 1.17 | if (i < vresolu | 
| 554 | greg | 1.2 | && (y <= 0 || zscan(y-1)[x] < zscan(i)[x])) | 
| 555 | greg | 1.4 | yback[x] = i; | 
| 556 |  |  | else | 
| 557 |  |  | yback[x] = y-1; | 
| 558 | greg | 1.2 | } | 
| 559 | greg | 1.7 | /* | 
| 560 |  |  | * Next, find background from left or right. | 
| 561 |  |  | */ | 
| 562 | greg | 1.4 | if (xback == -2) { | 
| 563 | greg | 1.17 | for (i = x+1; i < hresolu; i++) | 
| 564 | greg | 1.8 | if (zscan(y)[i] > 0) | 
| 565 | greg | 1.4 | break; | 
| 566 | greg | 1.17 | if (i < hresolu | 
| 567 | greg | 1.4 | && (x <= 0 || zscan(y)[x-1] < zscan(y)[i])) | 
| 568 |  |  | xback = i; | 
| 569 |  |  | else | 
| 570 |  |  | xback = x-1; | 
| 571 |  |  | } | 
| 572 | greg | 1.7 | /* | 
| 573 | greg | 1.26 | * If we have no background for this pixel, | 
| 574 |  |  | * use the given fill function. | 
| 575 | greg | 1.11 | */ | 
| 576 | greg | 1.27 | if (xback < 0 && yback[x] < 0) | 
| 577 |  |  | goto fillit; | 
| 578 | greg | 1.11 | /* | 
| 579 | greg | 1.7 | * Compare, and use the background that is | 
| 580 |  |  | * farther, unless one of them is next to us. | 
| 581 | greg | 1.27 | * If the background is too distant, call | 
| 582 |  |  | * the fill function. | 
| 583 | greg | 1.7 | */ | 
| 584 | greg | 1.11 | if ( yback[x] < 0 | 
| 585 |  |  | || (xback >= 0 && ABS(x-xback) <= 1) | 
| 586 | greg | 1.4 | || ( ABS(y-yback[x]) > 1 | 
| 587 | greg | 1.11 | && zscan(yback[x])[x] | 
| 588 | greg | 1.13 | < zscan(y)[xback] ) ) { | 
| 589 | greg | 1.27 | if (samp > 0 && ABS(x-xback) >= samp) | 
| 590 |  |  | goto fillit; | 
| 591 | greg | 1.4 | copycolr(pscan(y)[x],pscan(y)[xback]); | 
| 592 | greg | 1.13 | zscan(y)[x] = zscan(y)[xback]; | 
| 593 |  |  | } else { | 
| 594 | greg | 1.27 | if (samp > 0 && ABS(y-yback[x]) > samp) | 
| 595 |  |  | goto fillit; | 
| 596 | greg | 1.4 | copycolr(pscan(y)[x],pscan(yback[x])[x]); | 
| 597 | greg | 1.13 | zscan(y)[x] = zscan(yback[x])[x]; | 
| 598 | greg | 1.27 | } | 
| 599 |  |  | continue; | 
| 600 |  |  | fillit: | 
| 601 |  |  | (*fill)(x,y); | 
| 602 |  |  | if (fill == rcalfill) {         /* use it */ | 
| 603 |  |  | clearqueue(); | 
| 604 |  |  | xback = x; | 
| 605 |  |  | yback[x] = y; | 
| 606 | greg | 1.13 | } | 
| 607 | greg | 1.4 | } else {                                /* full pixel */ | 
| 608 |  |  | yback[x] = -2; | 
| 609 |  |  | xback = -2; | 
| 610 |  |  | } | 
| 611 |  |  | } | 
| 612 | greg | 1.2 | free((char *)yback); | 
| 613 | greg | 1.1 | } | 
| 614 |  |  |  | 
| 615 |  |  |  | 
| 616 | greg | 1.25 | fillpicture(fill)               /* paint in empty pixels using fill */ | 
| 617 |  |  | int     (*fill)(); | 
| 618 | greg | 1.11 | { | 
| 619 |  |  | register int    x, y; | 
| 620 |  |  |  | 
| 621 | greg | 1.17 | for (y = 0; y < vresolu; y++) | 
| 622 |  |  | for (x = 0; x < hresolu; x++) | 
| 623 | greg | 1.11 | if (zscan(y)[x] <= 0) | 
| 624 | greg | 1.25 | (*fill)(x,y); | 
| 625 | greg | 1.11 | } | 
| 626 |  |  |  | 
| 627 |  |  |  | 
| 628 | greg | 1.1 | writepicture()                          /* write out picture */ | 
| 629 |  |  | { | 
| 630 |  |  | int     y; | 
| 631 |  |  |  | 
| 632 | greg | 1.34 | fprtresolu(hresolu, vresolu, stdout); | 
| 633 | greg | 1.17 | for (y = vresolu-1; y >= 0; y--) | 
| 634 |  |  | if (fwritecolrs(pscan(y), hresolu, stdout) < 0) | 
| 635 | greg | 1.15 | syserror(); | 
| 636 | greg | 1.11 | } | 
| 637 |  |  |  | 
| 638 |  |  |  | 
| 639 |  |  | writedistance(fname)                    /* write out z file */ | 
| 640 |  |  | char    *fname; | 
| 641 |  |  | { | 
| 642 |  |  | extern double   sqrt(); | 
| 643 |  |  | int     donorm = normdist && ourview.type == VT_PER; | 
| 644 | greg | 1.19 | int     fd; | 
| 645 | greg | 1.11 | int     y; | 
| 646 |  |  | float   *zout; | 
| 647 |  |  |  | 
| 648 | greg | 1.19 | if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) { | 
| 649 | greg | 1.11 | perror(fname); | 
| 650 |  |  | exit(1); | 
| 651 |  |  | } | 
| 652 |  |  | if (donorm | 
| 653 | greg | 1.17 | && (zout = (float *)malloc(hresolu*sizeof(float))) == NULL) | 
| 654 | greg | 1.15 | syserror(); | 
| 655 | greg | 1.17 | for (y = vresolu-1; y >= 0; y--) { | 
| 656 | greg | 1.11 | if (donorm) { | 
| 657 |  |  | double  vx, yzn2; | 
| 658 |  |  | register int    x; | 
| 659 | greg | 1.29 | yzn2 = (y+.5)/vresolu + ourview.voff - .5; | 
| 660 | greg | 1.17 | yzn2 = 1. + yzn2*yzn2*ourview.vn2; | 
| 661 |  |  | for (x = 0; x < hresolu; x++) { | 
| 662 | greg | 1.29 | vx = (x+.5)/hresolu + ourview.hoff - .5; | 
| 663 | greg | 1.11 | zout[x] = zscan(y)[x] | 
| 664 | greg | 1.17 | * sqrt(vx*vx*ourview.hn2 + yzn2); | 
| 665 | greg | 1.11 | } | 
| 666 |  |  | } else | 
| 667 |  |  | zout = zscan(y); | 
| 668 | greg | 1.23 | if (write(fd, (char *)zout, hresolu*sizeof(float)) | 
| 669 | greg | 1.19 | < hresolu*sizeof(float)) { | 
| 670 | greg | 1.11 | perror(fname); | 
| 671 |  |  | exit(1); | 
| 672 |  |  | } | 
| 673 |  |  | } | 
| 674 |  |  | if (donorm) | 
| 675 |  |  | free((char *)zout); | 
| 676 | greg | 1.19 | close(fd); | 
| 677 | greg | 1.10 | } | 
| 678 |  |  |  | 
| 679 |  |  |  | 
| 680 |  |  | isfloat(s)                              /* see if string is floating number */ | 
| 681 |  |  | register char   *s; | 
| 682 |  |  | { | 
| 683 |  |  | for ( ; *s; s++) | 
| 684 |  |  | if ((*s < '0' || *s > '9') && *s != '.' && *s != '-' | 
| 685 |  |  | && *s != 'e' && *s != 'E' && *s != '+') | 
| 686 |  |  | return(0); | 
| 687 |  |  | return(1); | 
| 688 | greg | 1.12 | } | 
| 689 |  |  |  | 
| 690 |  |  |  | 
| 691 |  |  | backfill(x, y)                          /* fill pixel with background */ | 
| 692 |  |  | int     x, y; | 
| 693 |  |  | { | 
| 694 |  |  | register BYTE   *dest = pscan(y)[x]; | 
| 695 |  |  |  | 
| 696 |  |  | copycolr(dest, backcolr); | 
| 697 | greg | 1.13 | zscan(y)[x] = backz; | 
| 698 |  |  | } | 
| 699 |  |  |  | 
| 700 |  |  |  | 
| 701 | greg | 2.3 | calstart(prog, args)                    /* start fill calculation */ | 
| 702 | greg | 1.13 | char    *prog, *args; | 
| 703 |  |  | { | 
| 704 |  |  | char    combuf[512]; | 
| 705 | greg | 2.3 | char    *argv[64]; | 
| 706 |  |  | int     rval; | 
| 707 |  |  | register char   **wp, *cp; | 
| 708 | greg | 1.13 |  | 
| 709 | greg | 1.14 | if (childpid != -1) { | 
| 710 |  |  | fprintf(stderr, "%s: too many calculations\n", progname); | 
| 711 |  |  | exit(1); | 
| 712 |  |  | } | 
| 713 | greg | 2.3 | strcpy(combuf, prog); | 
| 714 |  |  | strcat(combuf, args); | 
| 715 |  |  | cp = combuf; | 
| 716 |  |  | wp = argv; | 
| 717 |  |  | for ( ; ; ) { | 
| 718 |  |  | while (isspace(*cp)) cp++; | 
| 719 |  |  | if (!*cp) break; | 
| 720 |  |  | *wp++ = cp; | 
| 721 |  |  | while (!isspace(*cp)) | 
| 722 |  |  | if (!*cp++) goto done; | 
| 723 |  |  | *cp++ = '\0'; | 
| 724 |  |  | } | 
| 725 |  |  | done: | 
| 726 |  |  | *wp = NULL; | 
| 727 |  |  | /* start process */ | 
| 728 |  |  | if ((rval = open_process(PDesc, argv)) < 0) | 
| 729 | greg | 1.14 | syserror(); | 
| 730 | greg | 2.3 | if (rval == 0) { | 
| 731 |  |  | fprintf(stderr, "%s: command not found\n", argv[0]); | 
| 732 |  |  | exit(1); | 
| 733 | greg | 1.13 | } | 
| 734 | greg | 2.3 | packsiz = rval/(6*sizeof(float)) - 1; | 
| 735 |  |  | if (packsiz > PACKSIZ) | 
| 736 |  |  | packsiz = PACKSIZ; | 
| 737 | greg | 1.13 | queuesiz = 0; | 
| 738 |  |  | } | 
| 739 |  |  |  | 
| 740 |  |  |  | 
| 741 | greg | 2.3 | caldone()                               /* done with calculation */ | 
| 742 | greg | 1.13 | { | 
| 743 | greg | 1.14 | if (childpid == -1) | 
| 744 |  |  | return; | 
| 745 | greg | 1.25 | clearqueue(); | 
| 746 | greg | 2.3 | close_process(PDesc); | 
| 747 | greg | 1.14 | childpid = -1; | 
| 748 | greg | 1.13 | } | 
| 749 |  |  |  | 
| 750 |  |  |  | 
| 751 | greg | 1.14 | rcalfill(x, y)                          /* fill with ray-calculated pixel */ | 
| 752 | greg | 1.13 | int     x, y; | 
| 753 |  |  | { | 
| 754 | greg | 2.3 | if (queuesiz >= packsiz)        /* flush queue if needed */ | 
| 755 | greg | 1.25 | clearqueue(); | 
| 756 | greg | 1.22 | /* add position to queue */ | 
| 757 | greg | 1.13 | queue[queuesiz][0] = x; | 
| 758 |  |  | queue[queuesiz][1] = y; | 
| 759 |  |  | queuesiz++; | 
| 760 |  |  | } | 
| 761 |  |  |  | 
| 762 |  |  |  | 
| 763 | greg | 1.25 | clearqueue()                            /* process queue */ | 
| 764 | greg | 1.13 | { | 
| 765 | greg | 1.22 | FVECT   orig, dir; | 
| 766 | greg | 2.3 | float   fbuf[6*(PACKSIZ+1)]; | 
| 767 |  |  | register float  *fbp; | 
| 768 | greg | 1.13 | register int    i; | 
| 769 |  |  |  | 
| 770 | greg | 2.3 | fbp = fbuf; | 
| 771 | greg | 1.13 | for (i = 0; i < queuesiz; i++) { | 
| 772 | greg | 1.22 | viewray(orig, dir, &ourview, | 
| 773 |  |  | (queue[i][0]+.5)/hresolu, | 
| 774 |  |  | (queue[i][1]+.5)/vresolu); | 
| 775 | greg | 2.3 | *fbp++ = orig[0]; *fbp++ = orig[1]; *fbp++ = orig[2]; | 
| 776 |  |  | *fbp++ = dir[0]; *fbp++ = dir[1]; *fbp++ = dir[2]; | 
| 777 | greg | 1.22 | } | 
| 778 | greg | 2.3 | /* mark end and get results */ | 
| 779 |  |  | bzero((char *)fbp, 6*sizeof(float)); | 
| 780 |  |  | if (process(PDesc, fbuf, fbuf, 4*sizeof(float)*queuesiz, | 
| 781 |  |  | 6*sizeof(float)*(queuesiz+1)) != | 
| 782 |  |  | 4*sizeof(float)*queuesiz) { | 
| 783 |  |  | fprintf(stderr, "%s: error reading from rtrace process\n", | 
| 784 |  |  | progname); | 
| 785 |  |  | exit(1); | 
| 786 |  |  | } | 
| 787 |  |  | fbp = fbuf; | 
| 788 | greg | 1.22 | for (i = 0; i < queuesiz; i++) { | 
| 789 | greg | 1.16 | if (ourexp > 0 && ourexp != 1.0) { | 
| 790 | greg | 2.3 | fbp[0] *= ourexp; | 
| 791 |  |  | fbp[1] *= ourexp; | 
| 792 |  |  | fbp[2] *= ourexp; | 
| 793 | greg | 1.14 | } | 
| 794 | greg | 1.13 | setcolr(pscan(queue[i][1])[queue[i][0]], | 
| 795 | greg | 2.3 | fbp[0], fbp[1], fbp[2]); | 
| 796 |  |  | zscan(queue[i][1])[queue[i][0]] = fbp[3]; | 
| 797 |  |  | fbp += 4; | 
| 798 | greg | 1.13 | } | 
| 799 |  |  | queuesiz = 0; | 
| 800 | greg | 1.14 | } | 
| 801 |  |  |  | 
| 802 |  |  |  | 
| 803 |  |  | syserror()                      /* report error and exit */ | 
| 804 |  |  | { | 
| 805 |  |  | perror(progname); | 
| 806 |  |  | exit(1); | 
| 807 | greg | 1.1 | } |