ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/protate.c
Revision: 1.1
Committed: Thu Feb 2 10:49:27 1989 UTC (35 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

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