summaryrefslogtreecommitdiffstats
path: root/hl/tools/gif2h5/hdf2gif.c
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2021-03-25 00:39:37 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2021-03-25 00:39:37 (GMT)
commitfeb20aac304b39e18c70f88cae2f7cf7d5c82db2 (patch)
treee15d7e751af4e3c42e77ea955d91db4cf27a71cf /hl/tools/gif2h5/hdf2gif.c
parentbdac2ecdbff2c389a222b3d93ff1eb1d23ec6b23 (diff)
downloadhdf5-feb20aac304b39e18c70f88cae2f7cf7d5c82db2.zip
hdf5-feb20aac304b39e18c70f88cae2f7cf7d5c82db2.tar.gz
hdf5-feb20aac304b39e18c70f88cae2f7cf7d5c82db2.tar.bz2
Formats the source and updates the gcc warning pragmas
Diffstat (limited to 'hl/tools/gif2h5/hdf2gif.c')
-rw-r--r--hl/tools/gif2h5/hdf2gif.c229
1 files changed, 99 insertions, 130 deletions
diff --git a/hl/tools/gif2h5/hdf2gif.c b/hl/tools/gif2h5/hdf2gif.c
index 1833c92..936fd21 100644
--- a/hl/tools/gif2h5/hdf2gif.c
+++ b/hl/tools/gif2h5/hdf2gif.c
@@ -21,9 +21,8 @@
/* Name of tool */
#define PROGRAMNAME "hdf2gif"
-#define IMAGE_WIDTH_MAX 65535 /* unsigned 16bits integer */
-#define IMAGE_HEIGHT_MAX 65535 /* unsigned 16bits integer */
-
+#define IMAGE_WIDTH_MAX 65535 /* unsigned 16bits integer */
+#define IMAGE_HEIGHT_MAX 65535 /* unsigned 16bits integer */
int EndianOrder;
@@ -31,8 +30,8 @@ static void
putword(int w, FILE *fp)
{
/* writes a 16-bit integer in GIF order (LSB first) */
- fputc(w &0xff, fp);
- fputc((w>>8)&0xff,fp);
+ fputc(w & 0xff, fp);
+ fputc((w >> 8) & 0xff, fp);
}
static void
@@ -42,18 +41,18 @@ usage(void)
fprintf(stdout, " h52gif -V \n");
fprintf(stdout, " Print HDF5 library version and exit\n");
printf("h52gif expects *at least* one h5_image.\n");
-
}
static void
leave(int ret)
{
- h5tools_close();
- HDexit(ret);
+ h5tools_close();
+ HDexit(ret);
}
FILE *fpGif = NULL;
-int main(int argc , char **argv)
+int
+main(int argc, char **argv)
{
GIFBYTE *Image;
@@ -61,25 +60,25 @@ int main(int argc , char **argv)
GIFCHAR *HDFName = NULL;
GIFCHAR *GIFName = NULL;
- GIFBYTE* b;
+ GIFBYTE *b;
- GIFBYTE GlobalPalette[256][3];
- GIFBYTE Red[256];
- GIFBYTE Green[256];
- GIFBYTE Blue[256];
+ GIFBYTE GlobalPalette[256][3];
+ GIFBYTE Red[256];
+ GIFBYTE Green[256];
+ GIFBYTE Blue[256];
- int RWidth, RHeight;
- int ColorMapSize, InitCodeSize, Background, BitsPerPixel;
- int j,nc;
- int i;
- int numcols = 0;
+ int RWidth, RHeight;
+ int ColorMapSize, InitCodeSize, Background, BitsPerPixel;
+ int j, nc;
+ int i;
+ int numcols = 0;
- GIFBYTE pc2nc[256] , r1[256] , g1[256] , b1[256];
+ GIFBYTE pc2nc[256], r1[256], g1[256], b1[256];
- int arg_index = 2;
- int bool_is_image = 0; /* 0 = false , 1 = true */
- char *image_name = NULL;
- int idx;
+ int arg_index = 2;
+ int bool_is_image = 0; /* 0 = false , 1 = true */
+ char *image_name = NULL;
+ int idx;
h5tools_setprogname(PROGRAMNAME);
h5tools_setstatus(EXIT_SUCCESS);
@@ -87,15 +86,12 @@ int main(int argc , char **argv)
/* Initialize h5tools lib */
h5tools_init();
- if ( argv[1] && (strcmp("-V",argv[1])==0) )
- {
+ if (argv[1] && (strcmp("-V", argv[1]) == 0)) {
print_version("gif2h5");
h5tools_setstatus(EXIT_SUCCESS);
}
-
- if (argc < 4)
- {
+ if (argc < 4) {
/* they didn't supply at least one image -- bail */
usage();
h5tools_setstatus(EXIT_FAILURE);
@@ -105,19 +101,17 @@ int main(int argc , char **argv)
GIFName = argv[2];
/* get the options */
- while (arg_index++ < argc - 1)
- {
- if (!strcmp(argv[arg_index] , "-i")) {
+ while (arg_index++ < argc - 1) {
+ if (!strcmp(argv[arg_index], "-i")) {
bool_is_image = 1;
continue;
}
- if (bool_is_image)
- {
+ if (bool_is_image) {
/* allocate space to store the image name */
size_t len = strlen(argv[arg_index]);
- image_name = (GIFCHAR*) malloc( len + 1);
- strcpy(image_name , argv[arg_index]);
+ image_name = (GIFCHAR *)malloc(len + 1);
+ strcpy(image_name, argv[arg_index]);
bool_is_image = 0;
continue;
@@ -129,80 +123,72 @@ int main(int argc , char **argv)
goto out;
}
- /* Do Endian Order testing and set Endian Order */
- idx = 0x0001;
- b = (GIFBYTE *) &idx;
- EndianOrder = (b[0] ? 1:0);
+ /* Do Endian Order testing and set Endian Order */
+ idx = 0x0001;
+ b = (GIFBYTE *)&idx;
+ EndianOrder = (b[0] ? 1 : 0);
- if (!(fpGif = fopen(GIFName , "wb")))
- {
+ if (!(fpGif = fopen(GIFName, "wb"))) {
printf("Error opening gif file for output. Aborting.\n");
goto out;
}
Background = 0;
{
- hsize_t width, height, planes;
- hid_t fid;
- char interlace[20];
- hssize_t npals;
- hsize_t pal_dims[2];
+ hsize_t width, height, planes;
+ hid_t fid;
+ char interlace[20];
+ hssize_t npals;
+ hsize_t pal_dims[2];
unsigned char *pal;
- if ((fid = H5Fopen(HDFName , H5F_ACC_RDONLY , H5P_DEFAULT)) < 0)
- {
- fprintf(stderr , "Unable to open HDF file for input. Aborting.\n");
+ if ((fid = H5Fopen(HDFName, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) {
+ fprintf(stderr, "Unable to open HDF file for input. Aborting.\n");
goto out;
}
/* get image's information */
- if ( H5IMget_image_info( fid, image_name, &width, &height, &planes, interlace, &npals ) < 0 )
- {
- fprintf(stderr , "Unable to get information of the image. Aborting.\n");
+ if (H5IMget_image_info(fid, image_name, &width, &height, &planes, interlace, &npals) < 0) {
+ fprintf(stderr, "Unable to get information of the image. Aborting.\n");
goto out;
}
- if (width > IMAGE_WIDTH_MAX || height > IMAGE_HEIGHT_MAX)
- {
- fprintf(stderr, "HDF5 image is too large. Limit is %d by %d.\n", IMAGE_WIDTH_MAX, IMAGE_HEIGHT_MAX);
+ if (width > IMAGE_WIDTH_MAX || height > IMAGE_HEIGHT_MAX) {
+ fprintf(stderr, "HDF5 image is too large. Limit is %d by %d.\n", IMAGE_WIDTH_MAX,
+ IMAGE_HEIGHT_MAX);
goto out;
}
/* tool can handle single plane images only. */
- if (planes > 1)
- {
+ if (planes > 1) {
fprintf(stderr, "Cannot handle multiple planes image\n");
goto out;
}
- Image = (GIFBYTE*) malloc( (size_t) width * (size_t) height );
+ Image = (GIFBYTE *)malloc((size_t)width * (size_t)height);
- if ( H5IMread_image( fid, image_name, Image ) < 0 )
- {
- fprintf(stderr , "Unable to read the image. Aborting.\n");
+ if (H5IMread_image(fid, image_name, Image) < 0) {
+ fprintf(stderr, "Unable to read the image. Aborting.\n");
goto out;
}
- if (npals)
- {
- if ( H5IMget_palette_info( fid, image_name, 0, pal_dims ) < 0 )
- {
- fprintf(stderr , "Unable to get information of the palette. Aborting.\n");
+ if (npals) {
+ if (H5IMget_palette_info(fid, image_name, 0, pal_dims) < 0) {
+ fprintf(stderr, "Unable to get information of the palette. Aborting.\n");
goto out;
}
- pal = (GIFBYTE*) malloc( (size_t) pal_dims[0] * (size_t) pal_dims[1] );
+ pal = (GIFBYTE *)malloc((size_t)pal_dims[0] * (size_t)pal_dims[1]);
- if ( H5IMget_palette( fid, image_name, 0, pal ) < 0 )
+ if (H5IMget_palette(fid, image_name, 0, pal) < 0)
goto out;
- numcols = (int) pal_dims[0];
+ numcols = (int)pal_dims[0];
- for (i = 0, j = 0 ; i < numcols ; j+=3, i++)
- {
+ for (i = 0, j = 0; i < numcols; j += 3, i++) {
GlobalPalette[i][0] = pal[j];
- GlobalPalette[i][1] = pal[j+1];
- GlobalPalette[i][2] = pal[j+2];
+ GlobalPalette[i][1] = pal[j + 1];
+ GlobalPalette[i][2] = pal[j + 2];
}
free(pal);
@@ -213,7 +199,6 @@ int main(int argc , char **argv)
RWidth = (int)width;
RHeight = (int)height;
-
/*
* If the first image does not have a palette, I make my own global
* color table Obviously this is not the best thing to do, better
@@ -223,62 +208,52 @@ int main(int argc , char **argv)
* palette
* 2. Check for palettes in any of the other images.
*/
- if (!npals)
- {
+ if (!npals) {
numcols = 256;
- for (i = 0 ; i < numcols ; i++)
- {
- Red[i] = (GIFBYTE)(255 - i);
+ for (i = 0; i < numcols; i++) {
+ Red[i] = (GIFBYTE)(255 - i);
Green[i] = (GIFBYTE)(255 - i);
- Blue[i] = (GIFBYTE)(255 - i);
+ Blue[i] = (GIFBYTE)(255 - i);
}
}
- else
- {
- for (i = 0 ; i < numcols ; i++)
- {
- Red[i] = GlobalPalette[i][0];
+ else {
+ for (i = 0; i < numcols; i++) {
+ Red[i] = GlobalPalette[i][0];
Green[i] = GlobalPalette[i][1];
- Blue[i] = GlobalPalette[i][2];
+ Blue[i] = GlobalPalette[i][2];
}
}
- for (i = 0; i < numcols; i++)
- {
+ for (i = 0; i < numcols; i++) {
pc2nc[i] = r1[i] = g1[i] = b1[i] = 0;
}
/* compute number of unique colors */
nc = 0;
- for (i = 0; i < numcols; i++)
- {
+ for (i = 0; i < numcols; i++) {
/* see if color #i is already used */
- for (j = 0; j < i; j++)
- {
+ for (j = 0; j < i; j++) {
if (Red[i] == Red[j] && Green[i] == Green[j] && Blue[i] == Blue[j])
break;
}
- if (j==i)
- {
+ if (j == i) {
/* wasn't found */
pc2nc[i] = (GIFBYTE)nc;
- r1[nc] = Red[i];
- g1[nc] = Green[i];
- b1[nc] = Blue[i];
+ r1[nc] = Red[i];
+ g1[nc] = Green[i];
+ b1[nc] = Blue[i];
nc++;
}
- else
- {
+ else {
pc2nc[i] = pc2nc[j];
}
}
/* figure out 'BitsPerPixel' */
- for (i = 1; i < 8; i++)
- {
- if ((1<<i) >= nc)
+ for (i = 1; i < 8; i++) {
+ if ((1 << i) >= nc)
break;
}
@@ -290,59 +265,54 @@ int main(int argc , char **argv)
else
InitCodeSize = BitsPerPixel;
- if (!fpGif)
- {
- fprintf(stderr, "WriteGIF: file not open for writing\n" );
+ if (!fpGif) {
+ fprintf(stderr, "WriteGIF: file not open for writing\n");
goto out;
}
+ fwrite("GIF87a", sizeof(char), 6, fpGif); /* the GIF magic number */
- fwrite("GIF87a", sizeof( char ), 6, fpGif); /* the GIF magic number */
-
- putword(RWidth, fpGif); /* screen descriptor */
+ putword(RWidth, fpGif); /* screen descriptor */
putword(RHeight, fpGif);
- i = 0x00; /* No, there is no color map */
- i |= (8-1)<<4; /* OR in the color resolution (hardwired 8) */
- i |= (BitsPerPixel - 1); /* OR in the # of bits per pixel */
- fputc(i,fpGif);
-
- fputc(Background,fpGif); /* background color */
- fputc(0, fpGif); /* future expansion byte */
+ i = 0x00; /* No, there is no color map */
+ i |= (8 - 1) << 4; /* OR in the color resolution (hardwired 8) */
+ i |= (BitsPerPixel - 1); /* OR in the # of bits per pixel */
+ fputc(i, fpGif);
+ fputc(Background, fpGif); /* background color */
+ fputc(0, fpGif); /* future expansion byte */
/*
* Put Image Descriptor
* Hardwiring Left Offset and Top Offset to 0x00
*/
- fputc(0x2c , fpGif);
- putword(0x00 , fpGif);
- putword(0x00 , fpGif);
- putword(RWidth , fpGif);
- putword(RHeight , fpGif);
+ fputc(0x2c, fpGif);
+ putword(0x00, fpGif);
+ putword(0x00, fpGif);
+ putword(RWidth, fpGif);
+ putword(RHeight, fpGif);
/* since we always have a local color palette ... */
- fputc((0x80 | (BitsPerPixel - 1)) , fpGif);
+ fputc((0x80 | (BitsPerPixel - 1)), fpGif);
- for (i = 0; i < ColorMapSize; i++)
- {
+ for (i = 0; i < ColorMapSize; i++) {
/* write out Global colormap */
fputc(r1[i], fpGif);
fputc(g1[i], fpGif);
fputc(b1[i], fpGif);
}
- fputc(InitCodeSize , fpGif);
+ fputc(InitCodeSize, fpGif);
- i = hdfWriteGIF(fpGif , Image , 0 , RHeight , RWidth , r1, g1 , b1 , pc2nc , 256 , 8 , BitsPerPixel);
+ i = hdfWriteGIF(fpGif, Image, 0, RHeight, RWidth, r1, g1, b1, pc2nc, 256, 8, BitsPerPixel);
fputc(0x00, fpGif);
free(Image);
}
- if (fputc(';',fpGif) == EOF)
- {
+ if (fputc(';', fpGif) == EOF) {
/* Write GIF file terminator */
- fprintf(stderr , "Error!");
+ fprintf(stderr, "Error!");
goto out;
}
@@ -353,7 +323,6 @@ int main(int argc , char **argv)
leave(h5tools_getstatus());
-
out:
if (fpGif != NULL)