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