Accessing Palettes
Contents:
Typical functions that you would use to access a palette are
as follows:
(The functions in bold are used in the program example in this tutorial.)
The gr_pal program is a sample program for attaching a palette to
a GR image, and then reading it back in and printing it to the screen.
You can either download the C program at the end, or just take a
look at the HTML version, with the HDF calls highlighted:
If you have downloaded this program, then you can
compile and run it.
Following is a detailed review of what this program does:
- Opens the HDF file called gr1.hdf in Read/Write mode,
starts the GR interface, and selects the GR image, "Image_1".
- Sets up a palette and then gets the palette id for it
(GRgetlutid/mggltid).
- Writes the palette to the file
(GRwritelut/mgwrlut/mgwclut).
- Reads the palette information into another buffer and prints
this to the screen
(GRreadlut/mgrdlut/mgrclut).
- Terminates access to the GR image and the GR interface, and closes
the file.
If you have compiled and run the gr_pal program, you can view the
palette that gets added to the gr1.hdf file, using the hdfed
utility, as follows:
hdfed gr1.hdf
hdfed>info -all
hdfed>next tag=301
hdfed>dump -byte
hdfed>quit
Currently, you are unable to view the palette using the hdp utility.
Following is the palette data output that the gr_pal program displays to
the screen:
Programs used in this tutorial:
[Compiling a program]