ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/resolu.c
Revision: 2.6
Committed: Wed Jun 7 17:52:03 2006 UTC (17 years, 10 months ago) by schorsch
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R2, rad4R2P2, rad5R0, rad5R1, rad4R2, rad4R1, rad4R0, rad3R8, rad3R9, rad4R2P1, rad5R3
Changes since 2.5: +2 -1 lines
Log Message:
Eliminated some compiler warnings.

File Contents

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