Back to index

radiance  4R0+20100331
resolu.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: resolu.c,v 2.6 2006/06/07 17:52:03 schorsch Exp $";
00003 #endif
00004 /*
00005  * Read and write image resolutions.
00006  *
00007  * Externals declared in resolu.h
00008  */
00009 
00010 #include "copyright.h"
00011 
00012 #include <stdlib.h>
00013 #include <stdio.h>
00014 
00015 #include "resolu.h"
00016 
00017 
00018 char  resolu_buf[RESOLU_BUFLEN];   /* resolution line buffer */
00019 
00020 
00021 void
00022 fputresolu(ord, sl, ns, fp)        /* put out picture dimensions */
00023 int  ord;                   /* scanline ordering */
00024 int  sl, ns;                /* scanline length and number */
00025 FILE  *fp;
00026 {
00027        RESOLU  rs;
00028 
00029        if ((rs.rt = ord) & YMAJOR) {
00030               rs.xr = sl;
00031               rs.yr = ns;
00032        } else {
00033               rs.xr = ns;
00034               rs.yr = sl;
00035        }
00036        fputsresolu(&rs, fp);
00037 }
00038 
00039 
00040 int
00041 fgetresolu(sl, ns, fp)                    /* get picture dimensions */
00042 int  *sl, *ns;                     /* scanline length and number */
00043 FILE  *fp;
00044 {
00045        RESOLU  rs;
00046 
00047        if (!fgetsresolu(&rs, fp))
00048               return(-1);
00049        if (rs.rt & YMAJOR) {
00050               *sl = rs.xr;
00051               *ns = rs.yr;
00052        } else {
00053               *sl = rs.yr;
00054               *ns = rs.xr;
00055        }
00056        return(rs.rt);
00057 }
00058 
00059 
00060 char *
00061 resolu2str(buf, rp)         /* convert resolution struct to line */
00062 char  *buf;
00063 register RESOLU  *rp;
00064 {
00065        if (rp->rt&YMAJOR)
00066               sprintf(buf, "%cY %d %cX %d\n",
00067                             rp->rt&YDECR ? '-' : '+', rp->yr,
00068                             rp->rt&XDECR ? '-' : '+', rp->xr);
00069        else
00070               sprintf(buf, "%cX %d %cY %d\n",
00071                             rp->rt&XDECR ? '-' : '+', rp->xr,
00072                             rp->rt&YDECR ? '-' : '+', rp->yr);
00073        return(buf);
00074 }
00075 
00076 
00077 int
00078 str2resolu(rp, buf)         /* convert resolution line to struct */
00079 register RESOLU  *rp;
00080 char  *buf;
00081 {
00082        register char  *xndx, *yndx;
00083        register char  *cp;
00084 
00085        if (buf == NULL)
00086               return(0);
00087        xndx = yndx = NULL;
00088        for (cp = buf; *cp; cp++)
00089               if (*cp == 'X')
00090                      xndx = cp;
00091               else if (*cp == 'Y')
00092                      yndx = cp;
00093        if (xndx == NULL || yndx == NULL)
00094               return(0);
00095        rp->rt = 0;
00096        if (xndx > yndx) rp->rt |= YMAJOR;
00097        if (xndx[-1] == '-') rp->rt |= XDECR;
00098        if (yndx[-1] == '-') rp->rt |= YDECR;
00099        if ((rp->xr = atoi(xndx+1)) <= 0)
00100               return(0);
00101        if ((rp->yr = atoi(yndx+1)) <= 0)
00102               return(0);
00103        return(1);
00104 }