| 31 |
|
char *argv[]; |
| 32 |
|
{ |
| 33 |
|
int i; |
| 34 |
< |
#ifdef MSDOS |
| 35 |
< |
extern int _fmode; |
| 36 |
< |
_fmode = O_BINARY; |
| 37 |
< |
setmode(fileno(stdin), O_BINARY); |
| 38 |
< |
setmode(fileno(stdout), O_BINARY); |
| 39 |
< |
#endif |
| 34 |
> |
|
| 35 |
|
progname = argv[0]; |
| 36 |
|
|
| 37 |
|
for (i = 1; i < argc; i++) |
| 59 |
|
exit(1); |
| 60 |
|
} |
| 61 |
|
if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) { |
| 62 |
< |
fprintf(stderr, "can't open output \"%s\"\n", |
| 62 |
> |
fprintf(stderr, "%s: can't open output \"%s\"\n", |
| 63 |
|
progname, argv[i+1]); |
| 64 |
|
exit(1); |
| 65 |
|
} |
| 66 |
+ |
#ifdef MSDOS |
| 67 |
+ |
setmode(fileno(stdin), O_BINARY); |
| 68 |
+ |
setmode(fileno(stdout), O_BINARY); |
| 69 |
+ |
#endif |
| 70 |
|
transfer(); |
| 71 |
|
exit(0); |
| 72 |
|
userr: |
| 89 |
|
|
| 90 |
|
transfer() /* transfer Radiance picture */ |
| 91 |
|
{ |
| 92 |
+ |
static char ourfmt[LPICFMT+1] = PICFMT; |
| 93 |
|
int order; |
| 94 |
|
int xmax, ymax; |
| 95 |
|
COLR *scanin; |
| 96 |
– |
register int x; |
| 96 |
|
int y; |
| 97 |
|
/* get header info. */ |
| 98 |
< |
if (checkheader(stdin, COLRFMT, stdout) < 0 || |
| 98 |
> |
if ((y = checkheader(stdin, ourfmt, stdout)) < 0 || |
| 99 |
|
(order = fgetresolu(&xmax, &ymax, stdin)) < 0) |
| 100 |
|
quiterr("bad picture format"); |
| 101 |
+ |
if (!y) |
| 102 |
+ |
strcpy(ourfmt, COLRFMT); |
| 103 |
|
fputs(progname, stdout); |
| 104 |
|
if (bradj) |
| 105 |
< |
printf(" -e %+d", bradj); |
| 106 |
< |
if (doflat) |
| 107 |
< |
fputs("\n", stdout); |
| 108 |
< |
else { |
| 108 |
< |
fputs(" -r\n", stdout); |
| 109 |
< |
fputformat(COLRFMT, stdout); |
| 110 |
< |
} |
| 105 |
> |
fprintf(stdout, " -e %+d", bradj); |
| 106 |
> |
if (!doflat) |
| 107 |
> |
fputs(" -r", stdout); |
| 108 |
> |
fputc('\n', stdout); |
| 109 |
|
if (bradj) |
| 110 |
|
fputexpos(pow(2.0, (double)bradj), stdout); |
| 111 |
< |
fputs("\n", stdout); |
| 111 |
> |
fputformat(ourfmt, stdout); |
| 112 |
> |
fputc('\n', stdout); |
| 113 |
|
fputresolu(order, xmax, ymax, stdout); |
| 114 |
|
/* allocate scanline */ |
| 115 |
|
scanin = (COLR *)malloc(xmax*sizeof(COLR)); |
| 116 |
|
if (scanin == NULL) |
| 117 |
|
quiterr("out of memory in transfer"); |
| 118 |
|
/* convert image */ |
| 119 |
< |
for (y = ymax-1; y >= 0; y--) { |
| 119 |
> |
for (y = ymax; y--; ) { |
| 120 |
|
if (freadcolrs(scanin, xmax, stdin) < 0) |
| 121 |
|
quiterr("error reading input picture"); |
| 122 |
|
if (bradj) |