--- ray/src/px/ra_rgbe.c 1992/01/03 22:58:08 2.2 +++ ray/src/px/ra_rgbe.c 1998/01/23 09:28:29 2.7 @@ -9,10 +9,16 @@ static char SCCSid[] = "$SunId$ LBL"; */ #include - +#include #include "color.h" #include "resolu.h" +#ifdef MSDOS +#include +#endif + +extern char *malloc(); + int bradj = 0; /* brightness adjustment */ int doflat = 1; /* produce flat file */ @@ -25,7 +31,7 @@ int argc; char *argv[]; { int i; - + progname = argv[0]; for (i = 1; i < argc; i++) @@ -53,10 +59,14 @@ char *argv[]; exit(1); } if (i == argc-2 && freopen(argv[i+1], "w", stdout) == NULL) { - fprintf(stderr, "can't open output \"%s\"\n", + fprintf(stderr, "%s: can't open output \"%s\"\n", progname, argv[i+1]); exit(1); } +#ifdef MSDOS + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); +#endif transfer(); exit(0); userr: @@ -79,35 +89,34 @@ char *err; transfer() /* transfer Radiance picture */ { - extern double pow(); + static char ourfmt[LPICFMT+1] = PICFMT; int order; - int xmax, ymax; + int xmax, ymax; COLR *scanin; - register int x; int y; /* get header info. */ - if (checkheader(stdin, COLRFMT, stdout) < 0 || + if ((y = checkheader(stdin, ourfmt, stdout)) < 0 || (order = fgetresolu(&xmax, &ymax, stdin)) < 0) quiterr("bad picture format"); + if (!y) + strcpy(ourfmt, COLRFMT); fputs(progname, stdout); if (bradj) - printf(" -e %+d", bradj); - if (doflat) - fputs("\n", stdout); - else { - fputs(" -r\n", stdout); - fputformat(COLRFMT, stdout); - } + fprintf(stdout, " -e %+d", bradj); + if (!doflat) + fputs(" -r", stdout); + fputc('\n', stdout); if (bradj) fputexpos(pow(2.0, (double)bradj), stdout); - fputs("\n", stdout); + fputformat(ourfmt, stdout); + fputc('\n', stdout); fputresolu(order, xmax, ymax, stdout); /* allocate scanline */ scanin = (COLR *)malloc(xmax*sizeof(COLR)); if (scanin == NULL) quiterr("out of memory in transfer"); /* convert image */ - for (y = ymax-1; y >= 0; y--) { + for (y = ymax; y--; ) { if (freadcolrs(scanin, xmax, stdin) < 0) quiterr("error reading input picture"); if (bradj) @@ -117,7 +126,7 @@ transfer() /* transfer Radiance picture */ else fwritecolrs(scanin, xmax, stdout); if (ferror(stdout)) - quiterr("error writing rasterfile"); + quiterr("error writing output picture"); } /* free scanline */ free((char *)scanin);