diff options
author | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2006-02-06 16:11:48 (GMT) |
---|---|---|
committer | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2006-02-06 16:11:48 (GMT) |
commit | 35c1f3682e1f41c716ddc1c55ff66f33574b2460 (patch) | |
tree | 901bcb5dd8d4e67d06ee05e4d03ccaa1f80fc7f7 | |
parent | 54956412967b86c64a58f775cf67573ca4a55bc1 (diff) | |
download | hdf5-35c1f3682e1f41c716ddc1c55ff66f33574b2460.zip hdf5-35c1f3682e1f41c716ddc1c55ff66f33574b2460.tar.gz hdf5-35c1f3682e1f41c716ddc1c55ff66f33574b2460.tar.bz2 |
[svn-r11918] Purpose:
bug fix , bugzilla bug #1
Description:
the gif2h5 was not writing HDF5 images correctly
Solution:
use the Image API to write the image, rewrote the writing functionY
Platforms tested:
linux
solaris
Misc. update:
-rwxr-xr-x | Makefile.am | 7 | ||||
-rw-r--r-- | Makefile.in | 6 | ||||
-rw-r--r-- | hl/tools/gif2h5/Makefile.am | 4 | ||||
-rw-r--r-- | hl/tools/gif2h5/Makefile.in | 11 | ||||
-rw-r--r-- | hl/tools/gif2h5/writehdf.c | 354 | ||||
-rw-r--r-- | tools/gifconv/Makefile.am | 4 | ||||
-rw-r--r-- | tools/gifconv/Makefile.in | 11 | ||||
-rw-r--r-- | tools/gifconv/writehdf.c | 354 |
8 files changed, 89 insertions, 662 deletions
diff --git a/Makefile.am b/Makefile.am index b6c00fe..ae8b9d3 100755 --- a/Makefile.am +++ b/Makefile.am @@ -71,9 +71,10 @@ else HDF5_HL_DIR= endif -SUBDIRS = src test $(TESTPARALLEL_DIR) tools . $(CXX_DIR) $(FORTRAN_DIR) \ - $(HDF5_HL_DIR) -DIST_SUBDIRS = src test testpar tools . c++ fortran hl perform examples +SUBDIRS = src test $(TESTPARALLEL_DIR) $(HDF5_HL_DIR) tools . $(CXX_DIR) \ + $(FORTRAN_DIR) + +DIST_SUBDIRS = src test testpar hl tools . c++ fortran perform examples # Some files generated during configure that should be cleaned DISTCLEANFILES=src/H5config.h src/H5pubconf.h config/stamp1 config/stamp2 diff --git a/Makefile.in b/Makefile.in index bfdd58f..45373df 100644 --- a/Makefile.in +++ b/Makefile.in @@ -359,10 +359,10 @@ CHECK_CLEANFILES = *.chkexe *.chklog *.clog @BUILD_FORTRAN_CONDITIONAL_TRUE@FORTRAN_DIR = fortran @BUILD_HDF5_HL_CONDITIONAL_FALSE@HDF5_HL_DIR = @BUILD_HDF5_HL_CONDITIONAL_TRUE@HDF5_HL_DIR = hl -SUBDIRS = src test $(TESTPARALLEL_DIR) tools . $(CXX_DIR) $(FORTRAN_DIR) \ - $(HDF5_HL_DIR) +SUBDIRS = src test $(TESTPARALLEL_DIR) $(HDF5_HL_DIR) tools . $(CXX_DIR) \ + $(FORTRAN_DIR) -DIST_SUBDIRS = src test testpar tools . c++ fortran hl perform examples +DIST_SUBDIRS = src test testpar hl tools . c++ fortran perform examples # Some files generated during configure that should be cleaned DISTCLEANFILES = src/H5config.h src/H5pubconf.h config/stamp1 config/stamp2 diff --git a/hl/tools/gif2h5/Makefile.am b/hl/tools/gif2h5/Makefile.am index db2f411..29db664 100644 --- a/hl/tools/gif2h5/Makefile.am +++ b/hl/tools/gif2h5/Makefile.am @@ -20,7 +20,7 @@ include $(top_srcdir)/config/commence.am # Include src and tools/lib directories -INCLUDES=-I$(top_srcdir)/src -I$(top_srcdir)/tools/lib +INCLUDES=-I$(top_srcdir)/src -I$(top_srcdir)/tools/lib -I$(top_srcdir)/hl/src # These are our main targets, the tools bin_PROGRAMS=gif2h5 h52gif @@ -29,6 +29,6 @@ gif2h5_SOURCES=gif2hdf.c gif2mem.c decompress.c gifread.c writehdf.c h52gif_SOURCES=hdf2gif.c hdfgifwr.c readhdf.c # Programs all depend on the hdf5 library and the tools library -LDADD=$(LIBH5TOOLS) $(LIBHDF5) +LDADD=$(LIBH5TOOLS) $(LIBHDF5) $(LIBH5_HL) include $(top_srcdir)/config/conclude.am diff --git a/hl/tools/gif2h5/Makefile.in b/hl/tools/gif2h5/Makefile.in index b9133a6..629af0a 100644 --- a/hl/tools/gif2h5/Makefile.in +++ b/hl/tools/gif2h5/Makefile.in @@ -75,12 +75,15 @@ gif2h5_OBJECTS = $(am_gif2h5_OBJECTS) gif2h5_LDADD = $(LDADD) am__DEPENDENCIES_1 = $(top_builddir)/tools/lib/libh5tools.la am__DEPENDENCIES_2 = $(top_builddir)/src/libhdf5.la -gif2h5_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) +am__DEPENDENCIES_3 = $(top_builddir)/hl/src/libhdf5_hl.la +gif2h5_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \ + $(am__DEPENDENCIES_3) am_h52gif_OBJECTS = hdf2gif.$(OBJEXT) hdfgifwr.$(OBJEXT) \ readhdf.$(OBJEXT) h52gif_OBJECTS = $(am_h52gif_OBJECTS) h52gif_LDADD = $(LDADD) -h52gif_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) +h52gif_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \ + $(am__DEPENDENCIES_3) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/bin/depcomp am__depfiles_maybe = depfiles @@ -336,12 +339,12 @@ TRACE = perl $(top_srcdir)/bin/trace CHECK_CLEANFILES = *.chkexe *.chklog *.clog # Include src and tools/lib directories -INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/tools/lib +INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/tools/lib -I$(top_srcdir)/hl/src gif2h5_SOURCES = gif2hdf.c gif2mem.c decompress.c gifread.c writehdf.c h52gif_SOURCES = hdf2gif.c hdfgifwr.c readhdf.c # Programs all depend on the hdf5 library and the tools library -LDADD = $(LIBH5TOOLS) $(LIBHDF5) +LDADD = $(LIBH5TOOLS) $(LIBHDF5) $(LIBH5_HL) # Automake needs to be taught how to build lib, progs, and tests targets. # These will be filled in automatically for the most part (e.g., diff --git a/hl/tools/gif2h5/writehdf.c b/hl/tools/gif2h5/writehdf.c index 8d7405e..ee7998c 100644 --- a/hl/tools/gif2h5/writehdf.c +++ b/hl/tools/gif2h5/writehdf.c @@ -16,54 +16,23 @@ #include <string.h> #include "gif.h" - -/******************************************************************* - * Function: write_text_attribute - * Use: Just a small wrapper to write text attributes easily - *******************************************************************/ -static int write_text_attribute(hid_t dataset_id , const char *attr_name, - const char *attr_value, const size_t attr_len) -{ - /* variables for the attributes */ - hsize_t attr_size; /* dimensions for the attribute */ - hid_t attr_dataspace_id; /* dataspaces needed for the various attributes */ - hid_t attr_attr_id; /* attribute id */ - hid_t attr_type_id; - - /* check strings */ - if (!attr_name || !attr_value) - return -1; - - /* figure out size of the data */ - attr_size = (hsize_t)attr_len; - - /* set the type to string */ - attr_type_id = H5Tcopy(H5T_C_S1); - H5Tset_size(attr_type_id , (size_t)attr_size); - - /* create the dataspace for the attribute */ - attr_dataspace_id = H5Screate(H5S_SCALAR); - - /* create the attribute */ - attr_attr_id = H5Acreate(dataset_id , attr_name , attr_type_id , - attr_dataspace_id , H5P_DEFAULT); - - /* write out the attribute data */ - if (H5Awrite(attr_attr_id , attr_type_id , attr_value) < 0) - return -1; - - /* close the attribute */ - if (H5Aclose(attr_attr_id) < 0) - return -1; - - /* close the dataspace */ - if (H5Sclose(attr_dataspace_id) < 0) { - fprintf(stderr , "Unable to close attribute dataspace. Aborting \n"); - return -1; - } - - return 0; -} +#include "H5IM.h" + + +/*------------------------------------------------------------------------- + * Function: WriteHDF + * + * Purpose: Write the GIF image with the HDF5 Image API + * + * Programmer: Unknown + * + * Modifications: pvn + * Use the HDF5 IMAGE API to write the HDF5 image and pallete + * + * Date: January, 31, 2006 + * + *------------------------------------------------------------------------- + */ int WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName , char *GIFFileName) @@ -78,14 +47,10 @@ WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName , char *GIFFileName) PlainTextCount; /* number of plain text extensions */ #endif /* UNUSED */ - char ImageName[256]; /* Image name for the GR Image */ - char GroupName[VSNAMELENMAX]; /* so that we can name the subgroups appropriately */ + char ImageName[256]; /* Image name for the Image */ /* H5 variables */ hid_t file_id; /* H5 file id */ - hid_t image_id; /* H5 id for the whole image */ - hid_t pal_id; /* H5 id for the palette */ - hobj_ref_t pal_ref; /* Create a reference for the palette */ /* temp counter */ int i; @@ -101,16 +66,6 @@ WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName , char *GIFFileName) PlainTextCount = (WORD)gifHead.PlainTextCount; #endif /* UNUSED */ - /* get the main group name from GIFFileName */ - GroupName[0]= '/'; - - if (strncpy(GroupName , GIFFileName , VSNAMELENMAX-2) == NULL) { - fprintf(stderr , "strncpy failed\n"); - exit(1); - } - - GroupName[VSNAMELENMAX - 1] = '\0'; - if ((file_id = H5Fcreate(HDFName , H5F_ACC_TRUNC , H5P_DEFAULT , H5P_DEFAULT)) < 0) { /* error occured opening the HDF File for write */ fprintf(stderr , "HDF file could not be opened for writing\n"); @@ -118,126 +73,23 @@ WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName , char *GIFFileName) exit(1); } - /* create a group within the root group to hold the gif image */ - /* might want to make a different naming style out here */ - image_id = H5Gcreate(file_id, GroupName , 0); - /* first create the global palette if there is one */ if (gifHead.PackedField & 0x80) { /* global palette exists */ - hid_t dataspace_id; /* identifier for dataspace */ hsize_t dims[2]; /* specify the dimensions of the palette */ hsize_t dimsr[1] = {1}; /* needed to store reference */ - hid_t ref_dataspace_id; /* dataspace id for references */ - hid_t ref_dataset_id; /* dataset id for references */ /* size of the palette is tablesize (rows) X 3 (columns) */ dims[0] = gifHead.TableSize; dims[1] = 3; - - /* create the dataspace */ - if ((dataspace_id = H5Screate_simple(2 , dims , NULL)) < 0) { - fprintf(stderr , "Could not create dataspace for palette. Aborting...\n"); - return -1; - } - - /* create the palette dataset */ - if ((pal_id = H5Dcreate(image_id , "Global Palette" , H5T_NATIVE_UINT8 , dataspace_id , H5P_DEFAULT )) < 0) { - fprintf(stderr , "Could not create palette dataset. Aborting...\n"); - return -1; - } - - /* write the palette data out */ - /****** Ask Elena about VOIDP ******/ - if (H5Dwrite(pal_id , H5T_NATIVE_UINT8 , H5S_ALL , H5S_ALL , H5P_DEFAULT , (void *)gifHead.HDFPalette) < 0) { - fprintf(stderr , "Error writing dataset. Aborting...\n"); - return -1; - } - - /* set palette attributes */ - - /* attribute CLASS = PALETTE */ - if ((write_text_attribute(pal_id , "CLASS" , "PALETTE",strlen("PALETTE"))) < 0) { - fprintf(stderr , "Unable to write palette attributes. Aborting\n"); - return -1; - } - - /* attribute PAL_COLORMODEL = RGB */ - if ((write_text_attribute(pal_id , "PAL_COLORMODEL" , "RGB",strlen("RGB"))) < 0) { - fprintf(stderr , "Unable to write palette attributes. Aborting\n"); - return -1; - } - - /* attribute PAL_TYPE = STANDARD8 */ - if ((write_text_attribute(pal_id , "PAL_TYPE" , "STANDARD8",strlen("STANDARD8"))) < 0) { - fprintf(stderr , "Unable to write palette attributes. Aborting\n"); - return -1; - } - - /* attribute PAL_VERSION = 1.0 */ - if ((write_text_attribute(pal_id , "PAL_VERSION" , "1.0",strlen("1.0"))) < 0) { - fprintf(stderr , "Unable to write palette attributes. Aborting\n"); - return -1; - } - - /* create dataspace for the dataset to store references */ - ref_dataspace_id = H5Screate_simple(1 , dimsr , NULL); - - /* create a dataset to store the references */ - ref_dataset_id = H5Dcreate(image_id , "Palette Reference" , H5T_STD_REF_OBJ , ref_dataspace_id , H5P_DEFAULT); - - /* create a reference to the palette */ - if (H5Rcreate(&pal_ref , image_id , "Global Palette" , H5R_OBJECT , -1) < 0) { - fprintf(stderr , "Unable to create palette reference\n"); - return -1; - } - - /* write the reference out */ - if (H5Dwrite(ref_dataset_id , H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL , H5P_DEFAULT, &pal_ref) < 0) { - fprintf(stderr , "Unable to write Palette Reference"); - return -1; - } - - /* close dataset */ - if (H5Dclose(ref_dataset_id) < 0) { - fprintf(stderr , "Unable to close palette dataset.\n"); - return -1; - } - - /* close dataspace */ - if (H5Sclose(ref_dataspace_id) < 0) { - fprintf(stderr , "Unable to close palette dataspace.\n"); - return -1; - } - - /* close everything */ - if (H5Dclose(pal_id) < 0) { - fprintf(stderr , "Unable to close palette dataset. Aborting.\n"); - return -1; - } - - if (H5Sclose(dataspace_id) < 0) { - fprintf(stderr , "Unable to close palette dataspace. Aborting.\n"); - return -1; - } + + /* make a palette */ + if (H5IMmake_palette(file_id,"Global Palette",dims,(unsigned char *)gifHead.HDFPalette)<0) + return -1; } for(i = 0; i < ImageCount; i++) { - /* variables for the images */ hsize_t dims[2]; /* dimensions for the dataset */ - hid_t dataspace_id; /* identifier for the dataspace */ - hid_t sub_image_id; /* wierd name to distinguish from the group_id */ - - /* variables for the attributes */ - hsize_t attr_dims[2]; /* dimensions for the attribute */ - hid_t attr_dataspace_id;/* dataspaces needed for the various attributes */ - hid_t attr_attr_id; /* attribute id */ - BYTE minmax[2]; /* lower and upper minmax values */ - - /* initialise minmax */ - minmax[0] = 0 ; - minmax[1] = 255; - /* get the gifImageDesc */ gifImageDesc = GifMemoryStruct.GifImageDesc[i]; @@ -245,162 +97,19 @@ WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName , char *GIFFileName) dims[0] = gifImageDesc->ImageHeight; dims[1] = gifImageDesc->ImageWidth; - /* create the empty dataspace */ - if ((dataspace_id = H5Screate_simple(2 , dims , NULL)) < 0) { - fprintf(stderr , "Could not create image dataspace. Aborting\n"); - return -1; - } - + /* create the image name */ sprintf(ImageName , "Image%d" , i); - - /* create the image data set */ - if ((sub_image_id = H5Dcreate(image_id , ImageName , H5T_NATIVE_UINT8 , dataspace_id , H5P_DEFAULT)) < 0) { - fprintf(stderr , "Could not create dataset for image. Aborting... \n"); - return -1; - } - - /* write out the image */ - /****** Ask Elena about VOIDP ******/ - if (H5Dwrite(sub_image_id , H5T_NATIVE_UINT8 , H5S_ALL , H5S_ALL , H5P_DEFAULT , (void *)(gifImageDesc->Image)) < 0) { - fprintf(stderr , "Error writing image. Aborting... \n"); - return -1; - } - - /* set the attributes */ - /* This info is available at http://hdf.ncsa.uiuc.edu/HDF5/doc/ImageSpec.html */ - /* The following attributes must be set for each image: - ** --------------------------------------- - ** Attribute Name Value - ** CLASS IMAGE - ** IMAGE_VERSION 1.0 - ** IMAGE_SUBCLASS IMAGE_BITMAP - ** PALETTE ref. to palette datasets - ** IMAGE_MINMAXRANGE [0,255] - ** --------------------------------------- - */ - - /**************************************** - ** Attribute: CLASS - ** Value : IMAGE - *****************************************/ - - if (write_text_attribute(sub_image_id , "CLASS" , "IMAGE",strlen("IMAGE")) < 0) { - fprintf(stderr , "Unable to write CLASS = IMAGE attribute\n"); - return -1; - } - - /**************************************** - ** Attribute: IMAGE_VERSION - ** Value : 1.0 - *****************************************/ - - if (write_text_attribute(sub_image_id , "IMAGE_VERSION" , "1.0",strlen("1.0")) < 0) { - fprintf(stderr , "Unable to write IMAGE_VERSION attribute\n"); - return -1; - } - - /**************************************** - ** Attribute: IMAGE_SUBCLASS - ** Value : IMAGE_BITMAP - *****************************************/ - - if (write_text_attribute(sub_image_id , "IMAGE_SUBCLASS" , "IMAGE_BITMAP", strlen("IMAGE_BITMAP")) < 0) { - fprintf(stderr , "Unable to write IMAGE_SUBCLASS attribute\n"); - return -1; - } - - /**************************************** - ** Attribute: IMAGE_COLORMODEL - ** Value : RGB - *****************************************/ - - if (write_text_attribute(sub_image_id , "IMAGE_COLORMODEL" , "RGB", strlen("RGB")) < 0) { - fprintf(stderr , "Unable to write IMAGE_SUBCLASS attribute\n"); - return -1; - } - - /**************************************** - ** Attribute: PALETTE - ** Value : Reference to Palette - *****************************************/ - - /**** MAKE SURE PALETTE EXISTS!!! ****/ - if (gifHead.PackedField & 0x80) { - /* global palette exists */ - attr_dims[0] = 1; - - /* create the dataspace for the attribute */ - attr_dataspace_id = H5Screate_simple(1 , attr_dims , NULL); - - /* create the attribute */ - attr_attr_id = H5Acreate(sub_image_id , "PALETTE" , H5T_STD_REF_OBJ , attr_dataspace_id , H5P_DEFAULT); - - if (H5Awrite(attr_attr_id , H5T_STD_REF_OBJ , &pal_ref) < 0) { - fprintf(stderr , "Unable to write attribute. Aborting \n"); - return -1; - } - - /* close the attribute */ - if (H5Aclose(attr_attr_id) < 0) { - fprintf(stderr , "Unable to close CLASS IMAGE attribute. Aborting.\n"); - return -1; - } - - /* close the dataspace */ - if (H5Sclose(attr_dataspace_id) < 0) { - fprintf(stderr , "Unable to close attribute dataspace. Aborting \n"); - return -1; - } - } - - /**************************************** - ** Attribute: IMAGE_MINMAXRANGE - ** Value : minmax - *****************************************/ - - attr_dims[0] = 2; - - /* create the dataspace for the attribute */ - attr_dataspace_id = H5Screate_simple(1 , attr_dims , NULL); - - /* create the attribute */ - attr_attr_id = H5Acreate(sub_image_id , "IMAGE_MINMAXRANGE" , H5T_NATIVE_UINT8 , attr_dataspace_id , H5P_DEFAULT); - - if (H5Awrite(attr_attr_id , H5T_NATIVE_UINT8 , minmax) < 0) { - fprintf(stderr , "Unable to write attribute. Aborting \n"); - return -1; - } - - /* close the attribute */ - if (H5Aclose(attr_attr_id) < 0) { - fprintf(stderr , "Unable to close CLASS IMAGE attribute. Aborting.\n"); - return -1; - } - - /* close the dataspace */ - if (H5Sclose(attr_dataspace_id) < 0) { - fprintf(stderr , "Unable to close attribute dataspace. Aborting \n"); - return -1; - } - - /* close everything */ - if (H5Dclose(sub_image_id) < 0) { - fprintf(stderr , "Unable to close image dataset. Aborting \n"); - return -1; - } - - if (H5Sclose(dataspace_id) < 0) { - fprintf(stderr , "Unable to close image dataspace. Aborting \n"); - return -1; - } + + /* write image */ + if (H5IMmake_image_8bit(file_id,ImageName,dims[1],dims[0],(gifImageDesc->Image))<0) + return -1; + + /* attach the palette to the image dataset */ + if (H5IMlink_palette(file_id,ImageName,"Global Palette")<0) + return -1; } - /* close the main image group */ - if (H5Gclose(image_id) < 0) { - fprintf(stderr , "Could not close the image group. Aborting...\n"); - return -1; - } /* close the H5 file */ if (H5Fclose(file_id) < 0) { @@ -410,3 +119,4 @@ WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName , char *GIFFileName) return 0; } + diff --git a/tools/gifconv/Makefile.am b/tools/gifconv/Makefile.am index db2f411..29db664 100644 --- a/tools/gifconv/Makefile.am +++ b/tools/gifconv/Makefile.am @@ -20,7 +20,7 @@ include $(top_srcdir)/config/commence.am # Include src and tools/lib directories -INCLUDES=-I$(top_srcdir)/src -I$(top_srcdir)/tools/lib +INCLUDES=-I$(top_srcdir)/src -I$(top_srcdir)/tools/lib -I$(top_srcdir)/hl/src # These are our main targets, the tools bin_PROGRAMS=gif2h5 h52gif @@ -29,6 +29,6 @@ gif2h5_SOURCES=gif2hdf.c gif2mem.c decompress.c gifread.c writehdf.c h52gif_SOURCES=hdf2gif.c hdfgifwr.c readhdf.c # Programs all depend on the hdf5 library and the tools library -LDADD=$(LIBH5TOOLS) $(LIBHDF5) +LDADD=$(LIBH5TOOLS) $(LIBHDF5) $(LIBH5_HL) include $(top_srcdir)/config/conclude.am diff --git a/tools/gifconv/Makefile.in b/tools/gifconv/Makefile.in index b9133a6..629af0a 100644 --- a/tools/gifconv/Makefile.in +++ b/tools/gifconv/Makefile.in @@ -75,12 +75,15 @@ gif2h5_OBJECTS = $(am_gif2h5_OBJECTS) gif2h5_LDADD = $(LDADD) am__DEPENDENCIES_1 = $(top_builddir)/tools/lib/libh5tools.la am__DEPENDENCIES_2 = $(top_builddir)/src/libhdf5.la -gif2h5_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) +am__DEPENDENCIES_3 = $(top_builddir)/hl/src/libhdf5_hl.la +gif2h5_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \ + $(am__DEPENDENCIES_3) am_h52gif_OBJECTS = hdf2gif.$(OBJEXT) hdfgifwr.$(OBJEXT) \ readhdf.$(OBJEXT) h52gif_OBJECTS = $(am_h52gif_OBJECTS) h52gif_LDADD = $(LDADD) -h52gif_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) +h52gif_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_2) \ + $(am__DEPENDENCIES_3) DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)/src depcomp = $(SHELL) $(top_srcdir)/bin/depcomp am__depfiles_maybe = depfiles @@ -336,12 +339,12 @@ TRACE = perl $(top_srcdir)/bin/trace CHECK_CLEANFILES = *.chkexe *.chklog *.clog # Include src and tools/lib directories -INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/tools/lib +INCLUDES = -I$(top_srcdir)/src -I$(top_srcdir)/tools/lib -I$(top_srcdir)/hl/src gif2h5_SOURCES = gif2hdf.c gif2mem.c decompress.c gifread.c writehdf.c h52gif_SOURCES = hdf2gif.c hdfgifwr.c readhdf.c # Programs all depend on the hdf5 library and the tools library -LDADD = $(LIBH5TOOLS) $(LIBHDF5) +LDADD = $(LIBH5TOOLS) $(LIBHDF5) $(LIBH5_HL) # Automake needs to be taught how to build lib, progs, and tests targets. # These will be filled in automatically for the most part (e.g., diff --git a/tools/gifconv/writehdf.c b/tools/gifconv/writehdf.c index 8d7405e..ee7998c 100644 --- a/tools/gifconv/writehdf.c +++ b/tools/gifconv/writehdf.c @@ -16,54 +16,23 @@ #include <string.h> #include "gif.h" - -/******************************************************************* - * Function: write_text_attribute - * Use: Just a small wrapper to write text attributes easily - *******************************************************************/ -static int write_text_attribute(hid_t dataset_id , const char *attr_name, - const char *attr_value, const size_t attr_len) -{ - /* variables for the attributes */ - hsize_t attr_size; /* dimensions for the attribute */ - hid_t attr_dataspace_id; /* dataspaces needed for the various attributes */ - hid_t attr_attr_id; /* attribute id */ - hid_t attr_type_id; - - /* check strings */ - if (!attr_name || !attr_value) - return -1; - - /* figure out size of the data */ - attr_size = (hsize_t)attr_len; - - /* set the type to string */ - attr_type_id = H5Tcopy(H5T_C_S1); - H5Tset_size(attr_type_id , (size_t)attr_size); - - /* create the dataspace for the attribute */ - attr_dataspace_id = H5Screate(H5S_SCALAR); - - /* create the attribute */ - attr_attr_id = H5Acreate(dataset_id , attr_name , attr_type_id , - attr_dataspace_id , H5P_DEFAULT); - - /* write out the attribute data */ - if (H5Awrite(attr_attr_id , attr_type_id , attr_value) < 0) - return -1; - - /* close the attribute */ - if (H5Aclose(attr_attr_id) < 0) - return -1; - - /* close the dataspace */ - if (H5Sclose(attr_dataspace_id) < 0) { - fprintf(stderr , "Unable to close attribute dataspace. Aborting \n"); - return -1; - } - - return 0; -} +#include "H5IM.h" + + +/*------------------------------------------------------------------------- + * Function: WriteHDF + * + * Purpose: Write the GIF image with the HDF5 Image API + * + * Programmer: Unknown + * + * Modifications: pvn + * Use the HDF5 IMAGE API to write the HDF5 image and pallete + * + * Date: January, 31, 2006 + * + *------------------------------------------------------------------------- + */ int WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName , char *GIFFileName) @@ -78,14 +47,10 @@ WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName , char *GIFFileName) PlainTextCount; /* number of plain text extensions */ #endif /* UNUSED */ - char ImageName[256]; /* Image name for the GR Image */ - char GroupName[VSNAMELENMAX]; /* so that we can name the subgroups appropriately */ + char ImageName[256]; /* Image name for the Image */ /* H5 variables */ hid_t file_id; /* H5 file id */ - hid_t image_id; /* H5 id for the whole image */ - hid_t pal_id; /* H5 id for the palette */ - hobj_ref_t pal_ref; /* Create a reference for the palette */ /* temp counter */ int i; @@ -101,16 +66,6 @@ WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName , char *GIFFileName) PlainTextCount = (WORD)gifHead.PlainTextCount; #endif /* UNUSED */ - /* get the main group name from GIFFileName */ - GroupName[0]= '/'; - - if (strncpy(GroupName , GIFFileName , VSNAMELENMAX-2) == NULL) { - fprintf(stderr , "strncpy failed\n"); - exit(1); - } - - GroupName[VSNAMELENMAX - 1] = '\0'; - if ((file_id = H5Fcreate(HDFName , H5F_ACC_TRUNC , H5P_DEFAULT , H5P_DEFAULT)) < 0) { /* error occured opening the HDF File for write */ fprintf(stderr , "HDF file could not be opened for writing\n"); @@ -118,126 +73,23 @@ WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName , char *GIFFileName) exit(1); } - /* create a group within the root group to hold the gif image */ - /* might want to make a different naming style out here */ - image_id = H5Gcreate(file_id, GroupName , 0); - /* first create the global palette if there is one */ if (gifHead.PackedField & 0x80) { /* global palette exists */ - hid_t dataspace_id; /* identifier for dataspace */ hsize_t dims[2]; /* specify the dimensions of the palette */ hsize_t dimsr[1] = {1}; /* needed to store reference */ - hid_t ref_dataspace_id; /* dataspace id for references */ - hid_t ref_dataset_id; /* dataset id for references */ /* size of the palette is tablesize (rows) X 3 (columns) */ dims[0] = gifHead.TableSize; dims[1] = 3; - - /* create the dataspace */ - if ((dataspace_id = H5Screate_simple(2 , dims , NULL)) < 0) { - fprintf(stderr , "Could not create dataspace for palette. Aborting...\n"); - return -1; - } - - /* create the palette dataset */ - if ((pal_id = H5Dcreate(image_id , "Global Palette" , H5T_NATIVE_UINT8 , dataspace_id , H5P_DEFAULT )) < 0) { - fprintf(stderr , "Could not create palette dataset. Aborting...\n"); - return -1; - } - - /* write the palette data out */ - /****** Ask Elena about VOIDP ******/ - if (H5Dwrite(pal_id , H5T_NATIVE_UINT8 , H5S_ALL , H5S_ALL , H5P_DEFAULT , (void *)gifHead.HDFPalette) < 0) { - fprintf(stderr , "Error writing dataset. Aborting...\n"); - return -1; - } - - /* set palette attributes */ - - /* attribute CLASS = PALETTE */ - if ((write_text_attribute(pal_id , "CLASS" , "PALETTE",strlen("PALETTE"))) < 0) { - fprintf(stderr , "Unable to write palette attributes. Aborting\n"); - return -1; - } - - /* attribute PAL_COLORMODEL = RGB */ - if ((write_text_attribute(pal_id , "PAL_COLORMODEL" , "RGB",strlen("RGB"))) < 0) { - fprintf(stderr , "Unable to write palette attributes. Aborting\n"); - return -1; - } - - /* attribute PAL_TYPE = STANDARD8 */ - if ((write_text_attribute(pal_id , "PAL_TYPE" , "STANDARD8",strlen("STANDARD8"))) < 0) { - fprintf(stderr , "Unable to write palette attributes. Aborting\n"); - return -1; - } - - /* attribute PAL_VERSION = 1.0 */ - if ((write_text_attribute(pal_id , "PAL_VERSION" , "1.0",strlen("1.0"))) < 0) { - fprintf(stderr , "Unable to write palette attributes. Aborting\n"); - return -1; - } - - /* create dataspace for the dataset to store references */ - ref_dataspace_id = H5Screate_simple(1 , dimsr , NULL); - - /* create a dataset to store the references */ - ref_dataset_id = H5Dcreate(image_id , "Palette Reference" , H5T_STD_REF_OBJ , ref_dataspace_id , H5P_DEFAULT); - - /* create a reference to the palette */ - if (H5Rcreate(&pal_ref , image_id , "Global Palette" , H5R_OBJECT , -1) < 0) { - fprintf(stderr , "Unable to create palette reference\n"); - return -1; - } - - /* write the reference out */ - if (H5Dwrite(ref_dataset_id , H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL , H5P_DEFAULT, &pal_ref) < 0) { - fprintf(stderr , "Unable to write Palette Reference"); - return -1; - } - - /* close dataset */ - if (H5Dclose(ref_dataset_id) < 0) { - fprintf(stderr , "Unable to close palette dataset.\n"); - return -1; - } - - /* close dataspace */ - if (H5Sclose(ref_dataspace_id) < 0) { - fprintf(stderr , "Unable to close palette dataspace.\n"); - return -1; - } - - /* close everything */ - if (H5Dclose(pal_id) < 0) { - fprintf(stderr , "Unable to close palette dataset. Aborting.\n"); - return -1; - } - - if (H5Sclose(dataspace_id) < 0) { - fprintf(stderr , "Unable to close palette dataspace. Aborting.\n"); - return -1; - } + + /* make a palette */ + if (H5IMmake_palette(file_id,"Global Palette",dims,(unsigned char *)gifHead.HDFPalette)<0) + return -1; } for(i = 0; i < ImageCount; i++) { - /* variables for the images */ hsize_t dims[2]; /* dimensions for the dataset */ - hid_t dataspace_id; /* identifier for the dataspace */ - hid_t sub_image_id; /* wierd name to distinguish from the group_id */ - - /* variables for the attributes */ - hsize_t attr_dims[2]; /* dimensions for the attribute */ - hid_t attr_dataspace_id;/* dataspaces needed for the various attributes */ - hid_t attr_attr_id; /* attribute id */ - BYTE minmax[2]; /* lower and upper minmax values */ - - /* initialise minmax */ - minmax[0] = 0 ; - minmax[1] = 255; - /* get the gifImageDesc */ gifImageDesc = GifMemoryStruct.GifImageDesc[i]; @@ -245,162 +97,19 @@ WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName , char *GIFFileName) dims[0] = gifImageDesc->ImageHeight; dims[1] = gifImageDesc->ImageWidth; - /* create the empty dataspace */ - if ((dataspace_id = H5Screate_simple(2 , dims , NULL)) < 0) { - fprintf(stderr , "Could not create image dataspace. Aborting\n"); - return -1; - } - + /* create the image name */ sprintf(ImageName , "Image%d" , i); - - /* create the image data set */ - if ((sub_image_id = H5Dcreate(image_id , ImageName , H5T_NATIVE_UINT8 , dataspace_id , H5P_DEFAULT)) < 0) { - fprintf(stderr , "Could not create dataset for image. Aborting... \n"); - return -1; - } - - /* write out the image */ - /****** Ask Elena about VOIDP ******/ - if (H5Dwrite(sub_image_id , H5T_NATIVE_UINT8 , H5S_ALL , H5S_ALL , H5P_DEFAULT , (void *)(gifImageDesc->Image)) < 0) { - fprintf(stderr , "Error writing image. Aborting... \n"); - return -1; - } - - /* set the attributes */ - /* This info is available at http://hdf.ncsa.uiuc.edu/HDF5/doc/ImageSpec.html */ - /* The following attributes must be set for each image: - ** --------------------------------------- - ** Attribute Name Value - ** CLASS IMAGE - ** IMAGE_VERSION 1.0 - ** IMAGE_SUBCLASS IMAGE_BITMAP - ** PALETTE ref. to palette datasets - ** IMAGE_MINMAXRANGE [0,255] - ** --------------------------------------- - */ - - /**************************************** - ** Attribute: CLASS - ** Value : IMAGE - *****************************************/ - - if (write_text_attribute(sub_image_id , "CLASS" , "IMAGE",strlen("IMAGE")) < 0) { - fprintf(stderr , "Unable to write CLASS = IMAGE attribute\n"); - return -1; - } - - /**************************************** - ** Attribute: IMAGE_VERSION - ** Value : 1.0 - *****************************************/ - - if (write_text_attribute(sub_image_id , "IMAGE_VERSION" , "1.0",strlen("1.0")) < 0) { - fprintf(stderr , "Unable to write IMAGE_VERSION attribute\n"); - return -1; - } - - /**************************************** - ** Attribute: IMAGE_SUBCLASS - ** Value : IMAGE_BITMAP - *****************************************/ - - if (write_text_attribute(sub_image_id , "IMAGE_SUBCLASS" , "IMAGE_BITMAP", strlen("IMAGE_BITMAP")) < 0) { - fprintf(stderr , "Unable to write IMAGE_SUBCLASS attribute\n"); - return -1; - } - - /**************************************** - ** Attribute: IMAGE_COLORMODEL - ** Value : RGB - *****************************************/ - - if (write_text_attribute(sub_image_id , "IMAGE_COLORMODEL" , "RGB", strlen("RGB")) < 0) { - fprintf(stderr , "Unable to write IMAGE_SUBCLASS attribute\n"); - return -1; - } - - /**************************************** - ** Attribute: PALETTE - ** Value : Reference to Palette - *****************************************/ - - /**** MAKE SURE PALETTE EXISTS!!! ****/ - if (gifHead.PackedField & 0x80) { - /* global palette exists */ - attr_dims[0] = 1; - - /* create the dataspace for the attribute */ - attr_dataspace_id = H5Screate_simple(1 , attr_dims , NULL); - - /* create the attribute */ - attr_attr_id = H5Acreate(sub_image_id , "PALETTE" , H5T_STD_REF_OBJ , attr_dataspace_id , H5P_DEFAULT); - - if (H5Awrite(attr_attr_id , H5T_STD_REF_OBJ , &pal_ref) < 0) { - fprintf(stderr , "Unable to write attribute. Aborting \n"); - return -1; - } - - /* close the attribute */ - if (H5Aclose(attr_attr_id) < 0) { - fprintf(stderr , "Unable to close CLASS IMAGE attribute. Aborting.\n"); - return -1; - } - - /* close the dataspace */ - if (H5Sclose(attr_dataspace_id) < 0) { - fprintf(stderr , "Unable to close attribute dataspace. Aborting \n"); - return -1; - } - } - - /**************************************** - ** Attribute: IMAGE_MINMAXRANGE - ** Value : minmax - *****************************************/ - - attr_dims[0] = 2; - - /* create the dataspace for the attribute */ - attr_dataspace_id = H5Screate_simple(1 , attr_dims , NULL); - - /* create the attribute */ - attr_attr_id = H5Acreate(sub_image_id , "IMAGE_MINMAXRANGE" , H5T_NATIVE_UINT8 , attr_dataspace_id , H5P_DEFAULT); - - if (H5Awrite(attr_attr_id , H5T_NATIVE_UINT8 , minmax) < 0) { - fprintf(stderr , "Unable to write attribute. Aborting \n"); - return -1; - } - - /* close the attribute */ - if (H5Aclose(attr_attr_id) < 0) { - fprintf(stderr , "Unable to close CLASS IMAGE attribute. Aborting.\n"); - return -1; - } - - /* close the dataspace */ - if (H5Sclose(attr_dataspace_id) < 0) { - fprintf(stderr , "Unable to close attribute dataspace. Aborting \n"); - return -1; - } - - /* close everything */ - if (H5Dclose(sub_image_id) < 0) { - fprintf(stderr , "Unable to close image dataset. Aborting \n"); - return -1; - } - - if (H5Sclose(dataspace_id) < 0) { - fprintf(stderr , "Unable to close image dataspace. Aborting \n"); - return -1; - } + + /* write image */ + if (H5IMmake_image_8bit(file_id,ImageName,dims[1],dims[0],(gifImageDesc->Image))<0) + return -1; + + /* attach the palette to the image dataset */ + if (H5IMlink_palette(file_id,ImageName,"Global Palette")<0) + return -1; } - /* close the main image group */ - if (H5Gclose(image_id) < 0) { - fprintf(stderr , "Could not close the image group. Aborting...\n"); - return -1; - } /* close the H5 file */ if (H5Fclose(file_id) < 0) { @@ -410,3 +119,4 @@ WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName , char *GIFFileName) return 0; } + |