ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/protate.c
Revision: 2.4
Committed: Mon Oct 16 11:40:22 1995 UTC (28 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.3: +5 -1 lines
Log Message:
added compatibility with alternate RADIANCE picture formats

File Contents

# User Rev Content
1 greg 1.9 /* Copyright (c) 1991 Regents of the University of California */
2 greg 1.1
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6 greg 1.9
7 greg 1.1 /*
8     * prot.c - program to rotate picture file 90 degrees clockwise.
9     *
10     * 2/26/88
11     */
12    
13 greg 1.7 #include "standard.h"
14 greg 1.1
15     #include "color.h"
16    
17 greg 1.9 #include "resolu.h"
18    
19     int order; /* input scanline order */
20 greg 1.1 int xres, yres; /* input resolution */
21    
22 greg 1.9 int correctorder = 0; /* order correction? */
23    
24 greg 2.2 #ifdef BIGMEM
25     char buf[1<<22]; /* output buffer */
26     #else
27 greg 1.1 char buf[1<<20]; /* output buffer */
28 greg 2.2 #endif
29 greg 1.1
30     int nrows; /* number of rows output at once */
31    
32     #define scanbar ((COLR *)buf)
33    
34     char *progname;
35    
36 greg 1.9 #define neworder() (correctorder ? order : \
37     (order^(order&YMAJOR?YDECR:XDECR)^YMAJOR))
38 greg 1.1
39 greg 1.8
40 greg 1.1 main(argc, argv)
41     int argc;
42     char *argv[];
43     {
44 greg 2.4 static char picfmt[LPICFMT+1] = PICFMT;
45     int rval;
46 greg 1.1 FILE *fin;
47    
48     progname = argv[0];
49    
50 greg 1.9 if (argc > 2 && !strcmp(argv[1], "-c")) {
51     correctorder++;
52     argc--; argv++;
53     }
54 greg 1.1 if (argc != 2 && argc != 3) {
55 greg 1.9 fprintf(stderr, "Usage: %s [-c] infile [outfile]\n", progname);
56 greg 1.1 exit(1);
57     }
58     if ((fin = fopen(argv[1], "r")) == NULL) {
59     fprintf(stderr, "%s: cannot open\n", argv[1]);
60     exit(1);
61     }
62     if (argc == 3 && freopen(argv[2], "w", stdout) == NULL) {
63     fprintf(stderr, "%s: cannot open\n", argv[2]);
64     exit(1);
65     }
66 greg 1.6 /* transfer header */
67 greg 2.4 if ((rval = checkheader(fin, picfmt, stdout)) < 0) {
68 greg 1.9 fprintf(stderr, "%s: not a Radiance picture\n", progname);
69 greg 1.8 exit(1);
70     }
71 greg 2.4 if (rval)
72     fputformat(picfmt, stdout);
73 greg 1.1 /* add new header info. */
74 greg 2.3 printf("%s%s\n\n", progname, correctorder?" -c":"");
75 greg 1.1 /* get picture size */
76 greg 1.9 if ((order = fgetresolu(&xres, &yres, fin)) < 0) {
77 greg 1.1 fprintf(stderr, "%s: bad picture size\n", progname);
78     exit(1);
79     }
80     /* write new picture size */
81 greg 1.9 fputresolu(neworder(), 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 }