1 |
+ |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
+ |
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
5 |
|
#endif |
10 |
|
|
11 |
|
#include <stdio.h> |
12 |
|
|
13 |
< |
#include "color.h" |
13 |
> |
#include "resolu.h" |
14 |
|
|
15 |
|
|
16 |
< |
fputresolu(ord, xres, yres, fp) /* put x and y resolution */ |
17 |
< |
register int ord; |
18 |
< |
int xres, yres; |
16 |
> |
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 |
|
FILE *fp; |
23 |
|
{ |
24 |
< |
if (ord&YMAJOR) |
25 |
< |
fprintf(fp, "%cY %d %cX %d\n", |
26 |
< |
ord&YDECR ? '-' : '+', yres, |
27 |
< |
ord&XDECR ? '-' : '+', xres); |
28 |
< |
else |
29 |
< |
fprintf(fp, "%cX %d %cY %d\n", |
30 |
< |
ord&XDECR ? '-' : '+', xres, |
31 |
< |
ord&YDECR ? '-' : '+', yres); |
24 |
> |
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 |
|
} |
35 |
|
|
36 |
|
|
37 |
< |
fgetresolu(xrp, yrp, fp) /* get x and y resolution */ |
38 |
< |
int *xrp, *yrp; |
37 |
> |
int |
38 |
> |
fgetresolu(sl, ns, fp) /* get picture dimensions */ |
39 |
> |
int *sl, *ns; /* scanline length and number */ |
40 |
|
FILE *fp; |
41 |
|
{ |
42 |
< |
char buf[64], *xndx, *yndx; |
35 |
< |
register char *cp; |
36 |
< |
register int ord; |
42 |
> |
RESOLU rs; |
43 |
|
|
44 |
< |
if (fgets(buf, sizeof(buf), fp) == NULL) |
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 |
+ |
char *xndx, *yndx; |
79 |
+ |
register char *cp; |
80 |
+ |
|
81 |
+ |
if (buf == NULL) |
82 |
+ |
return(0); |
83 |
|
xndx = yndx = NULL; |
84 |
|
for (cp = buf+1; *cp; cp++) |
85 |
|
if (*cp == 'X') |
87 |
|
else if (*cp == 'Y') |
88 |
|
yndx = cp; |
89 |
|
if (xndx == NULL || yndx == NULL) |
90 |
< |
return(-1); |
91 |
< |
ord = 0; |
92 |
< |
if (xndx > yndx) ord |= YMAJOR; |
93 |
< |
if (xndx[-1] == '-') ord |= XDECR; |
94 |
< |
if (yndx[-1] == '-') ord |= YDECR; |
95 |
< |
if ((*xrp = atoi(xndx+1)) <= 0) |
96 |
< |
return(-1); |
97 |
< |
if ((*yrp = atoi(yndx+1)) <= 0) |
98 |
< |
return(-1); |
99 |
< |
return(ord); |
90 |
> |
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 |
|
} |