home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / hdf / unix / hdf3_2r2 / src / df24.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-29  |  8.9 KB  |  296 lines

  1. /***************************************************************************
  2. *
  3. *
  4. *                         NCSA HDF version 3.2r2
  5. *                            October 30, 1992
  6. *
  7. * NCSA HDF Version 3.2 source code and documentation are in the public
  8. * domain.  Specifically, we give to the public domain all rights for future
  9. * licensing of the source code, all resale rights, and all publishing rights.
  10. *
  11. * We ask, but do not require, that the following message be included in all
  12. * derived works:
  13. *
  14. * Portions developed at the National Center for Supercomputing Applications at
  15. * the University of Illinois at Urbana-Champaign, in collaboration with the
  16. * Information Technology Institute of Singapore.
  17. *
  18. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  19. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  20. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  21. *
  22. ****************************************************************************
  23. */
  24.  
  25. #ifdef RCSID
  26. static char RcsId[] = "@(#)$Revision: 1.2 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/src/RCS/df24.c,v 1.2 1992/10/12 18:11:51 koziol beta koziol $
  30.  
  31. $Log: df24.c,v $
  32.  * Revision 1.2  1992/10/12  18:11:51  koziol
  33.  * Updated for v3.2r2 release
  34.  *
  35.  * Revision 1.1  1992/08/25  21:40:44  koziol
  36.  * Initial revision
  37.  *
  38. */
  39. /*-----------------------------------------------------------------------------
  40.  * File:    df24.c
  41.  * Purpose: read and write 24-bit raster images
  42.  * Invokes: dfgr.c
  43.  * Contents:
  44.  *  DF24getdims: get dimensions of image
  45.  *  DF24reqil: use this interlace when returning image
  46.  *  DF24getimage: read in image
  47.  *  DF24setdims: set dimensions of image
  48.  *  DF24addimage: write out image
  49.  *
  50.  * Remarks: A RIG specifies attributes associated with an image- lookup table,
  51.  *          dimension, compression, color compensation etc.
  52.  *---------------------------------------------------------------------------*/
  53.  
  54.  
  55. #include "dfgr.h"
  56. #include "herr.h"
  57.  
  58. static int Newdata = 0;                /* does Readrig contain fresh data? */
  59. static int dimsset = 0;                /* have dimensions been set? */
  60.  
  61. #define LUT     0
  62. #define IMAGE   1
  63.  
  64.  
  65. /*-----------------------------------------------------------------------------
  66.  * Name:    DF24getdims
  67.  * Purpose: get dimensions of next image RIG
  68.  * Inputs:  filename: name of HDF file
  69.  *          pxdim, pydim: pointer to locations for returning x,y dimensions
  70.  *          pil: location for returning interlace of image in file
  71.  * Returns: 0 on success, -1 on failure with DFerror set
  72.  *          *pxdim, *pydim, *pil set on success
  73.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  74.  * Invokes: DFGRIgetdims
  75.  * Remarks: none
  76.  *---------------------------------------------------------------------------*/
  77.  
  78. #ifdef PROTOTYPE
  79. int DF24getdims(char *filename, int32 *pxdim, int32 *pydim, int *pil)
  80. #else
  81. int DF24getdims(filename, pxdim, pydim, pil)
  82.     char *filename;
  83.     int32 *pxdim, *pydim;
  84.     int *pil;
  85. #endif
  86. {
  87.     int ncomps;
  88.  
  89.     do {
  90.         if (DFGRIgetdims(filename, pxdim, pydim, &ncomps, pil, IMAGE)<0)
  91.             return FAIL;
  92.     } while (ncomps!=3);
  93.  
  94.     Newdata = 1;
  95.     return SUCCEED;
  96. }
  97.  
  98. /*-----------------------------------------------------------------------------
  99.  * Name:    DF24reqil
  100.  * Purpose: get next image with specified interlace
  101.  * Inputs:  il: interlace to get next image with
  102.  * Returns: 0 on success, -1 on failure with DFerror set
  103.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  104.  * Invokes: DFGRIreqil
  105.  * Remarks: none
  106.  *---------------------------------------------------------------------------*/
  107.  
  108. #ifdef PROTOTYPE
  109. int DF24reqil(int il)
  110. #else
  111. int DF24reqil(il)
  112.     int il;
  113. #endif
  114. {
  115.     return(DFGRIreqil(il, IMAGE));
  116. }
  117.  
  118. /*-----------------------------------------------------------------------------
  119.  * Name:    DF24getimage
  120.  * Purpose: get image from next RIG
  121.  * Inputs:  filename: name of HDF file
  122.  *          image: pointer to space to return image
  123.  *          xdim, ydim: dimensions of space to return lut
  124.  * Returns: 0 on success, -1 on failure with DFerror set
  125.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  126.  * Invokes: DFGRIgetimlut
  127.  * Remarks: space is assumed to be xdim * ydim * 3 bytes
  128.  *---------------------------------------------------------------------------*/
  129.  
  130. #ifdef PROTOTYPE
  131. int DF24getimage(char *filename, VOIDP image, int32 xdim, int32 ydim)
  132. #else
  133. int DF24getimage(filename, image, xdim, ydim)
  134.     char *filename;
  135.     VOIDP image;
  136.     int32 xdim, ydim;
  137. #endif
  138. {
  139.     int ret, il;
  140.     int32 tx, ty;
  141.  
  142.     if (!Newdata && DF24getdims(filename, &tx, &ty, &il) == FAIL)
  143.        return FAIL;
  144.     ret = DFGRIgetimlut(filename, image, xdim, ydim, IMAGE, 0);
  145.     Newdata = 0;
  146.     return(ret);
  147. }
  148.  
  149. /*-----------------------------------------------------------------------------
  150.  * Name:    DF24setdims
  151.  * Purpose: set dimensions of image to write next
  152.  * Inputs:  xdim, ydim: dimensions of image
  153.  *          il: interlace of image
  154.  * Returns: 0 on success, -1 on failure with DFerror set
  155.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  156.  * Invokes: DFGRIsetdims
  157.  * Remarks: none
  158.  *---------------------------------------------------------------------------*/
  159.  
  160. #ifdef PROTOTYPE
  161. int DF24setdims(int32 xdim, int32 ydim)
  162. #else
  163. int DF24setdims(xdim, ydim)
  164.     int32 xdim, ydim;
  165. #endif
  166. {
  167.     dimsset = 1;
  168.     return(DFGRIsetdims(xdim, ydim, 3, IMAGE));
  169. }
  170.  
  171. /*-----------------------------------------------------------------------------
  172.  * Name:    DF24setil
  173.  * Purpose: set interlace of image to write next
  174.  * Inputs:  il: interlace of image
  175.  * Returns: 0 on success, -1 on failure with DFerror set
  176.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  177.  * Invokes: DFGRIsetil
  178.  * Remarks: none
  179.  *---------------------------------------------------------------------------*/
  180.  
  181. #ifdef PROTOTYPE
  182. int DF24setil(int il)
  183. #else
  184. int DF24setil(il)
  185.     int il;
  186. #endif
  187. {
  188.     return(DFGRIsetil(il, IMAGE));
  189. }
  190.  
  191. /*-----------------------------------------------------------------------------
  192.  * Name:    DF24restart
  193.  * Purpose: restart file
  194.  * Inputs:
  195.  * Returns: 0 on success, -1 on failure with DFerror set
  196.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  197.  * Invokes: DFGRIrestart
  198.  * Remarks: none
  199.  *---------------------------------------------------------------------------*/
  200. #ifdef PROTOTYPE
  201. int DF24restart(void)
  202. #else
  203. int DF24restart()
  204. #endif
  205. {
  206.     return DFGRIrestart();
  207. }
  208.  
  209. /*-----------------------------------------------------------------------------
  210.  * Name:    DF24addimage
  211.  * Purpose: Write out image
  212.  * Inputs:  filename: name of HDF file
  213.  *          image: image to write
  214.  *          xdim, ydim: dimensions of array image
  215.  * Returns: 0 on success, -1 on failure with DFerror set
  216.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  217.  * Invokes: DFGRIaddimlut
  218.  * Remarks: array image is assumed to be xdim * ydim * 3 bytes
  219.  *---------------------------------------------------------------------------*/
  220.  
  221. #ifdef PROTOTYPE
  222. int DF24addimage(char *filename, VOIDP image, int32 xdim, int32 ydim)
  223. #else
  224. int DF24addimage(filename, image, xdim, ydim)
  225.     char *filename;
  226.     VOIDP image;
  227.     int32 xdim, ydim;
  228. #endif
  229. {
  230.     /* 0 == C */
  231.     if (!dimsset && DFGRIsetdims(xdim, ydim, 3, IMAGE) == FAIL)
  232.        return FAIL;
  233.     dimsset = 0; /* reset to new rig */
  234.  
  235.     return(DFGRIaddimlut(filename, image, xdim, ydim, IMAGE, 0, 0));
  236. }
  237.  
  238. #ifdef PROTOTYPE
  239. int DF24putimage(char *filename, VOIDP image, int32 xdim, int32 ydim)
  240. #else
  241. int DF24putimage(filename, image, xdim, ydim)
  242.     char *filename;
  243.     VOIDP image;
  244.     int32 xdim, ydim;
  245. #endif
  246. {
  247.     /* 0 == C */
  248.     if (!dimsset && DFGRIsetdims(xdim, ydim, 3, IMAGE) == FAIL)
  249.        return FAIL;
  250.     dimsset = 0; /* reset to new rig */
  251.  
  252.     return(DFGRIaddimlut(filename, image, xdim, ydim, IMAGE, 0, 1));
  253. }
  254.  
  255.  
  256. /*-----------------------------------------------------------------------------
  257.  * Name:    DF24readref
  258.  * Purpose: Set ref of 24-rig to get next
  259.  * Inputs:  filename: file to which this applies
  260.  *          ref: reference number of next get
  261.  * Returns: 0 on success, -1 on failure
  262.  * Users:   HDF programmers, other routines and utilities
  263.  * Invokes: DFGRreadref
  264.  * Remarks: checks if 24-rig with this ref exists
  265.  *---------------------------------------------------------------------------*/
  266.  
  267. #ifdef PROTOTYPE
  268. int DF24readref(char *filename, uint16 ref)
  269. #else
  270. int DF24readref(filename, ref)
  271.     char *filename;
  272.     uint16 ref;
  273. #endif
  274. {
  275.     return (DFGRreadref(filename, ref));
  276. }
  277.  
  278. /*-----------------------------------------------------------------------------
  279.  * Name:    DF24lastref
  280.  * Purpose: Return reference number of last read or written RIG
  281.  * Inputs:
  282.  * Returns: Last reference number
  283.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  284.  * Invokes: DFGRIlastref
  285.  * Remarks: none
  286.  *---------------------------------------------------------------------------*/
  287. #ifdef PROTOTYPE
  288. uint16 DF24lastref(void)
  289. #else
  290. uint16 DF24lastref()
  291. #endif
  292. {
  293.     return DFGRIlastref();
  294. }
  295.  
  296.