ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/resolu.c
Revision: 2.9
Committed: Tue Nov 21 18:47:03 2023 UTC (5 months, 3 weeks ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 2.8: +20 -16 lines
Log Message:
style: Updated code to modern prototypes

File Contents

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