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