--- ray/src/px/protate.c 1990/01/25 08:28:35 1.4 +++ ray/src/px/protate.c 1991/11/11 14:01:44 1.9 @@ -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 */ @@ -65,11 +81,11 @@ char *argv[]; rotate(fp) /* rotate picture */ FILE *fp; { - register COLR *inline; + register COLR *inln; register int xoff, inx, iny; long start, ftell(); - if ((inline = (COLR *)malloc(xres*sizeof(COLR))) == NULL) { + if ((inln = (COLR *)malloc(xres*sizeof(COLR))) == NULL) { fprintf(stderr, "%s: out of memory\n", progname); exit(1); } @@ -80,12 +96,12 @@ FILE *fp; exit(1); } for (iny = yres-1; iny >= 0; iny--) { - if (freadcolrs(inline, xres, fp) < 0) { + if (freadcolrs(inln, xres, fp) < 0) { fprintf(stderr, "%s: read error\n", progname); exit(1); } for (inx = 0; inx < nrows && xoff+inx < xres; inx++) - bcopy((char *)inline[xoff+inx], + bcopy((char *)inln[xoff+inx], (char *)scanbar[inx*yres+iny], sizeof(COLR)); } @@ -95,5 +111,5 @@ FILE *fp; exit(1); } } - free((char *)inline); + free((char *)inln); }