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 | #include <stdlib.h>
|
---|
14 | #include <time.h>
|
---|
15 |
|
---|
16 | #include "resolu.h"
|
---|
17 |
|
---|
18 |
|
---|
19 | char resolu_buf[RESOLU_BUFLEN]; /* resolution line buffer */
|
---|
20 |
|
---|
21 |
|
---|
22 | void
|
---|
23 | fputresolu(ord, sl, ns, fp) /* put out picture dimensions */
|
---|
24 | int ord; /* scanline ordering */
|
---|
25 | int sl, ns; /* scanline length and number */
|
---|
26 | FILE *fp;
|
---|
27 | {
|
---|
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 | int
|
---|
42 | fgetresolu(sl, ns, fp) /* get picture dimensions */
|
---|
43 | int *sl, *ns; /* scanline length and number */
|
---|
44 | FILE *fp;
|
---|
45 | {
|
---|
46 | RESOLU rs;
|
---|
47 |
|
---|
48 | if (!fgetsresolu(&rs, fp))
|
---|
49 | return(-1);
|
---|
50 | if (rs.rt & YMAJOR) {
|
---|
51 | *sl = rs.xr;
|
---|
52 | *ns = rs.yr;
|
---|
53 | } else {
|
---|
54 | *sl = rs.yr;
|
---|
55 | *ns = rs.xr;
|
---|
56 | }
|
---|
57 | return(rs.rt);
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | char *
|
---|
62 | resolu2str(buf, rp) /* convert resolution struct to line */
|
---|
63 | char *buf;
|
---|
64 | register RESOLU *rp;
|
---|
65 | {
|
---|
66 | if (rp->rt&YMAJOR)
|
---|
67 | sprintf(buf, "%cY %d %cX %d\n",
|
---|
68 | rp->rt&YDECR ? '-' : '+', rp->yr,
|
---|
69 | rp->rt&XDECR ? '-' : '+', rp->xr);
|
---|
70 | else
|
---|
71 | sprintf(buf, "%cX %d %cY %d\n",
|
---|
72 | rp->rt&XDECR ? '-' : '+', rp->xr,
|
---|
73 | rp->rt&YDECR ? '-' : '+', rp->yr);
|
---|
74 | return(buf);
|
---|
75 | }
|
---|
76 |
|
---|
77 |
|
---|
78 | int
|
---|
79 | str2resolu(rp, buf) /* convert resolution line to struct */
|
---|
80 | register RESOLU *rp;
|
---|
81 | char *buf;
|
---|
82 | {
|
---|
83 | register char *xndx, *yndx;
|
---|
84 | register char *cp;
|
---|
85 |
|
---|
86 | if (buf == NULL)
|
---|
87 | return(0);
|
---|
88 | xndx = yndx = NULL;
|
---|
89 | for (cp = buf; *cp; cp++)
|
---|
90 | if (*cp == 'X')
|
---|
91 | xndx = cp;
|
---|
92 | else if (*cp == 'Y')
|
---|
93 | yndx = cp;
|
---|
94 | if (xndx == NULL || yndx == NULL)
|
---|
95 | return(0);
|
---|
96 | rp->rt = 0;
|
---|
97 | if (xndx > yndx) rp->rt |= YMAJOR;
|
---|
98 | if (xndx[-1] == '-') rp->rt |= XDECR;
|
---|
99 | if (yndx[-1] == '-') rp->rt |= YDECR;
|
---|
100 | if ((rp->xr = atoi(xndx+1)) <= 0)
|
---|
101 | return(0);
|
---|
102 | if ((rp->yr = atoi(yndx+1)) <= 0)
|
---|
103 | return(0);
|
---|
104 | return(1);
|
---|
105 | }
|
---|