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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines