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

Comparing ray/src/common/resolu.c (file contents):
Revision 1.1 by greg, Sat Sep 22 10:44:55 1990 UTC vs.
Revision 2.4 by greg, Tue Feb 25 02:47:22 2003 UTC

# Line 1 | Line 1
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
4
4   /*
5   * Read and write image resolutions.
6 + *
7 + * Externals declared in resolu.h
8   */
9  
10 + #include "copyright.h"
11 +
12   #include <stdio.h>
13 + #include <stdlib.h>
14 + #include <time.h>
15  
16 < #include "color.h"
16 > #include "resolu.h"
17  
18  
19 < fputresolu(ord, xres, yres, fp)         /* put x and y resolution */
20 < register int  ord;
21 < int  xres, yres;
19 > char  resolu_buf[RESOLU_BUFLEN];        /* resolution line buffer */
20 >
21 >
22 > void
23 > fputresolu(ord, sl, ns, fp)             /* put out picture dimensions */
24 > int  ord;                       /* scanline ordering */
25 > int  sl, ns;                    /* scanline length and number */
26   FILE  *fp;
27   {
28 <        if (ord&YMAJOR)
29 <                fprintf(fp, "%cY %d %cX %d\n",
30 <                                ord&YDECR ? '-' : '+', yres,
31 <                                ord&XDECR ? '-' : '+', xres);
32 <        else
33 <                fprintf(fp, "%cX %d %cY %d\n",
34 <                                ord&XDECR ? '-' : '+', xres,
35 <                                ord&YDECR ? '-' : '+', yres);
28 >        RESOLU  rs;
29 >
30 >        if ((rs.rt = ord) & YMAJOR) {
31 >                rs.xr = sl;
32 >                rs.yr = ns;
33 >        } else {
34 >                rs.xr = ns;
35 >                rs.yr = sl;
36 >        }
37 >        fputsresolu(&rs, fp);
38   }
39  
40  
41 < fgetresolu(xrp, yrp, fp)                /* get x and y resolution */
42 < int  *xrp, *yrp;
41 > int
42 > fgetresolu(sl, ns, fp)                  /* get picture dimensions */
43 > int  *sl, *ns;                  /* scanline length and number */
44   FILE  *fp;
45   {
46 <        char  buf[64], *xndx, *yndx;
35 <        register char  *cp;
36 <        register int  ord;
46 >        RESOLU  rs;
47  
48 <        if (fgets(buf, sizeof(buf), fp) == NULL)
48 >        if (!fgetsresolu(&rs, fp))
49                  return(-1);
50 +        if (rs.rt & YMAJOR) {
51 +                *sl = rs.xr;
52 +                *ns = rs.yr;
53 +        } else {
54 +                *sl = rs.yr;
55 +                *ns = rs.xr;
56 +        }
57 +        return(rs.rt);
58 + }
59 +
60 +
61 + char *
62 + resolu2str(buf, rp)             /* convert resolution struct to line */
63 + char  *buf;
64 + register RESOLU  *rp;
65 + {
66 +        if (rp->rt&YMAJOR)
67 +                sprintf(buf, "%cY %d %cX %d\n",
68 +                                rp->rt&YDECR ? '-' : '+', rp->yr,
69 +                                rp->rt&XDECR ? '-' : '+', rp->xr);
70 +        else
71 +                sprintf(buf, "%cX %d %cY %d\n",
72 +                                rp->rt&XDECR ? '-' : '+', rp->xr,
73 +                                rp->rt&YDECR ? '-' : '+', rp->yr);
74 +        return(buf);
75 + }
76 +
77 +
78 + int
79 + str2resolu(rp, buf)             /* convert resolution line to struct */
80 + register RESOLU  *rp;
81 + char  *buf;
82 + {
83 +        register char  *xndx, *yndx;
84 +        register char  *cp;
85 +
86 +        if (buf == NULL)
87 +                return(0);
88          xndx = yndx = NULL;
89 <        for (cp = buf+1; *cp; cp++)
89 >        for (cp = buf; *cp; cp++)
90                  if (*cp == 'X')
91                          xndx = cp;
92                  else if (*cp == 'Y')
93                          yndx = cp;
94          if (xndx == NULL || yndx == NULL)
95 <                return(-1);
96 <        ord = 0;
97 <        if (xndx > yndx) ord |= YMAJOR;
98 <        if (xndx[-1] == '-') ord |= XDECR;
99 <        if (yndx[-1] == '-') ord |= YDECR;
100 <        if ((*xrp = atoi(xndx+1)) <= 0)
101 <                return(-1);
102 <        if ((*yrp = atoi(yndx+1)) <= 0)
103 <                return(-1);
104 <        return(ord);
95 >                return(0);
96 >        rp->rt = 0;
97 >        if (xndx > yndx) rp->rt |= YMAJOR;
98 >        if (xndx[-1] == '-') rp->rt |= XDECR;
99 >        if (yndx[-1] == '-') rp->rt |= YDECR;
100 >        if ((rp->xr = atoi(xndx+1)) <= 0)
101 >                return(0);
102 >        if ((rp->yr = atoi(yndx+1)) <= 0)
103 >                return(0);
104 >        return(1);
105   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines