--- ray/src/px/protate.c 1990/12/04 11:25:46 1.7 +++ ray/src/px/protate.c 1995/02/01 09:52:34 2.3 @@ -1,8 +1,9 @@ -/* Copyright (c) 1988 Regents of the University of California */ +/* Copyright (c) 1991 Regents of the University of California */ #ifndef lint static char SCCSid[] = "$SunId$ LBL"; #endif + /* * prot.c - program to rotate picture file 90 degrees clockwise. * @@ -13,10 +14,18 @@ static char SCCSid[] = "$SunId$ LBL"; #include "color.h" +#include "resolu.h" + +int order; /* input scanline order */ int xres, yres; /* input resolution */ -double inpaspect = 1.0; /* input aspect ratio */ +int correctorder = 0; /* order correction? */ + +#ifdef BIGMEM +char buf[1<<22]; /* output buffer */ +#else char buf[1<<20]; /* output buffer */ +#endif int nrows; /* number of rows output at once */ @@ -24,16 +33,10 @@ int nrows; /* number of rows output at once */ char *progname; +#define neworder() (correctorder ? order : \ + (order^(order&YMAJOR?YDECR:XDECR)^YMAJOR)) -headline(s) /* process line from header */ -char *s; -{ - fputs(s, stdout); - if (isaspect(s)) - inpaspect *= aspectval(s); -} - main(argc, argv) int argc; char *argv[]; @@ -42,8 +45,12 @@ char *argv[]; progname = argv[0]; + if (argc > 2 && !strcmp(argv[1], "-c")) { + correctorder++; + argc--; argv++; + } if (argc != 2 && argc != 3) { - fprintf(stderr, "Usage: %s infile [outfile]\n", progname); + fprintf(stderr, "Usage: %s [-c] infile [outfile]\n", progname); exit(1); } if ((fin = fopen(argv[1], "r")) == NULL) { @@ -55,18 +62,19 @@ char *argv[]; exit(1); } /* transfer header */ - getheader(fin, headline); + if (checkheader(fin, COLRFMT, stdout) < 0) { + fprintf(stderr, "%s: not a Radiance picture\n", progname); + exit(1); + } /* add new header info. */ - if (inpaspect < .99 || inpaspect > 1.01) - fputaspect(1./inpaspect/inpaspect, stdout); - printf("%s\n\n", progname); + printf("%s%s\n\n", progname, correctorder?" -c":""); /* get picture size */ - if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { + if ((order = fgetresolu(&xres, &yres, fin)) < 0) { fprintf(stderr, "%s: bad picture size\n", progname); exit(1); } /* write new picture size */ - fputresolu(YMAJOR|YDECR, yres, xres, stdout); + fputresolu(neworder(), yres, xres, stdout); /* compute buffer capacity */ nrows = sizeof(buf)/sizeof(COLR)/yres; rotate(fin); /* rotate the image */