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 1.7 by greg, Tue Dec 4 11:25:46 1990 UTC vs.
Revision 2.6 by gwlarson, Tue Oct 27 16:32:33 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1988 Regents of the University of California */
1 > /* Copyright (c) 1991 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
5   #endif
6 +
7   /*
8   * prot.c - program to rotate picture file 90 degrees clockwise.
9   *
# Line 13 | Line 14 | static char SCCSid[] = "$SunId$ LBL";
14  
15   #include "color.h"
16  
17 + #include "resolu.h"
18 +
19 + int     order;                          /* input scanline order */
20   int     xres, yres;                     /* input resolution */
17 double  inpaspect = 1.0;                /* input aspect ratio */
21  
22 + int     correctorder = 0;               /* order correction? */
23 + int     ccw = 0;                        /* rotate CCW? */
24 +
25 + #ifdef BIGMEM
26 + char    buf[1<<22];                     /* output buffer */
27 + #else
28   char    buf[1<<20];                     /* output buffer */
29 + #endif
30  
31   int     nrows;                          /* number of rows output at once */
32  
# Line 24 | Line 34 | int    nrows;                          /* number of rows output at once */
34  
35   char    *progname;
36  
37 + short   ordertab[4][2] = {
38 +        {0,XDECR}, {XDECR,XDECR|YDECR}, {XDECR|YDECR,YDECR}, {YDECR,0}
39 + };
40  
41 < headline(s)                             /* process line from header */
42 < char    *s;
41 >
42 > int
43 > neworder()              /* return corrected order */
44   {
45 <        fputs(s, stdout);
46 <        if (isaspect(s))
47 <                inpaspect *= aspectval(s);
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  
# Line 38 | Line 58 | main(argc, argv)
58   int     argc;
59   char    *argv[];
60   {
61 +        static char     picfmt[LPICFMT+1] = PICFMT;
62 +        int     rval;
63          FILE    *fin;
64  
65          progname = argv[0];
66  
67 <        if (argc != 2 && argc != 3) {
68 <                fprintf(stderr, "Usage: %s infile [outfile]\n", progname);
69 <                exit(1);
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 +                goto userr;
82          if ((fin = fopen(argv[1], "r")) == NULL) {
83                  fprintf(stderr, "%s: cannot open\n", argv[1]);
84                  exit(1);
# Line 55 | Line 88 | char   *argv[];
88                  exit(1);
89          }
90                                          /* transfer header */
91 <        getheader(fin, headline);
91 >        if ((rval = checkheader(fin, picfmt, stdout)) < 0) {
92 >                fprintf(stderr, "%s: not a Radiance picture\n", progname);
93 >                exit(1);
94 >        }
95 >        if (rval)
96 >                fputformat(picfmt, stdout);
97                                          /* add new header info. */
98 <        if (inpaspect < .99 || inpaspect > 1.01)
99 <                fputaspect(1./inpaspect/inpaspect, stdout);
100 <        printf("%s\n\n", progname);
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 (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) {
103 >        if ((order = fgetresolu(&xres, &yres, fin)) < 0) {
104                  fprintf(stderr, "%s: bad picture size\n", progname);
105                  exit(1);
106          }
107                                          /* write new picture size */
108 <        fputresolu(YMAJOR|YDECR, yres, xres, stdout);
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 97 | Line 142 | FILE   *fp;
142                                  exit(1);
143                          }
144                          for (inx = 0; inx < nrows && xoff+inx < xres; inx++)
145 <                                bcopy((char *)inln[xoff+inx],
146 <                                                (char *)scanbar[inx*yres+iny],
102 <                                                sizeof(COLR));
145 >                                copycolr(scanbar[inx*yres+iny],
146 >                                                inln[xoff+inx]);
147                  }
148                  for (inx = 0; inx < nrows && xoff+inx < xres; inx++)
149 +                        if (fwritecolrs(scanbar+inx*yres, yres, stdout) < 0) {
150 +                                fprintf(stderr, "%s: write error\n", progname);
151 +                                exit(1);
152 +                        }
153 +        }
154 +        free((char *)inln);
155 + }
156 +
157 +
158 + rotateccw(fp)                   /* rotate picture counter-clockwise */
159 + FILE    *fp;
160 + {
161 +        register COLR   *inln;
162 +        register int    xoff, inx, iny;
163 +        long    start, ftell();
164 +
165 +        if ((inln = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
166 +                fprintf(stderr, "%s: out of memory\n", progname);
167 +                exit(1);
168 +        }
169 +        start = ftell(fp);
170 +        for (xoff = xres-1; xoff >= 0; xoff -= nrows) {
171 +                if (fseek(fp, start, 0) < 0) {
172 +                        fprintf(stderr, "%s: seek error\n", progname);
173 +                        exit(1);
174 +                }
175 +                for (iny = 0; iny < yres; iny++) {
176 +                        if (freadcolrs(inln, xres, fp) < 0) {
177 +                                fprintf(stderr, "%s: read error\n", progname);
178 +                                exit(1);
179 +                        }
180 +                        for (inx = 0; inx < nrows && xoff-inx >= 0; inx++)
181 +                                copycolr(scanbar[inx*yres+iny],
182 +                                                inln[xoff-inx]);
183 +                }
184 +                for (inx = 0; inx < nrows && xoff-inx >= 0; inx++)
185                          if (fwritecolrs(scanbar+inx*yres, yres, stdout) < 0) {
186                                  fprintf(stderr, "%s: write error\n", progname);
187                                  exit(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines