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