--- ray/src/hd/rhcopy.c 2008/11/10 19:08:19 3.24 +++ ray/src/hd/rhcopy.c 2019/11/07 23:17:58 3.33 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rhcopy.c,v 3.24 2008/11/10 19:08:19 greg Exp $"; +static const char RCSid[] = "$Id: rhcopy.c,v 3.33 2019/11/07 23:17:58 greg Exp $"; #endif /* * Copy data into a holodeck file @@ -94,14 +94,16 @@ userr: #define H_BADF 01 #define H_OBST 02 #define H_OBSF 04 +#define H_SWAP 010 static int holheadline( /* check holodeck header line */ - register char *s, + char *s, void *vhf ) { - char fmt[32]; + int be; + char fmt[MAXFMTLEN]; int *hf = vhf; if (formatval(fmt, s)) { @@ -122,6 +124,10 @@ holheadline( /* check holodeck header line */ error(WARNING, "bad OBSTRUCTIONS value in holodeck"); return(0); } + if ((be = isbigendian(s)) >= 0) { + if (be != nativebigendian()) + *hf |= H_SWAP; + } return(0); } @@ -134,25 +140,25 @@ openholo( /* open existing holodeck file for i/o */ FILE *fp; int fd; int hflags = 0; - long nextloc; + off_t nextloc; int n; /* open holodeck file */ - if ((fp = fopen(fname, append ? "r+" : "r")) == NULL) { + if ((fp = fopen(fname, append ? "rb+" : "rb")) == NULL) { sprintf(errmsg, "cannot open \"%s\" for %s", fname, append ? "appending" : "reading"); error(SYSTEM, errmsg); } /* check header and magic number */ if (getheader(fp, holheadline, &hflags) < 0 || - hflags&H_BADF || getw(fp) != HOLOMAGIC) { - sprintf(errmsg, "file \"%s\" not in holodeck format", fname); + hflags&(H_BADF|H_SWAP) || getw(fp) != HOLOMAGIC) { + sprintf(errmsg, "holodeck \"%s\" not in expected format", fname); error(USER, errmsg); } fd = dup(fileno(fp)); /* dup file handle */ nextloc = ftell(fp); /* get stdio position */ fclose(fp); /* done with stdio */ for (n = 0; nextloc > 0L; n++) { /* initialize each section */ - lseek(fd, (off_t)nextloc, SEEK_SET); + lseek(fd, nextloc, SEEK_SET); read(fd, (char *)&nextloc, sizeof(nextloc)); hdinit(fd, NULL)->priv = hflags&H_OBST ? &obstr : hflags&H_OBSF ? &unobstr : (char *)NULL; @@ -174,13 +180,13 @@ addray( /* add a ray to our output holodeck */ ) { int sn, bi, n; - register HOLO *hp; + HOLO *hp; GCOORD gc[2]; - BYTE rr[2][2]; + uby8 rr[2][2]; BEAM *bp; double d0, d1; unsigned dc; - register RAYVAL *rv; + RAYVAL *rv; /* check each output section */ for (sn = noutsects; sn--; ) { hp = hdlist[sn]; @@ -223,7 +229,7 @@ bpcmp( /* compare beam positions on disk */ const void *b2p ) { - register off_t pdif = beamdir[*(int*)b1p].fo - beamdir[*(int*)b2p].fo; + off_t pdif = beamdir[*(int*)b1p].fo - beamdir[*(int*)b2p].fo; if (pdif > 0L) return(1); if (pdif < 0L) return(-1); @@ -241,8 +247,8 @@ addclump( /* transfer the given clump and free */ FVECT ro, rd; double d; int i; - register int k; - register BEAM *bp; + int k; + BEAM *bp; /* sort based on file position */ beamdir = hp->bi; qsort((char *)bq, nb, sizeof(*bq), bpcmp); @@ -334,9 +340,9 @@ addpicz( /* add a picture + depth-buffer */ double aftd; COLOR ctmp; int j; - register int i; + int i; /* open files */ - if ((pfp = fopen(pcf, "r")) == NULL) { + if ((pfp = fopen(pcf, "rb")) == NULL) { sprintf(errmsg, "cannot open picture file \"%s\"", pcf); error(SYSTEM, pcf); } @@ -344,6 +350,7 @@ addpicz( /* add a picture + depth-buffer */ sprintf(errmsg, "cannot open depth file \"%s\"", zbf); error(SYSTEM, pcf); } + SET_FD_BINARY(zfd); /* load picture header */ phd.vw = stdview; phd.expos = 1.0; @@ -359,7 +366,7 @@ addpicz( /* add a picture + depth-buffer */ error(USER, errmsg); } if (phd.altprims) { - sprintf(errmsg, "ignoring primary values in picture \"%s\"", + sprintf(errmsg, "ignoring color primaries in picture \"%s\"", pcf); error(WARNING, errmsg); } @@ -392,12 +399,14 @@ addpicz( /* add a picture + depth-buffer */ } if (eshft) /* shift exposure */ shiftcolrs(cscn, i, eshft); - i *= sizeof(float); /* read depth */ - if (read(zfd, (char *)zscn, i) != i) { + /* read depth */ + if (read(zfd, zscn, i*sizeof(float)) != i*sizeof(float)) { sprintf(errmsg, "error reading depth file \"%s\"", zbf); error(USER, errmsg); } - for (i = scanlen(&prs); i--; ) { /* do each pixel */ + while (i--) { /* process each pixel */ + if (zscn[i] <= 0.0) + continue; /* illegal depth */ pix2loc(vl, &prs, i, j); aftd = viewray(ro, rd, &phd.vw, vl[0], vl[1]); if (aftd < -FTINY) @@ -425,7 +434,7 @@ addpicz( /* add a picture + depth-buffer */ void eputs( /* put error message to stderr */ - register char *s + char *s ) { static int midline = 0;