1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: resolu.c,v 2.4 2003/02/25 02:47:22 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 <stdio.h> |
13 |
|
14 |
#include "resolu.h" |
15 |
|
16 |
|
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 |
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 |
int |
40 |
fgetresolu(sl, ns, fp) /* get picture dimensions */ |
41 |
int *sl, *ns; /* scanline length and number */ |
42 |
FILE *fp; |
43 |
{ |
44 |
RESOLU rs; |
45 |
|
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; *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(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 |
} |