summaryrefslogtreecommitdiffstats
path: root/tools/h4toh5pal.c
diff options
context:
space:
mode:
authorMuQun Yang <ymuqun@hdfgroup.org>2000-09-28 20:51:45 (GMT)
committerMuQun Yang <ymuqun@hdfgroup.org>2000-09-28 20:51:45 (GMT)
commit9918e0e06e27481a56f90044cac4017d35cdfd6e (patch)
tree9d8618e605b91633f9a24e7d87e0cadd7900ec75 /tools/h4toh5pal.c
parentda81e18888e11da7d0268a6bfa8d8a3c811c9d96 (diff)
downloadhdf5-9918e0e06e27481a56f90044cac4017d35cdfd6e.zip
hdf5-9918e0e06e27481a56f90044cac4017d35cdfd6e.tar.gz
hdf5-9918e0e06e27481a56f90044cac4017d35cdfd6e.tar.bz2
[svn-r2614]
Purpose: add h4toh5 converter source codes under tools directory. Description: [describe the bug, or describe the new feature, etc] Solution: [details about the changes, algorithm, etc...] [Please as detail as you can since your own explanation is better than others guessing it from the code.] Platforms tested: [machines you have tested the changed version. This is absolute important. Test it out on at least two or three different platforms such as Big-endian-32bit (SUN/IRIX), little-endian-32(LINUX) and 64-bit (IRIX64/UNICOS/DEC-ALPHA) would be good.]
Diffstat (limited to 'tools/h4toh5pal.c')
-rw-r--r--tools/h4toh5pal.c167
1 files changed, 167 insertions, 0 deletions
diff --git a/tools/h4toh5pal.c b/tools/h4toh5pal.c
new file mode 100644
index 0000000..fc59cce
--- /dev/null
+++ b/tools/h4toh5pal.c
@@ -0,0 +1,167 @@
+#include "h4toh5main.h"
+
+
+/*-------------------------------------------------------------------------
+ * Function: Palette_h4_to_h5
+ *
+ * Purpose: translate palette into hdf5 dataset
+ *
+ * Return: FAIL if failed, SUCCEED if successful.
+ *
+ * In :
+ file_id: file id
+ pal_id: PALETTE identifier
+ h5_g: hdf5 group id
+ pal_name: path name of the group where all palettes are in
+
+ *-------------------------------------------------------------------------
+ */
+
+int Palette_h4_to_h5(int32 file_id,int32 pal_id,hid_t h5g,char*pal_name) {
+
+ int32 ncomp;
+ int32 pal_ref;
+ int32 pal_type;
+ int32 interlace_mode;
+ int32 num_entries;
+ void* pal_data;
+ size_t h4memsize;
+ size_t h4size;
+
+ char palette_label[MAX_NC_NAME];
+ char palette_class[MAX_NC_NAME];
+ char palette_type[MAX_NC_NAME];
+
+ hid_t h5memtype;
+ hid_t h5type;
+ hid_t h5d_sid;
+ hid_t h5dset;
+ hsize_t h5dims[2];
+
+ pal_ref = GRluttoref(pal_id);
+
+ if(pal_ref <0) {
+ printf("error in obtaining palette.\n");
+ return FAIL;
+ }
+
+ /* no palette, just return. */
+ if(pal_ref == 0) return SUCCEED;
+
+ if(GRgetlutinfo(pal_id,&ncomp,&pal_type,&interlace_mode,&num_entries)==FAIL) {
+ printf("error in getting palette information.\n");
+ return FAIL;
+ }
+
+ if(h4type_to_h5type(pal_type,&h5memtype,&h4memsize,&h4size,&h5type)== FAIL) {
+ fprintf(stderr,"failed to translate image datatype. \n");
+ return FAIL;
+ }
+
+ /* according to mapping document, data type for palette will always be
+ uint8. */
+
+ if (h5type == H5T_STRING) {
+ if(h5string_to_int(DFNT_UCHAR8,&h5memtype,h4memsize,&h5type)==FAIL) {
+ fprintf(stderr,"failed to translate H5T_STRING to int8.");
+ return FAIL;
+ }
+ }
+
+ h5dims[0] = num_entries;
+ h5dims[1] = ncomp;
+
+ pal_data = malloc(h4memsize*ncomp*num_entries);
+
+ if (pal_data == NULL) {
+ printf("error in allocating memory for palette data.\n");
+ return FAIL;
+ }
+
+ if (GRreadlut(pal_id,(VOIDP)pal_data)==FAIL) {
+ printf("error in reading palette data. \n");
+ free(pal_data);
+ return FAIL;
+ }
+
+ h5d_sid = H5Screate_simple(2,h5dims,NULL);
+
+ if (h5d_sid <0) {
+ printf("error in creating space.\n");
+ free(pal_data);
+ return FAIL;
+ }
+
+ h5dset = H5Dcreate(h5g,pal_name,h5type,h5d_sid,H5P_DEFAULT);
+
+ if (h5dset < 0) {
+ printf("error in creating dataset. \n");
+ free(pal_data);
+ H5Sclose(h5d_sid);
+ return FAIL;
+ }
+
+ if (H5Dwrite(h5dset,h5memtype,h5d_sid,h5d_sid,H5P_DEFAULT,
+ (void *)pal_data)<0) {
+ fprintf(stdout,"error writing data for palette data\n");
+ free(pal_data);
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ return FAIL;
+ }
+ free(pal_data);
+
+
+ strcpy(palette_label,PALABEL);
+ strcpy(palette_class,PALETTE);
+ strcpy(palette_type,PAL_TYPE);
+
+ /* convert palette annotation into attribute of palette dataset.
+ Since there are no routines to find the exact tag of palette object,
+ we will check three possible object tags of palette objects, that is:
+ DFTAG_LUT. If the object tag of palette object is
+ falling out of this scope, we will not convert annotations into
+ hdf5 attributes; it is user's responsibility to make sure that object tags
+ for palette objects are DFTAG_LUT.*/
+
+ if(Annoobj_h4_to_h5(file_id,pal_ref,DFTAG_LUT,h5dset)== FAIL){
+ printf("failed to convert palette annotation into hdf5 attribute.\n");
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ return FAIL;
+ }
+
+ if(h4_transpredattrs(h5dset,HDF4_OBJECT_TYPE,palette_label)==FAIL) {
+ printf("unable to transfer palette label to HDF4 OBJECT TYPE.\n");
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ return FAIL;
+ }
+
+ if(h4_transpredattrs(h5dset,HDF4_PALETTE_CLASS,palette_class)==FAIL){
+ printf("unable to transfer palette class to HDF4 PALETTE CLASS.\n");
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ return FAIL;
+ }
+
+ if(h4_transpredattrs(h5dset,HDF4_PALETTE_TYPE,palette_type)==FAIL){
+ printf("unable to transfer palette type to HDF4 PALETTE TYPE.\n");
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ return FAIL;
+ }
+
+ if(h4_transnumattr(h5dset,HDF4_REF_NUM,pal_ref)==FAIL) {
+ printf("unable to transfer palette reference number to HDF4 REF. NUM.\n");
+ H5Sclose(h5d_sid);
+ H5Dclose(h5dset);
+ return FAIL;
+ }
+ return SUCCEED;
+}
+
+
+
+
+