Skip to content

Commit

Permalink
fix(rcode_depth, rcode_norm): TEXT/BINARY mode was mishandled for Win…
Browse files Browse the repository at this point in the history
…dows
  • Loading branch information
Gregungory committed Jul 20, 2020
1 parent 4f41e0a commit a0cb878
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
14 changes: 9 additions & 5 deletions src/util/rcode_depth.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static const char RCSid[] = "$Id: rcode_depth.c,v 2.10 2020/02/12 01:13:01 greg Exp $";
static const char RCSid[] = "$Id: rcode_depth.c,v 2.11 2020/07/20 15:53:30 greg Exp $";
#endif
/*
* Encode and decode depth map using 16-bit integers
Expand Down Expand Up @@ -59,6 +59,8 @@ encode_depths(DEPTHCODEC *dcp)
return 0;
}
}
if (dcp->format == 'a')
SET_FILE_TEXT(dcp->finp);

do {
int ok = 0;
Expand Down Expand Up @@ -256,7 +258,7 @@ 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);
Expand Down Expand Up @@ -416,16 +418,18 @@ 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);
#endif
/* 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 */
Expand Down
13 changes: 9 additions & 4 deletions src/util/rcode_norm.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef lint
static const char RCSid[] = "$Id: rcode_norm.c,v 2.7 2020/02/12 01:13:01 greg Exp $";
static const char RCSid[] = "$Id: rcode_norm.c,v 2.8 2020/07/20 15:53:30 greg Exp $";
#endif
/*
* Encode and decode surface normal map using 32-bit integers
Expand Down Expand Up @@ -52,6 +52,8 @@ encode_normals(NORMCODEC *ncp)
return 0;
}
}
if (ncp->format == 'a')
SET_FILE_TEXT(ncp->finp);

do {
int ok = 0;
Expand Down Expand Up @@ -189,6 +191,7 @@ pixel_normals(NORMCODEC *ncp, int unbuf)
fputs(": can only handle standard pixel ordering\n", stderr);
return 0;
}

while (scanf("%d %d", &x, &y) == 2) {

y = ncp->res.yr-1 - y;
Expand Down Expand Up @@ -339,16 +342,18 @@ main(int argc, char *argv[])
fputs(": cannot open for writing\n", stderr);
return 1;
}
SET_FILE_BINARY(nc.finp);
if (reverse || nc.format != 'a')
SET_FILE_BINARY(stdout);
SET_FILE_BINARY(dc.finp); /* starting assumption */
SET_FILE_BINARY(stdout);
#ifdef getc_unlocked /* avoid stupid semaphores */
flockfile(nc.finp);
flockfile(stdout);
#endif
/* read/copy header */
if (!process_nc_header(&nc, a, argv))
return 1;

if (reverse && nc.format == 'a')
SET_FILE_TEXT(stdout);
/* process data */
if (!reverse) {
if (!encode_normals(&nc))
Expand Down

0 comments on commit a0cb878

Please # to comment.