--- ray/src/px/protate.c 1990/01/25 08:28:35 1.4 +++ ray/src/px/protate.c 1991/04/18 14:42:06 1.8 @@ -9,21 +9,39 @@ static char SCCSid[] = "$SunId$ LBL"; * 2/26/88 */ -#include +#include "standard.h" #include "color.h" int xres, yres; /* input resolution */ +double inpaspect = 1.0; /* input aspect ratio */ char buf[1<<20]; /* output buffer */ int nrows; /* number of rows output at once */ +int wrongformat = 0; + #define scanbar ((COLR *)buf) char *progname; +headline(s) /* process line from header */ +char *s; +{ + char fmt[32]; + + fputs(s, stdout); + if (isaspect(s)) + inpaspect *= aspectval(s); + else if (isformat(s)) { + formatval(fmt, s); + wrongformat = strcmp(fmt, COLRFMT); + } +} + + main(argc, argv) int argc; char *argv[]; @@ -44,9 +62,15 @@ char *argv[]; fprintf(stderr, "%s: cannot open\n", argv[2]); exit(1); } - /* copy header */ - copyheader(fin, stdout); + /* transfer header */ + getheader(fin, headline, NULL); + if (wrongformat) { + fprintf(stderr, "%s: wrong picture format\n", progname); + exit(1); + } /* add new header info. */ + if (inpaspect < .99 || inpaspect > 1.01) + fputaspect(1./inpaspect/inpaspect, stdout); printf("%s\n\n", progname); /* get picture size */ if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { @@ -65,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); } @@ -80,12 +104,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 +119,5 @@ FILE *fp; exit(1); } } - free((char *)inline); + free((char *)inln); }