ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/protate.c
(Generate patch)

Comparing ray/src/px/protate.c (file contents):
Revision 1.3 by greg, Thu Jan 18 23:58:15 1990 UTC vs.
Revision 2.3 by greg, Wed Feb 1 09:52:34 1995 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1988 Regents of the University of California */
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 <stdio.h>
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  
# Line 23 | Line 33 | int    nrows;                          /* number of rows output at once */
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[];
# Line 32 | Line 45 | char   *argv[];
45  
46          progname = argv[0];
47  
48 +        if (argc > 2 && !strcmp(argv[1], "-c")) {
49 +                correctorder++;
50 +                argc--; argv++;
51 +        }
52          if (argc != 2 && argc != 3) {
53 <                fprintf(stderr, "Usage: %s infile [outfile]\n", progname);
53 >                fprintf(stderr, "Usage: %s [-c] infile [outfile]\n", progname);
54                  exit(1);
55          }
56          if ((fin = fopen(argv[1], "r")) == NULL) {
# Line 44 | Line 61 | char   *argv[];
61                  fprintf(stderr, "%s: cannot open\n", argv[2]);
62                  exit(1);
63          }
64 <                                        /* copy header */
65 <        while (fgets(buf, sizeof(buf), fin) != NULL && buf[0] != '\n')
66 <                fputs(buf, stdout);
64 >                                        /* transfer header */
65 >        if (checkheader(fin, COLRFMT, stdout) < 0) {
66 >                fprintf(stderr, "%s: not a Radiance picture\n", progname);
67 >                exit(1);
68 >        }
69                                          /* add new header info. */
70 <        printf("%s\n\n", progname);
70 >        printf("%s%s\n\n", progname, correctorder?" -c":"");
71                                          /* get picture size */
72 <        if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) {
72 >        if ((order = fgetresolu(&xres, &yres, fin)) < 0) {
73                  fprintf(stderr, "%s: bad picture size\n", progname);
74                  exit(1);
75          }
76                                          /* write new picture size */
77 <        fputresolu(YMAJOR|YDECR, yres, xres, stdout);
77 >        fputresolu(neworder(), yres, xres, stdout);
78                                          /* compute buffer capacity */
79          nrows = sizeof(buf)/sizeof(COLR)/yres;
80          rotate(fin);                    /* rotate the image */
# Line 66 | Line 85 | char   *argv[];
85   rotate(fp)                      /* rotate picture */
86   FILE    *fp;
87   {
88 <        register COLR   *inline;
88 >        register COLR   *inln;
89          register int    xoff, inx, iny;
90          long    start, ftell();
91  
92 <        if ((inline = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
92 >        if ((inln = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
93                  fprintf(stderr, "%s: out of memory\n", progname);
94                  exit(1);
95          }
# Line 81 | Line 100 | FILE   *fp;
100                          exit(1);
101                  }
102                  for (iny = yres-1; iny >= 0; iny--) {
103 <                        if (freadcolrs(inline, xres, fp) < 0) {
103 >                        if (freadcolrs(inln, xres, fp) < 0) {
104                                  fprintf(stderr, "%s: read error\n", progname);
105                                  exit(1);
106                          }
107                          for (inx = 0; inx < nrows && xoff+inx < xres; inx++)
108 <                                bcopy((char *)inline[xoff+inx],
108 >                                bcopy((char *)inln[xoff+inx],
109                                                  (char *)scanbar[inx*yres+iny],
110                                                  sizeof(COLR));
111                  }
# Line 96 | Line 115 | FILE   *fp;
115                                  exit(1);
116                          }
117          }
118 <        free((char *)inline);
118 >        free((char *)inln);
119   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines