--- ray/src/px/pflip.c 1991/11/12 16:04:49 2.1 +++ ray/src/px/pflip.c 1995/10/16 11:40:11 2.4 @@ -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,6 +10,10 @@ static char SCCSid[] = "$SunId$ LBL"; #include +#ifdef MSDOS +#include +#endif + #include "color.h" #include "resolu.h" @@ -27,7 +31,9 @@ FILE *fin; /* input file */ char *progname; +extern char *malloc(); + int neworder() /* figure out new order from old */ { @@ -50,8 +56,13 @@ main(argc, argv) int argc; char *argv[]; { - int i; - + static char picfmt[LPICFMT+1] = PICFMT; + int i, rval; +#ifdef MSDOS + extern int _fmode; + _fmode = O_BINARY; + setmode(fileno(stdout), O_BINARY); +#endif progname = argv[0]; for (i = 1; i < argc; i++) @@ -77,14 +88,15 @@ char *argv[]; exit(1); } /* transfer header */ - if (checkheader(fin, COLRFMT, stdout) < 0) { + if ((rval = checkheader(fin, picfmt, stdout)) < 0) { fprintf(stderr, "%s: input not a Radiance picture\n", progname); exit(1); } + if (rval) + fputformat(picfmt, stdout); /* add new header info. */ printargs(i, argv, stdout); - fputformat(COLRFMT, stdout); putchar('\n'); /* get picture size */ if ((order = fgetresolu(&xres, &yres, fin)) < 0) { @@ -118,13 +130,14 @@ scanfile() /* scan to the end of file */ memerr(); if ((scanin = (COLR *)malloc(xres*sizeof(COLR))) == NULL) memerr(); - for (y = yres-1; y >= 0; y--) { + for (y = yres-1; y > 0; y--) { scanpos[y] = ftell(fin); if (freadcolrs(scanin, xres, fin) < 0) { fprintf(stderr, "%s: read error\n", progname); exit(1); } } + scanpos[0] = ftell(fin); free((char *)scanin); } @@ -160,5 +173,6 @@ flip() /* flip the picture */ } } free((char *)scanin); - free((char *)scanout); + if (fhoriz) + free((char *)scanout); }