Working with Palettes inside the GR API
In addition to the Palette API, the GR API also provides the routines to work with palette data attached general raster images. This is the recommended method for these types of files rather then using the Palette API. Among other operations, the following are possible:
Once knowing the id number of the raster image (ri_id) with an attached palette, and the index number of the palette (lut_index), the user can determint the palette identifier (pal_id):
pal_id = GRgetlutid(ri_id,lut_index); (C)
or
pal_id = mggltid(ri_id,lut_index) (FORTRAN)
This palette identifier can be used to determine the palette reference number(pal_ref):
pal_ref = GRluttoref(pal_id); (C)
or
pal_ref = mglt2rf(pal_id) (FORTRAN)
After opening the HDF file (hopen/Hopen), intitilaizing the GR interface (mgstart/GRstart), creating the raster image array (mgcreat/GRcreate, and writing the image data (mgwrimg/GRwriteimage) as described previously, the associated palette for the image can also be written
After initializing the palette buffer array, the user/programmer needs to define the palette identifier (pal_id) for the image. Setting the palette index to zero (pal_index =0):
pal_id = mggltid(ri_id,pal_index) (FORTRAN)
or
pal_id = GRgetlutid(ri_id,pal_id) (C)
Then, the user can write the necessary data to the palette:
ret = mgwclut(pal_id,n_comps_pal,data_type,interlace_mode,num_entries,pal_data) (FORTRAN)
or
ret = GRwritelut(pal_id,n_comps_pal,data_type,interlace_mode,num_entries,pal_data) (C)
where the dat_type, interlace_mode, num_entries, and pal_id are as before and:
n_comps_pal = number of pixel components
pal_data = buffer containing the palette data
The user can then close the access to the raster image, GR API, and the HDF file as before:
retn = mgendac(ri_id) (FORTRAN)
retn = mgend(gr_id)
retn = hclose(file_id)
or
retn = GRendaccess(ri_id); ( C )
retn = GRend(gr_id)
retn = Hclose(file_id)
After opening the HDF file (hopen/Hopen), intitilaizing the GR interface (mgstart/GRstart), selecting the raster image array (mgselct/GRselect) as described perviously, the associated palette for the image can also be read. The first step is to get the palette identifier (pal_id) for the image:
pal_id = mggltid(ri_id,pal_index) (FORTRAN)
or
pal_id = GRgetlutid(ri_id,pal_id) (C)
Next, information can be obtained on the palette itself and then written to a normal array inside the program:
ret=mgglinf(pal_id,n_comps,data_type,interlace_mode,num_entries) (FORTRAN)
or
pal_id = GRgetlutinfo(pal_id,n_comps,data_type,interlace_mode,num_entries) (C)
The user can also read the palette data itself into the buffer (pal_data):
ret = mgrclut(pal_id,pal_data) (FORTRAN)
or
ret = GRreadlut(pal_id,pal_data) (C)
The user can then close the access to the raster image, GR API, and the HDF file as before:
retn = mgendac(ri_id) (FORTRAN)
retn = mgend(gr_id)
retn = hclose(file_id)
or
retn = GRendaccess(ri_id); ( C )
retn = GRend(gr_id)
retn = Hclose(file_id)