| 10 |
|
#include "rtio.h" |
| 11 |
|
#include "resolu.h" |
| 12 |
|
#include "platform.h" |
| 13 |
– |
#include "paths.h" |
| 13 |
|
#include "random.h" |
| 14 |
|
#include "rmatrix.h" |
| 15 |
|
#if !defined(_WIN32) && !defined(_WIN64) |
| 16 |
|
#include <sys/mman.h> |
| 17 |
+ |
#include <sys/wait.h> |
| 18 |
|
#endif |
| 19 |
|
|
| 20 |
+ |
#define VIEWSTR "VIEW=" /* borrowed from common/view.h */ |
| 21 |
+ |
#define VIEWSTRL 5 |
| 22 |
+ |
|
| 23 |
|
int nprocs = 1; /* # of calculation processes (Unix) */ |
| 24 |
|
int in_type = DTfromHeader; /* input data type */ |
| 25 |
|
int out_type = DTfromHeader; /* output data type */ |
| 29 |
|
int iswapped = 0; /* input data is byte-swapped? */ |
| 30 |
|
int ncomp = 3; /* # input components */ |
| 31 |
|
int xres=0, yres=0; /* input image dimensions */ |
| 32 |
+ |
char viewspec[128] = ""; /* VIEW= line from first header */ |
| 33 |
+ |
char pixasp[48] = ""; /* PIXASPECT= line from header */ |
| 34 |
|
|
| 35 |
+ |
int gargc; /* global argc */ |
| 36 |
+ |
char **gargv; /* global argv */ |
| 37 |
+ |
|
| 38 |
|
RMATRIX *cmtx = NULL; /* coefficient matrix */ |
| 39 |
|
|
| 40 |
|
/* does the given spec contain integer format? */ |
| 87 |
|
iswapped = (i != nativebigendian()); |
| 88 |
|
return(1); |
| 89 |
|
} |
| 90 |
+ |
if (!strncmp(s, VIEWSTR, VIEWSTRL)) { |
| 91 |
+ |
strcpy(viewspec, s); |
| 92 |
+ |
return(1); |
| 93 |
+ |
} |
| 94 |
+ |
if (isaspect(s)) { |
| 95 |
+ |
strcpy(pixasp, s); |
| 96 |
+ |
return(1); |
| 97 |
+ |
} |
| 98 |
|
return(0); |
| 99 |
|
} |
| 100 |
|
|
| 258 |
|
fputs(cmtx->info, fp); |
| 259 |
|
else |
| 260 |
|
fputnow(fp); |
| 261 |
+ |
printargs(gargc, gargv, fp); /* this command */ |
| 262 |
|
if (fno >= 0) |
| 263 |
|
fprintf(fp, "FRAME=%d\n", fno); |
| 264 |
+ |
if (viewspec[0]) |
| 265 |
+ |
fputs(viewspec, fp); |
| 266 |
+ |
if (pixasp[0]) |
| 267 |
+ |
fputs(pixasp, fp); |
| 268 |
|
switch (out_type) { |
| 269 |
|
case DTfloat: |
| 270 |
|
case DTdouble: |
| 400 |
|
return(0); |
| 401 |
|
} |
| 402 |
|
|
| 403 |
+ |
#if defined(_WIN32) || defined(_WIN64) |
| 404 |
+ |
#define multi_process solo_process |
| 405 |
+ |
#else |
| 406 |
+ |
|
| 407 |
|
/* allocate a scrambled index array of the specified length */ |
| 408 |
|
int * |
| 409 |
|
scramble(int n) |
| 431 |
|
int |
| 432 |
|
multi_process(void) |
| 433 |
|
{ |
| 409 |
– |
#if defined(_WIN32) || defined(_WIN64) |
| 410 |
– |
fputs("Bad call to multi_process()\n", stderr); |
| 411 |
– |
return(0); |
| 412 |
– |
#else |
| 434 |
|
int coff = nprocs; |
| 435 |
|
int odd = 0; |
| 436 |
|
char fbuf[512]; |
| 492 |
|
return(0); |
| 493 |
|
} |
| 494 |
|
i = in_type==DTfloat ? ncomp*(int)sizeof(float) : ncomp+1; |
| 495 |
< |
maplen = dstart + yres*xres*i; |
| 495 |
> |
maplen = dstart + (size_t)yres*xres*i; |
| 496 |
|
imap = mmap(NULL, maplen, PROT_READ, |
| 497 |
|
MAP_FILE|MAP_SHARED, fileno(finp), 0); |
| 498 |
|
fclose(finp); /* will read from map (randomly) */ |
| 559 |
|
writerr: |
| 560 |
|
fprintf(stderr, "%s: write error\n", fbuf); |
| 561 |
|
return(0); |
| 541 |
– |
#endif |
| 562 |
|
} |
| 563 |
|
|
| 564 |
+ |
#endif /* ! Windows */ |
| 565 |
+ |
|
| 566 |
|
int |
| 567 |
|
main(int argc, char *argv[]) |
| 568 |
|
{ |
| 569 |
|
int a; |
| 570 |
|
|
| 571 |
+ |
gargc = argc; /* for header output */ |
| 572 |
+ |
gargv = argv; |
| 573 |
+ |
|
| 574 |
|
for (a = 1; a < argc-1 && argv[a][0] == '-'; a++) |
| 575 |
|
switch (argv[a][1]) { |
| 576 |
|
case 'o': /* output spec/format */ |
| 602 |
|
if ((argc-a < 1) | (argc-a > 2) || argv[a][0] == '-') |
| 603 |
|
goto userr; |
| 604 |
|
in_spec = argv[a]; |
| 605 |
< |
cmtx = rmx_load(argv[a+1], RMPnone); /* loads from stdin if a+1==argc */ |
| 605 |
> |
cmtx = rmx_load(argv[a+1]); /* loads from stdin if a+1==argc */ |
| 606 |
|
if (cmtx == NULL) |
| 607 |
|
return(1); /* error reported */ |
| 608 |
|
if (nprocs > cmtx->ncols) |