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.1 by greg, Thu Feb 2 10:49:27 1989 UTC vs.
Revision 2.1 by greg, Tue Nov 12 16:04:09 1991 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   char    buf[1<<20];                     /* output buffer */
25  
26   int     nrows;                          /* number of rows output at once */
# Line 23 | Line 29 | int    nrows;                          /* number of rows output at once */
29  
30   char    *progname;
31  
32 + #define neworder()      (correctorder ? order : \
33 +                        (order^(order&YMAJOR?YDECR:XDECR)^YMAJOR))
34  
35 +
36   main(argc, argv)
37   int     argc;
38   char    *argv[];
# Line 32 | Line 41 | char   *argv[];
41  
42          progname = argv[0];
43  
44 +        if (argc > 2 && !strcmp(argv[1], "-c")) {
45 +                correctorder++;
46 +                argc--; argv++;
47 +        }
48          if (argc != 2 && argc != 3) {
49 <                fprintf(stderr, "Usage: %s infile [outfile]\n", progname);
49 >                fprintf(stderr, "Usage: %s [-c] infile [outfile]\n", progname);
50                  exit(1);
51          }
52          if ((fin = fopen(argv[1], "r")) == NULL) {
# Line 44 | Line 57 | char   *argv[];
57                  fprintf(stderr, "%s: cannot open\n", argv[2]);
58                  exit(1);
59          }
60 <                                        /* copy header */
61 <        while (fgets(buf, sizeof(buf), fin) != NULL && buf[0] != '\n')
62 <                fputs(buf, stdout);
60 >                                        /* transfer header */
61 >        if (checkheader(fin, COLRFMT, stdout) < 0) {
62 >                fprintf(stderr, "%s: not a Radiance picture\n", progname);
63 >                exit(1);
64 >        }
65                                          /* add new header info. */
66          printf("%s\n\n", progname);
67                                          /* get picture size */
68 <        if (fgets(buf, sizeof(buf), fin) == NULL ||
54 <                        sscanf(buf, "-Y %d +X %d\n", &yres, &xres) != 2) {
68 >        if ((order = fgetresolu(&xres, &yres, fin)) < 0) {
69                  fprintf(stderr, "%s: bad picture size\n", progname);
70                  exit(1);
71          }
72                                          /* write new picture size */
73 <        printf("-Y %d +X %d\n", xres, yres);
73 >        fputresolu(neworder(), yres, xres, stdout);
74                                          /* compute buffer capacity */
75          nrows = sizeof(buf)/sizeof(COLR)/yres;
76          rotate(fin);                    /* rotate the image */
# Line 67 | Line 81 | char   *argv[];
81   rotate(fp)                      /* rotate picture */
82   FILE    *fp;
83   {
84 <        register COLR   *inline;
84 >        register COLR   *inln;
85          register int    xoff, inx, iny;
86          long    start, ftell();
87  
88 <        if ((inline = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
88 >        if ((inln = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
89                  fprintf(stderr, "%s: out of memory\n", progname);
90                  exit(1);
91          }
# Line 82 | Line 96 | FILE   *fp;
96                          exit(1);
97                  }
98                  for (iny = yres-1; iny >= 0; iny--) {
99 <                        if (freadcolrs(inline, xres, fp) < 0) {
99 >                        if (freadcolrs(inln, xres, fp) < 0) {
100                                  fprintf(stderr, "%s: read error\n", progname);
101                                  exit(1);
102                          }
103                          for (inx = 0; inx < nrows && xoff+inx < xres; inx++)
104 <                                bcopy(inline[xoff+inx], scanbar[inx*yres+iny],
104 >                                bcopy((char *)inln[xoff+inx],
105 >                                                (char *)scanbar[inx*yres+iny],
106                                                  sizeof(COLR));
107                  }
108                  for (inx = 0; inx < nrows && xoff+inx < xres; inx++)
# Line 96 | Line 111 | FILE   *fp;
111                                  exit(1);
112                          }
113          }
114 <        free((char *)inline);
114 >        free((char *)inln);
115   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines