home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / hdf3_2r2.lha / HDF3.2r2 / src / df24f.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-30  |  13.1 KB  |  442 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.5 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/src/RCS/df24f.c,v 1.5 1992/10/30 18:36:52 koziol beta koziol $
  30.  
  31. $Log: df24f.c,v $
  32.  * Revision 1.5  1992/10/30  18:36:52  koziol
  33.  * Fixed casts in a bunch of functions to make the SGI ANSI compiler happy
  34.  *
  35.  * Revision 1.4  1992/10/27  22:18:31  koziol
  36.  * typo
  37.  *
  38.  * Revision 1.3  1992/10/12  18:11:51  koziol
  39.  * Updated for v3.2r2 release
  40.  *
  41.  * Revision 1.2  1992/09/11  14:15:04  koziol
  42.  * Changed Fortran stubs' parameter passing to use a new typedef, intf,
  43.  * which should be typed to the size of an INTEGER*4 in whatever Fortran
  44.  * compiler the C functions need to be compatible with.  (This is mostly
  45.  * for the PC and possibly for the Mac)
  46.  *
  47.  * Revision 1.1  1992/08/25  21:40:44  koziol
  48.  * Initial revision
  49.  *
  50. */
  51. /*-----------------------------------------------------------------------------
  52.  * File:    df24F.c
  53.  * Purpose: read and write 24-bit raster images
  54.  * Invokes: dfgr.c df24.c
  55.  * Contents: 
  56.  *  d2reqil_: use this interlace when returning image
  57.  *  df24reqil_: use this interlace when returning image
  58.  *  d2sdims_: set dimensions of image
  59.  *  df24setdims_: set dimensions of image
  60.  *  d2setil_: set interlace for image
  61.  *  df24setil_: set interlace for image
  62.  *  d2first_: restart 24 bit raster
  63.  *  df24restart_: restart 24 bit raster
  64.  *  d2igdim_: get dimensions of image
  65.  *  d2igimg_: read in image
  66.  *  d2iaimg_: write out image
  67.  *  d24lref_: last ref number
  68.  *
  69.  * Remarks:A RIG specifies attributes associated with an image - lookup table, 
  70.  *          dimension, compression, color compensation etc.
  71.  *---------------------------------------------------------------------------*/
  72.  
  73. #include "hdf.h"
  74. #include "dfgr.h"
  75.  
  76. #ifndef DF24_FNAMES
  77. #   define DF24_FNAMES
  78. #ifdef DF_CAPFNAMES
  79. #   define nd2reqil  FNAME(D2REQIL)
  80. #   define ndf24reqil    FNAME(DF24REQIL)
  81. #   define nd2sdims  FNAME(D2SDIMS)
  82. #   define ndf24setdims  FNAME(DF24SETDIMS)
  83. #   define nd2setil  FNAME(D2SETIL)
  84. #   define ndf24setil    FNAME(DF24SETIL)
  85. #   define nd2first  FNAME(D2FIRST)
  86. #   define ndf24restart  FNAME(DF24RESTART)
  87. #   define nd2igdim  FNAME(D2IGDIM)
  88. #   define nd2igimg  FNAME(D2IGIMG)
  89. #   define nd2iaimg  FNAME(D2IAIMG)
  90. #   define nd2irref  FNAME(D2IRREF)
  91. #else
  92. #   define nd2reqil  FNAME(d2reqil)
  93. #   define ndf24reqil    FNAME(df24reqil)
  94. #   define nd2sdims  FNAME(d2sdims)
  95. #   define ndf24setdims  FNAME(df24setdims)
  96. #   define nd2setil  FNAME(d2setil)
  97. #   define ndf24setil    FNAME(df24setil)
  98. #   define nd2first  FNAME(d2first)
  99. #   define ndf24restart  FNAME(df24restart)
  100. #   define nd2igdim  FNAME(d2igdim)
  101. #   define nd2igimg  FNAME(d2igimg)
  102. #   define nd2iaimg  FNAME(d2iaimg)
  103. #   define nd2irref  FNAME(d2irref)
  104. #endif /* DF_CAPFNAMES */
  105. #endif /* DF24_FNAMES */
  106.  
  107. #define LUT     0
  108. #define IMAGE   1
  109.  
  110. static int dimsset = 0;
  111.  
  112.  
  113. /*-----------------------------------------------------------------------------
  114.  * Name:    d2reqil
  115.  * Purpose: get next image with specified interlace
  116.  * Inputs:  il: interlace to get next image with
  117.  * Returns: 0 on success, -1 on failure with DFerror set
  118.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  119.  * Invokes: DFGRIreqil
  120.  * Remarks: none
  121.  *---------------------------------------------------------------------------*/
  122.  
  123.     FRETVAL(intf)
  124. #ifdef PROTOTYPE
  125. nd2reqil(intf *il)
  126. #else
  127. nd2reqil(il)
  128.     intf *il;
  129. #endif /* PROTOTYPE */
  130. {
  131.     return(DFGRIreqil(*il, IMAGE));
  132. }
  133.  
  134. /*-----------------------------------------------------------------------------
  135.  * Name:    d2sdims
  136.  * Purpose: set dimensions of image to write next
  137.  * Inputs:  xdim, ydim: dimensions of image
  138.  *          il: interlace of image
  139.  * Returns: 0 on success, -1 on failure with DFerror set
  140.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  141.  * Invokes: DFGRIsetdims
  142.  * Remarks: none
  143.  *---------------------------------------------------------------------------*/
  144.  
  145.     FRETVAL(intf)
  146. #ifdef PROTOTYPE
  147. nd2sdims(intf *xdim, intf *ydim)
  148. #else
  149. nd2sdims(xdim, ydim)
  150.     intf *xdim, *ydim;
  151. #endif /* PROTOTYPE */
  152. {
  153.     dimsset = 1;
  154.     return(DFGRIsetdims(*xdim, *ydim, 3, IMAGE));
  155. }
  156.  
  157.  
  158. /*-----------------------------------------------------------------------------
  159.  * Name:    d2igdim
  160.  * Purpose: get dimensions of next image RIG
  161.  * Inputs:  filename: name of HDF file
  162.  *          pxdim, pydim: pointer to locations for returning x,y dimensions
  163.  *          pil: location for returning interlace of image in file
  164.  *          fnlen: length of filename
  165.  * Returns: 0 on success, -1 on failure with DFerror set
  166.  *          *pxdim, *pydim, *pil set on success
  167.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  168.  * Invokes: DF24getdims
  169.  * Remarks: none
  170.  *---------------------------------------------------------------------------*/
  171.  
  172.     FRETVAL(intf)
  173. #ifdef PROTOTYPE
  174. nd2igdim(_fcd filename, intf *pxdim, intf *pydim, intf *pil, intf *fnlen)
  175. #else
  176. nd2igdim(filename, pxdim, pydim, pil, fnlen)
  177.     _fcd filename;
  178.     intf *pxdim, *pydim;
  179.     intf *pil, *fnlen;
  180. #endif /* PROTOTYPE */
  181. {
  182.     char *fn;
  183.     intf ret;
  184.  
  185.     fn = HDf2cstring(filename, *fnlen);
  186.     ret =  DF24getdims(fn, (int32 *)pxdim, (int32 *)pydim, (intn *)pil);
  187.     HDfreespace(fn);
  188.     return(ret);
  189. }
  190.  
  191.  
  192. /*-----------------------------------------------------------------------------
  193.  * Name:    d2igimg
  194.  * Purpose: get image from next RIG
  195.  * Inputs:  filename: name of HDF file
  196.  *          image: pointer to space to return image
  197.  *          xdim, ydim: dimensions of space to return image
  198.  *          fnlen: length of filename
  199.  * Returns: 0 on success, -1 on failure with DFerror set
  200.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  201.  * Invokes: DFGRIgetimlut
  202.  * Remarks: space is assumed to be xdim * ydim * 3 bytes
  203.  *---------------------------------------------------------------------------*/
  204.  
  205.     FRETVAL(intf)
  206. #ifdef PROTOTYPE
  207. nd2igimg(_fcd filename, _fcd image, intf *xdim, intf *ydim, intf *fnlen)
  208. #else
  209. nd2igimg(filename, image, xdim, ydim, fnlen)
  210.     _fcd filename;
  211.     _fcd image;
  212.     intf *xdim, *ydim;
  213.     intf *fnlen;
  214. #endif /* PROTOTYPE */
  215. {
  216.     char *fn;
  217.     intf ret;
  218.  
  219.     fn = HDf2cstring(filename, *fnlen);
  220.     ret =  DF24getimage(fn, (VOIDP)_fcdtocp(image), *xdim, *ydim);
  221.     HDfreespace(fn);
  222.     return(ret);
  223. }
  224.  
  225.  
  226. /*-----------------------------------------------------------------------------
  227.  * Name:    d2iaimg
  228.  * Purpose: Write out image
  229.  * Inputs:  filename: name of HDF file
  230.  *          image: image to write
  231.  *          xdim, ydim: dimensions of array image
  232.  *          fnlen: length of filename
  233.  * Returns: 0 on success, -1 on failure with DFerror set
  234.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  235.  * Invokes: DFGRIaddimlut
  236.  * Remarks: array image is assumed to be xdim * ydim * ncomps bytes
  237.  *---------------------------------------------------------------------------*/
  238.  
  239.     FRETVAL(intf)
  240. #ifdef PROTOTYPE
  241. nd2iaimg(_fcd filename, _fcd image, intf *xdim, intf *ydim, intf *fnlen,
  242.     intf *newfile)
  243. #else
  244. nd2iaimg(filename, image, xdim, ydim, fnlen, newfile)
  245.     _fcd filename;
  246.     _fcd image;
  247.     intf *xdim, *ydim;
  248.     intf *fnlen, *newfile;
  249. #endif /* PROTOTYPE */
  250. {
  251.     char *fn;
  252.     intf ret;
  253.  
  254.     if (!dimsset)
  255.         if (DFGRIsetdims(*xdim, *ydim, 3, IMAGE)<0) return(-1);
  256.  
  257.     fn = HDf2cstring(filename, *fnlen);
  258.     ret = DFGRIaddimlut(fn, (VOIDP)_fcdtocp(image), *xdim, *ydim,
  259.             IMAGE, 1, *newfile);
  260.     HDfreespace(fn);
  261.     return(ret);
  262. }
  263.  
  264.  
  265. /*-----------------------------------------------------------------------------
  266.  * Name:    d2setil
  267.  * Purpose: set interlace store with following images
  268.  * Inputs:  il: interlace to set
  269.  * Returns: 0 on success, -1 on failure with DFerror set
  270.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  271.  * Invokes: DFGRIsetil
  272.  * Remarks: none
  273.  *---------------------------------------------------------------------------*/
  274.  
  275.     FRETVAL(intf)
  276. #ifdef PROTOTYPE
  277. nd2setil(intf *il)
  278. #else
  279. nd2setil(il)
  280.     intf *il;
  281. #endif /* PROTOTYPE */
  282. {
  283.     return (DFGRIsetil(*il, IMAGE));
  284. }
  285.  
  286. /*-----------------------------------------------------------------------------
  287.  * Name:    df24first
  288.  * Purpose: restart 24 bit raster file
  289.  * Inputs:  
  290.  * Returns: 0 on success, -1 on failure with DFerror set
  291.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  292.  * Invokes: DFGRIrestart
  293.  * Remarks: none
  294.  *---------------------------------------------------------------------------*/
  295.  
  296.     FRETVAL(intf)
  297. #ifdef PROTOTYPE
  298. nd2first(void)
  299. #else
  300. nd2first()
  301. #endif /* PROTOTYPE */
  302. {
  303.     return (DFGRIrestart());
  304. }
  305.  
  306.  
  307. /*-----------------------------------------------------------------------------
  308.  * Name:    d24lref
  309.  * Purpose: return last reference number 
  310.  * Inputs:  
  311.  * Returns: last ref number
  312.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  313.  * Invokes: DFGRIrestart
  314.  * Remarks: none
  315.  *---------------------------------------------------------------------------*/
  316.  
  317.     FRETVAL(intf)
  318. #ifdef PROTOTYPE
  319. nd24lref(void)
  320. #else
  321. nd24lref()
  322. #endif /* PROTOTYPE */
  323. {
  324.     return (DFGRIlastref());
  325. }
  326.  
  327. /*-----------------------------------------------------------------------------
  328.  * Name:    df24reqil
  329.  * Purpose: get next image with specified interlace
  330.  * Inputs:  il: interlace to get next image with
  331.  * Returns: 0 on success, -1 on failure with DFerror set
  332.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  333.  * Invokes: DFGRIreqil
  334.  * Remarks: none
  335.  *---------------------------------------------------------------------------*/
  336.  
  337.     FRETVAL(intf)
  338. #ifdef PROTOTYPE
  339. ndf24reqil(intf *il)
  340. #else
  341. ndf24reqil(il)
  342.     intf *il;
  343. #endif /* PROTOTYPE */
  344. {
  345.     return(DFGRIreqil(*il, IMAGE));
  346. }
  347.  
  348. /*-----------------------------------------------------------------------------
  349.  * Name:    df24setdims
  350.  * Purpose: set dimensions of image to write next
  351.  * Inputs:  xdim, ydim: dimensions of image
  352.  *          il: interlace of image
  353.  * Returns: 0 on success, -1 on failure with DFerror set
  354.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  355.  * Invokes: DFGRIsetdims
  356.  * Remarks: none
  357.  *---------------------------------------------------------------------------*/
  358.  
  359.     FRETVAL(intf)
  360. #ifdef PROTOTYPE
  361. ndf24setdims(intf *xdim, intf *ydim)
  362. #else
  363. ndf24setdims(xdim, ydim)
  364.     intf *xdim, *ydim;
  365. #endif /* PROTOTYPE */
  366. {
  367.     dimsset = 1;
  368.     return(DFGRIsetdims(*xdim, *ydim, 3, IMAGE));
  369. }
  370.  
  371. /*-----------------------------------------------------------------------------
  372.  * Name:    df24setil
  373.  * Purpose: set interlace store with following images
  374.  * Inputs:  il: interlace to set
  375.  * Returns: 0 on success, -1 on failure with DFerror set
  376.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  377.  * Invokes: DFGRIsetil
  378.  * Remarks: none
  379.  *---------------------------------------------------------------------------*/
  380.  
  381.     FRETVAL(intf)
  382. #ifdef PROTOTYPE
  383. ndf24setil(intf *il)
  384. #else
  385. ndf24setil(il)
  386.     intf *il;
  387. #endif /* PROTOTYPE */
  388. {
  389.     return (DFGRIsetil(*il, IMAGE));
  390. }
  391.  
  392. /*-----------------------------------------------------------------------------
  393.  * Name:    df24restart
  394.  * Purpose: restart 24 bit raster file
  395.  * Inputs:  
  396.  * Returns: 0 on success, -1 on failure with DFerror set
  397.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  398.  * Invokes: DFGRIrestart
  399.  * Remarks: none
  400.  *---------------------------------------------------------------------------*/
  401.  
  402.     FRETVAL(intf)
  403. #ifdef PROTOTYPE
  404. ndf24restart(void)
  405. #else
  406. ndf24restart()
  407. #endif /* PROTOTYPE */
  408. {
  409.     return (DFGRIrestart());
  410. }
  411.  
  412. /*-----------------------------------------------------------------------------
  413.  * Name:    d2irref
  414.  * Purpose: Internal stub for setting ref of rig to read next
  415.  * Inputs:  filename: name of HDF file
  416.  *          ref: reference
  417.  *          fnlen: length of filename
  418.  * Returns: 0 on success, -1 on failure with DFerror set
  419.  * Users:   HDF HLL (high-level library) users, utilities, other routines
  420.  * Invokes: DFGRreadref
  421.  * Remarks: 
  422.  *---------------------------------------------------------------------------*/
  423.  
  424.     FRETVAL(intf)
  425. #ifdef PROTOTYPE
  426. nd2irref(_fcd filename, intf *ref, intf *fnlen)
  427. #else
  428. nd2irref(filename, ref, fnlen)
  429.     _fcd filename;
  430.     intf *ref;
  431.     intf *fnlen;
  432. #endif /* PROTOTYPE */
  433. {
  434.     char *fn;
  435.     intf ret;
  436.  
  437.     fn = HDf2cstring(filename, *fnlen);
  438.     ret = DFGRreadref(fn, (uint16)*ref);
  439.     HDfreespace(fn);
  440.     return(ret);
  441. }
  442.