--- ray/src/px/ra_rgbe.c 1991/08/23 17:37:14 1.1 +++ ray/src/px/ra_rgbe.c 1998/01/23 09:28:29 2.7 @@ -1,4 +1,4 @@ -/* Copyright (c) 1991 Regents of the University of California */ +/* Copyright (c) 1992 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; @@ -9,9 +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 */ @@ -24,7 +31,7 @@ int argc; char *argv[]; { int i; - + progname = argv[0]; for (i = 1; i < argc; i++) @@ -52,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: @@ -78,29 +89,34 @@ char *err; transfer() /* transfer Radiance picture */ { - extern double pow(); - int xmax, ymax; + static char ourfmt[LPICFMT+1] = PICFMT; + int order; + int xmax, ymax; COLR *scanin; - register int x; int y; /* get header info. */ - if (checkheader(stdin, COLRFMT, stdout) < 0 || - fgetresolu(&xmax, &ymax, stdin) != (YMAJOR|YDECR)) + 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) + fprintf(stdout, " -e %+d", bradj); + if (!doflat) + fputs(" -r", stdout); + fputc('\n', stdout); + if (bradj) fputexpos(pow(2.0, (double)bradj), stdout); - if (!doflat) { - fputformat(COLRFMT, stdout); - printf("%s -r\n\n", progname); - } else - printf("%s\n\n", progname); - fputresolu(YMAJOR|YDECR, xmax, ymax, 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) @@ -110,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);