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

Comparing ray/src/px/pflip.c (file contents):
Revision 1.4 by greg, Thu Apr 18 14:35:24 1991 UTC vs.
Revision 2.4 by greg, Mon Oct 16 11:40:11 1995 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1991 Regents of the University of California */
1 > /* Copyright (c) 1992 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include <stdio.h>
12  
13 + #ifdef MSDOS
14 + #include  <fcntl.h>
15 + #endif
16 +
17   #include "color.h"
18  
19 < int     xres, yres;                     /* input resolution */
19 > #include "resolu.h"
20  
21 + int     order;                          /* input orientation */
22 + int     xres, yres;                     /* resolution (scanlen, nscans) */
23 +
24   long    *scanpos;                       /* scanline positions */
25  
26 < int     fhoriz, fvert;                  /* flip flags */
26 > int     fhoriz=0, fvert=0;              /* flip flags */
27  
28 + int     correctorder = 0;               /* correcting orientation? */
29 +
30   FILE    *fin;                           /* input file */
31  
32   char    *progname;
33  
34 + extern char     *malloc();
35  
36 +
37 + int
38 + neworder()                      /* figure out new order from old */
39 + {
40 +        register int  no;
41 +
42 +        if (correctorder)
43 +                return(order);          /* just leave it */
44 +        if ((no = order) & YMAJOR) {
45 +                if (fhoriz) no ^= XDECR;
46 +                if (fvert) no ^= YDECR;
47 +        } else {
48 +                if (fhoriz) no ^= YDECR;
49 +                if (fvert) no ^= XDECR;
50 +        }
51 +        return(no);
52 + }
53 +
54 +
55   main(argc, argv)
56   int     argc;
57   char    *argv[];
58   {
59 <        int     i;
60 <
59 >        static char     picfmt[LPICFMT+1] = PICFMT;
60 >        int     i, rval;
61 > #ifdef MSDOS
62 >        extern int  _fmode;
63 >        _fmode = O_BINARY;
64 >        setmode(fileno(stdout), O_BINARY);
65 > #endif
66          progname = argv[0];
67  
68          for (i = 1; i < argc; i++)
# Line 36 | Line 70 | char   *argv[];
70                          fhoriz++;
71                  else if (!strcmp(argv[i], "-v"))
72                          fvert++;
73 +                else if (!strcmp(argv[i], "-c"))
74 +                        correctorder++;
75                  else
76                          break;
77          if (i >= argc || argv[i][0] == '-') {
78 <                fprintf(stderr, "Usage: %s [-h][-v] infile [outfile]\n",
78 >                fprintf(stderr, "Usage: %s [-h][-v][-c] infile [outfile]\n",
79                                  progname);
80                  exit(1);
81          }
# Line 52 | Line 88 | char   *argv[];
88                  exit(1);
89          }
90                                          /* transfer header */
91 <        if (checkheader(fin, COLRFMT, stdout) < 0) {
91 >        if ((rval = checkheader(fin, picfmt, stdout)) < 0) {
92                  fprintf(stderr, "%s: input not a Radiance picture\n",
93                                  progname);
94                  exit(1);
95          }
96 +        if (rval)
97 +                fputformat(picfmt, stdout);
98                                          /* add new header info. */
99          printargs(i, argv, stdout);
62        fputformat(COLRFMT, stdout);
100          putchar('\n');
101                                          /* get picture size */
102 <        if (fgetresolu(&xres, &yres, fin) != (YMAJOR|YDECR)) {
102 >        if ((order = fgetresolu(&xres, &yres, fin)) < 0) {
103                  fprintf(stderr, "%s: bad picture size\n", progname);
104                  exit(1);
105          }
106                                          /* write new picture size */
107 <        fputresolu(YMAJOR|YDECR, xres, yres, stdout);
107 >        fputresolu(neworder(), xres, yres, stdout);
108                                          /* goto end if vertical flip */
109          if (fvert)
110                  scanfile();
# Line 93 | Line 130 | scanfile()                             /* scan to the end of file */
130                  memerr();
131          if ((scanin = (COLR *)malloc(xres*sizeof(COLR))) == NULL)
132                  memerr();
133 <        for (y = yres-1; y >= 0; y--) {
133 >        for (y = yres-1; y > 0; y--) {
134                  scanpos[y] = ftell(fin);
135                  if (freadcolrs(scanin, xres, fin) < 0) {
136                          fprintf(stderr, "%s: read error\n", progname);
137                          exit(1);
138                  }
139          }
140 +        scanpos[0] = ftell(fin);
141          free((char *)scanin);
142   }
143  
# Line 135 | Line 173 | flip()                                 /* flip the picture */
173                  }
174          }
175          free((char *)scanin);
176 <        free((char *)scanout);
176 >        if (fhoriz)
177 >                free((char *)scanout);
178   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines