--- ray/src/px/protate.c 1998/10/27 16:32:33 2.6 +++ ray/src/px/protate.c 2012/02/08 04:18:13 2.11 @@ -1,19 +1,19 @@ -/* Copyright (c) 1991 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ LBL"; +static const char RCSid[] = "$Id: protate.c,v 2.11 2012/02/08 04:18:13 greg Exp $"; #endif - /* * prot.c - program to rotate picture file 90 degrees clockwise. * * 2/26/88 */ +#include "platform.h" #include "standard.h" #include "color.h" +#include + #include "resolu.h" int order; /* input scanline order */ @@ -22,10 +22,10 @@ int xres, yres; /* input resolution */ int correctorder = 0; /* order correction? */ int ccw = 0; /* rotate CCW? */ -#ifdef BIGMEM -char buf[1<<22]; /* output buffer */ -#else +#ifdef SMLMEM char buf[1<<20]; /* output buffer */ +#else +char buf[1<<22]; /* output buffer */ #endif int nrows; /* number of rows output at once */ @@ -35,33 +35,56 @@ int nrows; /* number of rows output at once */ char *progname; short ordertab[4][2] = { - {0,XDECR}, {XDECR,XDECR|YDECR}, {XDECR|YDECR,YDECR}, {YDECR,0} + {0,0}, {XDECR,XDECR|YDECR}, {XDECR|YDECR,YDECR}, {YDECR,XDECR} }; -int -neworder() /* return corrected order */ +static int neworder(void); +static void rotatecw(FILE *fp); +static void rotateccw(FILE *fp); + + + +static int +neworder(void) /* return corrected order */ { + static short ordercw[8]; register int i; if (correctorder) return(order); - for (i = 4; i--; ) - if ((order&~YMAJOR) == ordertab[i][ccw]) - return(ordertab[i][1-ccw] | ((order&YMAJOR)^YMAJOR)); + if (!ordercw[0]) { + ordercw[YMAJOR|YDECR] = 0; + ordercw[0] = YMAJOR|XDECR; + ordercw[YMAJOR|XDECR] = XDECR|YDECR; + ordercw[XDECR|YDECR] = YMAJOR|YDECR; + ordercw[YMAJOR|XDECR|YDECR] = XDECR; + ordercw[XDECR] = YMAJOR; + ordercw[YMAJOR] = YDECR; + ordercw[YDECR] = YMAJOR|XDECR|YDECR; + } + if (!ccw) + return(ordercw[order]); + for (i = 8; i--; ) + if (ordercw[i] == order) + return(i); fputs("Order botch!\n", stderr); exit(2); } - -main(argc, argv) -int argc; -char *argv[]; +int +main( + int argc, + char *argv[] +) { static char picfmt[LPICFMT+1] = PICFMT; int rval; FILE *fin; + SET_DEFAULT_BINARY(); + SET_FILE_BINARY(stdout); + progname = argv[0]; while (argc > 2 && argv[1][0] == '-') { @@ -119,8 +142,10 @@ userr: } -rotatecw(fp) /* rotate picture clockwise */ -FILE *fp; +static void +rotatecw( /* rotate picture clockwise */ + FILE *fp +) { register COLR *inln; register int xoff, inx, iny; @@ -151,12 +176,14 @@ FILE *fp; exit(1); } } - free((char *)inln); + free((void *)inln); } -rotateccw(fp) /* rotate picture counter-clockwise */ -FILE *fp; +static void +rotateccw( /* rotate picture counter-clockwise */ + FILE *fp +) { register COLR *inln; register int xoff, inx, iny; @@ -187,5 +214,5 @@ FILE *fp; exit(1); } } - free((char *)inln); + free((void *)inln); }