ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/resolu.c
Revision: 2.4
Committed: Tue Feb 25 02:47:22 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5, rad3R6, rad3R6P1
Changes since 2.3: +1 -56 lines
Log Message:
Replaced inline copyright notice with #include "copyright.h"

File Contents

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