ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/protate.c
Revision: 1.8
Committed: Thu Apr 18 14:42:06 1991 UTC (33 years ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.7: +13 -1 lines
Log Message:
added format information to headers

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1988 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6     /*
7     * prot.c - program to rotate picture file 90 degrees clockwise.
8     *
9     * 2/26/88
10     */
11    
12 greg 1.7 #include "standard.h"
13 greg 1.1
14     #include "color.h"
15    
16     int xres, yres; /* input resolution */
17 greg 1.6 double inpaspect = 1.0; /* input aspect ratio */
18 greg 1.1
19     char buf[1<<20]; /* output buffer */
20    
21     int nrows; /* number of rows output at once */
22    
23 greg 1.8 int wrongformat = 0;
24    
25 greg 1.1 #define scanbar ((COLR *)buf)
26    
27     char *progname;
28    
29    
30 greg 1.6 headline(s) /* process line from header */
31     char *s;
32     {
33 greg 1.8 char fmt[32];
34    
35 greg 1.6 fputs(s, stdout);
36     if (isaspect(s))
37     inpaspect *= aspectval(s);
38 greg 1.8 else if (isformat(s)) {
39     formatval(fmt, s);
40     wrongformat = strcmp(fmt, COLRFMT);
41     }
42 greg 1.6 }
43    
44    
45 greg 1.1 main(argc, argv)
46     int argc;
47     char *argv[];
48     {
49     FILE *fin;
50    
51     progname = argv[0];
52    
53     if (argc != 2 && argc != 3) {
54     fprintf(stderr, "Usage: %s infile [outfile]\n", progname);
55     exit(1);
56     }
57     if ((fin = fopen(argv[1], "r")) == NULL) {
58     fprintf(stderr, "%s: cannot open\n", argv[1]);
59     exit(1);
60     }
61     if (argc == 3 && freopen(argv[2], "w", stdout) == NULL) {
62     fprintf(stderr, "%s: cannot open\n", argv[2]);
63     exit(1);
64     }
65 greg 1.6 /* transfer header */
66 greg 1.8 getheader(fin, headline, NULL);
67     if (wrongformat) {
68     fprintf(stderr, "%s: wrong picture format\n", progname);
69     exit(1);
70     }
71 greg 1.1 /* add new header info. */
72 greg 1.6 if (inpaspect < .99 || inpaspect > 1.01)
73     fputaspect(1./inpaspect/inpaspect, stdout);
74 greg 1.1 printf("%s\n\n", progname);
75     /* get picture size */
76 greg 1.2 if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) {
77 greg 1.1 fprintf(stderr, "%s: bad picture size\n", progname);
78     exit(1);
79     }
80     /* write new picture size */
81 greg 1.2 fputresolu(YMAJOR|YDECR, yres, xres, stdout);
82 greg 1.1 /* compute buffer capacity */
83     nrows = sizeof(buf)/sizeof(COLR)/yres;
84     rotate(fin); /* rotate the image */
85     exit(0);
86     }
87    
88    
89     rotate(fp) /* rotate picture */
90     FILE *fp;
91     {
92 greg 1.5 register COLR *inln;
93 greg 1.1 register int xoff, inx, iny;
94     long start, ftell();
95    
96 greg 1.5 if ((inln = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
97 greg 1.1 fprintf(stderr, "%s: out of memory\n", progname);
98     exit(1);
99     }
100     start = ftell(fp);
101     for (xoff = 0; xoff < xres; xoff += nrows) {
102     if (fseek(fp, start, 0) < 0) {
103     fprintf(stderr, "%s: seek error\n", progname);
104     exit(1);
105     }
106     for (iny = yres-1; iny >= 0; iny--) {
107 greg 1.5 if (freadcolrs(inln, xres, fp) < 0) {
108 greg 1.1 fprintf(stderr, "%s: read error\n", progname);
109     exit(1);
110     }
111     for (inx = 0; inx < nrows && xoff+inx < xres; inx++)
112 greg 1.5 bcopy((char *)inln[xoff+inx],
113 greg 1.3 (char *)scanbar[inx*yres+iny],
114 greg 1.1 sizeof(COLR));
115     }
116     for (inx = 0; inx < nrows && xoff+inx < xres; inx++)
117     if (fwritecolrs(scanbar+inx*yres, yres, stdout) < 0) {
118     fprintf(stderr, "%s: write error\n", progname);
119     exit(1);
120     }
121     }
122 greg 1.5 free((char *)inln);
123 greg 1.1 }