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