ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/resolu.c
Revision: 2.5
Committed: Tue Feb 1 01:28:16 2005 UTC (19 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R7P2, rad3R7P1
Changes since 2.4: +1 -3 lines
Log Message:
Eliminated redundant include files.

File Contents

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