--- ray/src/px/protate.c 1989/09/12 13:04:27 1.2 +++ ray/src/px/protate.c 1995/10/16 11:40:22 2.4 @@ -1,21 +1,31 @@ -/* 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? */ + +#ifdef BIGMEM +char buf[1<<22]; /* output buffer */ +#else char buf[1<<20]; /* output buffer */ +#endif int nrows; /* number of rows output at once */ @@ -23,17 +33,26 @@ 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[]; { + static char picfmt[LPICFMT+1] = PICFMT; + int rval; FILE *fin; 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,18 +63,22 @@ char *argv[]; fprintf(stderr, "%s: cannot open\n", argv[2]); exit(1); } - /* copy header */ - while (fgets(buf, sizeof(buf), fin) != NULL && buf[0] != '\n') - fputs(buf, stdout); + /* transfer header */ + if ((rval = checkheader(fin, picfmt, stdout)) < 0) { + fprintf(stderr, "%s: not a Radiance picture\n", progname); + exit(1); + } + if (rval) + fputformat(picfmt, stdout); /* add new header info. */ - 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 */ @@ -66,11 +89,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); } @@ -81,12 +104,13 @@ 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(inline[xoff+inx], scanbar[inx*yres+iny], + bcopy((char *)inln[xoff+inx], + (char *)scanbar[inx*yres+iny], sizeof(COLR)); } for (inx = 0; inx < nrows && xoff+inx < xres; inx++) @@ -95,5 +119,5 @@ FILE *fp; exit(1); } } - free((char *)inline); + free((char *)inln); }