ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/protate.c
Revision: 1.7
Committed: Tue Dec 4 11:25:46 1990 UTC (33 years, 5 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.6: +1 -1 lines
Log Message:
added standard.h to take care of bcopy() incompatibilities

File Contents

# Content
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 #include "standard.h"
13
14 #include "color.h"
15
16 int xres, yres; /* input resolution */
17 double inpaspect = 1.0; /* input aspect ratio */
18
19 char buf[1<<20]; /* output buffer */
20
21 int nrows; /* number of rows output at once */
22
23 #define scanbar ((COLR *)buf)
24
25 char *progname;
26
27
28 headline(s) /* process line from header */
29 char *s;
30 {
31 fputs(s, stdout);
32 if (isaspect(s))
33 inpaspect *= aspectval(s);
34 }
35
36
37 main(argc, argv)
38 int argc;
39 char *argv[];
40 {
41 FILE *fin;
42
43 progname = argv[0];
44
45 if (argc != 2 && argc != 3) {
46 fprintf(stderr, "Usage: %s infile [outfile]\n", progname);
47 exit(1);
48 }
49 if ((fin = fopen(argv[1], "r")) == NULL) {
50 fprintf(stderr, "%s: cannot open\n", argv[1]);
51 exit(1);
52 }
53 if (argc == 3 && freopen(argv[2], "w", stdout) == NULL) {
54 fprintf(stderr, "%s: cannot open\n", argv[2]);
55 exit(1);
56 }
57 /* transfer header */
58 getheader(fin, headline);
59 /* add new header info. */
60 if (inpaspect < .99 || inpaspect > 1.01)
61 fputaspect(1./inpaspect/inpaspect, stdout);
62 printf("%s\n\n", progname);
63 /* get picture size */
64 if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) {
65 fprintf(stderr, "%s: bad picture size\n", progname);
66 exit(1);
67 }
68 /* write new picture size */
69 fputresolu(YMAJOR|YDECR, yres, xres, stdout);
70 /* compute buffer capacity */
71 nrows = sizeof(buf)/sizeof(COLR)/yres;
72 rotate(fin); /* rotate the image */
73 exit(0);
74 }
75
76
77 rotate(fp) /* rotate picture */
78 FILE *fp;
79 {
80 register COLR *inln;
81 register int xoff, inx, iny;
82 long start, ftell();
83
84 if ((inln = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
85 fprintf(stderr, "%s: out of memory\n", progname);
86 exit(1);
87 }
88 start = ftell(fp);
89 for (xoff = 0; xoff < xres; xoff += nrows) {
90 if (fseek(fp, start, 0) < 0) {
91 fprintf(stderr, "%s: seek error\n", progname);
92 exit(1);
93 }
94 for (iny = yres-1; iny >= 0; iny--) {
95 if (freadcolrs(inln, xres, fp) < 0) {
96 fprintf(stderr, "%s: read error\n", progname);
97 exit(1);
98 }
99 for (inx = 0; inx < nrows && xoff+inx < xres; inx++)
100 bcopy((char *)inln[xoff+inx],
101 (char *)scanbar[inx*yres+iny],
102 sizeof(COLR));
103 }
104 for (inx = 0; inx < nrows && xoff+inx < xres; inx++)
105 if (fwritecolrs(scanbar+inx*yres, yres, stdout) < 0) {
106 fprintf(stderr, "%s: write error\n", progname);
107 exit(1);
108 }
109 }
110 free((char *)inln);
111 }