--- ray/src/px/protate.c 1989/02/02 10:49:27 1.1 +++ ray/src/px/protate.c 1990/12/04 11:25:46 1.7 @@ -9,11 +9,12 @@ 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 */ @@ -24,6 +25,15 @@ int nrows; /* number of rows output at once */ char *progname; +headline(s) /* process line from header */ +char *s; +{ + fputs(s, stdout); + if (isaspect(s)) + inpaspect *= aspectval(s); +} + + main(argc, argv) int argc; char *argv[]; @@ -44,19 +54,19 @@ 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 */ + getheader(fin, headline); /* add new header info. */ + if (inpaspect < .99 || inpaspect > 1.01) + fputaspect(1./inpaspect/inpaspect, stdout); printf("%s\n\n", progname); /* get picture size */ - if (fgets(buf, sizeof(buf), fin) == NULL || - sscanf(buf, "-Y %d +X %d\n", &yres, &xres) != 2) { + if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) { fprintf(stderr, "%s: bad picture size\n", progname); exit(1); } /* write new picture size */ - printf("-Y %d +X %d\n", xres, yres); + fputresolu(YMAJOR|YDECR, yres, xres, stdout); /* compute buffer capacity */ nrows = sizeof(buf)/sizeof(COLR)/yres; rotate(fin); /* rotate the image */ @@ -67,11 +77,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); } @@ -82,12 +92,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++) @@ -96,5 +107,5 @@ FILE *fp; exit(1); } } - free((char *)inline); + free((char *)inln); }