9 |
|
|
10 |
|
#include <stdlib.h> |
11 |
|
#include "platform.h" |
12 |
+ |
#include "paths.h" |
13 |
|
#include "rtio.h" |
14 |
|
#include "rtmath.h" |
15 |
|
#include "normcodec.h" |
16 |
|
|
16 |
– |
char *progname; /* set in main() */ |
17 |
|
|
18 |
– |
|
18 |
|
/* Report usage error and exit */ |
19 |
|
static void |
20 |
|
usage_exit(int code) |
37 |
|
long nexpected = (long)ncp->res.xr * ncp->res.yr; |
38 |
|
|
39 |
|
if (ncp->inpfmt[0]) { |
40 |
< |
if (strstr(ncp->inpfmt, "ascii") != NULL) |
40 |
> |
if (!strcmp(ncp->inpfmt, "ascii")) |
41 |
|
ncp->format = 'a'; |
42 |
< |
else if (strstr(ncp->inpfmt, "float") != NULL) |
42 |
> |
else if (!strcmp(ncp->inpfmt, "float")) |
43 |
|
ncp->format = 'f'; |
44 |
< |
else if (strstr(ncp->inpfmt, "double") != NULL) |
44 |
> |
else if (!strcmp(ncp->inpfmt, "double")) |
45 |
|
ncp->format = 'd'; |
46 |
|
else { |
47 |
|
fputs(ncp->inpname, stderr); |
51 |
|
return 0; |
52 |
|
} |
53 |
|
} |
54 |
+ |
if (ncp->format == 'a') |
55 |
+ |
SET_FILE_TEXT(ncp->finp); |
56 |
|
|
57 |
|
do { |
58 |
|
int ok = 0; |
190 |
|
fputs(": can only handle standard pixel ordering\n", stderr); |
191 |
|
return 0; |
192 |
|
} |
193 |
+ |
|
194 |
|
while (scanf("%d %d", &x, &y) == 2) { |
195 |
|
|
196 |
|
y = ncp->res.yr-1 - y; |
224 |
|
int unbuffered = 0; |
225 |
|
NORMCODEC nc; |
226 |
|
int a; |
227 |
< |
|
228 |
< |
progname = argv[0]; |
227 |
> |
/* set global progname */ |
228 |
> |
fixargv0(argv[0]); |
229 |
|
set_nc_defaults(&nc); |
230 |
|
nc.hdrflags = HF_ALL; |
231 |
|
for (a = 1; a < argc && argv[a][0] == '-'; a++) |
341 |
|
fputs(": cannot open for writing\n", stderr); |
342 |
|
return 1; |
343 |
|
} |
344 |
< |
SET_FILE_BINARY(nc.finp); |
345 |
< |
if (reverse || nc.format != 'a') |
344 |
< |
SET_FILE_BINARY(stdout); |
344 |
> |
SET_FILE_BINARY(nc.finp); /* starting assumption */ |
345 |
> |
SET_FILE_BINARY(stdout); |
346 |
|
#ifdef getc_unlocked /* avoid stupid semaphores */ |
347 |
|
flockfile(nc.finp); |
348 |
|
flockfile(stdout); |
350 |
|
/* read/copy header */ |
351 |
|
if (!process_nc_header(&nc, a, argv)) |
352 |
|
return 1; |
353 |
+ |
|
354 |
+ |
if (reverse && nc.format == 'a') |
355 |
+ |
SET_FILE_TEXT(stdout); |
356 |
|
/* process data */ |
357 |
|
if (!reverse) { |
358 |
|
if (!encode_normals(&nc)) |