home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / graphics.formats / hdf / NCSA_HDF / HDF.3.ascii.Z / HDF.3.ascii
Encoding:
Text File  |  1991-09-24  |  6.9 KB  |  239 lines

  1. 3.1NCSA HDF Calling Interfaces and Utilities
  2.  
  3. Storing Palettes3.1
  4.  
  5. National Center for Supercomputing Applications
  6.  
  7. November 1989
  8.  
  9.  
  10.  
  11.  
  12.  
  13. 3.1NCSA HDF Calling Interfaces and Utilities
  14.  
  15. Storing Palettes3.1
  16.  
  17. National Center for Supercomputing Applications
  18.  
  19. November 1989
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. Chapter 3Storing Palettes
  30.  
  31.  
  32.  
  33. Chapter Overview
  34. HDF 8-Bit Palettes
  35. Writing Palettes to a File
  36. Reading Palettes from a File
  37. Other Palette Routines
  38.  
  39. Chapter Overview
  40.  
  41. This chapter describes the routines that are available for storing and retrieving 8-bit palettes.
  42.  
  43.  
  44. HDF 8-Bit Palettes
  45.  
  46. An 8-bit palette is a lookup table with 256 entries that tell the system hardware which color to associate with each of the 256 possible pixel values. Each entry in the palette is chosen from a master palette of 224 RGB colors.
  47.  
  48. In HDF files, 8-bit palettes are assumed to be organized as follows. Each palette entry consists of 3 bytes-one each for red, green, and blue. The first three bytes represent the R, G, and B values of the first color in the palette; the next three the R, G, and B values of the second color; and so forth. The total size of a palette is 768 bytes. 
  49.  
  50. The HDF library contains routines for storing and retrieving palettes. These routines are callable from C and FORTRAN programs that have access to the library. All of the callable palette routines in the library begin with the letters DFP.
  51.  
  52. The functions, DFPaddpal and DFPgetpal, are the primary routines for palette I/O and should be sufficient for most palette I/O operations. The other six palette functions-DFPputpal, DFPnpals, DFPwriteref, DFPreadref, DFPrestart, and DFPlastref-provide greater control of the I/O process and are available to you if more control is needed.
  53.  
  54. Table 2.1 lists the long and short names and the functions of the palette routines currently contained in the HDF library. The following sections provide descriptions and examples of these calling routines.
  55.  
  56. Table 3.1Palette I/O Routines in the HDF Library
  57. Long NameShort NameFunction
  58.  
  59. DFPaddpaldpapalappends a palette to a file.
  60.  
  61. DFPgetpaldpgpalreads in the next palette in the file.
  62.  
  63. DFPputpaldpppalwrites a palette to a file.
  64.  
  65. DFPnpalsdpnpalsindicates number of palettes in a file.
  66.  
  67. DFPwriterefdpwrefsets the reference number of the next palette to be written.
  68.  
  69. DFPreadrefdprrefsets the reference number of the next palette to be retrieved.
  70.  
  71. DFPrestartdprestspecifies that the next call to DFPgetpal reads the first palette in the file, rather than the next.
  72.  
  73. DFPlastrefdplrefreturns the value of the reference number most recently read or written.
  74.  
  75.  
  76. Writing Palettes to a File
  77.  
  78. DFPaddpal
  79. FORTRAN:
  80. INTEGER FUNCTION DFPaddpal(filename, pal)
  81. CHARACTER*(*) filename-name of HDF file
  82. CHARACTER*(*) pal-768-byte space with palette
  83. C:
  84. int DFPaddpal(filename, palette)
  85. char *filename;/* name of HDF file */
  86. unsigned char *palette;/*768-byte space with palette */
  87.  
  88.  
  89. Purpose:  To append the palette stored in the array palette to an HDF file.
  90.  
  91. Returns:  0 on success; ╨1 on failure.
  92.  
  93. If file does not exist, it is created and the palette written to it.
  94.  
  95. DFPaddpal is often sufficient for adding the palette that you want to an HDF file. Other palette routines, which provide more refined access to palettes, are described next.
  96.  
  97.  
  98. Example: Writing a Palette to a File  with DFPaddpal
  99. Figure 3.1 shows a C code segment for writing a palette to an HDF file.
  100.  
  101. Figure 3.1Writing a Palette to a File
  102. C:
  103. intDFPaddpal();
  104. charpal[768];
  105.  
  106. DFaddpal("myfile.hdf",pal);
  107. ...
  108.  
  109.  
  110. DFPputpal
  111. FORTRAN:
  112. INTEGER FUNCTION DFPputpal(filename, pal, ow, filemode)
  113. CHARACTER*(*) filename-name of HDF file
  114. CHARACTER*(*) pal-768╨byte space for palette
  115. INTEGER ow-if 1, overwrite last palette read or written 
  116. if 0, write it as a fresh palette 
  117. INTEGER filemode-if "a", append palette to file 
  118. if "w", create new file 
  119. C:
  120. int DFPputpal(filename, palette, overwrite, filemode)
  121. char *filename;/* name of HDF file */
  122. unsigned char *palette;/* 768╨byte space for palette */
  123. int overwrite;/* if 1, overwrite last palette read or written */
  124. /* if 0, write it as a fresh palette */
  125. char *filemode;/* if "a", append palette to file */
  126. /* if "w", create new file */
  127.  
  128.  
  129. Purpose:  To write a palette to file.
  130.  
  131. Returns:  0 on success; ╨1 on failure.
  132.  
  133. This routine provides more control than DFPaddpal. Note that the combination filemode="w" and overwrite=1 has no meaning and will generate an error.
  134.  
  135.  
  136. Reading Palettes from a File
  137.  
  138. DFPgetpal
  139. FORTRAN:
  140. INTEGER FUNCTION DFPgetpal(filename, pal)
  141. CHARACTER*(*) filename-name of HDF file
  142. CHARACTER*(*) pal-768╨byte space for palette 
  143. C:
  144. int DFPgetpal(filename, palette)
  145. char *filename;/* name of HDF file */
  146. unsigned char *palette;/* 768╨byte space for palette */
  147.  
  148.  
  149. Purpose:  To get the next palette from file and store it in the array palette.
  150.  
  151. Returns:  0 on success; ╨1 on failure.
  152.  
  153. The array palette is assumed to be allocated at least 768 bytes. Successive additional calls to DFPgetpal retrieve the palettes in the file in the sequence in which they are stored.
  154.  
  155. DFPgetpal is often sufficient for getting the palette that you want from an HDF file. Other palette routines, which provide more refined access to palettes are described below.
  156.  
  157.  
  158. Example: Reading the First Available Palette
  159. Figure 3.2 shows a C code segment that reads the first available palette from an HDF file. 
  160.  
  161. Figure 3.2Reading the First Available Palette
  162. C:
  163. intDFPgetpal();
  164. charpal[768];
  165.  
  166. DFPgetpal("myfile.hdf",pal);
  167. ...
  168.  
  169.  
  170. Other Palette Routines
  171.  
  172. DFPnpals
  173. FORTRAN:
  174. INTEGER FUNCTION DFPnpals(filename)
  175. CHARACTER*(*) filename
  176. C:
  177. int DFPnpals(filename)
  178. char *filename;/* name of HDF file */
  179.  
  180.  
  181. Purpose:  To tell how many palettes are present in a file.
  182.  
  183. Returns:  Number of palettes on success; ╨1 on failure.
  184.  
  185. DFPwriteref
  186. FORTRAN:
  187. INTEGER FUNCTION DFPwriteref(filename, ref)
  188. CHARACTER*(*) filename-name of HDF file
  189. INTEGER ref-ref number to be used in next
  190. palette write 
  191. C:
  192. int DFPwriteref(filename, ref)
  193. char *filename;/* name of HDF file */
  194. uint16 ref;/* ref number to be used in next palette write */
  195.  
  196.  
  197. Purpose:  To set the reference number of the next palette to be written.
  198.  
  199. Returns:  0 on success; ╨1 on failure.
  200.  
  201.  
  202. DFPreadref
  203. FORTRAN:
  204. INTEGER FUNCTION DFPreadref(filename, ref)
  205. CHARACTER*(*) filename-name of HDF file
  206. INTEGER ref-ref number to be used in next read 
  207. C:
  208. int DFPreadref(filename, ref)
  209. char *filename;/* name of HDF file */
  210. uint16 ref;/* ref number to be used in next DFPgetpal */
  211.  
  212.  
  213. Purpose:  To set the reference number of the palette that DFPgetpal will retrieve next.
  214.  
  215. Returns:  0 on success; ╨1 if a palette with this reference number does not exist or if an error occurs.
  216.  
  217.  
  218. DFPrestart
  219. FORTRAN:
  220. INTEGER FUNCTION DFPrestart()
  221. C:
  222. int DFPrestart()
  223.  
  224.  
  225. Purpose:  To cause the next call to DFPgetpal to read the first palette in the file.
  226.  
  227. Returns:  0 on success.
  228.  
  229. DFPlastref
  230. FORTRAN:
  231. INTEGER FUNCTION DFPlastref()
  232. C:
  233. int DFPlastref()
  234.  
  235.  
  236. Purpose:  To determine the value of the reference number most recently read or written by a palette function call.
  237.  
  238. Returns:  The reference number on success; ╨1 on failure.
  239.