--- ray/src/px/ra_ppm.c 1991/11/11 14:01:32 1.2 +++ ray/src/px/ra_ppm.c 1994/02/27 10:17:07 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"; @@ -10,14 +10,21 @@ static char SCCSid[] = "$SunId$ LBL"; #include +#ifdef MSDOS +#include +#endif + +#include + #include #include "color.h" #include "resolu.h" -extern double atof(), pow(); +extern char *malloc(); + int agryscan(), bgryscan(), aclrscan(), bclrscan(); int bradj = 0; /* brightness adjustment */ @@ -33,7 +40,8 @@ main(argc, argv) int argc; char *argv[]; { - double gamma = 2.2; + char inpbuf[2]; + double gamcor = 2.2; int binflag = 1; int reverse = 0; int ptype; @@ -45,7 +53,7 @@ char *argv[]; if (argv[i][0] == '-') switch (argv[i][1]) { case 'g': - gamma = atof(argv[++i]); + gamcor = atof(argv[++i]); break; case 'e': if (argv[i+1][0] != '+' && argv[i+1][0] != '-') @@ -72,20 +80,26 @@ 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); } - setcolrgam(gamma); + setcolrgam(gamcor); if (reverse) { /* get header */ - if (getc(stdin) != 'P') + if (read(fileno(stdin), inpbuf, 2) != 2 || inpbuf[0] != 'P') quiterr("input not a Poskanzer Pixmap"); - ptype = getc(stdin); + ptype = inpbuf[1]; +#ifdef MSDOS + if (ptype > 4) + setmode(fileno(stdin), O_BINARY); + setmode(fileno(stdout), O_BINARY); +#endif xmax = scanint(stdin); ymax = scanint(stdin); maxval = scanint(stdin); /* put header */ + newheader("RADIANCE", stdout); printargs(i, argv, stdout); fputformat(COLRFMT, stdout); putchar('\n'); @@ -108,6 +122,11 @@ char *argv[]; quiterr("unsupported Pixmap type"); } } else { +#ifdef MSDOS + setmode(fileno(stdin), O_BINARY); + if (binflag) + setmode(fileno(stdout), O_BINARY); +#endif /* get header info. */ if (checkheader(stdin, COLRFMT, NULL) < 0 || fgetresolu(&xmax, &ymax, stdin) < 0) @@ -142,7 +161,6 @@ ppm2ra(getscan) /* convert color Pixmap to Radiance p int (*getscan)(); { COLR *scanout; - register int x; int y; /* allocate scanline */ scanout = (COLR *)malloc(xmax*sizeof(COLR));