--- ray/src/util/rcode_depth.c 2020/02/11 18:15:23 2.9 +++ ray/src/util/rcode_depth.c 2022/06/30 00:16:49 2.12 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcode_depth.c,v 2.9 2020/02/11 18:15:23 greg Exp $"; +static const char RCSid[] = "$Id: rcode_depth.c,v 2.12 2022/06/30 00:16:49 greg Exp $"; #endif /* * Encode and decode depth map using 16-bit integers @@ -45,11 +45,11 @@ encode_depths(DEPTHCODEC *dcp) long nexpected = (long)dcp->res.xr * dcp->res.yr; if (dcp->inpfmt[0]) { - if (strstr(dcp->inpfmt, "ascii") != NULL) + if (!strcmp(dcp->inpfmt, "ascii")) dcp->format = 'a'; - else if (strstr(dcp->inpfmt, "float") != NULL) + else if (!strcmp(dcp->inpfmt, "float")) dcp->format = 'f'; - else if (strstr(dcp->inpfmt, "double") != NULL) + else if (!strcmp(dcp->inpfmt, "double")) dcp->format = 'd'; else { fputs(dcp->inpname, stderr); @@ -59,6 +59,8 @@ encode_depths(DEPTHCODEC *dcp) return 0; } } + if (dcp->format == 'a') + SET_FILE_TEXT(dcp->finp); do { int ok = 0; @@ -160,16 +162,12 @@ pixel_depths(DEPTHCODEC *dcp, int unbuf) return 0; while (scanf("%d %d", &xy[0], &xy[1]) == 2) { - - loc2pix(xy, &dcp->res, - (xy[0]+.5)/dcp->res.xr, (xy[1]+.5)/dcp->res.yr); - + loc2pix(xy, &dcp->res, xy[0]/(double)dcp->res.xr, + xy[1]/(double)dcp->res.yr); d = decode_depth_pix(dcp, xy[0], xy[1]); if (d < -FTINY) return 0; - output_depth(dcp, d); - if (unbuf && fflush(stdout) == EOF) { fputs(progname, stderr); fputs(": write error on output\n", stderr); @@ -256,10 +254,10 @@ pixel_points(DEPTHCODEC *dcp, int unbuf) } if (!check_decode_worldpos(dcp)) return 0; - + while (scanf("%d %d", &xy[0], &xy[1]) == 2) { - loc2pix(xy, &dcp->res, - (xy[0]+.5)/dcp->res.xr, (xy[1]+.5)/dcp->res.yr); + loc2pix(xy, &dcp->res, xy[0]/(double)dcp->res.xr, + xy[1]/(double)dcp->res.yr); if (get_worldpos_pix(wpos, dcp, xy[0], xy[1]) < 0) return 0; output_worldpos(dcp, wpos); @@ -416,9 +414,8 @@ main(int argc, char *argv[]) fputs(": cannot open for writing\n", stderr); return 1; } - SET_FILE_BINARY(dc.finp); - if ((conversion != CV_FWD) | (dc.format != 'a')) - SET_FILE_BINARY(stdout); + SET_FILE_BINARY(dc.finp); /* starting assumption */ + SET_FILE_BINARY(stdout); #ifdef getc_unlocked /* avoid stupid semaphores */ flockfile(dc.finp); flockfile(stdout); @@ -426,6 +423,9 @@ main(int argc, char *argv[]) /* read/copy header */ if (!process_dc_header(&dc, a, argv)) return 1; + + if ((conversion != CV_FWD) & (dc.format == 'a')) + SET_FILE_TEXT(stdout); /* process data */ switch (conversion) { case CV_FWD: /* distance -> depth code */