home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / NEWS / RADIANCE / SRC / COMMON / RESOLU.C < prev    next >
C/C++ Source or Header  |  1993-10-07  |  2KB  |  101 lines

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