--- ray/src/px/pflip.c 1991/11/11 14:02:02 1.5 +++ ray/src/px/pflip.c 2003/07/03 22:41:44 2.7 @@ -1,17 +1,16 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: pflip.c,v 2.7 2003/07/03 22:41:44 schorsch Exp $"; #endif - /* * flip picture file horizontally and/or vertically */ #include +#include +#include +#include "platform.h" #include "color.h" - #include "resolu.h" int order; /* input orientation */ @@ -50,8 +49,10 @@ main(argc, argv) int argc; char *argv[]; { - int i; - + static char picfmt[LPICFMT+1] = PICFMT; + int i, rval; + SET_DEFAULT_BINARY(); + SET_FILE_BINARY(stdout); progname = argv[0]; for (i = 1; i < argc; i++) @@ -77,14 +78,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,14 +120,15 @@ 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); } } - free((char *)scanin); + scanpos[0] = ftell(fin); + free((void *)scanin); } @@ -159,6 +162,7 @@ flip() /* flip the picture */ exit(1); } } - free((char *)scanin); - free((char *)scanout); + free((void *)scanin); + if (fhoriz) + free((void *)scanout); }