2003-04-01 02:04:52 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2007-02-07 22:56:24 +08:00
|
|
|
* Copyright by The HDF Group. *
|
2003-04-01 02:04:52 +08:00
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-15 00:54:16 +08:00
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
|
|
|
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
|
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
2003-04-01 02:04:52 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
2001-05-13 01:55:47 +08:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2001-07-25 01:51:22 +08:00
|
|
|
#include "gif.h"
|
2006-04-13 05:21:38 +08:00
|
|
|
#include "H5IMpublic.h"
|
2006-02-07 00:11:48 +08:00
|
|
|
|
2007-04-03 04:47:29 +08:00
|
|
|
#define PAL_NAME "global"
|
|
|
|
|
2006-02-07 00:11:48 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2001-05-13 01:55:47 +08:00
|
|
|
|
|
|
|
int
|
2010-08-13 05:11:00 +08:00
|
|
|
WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName)
|
2001-05-13 01:55:47 +08:00
|
|
|
{
|
2001-07-25 01:51:22 +08:00
|
|
|
GIFHEAD gifHead; /* GIF Header structure */
|
|
|
|
GIFIMAGEDESC *gifImageDesc; /* Logical Image Descriptor struct */
|
2007-04-03 04:47:29 +08:00
|
|
|
int has_pal=0;
|
2001-07-25 01:51:22 +08:00
|
|
|
|
2001-08-11 06:30:01 +08:00
|
|
|
long ImageCount; /* number of images */
|
2007-04-03 04:47:29 +08:00
|
|
|
#ifdef UNUSED
|
|
|
|
long CommentCount, /* number of comments */
|
|
|
|
ApplicationCount, /* number of application extensions */
|
|
|
|
PlainTextCount; /* number of plain text extensions */
|
|
|
|
#endif /* UNUSED */
|
2001-07-25 01:51:22 +08:00
|
|
|
|
2006-02-07 00:11:48 +08:00
|
|
|
char ImageName[256]; /* Image name for the Image */
|
2001-07-25 01:51:22 +08:00
|
|
|
|
|
|
|
/* H5 variables */
|
|
|
|
hid_t file_id; /* H5 file id */
|
|
|
|
|
|
|
|
/* temp counter */
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* get the GIFMem stuff */
|
|
|
|
gifHead = *(GifMemoryStruct.GifHeader);
|
|
|
|
|
|
|
|
/* get some data from gifHead */
|
2001-08-11 06:30:01 +08:00
|
|
|
ImageCount = gifHead.ImageCount;
|
2007-04-03 04:47:29 +08:00
|
|
|
#ifdef UNUSED
|
|
|
|
CommentCount = (WORD)gifHead.CommentCount;
|
|
|
|
ApplicationCount = (WORD)gifHead.ApplicationCount;
|
|
|
|
PlainTextCount = (WORD)gifHead.PlainTextCount;
|
|
|
|
#endif /* UNUSED */
|
2001-07-25 01:51:22 +08:00
|
|
|
|
|
|
|
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");
|
|
|
|
fprintf(stderr , "NOTE: GIF file must be present in the same directory as the binary on UNIX systems.\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* first create the global palette if there is one */
|
|
|
|
if (gifHead.PackedField & 0x80) { /* global palette exists */
|
2007-03-28 05:40:24 +08:00
|
|
|
hsize_t dims[2]; /* specify the dimensions of the palette */
|
2001-07-25 01:51:22 +08:00
|
|
|
|
|
|
|
/* size of the palette is tablesize (rows) X 3 (columns) */
|
|
|
|
dims[0] = gifHead.TableSize;
|
|
|
|
dims[1] = 3;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2006-02-07 00:11:48 +08:00
|
|
|
/* make a palette */
|
2007-04-03 04:47:29 +08:00
|
|
|
if (H5IMmake_palette(file_id,PAL_NAME,dims,(unsigned char *)gifHead.HDFPalette)<0)
|
2006-02-07 00:11:48 +08:00
|
|
|
return -1;
|
2007-04-03 04:47:29 +08:00
|
|
|
|
|
|
|
has_pal=1;
|
2001-07-25 01:51:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < ImageCount; i++) {
|
|
|
|
hsize_t dims[2]; /* dimensions for the dataset */
|
|
|
|
/* get the gifImageDesc */
|
|
|
|
gifImageDesc = GifMemoryStruct.GifImageDesc[i];
|
|
|
|
|
|
|
|
/* set the dimensions */
|
|
|
|
dims[0] = gifImageDesc->ImageHeight;
|
|
|
|
dims[1] = gifImageDesc->ImageWidth;
|
|
|
|
|
|
|
|
/* create the image name */
|
|
|
|
sprintf(ImageName , "Image%d" , i);
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2006-02-07 00:11:48 +08:00
|
|
|
/* write image */
|
|
|
|
if (H5IMmake_image_8bit(file_id,ImageName,dims[1],dims[0],(gifImageDesc->Image))<0)
|
|
|
|
return -1;
|
2008-09-16 23:52:51 +08:00
|
|
|
|
2006-02-07 00:11:48 +08:00
|
|
|
/* attach the palette to the image dataset */
|
2007-04-03 04:47:29 +08:00
|
|
|
if (has_pal)
|
|
|
|
{
|
|
|
|
if (H5IMlink_palette(file_id,ImageName,PAL_NAME)<0)
|
|
|
|
return -1;
|
|
|
|
}
|
2001-07-25 01:51:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* close the H5 file */
|
2001-08-11 06:30:01 +08:00
|
|
|
if (H5Fclose(file_id) < 0) {
|
2001-07-25 01:51:22 +08:00
|
|
|
fprintf(stderr , "Could not close HDF5 file. Aborting...\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2001-05-13 01:55:47 +08:00
|
|
|
}
|
2006-02-07 00:11:48 +08:00
|
|
|
|