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

# Content
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 *
10 * 2/26/88
11 */
12
13 #include "standard.h"
14
15 #include "color.h"
16
17 #include "resolu.h"
18
19 int order; /* input scanline order */
20 int xres, yres; /* input resolution */
21
22 int correctorder = 0; /* order correction? */
23
24 #ifdef BIGMEM
25 char buf[1<<22]; /* output buffer */
26 #else
27 char buf[1<<20]; /* output buffer */
28 #endif
29
30 int nrows; /* number of rows output at once */
31
32 #define scanbar ((COLR *)buf)
33
34 char *progname;
35
36 #define neworder() (correctorder ? order : \
37 (order^(order&YMAJOR?YDECR:XDECR)^YMAJOR))
38
39
40 main(argc, argv)
41 int argc;
42 char *argv[];
43 {
44 static char picfmt[LPICFMT+1] = PICFMT;
45 int rval;
46 FILE *fin;
47
48 progname = argv[0];
49
50 if (argc > 2 && !strcmp(argv[1], "-c")) {
51 correctorder++;
52 argc--; argv++;
53 }
54 if (argc != 2 && argc != 3) {
55 fprintf(stderr, "Usage: %s [-c] infile [outfile]\n", progname);
56 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 /* transfer header */
67 if ((rval = checkheader(fin, picfmt, stdout)) < 0) {
68 fprintf(stderr, "%s: not a Radiance picture\n", progname);
69 exit(1);
70 }
71 if (rval)
72 fputformat(picfmt, stdout);
73 /* add new header info. */
74 printf("%s%s\n\n", progname, correctorder?" -c":"");
75 /* get picture size */
76 if ((order = fgetresolu(&xres, &yres, fin)) < 0) {
77 fprintf(stderr, "%s: bad picture size\n", progname);
78 exit(1);
79 }
80 /* write new picture size */
81 fputresolu(neworder(), yres, xres, stdout);
82 /* 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 register COLR *inln;
93 register int xoff, inx, iny;
94 long start, ftell();
95
96 if ((inln = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
97 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 if (freadcolrs(inln, xres, fp) < 0) {
108 fprintf(stderr, "%s: read error\n", progname);
109 exit(1);
110 }
111 for (inx = 0; inx < nrows && xoff+inx < xres; inx++)
112 bcopy((char *)inln[xoff+inx],
113 (char *)scanbar[inx*yres+iny],
114 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 free((char *)inln);
123 }