--- ray/src/px/protate.c 1990/06/26 09:09:35 1.5 +++ ray/src/px/protate.c 1991/11/12 16:04:09 2.1 @@ -1,20 +1,26 @@ -/* 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. * * 2/26/88 */ -#include +#include "standard.h" #include "color.h" +#include "resolu.h" + +int order; /* input scanline order */ int xres, yres; /* input resolution */ +int correctorder = 0; /* order correction? */ + char buf[1<<20]; /* output buffer */ int nrows; /* number of rows output at once */ @@ -23,7 +29,10 @@ int nrows; /* number of rows output at once */ char *progname; +#define neworder() (correctorder ? order : \ + (order^(order&YMAJOR?YDECR:XDECR)^YMAJOR)) + main(argc, argv) int argc; char *argv[]; @@ -32,8 +41,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) { @@ -44,17 +57,20 @@ char *argv[]; fprintf(stderr, "%s: cannot open\n", argv[2]); exit(1); } - /* copy header */ - copyheader(fin, stdout); + /* transfer header */ + if (checkheader(fin, COLRFMT, stdout) < 0) { + fprintf(stderr, "%s: not a Radiance picture\n", progname); + exit(1); + } /* add new header info. */ printf("%s\n\n", progname); /* 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 */