ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/protate.c
(Generate patch)

Comparing ray/src/px/protate.c (file contents):
Revision 2.4 by greg, Mon Oct 16 11:40:22 1995 UTC vs.
Revision 2.5 by gwlarson, Tue Oct 27 12:34:39 1998 UTC

# Line 20 | Line 20 | int    order;                          /* input scanline order */
20   int     xres, yres;                     /* input resolution */
21  
22   int     correctorder = 0;               /* order correction? */
23 + int     ccw = 0;                        /* rotate CCW? */
24  
25   #ifdef BIGMEM
26   char    buf[1<<22];                     /* output buffer */
# Line 33 | Line 34 | int    nrows;                          /* number of rows output at once */
34  
35   char    *progname;
36  
37 < #define neworder()      (correctorder ? order : \
38 <                        (order^(order&YMAJOR?YDECR:XDECR)^YMAJOR))
37 > short   ordertab[4][2] = {
38 >        {0,XDECR}, {XDECR,XDECR|YDECR}, {XDECR|YDECR,YDECR}, {YDECR,0}
39 > };
40  
41  
42 + int
43 + neworder()              /* return corrected order */
44 + {
45 +        register int    i;
46 +
47 +        if (correctorder)
48 +                return(order);
49 +        for (i = 4; i--; )
50 +                if ((order&~YMAJOR) == ordertab[i][ccw])
51 +                        return(ordertab[i][1-ccw] | ((order&YMAJOR)^YMAJOR));
52 +        fputs("Order botch!\n", stderr);
53 +        exit(2);
54 + }
55 +
56 +
57   main(argc, argv)
58   int     argc;
59   char    *argv[];
# Line 47 | Line 64 | char   *argv[];
64  
65          progname = argv[0];
66  
67 <        if (argc > 2 && !strcmp(argv[1], "-c")) {
68 <                correctorder++;
67 >        while (argc > 2 && argv[1][0] == '-') {
68 >                switch (argv[1][1]) {
69 >                case 'c':
70 >                        correctorder = 1;
71 >                        break;
72 >                case 'r':
73 >                        ccw = 1;
74 >                        break;
75 >                default:
76 >                        goto userr;
77 >                }
78                  argc--; argv++;
79          }
80 <        if (argc != 2 && argc != 3) {
81 <                fprintf(stderr, "Usage: %s [-c] infile [outfile]\n", progname);
56 <                exit(1);
57 <        }
80 >        if (argc != 2 && argc != 3)
81 >                goto userr;
82          if ((fin = fopen(argv[1], "r")) == NULL) {
83                  fprintf(stderr, "%s: cannot open\n", argv[1]);
84                  exit(1);
# Line 71 | Line 95 | char   *argv[];
95          if (rval)
96                  fputformat(picfmt, stdout);
97                                          /* add new header info. */
98 <        printf("%s%s\n\n", progname, correctorder?" -c":"");
98 >        fputs(progname, stdout);
99 >        if (ccw) fputs(" -r", stdout);
100 >        if (correctorder) fputs(" -c", stdout);
101 >        fputs("\n\n", stdout);
102                                          /* get picture size */
103          if ((order = fgetresolu(&xres, &yres, fin)) < 0) {
104                  fprintf(stderr, "%s: bad picture size\n", progname);
# Line 81 | Line 108 | char   *argv[];
108          fputresolu(neworder(), yres, xres, stdout);
109                                          /* compute buffer capacity */
110          nrows = sizeof(buf)/sizeof(COLR)/yres;
111 <        rotate(fin);                    /* rotate the image */
111 >        if (ccw)                        /* rotate the image */
112 >                rotateccw(fin);
113 >        else
114 >                rotatecw(fin);
115          exit(0);
116 + userr:
117 +        fprintf(stderr, "Usage: %s [-r][-c] infile [outfile]\n", progname);
118 +        exit(1);
119   }
120  
121  
122 < rotate(fp)                      /* rotate picture */
122 > rotatecw(fp)                    /* rotate picture clockwise */
123   FILE    *fp;
124   {
125          register COLR   *inln;
# Line 114 | Line 147 | FILE   *fp;
147                                                  sizeof(COLR));
148                  }
149                  for (inx = 0; inx < nrows && xoff+inx < xres; inx++)
150 +                        if (fwritecolrs(scanbar+inx*yres, yres, stdout) < 0) {
151 +                                fprintf(stderr, "%s: write error\n", progname);
152 +                                exit(1);
153 +                        }
154 +        }
155 +        free((char *)inln);
156 + }
157 +
158 +
159 + rotateccw(fp)                   /* rotate picture counter-clockwise */
160 + FILE    *fp;
161 + {
162 +        register COLR   *inln;
163 +        register int    xoff, inx, iny;
164 +        long    start, ftell();
165 +
166 +        if ((inln = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
167 +                fprintf(stderr, "%s: out of memory\n", progname);
168 +                exit(1);
169 +        }
170 +        start = ftell(fp);
171 +        for (xoff = xres-1; xoff >= 0; xoff -= nrows) {
172 +                if (fseek(fp, start, 0) < 0) {
173 +                        fprintf(stderr, "%s: seek error\n", progname);
174 +                        exit(1);
175 +                }
176 +                for (iny = 0; iny < yres; iny++) {
177 +                        if (freadcolrs(inln, xres, fp) < 0) {
178 +                                fprintf(stderr, "%s: read error\n", progname);
179 +                                exit(1);
180 +                        }
181 +                        for (inx = 0; inx < nrows && xoff-inx >= 0; inx++)
182 +                                bcopy((char *)inln[xoff-inx],
183 +                                                (char *)scanbar[inx*yres+iny],
184 +                                                sizeof(COLR));
185 +                }
186 +                for (inx = 0; inx < nrows && xoff-inx >= 0; inx++)
187                          if (fwritecolrs(scanbar+inx*yres, yres, stdout) < 0) {
188                                  fprintf(stderr, "%s: write error\n", progname);
189                                  exit(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines