summaryrefslogtreecommitdiffstats
path: root/tools/gifconv/gif2hdf.c
diff options
context:
space:
mode:
authorRushabh Doshi <rushabh@ncsa.uiuc.edu>2001-05-12 17:55:47 (GMT)
committerRushabh Doshi <rushabh@ncsa.uiuc.edu>2001-05-12 17:55:47 (GMT)
commit2eb5516b099b36d0d5222b89901a2302462098a2 (patch)
treeb211e58feb139f86fbf2e3f32ae5ec9483e18a71 /tools/gifconv/gif2hdf.c
parent00eeb08a51a6bc58112db4556875243edca61221 (diff)
downloadhdf5-2eb5516b099b36d0d5222b89901a2302462098a2.zip
hdf5-2eb5516b099b36d0d5222b89901a2302462098a2.tar.gz
hdf5-2eb5516b099b36d0d5222b89901a2302462098a2.tar.bz2
[svn-r3919]
Purpose: Adding new feature Description: Added gif2h5 and h52gif conversion utilities Solution: The utilites follow the framework built for the gif2hdf and hdf2gif utilities for hdf4. The main files modified were those that read the H5 file and those that write H5 file. In the future, if you wish to continue with the framework and extend it to .png or some other fileformat the main files to edit will be the gif reader and writer. One point to note with h52gif. You have to specify the exact location of the image and the palette that it links to. You can choose not to specify a palette (uniform grayscale chosen in this case) but you must specify image location. In the future, someone could edit the readhdf.c source to enable the reader to parse the hdf file and select all images with corresponding palettes. Platforms tested: modi4 , eirene , hawkwind , arabica , Ren (NT 4.0) , Personal box (win2k)
Diffstat (limited to 'tools/gifconv/gif2hdf.c')
-rw-r--r--tools/gifconv/gif2hdf.c114
1 files changed, 114 insertions, 0 deletions
diff --git a/tools/gifconv/gif2hdf.c b/tools/gifconv/gif2hdf.c
new file mode 100644
index 0000000..0211143
--- /dev/null
+++ b/tools/gifconv/gif2hdf.c
@@ -0,0 +1,114 @@
+/* #include <hdf.h> */
+#include "gif.h"
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+int
+main(argv , argc)
+int argv;
+char *argc[];
+{
+
+ GIFTOMEM GifMemoryStruct;
+ GIFIMAGEDESC gifImageDesc;
+
+ FILE *fpGif;
+
+ /* replacing int32 with long */
+ long i,ImageCount;
+ long filesize;
+
+ BYTE *MemGif;
+ BYTE *StartPos;
+
+ /* VSNAMELENMAX is a carryover from HDF4 and is #defined to 256 in gif.h */
+ char GIFFileName[VSNAMELENMAX];
+ char HDFFileName[VSNAMELENMAX];
+
+ /* Initialize all GifMemoryStruct pointers to null
+ ** to prevent hassles later on
+ */
+ GifMemoryStruct.GifHeader = NULL;
+ GifMemoryStruct.GifImageDesc = NULL;
+ GifMemoryStruct.GifGraphicControlExtension = NULL;
+ GifMemoryStruct.GifPlainTextExtension = NULL;
+ GifMemoryStruct.GifApplicationExtension = NULL;
+ GifMemoryStruct.GifCommentExtension = NULL;
+
+
+ if (argv<3)
+ {
+ printf("\n\nWrong Usage. Use:\ngif2hdf <GIFFILE> <HDFFILE>\n\n");
+ return(-1);
+ }
+
+
+
+ strncpy(GIFFileName , argc[1] , VSNAMELENMAX - 1);
+ strncpy(HDFFileName , argc[2] , VSNAMELENMAX - 1);
+ GIFFileName[VSNAMELENMAX - 1] = '\0';
+ HDFFileName[VSNAMELENMAX - 1] = '\0';
+
+ if (!(fpGif = fopen(GIFFileName,"rb"))) {
+ printf("Unable to open GIF file for reading.\n");
+ printf("Filename (including path) must be less than %d charachters in length\n",VSNAMELENMAX);
+ exit(-1);
+ }
+
+ /* Get the whole file into memory. Mem's much faster than I/O */
+ fseek(fpGif, 0L , 2);
+ filesize = ftell(fpGif);
+ fseek(fpGif, 0L , 0);
+ if (filesize == 0) printf("File Size Zero");
+ if (!(MemGif = StartPos = (BYTE *)malloc(filesize))) {
+ printf("Out of memory");
+ exit (-1);
+ }
+ if (fread(MemGif,filesize,1,fpGif) != 1) {
+ printf("Corrupted Input File");
+ exit(-1);
+ }
+
+ fseek(fpGif,0L,0);
+
+ /*
+ ** Call Gif2Mem and break the whole file into parts.
+ ** Gif2Mem also calls decompresses the images so we don't
+ ** have to worry about that
+ */
+ GifMemoryStruct = Gif2Mem(MemGif);
+ if (ferror(fpGif)) {
+ printf("File Stream Error\n\n");
+ exit(-1);
+ }
+ fclose(fpGif);
+
+ /* Call WriteHDF from here. Go ahead and change WriteHDF to write
+ ** whatever format you want
+ */
+ if (WriteHDF(GifMemoryStruct , argc[2] , argc[1]))
+ printf("HDF Write Error\n\n");
+
+ /* Free all buffers */
+ /* replacing int32 with long */
+ ImageCount = (long)((GifMemoryStruct.GifHeader)->ImageCount);
+
+ for(i = 0 ; i < ImageCount ; i++)
+ {
+ gifImageDesc = *(GifMemoryStruct.GifImageDesc[i]);
+ if (gifImageDesc.Image != NULL)
+ free(gifImageDesc.Image);
+
+ if (GifMemoryStruct.GifGraphicControlExtension[i] != NULL)
+ free(GifMemoryStruct.GifGraphicControlExtension[i]);
+
+ }
+ free(StartPos);
+
+ free (GifMemoryStruct.GifHeader);
+
+ if (GifMemoryStruct.GifApplicationExtension != NULL)
+ free (GifMemoryStruct.GifApplicationExtension);
+
+ return (0);
+}